clang: lib/Sema/SemaFixItUtils.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

19

20using namespace clang;

21

28 return false;

29

32

33

39 }

40

43

44 if ((FromUnq == ToUnq || (S.IsDerivedFrom(Loc, FromUnq, ToUnq))) &&

46 return true;

47 return false;

48}

49

55 return false;

56

62

63

64

66

67 bool NeedParen = true;

89 NeedParen = false;

90

91

92

93 if (const PointerType *FromPtrTy = dyn_cast(FromQTy)) {

95

99 if (CanConvert) {

100

103 return false;

104

106 if (UO->getOpcode() == UO_AddrOf) {

110 }

111 } else if (NeedParen) {

114 } else {

116 }

117

120 Kind = FixKind;

121 return true;

122 }

123 }

124

125

126

127 if (const auto *ToPtrTy = dyn_cast(ToQTy)) {

128 bool CanConvert = false;

130

131

133 return false;

134

135

136 if (isa(FromQTy) && ToPtrTy->isVoidPointerType())

137 return false;

138

141 if (CanConvert) {

142

144 if (UO->getOpcode() == UO_Deref) {

148 }

149 } else if (NeedParen) {

152 } else {

154 }

155

158 Kind = FixKind;

159 return true;

160 }

161 }

162

163 return false;

164}

165

170

173 assert(T.isScalarType() && "use scalar types only");

174

175

176 if (T.isEnumeralType())

177 return std::string();

178 if ((T.isObjCObjectPointerType() || T.isBlockPointerType()) &&

180 return "nil";

181 if (T.isRealFloatingType())

182 return "0.0";

183 if (T.isBooleanType() &&

185 return "false";

186 if (T.isPointerType() || T.isMemberPointerType()) {

188 return "nullptr";

190 return "NULL";

191 }

192 if (T.isCharType())

193 return "'\\0'";

194 if (T.isWideCharType())

195 return "L'\\0'";

196 if (T.isChar16Type())

197 return "u'\\0'";

198 if (T.isChar32Type())

199 return "U'\\0'";

200 return "0";

201}

202

203std::string

205 if (T->isScalarType()) {

207 if (s.empty())

208 s = " = " + s;

209 return s;

210 }

211

214 return std::string();

216 return "{}";

218 return " = {}";

219 return std::string();

220}

221

222std::string

Defines the clang::ASTContext interface.

Defines the clang::Expr interface and subclasses for C++ expressions.

Defines the clang::Preprocessor interface.

static std::string getScalarZeroExpressionForType(const Type &T, SourceLocation Loc, const Sema &S)

Definition SemaFixItUtils.cpp:171

static bool isMacroDefined(const Sema &S, SourceLocation Loc, StringRef Name)

Definition SemaFixItUtils.cpp:166

static QualType getPointeeType(const MemRegion *R)

__device__ __2f16 float __ockl_bool s

static CanQualType getCanonicalType(QualType T)

Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...

QualType getPointerType(QualType T) const

Return the uniqued reference to the type for a pointer to the specified type.

Represents a C++ struct/union/class.

bool isAggregate() const

Determine whether this class is an aggregate (C++ [dcl.init.aggr]), which is a class with no user-dec...

bool hasUserProvidedDefaultConstructor() const

Whether this class has a user-provided default constructor per C++11.

bool hasDefinition() const

CanQual< Type > getNonReferenceType() const

If the canonical type is a reference type, returns the type that it refers to; otherwise,...

bool isAtLeastAsQualifiedAs(CanQual< T > Other, const ASTContext &Ctx) const

Determines whether this canonical type is at least as qualified as the Other canonical type.

CanQual< T > getUnqualifiedType() const

Retrieve the unqualified form of this type.

static CharSourceRange getTokenRange(SourceRange R)

This represents one expression.

Expr * IgnoreParenCasts() LLVM_READONLY

Skip past any parentheses and casts which might surround this expression until reaching a fixed point...

bool isLValue() const

isLValue - True if this expression is an "l-value" according to the rules of the current language.

@ NPC_ValueDependentIsNotNull

Specifies that a value-dependent expression should be considered to never be a null pointer constant.

ExprObjectKind getObjectKind() const

getObjectKind - The object kind that this expression produces.

Expr * IgnoreImpCasts() LLVM_READONLY

Skip past any implicit casts which might surround this expression until reaching a fixed point.

static FixItHint CreateRemoval(CharSourceRange RemoveRange)

Create a code modification hint that removes the given source range.

static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)

Create a code modification hint that inserts the given code string at a specific location.

FullExpr - Represents a "full-expression" node.

IdentifierInfo & get(StringRef Name)

Return the identifier token info for the specified named identifier.

PointerType - C99 6.7.5.1 - Pointer Declarators.

MacroDefinition getMacroDefinitionAtLoc(const IdentifierInfo *II, SourceLocation Loc)

A (possibly-)qualified type.

Sema - This implements semantic analysis and AST building for C.

std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const

Definition SemaFixItUtils.cpp:223

ASTContext & getASTContext() const

std::string getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const

Get a string to suggest for zero-initialization of a type.

Definition SemaFixItUtils.cpp:204

SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)

Calls Lexer::getLocForEndOfToken()

const LangOptions & LangOpts

bool IsDerivedFrom(SourceLocation Loc, CXXRecordDecl *Derived, CXXRecordDecl *Base, CXXBasePaths &Paths)

Determine whether the type Derived is a C++ class that is derived from the type Base.

Encodes a location in the source.

SourceLocation getEnd() const

SourceLocation getBegin() const

SourceRange getSourceRange() const LLVM_READONLY

SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...

The base class of the type hierarchy.

UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...

The JSON file list parser is used to communicate input to InstallAPI.

CanQual< Type > CanQualType

Represents a canonical, potentially-qualified type.

bool isa(CodeGen::Address addr)

@ OK_Ordinary

An ordinary object is located at an address in memory.

const FunctionProtoType * T

ExprValueKind

The categorization of expression values, currently following the C++11 scheme.

@ VK_PRValue

A pr-value expression (in the C++11 taxonomy) produces a temporary value.

@ VK_LValue

An l-value expression is a reference to an object with independent storage.

U cast(CodeGen::Address addr)

OverloadFixItKind Kind

The type of fix applied.

unsigned NumConversionsFixed

The number of Conversions fixed.

TypeComparisonFuncTy CompareTypes

The type comparison function used to decide if expression FromExpr of type FromTy can be converted to...

bool tryToFixConversion(const Expr *FromExpr, const QualType FromQTy, const QualType ToQTy, Sema &S)

If possible, generates and stores a fix for the given conversion.

Definition SemaFixItUtils.cpp:50

static bool compareTypesSimple(CanQualType From, CanQualType To, Sema &S, SourceLocation Loc, ExprValueKind FromVK)

Performs a simple check to see if From type can be converted to To type.

Definition SemaFixItUtils.cpp:22

std::vector< FixItHint > Hints

The list of Hints generated so far.