11 #include "clang/AST/ASTContext.h"
12 #include "clang/AST/Type.h"
20 SourceLocation AmpLocation = Var.getLocation();
22 AmpLocation, Context.getSourceManager(), Context.getLangOpts());
23 if (!Token.is(tok::unknown))
24 AmpLocation = Lexer::getLocForEndOfToken(Token.getLocation(), 0,
25 Context.getSourceManager(),
26 Context.getLangOpts());
27 return FixItHint::CreateInsertion(AmpLocation,
"&");
31 return !(isa<PointerType>(T) || isa<ReferenceType>(T) || isa<ArrayType>(T) ||
32 isa<MemberPointerType>(T) || isa<ObjCObjectPointerType>(T));
36 return (QT->isPointerType() && QT->isFunctionPointerType()) ||
37 isa<MemberPointerType>(QT.getTypePtr());
41 return S.isInvalid() || S.isMacroID();
44 static Optional<SourceLocation>
49 auto PreviousTokenLParen = [&Start, &Context]() {
52 Context.getLangOpts());
53 return T.is(tok::l_paren);
56 while (Start.isValid() && PreviousTokenLParen())
58 Context.getLangOpts());
69 return FixItHint::CreateInsertion(
Loc,
Text);
75 bool WhitespaceBefore =
false) {
77 return (llvm::Twine(
' ') + DeclSpec::getSpecifierName(Qualifier)).str();
78 return (llvm::Twine(DeclSpec::getSpecifierName(Qualifier)) +
" ").str();
82 DeclSpec::TQ Qualifier,
85 const ASTContext &Context) {
91 Optional<SourceLocation> IgnoredParens =
98 llvm_unreachable(
"Unknown QualifierPolicy enum");
102 DeclSpec::TQ Qualifier,
103 const ASTContext &Context) {
107 Optional<SourceLocation> IgnoredParens =
114 static Optional<FixItHint>
117 const ASTContext &Context) {
136 Var.getLocation(), Context.getSourceManager(), Context.getLangOpts(),
141 Optional<SourceLocation> IgnoredParens =
157 Var.getLocation(), Context.getSourceManager(), Context.getLangOpts(),
165 static Optional<FixItHint>
168 const ASTContext &Context) {
174 Var.getLocation(), Context.getSourceManager(), Context.getLangOpts(),
175 tok::amp, tok::ampamp);
176 Optional<SourceLocation> IgnoredParens =
185 const ASTContext &Context,
186 DeclSpec::TQ Qualifier,
191 "Unexpected Insertion Policy");
194 "Unexpected Target");
196 QualType ParenStrippedType = Var.getType().IgnoreParens();
198 return changeValue(Var, Qualifier, QualTarget, QualPolicy, Context);
200 if (ParenStrippedType->isReferenceType())
202 QualTarget, QualPolicy, Context);
207 if (ParenStrippedType->isPointerType())
209 ParenStrippedType->getPointeeType().getTypePtr(),
210 QualTarget, QualPolicy, Context);
212 if (ParenStrippedType->isArrayType()) {
213 const Type *AT = ParenStrippedType->getBaseElementTypeUnsafe();
214 assert(AT &&
"Did not retrieve array element type for an array.");
217 return changeValue(Var, Qualifier, QualTarget, QualPolicy, Context);
219 if (AT->isPointerType())
220 return changePointer(Var, Qualifier, AT->getPointeeType().getTypePtr(),
221 QualTarget, QualPolicy, Context);