1 //===- LLLexer.cpp - Lexer for .ll Files ----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Implement the Lexer for .ll files.
12 //===----------------------------------------------------------------------===//
15 #include "llvm/DerivedTypes.h"
16 #include "llvm/Instruction.h"
17 #include "llvm/LLVMContext.h"
18 #include "llvm/ADT/Twine.h"
19 #include "llvm/Assembly/Parser.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/MemoryBuffer.h"
22 #include "llvm/Support/MathExtras.h"
23 #include "llvm/Support/SourceMgr.h"
24 #include "llvm/Support/raw_ostream.h"
31 bool LLLexer::Error(LocTy ErrorLoc, const Twine &Msg) const {
32 ErrorInfo = SM.GetMessage(ErrorLoc, Msg, "error");
36 //===----------------------------------------------------------------------===//
38 //===----------------------------------------------------------------------===//
40 // atoull - Convert an ascii string of decimal digits into the unsigned long
41 // long representation... this does not have to do input error checking,
42 // because we know that the input will be matched by a suitable regex...
44 uint64_t LLLexer::atoull(const char *Buffer, const char *End) {
46 for (; Buffer != End; Buffer++) {
47 uint64_t OldRes = Result;
49 Result += *Buffer-'0';
50 if (Result < OldRes) { // Uh, oh, overflow detected!!!
51 Error("constant bigger than 64 bits detected!");
58 uint64_t LLLexer::HexIntToVal(const char *Buffer, const char *End) {
60 for (; Buffer != End; ++Buffer) {
61 uint64_t OldRes = Result;
64 if (C >= '0' && C <= '9')
66 else if (C >= 'A' && C <= 'F')
68 else if (C >= 'a' && C <= 'f')
71 if (Result < OldRes) { // Uh, oh, overflow detected!!!
72 Error("constant bigger than 64 bits detected!");
79 void LLLexer::HexToIntPair(const char *Buffer, const char *End,
82 for (int i=0; i<16; i++, Buffer++) {
83 assert(Buffer != End);
86 if (C >= '0' && C <= '9')
88 else if (C >= 'A' && C <= 'F')
90 else if (C >= 'a' && C <= 'f')
94 for (int i=0; i<16 && Buffer != End; i++, Buffer++) {
97 if (C >= '0' && C <= '9')
99 else if (C >= 'A' && C <= 'F')
101 else if (C >= 'a' && C <= 'f')
105 Error("constant bigger than 128 bits detected!");
108 /// FP80HexToIntPair - translate an 80 bit FP80 number (20 hexits) into
109 /// { low64, high16 } as usual for an APInt.
110 void LLLexer::FP80HexToIntPair(const char *Buffer, const char *End,
113 for (int i=0; i<4 && Buffer != End; i++, Buffer++) {
114 assert(Buffer != End);
117 if (C >= '0' && C <= '9')
119 else if (C >= 'A' && C <= 'F')
121 else if (C >= 'a' && C <= 'f')
125 for (int i=0; i<16; i++, Buffer++) {
128 if (C >= '0' && C <= '9')
130 else if (C >= 'A' && C <= 'F')
132 else if (C >= 'a' && C <= 'f')
136 Error("constant bigger than 128 bits detected!");
139 // UnEscapeLexed - Run through the specified buffer and change \xx codes to the
140 // appropriate character.
141 static void UnEscapeLexed(std::string &Str) {
142 if (Str.empty()) return;
144 char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
146 for (char *BIn = Buffer; BIn != EndBuffer; ) {
147 if (BIn[0] == '\\') {
148 if (BIn < EndBuffer-1 && BIn[1] == '\\') {
149 *BOut++ = '\\'; // Two \ becomes one
151 } else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
152 char Tmp = BIn[3]; BIn[3] = 0; // Terminate string
153 *BOut = (char)strtol(BIn+1, 0, 16); // Convert to number
154 BIn[3] = Tmp; // Restore character
155 BIn += 3; // Skip over handled chars
164 Str.resize(BOut-Buffer);
167 /// isLabelChar - Return true for [-a-zA-Z$._0-9].
168 static bool isLabelChar(char C) {
169 return isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_';
173 /// isLabelTail - Return true if this pointer points to a valid end of a label.
174 static const char *isLabelTail(const char *CurPtr) {
176 if (CurPtr[0] == ':') return CurPtr+1;
177 if (!isLabelChar(CurPtr[0])) return 0;
184 //===----------------------------------------------------------------------===//
186 //===----------------------------------------------------------------------===//
188 LLLexer::LLLexer(MemoryBuffer *StartBuf, SourceMgr &sm, SMDiagnostic &Err,
190 : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), Context(C), APFloatVal(0.0) {
191 CurPtr = CurBuf->getBufferStart();
194 std::string LLLexer::getFilename() const {
195 return CurBuf->getBufferIdentifier();
198 int LLLexer::getNextChar() {
199 char CurChar = *CurPtr++;
201 default: return (unsigned char)CurChar;
203 // A nul character in the stream is either the end of the current buffer or
204 // a random nul in the file. Disambiguate that here.
205 if (CurPtr-1 != CurBuf->getBufferEnd())
206 return 0; // Just whitespace.
208 // Otherwise, return end of file.
209 --CurPtr; // Another call to lex will return EOF again.
215 lltok::Kind LLLexer::LexToken() {
218 int CurChar = getNextChar();
221 // Handle letters: [a-zA-Z_]
222 if (isalpha(CurChar) || CurChar == '_')
223 return LexIdentifier();
226 case EOF: return lltok::Eof;
232 // Ignore whitespace.
234 case '+': return LexPositive();
235 case '@': return LexAt();
236 case '%': return LexPercent();
237 case '"': return LexQuote();
239 if (const char *Ptr = isLabelTail(CurPtr)) {
241 StrVal.assign(TokStart, CurPtr-1);
242 return lltok::LabelStr;
244 if (CurPtr[0] == '.' && CurPtr[1] == '.') {
246 return lltok::dotdotdot;
250 if (const char *Ptr = isLabelTail(CurPtr)) {
252 StrVal.assign(TokStart, CurPtr-1);
253 return lltok::LabelStr;
259 case '!': return LexExclaim();
260 case '0': case '1': case '2': case '3': case '4':
261 case '5': case '6': case '7': case '8': case '9':
263 return LexDigitOrNegative();
264 case '=': return lltok::equal;
265 case '[': return lltok::lsquare;
266 case ']': return lltok::rsquare;
267 case '{': return lltok::lbrace;
268 case '}': return lltok::rbrace;
269 case '<': return lltok::less;
270 case '>': return lltok::greater;
271 case '(': return lltok::lparen;
272 case ')': return lltok::rparen;
273 case ',': return lltok::comma;
274 case '*': return lltok::star;
275 case '\\': return lltok::backslash;
279 void LLLexer::SkipLineComment() {
281 if (CurPtr[0] == '\n' || CurPtr[0] == '\r' || getNextChar() == EOF)
286 /// LexAt - Lex all tokens that start with an @ character:
287 /// GlobalVar @\"[^\"]*\"
288 /// GlobalVar @[-a-zA-Z$._][-a-zA-Z$._0-9]*
289 /// GlobalVarID @[0-9]+
290 lltok::Kind LLLexer::LexAt() {
291 // Handle AtStringConstant: @\"[^\"]*\"
292 if (CurPtr[0] == '"') {
296 int CurChar = getNextChar();
298 if (CurChar == EOF) {
299 Error("end of file in global variable name");
302 if (CurChar == '"') {
303 StrVal.assign(TokStart+2, CurPtr-1);
304 UnEscapeLexed(StrVal);
305 return lltok::GlobalVar;
310 // Handle GlobalVarName: @[-a-zA-Z$._][-a-zA-Z$._0-9]*
312 return lltok::GlobalVar;
314 // Handle GlobalVarID: @[0-9]+
315 if (isdigit(CurPtr[0])) {
316 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
319 uint64_t Val = atoull(TokStart+1, CurPtr);
320 if ((unsigned)Val != Val)
321 Error("invalid value number (too large)!");
322 UIntVal = unsigned(Val);
323 return lltok::GlobalID;
329 /// ReadString - Read a string until the closing quote.
330 lltok::Kind LLLexer::ReadString(lltok::Kind kind) {
331 const char *Start = CurPtr;
333 int CurChar = getNextChar();
335 if (CurChar == EOF) {
336 Error("end of file in string constant");
339 if (CurChar == '"') {
340 StrVal.assign(Start, CurPtr-1);
341 UnEscapeLexed(StrVal);
347 /// ReadVarName - Read the rest of a token containing a variable name.
348 bool LLLexer::ReadVarName() {
349 const char *NameStart = CurPtr;
350 if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
351 CurPtr[0] == '.' || CurPtr[0] == '_') {
353 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
354 CurPtr[0] == '.' || CurPtr[0] == '_')
357 StrVal.assign(NameStart, CurPtr);
363 /// LexPercent - Lex all tokens that start with a % character:
364 /// LocalVar ::= %\"[^\"]*\"
365 /// LocalVar ::= %[-a-zA-Z$._][-a-zA-Z$._0-9]*
366 /// LocalVarID ::= %[0-9]+
367 lltok::Kind LLLexer::LexPercent() {
368 // Handle LocalVarName: %\"[^\"]*\"
369 if (CurPtr[0] == '"') {
371 return ReadString(lltok::LocalVar);
374 // Handle LocalVarName: %[-a-zA-Z$._][-a-zA-Z$._0-9]*
376 return lltok::LocalVar;
378 // Handle LocalVarID: %[0-9]+
379 if (isdigit(CurPtr[0])) {
380 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
383 uint64_t Val = atoull(TokStart+1, CurPtr);
384 if ((unsigned)Val != Val)
385 Error("invalid value number (too large)!");
386 UIntVal = unsigned(Val);
387 return lltok::LocalVarID;
393 /// LexQuote - Lex all tokens that start with a " character:
394 /// QuoteLabel "[^"]+":
395 /// StringConstant "[^"]*"
396 lltok::Kind LLLexer::LexQuote() {
397 lltok::Kind kind = ReadString(lltok::StringConstant);
398 if (kind == lltok::Error || kind == lltok::Eof)
401 if (CurPtr[0] == ':') {
403 kind = lltok::LabelStr;
412 lltok::Kind LLLexer::LexExclaim() {
413 // Lex a metadata name as a MetadataVar.
414 if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
415 CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\') {
417 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
418 CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\')
421 StrVal.assign(TokStart+1, CurPtr); // Skip !
422 UnEscapeLexed(StrVal);
423 return lltok::MetadataVar;
425 return lltok::exclaim;
428 /// LexIdentifier: Handle several related productions:
429 /// Label [-a-zA-Z$._0-9]+:
430 /// IntegerType i[0-9]+
431 /// Keyword sdiv, float, ...
432 /// HexIntConstant [us]0x[0-9A-Fa-f]+
433 lltok::Kind LLLexer::LexIdentifier() {
434 const char *StartChar = CurPtr;
435 const char *IntEnd = CurPtr[-1] == 'i' ? 0 : StartChar;
436 const char *KeywordEnd = 0;
438 for (; isLabelChar(*CurPtr); ++CurPtr) {
439 // If we decide this is an integer, remember the end of the sequence.
440 if (!IntEnd && !isdigit(*CurPtr)) IntEnd = CurPtr;
441 if (!KeywordEnd && !isalnum(*CurPtr) && *CurPtr != '_') KeywordEnd = CurPtr;
444 // If we stopped due to a colon, this really is a label.
445 if (*CurPtr == ':') {
446 StrVal.assign(StartChar-1, CurPtr++);
447 return lltok::LabelStr;
450 // Otherwise, this wasn't a label. If this was valid as an integer type,
452 if (IntEnd == 0) IntEnd = CurPtr;
453 if (IntEnd != StartChar) {
455 uint64_t NumBits = atoull(StartChar, CurPtr);
456 if (NumBits < IntegerType::MIN_INT_BITS ||
457 NumBits > IntegerType::MAX_INT_BITS) {
458 Error("bitwidth for integer type out of range!");
461 TyVal = IntegerType::get(Context, NumBits);
465 // Otherwise, this was a letter sequence. See which keyword this is.
466 if (KeywordEnd == 0) KeywordEnd = CurPtr;
469 unsigned Len = CurPtr-StartChar;
470 #define KEYWORD(STR) \
471 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) \
472 return lltok::kw_##STR;
474 KEYWORD(true); KEYWORD(false);
475 KEYWORD(declare); KEYWORD(define);
476 KEYWORD(global); KEYWORD(constant);
479 KEYWORD(linker_private);
480 KEYWORD(linker_private_weak);
481 KEYWORD(linker_private_weak_def_auto);
483 KEYWORD(available_externally);
485 KEYWORD(linkonce_odr);
495 KEYWORD(unnamed_addr);
496 KEYWORD(extern_weak);
498 KEYWORD(thread_local);
499 KEYWORD(zeroinitializer);
516 KEYWORD(singlethread);
535 KEYWORD(x86_stdcallcc);
536 KEYWORD(x86_fastcallcc);
537 KEYWORD(x86_thiscallcc);
539 KEYWORD(arm_aapcscc);
540 KEYWORD(arm_aapcs_vfpcc);
541 KEYWORD(msp430_intrcc);
564 KEYWORD(alwaysinline);
569 KEYWORD(noimplicitfloat);
572 KEYWORD(nonlazybind);
577 KEYWORD(eq); KEYWORD(ne); KEYWORD(slt); KEYWORD(sgt); KEYWORD(sle);
578 KEYWORD(sge); KEYWORD(ult); KEYWORD(ugt); KEYWORD(ule); KEYWORD(uge);
579 KEYWORD(oeq); KEYWORD(one); KEYWORD(olt); KEYWORD(ogt); KEYWORD(ole);
580 KEYWORD(oge); KEYWORD(ord); KEYWORD(uno); KEYWORD(ueq); KEYWORD(une);
582 KEYWORD(xchg); KEYWORD(nand); KEYWORD(max); KEYWORD(min); KEYWORD(umax);
586 KEYWORD(blockaddress);
588 KEYWORD(personality);
594 // Keywords for types.
595 #define TYPEKEYWORD(STR, LLVMTY) \
596 if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
597 TyVal = LLVMTY; return lltok::Type; }
598 TYPEKEYWORD("void", Type::getVoidTy(Context));
599 TYPEKEYWORD("float", Type::getFloatTy(Context));
600 TYPEKEYWORD("double", Type::getDoubleTy(Context));
601 TYPEKEYWORD("x86_fp80", Type::getX86_FP80Ty(Context));
602 TYPEKEYWORD("fp128", Type::getFP128Ty(Context));
603 TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context));
604 TYPEKEYWORD("label", Type::getLabelTy(Context));
605 TYPEKEYWORD("metadata", Type::getMetadataTy(Context));
606 TYPEKEYWORD("x86_mmx", Type::getX86_MMXTy(Context));
609 // Keywords for instructions.
610 #define INSTKEYWORD(STR, Enum) \
611 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \
612 UIntVal = Instruction::Enum; return lltok::kw_##STR; }
614 INSTKEYWORD(add, Add); INSTKEYWORD(fadd, FAdd);
615 INSTKEYWORD(sub, Sub); INSTKEYWORD(fsub, FSub);
616 INSTKEYWORD(mul, Mul); INSTKEYWORD(fmul, FMul);
617 INSTKEYWORD(udiv, UDiv); INSTKEYWORD(sdiv, SDiv); INSTKEYWORD(fdiv, FDiv);
618 INSTKEYWORD(urem, URem); INSTKEYWORD(srem, SRem); INSTKEYWORD(frem, FRem);
619 INSTKEYWORD(shl, Shl); INSTKEYWORD(lshr, LShr); INSTKEYWORD(ashr, AShr);
620 INSTKEYWORD(and, And); INSTKEYWORD(or, Or); INSTKEYWORD(xor, Xor);
621 INSTKEYWORD(icmp, ICmp); INSTKEYWORD(fcmp, FCmp);
623 INSTKEYWORD(phi, PHI);
624 INSTKEYWORD(call, Call);
625 INSTKEYWORD(trunc, Trunc);
626 INSTKEYWORD(zext, ZExt);
627 INSTKEYWORD(sext, SExt);
628 INSTKEYWORD(fptrunc, FPTrunc);
629 INSTKEYWORD(fpext, FPExt);
630 INSTKEYWORD(uitofp, UIToFP);
631 INSTKEYWORD(sitofp, SIToFP);
632 INSTKEYWORD(fptoui, FPToUI);
633 INSTKEYWORD(fptosi, FPToSI);
634 INSTKEYWORD(inttoptr, IntToPtr);
635 INSTKEYWORD(ptrtoint, PtrToInt);
636 INSTKEYWORD(bitcast, BitCast);
637 INSTKEYWORD(select, Select);
638 INSTKEYWORD(va_arg, VAArg);
639 INSTKEYWORD(ret, Ret);
641 INSTKEYWORD(switch, Switch);
642 INSTKEYWORD(indirectbr, IndirectBr);
643 INSTKEYWORD(invoke, Invoke);
644 INSTKEYWORD(resume, Resume);
645 INSTKEYWORD(unwind, Unwind);
646 INSTKEYWORD(unreachable, Unreachable);
648 INSTKEYWORD(alloca, Alloca);
649 INSTKEYWORD(load, Load);
650 INSTKEYWORD(store, Store);
651 INSTKEYWORD(cmpxchg, AtomicCmpXchg);
652 INSTKEYWORD(atomicrmw, AtomicRMW);
653 INSTKEYWORD(fence, Fence);
654 INSTKEYWORD(getelementptr, GetElementPtr);
656 INSTKEYWORD(extractelement, ExtractElement);
657 INSTKEYWORD(insertelement, InsertElement);
658 INSTKEYWORD(shufflevector, ShuffleVector);
659 INSTKEYWORD(extractvalue, ExtractValue);
660 INSTKEYWORD(insertvalue, InsertValue);
661 INSTKEYWORD(landingpad, LandingPad);
664 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
665 // the CFE to avoid forcing it to deal with 64-bit numbers.
666 if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
667 TokStart[1] == '0' && TokStart[2] == 'x' && isxdigit(TokStart[3])) {
668 int len = CurPtr-TokStart-3;
669 uint32_t bits = len * 4;
670 APInt Tmp(bits, StringRef(TokStart+3, len), 16);
671 uint32_t activeBits = Tmp.getActiveBits();
672 if (activeBits > 0 && activeBits < bits)
673 Tmp = Tmp.trunc(activeBits);
674 APSIntVal = APSInt(Tmp, TokStart[0] == 'u');
675 return lltok::APSInt;
678 // If this is "cc1234", return this as just "cc".
679 if (TokStart[0] == 'c' && TokStart[1] == 'c') {
684 // Finally, if this isn't known, return an error.
690 /// Lex0x: Handle productions that start with 0x, knowing that it matches and
691 /// that this is not a label:
692 /// HexFPConstant 0x[0-9A-Fa-f]+
693 /// HexFP80Constant 0xK[0-9A-Fa-f]+
694 /// HexFP128Constant 0xL[0-9A-Fa-f]+
695 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
696 lltok::Kind LLLexer::Lex0x() {
697 CurPtr = TokStart + 2;
700 if (CurPtr[0] >= 'K' && CurPtr[0] <= 'M') {
706 if (!isxdigit(CurPtr[0])) {
707 // Bad token, return it as an error.
712 while (isxdigit(CurPtr[0]))
716 // HexFPConstant - Floating point constant represented in IEEE format as a
717 // hexadecimal number for when exponential notation is not precise enough.
718 // Float and double only.
719 APFloatVal = APFloat(BitsToDouble(HexIntToVal(TokStart+2, CurPtr)));
720 return lltok::APFloat;
725 default: llvm_unreachable("Unknown kind!");
727 // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
728 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
729 APFloatVal = APFloat(APInt(80, Pair));
730 return lltok::APFloat;
732 // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
733 HexToIntPair(TokStart+3, CurPtr, Pair);
734 APFloatVal = APFloat(APInt(128, Pair), true);
735 return lltok::APFloat;
737 // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
738 HexToIntPair(TokStart+3, CurPtr, Pair);
739 APFloatVal = APFloat(APInt(128, Pair));
740 return lltok::APFloat;
744 /// LexIdentifier: Handle several related productions:
745 /// Label [-a-zA-Z$._0-9]+:
747 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
749 /// HexFPConstant 0x[0-9A-Fa-f]+
750 /// HexFP80Constant 0xK[0-9A-Fa-f]+
751 /// HexFP128Constant 0xL[0-9A-Fa-f]+
752 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
753 lltok::Kind LLLexer::LexDigitOrNegative() {
754 // If the letter after the negative is a number, this is probably a label.
755 if (!isdigit(TokStart[0]) && !isdigit(CurPtr[0])) {
756 // Okay, this is not a number after the -, it's probably a label.
757 if (const char *End = isLabelTail(CurPtr)) {
758 StrVal.assign(TokStart, End-1);
760 return lltok::LabelStr;
766 // At this point, it is either a label, int or fp constant.
768 // Skip digits, we have at least one.
769 for (; isdigit(CurPtr[0]); ++CurPtr)
772 // Check to see if this really is a label afterall, e.g. "-1:".
773 if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
774 if (const char *End = isLabelTail(CurPtr)) {
775 StrVal.assign(TokStart, End-1);
777 return lltok::LabelStr;
781 // If the next character is a '.', then it is a fp value, otherwise its
783 if (CurPtr[0] != '.') {
784 if (TokStart[0] == '0' && TokStart[1] == 'x')
786 unsigned Len = CurPtr-TokStart;
787 uint32_t numBits = ((Len * 64) / 19) + 2;
788 APInt Tmp(numBits, StringRef(TokStart, Len), 10);
789 if (TokStart[0] == '-') {
790 uint32_t minBits = Tmp.getMinSignedBits();
791 if (minBits > 0 && minBits < numBits)
792 Tmp = Tmp.trunc(minBits);
793 APSIntVal = APSInt(Tmp, false);
795 uint32_t activeBits = Tmp.getActiveBits();
796 if (activeBits > 0 && activeBits < numBits)
797 Tmp = Tmp.trunc(activeBits);
798 APSIntVal = APSInt(Tmp, true);
800 return lltok::APSInt;
805 // Skip over [0-9]*([eE][-+]?[0-9]+)?
806 while (isdigit(CurPtr[0])) ++CurPtr;
808 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
809 if (isdigit(CurPtr[1]) ||
810 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
812 while (isdigit(CurPtr[0])) ++CurPtr;
816 APFloatVal = APFloat(std::atof(TokStart));
817 return lltok::APFloat;
820 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
821 lltok::Kind LLLexer::LexPositive() {
822 // If the letter after the negative is a number, this is probably not a
824 if (!isdigit(CurPtr[0]))
828 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
831 // At this point, we need a '.'.
832 if (CurPtr[0] != '.') {
839 // Skip over [0-9]*([eE][-+]?[0-9]+)?
840 while (isdigit(CurPtr[0])) ++CurPtr;
842 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
843 if (isdigit(CurPtr[1]) ||
844 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
846 while (isdigit(CurPtr[0])) ++CurPtr;
850 APFloatVal = APFloat(std::atof(TokStart));
851 return lltok::APFloat;