static SourceLocation findSemiAfterLocation()

in legacy/objc/src/XPFlagRefactoring/XPFlagRefactoring.cpp [82:118]


  static SourceLocation findSemiAfterLocation(SourceLocation loc,
                                              ASTContext &Ctx, bool IsDecl) {
    SourceManager &SM = Ctx.getSourceManager();
    if (loc.isMacroID()) {
      if (!Lexer::isAtEndOfMacroExpansion(loc, SM, Ctx.getLangOpts(), &loc))
        return SourceLocation();
    }

    loc = Lexer::getLocForEndOfToken(loc, 0, SM, Ctx.getLangOpts());

    // Break down the source location.
    std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(loc);

    // Try to load the file buffer.
    bool invalidTemp = false;
    StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
    if (invalidTemp) {
      return SourceLocation();
    }
    const char *tokenBegin = file.data() + locInfo.second;

    // Lex from the start of the given location.
    Lexer lexer(SM.getLocForStartOfFile(locInfo.first), Ctx.getLangOpts(),
                file.begin(), tokenBegin, file.end());
    Token tok;
    lexer.LexFromRawLexer(tok);

    if (tok.isNot(tok::semi)) {
      if (!IsDecl)
        return SourceLocation();
      // Declaration may be followed with other tokens; such as an __attribute,
      // before ending with a semicolon.
      return findSemiAfterLocation(tok.getLocation(), Ctx, true);
    }

    return tok.getLocation();
  }