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

34 if (isa(From) && isa(To)) {

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;

68 if (isa(Expr) ||

69 isa(Expr) ||

70 isa(Expr) ||

71 isa(Expr) ||

72 isa(Expr) ||

73 isa(Expr) ||

74 isa(Expr) ||

75 isa(Expr) ||

76 isa(Expr) ||

77 isa(Expr) ||

78 isa(Expr) ||

79 isa(Expr) ||

80 isa(Expr) ||

81 isa(Expr) ||

82 isa(Expr) ||

83 isa(Expr) ||

84 isa(Expr) ||

86 isa(Expr) ||

87 isa(Expr) ||

88 isa(Expr))

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

169}

170

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

174

175

177 return std::string();

180 return "nil";

182 return "0.0";

185 return "false";

188 return "nullptr";

190 return "NULL";

191 }

193 return "'\\0'";

195 return "L'\\0'";

197 return "u'\\0'";

199 return "U'\\0'";

200 return "0";

201}

202

203std::string

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

225}

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)

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

static QualType getPointeeType(const MemRegion *R)

__device__ __2f16 float __ockl_bool s

CanQualType getCanonicalType(QualType T) const

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

ASTContext & getASTContext() const

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

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

SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)

Calls Lexer::getLocForEndOfToken()

const LangOptions & LangOpts

bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base)

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.

CXXRecordDecl * getAsCXXRecordDecl() const

Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...

bool isBlockPointerType() const

bool isBooleanType() const

bool isPointerType() const

bool isEnumeralType() const

bool isScalarType() const

bool isChar16Type() const

bool isMemberPointerType() const

bool isChar32Type() const

bool isObjCObjectPointerType() const

bool isRealFloatingType() const

Floating point categories.

bool isWideCharType() const

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

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

@ OK_Ordinary

An ordinary object is located at an address in memory.

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.

const FunctionProtoType * T

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.

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.

std::vector< FixItHint > Hints

The list of Hints generated so far.