@@ -318,6 +318,15 @@ class SDKContext {
318
318
}
319
319
bool checkingABI () const { return ABI; }
320
320
ArrayRef<ABIAttributeInfo> getABIAttributeInfo () const { return ABIAttrs; }
321
+
322
+ template <class YAMLNodeTy , typename ...ArgTypes>
323
+ void diagnose (YAMLNodeTy node, Diag<ArgTypes...> ID,
324
+ typename detail::PassArgument<ArgTypes>::type... args) {
325
+ auto smRange = node->getSourceRange ();
326
+ auto range = SourceRange (SourceLoc (smRange.Start ), SourceLoc (smRange.End ));
327
+ Diags.diagnose (range.Start , ID, std::forward<ArgTypes>(args)...)
328
+ .highlight (range);
329
+ }
321
330
};
322
331
323
332
// A node matcher will traverse two trees of SDKNode and find matched nodes
@@ -1045,9 +1054,6 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
1045
1054
return std::stoi (cast<llvm::yaml::ScalarNode>(N)->getRawValue ());
1046
1055
};
1047
1056
1048
- static auto convertRange = [](llvm::SMRange Range) -> SourceRange {
1049
- return SourceRange (SourceLoc (Range.Start ), SourceLoc (Range.End ));
1050
- };
1051
1057
SDKNodeKind Kind;
1052
1058
SDKNodeInitInfo Info (Ctx);
1053
1059
NodeVector Children;
@@ -1060,10 +1066,8 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
1060
1066
if (auto parsedKind = parseSDKNodeKind (GetScalarString (Pair.getValue ()))) {
1061
1067
Kind = *parsedKind;
1062
1068
} else {
1063
- auto range = convertRange (Pair.getValue ()->getSourceRange ());
1064
- Ctx.getDiags ().diagnose (range.Start , diag::sdk_node_unrecognized_node_kind,
1065
- GetScalarString (Pair.getValue ()))
1066
- .highlight (range);
1069
+ Ctx.diagnose (Pair.getValue (), diag::sdk_node_unrecognized_node_kind,
1070
+ GetScalarString (Pair.getValue ()));
1067
1071
}
1068
1072
break ;
1069
1073
case KeyKind::KK_name:
@@ -1167,10 +1171,8 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
1167
1171
}
1168
1172
}
1169
1173
else {
1170
- auto range = convertRange (Pair.getKey ()->getSourceRange ());
1171
- Ctx.getDiags ().diagnose (range.Start , diag::sdk_node_unrecognized_key,
1172
- keyString)
1173
- .highlight (range);
1174
+ Ctx.diagnose (Pair.getKey (), diag::sdk_node_unrecognized_key,
1175
+ keyString);
1174
1176
Pair.skip ();
1175
1177
}
1176
1178
};
0 commit comments