@@ -6,19 +6,20 @@ namespace root_signature {
6
6
7
7
// Lexer Definitions
8
8
9
- static bool IsPreprocessorNumberChar (char C) {
9
+ static bool IsNumberChar (char C) {
10
10
// TODO: extend for float support with or without hexadecimal/exponent
11
11
return isdigit (C); // integer support
12
12
}
13
13
14
14
bool RootSignatureLexer::LexNumber (RootSignatureToken &Result) {
15
15
// NumericLiteralParser does not handle the sign so we will manually apply it
16
- Result.Signed = Buffer.front () == ' -' ;
16
+ bool Negative = Buffer.front () == ' -' ;
17
+ Result.Signed = Negative || Buffer.front () == ' +' ;
17
18
if (Result.Signed )
18
19
AdvanceBuffer ();
19
20
20
21
// Retrieve the possible number
21
- StringRef NumSpelling = Buffer.take_while (IsPreprocessorNumberChar );
22
+ StringRef NumSpelling = Buffer.take_while (IsNumberChar );
22
23
23
24
// Parse the numeric value and do semantic checks on its specification
24
25
clang::NumericLiteralParser Literal (NumSpelling, SourceLoc,
@@ -35,7 +36,7 @@ bool RootSignatureLexer::LexNumber(RootSignatureToken &Result) {
35
36
if (Literal.GetIntegerValue (X))
36
37
return true ; // TODO: Report overflow error
37
38
38
- X = Result. Signed ? -X : X;
39
+ X = Negative ? -X : X;
39
40
Result.IntLiteral = (uint32_t )X.getZExtValue ();
40
41
} else {
41
42
return true ; // TODO: report unsupported number literal specification
@@ -84,7 +85,7 @@ bool RootSignatureLexer::LexToken(RootSignatureToken &Result) {
84
85
}
85
86
86
87
// Numeric constant
87
- if (isdigit (C) || C == ' -' )
88
+ if (isdigit (C) || C == ' -' || C == ' + ' )
88
89
return LexNumber (Result);
89
90
90
91
// All following tokens require at least one additional character
@@ -101,7 +102,8 @@ bool RootSignatureLexer::LexToken(RootSignatureToken &Result) {
101
102
if (LexNumber (Result))
102
103
return true ;
103
104
104
- // Lex number could also parse a float so ensure it was an unsigned int
105
+ // Lex number could also parse a signed int/float so ensure it was an
106
+ // unsigned int
105
107
if (Result.Kind != TokenKind::int_literal || Result.Signed )
106
108
return true ; // Return invalid number literal for register error
107
109
0 commit comments