clang 22.0.0git
SourceCode.cpp
Go to the documentation of this file.
1//===--- SourceCode.cpp - Source code manipulation routines -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides functions that simplify extraction of source code.
10//
11//===----------------------------------------------------------------------===//
14#include "clang/AST/Attr.h"
15#include "clang/AST/Comment.h"
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclCXX.h"
19#include "clang/AST/Expr.h"
21#include "clang/Lex/Lexer.h"
22#include "llvm/Support/Errc.h"
23#include "llvm/Support/Error.h"
24#include <set>
25
26using namespace clang;
27
28using llvm::errc;
29using llvm::StringError;
30
32 const ASTContext &Context) {
33 return Lexer::getSourceText(Range, Context.getSourceManager(),
34 Context.getLangOpts());
35}
36
39 ASTContext &Context) {
40 CharSourceRange R = Lexer::getAsCharRange(Range, Context.getSourceManager(),
41 Context.getLangOpts());
42 if (R.isInvalid())
43 return Range;
44 Token Tok;
45 bool Err =
46 Lexer::getRawToken(R.getEnd(), Tok, Context.getSourceManager(),
47 Context.getLangOpts(), /*IgnoreWhiteSpace=*/true);
48 if (Err || !Tok.is(Next))
49 return Range;
50 return CharSourceRange::getTokenRange(Range.getBegin(), Tok.getLocation());
51}
52
54 const SourceManager &SM,
55 bool AllowSystemHeaders) {
56 if (Range.isInvalid())
57 return llvm::make_error<StringError>(errc::invalid_argument,
58 "Invalid range");
59
60 if (Range.getBegin().isMacroID() || Range.getEnd().isMacroID())
61 return llvm::make_error<StringError>(
62 errc::invalid_argument, "Range starts or ends in a macro expansion");
63
64 if (!AllowSystemHeaders) {
65 if (SM.isInSystemHeader(Range.getBegin()) ||
66 SM.isInSystemHeader(Range.getEnd()))
67 return llvm::make_error<StringError>(errc::invalid_argument,
68 "Range is in system header");
69 }
70
71 FileIDAndOffset BeginInfo = SM.getDecomposedLoc(Range.getBegin());
72 FileIDAndOffset EndInfo = SM.getDecomposedLoc(Range.getEnd());
73 if (BeginInfo.first != EndInfo.first)
74 return llvm::make_error<StringError>(
75 errc::invalid_argument, "Range begins and ends in different files");
76
77 if (BeginInfo.second > EndInfo.second)
78 return llvm::make_error<StringError>(errc::invalid_argument,
79 "Range's begin is past its end");
80
81 return llvm::Error::success();
82}
83
85 const SourceManager &SM) {
86 return validateRange(Range, SM, /*AllowSystemHeaders=*/false);
87}
88
89// Returns the location of the top-level macro argument that is the spelling for
90// the expansion `Loc` is from. If `Loc` is spelled in the macro definition,
91// returns an invalid `SourceLocation`.
93 const SourceManager &SM) {
94 assert(Loc.isMacroID() && "Location must be in a macro");
95 while (Loc.isMacroID()) {
96 const auto &Expansion = SM.getSLocEntry(SM.getFileID(Loc)).getExpansion();
97 if (Expansion.isMacroArgExpansion()) {
98 // Check the spelling location of the macro arg, in case the arg itself is
99 // in a macro expansion.
100 Loc = Expansion.getSpellingLoc();
101 } else {
102 return {};
103 }
104 }
105 return Loc;
106}
107
109 const SourceManager &SM) {
110 if (Range.getBegin().isMacroID() && Range.getEnd().isMacroID()) {
111 // Check whether the range is entirely within a single macro argument.
112 auto B = getMacroArgumentSpellingLoc(Range.getBegin(), SM);
113 auto E = getMacroArgumentSpellingLoc(Range.getEnd(), SM);
114 return B.isInvalid() || B != E;
115 }
116
117 if (Range.getBegin().isMacroID())
118 return getMacroArgumentSpellingLoc(Range.getBegin(), SM).isInvalid();
119 if (Range.getEnd().isMacroID())
120 return getMacroArgumentSpellingLoc(Range.getEnd(), SM).isInvalid();
121
122 return false;
123}
124
125// Returns the expansion char-range of `Loc` if `Loc` is a split token. For
126// example, `>>` in nested templates needs the first `>` to be split, otherwise
127// the `SourceLocation` of the token would lex as `>>` instead of `>`.
128static std::optional<CharSourceRange>
130 const LangOptions &LangOpts) {
131 if (Loc.isMacroID()) {
132 bool Invalid = false;
133 auto &SLoc = SM.getSLocEntry(SM.getFileID(Loc), &Invalid);
134 if (Invalid)
135 return std::nullopt;
136 if (auto &Expansion = SLoc.getExpansion();
137 !Expansion.isExpansionTokenRange()) {
138 // A char-range expansion is only used where a token-range would be
139 // incorrect, and so identifies this as a split token (and importantly,
140 // not as a macro).
141 return Expansion.getExpansionLocRange();
142 }
143 }
144 return std::nullopt;
145}
146
147// If `Range` covers a split token, returns the expansion range, otherwise
148// returns `Range`.
150 const SourceManager &SM,
151 const LangOptions &LangOpts) {
152 if (Range.isTokenRange()) {
153 auto BeginToken = getExpansionForSplitToken(Range.getBegin(), SM, LangOpts);
154 auto EndToken = getExpansionForSplitToken(Range.getEnd(), SM, LangOpts);
155 if (EndToken) {
156 SourceLocation BeginLoc =
157 BeginToken ? BeginToken->getBegin() : Range.getBegin();
158 // We can't use the expansion location with a token-range, because that
159 // will incorrectly lex the end token, so use a char-range that ends at
160 // the split.
161 return CharSourceRange::getCharRange(BeginLoc, EndToken->getEnd());
162 } else if (BeginToken) {
163 // Since the end token is not split, the whole range covers the split, so
164 // the only adjustment we make is to use the expansion location of the
165 // begin token.
166 return CharSourceRange::getTokenRange(BeginToken->getBegin(),
167 Range.getEnd());
168 }
169 }
170 return Range;
171}
172
174 const SourceManager &SM,
175 const LangOptions &LangOpts,
176 bool IncludeMacroExpansion) {
177 CharSourceRange Range;
178 if (IncludeMacroExpansion) {
179 Range = Lexer::makeFileCharRange(EditRange, SM, LangOpts);
180 } else {
181 auto AdjustedRange = getRangeForSplitTokens(EditRange, SM, LangOpts);
182 if (spelledInMacroDefinition(AdjustedRange, SM))
183 return {};
184
185 auto B = SM.getSpellingLoc(AdjustedRange.getBegin());
186 auto E = SM.getSpellingLoc(AdjustedRange.getEnd());
187 if (AdjustedRange.isTokenRange())
188 E = Lexer::getLocForEndOfToken(E, 0, SM, LangOpts);
189 Range = CharSourceRange::getCharRange(B, E);
190 }
191 return Range;
192}
193
194std::optional<CharSourceRange> clang::tooling::getFileRangeForEdit(
195 const CharSourceRange &EditRange, const SourceManager &SM,
196 const LangOptions &LangOpts, bool IncludeMacroExpansion) {
198 getRange(EditRange, SM, LangOpts, IncludeMacroExpansion);
199 bool IsInvalid = llvm::errorToBool(validateEditRange(Range, SM));
200 if (IsInvalid)
201 return std::nullopt;
202 return Range;
203}
204
205std::optional<CharSourceRange> clang::tooling::getFileRange(
206 const CharSourceRange &EditRange, const SourceManager &SM,
207 const LangOptions &LangOpts, bool IncludeMacroExpansion) {
209 getRange(EditRange, SM, LangOpts, IncludeMacroExpansion);
210 bool IsInvalid =
211 llvm::errorToBool(validateRange(Range, SM, /*AllowSystemHeaders=*/true));
212 if (IsInvalid)
213 return std::nullopt;
214 return Range;
215}
216
217static bool startsWithNewline(const SourceManager &SM, const Token &Tok) {
218 return isVerticalWhitespace(SM.getCharacterData(Tok.getLocation())[0]);
219}
220
221static bool contains(const std::set<tok::TokenKind> &Terminators,
222 const Token &Tok) {
223 return Terminators.count(Tok.getKind()) > 0;
224}
225
226// Returns the exclusive, *file* end location of the entity whose last token is
227// at location 'EntityLast'. That is, it returns the location one past the last
228// relevant character.
229//
230// Associated tokens include comments, horizontal whitespace and 'Terminators'
231// -- optional tokens, which, if any are found, will be included; if
232// 'Terminators' is empty, we will not include any extra tokens beyond comments
233// and horizontal whitespace.
234static SourceLocation
236 const std::set<tok::TokenKind> &Terminators,
237 const LangOptions &LangOpts) {
238 assert(EntityLast.isValid() && "Invalid end location found.");
239
240 // We remember the last location of a non-horizontal-whitespace token we have
241 // lexed; this is the location up to which we will want to delete.
242 // FIXME: Support using the spelling loc here for cases where we want to
243 // analyze the macro text.
244
245 CharSourceRange ExpansionRange = SM.getExpansionRange(EntityLast);
246 // FIXME: Should check isTokenRange(), for the (rare) case that
247 // `ExpansionRange` is a character range.
248 std::unique_ptr<Lexer> Lexer = [&]() {
249 bool Invalid = false;
250 auto FileOffset = SM.getDecomposedLoc(ExpansionRange.getEnd());
251 llvm::StringRef File = SM.getBufferData(FileOffset.first, &Invalid);
252 assert(!Invalid && "Cannot get file/offset");
253 return std::make_unique<clang::Lexer>(
254 SM.getLocForStartOfFile(FileOffset.first), LangOpts, File.begin(),
255 File.data() + FileOffset.second, File.end());
256 }();
257
258 // Tell Lexer to return whitespace as pseudo-tokens (kind is tok::unknown).
260
261 // Generally, the code we want to include looks like this ([] are optional),
262 // If Terminators is empty:
263 // [ <comment> ] [ <newline> ]
264 // Otherwise:
265 // ... <terminator> [ <comment> ] [ <newline> ]
266
267 Token Tok;
268 bool Terminated = false;
269
270 // First, lex to the current token (which is the last token of the range that
271 // is definitely associated with the decl). Then, we process the first token
272 // separately from the rest based on conditions that hold specifically for
273 // that first token.
274 //
275 // We do not search for a terminator if none is required or we've already
276 // encountered it. Otherwise, if the original `EntityLast` location was in a
277 // macro expansion, we don't have visibility into the text, so we assume we've
278 // already terminated. However, we note this assumption with
279 // `TerminatedByMacro`, because we'll want to handle it somewhat differently
280 // for the terminators semicolon and comma. These terminators can be safely
281 // associated with the entity when they appear after the macro -- extra
282 // semicolons have no effect on the program and a well-formed program won't
283 // have multiple commas in a row, so we're guaranteed that there is only one.
284 //
285 // FIXME: This handling of macros is more conservative than necessary. When
286 // the end of the expansion coincides with the end of the node, we can still
287 // safely analyze the code. But, it is more complicated, because we need to
288 // start by lexing the spelling loc for the first token and then switch to the
289 // expansion loc.
290 bool TerminatedByMacro = false;
292 if (Terminators.empty() || contains(Terminators, Tok))
293 Terminated = true;
294 else if (EntityLast.isMacroID()) {
295 Terminated = true;
296 TerminatedByMacro = true;
297 }
298
299 // We save the most recent candidate for the exclusive end location.
300 SourceLocation End = Tok.getEndLoc();
301
302 while (!Terminated) {
303 // Lex the next token we want to possibly expand the range with.
305
306 switch (Tok.getKind()) {
307 case tok::eof:
308 // Unexpected separators.
309 case tok::l_brace:
310 case tok::r_brace:
311 case tok::comma:
312 return End;
313 // Whitespace pseudo-tokens.
314 case tok::unknown:
316 // Include at least until the end of the line.
317 End = Tok.getEndLoc();
318 break;
319 default:
320 if (contains(Terminators, Tok))
321 Terminated = true;
322 End = Tok.getEndLoc();
323 break;
324 }
325 }
326
327 do {
328 // Lex the next token we want to possibly expand the range with.
330
331 switch (Tok.getKind()) {
332 case tok::unknown:
334 // We're done, but include this newline.
335 return Tok.getEndLoc();
336 break;
337 case tok::comment:
338 // Include any comments we find on the way.
339 End = Tok.getEndLoc();
340 break;
341 case tok::semi:
342 case tok::comma:
343 if (TerminatedByMacro && contains(Terminators, Tok)) {
344 End = Tok.getEndLoc();
345 // We've found a real terminator.
346 TerminatedByMacro = false;
347 break;
348 }
349 // Found an unrelated token; stop and don't include it.
350 return End;
351 default:
352 // Found an unrelated token; stop and don't include it.
353 return End;
354 }
355 } while (true);
356}
357
358// Returns the expected terminator tokens for the given declaration.
359//
360// If we do not know the correct terminator token, returns an empty set.
361//
362// There are cases where we have more than one possible terminator (for example,
363// we find either a comma or a semicolon after a VarDecl).
364static std::set<tok::TokenKind> getTerminators(const Decl &D) {
365 if (llvm::isa<RecordDecl>(D) || llvm::isa<UsingDecl>(D))
366 return {tok::semi};
367
368 if (llvm::isa<FunctionDecl>(D) || llvm::isa<LinkageSpecDecl>(D))
369 return {tok::r_brace, tok::semi};
370
371 if (llvm::isa<VarDecl>(D) || llvm::isa<FieldDecl>(D))
372 return {tok::comma, tok::semi};
373
374 return {};
375}
376
377// Starting from `Loc`, skips whitespace up to, and including, a single
378// newline. Returns the (exclusive) end of any skipped whitespace (that is, the
379// location immediately after the whitespace).
381 SourceLocation Loc,
382 const LangOptions &LangOpts) {
383 const char *LocChars = SM.getCharacterData(Loc);
384 int i = 0;
385 while (isHorizontalWhitespace(LocChars[i]))
386 ++i;
387 if (isVerticalWhitespace(LocChars[i]))
388 ++i;
389 return Loc.getLocWithOffset(i);
390}
391
392// Is `Loc` separated from any following decl by something meaningful (e.g. an
393// empty line, a comment), ignoring horizontal whitespace? Since this is a
394// heuristic, we return false when in doubt. `Loc` cannot be the first location
395// in the file.
397 const LangOptions &LangOpts) {
398 // If the preceding character is a newline, we'll check for an empty line as a
399 // separator. However, we can't identify an empty line using tokens, so we
400 // analyse the characters. If we try to use tokens, we'll just end up with a
401 // whitespace token, whose characters we'd have to analyse anyhow.
402 bool Invalid = false;
403 const char *LocChars =
404 SM.getCharacterData(Loc.getLocWithOffset(-1), &Invalid);
405 assert(!Invalid &&
406 "Loc must be a valid character and not the first of the source file.");
407 if (isVerticalWhitespace(LocChars[0])) {
408 for (int i = 1; isWhitespace(LocChars[i]); ++i)
409 if (isVerticalWhitespace(LocChars[i]))
410 return true;
411 }
412 // We didn't find an empty line, so lex the next token, skipping past any
413 // whitespace we just scanned.
414 Token Tok;
415 bool Failed = Lexer::getRawToken(Loc, Tok, SM, LangOpts,
416 /*IgnoreWhiteSpace=*/true);
417 if (Failed)
418 // Any text that confuses the lexer seems fair to consider a separation.
419 return true;
420
421 switch (Tok.getKind()) {
422 case tok::comment:
423 case tok::l_brace:
424 case tok::r_brace:
425 case tok::eof:
426 return true;
427 default:
428 return false;
429 }
430}
431
433 ASTContext &Context) {
434 const SourceManager &SM = Context.getSourceManager();
435 const LangOptions &LangOpts = Context.getLangOpts();
437
438 // First, expand to the start of the template<> declaration if necessary.
439 if (const auto *Record = llvm::dyn_cast<CXXRecordDecl>(&Decl)) {
440 if (const auto *T = Record->getDescribedClassTemplate())
441 if (SM.isBeforeInTranslationUnit(T->getBeginLoc(), Range.getBegin()))
442 Range.setBegin(T->getBeginLoc());
443 } else if (const auto *F = llvm::dyn_cast<FunctionDecl>(&Decl)) {
444 if (const auto *T = F->getDescribedFunctionTemplate())
445 if (SM.isBeforeInTranslationUnit(T->getBeginLoc(), Range.getBegin()))
446 Range.setBegin(T->getBeginLoc());
447 }
448
449 // Next, expand the end location past trailing comments to include a potential
450 // newline at the end of the decl's line.
451 Range.setEnd(
453 Range.setTokenRange(false);
454
455 // Expand to include preceeding associated comments. We ignore any comments
456 // that are not preceeding the decl, since we've already skipped trailing
457 // comments with getEntityEndLoc.
458 if (const RawComment *Comment =
460 // Only include a preceding comment if:
461 // * it is *not* separate from the declaration (not including any newline
462 // that immediately follows the comment),
463 // * the decl *is* separate from any following entity (so, there are no
464 // other entities the comment could refer to), and
465 // * it is not a IfThisThenThat lint check.
466 if (SM.isBeforeInTranslationUnit(Comment->getBeginLoc(),
467 Range.getBegin()) &&
469 SM, skipWhitespaceAndNewline(SM, Comment->getEndLoc(), LangOpts),
470 LangOpts) &&
471 atOrBeforeSeparation(SM, Range.getEnd(), LangOpts)) {
472 const StringRef CommentText = Comment->getRawText(SM);
473 if (!CommentText.contains("LINT.IfChange") &&
474 !CommentText.contains("LINT.ThenChange"))
475 Range.setBegin(Comment->getBeginLoc());
476 }
477 // Add leading attributes.
478 for (auto *Attr : Decl.attrs()) {
479 if (Attr->getLocation().isInvalid() ||
480 !SM.isBeforeInTranslationUnit(Attr->getLocation(), Range.getBegin()))
481 continue;
482 Range.setBegin(Attr->getLocation());
483
484 // Extend to the left '[[' or '__attribute((' if we saw the attribute,
485 // unless it is not a valid location.
486 bool Invalid;
487 StringRef Source =
488 SM.getBufferData(SM.getFileID(Range.getBegin()), &Invalid);
489 if (Invalid)
490 continue;
491 llvm::StringRef BeforeAttr =
492 Source.substr(0, SM.getFileOffset(Range.getBegin()));
493 llvm::StringRef BeforeAttrStripped = BeforeAttr.rtrim();
494
495 for (llvm::StringRef Prefix : {"[[", "__attribute__(("}) {
496 // Handle whitespace between attribute prefix and attribute value.
497 if (BeforeAttrStripped.ends_with(Prefix)) {
498 // Move start to start position of prefix, which is
499 // length(BeforeAttr) - length(BeforeAttrStripped) + length(Prefix)
500 // positions to the left.
501 Range.setBegin(Range.getBegin().getLocWithOffset(static_cast<int>(
502 -BeforeAttr.size() + BeforeAttrStripped.size() - Prefix.size())));
503 break;
504 // If we didn't see '[[' or '__attribute' it's probably coming from a
505 // macro expansion which is already handled by makeFileCharRange(),
506 // below.
507 }
508 }
509 }
510
511 // Range.getEnd() is already fully un-expanded by getEntityEndLoc. But,
512 // Range.getBegin() may be inside an expansion.
513 return Lexer::makeFileCharRange(Range, SM, LangOpts);
514}
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Token Tok
The Token.
FormatToken * Next
The next token in the unwrapped line.
llvm::MachO::Record Record
Definition MachO.h:31
#define SM(sm)
static SourceLocation getMacroArgumentSpellingLoc(SourceLocation Loc, const SourceManager &SM)
static bool contains(const std::set< tok::TokenKind > &Terminators, const Token &Tok)
static bool atOrBeforeSeparation(const SourceManager &SM, SourceLocation Loc, const LangOptions &LangOpts)
static bool startsWithNewline(const SourceManager &SM, const Token &Tok)
static SourceLocation getEntityEndLoc(const SourceManager &SM, SourceLocation EntityLast, const std::set< tok::TokenKind > &Terminators, const LangOptions &LangOpts)
static CharSourceRange getRangeForSplitTokens(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts)
static SourceLocation skipWhitespaceAndNewline(const SourceManager &SM, SourceLocation Loc, const LangOptions &LangOpts)
static std::optional< CharSourceRange > getExpansionForSplitToken(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
static CharSourceRange getRange(const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion)
static bool spelledInMacroDefinition(CharSourceRange Range, const SourceManager &SM)
static std::set< tok::TokenKind > getTerminators(const Decl &D)
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:220
RawComment * getRawCommentForDeclNoCache(const Decl *D) const
Return the documentation comment attached to a given declaration, without looking into cache.
Attr - This represents one attribute.
Definition Attr.h:45
SourceLocation getLocation() const
Definition Attr.h:98
Represents a character-granular source range.
static CharSourceRange getCharRange(SourceRange R)
static CharSourceRange getTokenRange(SourceRange R)
SourceLocation getEnd() const
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition DeclBase.h:435
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:546
attr_range attrs() const
Definition DeclBase.h:535
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition DeclBase.h:427
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
Definition Lexer.h:78
static StringRef getSourceText(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts, bool *Invalid=nullptr)
Returns a string for the source that the range encompasses.
Definition Lexer.cpp:1020
void SetKeepWhitespaceMode(bool Val)
SetKeepWhitespaceMode - This method lets clients enable or disable whitespace retention mode.
Definition Lexer.h:254
bool LexFromRawLexer(Token &Result)
LexFromRawLexer - Lex a token from a designated raw lexer (one with no associated preprocessor object...
Definition Lexer.h:236
static CharSourceRange getAsCharRange(SourceRange Range, const SourceManager &SM, const LangOptions &LangOpts)
Given a token range, produce a corresponding CharSourceRange that is not a token range.
Definition Lexer.h:430
static CharSourceRange makeFileCharRange(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts)
Accepts a range and returns a character range with file locations.
Definition Lexer.cpp:951
static bool getRawToken(SourceLocation Loc, Token &Result, const SourceManager &SM, const LangOptions &LangOpts, bool IgnoreWhiteSpace=false)
Relex the token at the specified location.
Definition Lexer.cpp:509
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
Definition Lexer.cpp:848
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
Token - This structure provides full information about a lexed token.
Definition Token.h:36
A source range independent of the SourceManager.
Definition Replacement.h:44
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition TokenKinds.h:25
std::optional< CharSourceRange > getFileRangeForEdit(const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion=true)
Attempts to resolve the given range to one that can be edited by a rewrite; generally,...
llvm::Error validateRange(const CharSourceRange &Range, const SourceManager &SM, bool AllowSystemHeaders)
Determines whether Range is one that can be read from.
llvm::Error validateEditRange(const CharSourceRange &Range, const SourceManager &SM)
Determines whether Range is one that can be edited by a rewrite; generally, one that starts and ends ...
std::optional< CharSourceRange > getFileRange(const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion)
Attempts to resolve the given range to one that starts and ends in a particular file.
CharSourceRange maybeExtendRange(CharSourceRange Range, tok::TokenKind Terminator, ASTContext &Context)
Extends Range to include the token Terminator, if it immediately follows the end of the range.
StringRef getText(CharSourceRange Range, const ASTContext &Context)
Returns the source-code text in the specified range.
CharSourceRange getAssociatedRange(const Decl &D, ASTContext &Context)
Returns the logical source range of the node extended to include associated comments and whitespace b...
The JSON file list parser is used to communicate input to InstallAPI.
LLVM_READONLY bool isVerticalWhitespace(unsigned char c)
Returns true if this character is vertical ASCII whitespace: '\n', '\r'.
Definition CharInfo.h:99
std::pair< FileID, unsigned > FileIDAndOffset
LLVM_READONLY bool isHorizontalWhitespace(unsigned char c)
Returns true if this character is horizontal ASCII whitespace: ' ', '\t', '\f', '\v'.
Definition CharInfo.h:91
const FunctionProtoType * T
LLVM_READONLY bool isWhitespace(unsigned char c)
Return true if this character is horizontal or vertical ASCII whitespace: ' ', '\t',...
Definition CharInfo.h:108