diff options
Diffstat (limited to 'lib/TableGen/TGLexer.cpp')
| -rw-r--r-- | lib/TableGen/TGLexer.cpp | 60 | 
1 files changed, 35 insertions, 25 deletions
diff --git a/lib/TableGen/TGLexer.cpp b/lib/TableGen/TGLexer.cpp index 5d6f7c23e0b6..652be6e8dbbf 100644 --- a/lib/TableGen/TGLexer.cpp +++ b/lib/TableGen/TGLexer.cpp @@ -56,7 +56,7 @@ int TGLexer::getNextChar() {      // a random nul in the file.  Disambiguate that here.      if (CurPtr-1 != CurBuf.end())        return 0;  // Just whitespace. -     +      // If this is the end of an included file, pop the parent file off the      // include stack.      SMLoc ParentIncludeLoc = SrcMgr.getParentIncludeLoc(CurBuffer); @@ -66,9 +66,9 @@ int TGLexer::getNextChar() {        CurPtr = ParentIncludeLoc.getPointer();        return getNextChar();      } -     +      // Otherwise, return end of file. -    --CurPtr;  // Another call to lex will return EOF again.   +    --CurPtr;  // Another call to lex will return EOF again.      return EOF;    }    case '\n': @@ -80,7 +80,7 @@ int TGLexer::getNextChar() {          *CurPtr != CurChar)        ++CurPtr;  // Eat the two char newline sequence.      return '\n'; -  }   +  }  }  int TGLexer::peekNextChar(int Index) { @@ -115,7 +115,7 @@ tgtok::TokKind TGLexer::LexToken() {    case '=': return tgtok::equal;    case '?': return tgtok::question;    case '#': return tgtok::paste; -       +    case 0:    case ' ':    case '\t': @@ -154,7 +154,7 @@ tgtok::TokKind TGLexer::LexToken() {          switch (NextNextChar) {          default:            break; -        case '0': case '1':  +        case '0': case '1':            if (NextChar == 'b')              return LexNumber();            LLVM_FALLTHROUGH; @@ -184,24 +184,24 @@ tgtok::TokKind TGLexer::LexToken() {  /// LexString - Lex "[^"]*"  tgtok::TokKind TGLexer::LexString() {    const char *StrStart = CurPtr; -   +    CurStrVal = ""; -   +    while (*CurPtr != '"') {      // If we hit the end of the buffer, report an error.      if (*CurPtr == 0 && CurPtr == CurBuf.end())        return ReturnError(StrStart, "End of file in string literal"); -     +      if (*CurPtr == '\n' || *CurPtr == '\r')        return ReturnError(StrStart, "End of line in string literal"); -     +      if (*CurPtr != '\\') {        CurStrVal += *CurPtr++;        continue;      }      ++CurPtr; -     +      switch (*CurPtr) {      case '\\': case '\'': case '"':        // These turn into their literal character. @@ -215,7 +215,7 @@ tgtok::TokKind TGLexer::LexString() {        CurStrVal += '\n';        ++CurPtr;        break; -         +      case '\n':      case '\r':        return ReturnError(CurPtr, "escaped newlines not supported in tblgen"); @@ -229,7 +229,7 @@ tgtok::TokKind TGLexer::LexString() {        return ReturnError(CurPtr, "invalid escape in string literal");      }    } -   +    ++CurPtr;    return tgtok::StrVal;  } @@ -237,10 +237,10 @@ tgtok::TokKind TGLexer::LexString() {  tgtok::TokKind TGLexer::LexVarName() {    if (!isalpha(CurPtr[0]) && CurPtr[0] != '_')      return ReturnError(TokStart, "Invalid variable name"); -   +    // Otherwise, we're ok, consume the rest of the characters.    const char *VarNameStart = CurPtr++; -   +    while (isalpha(*CurPtr) || isdigit(*CurPtr) || *CurPtr == '_')      ++CurPtr; @@ -276,6 +276,7 @@ tgtok::TokKind TGLexer::LexIdentifier() {      .Case("def", tgtok::Def)      .Case("foreach", tgtok::Foreach)      .Case("defm", tgtok::Defm) +    .Case("defset", tgtok::Defset)      .Case("multiclass", tgtok::MultiClass)      .Case("field", tgtok::Field)      .Case("let", tgtok::Let) @@ -308,7 +309,7 @@ bool TGLexer::LexInclude() {      PrintError(getLoc(), "Could not find include file '" + Filename + "'");      return true;    } -   +    DependenciesMapTy::const_iterator Found = Dependencies.find(IncludedFile);    if (Found != Dependencies.end()) {      PrintError(getLoc(), @@ -347,7 +348,7 @@ void TGLexer::SkipBCPLComment() {  bool TGLexer::SkipCComment() {    ++CurPtr;  // skip the star.    unsigned CommentDepth = 1; -   +    while (true) {      int CurChar = getNextChar();      switch (CurChar) { @@ -357,7 +358,7 @@ bool TGLexer::SkipCComment() {      case '*':        // End of the comment?        if (CurPtr[0] != '/') break; -       +        ++CurPtr;   // End the */.        if (--CommentDepth == 0)          return false; @@ -383,7 +384,7 @@ tgtok::TokKind TGLexer::LexNumber() {        const char *NumStart = CurPtr;        while (isxdigit(CurPtr[0]))          ++CurPtr; -       +        // Requires at least one hex digit.        if (CurPtr == NumStart)          return ReturnError(TokStart, "Invalid hexadecimal number"); @@ -422,7 +423,7 @@ tgtok::TokKind TGLexer::LexNumber() {      else if (CurPtr[-1] == '+')        return tgtok::plus;    } -   +    while (isdigit(CurPtr[0]))      ++CurPtr;    CurIntVal = strtoll(TokStart, nullptr, 10); @@ -439,9 +440,9 @@ tgtok::TokKind TGLexer::LexBracket() {    while (true) {      int Char = getNextChar();      if (Char == EOF) break; -     +      if (Char != '}') continue; -     +      Char = getNextChar();      if (Char == EOF) break;      if (Char == ']') { @@ -449,7 +450,7 @@ tgtok::TokKind TGLexer::LexBracket() {        return tgtok::CodeFragment;      }    } -   +    return ReturnError(CodeStart-2, "Unterminated Code Block");  } @@ -457,19 +458,27 @@ tgtok::TokKind TGLexer::LexBracket() {  tgtok::TokKind TGLexer::LexExclaim() {    if (!isalpha(*CurPtr))      return ReturnError(CurPtr - 1, "Invalid \"!operator\""); -   +    const char *Start = CurPtr++;    while (isalpha(*CurPtr))      ++CurPtr; -   +    // Check to see which operator this is.    tgtok::TokKind Kind =      StringSwitch<tgtok::TokKind>(StringRef(Start, CurPtr - Start))      .Case("eq", tgtok::XEq) +    .Case("ne", tgtok::XNe) +    .Case("le", tgtok::XLe) +    .Case("lt", tgtok::XLt) +    .Case("ge", tgtok::XGe) +    .Case("gt", tgtok::XGt)      .Case("if", tgtok::XIf) +    .Case("isa", tgtok::XIsA)      .Case("head", tgtok::XHead)      .Case("tail", tgtok::XTail) +    .Case("size", tgtok::XSize)      .Case("con", tgtok::XConcat) +    .Case("dag", tgtok::XDag)      .Case("add", tgtok::XADD)      .Case("and", tgtok::XAND)      .Case("or", tgtok::XOR) @@ -479,6 +488,7 @@ tgtok::TokKind TGLexer::LexExclaim() {      .Case("cast", tgtok::XCast)      .Case("empty", tgtok::XEmpty)      .Case("subst", tgtok::XSubst) +    .Case("foldl", tgtok::XFoldl)      .Case("foreach", tgtok::XForEach)      .Case("listconcat", tgtok::XListConcat)      .Case("strconcat", tgtok::XStrConcat)  | 
