17 const LangOptions &LangOpts,
bool SkipComments) {
19 Token.setKind(tok::unknown);
21 Location = Location.getLocWithOffset(-1);
22 if (Location.isInvalid())
25 auto StartOfFile = SM.getLocForStartOfFile(SM.getFileID(Location));
26 while (Location != StartOfFile) {
27 Location = Lexer::GetBeginningOfToken(Location, SM, LangOpts);
28 if (!Lexer::getRawToken(Location, Token, SM, LangOpts) &&
29 (!SkipComments || !Token.is(tok::comment))) {
32 Location = Location.getLocWithOffset(-1);
38 const SourceManager &SM,
39 const LangOptions &LangOpts) {
40 if (Start.isInvalid() || Start.isMacroID())
41 return SourceLocation();
43 SourceLocation BeforeStart = Start.getLocWithOffset(-1);
44 if (BeforeStart.isInvalid() || BeforeStart.isMacroID())
45 return SourceLocation();
47 return Lexer::GetBeginningOfToken(BeforeStart, SM, LangOpts);
51 const SourceManager &SM,
52 const LangOptions &LangOpts,
54 if (Start.isInvalid() || Start.isMacroID())
55 return SourceLocation();
59 if (L.isInvalid() || L.isMacroID())
60 return SourceLocation();
63 if (Lexer::getRawToken(L, T, SM, LangOpts,
true))
64 return SourceLocation();
67 return T.getLocation();
74 const LangOptions &LangOpts) {
79 const SourceManager &SM,
80 const LangOptions &LangOpts) {
81 Optional<Token> CurrentToken;
83 CurrentToken = Lexer::findNextToken(Start, SM, LangOpts);
84 }
while (CurrentToken && CurrentToken->is(tok::comment));
89 const SourceManager &SM,
90 const LangOptions &LangOpts) {
91 assert(Range.isValid() &&
"Invalid Range for relexing provided");
92 SourceLocation
Loc = Range.getBegin();
94 while (Loc < Range.getEnd()) {
98 llvm::Optional<Token> Tok = Lexer::findNextToken(Loc, SM, LangOpts);
103 if (Tok->is(tok::hash))
106 Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts).getLocWithOffset(1);
113 CharSourceRange
Range,
114 const ASTContext &Context,
115 const SourceManager &SM) {
116 assert((TK == tok::kw_const || TK == tok::kw_volatile ||
117 TK == tok::kw_restrict) &&
118 "TK is not a qualifier keyword");
119 std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Range.getBegin());
120 StringRef File = SM.getBufferData(LocInfo.first);
121 Lexer RawLexer(SM.getLocForStartOfFile(LocInfo.first), Context.getLangOpts(),
122 File.begin(), File.data() + LocInfo.second, File.end());
123 llvm::Optional<Token> LastMatchBeforeTemplate;
124 llvm::Optional<Token> LastMatchAfterTemplate;
125 bool SawTemplate =
false;
127 while (!RawLexer.LexFromRawLexer(Tok) &&
128 Range.getEnd() != Tok.getLocation() &&
129 !SM.isBeforeInTranslationUnit(Range.getEnd(), Tok.getLocation())) {
130 if (Tok.is(tok::raw_identifier)) {
131 IdentifierInfo &
Info = Context.Idents.get(
132 StringRef(SM.getCharacterData(Tok.getLocation()), Tok.getLength()));
133 Tok.setIdentifierInfo(&Info);
134 Tok.setKind(Info.getTokenID());
136 if (Tok.is(tok::less))
138 else if (Tok.isOneOf(tok::greater, tok::greatergreater))
139 LastMatchAfterTemplate = None;
140 else if (Tok.is(TK)) {
142 LastMatchAfterTemplate = Tok;
144 LastMatchBeforeTemplate = Tok;
147 return LastMatchAfterTemplate != None ? LastMatchAfterTemplate
148 : LastMatchBeforeTemplate;
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)
Optional< Token > findNextTokenSkippingComments(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
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)
llvm::Optional< Token > getQualifyingToken(tok::TokenKind TK, CharSourceRange Range, const ASTContext &Context, const SourceManager &SM)
Assuming that Range spans a CVR-qualified type, returns the token in Range that is responsible for th...