Ejemplo n.º 1
0
// Re-lex the tokens to get precise locations to insert 'override' and remove
// 'virtual'.
static SmallVector<Token, 16>
ParseTokens(CharSourceRange Range, const MatchFinder::MatchResult &Result) {
  const SourceManager &Sources = *Result.SourceManager;
  std::pair<FileID, unsigned> LocInfo =
      Sources.getDecomposedLoc(Range.getBegin());
  StringRef File = Sources.getBufferData(LocInfo.first);
  const char *TokenBegin = File.data() + LocInfo.second;
  Lexer RawLexer(Sources.getLocForStartOfFile(LocInfo.first),
                 Result.Context->getLangOpts(), File.begin(), TokenBegin,
                 File.end());
  SmallVector<Token, 16> Tokens;
  Token Tok;
  while (!RawLexer.LexFromRawLexer(Tok)) {
    if (Tok.is(tok::semi) || Tok.is(tok::l_brace))
      break;
    if (Sources.isBeforeInTranslationUnit(Range.getEnd(), Tok.getLocation()))
      break;
    if (Tok.is(tok::raw_identifier)) {
      IdentifierInfo &Info = Result.Context->Idents.get(StringRef(
          Sources.getCharacterData(Tok.getLocation()), Tok.getLength()));
      Tok.setIdentifierInfo(&Info);
      Tok.setKind(Info.getTokenID());
    }
    Tokens.push_back(Tok);
  }
  return Tokens;
}
Ejemplo n.º 2
0
// Re-lex the tokens to get precise locations to insert 'override' and remove
// 'virtual'.
static SmallVector<Token, 16> ParseTokens(CharSourceRange Range,
                                          const SourceManager &Sources,
                                          LangOptions LangOpts) {
  std::pair<FileID, unsigned> LocInfo =
      Sources.getDecomposedLoc(Range.getBegin());
  StringRef File = Sources.getBufferData(LocInfo.first);
  const char *TokenBegin = File.data() + LocInfo.second;
  Lexer RawLexer(Sources.getLocForStartOfFile(LocInfo.first), LangOpts,
                 File.begin(), TokenBegin, File.end());
  SmallVector<Token, 16> Tokens;
  Token Tok;
  while (!RawLexer.LexFromRawLexer(Tok)) {
    if (Tok.is(tok::semi) || Tok.is(tok::l_brace))
      break;
    if (Sources.isBeforeInTranslationUnit(Range.getEnd(), Tok.getLocation()))
      break;
    Tokens.push_back(Tok);
  }
  return Tokens;
}
Ejemplo n.º 3
0
  InputValidator::Result
  InputValidator::Validate(llvm::StringRef input_line, LangOptions& LO) {
    if (!m_Input.empty())
      m_Input.append("\n");
    else
      m_Input = "";

    m_Input.append(input_line);

    llvm::MemoryBuffer* MB = llvm::MemoryBuffer::getMemBuffer(input_line);
    Lexer RawLexer(SourceLocation(), LO, MB->getBufferStart(),
                   MB->getBufferStart(), MB->getBufferEnd());
    Token Tok;
    do {
      RawLexer.LexFromRawLexer(Tok);
      int kind = (int)Tok.getKind();
      if (kind >= (int)tok::l_square
          && kind <= (int)tok::r_brace) {
        kind -= (int)tok::l_square;
        if (kind % 2) {
          // closing the right one?
          if (m_ParenStack.empty()) return kMismatch;
          int prev = m_ParenStack.top();
          if (prev != kind - 1) return kMismatch;
          m_ParenStack.pop();
        } else {
          m_ParenStack.push(kind);
        }
      }
    }
    while (Tok.isNot(tok::eof));
    if (!m_ParenStack.empty()) 
      return kIncomplete;

    return kComplete;
  }