blob: 0dc1c70136b5e154fab0c89b610f139882cf3c31 [file] [log] [blame]
Chris Lattnera8058742007-11-18 02:57:27 +00001//===- TGLexer.cpp - Lexer for TableGen -----------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner30609102007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnera8058742007-11-18 02:57:27 +00007//
8//===----------------------------------------------------------------------===//
9//
10// Implement the Lexer for TableGen.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattner6aaca042007-11-18 05:25:45 +000014#include "TGLexer.h"
Peter Collingbourne7c788882011-10-01 16:41:13 +000015#include "llvm/TableGen/Error.h"
Chris Lattner099e1982009-06-21 03:36:54 +000016#include "llvm/Support/SourceMgr.h"
Chris Lattnera8058742007-11-18 02:57:27 +000017#include "llvm/Support/MemoryBuffer.h"
Chuck Rose III8b0ec642007-11-21 19:36:25 +000018#include "llvm/Config/config.h"
Bill Wendlingcd466f52010-12-08 20:02:49 +000019#include "llvm/ADT/StringSwitch.h"
20#include "llvm/ADT/Twine.h"
Chris Lattnera8058742007-11-18 02:57:27 +000021#include <cctype>
Duncan Sands4520dd22008-10-08 07:23:46 +000022#include <cstdio>
Anton Korobeynikovae9f3a32008-02-20 11:08:44 +000023#include <cstdlib>
24#include <cstring>
Dan Gohman63f97202008-10-17 01:33:43 +000025#include <cerrno>
Chris Lattnera8058742007-11-18 02:57:27 +000026using namespace llvm;
27
Chris Lattner8070ea32009-06-21 03:41:50 +000028TGLexer::TGLexer(SourceMgr &SM) : SrcMgr(SM) {
Chris Lattneraa739d22009-03-13 07:05:43 +000029 CurBuffer = 0;
30 CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
Chris Lattnera8058742007-11-18 02:57:27 +000031 CurPtr = CurBuf->getBufferStart();
Chris Lattner56a9fcf2007-11-19 07:43:52 +000032 TokStart = 0;
Chris Lattnera8058742007-11-18 02:57:27 +000033}
34
Chris Lattner1e3a8a42009-06-21 03:39:35 +000035SMLoc TGLexer::getLoc() const {
36 return SMLoc::getFromPointer(TokStart);
Chris Lattner1c8ae592009-03-13 16:01:53 +000037}
38
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +000039/// ReturnError - Set the error to the specified string at the specified
Chris Lattnerf4601652007-11-22 20:49:04 +000040/// location. This is defined to always return tgtok::Error.
Benjamin Kramerd1e17032010-09-27 17:42:11 +000041tgtok::TokKind TGLexer::ReturnError(const char *Loc, const Twine &Msg) {
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +000042 PrintError(Loc, Msg);
Chris Lattnerf4601652007-11-22 20:49:04 +000043 return tgtok::Error;
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +000044}
Chris Lattnera8058742007-11-18 02:57:27 +000045
Chris Lattnera8058742007-11-18 02:57:27 +000046int TGLexer::getNextChar() {
47 char CurChar = *CurPtr++;
48 switch (CurChar) {
49 default:
Chris Lattnerc1819182007-11-18 05:48:46 +000050 return (unsigned char)CurChar;
Chris Lattneraa739d22009-03-13 07:05:43 +000051 case 0: {
Chris Lattnera8058742007-11-18 02:57:27 +000052 // A nul character in the stream is either the end of the current buffer or
53 // a random nul in the file. Disambiguate that here.
54 if (CurPtr-1 != CurBuf->getBufferEnd())
55 return 0; // Just whitespace.
56
57 // If this is the end of an included file, pop the parent file off the
58 // include stack.
Chris Lattner1e3a8a42009-06-21 03:39:35 +000059 SMLoc ParentIncludeLoc = SrcMgr.getParentIncludeLoc(CurBuffer);
60 if (ParentIncludeLoc != SMLoc()) {
Chris Lattneraa739d22009-03-13 07:05:43 +000061 CurBuffer = SrcMgr.FindBufferContainingLoc(ParentIncludeLoc);
62 CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
Chris Lattner1c8ae592009-03-13 16:01:53 +000063 CurPtr = ParentIncludeLoc.getPointer();
Chris Lattnera8058742007-11-18 02:57:27 +000064 return getNextChar();
65 }
66
67 // Otherwise, return end of file.
68 --CurPtr; // Another call to lex will return EOF again.
69 return EOF;
Chris Lattneraa739d22009-03-13 07:05:43 +000070 }
Chris Lattnera8058742007-11-18 02:57:27 +000071 case '\n':
72 case '\r':
73 // Handle the newline character by ignoring it and incrementing the line
74 // count. However, be careful about 'dos style' files with \n\r in them.
75 // Only treat a \n\r or \r\n as a single line.
76 if ((*CurPtr == '\n' || (*CurPtr == '\r')) &&
77 *CurPtr != CurChar)
Chris Lattnerc1819182007-11-18 05:48:46 +000078 ++CurPtr; // Eat the two char newline sequence.
Chris Lattnera8058742007-11-18 02:57:27 +000079 return '\n';
80 }
81}
82
Chris Lattnerf4601652007-11-22 20:49:04 +000083tgtok::TokKind TGLexer::LexToken() {
Chris Lattner56a9fcf2007-11-19 07:43:52 +000084 TokStart = CurPtr;
Chris Lattnera8058742007-11-18 02:57:27 +000085 // This always consumes at least one character.
86 int CurChar = getNextChar();
87
88 switch (CurChar) {
89 default:
Chris Lattnerc2b08752010-10-05 22:59:29 +000090 // Handle letters: [a-zA-Z_#]
David Greene065f2592009-05-05 16:28:25 +000091 if (isalpha(CurChar) || CurChar == '_' || CurChar == '#')
Chris Lattnera8058742007-11-18 02:57:27 +000092 return LexIdentifier();
93
Chris Lattnerf4601652007-11-22 20:49:04 +000094 // Unknown character, emit an error.
95 return ReturnError(TokStart, "Unexpected character");
96 case EOF: return tgtok::Eof;
97 case ':': return tgtok::colon;
98 case ';': return tgtok::semi;
99 case '.': return tgtok::period;
100 case ',': return tgtok::comma;
101 case '<': return tgtok::less;
102 case '>': return tgtok::greater;
103 case ']': return tgtok::r_square;
104 case '{': return tgtok::l_brace;
105 case '}': return tgtok::r_brace;
106 case '(': return tgtok::l_paren;
107 case ')': return tgtok::r_paren;
108 case '=': return tgtok::equal;
109 case '?': return tgtok::question;
110
Chris Lattnera8058742007-11-18 02:57:27 +0000111 case 0:
112 case ' ':
113 case '\t':
114 case '\n':
115 case '\r':
116 // Ignore whitespace.
117 return LexToken();
118 case '/':
119 // If this is the start of a // comment, skip until the end of the line or
120 // the end of the buffer.
121 if (*CurPtr == '/')
122 SkipBCPLComment();
123 else if (*CurPtr == '*') {
124 if (SkipCComment())
Chris Lattnerf4601652007-11-22 20:49:04 +0000125 return tgtok::Error;
126 } else // Otherwise, this is an error.
127 return ReturnError(TokStart, "Unexpected character");
Chris Lattnera8058742007-11-18 02:57:27 +0000128 return LexToken();
129 case '-': case '+':
130 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
131 case '7': case '8': case '9':
132 return LexNumber();
133 case '"': return LexString();
134 case '$': return LexVarName();
135 case '[': return LexBracket();
136 case '!': return LexExclaim();
137 }
138}
139
140/// LexString - Lex "[^"]*"
Chris Lattnerf4601652007-11-22 20:49:04 +0000141tgtok::TokKind TGLexer::LexString() {
Chris Lattnera8058742007-11-18 02:57:27 +0000142 const char *StrStart = CurPtr;
143
Chris Lattnerea9f4df2009-03-13 21:03:27 +0000144 CurStrVal = "";
145
Chris Lattnera8058742007-11-18 02:57:27 +0000146 while (*CurPtr != '"') {
147 // If we hit the end of the buffer, report an error.
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000148 if (*CurPtr == 0 && CurPtr == CurBuf->getBufferEnd())
149 return ReturnError(StrStart, "End of file in string literal");
150
151 if (*CurPtr == '\n' || *CurPtr == '\r')
152 return ReturnError(StrStart, "End of line in string literal");
Chris Lattnera8058742007-11-18 02:57:27 +0000153
Chris Lattnerea9f4df2009-03-13 21:03:27 +0000154 if (*CurPtr != '\\') {
155 CurStrVal += *CurPtr++;
156 continue;
157 }
158
Chris Lattnera8058742007-11-18 02:57:27 +0000159 ++CurPtr;
Chris Lattnerea9f4df2009-03-13 21:03:27 +0000160
161 switch (*CurPtr) {
162 case '\\': case '\'': case '"':
163 // These turn into their literal character.
164 CurStrVal += *CurPtr++;
165 break;
Chris Lattnere023bb62009-03-13 21:23:43 +0000166 case 't':
Chris Lattner7f3b28a2009-03-13 21:33:17 +0000167 CurStrVal += '\t';
Chris Lattnere023bb62009-03-13 21:23:43 +0000168 ++CurPtr;
169 break;
170 case 'n':
Chris Lattner7f3b28a2009-03-13 21:33:17 +0000171 CurStrVal += '\n';
Chris Lattnere023bb62009-03-13 21:23:43 +0000172 ++CurPtr;
173 break;
174
Chris Lattnerea9f4df2009-03-13 21:03:27 +0000175 case '\n':
176 case '\r':
177 return ReturnError(CurPtr, "escaped newlines not supported in tblgen");
178
179 // If we hit the end of the buffer, report an error.
180 case '\0':
181 if (CurPtr == CurBuf->getBufferEnd())
182 return ReturnError(StrStart, "End of file in string literal");
183 // FALL THROUGH
184 default:
185 return ReturnError(CurPtr, "invalid escape in string literal");
186 }
Chris Lattnera8058742007-11-18 02:57:27 +0000187 }
188
Chris Lattnera8058742007-11-18 02:57:27 +0000189 ++CurPtr;
Chris Lattnerf4601652007-11-22 20:49:04 +0000190 return tgtok::StrVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000191}
192
Chris Lattnerf4601652007-11-22 20:49:04 +0000193tgtok::TokKind TGLexer::LexVarName() {
Chris Lattnera8058742007-11-18 02:57:27 +0000194 if (!isalpha(CurPtr[0]) && CurPtr[0] != '_')
Chris Lattnerf4601652007-11-22 20:49:04 +0000195 return ReturnError(TokStart, "Invalid variable name");
Chris Lattnera8058742007-11-18 02:57:27 +0000196
197 // Otherwise, we're ok, consume the rest of the characters.
198 const char *VarNameStart = CurPtr++;
199
200 while (isalpha(*CurPtr) || isdigit(*CurPtr) || *CurPtr == '_')
201 ++CurPtr;
202
Chris Lattnerf4601652007-11-22 20:49:04 +0000203 CurStrVal.assign(VarNameStart, CurPtr);
204 return tgtok::VarName;
Chris Lattnera8058742007-11-18 02:57:27 +0000205}
206
207
Chris Lattnerf4601652007-11-22 20:49:04 +0000208tgtok::TokKind TGLexer::LexIdentifier() {
Chris Lattnerc2b08752010-10-05 22:59:29 +0000209 // The first letter is [a-zA-Z_#].
Chris Lattnerf4601652007-11-22 20:49:04 +0000210 const char *IdentStart = TokStart;
Chris Lattnera8058742007-11-18 02:57:27 +0000211
Chris Lattnerc2b08752010-10-05 22:59:29 +0000212 // Match the rest of the identifier regex: [0-9a-zA-Z_#]*
213 while (isalpha(*CurPtr) || isdigit(*CurPtr) || *CurPtr == '_' ||
214 *CurPtr == '#')
215 ++CurPtr;
David Greene065f2592009-05-05 16:28:25 +0000216
Chris Lattnera8058742007-11-18 02:57:27 +0000217
218 // Check to see if this identifier is a keyword.
219 unsigned Len = CurPtr-IdentStart;
220
Chris Lattnerf4601652007-11-22 20:49:04 +0000221 if (Len == 3 && !memcmp(IdentStart, "int", 3)) return tgtok::Int;
222 if (Len == 3 && !memcmp(IdentStart, "bit", 3)) return tgtok::Bit;
223 if (Len == 4 && !memcmp(IdentStart, "bits", 4)) return tgtok::Bits;
224 if (Len == 6 && !memcmp(IdentStart, "string", 6)) return tgtok::String;
225 if (Len == 4 && !memcmp(IdentStart, "list", 4)) return tgtok::List;
226 if (Len == 4 && !memcmp(IdentStart, "code", 4)) return tgtok::Code;
227 if (Len == 3 && !memcmp(IdentStart, "dag", 3)) return tgtok::Dag;
Chris Lattnera8058742007-11-18 02:57:27 +0000228
Chris Lattnerf4601652007-11-22 20:49:04 +0000229 if (Len == 5 && !memcmp(IdentStart, "class", 5)) return tgtok::Class;
230 if (Len == 3 && !memcmp(IdentStart, "def", 3)) return tgtok::Def;
231 if (Len == 4 && !memcmp(IdentStart, "defm", 4)) return tgtok::Defm;
232 if (Len == 10 && !memcmp(IdentStart, "multiclass", 10))
233 return tgtok::MultiClass;
234 if (Len == 5 && !memcmp(IdentStart, "field", 5)) return tgtok::Field;
235 if (Len == 3 && !memcmp(IdentStart, "let", 3)) return tgtok::Let;
236 if (Len == 2 && !memcmp(IdentStart, "in", 2)) return tgtok::In;
Chris Lattnera8058742007-11-18 02:57:27 +0000237
238 if (Len == 7 && !memcmp(IdentStart, "include", 7)) {
Chris Lattnerf4601652007-11-22 20:49:04 +0000239 if (LexInclude()) return tgtok::Error;
240 return Lex();
Chris Lattnera8058742007-11-18 02:57:27 +0000241 }
242
Chris Lattnerf4601652007-11-22 20:49:04 +0000243 CurStrVal.assign(IdentStart, CurPtr);
244 return tgtok::Id;
Chris Lattnera8058742007-11-18 02:57:27 +0000245}
246
247/// LexInclude - We just read the "include" token. Get the string token that
248/// comes next and enter the include.
249bool TGLexer::LexInclude() {
250 // The token after the include must be a string.
Chris Lattnerf4601652007-11-22 20:49:04 +0000251 tgtok::TokKind Tok = LexToken();
252 if (Tok == tgtok::Error) return true;
253 if (Tok != tgtok::StrVal) {
254 PrintError(getLoc(), "Expected filename after include");
Chris Lattnera8058742007-11-18 02:57:27 +0000255 return true;
256 }
257
258 // Get the string.
Chris Lattnerf4601652007-11-22 20:49:04 +0000259 std::string Filename = CurStrVal;
Joerg Sonnenbergerdd137902011-06-01 13:10:15 +0000260 std::string IncludedFile;
Chris Lattnera8058742007-11-18 02:57:27 +0000261
Chris Lattner7ee5d5f2009-06-21 05:06:04 +0000262
Joerg Sonnenbergerdd137902011-06-01 13:10:15 +0000263 CurBuffer = SrcMgr.AddIncludeFile(Filename, SMLoc::getFromPointer(CurPtr),
264 IncludedFile);
Chris Lattnerd926e042009-06-21 05:33:06 +0000265 if (CurBuffer == -1) {
Chris Lattnerf4601652007-11-22 20:49:04 +0000266 PrintError(getLoc(), "Could not find include file '" + Filename + "'");
Chris Lattnera8058742007-11-18 02:57:27 +0000267 return true;
268 }
269
Joerg Sonnenbergerdd137902011-06-01 13:10:15 +0000270 Dependencies.push_back(IncludedFile);
Chris Lattnera8058742007-11-18 02:57:27 +0000271 // Save the line number and lex buffer of the includer.
Chris Lattner7ee5d5f2009-06-21 05:06:04 +0000272 CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
Chris Lattnera8058742007-11-18 02:57:27 +0000273 CurPtr = CurBuf->getBufferStart();
274 return false;
275}
276
277void TGLexer::SkipBCPLComment() {
278 ++CurPtr; // skip the second slash.
279 while (1) {
280 switch (*CurPtr) {
281 case '\n':
282 case '\r':
283 return; // Newline is end of comment.
284 case 0:
285 // If this is the end of the buffer, end the comment.
286 if (CurPtr == CurBuf->getBufferEnd())
287 return;
288 break;
289 }
290 // Otherwise, skip the character.
291 ++CurPtr;
292 }
293}
294
295/// SkipCComment - This skips C-style /**/ comments. The only difference from C
296/// is that we allow nesting.
297bool TGLexer::SkipCComment() {
298 ++CurPtr; // skip the star.
299 unsigned CommentDepth = 1;
300
301 while (1) {
302 int CurChar = getNextChar();
303 switch (CurChar) {
304 case EOF:
Chris Lattnerf4601652007-11-22 20:49:04 +0000305 PrintError(TokStart, "Unterminated comment!");
Chris Lattnera8058742007-11-18 02:57:27 +0000306 return true;
307 case '*':
308 // End of the comment?
309 if (CurPtr[0] != '/') break;
310
311 ++CurPtr; // End the */.
312 if (--CommentDepth == 0)
313 return false;
314 break;
315 case '/':
316 // Start of a nested comment?
317 if (CurPtr[0] != '*') break;
318 ++CurPtr;
319 ++CommentDepth;
320 break;
321 }
322 }
323}
324
325/// LexNumber - Lex:
326/// [-+]?[0-9]+
327/// 0x[0-9a-fA-F]+
328/// 0b[01]+
Chris Lattnerf4601652007-11-22 20:49:04 +0000329tgtok::TokKind TGLexer::LexNumber() {
Chris Lattnera8058742007-11-18 02:57:27 +0000330 if (CurPtr[-1] == '0') {
331 if (CurPtr[0] == 'x') {
332 ++CurPtr;
Chris Lattnerf4601652007-11-22 20:49:04 +0000333 const char *NumStart = CurPtr;
Chris Lattnera8058742007-11-18 02:57:27 +0000334 while (isxdigit(CurPtr[0]))
335 ++CurPtr;
336
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000337 // Requires at least one hex digit.
338 if (CurPtr == NumStart)
Chris Lattner4226bb02009-06-21 19:22:49 +0000339 return ReturnError(TokStart, "Invalid hexadecimal number");
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000340
Dan Gohman63f97202008-10-17 01:33:43 +0000341 errno = 0;
Chris Lattnerf4601652007-11-22 20:49:04 +0000342 CurIntVal = strtoll(NumStart, 0, 16);
Dan Gohman63f97202008-10-17 01:33:43 +0000343 if (errno == EINVAL)
Chris Lattner4226bb02009-06-21 19:22:49 +0000344 return ReturnError(TokStart, "Invalid hexadecimal number");
Dan Gohman63f97202008-10-17 01:33:43 +0000345 if (errno == ERANGE) {
346 errno = 0;
347 CurIntVal = (int64_t)strtoull(NumStart, 0, 16);
348 if (errno == EINVAL)
Chris Lattner4226bb02009-06-21 19:22:49 +0000349 return ReturnError(TokStart, "Invalid hexadecimal number");
Dan Gohman63f97202008-10-17 01:33:43 +0000350 if (errno == ERANGE)
Chris Lattner4226bb02009-06-21 19:22:49 +0000351 return ReturnError(TokStart, "Hexadecimal number out of range");
Dan Gohman63f97202008-10-17 01:33:43 +0000352 }
Chris Lattnerf4601652007-11-22 20:49:04 +0000353 return tgtok::IntVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000354 } else if (CurPtr[0] == 'b') {
355 ++CurPtr;
Chris Lattnerf4601652007-11-22 20:49:04 +0000356 const char *NumStart = CurPtr;
Chris Lattnera8058742007-11-18 02:57:27 +0000357 while (CurPtr[0] == '0' || CurPtr[0] == '1')
358 ++CurPtr;
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000359
360 // Requires at least one binary digit.
361 if (CurPtr == NumStart)
362 return ReturnError(CurPtr-2, "Invalid binary number");
Chris Lattnerf4601652007-11-22 20:49:04 +0000363 CurIntVal = strtoll(NumStart, 0, 2);
364 return tgtok::IntVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000365 }
366 }
367
368 // Check for a sign without a digit.
Chris Lattnerf4601652007-11-22 20:49:04 +0000369 if (!isdigit(CurPtr[0])) {
370 if (CurPtr[-1] == '-')
371 return tgtok::minus;
372 else if (CurPtr[-1] == '+')
373 return tgtok::plus;
Chris Lattnera8058742007-11-18 02:57:27 +0000374 }
375
376 while (isdigit(CurPtr[0]))
377 ++CurPtr;
Chris Lattnerf4601652007-11-22 20:49:04 +0000378 CurIntVal = strtoll(TokStart, 0, 10);
379 return tgtok::IntVal;
Chris Lattnera8058742007-11-18 02:57:27 +0000380}
381
382/// LexBracket - We just read '['. If this is a code block, return it,
383/// otherwise return the bracket. Match: '[' and '[{ ( [^}]+ | }[^]] )* }]'
Chris Lattnerf4601652007-11-22 20:49:04 +0000384tgtok::TokKind TGLexer::LexBracket() {
Chris Lattnera8058742007-11-18 02:57:27 +0000385 if (CurPtr[0] != '{')
Chris Lattnerf4601652007-11-22 20:49:04 +0000386 return tgtok::l_square;
Chris Lattnera8058742007-11-18 02:57:27 +0000387 ++CurPtr;
388 const char *CodeStart = CurPtr;
389 while (1) {
390 int Char = getNextChar();
391 if (Char == EOF) break;
392
393 if (Char != '}') continue;
394
395 Char = getNextChar();
396 if (Char == EOF) break;
397 if (Char == ']') {
Chris Lattnerf4601652007-11-22 20:49:04 +0000398 CurStrVal.assign(CodeStart, CurPtr-2);
399 return tgtok::CodeFragment;
Chris Lattnera8058742007-11-18 02:57:27 +0000400 }
401 }
402
Chris Lattnerc8a9bbc2007-11-19 07:38:58 +0000403 return ReturnError(CodeStart-2, "Unterminated Code Block");
Chris Lattnera8058742007-11-18 02:57:27 +0000404}
405
406/// LexExclaim - Lex '!' and '![a-zA-Z]+'.
Chris Lattnerf4601652007-11-22 20:49:04 +0000407tgtok::TokKind TGLexer::LexExclaim() {
Chris Lattnera8058742007-11-18 02:57:27 +0000408 if (!isalpha(*CurPtr))
Bill Wendlingdd2b6cb2010-12-08 13:03:15 +0000409 return ReturnError(CurPtr - 1, "Invalid \"!operator\"");
Chris Lattnera8058742007-11-18 02:57:27 +0000410
411 const char *Start = CurPtr++;
412 while (isalpha(*CurPtr))
413 ++CurPtr;
414
415 // Check to see which operator this is.
Bill Wendlingcd466f52010-12-08 20:02:49 +0000416 tgtok::TokKind Kind =
417 StringSwitch<tgtok::TokKind>(StringRef(Start, CurPtr - Start))
418 .Case("eq", tgtok::XEq)
419 .Case("if", tgtok::XIf)
David Greene1434f662011-01-07 17:05:37 +0000420 .Case("head", tgtok::XHead)
421 .Case("tail", tgtok::XTail)
Bill Wendlingcd466f52010-12-08 20:02:49 +0000422 .Case("con", tgtok::XConcat)
423 .Case("shl", tgtok::XSHL)
424 .Case("sra", tgtok::XSRA)
425 .Case("srl", tgtok::XSRL)
426 .Case("cast", tgtok::XCast)
David Greene1434f662011-01-07 17:05:37 +0000427 .Case("empty", tgtok::XEmpty)
Bill Wendlingcd466f52010-12-08 20:02:49 +0000428 .Case("subst", tgtok::XSubst)
429 .Case("foreach", tgtok::XForEach)
430 .Case("strconcat", tgtok::XStrConcat)
431 .Default(tgtok::Error);
David Greened418c1b2009-05-14 20:54:48 +0000432
Bill Wendlingcd466f52010-12-08 20:02:49 +0000433 return Kind != tgtok::Error ? Kind : ReturnError(Start-1, "Unknown operator");
Chris Lattnera8058742007-11-18 02:57:27 +0000434}
435