17 const LangOptions &LangOpts,
bool SkipComments) {
19 Token.setKind(tok::unknown);
20 Location = Location.getLocWithOffset(-1);
21 auto StartOfFile = SM.getLocForStartOfFile(SM.getFileID(Location));
22 while (Location != StartOfFile) {
23 Location = Lexer::GetBeginningOfToken(Location, SM, LangOpts);
24 if (!Lexer::getRawToken(Location, Token, SM, LangOpts) &&
25 (!SkipComments || !Token.is(tok::comment))) {
28 Location = Location.getLocWithOffset(-1);
34 const SourceManager &SM,
35 const LangOptions &LangOpts) {
36 if (Start.isInvalid() || Start.isMacroID())
37 return SourceLocation();
39 SourceLocation BeforeStart = Start.getLocWithOffset(-1);
40 if (BeforeStart.isInvalid() || BeforeStart.isMacroID())
41 return SourceLocation();
43 return Lexer::GetBeginningOfToken(BeforeStart, SM, LangOpts);
47 const SourceManager &SM,
48 const LangOptions &LangOpts,
52 if (L.isInvalid() || L.isMacroID())
53 return SourceLocation();
56 if (Lexer::getRawToken(L, T, SM, LangOpts,
true))
57 return SourceLocation();
60 return T.getLocation();
67 const LangOptions &LangOpts) {
72 const SourceManager &SM,
73 const LangOptions &LangOpts) {
74 assert(Range.isValid() &&
"Invalid Range for relexing provided");
75 SourceLocation
Loc = Range.getBegin();
77 while (Loc < Range.getEnd()) {
81 llvm::Optional<Token> Tok = Lexer::findNextToken(Loc, SM, LangOpts);
86 if (Tok->is(tok::hash))
89 Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts).getLocWithOffset(1);
96 const ASTContext &Context,
97 const SourceManager &SM) {
98 std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Range.getBegin());
99 StringRef File = SM.getBufferData(LocInfo.first);
100 Lexer RawLexer(SM.getLocForStartOfFile(LocInfo.first), Context.getLangOpts(),
101 File.begin(), File.data() + LocInfo.second, File.end());
102 llvm::Optional<Token> FirstConstTok;
103 Token LastTokInRange;
105 while (!RawLexer.LexFromRawLexer(Tok) &&
106 Range.getEnd() != Tok.getLocation() &&
107 !SM.isBeforeInTranslationUnit(Range.getEnd(), Tok.getLocation())) {
108 if (Tok.is(tok::raw_identifier)) {
109 IdentifierInfo &
Info = Context.Idents.get(
110 StringRef(SM.getCharacterData(Tok.getLocation()), Tok.getLength()));
111 Tok.setIdentifierInfo(&Info);
112 Tok.setKind(Info.getTokenID());
114 if (Tok.is(tok::kw_const) && !FirstConstTok)
116 LastTokInRange = Tok;
120 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)