clang: lib/Analysis/FixitUtil.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
11
12using namespace llvm;
13using namespace clang;
15
16
17
18
19
20
21std::optionalstd::string
24 std::optional *QualifiersToAppend) {
27
29 "Expecting a VarDecl of type of pointer to object type");
31
34
35
36
38 case TypeLoc::ConstantArray:
39 case TypeLoc::IncompleteArray:
40 case TypeLoc::VariableArray:
41 case TypeLoc::DependentSizedArray:
42 case TypeLoc::Decayed:
43 assert(isa(VD) && "An array type shall not be treated as a "
44 "pointer type unless it decays.");
46 break;
47 case TypeLoc::Pointer:
49 break;
50 default:
51 return std::nullopt;
52 }
53 if (PteTyLoc.isNull())
54
55
56 return std::nullopt;
57
58
60
62
63
64
65 return std::nullopt;
66 }
67
68
71
72 if (!PteEndOfTokenLoc.isValid())
73
74
75 return std::nullopt;
76 if (.isBeforeInTranslationUnit(PteEndOfTokenLoc, IdentLoc) &&
77 PteEndOfTokenLoc != IdentLoc) {
78
79
80
81
82
83
84 return std::nullopt;
85 }
87
88
89
91 }
93 ->str();
94}
95
96
97std::optionalstd::string
100 std::optional *QualifiersToAppend) {
101
104 "Expecting a VarDecl of reference to pointer type");
105
108
110 "Expecting a VarDecl of type of pointer to object type");
112
116
117
118
120 case TypeLoc::ConstantArray:
121 case TypeLoc::IncompleteArray:
122 case TypeLoc::VariableArray:
123 case TypeLoc::DependentSizedArray:
124 case TypeLoc::LValueReference:
128 break;
129 }
130 return std::nullopt;
131 break;
132 default:
133 return std::nullopt;
134 }
135 if (PteTyLoc.isNull())
136
137
138 return std::nullopt;
139
140
142
144
145
146
147 return std::nullopt;
148 }
149
150
153
154 if (!PteEndOfTokenLoc.isValid())
155
156
157 return std::nullopt;
158 if (.isBeforeInTranslationUnit(PteEndOfTokenLoc, IdentLoc)) {
159
160
161
162
163
164
165 return std::nullopt;
166 }
168
169
170
172 }
174 ->str();
175}
176
183
184
191
194 return std::nullopt;
195}
196
197
198std::optional
205
208 }
209
210 if (ParmIdentEndLoc.isMacroID() &&
212 return std::nullopt;
213 return getRangeText({ParmIdentBeginLoc, ParmIdentEndLoc}, SM, LangOpts);
214}
215
216
220 std::optional LastCharLoc = getPastLoc(E, SM, LangOpts);
221
222 if (LastCharLoc)
225 LangOpts);
226
227 return std::nullopt;
228}
229
230
231
Represents a character-granular source range.
static CharSourceRange getCharRange(SourceRange R)
SourceLocation getLocation() const
Represents a ValueDecl that came out of a declarator.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
TypeSourceInfo * getTypeSourceInfo() const
This represents one expression.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
static StringRef getSourceText(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts, bool *Invalid=nullptr)
Returns a string for the source that the range encompasses.
static bool isAtEndOfMacroExpansion(SourceLocation loc, const SourceManager &SM, const LangOptions &LangOpts, SourceLocation *MacroEnd=nullptr)
Returns true if the given MacroID location points at the last token of the macro expansion.
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.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
Wrapper for source info for pointers.
A (possibly-)qualified type.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
SourceLocation getBeginLoc() const LLVM_READONLY
Base wrapper for a particular "section" of type source info.
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
TypeLoc getNextTypeLoc() const
Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the TypeLoc is a PointerLoc and next Typ...
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
TypeLocClass getTypeLocClass() const
SourceLocation getEndLoc() const
Get the end source location.
SourceLocation getBeginLoc() const
Get the begin source location.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
bool isFunctionPointerType() const
bool isPointerType() const
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
SourceLocation getVarDeclIdentifierLoc(const DeclaratorDecl *VD)
Definition FixitUtil.cpp:232
SourceLocation getBeginLocOfNestedIdentifier(const DeclaratorDecl *D)
Definition FixitUtil.cpp:177
std::optional< StringRef > getExprText(const Expr *E, const SourceManager &SM, const LangOptions &LangOpts)
Definition FixitUtil.cpp:217
std::optional< std::string > getPointeeTypeText(const DeclaratorDecl *VD, const SourceManager &SM, const LangOptions &LangOpts, std::optional< Qualifiers > *QualifiersToAppend)
Definition FixitUtil.cpp:22
std::optional< std::string > getPointee2TypeText(const DeclaratorDecl *VD, const SourceManager &SM, const LangOptions &LangOpts, std::optional< Qualifiers > *QualifiersToAppend)
std::optional< StringRef > getRangeText(SourceRange SR, const SourceManager &SM, const LangOptions &LangOpts)
Definition FixitUtil.cpp:185
std::optional< StringRef > getVarDeclIdentifierText(const DeclaratorDecl *VD, const SourceManager &SM, const LangOptions &LangOpts)
Definition FixitUtil.cpp:199
std::optional< SourceLocation > getPastLoc(const NodeTy *Node, const SourceManager &SM, const LangOptions &LangOpts)
Diagnostic wrappers for TextAPI types for error reporting.