18 const LangOptions &LangOpts,
bool SkipComments) {
20 Token.setKind(tok::unknown);
21 Location = Location.getLocWithOffset(-1);
22 auto StartOfFile = SM.getLocForStartOfFile(SM.getFileID(Location));
23 while (Location != StartOfFile) {
24 Location = Lexer::GetBeginningOfToken(Location, SM, LangOpts);
25 if (!Lexer::getRawToken(Location, Token, SM, LangOpts) &&
26 (!SkipComments || !Token.is(tok::comment))) {
29 Location = Location.getLocWithOffset(-1);
35 const SourceManager &SM,
36 const LangOptions &LangOpts) {
37 if (Start.isInvalid() || Start.isMacroID())
38 return SourceLocation();
40 SourceLocation BeforeStart = Start.getLocWithOffset(-1);
41 if (BeforeStart.isInvalid() || BeforeStart.isMacroID())
42 return SourceLocation();
44 return Lexer::GetBeginningOfToken(BeforeStart, SM, LangOpts);
48 const SourceManager &SM,
49 const LangOptions &LangOpts,
53 if (L.isInvalid() || L.isMacroID())
54 return SourceLocation();
57 if (Lexer::getRawToken(L, T, SM, LangOpts,
true))
58 return SourceLocation();
61 return T.getLocation();
68 const LangOptions &LangOpts) {
73 const SourceManager &SM,
74 const LangOptions &LangOpts) {
75 assert(Range.isValid() &&
"Invalid Range for relexing provided");
76 SourceLocation
Loc = Range.getBegin();
78 while (Loc < Range.getEnd()) {
82 llvm::Optional<Token> Tok = Lexer::findNextToken(Loc, SM, LangOpts);
87 if (Tok->is(tok::hash))
90 Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts).getLocWithOffset(1);
97 const ASTContext &Context,
98 const SourceManager &SM) {
99 std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Range.getBegin());
100 StringRef File = SM.getBufferData(LocInfo.first);
101 Lexer RawLexer(SM.getLocForStartOfFile(LocInfo.first), Context.getLangOpts(),
102 File.begin(), File.data() + LocInfo.second, File.end());
103 llvm::Optional<Token> FirstConstTok;
104 Token LastTokInRange;
106 while (!RawLexer.LexFromRawLexer(Tok) &&
107 Range.getEnd() != Tok.getLocation() &&
108 !SM.isBeforeInTranslationUnit(Range.getEnd(), Tok.getLocation())) {
109 if (Tok.is(tok::raw_identifier)) {
110 IdentifierInfo &
Info = Context.Idents.get(
111 StringRef(SM.getCharacterData(Tok.getLocation()), Tok.getLength()));
112 Tok.setIdentifierInfo(&Info);
113 Tok.setKind(Info.getTokenID());
115 if (Tok.is(tok::kw_const) && !FirstConstTok)
117 LastTokInRange = Tok;
121 return LastTokInRange.is(tok::kw_const) ? LastTokInRange : FirstConstTok;
SourceLocation Loc
'#' location in the include directive
bool rangeContainsExpansionsOrDirectives(SourceRange Range, const SourceManager &SM, const LangOptions &LangOpts)
Re-lex the provide Range and return false if either a macro spans multiple tokens, a pre-processor directive or failure to retrieve the next token is found, otherwise true.
Token getPreviousToken(SourceLocation Location, const SourceManager &SM, const LangOptions &LangOpts, bool SkipComments)
Returns previous token or tok::unknown if not found.
SourceLocation findNextTerminator(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
SourceLocation findNextAnyTokenKind(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts, TokenKind TK, TokenKinds... TKs)
llvm::Optional< Token > getConstQualifyingToken(CharSourceRange Range, const ASTContext &Context, const SourceManager &SM)
Assuming that Range spans a const-qualified type, returns the const token in Range that is responsibl...
SourceLocation findPreviousTokenStart(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
CharSourceRange Range
SourceRange for the file name.
SourceLocation findPreviousTokenKind(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts, tok::TokenKind TK)