003 File Manager
Current Path:
/usr/src/contrib/llvm-project/clang/lib/Sema
usr
/
src
/
contrib
/
llvm-project
/
clang
/
lib
/
Sema
/
📁
..
📄
AnalysisBasedWarnings.cpp
(83.16 KB)
📄
CodeCompleteConsumer.cpp
(22.58 KB)
📄
CoroutineStmtBuilder.h
(2.34 KB)
📄
DeclSpec.cpp
(52.98 KB)
📄
DelayedDiagnostic.cpp
(2.46 KB)
📄
IdentifierResolver.cpp
(12.75 KB)
📄
JumpDiagnostics.cpp
(37.08 KB)
📄
MultiplexExternalSemaSource.cpp
(11.97 KB)
📄
OpenCLBuiltins.td
(74.48 KB)
📄
ParsedAttr.cpp
(6.91 KB)
📄
Scope.cpp
(6.24 KB)
📄
ScopeInfo.cpp
(8.02 KB)
📄
Sema.cpp
(92.56 KB)
📄
SemaAccess.cpp
(70.03 KB)
📄
SemaAttr.cpp
(39.44 KB)
📄
SemaAvailability.cpp
(35.52 KB)
📄
SemaCUDA.cpp
(32.46 KB)
📄
SemaCXXScopeSpec.cpp
(42.62 KB)
📄
SemaCast.cpp
(117.77 KB)
📄
SemaChecking.cpp
(580.53 KB)
📄
SemaCodeComplete.cpp
(357.59 KB)
📄
SemaConcept.cpp
(41.79 KB)
📄
SemaConsumer.cpp
(464 B)
📄
SemaCoroutine.cpp
(61.87 KB)
📄
SemaDecl.cpp
(711.18 KB)
📄
SemaDeclAttr.cpp
(266.6 KB)
📄
SemaDeclCXX.cpp
(674.92 KB)
📄
SemaDeclObjC.cpp
(208.27 KB)
📄
SemaExceptionSpec.cpp
(58.64 KB)
📄
SemaExpr.cpp
(744.15 KB)
📄
SemaExprCXX.cpp
(343.26 KB)
📄
SemaExprMember.cpp
(73.07 KB)
📄
SemaExprObjC.cpp
(184.87 KB)
📄
SemaFixItUtils.cpp
(7.49 KB)
📄
SemaInit.cpp
(392.01 KB)
📄
SemaLambda.cpp
(80.53 KB)
📄
SemaLookup.cpp
(202.16 KB)
📄
SemaModule.cpp
(27.05 KB)
📄
SemaObjCProperty.cpp
(119.38 KB)
📄
SemaOpenMP.cpp
(760.99 KB)
📄
SemaOverload.cpp
(596.12 KB)
📄
SemaPseudoObject.cpp
(64.4 KB)
📄
SemaSYCL.cpp
(2 KB)
📄
SemaStmt.cpp
(167.23 KB)
📄
SemaStmtAsm.cpp
(36.06 KB)
📄
SemaStmtAttr.cpp
(14.59 KB)
📄
SemaTemplate.cpp
(438.46 KB)
📄
SemaTemplateDeduction.cpp
(247.26 KB)
📄
SemaTemplateInstantiate.cpp
(150.48 KB)
📄
SemaTemplateInstantiateDecl.cpp
(240.7 KB)
📄
SemaTemplateVariadic.cpp
(44.44 KB)
📄
SemaType.cpp
(332.48 KB)
📄
TreeTransform.h
(554.25 KB)
📄
TypeLocBuilder.cpp
(5.17 KB)
📄
TypeLocBuilder.h
(4.5 KB)
📄
UsedDeclVisitor.h
(3.33 KB)
Editing: SemaFixItUtils.cpp
//===--- SemaFixItUtils.cpp - Sema FixIts ---------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines helper classes for generation of Sema FixItHints. // //===----------------------------------------------------------------------===// #include "clang/AST/ASTContext.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" #include "clang/Lex/Preprocessor.h" #include "clang/Sema/Sema.h" #include "clang/Sema/SemaFixItUtils.h" using namespace clang; bool ConversionFixItGenerator::compareTypesSimple(CanQualType From, CanQualType To, Sema &S, SourceLocation Loc, ExprValueKind FromVK) { if (!To.isAtLeastAsQualifiedAs(From)) return false; From = From.getNonReferenceType(); To = To.getNonReferenceType(); // If both are pointer types, work with the pointee types. if (isa<PointerType>(From) && isa<PointerType>(To)) { From = S.Context.getCanonicalType( (cast<PointerType>(From))->getPointeeType()); To = S.Context.getCanonicalType( (cast<PointerType>(To))->getPointeeType()); } const CanQualType FromUnq = From.getUnqualifiedType(); const CanQualType ToUnq = To.getUnqualifiedType(); if ((FromUnq == ToUnq || (S.IsDerivedFrom(Loc, FromUnq, ToUnq)) ) && To.isAtLeastAsQualifiedAs(From)) return true; return false; } bool ConversionFixItGenerator::tryToFixConversion(const Expr *FullExpr, const QualType FromTy, const QualType ToTy, Sema &S) { if (!FullExpr) return false; const CanQualType FromQTy = S.Context.getCanonicalType(FromTy); const CanQualType ToQTy = S.Context.getCanonicalType(ToTy); const SourceLocation Begin = FullExpr->getSourceRange().getBegin(); const SourceLocation End = S.getLocForEndOfToken(FullExpr->getSourceRange() .getEnd()); // Strip the implicit casts - those are implied by the compiler, not the // original source code. const Expr* Expr = FullExpr->IgnoreImpCasts(); bool NeedParen = true; if (isa<ArraySubscriptExpr>(Expr) || isa<CallExpr>(Expr) || isa<DeclRefExpr>(Expr) || isa<CastExpr>(Expr) || isa<CXXNewExpr>(Expr) || isa<CXXConstructExpr>(Expr) || isa<CXXDeleteExpr>(Expr) || isa<CXXNoexceptExpr>(Expr) || isa<CXXPseudoDestructorExpr>(Expr) || isa<CXXScalarValueInitExpr>(Expr) || isa<CXXThisExpr>(Expr) || isa<CXXTypeidExpr>(Expr) || isa<CXXUnresolvedConstructExpr>(Expr) || isa<ObjCMessageExpr>(Expr) || isa<ObjCPropertyRefExpr>(Expr) || isa<ObjCProtocolExpr>(Expr) || isa<MemberExpr>(Expr) || isa<ParenExpr>(FullExpr) || isa<ParenListExpr>(Expr) || isa<SizeOfPackExpr>(Expr) || isa<UnaryOperator>(Expr)) NeedParen = false; // Check if the argument needs to be dereferenced: // (type * -> type) or (type * -> type &). if (const PointerType *FromPtrTy = dyn_cast<PointerType>(FromQTy)) { OverloadFixItKind FixKind = OFIK_Dereference; bool CanConvert = CompareTypes( S.Context.getCanonicalType(FromPtrTy->getPointeeType()), ToQTy, S, Begin, VK_LValue); if (CanConvert) { // Do not suggest dereferencing a Null pointer. if (Expr->IgnoreParenCasts()-> isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull)) return false; if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(Expr)) { if (UO->getOpcode() == UO_AddrOf) { FixKind = OFIK_RemoveTakeAddress; Hints.push_back(FixItHint::CreateRemoval( CharSourceRange::getTokenRange(Begin, Begin))); } } else if (NeedParen) { Hints.push_back(FixItHint::CreateInsertion(Begin, "*(")); Hints.push_back(FixItHint::CreateInsertion(End, ")")); } else { Hints.push_back(FixItHint::CreateInsertion(Begin, "*")); } NumConversionsFixed++; if (NumConversionsFixed == 1) Kind = FixKind; return true; } } // Check if the pointer to the argument needs to be passed: // (type -> type *) or (type & -> type *). if (isa<PointerType>(ToQTy)) { bool CanConvert = false; OverloadFixItKind FixKind = OFIK_TakeAddress; // Only suggest taking address of L-values. if (!Expr->isLValue() || Expr->getObjectKind() != OK_Ordinary) return false; CanConvert = CompareTypes(S.Context.getPointerType(FromQTy), ToQTy, S, Begin, VK_RValue); if (CanConvert) { if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(Expr)) { if (UO->getOpcode() == UO_Deref) { FixKind = OFIK_RemoveDereference; Hints.push_back(FixItHint::CreateRemoval( CharSourceRange::getTokenRange(Begin, Begin))); } } else if (NeedParen) { Hints.push_back(FixItHint::CreateInsertion(Begin, "&(")); Hints.push_back(FixItHint::CreateInsertion(End, ")")); } else { Hints.push_back(FixItHint::CreateInsertion(Begin, "&")); } NumConversionsFixed++; if (NumConversionsFixed == 1) Kind = FixKind; return true; } } return false; } static bool isMacroDefined(const Sema &S, SourceLocation Loc, StringRef Name) { return (bool)S.PP.getMacroDefinitionAtLoc(&S.getASTContext().Idents.get(Name), Loc); } static std::string getScalarZeroExpressionForType( const Type &T, SourceLocation Loc, const Sema &S) { assert(T.isScalarType() && "use scalar types only"); // Suggest "0" for non-enumeration scalar types, unless we can find a // better initializer. if (T.isEnumeralType()) return std::string(); if ((T.isObjCObjectPointerType() || T.isBlockPointerType()) && isMacroDefined(S, Loc, "nil")) return "nil"; if (T.isRealFloatingType()) return "0.0"; if (T.isBooleanType() && (S.LangOpts.CPlusPlus || isMacroDefined(S, Loc, "false"))) return "false"; if (T.isPointerType() || T.isMemberPointerType()) { if (S.LangOpts.CPlusPlus11) return "nullptr"; if (isMacroDefined(S, Loc, "NULL")) return "NULL"; } if (T.isCharType()) return "'\\0'"; if (T.isWideCharType()) return "L'\\0'"; if (T.isChar16Type()) return "u'\\0'"; if (T.isChar32Type()) return "U'\\0'"; return "0"; } std::string Sema::getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const { if (T->isScalarType()) { std::string s = getScalarZeroExpressionForType(*T, Loc, *this); if (!s.empty()) s = " = " + s; return s; } const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); if (!RD || !RD->hasDefinition()) return std::string(); if (LangOpts.CPlusPlus11 && !RD->hasUserProvidedDefaultConstructor()) return "{}"; if (RD->isAggregate()) return " = {}"; return std::string(); } std::string Sema::getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const { return getScalarZeroExpressionForType(*T, Loc, *this); }
Upload File
Create Folder