[clang] [HLSL] Rewrite semantics parsing (PR #152537)
Nathan Gauër via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 9 05:25:11 PDT 2025
================
@@ -118,6 +118,47 @@ static void fixSeparateAttrArgAndNumber(StringRef ArgStr, SourceLocation ArgLoc,
Slot = new (Ctx) IdentifierLoc(ArgLoc, PP.getIdentifierInfo(FixedArg));
}
+Parser::ParsedSemantic Parser::ParseHLSLSemantic() {
+ assert(Tok.is(tok::identifier) && "Not a HLSL Annotation");
+
+ // Semantic pattern: [A-Za-z_]([A-Za-z_0-9]*[A-Za-z_])?[0-9]*
+ // The first part is the semantic name, the second is the optional
+ // semantic index. The semantic index is the number at the end of
+ // the semantic, including leading zeroes. Digits located before
+ // the last letter are part of the semantic name.
+ bool Invalid = false;
+ SmallString<256> Buffer;
+ Buffer.resize(Tok.getLength() + 1);
+ StringRef Identifier = PP.getSpelling(Tok, Buffer);
+ if (Invalid) {
+ Diag(Tok.getLocation(), diag::err_expected_semantic_identifier);
+ return {};
+ }
+
+ assert(Identifier.size() > 0);
+ unsigned I = Identifier.size();
+ for (; I > 0 && isDigit(Identifier[I - 1]); --I)
----------------
Keenuts wrote:
Replaced this loop with `find_last_not_of` which in our case is a good replacement
https://github.com/llvm/llvm-project/pull/152537
More information about the cfe-commits
mailing list