[clang] [HLSL][RootSignature] Implement Lexing of DescriptorTables (PR #122981)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 9 13:10:13 PST 2025


================
@@ -0,0 +1,171 @@
+#include "clang/Parse/ParseHLSLRootSignature.h"
+
+namespace clang {
+namespace hlsl {
+
+// Lexer Definitions
+
+static bool IsNumberChar(char C) {
+  // TODO(#120472): extend for float support exponents
+  return isdigit(C); // integer support
+}
+
+bool RootSignatureLexer::LexNumber(RootSignatureToken &Result) {
+  // NumericLiteralParser does not handle the sign so we will manually apply it
+  bool Negative = Buffer.front() == '-';
+  bool Signed = Negative || Buffer.front() == '+';
+  if (Signed)
+    AdvanceBuffer();
+
+  // Retrieve the possible number
+  StringRef NumSpelling = Buffer.take_while(IsNumberChar);
+
+  // Catch this now as the Literal Parser will accept it as valid
+  if (NumSpelling.empty()) {
+    PP.getDiagnostics().Report(Result.TokLoc,
+                               diag::err_hlsl_invalid_number_literal);
----------------
llvm-beanz wrote:

IIUC, this occurs if the parser sees a `-` or `+` but no specified literal value after that. Is that correct?

A more succinct error message like "expected numeric literal" is probably a better message. The current one "expected number literal is not a supported number literal of unsigned integer or integer" is quite confusing.


https://github.com/llvm/llvm-project/pull/122981


More information about the cfe-commits mailing list