summaryrefslogtreecommitdiffstats
path: root/llvm/lib/TableGen
diff options
context:
space:
mode:
authorDavid Greene <greened@obbligato.org>2011-10-19 13:03:39 +0000
committerDavid Greene <greened@obbligato.org>2011-10-19 13:03:39 +0000
commit5c9fa026dcd6f7213d7fadacdaa389fd4cfae7b6 (patch)
tree3c121a714a14f7b730a470d65b33be0f27a9ea3a /llvm/lib/TableGen
parent9ba42085dac878f3ae6fc15345c43796d5122d00 (diff)
downloadbcm5719-llvm-5c9fa026dcd6f7213d7fadacdaa389fd4cfae7b6.tar.gz
bcm5719-llvm-5c9fa026dcd6f7213d7fadacdaa389fd4cfae7b6.zip
Disambiguate Numbers and Identifiers
Use lookahead to determine whether a number is really a number or is part of something forming an identifier. This won't come into play until the paste operator is recognized as a unique token. llvm-svn: 142513
Diffstat (limited to 'llvm/lib/TableGen')
-rw-r--r--llvm/lib/TableGen/TGLexer.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index c1b00b66ef5..3262121ee8d 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -132,8 +132,44 @@ tgtok::TokKind TGLexer::LexToken() {
return LexToken();
case '-': case '+':
case '0': case '1': case '2': case '3': case '4': case '5': case '6':
- case '7': case '8': case '9':
+ case '7': case '8': case '9': {
+ int NextChar = 0;
+ if (isdigit(CurChar)) {
+ // Allow identifiers to start with a number if it is followed by
+ // an identifier. This can happen with paste operations like
+ // foo#8i.
+ int i = 0;
+ do {
+ NextChar = peekNextChar(i++);
+ } while (isdigit(NextChar));
+
+ if (NextChar == 'x' || NextChar == 'b') {
+ // If this is [0-9]b[01] or [0-9]x[0-9A-fa-f] this is most
+ // likely a number.
+ int NextNextChar = peekNextChar(i);
+ switch (NextNextChar) {
+ default:
+ break;
+ case '0': case '1':
+ if (NextChar == 'b')
+ return LexNumber();
+ // Fallthrough
+ case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ if (NextChar == 'x')
+ return LexNumber();
+ break;
+ }
+ }
+ }
+
+ if (isalpha(NextChar) || NextChar == '_')
+ return LexIdentifier();
+
return LexNumber();
+ }
case '"': return LexString();
case '$': return LexVarName();
case '[': return LexBracket();
OpenPOWER on IntegriCloud