From 676fbe8105eeb6ff4bb2ed261cb212fcfdbe7b63 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 19 Jan 2019 10:04:05 +0000 Subject: Vendor import of clang trunk r351319 (just before the release_80 branch point): https://llvm.org/svn/llvm-project/cfe/trunk@351319 --- include/clang/AST/ASTContext.h | 97 +- include/clang/AST/ASTContextAllocate.h | 38 + include/clang/AST/ASTDiagnostic.h | 12 +- include/clang/AST/ASTDumperUtils.h | 97 + include/clang/AST/ASTImporter.h | 193 +- include/clang/AST/ASTImporterLookupTable.h | 75 + include/clang/AST/ASTStructuralEquivalence.h | 14 +- include/clang/AST/ASTVector.h | 1 + include/clang/AST/Attr.h | 14 + include/clang/AST/AttrIterator.h | 19 - include/clang/AST/AttrVisitor.h | 76 + include/clang/AST/BaseSubobject.h | 1 + include/clang/AST/CMakeLists.txt | 9 +- include/clang/AST/CanonicalType.h | 2 +- include/clang/AST/Comment.h | 35 +- include/clang/AST/CommentDiagnostic.h | 15 +- include/clang/AST/CommentVisitor.h | 34 +- include/clang/AST/Decl.h | 718 ++--- include/clang/AST/DeclBase.h | 621 +++- include/clang/AST/DeclCXX.h | 154 +- include/clang/AST/DeclFriend.h | 2 +- include/clang/AST/DeclObjC.h | 191 +- include/clang/AST/DeclOpenMP.h | 120 +- include/clang/AST/DeclTemplate.h | 4 + include/clang/AST/DeclVisitor.h | 13 +- include/clang/AST/DeclarationName.h | 621 ++-- include/clang/AST/EvaluatedExprVisitor.h | 18 +- include/clang/AST/Expr.h | 1312 ++++---- include/clang/AST/ExprCXX.h | 1613 +++++----- include/clang/AST/ExprObjC.h | 90 +- include/clang/AST/ExprOpenMP.h | 6 +- include/clang/AST/FormatString.h | 752 +++++ include/clang/AST/GlobalDecl.h | 28 +- .../AST/LexicallyOrderedRecursiveASTVisitor.h | 4 +- include/clang/AST/Mangle.h | 1 + include/clang/AST/NSAPI.h | 11 +- include/clang/AST/NestedNameSpecifier.h | 11 +- include/clang/AST/ODRHash.h | 10 +- include/clang/AST/OSLog.h | 161 + include/clang/AST/OpenMPClause.h | 448 ++- include/clang/AST/OperationKinds.def | 16 +- include/clang/AST/PrettyPrinter.h | 62 +- include/clang/AST/RawCommentList.h | 6 +- include/clang/AST/RecursiveASTVisitor.h | 104 +- include/clang/AST/Stmt.h | 1795 ++++++++--- include/clang/AST/StmtCXX.h | 56 +- include/clang/AST/StmtDataCollectors.td | 6 +- include/clang/AST/StmtObjC.h | 38 +- include/clang/AST/StmtOpenMP.h | 40 +- include/clang/AST/StmtVisitor.h | 51 +- include/clang/AST/TemplateArgumentVisitor.h | 99 + include/clang/AST/TemplateBase.h | 21 +- include/clang/AST/TemplateName.h | 1 + include/clang/AST/TextNodeDumper.h | 298 ++ include/clang/AST/Type.h | 909 ++++-- include/clang/AST/TypeLoc.h | 93 +- include/clang/ASTMatchers/ASTMatchers.h | 252 +- include/clang/ASTMatchers/ASTMatchersInternal.h | 2 +- include/clang/ASTMatchers/Dynamic/Parser.h | 1 + .../clang/Analysis/Analyses/ExprMutationAnalyzer.h | 96 + include/clang/Analysis/Analyses/FormatString.h | 719 ----- include/clang/Analysis/Analyses/LiveVariables.h | 8 +- include/clang/Analysis/Analyses/OSLog.h | 155 - .../Analysis/Analyses/PseudoConstantAnalysis.h | 45 - .../clang/Analysis/Analyses/ThreadSafetyCommon.h | 2 + include/clang/Analysis/Analyses/ThreadSafetyTIL.h | 8 +- .../clang/Analysis/Analyses/ThreadSafetyTraverse.h | 21 +- include/clang/Analysis/AnalysisDeclContext.h | 32 +- include/clang/Analysis/AnalysisDiagnostic.h | 15 +- include/clang/Analysis/CallGraph.h | 1 + include/clang/Analysis/CloneDetection.h | 2 +- include/clang/Analysis/ConstructionContext.h | 14 +- include/clang/Analysis/ProgramPoint.h | 28 + include/clang/Analysis/SelectorExtras.h | 37 + include/clang/Basic/AlignedAllocation.h | 4 +- include/clang/Basic/AllDiagnostics.h | 22 +- include/clang/Basic/Attr.td | 278 +- include/clang/Basic/AttrDocs.td | 453 ++- include/clang/Basic/Builtins.def | 35 +- include/clang/Basic/BuiltinsAArch64.def | 105 + include/clang/Basic/BuiltinsAMDGPU.def | 37 +- include/clang/Basic/BuiltinsARM.def | 98 + include/clang/Basic/BuiltinsHexagon.def | 3302 ++++++++++---------- include/clang/Basic/BuiltinsNios2.def | 70 - include/clang/Basic/BuiltinsPPC.def | 6 + include/clang/Basic/BuiltinsWebAssembly.def | 90 +- include/clang/Basic/BuiltinsX86.def | 251 +- include/clang/Basic/BuiltinsX86_64.def | 7 +- include/clang/Basic/CodeGenOptions.def | 370 +++ include/clang/Basic/CodeGenOptions.h | 333 ++ include/clang/Basic/Cuda.h | 8 +- include/clang/Basic/DebugInfoOptions.h | 6 + include/clang/Basic/DeclNodes.td | 1 + include/clang/Basic/Diagnostic.h | 9 +- include/clang/Basic/DiagnosticAST.h | 29 + include/clang/Basic/DiagnosticASTKinds.td | 39 + include/clang/Basic/DiagnosticAnalysis.h | 29 + include/clang/Basic/DiagnosticComment.h | 29 + include/clang/Basic/DiagnosticCommonKinds.td | 51 + include/clang/Basic/DiagnosticCrossTU.h | 29 + include/clang/Basic/DiagnosticCrossTUKinds.td | 9 +- include/clang/Basic/DiagnosticDriver.h | 29 + include/clang/Basic/DiagnosticDriverKinds.td | 41 +- include/clang/Basic/DiagnosticFrontend.h | 29 + include/clang/Basic/DiagnosticFrontendKinds.td | 70 +- include/clang/Basic/DiagnosticGroups.td | 28 +- include/clang/Basic/DiagnosticIDs.h | 2 +- include/clang/Basic/DiagnosticLex.h | 29 + include/clang/Basic/DiagnosticLexKinds.td | 23 +- include/clang/Basic/DiagnosticParse.h | 29 + include/clang/Basic/DiagnosticParseKinds.td | 65 +- include/clang/Basic/DiagnosticRefactoring.h | 29 + include/clang/Basic/DiagnosticSema.h | 29 + include/clang/Basic/DiagnosticSemaKinds.td | 408 +-- include/clang/Basic/DiagnosticSerialization.h | 29 + include/clang/Basic/Features.def | 40 +- include/clang/Basic/FileManager.h | 44 +- include/clang/Basic/FileSystemStatCache.h | 46 +- include/clang/Basic/FixedPoint.h | 138 + include/clang/Basic/IdentifierTable.h | 237 +- include/clang/Basic/LangOptions.def | 17 +- include/clang/Basic/LangOptions.h | 83 +- include/clang/Basic/MSP430Target.def | 247 ++ include/clang/Basic/ObjCRuntime.h | 74 + include/clang/Basic/OpenCLExtensionTypes.def | 41 + include/clang/Basic/OpenCLExtensions.def | 1 + include/clang/Basic/OpenMPKinds.def | 37 +- include/clang/Basic/OpenMPKinds.h | 17 + include/clang/Basic/PlistSupport.h | 25 +- include/clang/Basic/Sanitizers.def | 29 +- include/clang/Basic/Sanitizers.h | 2 +- include/clang/Basic/SourceLocation.h | 4 + include/clang/Basic/SourceManager.h | 21 +- include/clang/Basic/Specifiers.h | 1 + include/clang/Basic/StmtNodes.td | 6 +- include/clang/Basic/TargetBuiltins.h | 10 - include/clang/Basic/TargetInfo.h | 36 +- include/clang/Basic/TargetOptions.h | 14 +- include/clang/Basic/TokenKinds.def | 85 +- include/clang/Basic/TokenKinds.h | 3 +- include/clang/Basic/TypeTraits.h | 6 + include/clang/Basic/VirtualFileSystem.h | 454 --- include/clang/Basic/X86Target.def | 9 + include/clang/Basic/XRayInstr.h | 2 + include/clang/Basic/arm_neon.td | 109 +- include/clang/Basic/arm_neon_incl.td | 7 + include/clang/CodeGen/CGFunctionInfo.h | 6 +- include/clang/CodeGen/SwiftCallingConv.h | 3 + include/clang/CrossTU/CrossTUDiagnostic.h | 18 +- include/clang/CrossTU/CrossTranslationUnit.h | 30 +- include/clang/Driver/Action.h | 27 +- include/clang/Driver/CC1Options.td | 61 +- include/clang/Driver/CLCompatOptions.td | 83 +- include/clang/Driver/DarwinSDKInfo.h | 42 + include/clang/Driver/Distro.h | 12 +- include/clang/Driver/Driver.h | 23 +- include/clang/Driver/DriverDiagnostic.h | 15 +- include/clang/Driver/Job.h | 15 +- include/clang/Driver/Options.td | 199 +- include/clang/Driver/SanitizerArgs.h | 5 + include/clang/Driver/ToolChain.h | 42 +- include/clang/Driver/Types.def | 1 + include/clang/Format/Format.h | 71 +- include/clang/Frontend/ASTConsumers.h | 4 - include/clang/Frontend/ASTUnit.h | 48 +- include/clang/Frontend/CodeGenOptions.def | 346 -- include/clang/Frontend/CodeGenOptions.h | 307 -- include/clang/Frontend/CompilerInstance.h | 15 +- include/clang/Frontend/CompilerInvocation.h | 23 +- include/clang/Frontend/FrontendAction.h | 20 +- include/clang/Frontend/FrontendActions.h | 18 +- include/clang/Frontend/FrontendDiagnostic.h | 15 +- include/clang/Frontend/FrontendOptions.h | 9 +- include/clang/Frontend/LangStandards.def | 3 + include/clang/Frontend/PCHContainerOperations.h | 106 +- include/clang/Frontend/PrecompiledPreamble.h | 26 +- include/clang/Frontend/Utils.h | 19 +- include/clang/Index/IndexDataConsumer.h | 5 + include/clang/Index/IndexSymbol.h | 6 +- include/clang/Index/IndexingAction.h | 11 +- include/clang/Index/USRGeneration.h | 27 +- include/clang/Lex/CodeCompletionHandler.h | 7 + include/clang/Lex/DirectoryLookup.h | 2 +- include/clang/Lex/HeaderMap.h | 3 +- include/clang/Lex/HeaderSearch.h | 26 +- include/clang/Lex/LexDiagnostic.h | 15 +- include/clang/Lex/Lexer.h | 26 +- include/clang/Lex/MacroInfo.h | 3 +- include/clang/Lex/ModuleMap.h | 16 +- include/clang/Lex/PPCallbacks.h | 13 + include/clang/Lex/PTHLexer.h | 107 - include/clang/Lex/PTHManager.h | 149 - include/clang/Lex/Pragma.h | 2 +- include/clang/Lex/PreprocessingRecord.h | 1 + include/clang/Lex/Preprocessor.h | 115 +- include/clang/Lex/PreprocessorLexer.h | 2 +- include/clang/Lex/PreprocessorOptions.h | 19 +- include/clang/Lex/TokenConcatenation.h | 4 +- include/clang/Lex/TokenLexer.h | 44 +- include/clang/Parse/LoopHint.h | 45 + include/clang/Parse/ParseDiagnostic.h | 15 +- include/clang/Parse/Parser.h | 63 +- include/clang/Sema/CodeCompleteConsumer.h | 70 +- include/clang/Sema/CodeCompleteOptions.h | 3 +- include/clang/Sema/DeclSpec.h | 89 +- include/clang/Sema/Initialization.h | 25 +- include/clang/Sema/Lookup.h | 6 +- include/clang/Sema/LoopHint.h | 45 - include/clang/Sema/Overload.h | 13 +- include/clang/Sema/ParsedAttr.h | 228 +- include/clang/Sema/Scope.h | 1 + include/clang/Sema/ScopeInfo.h | 17 + include/clang/Sema/Sema.h | 356 ++- include/clang/Sema/SemaDiagnostic.h | 15 +- include/clang/Serialization/ASTBitCodes.h | 14 +- include/clang/Serialization/ASTReader.h | 37 +- include/clang/Serialization/ASTWriter.h | 18 +- include/clang/Serialization/ContinuousRangeMap.h | 2 +- include/clang/Serialization/GlobalModuleIndex.h | 17 +- .../clang/Serialization/PCHContainerOperations.h | 117 + .../clang/Serialization/SerializationDiagnostic.h | 15 +- .../Checkers/BuiltinCheckerRegistration.h | 37 + .../clang/StaticAnalyzer/Checkers/CheckerBase.td | 50 +- include/clang/StaticAnalyzer/Checkers/Checkers.td | 579 ++-- .../clang/StaticAnalyzer/Checkers/ClangCheckers.h | 22 - .../StaticAnalyzer/Checkers/ObjCRetainCount.h | 232 -- include/clang/StaticAnalyzer/Core/Analyses.def | 1 + .../clang/StaticAnalyzer/Core/AnalyzerOptions.def | 377 +++ .../clang/StaticAnalyzer/Core/AnalyzerOptions.h | 607 +--- .../Core/BugReporter/BugReporterVisitors.h | 39 +- .../StaticAnalyzer/Core/BugReporter/BugType.h | 2 - .../Core/BugReporter/CommonBugCategories.h | 2 +- .../Core/BugReporter/PathDiagnostic.h | 21 +- include/clang/StaticAnalyzer/Core/Checker.h | 2 + include/clang/StaticAnalyzer/Core/CheckerManager.h | 16 +- include/clang/StaticAnalyzer/Core/CheckerOptInfo.h | 44 - .../clang/StaticAnalyzer/Core/CheckerRegistry.h | 148 - .../Core/PathSensitive/AnalysisManager.h | 11 +- .../Core/PathSensitive/BasicValueFactory.h | 3 +- .../StaticAnalyzer/Core/PathSensitive/CallEvent.h | 80 +- .../Core/PathSensitive/CheckerContext.h | 50 - .../Core/PathSensitive/DynamicTypeMap.h | 5 +- .../Core/PathSensitive/Environment.h | 1 + .../Core/PathSensitive/ExplodedGraph.h | 72 +- .../StaticAnalyzer/Core/PathSensitive/ExprEngine.h | 50 +- .../StaticAnalyzer/Core/PathSensitive/MemRegion.h | 65 +- .../Core/PathSensitive/ProgramState.h | 42 +- .../Core/PathSensitive/ProgramStateTrait.h | 108 +- .../Core/PathSensitive/RangedConstraintManager.h | 2 +- .../StaticAnalyzer/Core/PathSensitive/Regions.def | 1 + .../Core/PathSensitive/SMTConstraintManager.h | 281 +- .../StaticAnalyzer/Core/PathSensitive/SMTContext.h | 31 - .../StaticAnalyzer/Core/PathSensitive/SMTConv.h | 753 +++++ .../StaticAnalyzer/Core/PathSensitive/SMTSolver.h | 731 +---- .../Core/PathSensitive/SValBuilder.h | 4 +- .../StaticAnalyzer/Core/PathSensitive/SVals.h | 4 +- .../StaticAnalyzer/Core/PathSensitive/Store.h | 9 +- .../StaticAnalyzer/Core/PathSensitive/SubEngine.h | 5 +- .../Core/PathSensitive/SymbolManager.h | 29 +- .../Core/PathSensitive/TaintManager.h | 10 +- .../StaticAnalyzer/Core/PathSensitive/WorkList.h | 1 + .../StaticAnalyzer/Core/RetainSummaryManager.h | 798 +++++ .../StaticAnalyzer/Frontend/CheckerRegistration.h | 4 +- .../StaticAnalyzer/Frontend/CheckerRegistry.h | 153 + .../StaticAnalyzer/Frontend/FrontendActions.h | 7 +- include/clang/Tooling/AllTUsExecution.h | 4 + include/clang/Tooling/CompilationDatabase.h | 21 - .../Tooling/CompilationDatabasePluginRegistry.h | 21 + include/clang/Tooling/DiagnosticsYaml.h | 10 + include/clang/Tooling/Execution.h | 9 + .../Tooling/Refactoring/RecursiveSymbolVisitor.h | 2 +- .../Tooling/Refactoring/RefactoringDiagnostic.h | 17 +- include/clang/Tooling/StandaloneExecution.h | 5 +- include/clang/Tooling/Tooling.h | 31 +- include/clang/module.modulemap | 22 +- 275 files changed, 18814 insertions(+), 11302 deletions(-) create mode 100644 include/clang/AST/ASTContextAllocate.h create mode 100644 include/clang/AST/ASTDumperUtils.h create mode 100644 include/clang/AST/ASTImporterLookupTable.h create mode 100644 include/clang/AST/AttrVisitor.h create mode 100644 include/clang/AST/FormatString.h create mode 100644 include/clang/AST/OSLog.h create mode 100644 include/clang/AST/TemplateArgumentVisitor.h create mode 100644 include/clang/AST/TextNodeDumper.h create mode 100644 include/clang/Analysis/Analyses/ExprMutationAnalyzer.h delete mode 100644 include/clang/Analysis/Analyses/FormatString.h delete mode 100644 include/clang/Analysis/Analyses/OSLog.h delete mode 100644 include/clang/Analysis/Analyses/PseudoConstantAnalysis.h create mode 100644 include/clang/Analysis/SelectorExtras.h delete mode 100644 include/clang/Basic/BuiltinsNios2.def create mode 100644 include/clang/Basic/CodeGenOptions.def create mode 100644 include/clang/Basic/CodeGenOptions.h create mode 100644 include/clang/Basic/DiagnosticAST.h create mode 100644 include/clang/Basic/DiagnosticAnalysis.h create mode 100644 include/clang/Basic/DiagnosticComment.h create mode 100644 include/clang/Basic/DiagnosticCrossTU.h create mode 100644 include/clang/Basic/DiagnosticDriver.h create mode 100644 include/clang/Basic/DiagnosticFrontend.h create mode 100644 include/clang/Basic/DiagnosticLex.h create mode 100644 include/clang/Basic/DiagnosticParse.h create mode 100644 include/clang/Basic/DiagnosticRefactoring.h create mode 100644 include/clang/Basic/DiagnosticSema.h create mode 100644 include/clang/Basic/DiagnosticSerialization.h create mode 100644 include/clang/Basic/FixedPoint.h create mode 100644 include/clang/Basic/MSP430Target.def create mode 100644 include/clang/Basic/OpenCLExtensionTypes.def delete mode 100644 include/clang/Basic/VirtualFileSystem.h create mode 100644 include/clang/Driver/DarwinSDKInfo.h delete mode 100644 include/clang/Frontend/CodeGenOptions.def delete mode 100644 include/clang/Frontend/CodeGenOptions.h delete mode 100644 include/clang/Lex/PTHLexer.h delete mode 100644 include/clang/Lex/PTHManager.h create mode 100644 include/clang/Parse/LoopHint.h delete mode 100644 include/clang/Sema/LoopHint.h create mode 100644 include/clang/Serialization/PCHContainerOperations.h create mode 100644 include/clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h delete mode 100644 include/clang/StaticAnalyzer/Checkers/ClangCheckers.h delete mode 100644 include/clang/StaticAnalyzer/Checkers/ObjCRetainCount.h create mode 100644 include/clang/StaticAnalyzer/Core/AnalyzerOptions.def delete mode 100644 include/clang/StaticAnalyzer/Core/CheckerOptInfo.h delete mode 100644 include/clang/StaticAnalyzer/Core/CheckerRegistry.h delete mode 100644 include/clang/StaticAnalyzer/Core/PathSensitive/SMTContext.h create mode 100644 include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h create mode 100644 include/clang/StaticAnalyzer/Core/RetainSummaryManager.h create mode 100644 include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h (limited to 'include/clang') diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index a9ab687a8de9e..13870116c7fd5 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -15,6 +15,7 @@ #ifndef LLVM_CLANG_AST_ASTCONTEXT_H #define LLVM_CLANG_AST_ASTCONTEXT_H +#include "clang/AST/ASTContextAllocate.h" #include "clang/AST/ASTTypeTraits.h" #include "clang/AST/CanonicalType.h" #include "clang/AST/CommentCommandTraits.h" @@ -22,6 +23,7 @@ #include "clang/AST/Decl.h" #include "clang/AST/DeclBase.h" #include "clang/AST/DeclarationName.h" +#include "clang/AST/Expr.h" #include "clang/AST/ExternalASTSource.h" #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/PrettyPrinter.h" @@ -30,6 +32,7 @@ #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/Basic/AddressSpaces.h" +#include "clang/Basic/AttrKinds.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" @@ -79,6 +82,7 @@ struct fltSemantics; namespace clang { +class APFixedPoint; class APValue; class ASTMutationListener; class ASTRecordLayout; @@ -92,6 +96,7 @@ class CXXMethodDecl; class CXXRecordDecl; class DiagnosticsEngine; class Expr; +class FixedPointSemantics; class MangleContext; class MangleNumberingContext; class MaterializeTemporaryExpr; @@ -148,6 +153,22 @@ struct TypeInfo { /// Holds long-lived AST nodes (such as types and decls) that can be /// referred to throughout the semantic analysis of a file. class ASTContext : public RefCountedBase { +public: + /// Copy initialization expr of a __block variable and a boolean flag that + /// indicates whether the expression can throw. + struct BlockVarCopyInit { + BlockVarCopyInit() = default; + BlockVarCopyInit(Expr *CopyExpr, bool CanThrow) + : ExprAndFlag(CopyExpr, CanThrow) {} + void setExprAndFlag(Expr *CopyExpr, bool CanThrow) { + ExprAndFlag.setPointerAndInt(CopyExpr, CanThrow); + } + Expr *getCopyExpr() const { return ExprAndFlag.getPointer(); } + bool canThrow() const { return ExprAndFlag.getInt(); } + llvm::PointerIntPair ExprAndFlag; + }; + +private: friend class NestedNameSpecifier; mutable SmallVector Types; @@ -242,8 +263,8 @@ class ASTContext : public RefCountedBase { /// interface. llvm::DenseMap ObjCMethodRedecls; - /// Mapping from __block VarDecls to their copy initialization expr. - llvm::DenseMap BlockVarCopyInits; + /// Mapping from __block VarDecls to BlockVarCopyInit. + llvm::DenseMap BlockVarCopyInits; /// Mapping from class scope functions specialization to their /// template patterns. @@ -316,7 +337,7 @@ class ASTContext : public RefCountedBase { mutable IdentifierInfo *BoolName = nullptr; /// The identifier 'NSObject'. - IdentifierInfo *NSObjectName = nullptr; + mutable IdentifierInfo *NSObjectName = nullptr; /// The identifier 'NSCopying'. IdentifierInfo *NSCopyingName = nullptr; @@ -549,26 +570,6 @@ public: IntrusiveRefCntPtr ExternalSource; ASTMutationListener *Listener = nullptr; - /// Contains parents of a node. - using ParentVector = llvm::SmallVector; - - /// Maps from a node to its parents. This is used for nodes that have - /// pointer identity only, which are more common and we can save space by - /// only storing a unique pointer to them. - using ParentMapPointers = - llvm::DenseMap>; - - /// Parent map for nodes without pointer identity. We store a full - /// DynTypedNode for all keys. - using ParentMapOtherNodes = - llvm::DenseMap>; - /// Container for either a single DynTypedNode or for an ArrayRef to /// DynTypedNode. For use with ParentMap. class DynTypedNodeList { @@ -610,7 +611,17 @@ public: } }; - /// Returns the parents of the given node. + // A traversal scope limits the parts of the AST visible to certain analyses. + // RecursiveASTVisitor::TraverseAST will only visit reachable nodes, and + // getParents() will only observe reachable parent edges. + // + // The scope is defined by a set of "top-level" declarations. + // Initially, it is the entire TU: {getTranslationUnitDecl()}. + // Changing the scope clears the parent cache, which is expensive to rebuild. + std::vector getTraversalScope() const { return TraversalScope; } + void setTraversalScope(const std::vector &); + + /// Returns the parents of the given node (within the traversal scope). /// /// Note that this will lazily compute the parents of all nodes /// and store them for later retrieval. Thus, the first call is O(n) @@ -977,7 +988,8 @@ public: /// Get the additional modules in which the definition \p Def has /// been merged. ArrayRef getModulesWithMergedDefinition(const NamedDecl *Def) { - auto MergedIt = MergedDefModules.find(Def); + auto MergedIt = + MergedDefModules.find(cast(Def->getCanonicalDecl())); if (MergedIt == MergedDefModules.end()) return None; return MergedIt->second; @@ -1041,6 +1053,9 @@ public: CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy; CanQualType OCLQueueTy, OCLReserveIDTy; CanQualType OMPArraySectionTy; +#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ + CanQualType Id##Ty; +#include "clang/Basic/OpenCLExtensionTypes.def" // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. mutable QualType AutoDeductTy; // Deduction against 'auto'. @@ -1403,7 +1418,7 @@ public: QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const; - QualType getAttributedType(AttributedType::Kind attrKind, + QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType); @@ -1656,7 +1671,7 @@ public: } /// Retrieve the identifier 'NSObject'. - IdentifierInfo *getNSObjectName() { + IdentifierInfo *getNSObjectName() const { if (!NSObjectName) { NSObjectName = &Idents.get("NSObject"); } @@ -1961,6 +1976,9 @@ public: unsigned char getFixedPointScale(QualType Ty) const; unsigned char getFixedPointIBits(QualType Ty) const; + FixedPointSemantics getFixedPointSemantics(QualType Ty) const; + APFixedPoint getFixedPointMax(QualType Ty) const; + APFixedPoint getFixedPointMin(QualType Ty) const; DeclarationNameInfo getNameForTemplate(TemplateName Name, SourceLocation NameLoc) const; @@ -2488,6 +2506,8 @@ public: unsigned getTargetAddressSpace(LangAS AS) const; + LangAS getLangASForBuiltinAddressSpace(unsigned AS) const; + /// Get target-dependent integer value for null pointer which is used for /// constant folding. uint64_t getTargetNullPointerValue(QualType QT) const; @@ -2657,12 +2677,13 @@ public: /// otherwise returns null. const ObjCInterfaceDecl *getObjContainingInterface(const NamedDecl *ND) const; - /// Set the copy inialization expression of a block var decl. - void setBlockVarCopyInits(VarDecl*VD, Expr* Init); + /// Set the copy inialization expression of a block var decl. \p CanThrow + /// indicates whether the copy expression can throw or not. + void setBlockVarCopyInit(const VarDecl* VD, Expr *CopyExpr, bool CanThrow); /// Get the copy initialization expression of the VarDecl \p VD, or /// nullptr if none exists. - Expr *getBlockVarCopyInits(const VarDecl* VD); + BlockVarCopyInit getBlockVarCopyInit(const VarDecl* VD) const; /// Allocate an uninitialized TypeSourceInfo. /// @@ -2718,7 +2739,7 @@ public: /// predicate. void forEachMultiversionedFunctionVersion( const FunctionDecl *FD, - llvm::function_ref Pred) const; + llvm::function_ref Pred) const; const CXXConstructorDecl * getCopyConstructorForExceptionObject(CXXRecordDecl *RD); @@ -2894,13 +2915,13 @@ private: // but we include it here so that ASTContext can quickly deallocate them. llvm::PointerIntPair LastSDM; - std::unique_ptr PointerParents; - std::unique_ptr OtherParents; + std::vector TraversalScope; + class ParentMap; + std::unique_ptr Parents; std::unique_ptr VTContext; void ReleaseDeclContextMaps(); - void ReleaseParentMapEntries(); public: enum PragmaSectionFlag : unsigned { @@ -2949,8 +2970,8 @@ inline Selector GetUnarySelector(StringRef name, ASTContext &Ctx) { /// This placement form of operator new uses the ASTContext's allocator for /// obtaining memory. /// -/// IMPORTANT: These are also declared in clang/AST/AttrIterator.h! Any changes -/// here need to also be made there. +/// IMPORTANT: These are also declared in clang/AST/ASTContextAllocate.h! +/// Any changes here need to also be made there. /// /// We intentionally avoid using a nothrow specification here so that the calls /// to this operator will not perform a null check on the result -- the @@ -2973,7 +2994,7 @@ inline Selector GetUnarySelector(StringRef name, ASTContext &Ctx) { /// allocator supports it). /// @return The allocated memory. Could be nullptr. inline void *operator new(size_t Bytes, const clang::ASTContext &C, - size_t Alignment) { + size_t Alignment /* = 8 */) { return C.Allocate(Bytes, Alignment); } @@ -3011,7 +3032,7 @@ inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) { /// allocator supports it). /// @return The allocated memory. Could be nullptr. inline void *operator new[](size_t Bytes, const clang::ASTContext& C, - size_t Alignment = 8) { + size_t Alignment /* = 8 */) { return C.Allocate(Bytes, Alignment); } diff --git a/include/clang/AST/ASTContextAllocate.h b/include/clang/AST/ASTContextAllocate.h new file mode 100644 index 0000000000000..5b9eed208a4d1 --- /dev/null +++ b/include/clang/AST/ASTContextAllocate.h @@ -0,0 +1,38 @@ +//===- ASTContextAllocate.h - ASTContext allocate functions -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file declares ASTContext allocation functions separate from the main +// code in ASTContext.h. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_ASTCONTEXTALLOCATE_H +#define LLVM_CLANG_AST_ASTCONTEXTALLOCATE_H + +#include + +namespace clang { + +class ASTContext; + +} // namespace clang + +// Defined in ASTContext.h +void *operator new(size_t Bytes, const clang::ASTContext &C, + size_t Alignment = 8); +void *operator new[](size_t Bytes, const clang::ASTContext &C, + size_t Alignment = 8); + +// It is good practice to pair new/delete operators. Also, MSVC gives many +// warnings if a matching delete overload is not declared, even though the +// throw() spec guarantees it will not be implicitly called. +void operator delete(void *Ptr, const clang::ASTContext &C, size_t); +void operator delete[](void *Ptr, const clang::ASTContext &C, size_t); + +#endif // LLVM_CLANG_AST_ASTCONTEXTALLOCATE_H diff --git a/include/clang/AST/ASTDiagnostic.h b/include/clang/AST/ASTDiagnostic.h index 2534272da3a30..fe92604587ef7 100644 --- a/include/clang/AST/ASTDiagnostic.h +++ b/include/clang/AST/ASTDiagnostic.h @@ -11,19 +11,9 @@ #define LLVM_CLANG_AST_ASTDIAGNOSTIC_H #include "clang/Basic/Diagnostic.h" +#include "clang/Basic/DiagnosticAST.h" namespace clang { - namespace diag { - enum { -#define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\ - SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY) ENUM, -#define ASTSTART -#include "clang/Basic/DiagnosticASTKinds.inc" -#undef DIAG - NUM_BUILTIN_AST_DIAGNOSTICS - }; - } // end namespace diag - /// DiagnosticsEngine argument formatting function for diagnostics that /// involve AST nodes. /// diff --git a/include/clang/AST/ASTDumperUtils.h b/include/clang/AST/ASTDumperUtils.h new file mode 100644 index 0000000000000..5e62e902b4231 --- /dev/null +++ b/include/clang/AST/ASTDumperUtils.h @@ -0,0 +1,97 @@ +//===--- ASTDumperUtils.h - Printing of AST nodes -------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements AST utilities for traversal down the tree. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_ASTDUMPERUTILS_H +#define LLVM_CLANG_AST_ASTDUMPERUTILS_H + +#include "llvm/Support/raw_ostream.h" + +namespace clang { + +// Colors used for various parts of the AST dump +// Do not use bold yellow for any text. It is hard to read on white screens. + +struct TerminalColor { + llvm::raw_ostream::Colors Color; + bool Bold; +}; + +// Red - CastColor +// Green - TypeColor +// Bold Green - DeclKindNameColor, UndeserializedColor +// Yellow - AddressColor, LocationColor +// Blue - CommentColor, NullColor, IndentColor +// Bold Blue - AttrColor +// Bold Magenta - StmtColor +// Cyan - ValueKindColor, ObjectKindColor +// Bold Cyan - ValueColor, DeclNameColor + +// Decl kind names (VarDecl, FunctionDecl, etc) +static const TerminalColor DeclKindNameColor = {llvm::raw_ostream::GREEN, true}; +// Attr names (CleanupAttr, GuardedByAttr, etc) +static const TerminalColor AttrColor = {llvm::raw_ostream::BLUE, true}; +// Statement names (DeclStmt, ImplicitCastExpr, etc) +static const TerminalColor StmtColor = {llvm::raw_ostream::MAGENTA, true}; +// Comment names (FullComment, ParagraphComment, TextComment, etc) +static const TerminalColor CommentColor = {llvm::raw_ostream::BLUE, false}; + +// Type names (int, float, etc, plus user defined types) +static const TerminalColor TypeColor = {llvm::raw_ostream::GREEN, false}; + +// Pointer address +static const TerminalColor AddressColor = {llvm::raw_ostream::YELLOW, false}; +// Source locations +static const TerminalColor LocationColor = {llvm::raw_ostream::YELLOW, false}; + +// lvalue/xvalue +static const TerminalColor ValueKindColor = {llvm::raw_ostream::CYAN, false}; +// bitfield/objcproperty/objcsubscript/vectorcomponent +static const TerminalColor ObjectKindColor = {llvm::raw_ostream::CYAN, false}; + +// Null statements +static const TerminalColor NullColor = {llvm::raw_ostream::BLUE, false}; + +// Undeserialized entities +static const TerminalColor UndeserializedColor = {llvm::raw_ostream::GREEN, + true}; + +// CastKind from CastExpr's +static const TerminalColor CastColor = {llvm::raw_ostream::RED, false}; + +// Value of the statement +static const TerminalColor ValueColor = {llvm::raw_ostream::CYAN, true}; +// Decl names +static const TerminalColor DeclNameColor = {llvm::raw_ostream::CYAN, true}; + +// Indents ( `, -. | ) +static const TerminalColor IndentColor = {llvm::raw_ostream::BLUE, false}; + +class ColorScope { + llvm::raw_ostream &OS; + const bool ShowColors; + +public: + ColorScope(llvm::raw_ostream &OS, bool ShowColors, TerminalColor Color) + : OS(OS), ShowColors(ShowColors) { + if (ShowColors) + OS.changeColor(Color.Color, Color.Bold); + } + ~ColorScope() { + if (ShowColors) + OS.resetColor(); + } +}; + +} // namespace clang + +#endif // LLVM_CLANG_AST_ASTDUMPERUTILS_H diff --git a/include/clang/AST/ASTImporter.h b/include/clang/AST/ASTImporter.h index 2e9a8775a8a23..dbb9cf35ddead 100644 --- a/include/clang/AST/ASTImporter.h +++ b/include/clang/AST/ASTImporter.h @@ -25,12 +25,15 @@ #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Error.h" #include namespace clang { class ASTContext; +class ASTImporterLookupTable; class CXXBaseSpecifier; class CXXCtorInitializer; class Decl; @@ -43,6 +46,29 @@ class TagDecl; class TypeSourceInfo; class Attr; + class ImportError : public llvm::ErrorInfo { + public: + /// \brief Kind of error when importing an AST component. + enum ErrorKind { + NameConflict, /// Naming ambiguity (likely ODR violation). + UnsupportedConstruct, /// Not supported node or case. + Unknown /// Other error. + }; + + ErrorKind Error; + + static char ID; + + ImportError() : Error(Unknown) { } + ImportError(const ImportError &Other) : Error(Other.Error) { } + ImportError(ErrorKind Error) : Error(Error) { } + + std::string toString() const; + + void log(raw_ostream &OS) const override; + std::error_code convertToErrorCode() const override; + }; + // \brief Returns with a list of declarations started from the canonical decl // then followed by subsequent decls in the translation unit. // This gives a canonical list for each entry in the redecl chain. @@ -55,12 +81,21 @@ class Attr; /// Imports selected nodes from one AST context into another context, /// merging AST nodes where appropriate. class ASTImporter { + friend class ASTNodeImporter; public: using NonEquivalentDeclSet = llvm::DenseSet>; using ImportedCXXBaseSpecifierMap = llvm::DenseMap; private: + + /// Pointer to the import specific lookup table, which may be shared + /// amongst several ASTImporter objects. + /// This is an externally managed resource (and should exist during the + /// lifetime of the ASTImporter object) + /// If not set then the original C/C++ lookup is used. + ASTImporterLookupTable *LookupTable = nullptr; + /// The contexts we're importing to and from. ASTContext &ToContext, &FromContext; @@ -98,9 +133,13 @@ class Attr; /// (which we have already complained about). NonEquivalentDeclSet NonEquivalentDecls; + using FoundDeclsTy = SmallVector; + FoundDeclsTy findDeclsInToCtx(DeclContext *DC, DeclarationName Name); + + void AddToLookupTable(Decl *ToD); + public: - /// Create a new AST importer. - /// + /// \param ToContext The context we'll be importing into. /// /// \param ToFileManager The file manager we'll be importing into. @@ -112,9 +151,14 @@ class Attr; /// \param MinimalImport If true, the importer will attempt to import /// as little as it can, e.g., by importing declarations as forward /// declarations that can be completed at a later point. + /// + /// \param LookupTable The importer specific lookup table which may be + /// shared amongst several ASTImporter objects. + /// If not set then the original C/C++ lookup is used. ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, - bool MinimalImport); + bool MinimalImport, + ASTImporterLookupTable *LookupTable = nullptr); virtual ~ASTImporter(); @@ -122,31 +166,60 @@ class Attr; /// to-be-completed forward declarations when possible. bool isMinimalImport() const { return Minimal; } + /// \brief Import the given object, returns the result. + /// + /// \param To Import the object into this variable. + /// \param From Object to import. + /// \return Error information (success or error). + template + LLVM_NODISCARD llvm::Error importInto(ImportT &To, const ImportT &From) { + To = Import(From); + if (From && !To) + return llvm::make_error(); + return llvm::Error::success(); + // FIXME: this should be the final code + //auto ToOrErr = Import(From); + //if (ToOrErr) + // To = *ToOrErr; + //return ToOrErr.takeError(); + } + /// Import the given type from the "from" context into the "to" - /// context. + /// context. A null type is imported as a null type (no error). /// - /// \returns the equivalent type in the "to" context, or a NULL type if - /// an error occurred. + /// \returns The equivalent type in the "to" context, or the import error. + llvm::Expected Import_New(QualType FromT); + // FIXME: Remove this version. QualType Import(QualType FromT); /// Import the given type source information from the /// "from" context into the "to" context. /// - /// \returns the equivalent type source information in the "to" - /// context, or NULL if an error occurred. + /// \returns The equivalent type source information in the "to" + /// context, or the import error. + llvm::Expected Import_New(TypeSourceInfo *FromTSI); + // FIXME: Remove this version. TypeSourceInfo *Import(TypeSourceInfo *FromTSI); /// Import the given attribute from the "from" context into the /// "to" context. /// - /// \returns the equivalent attribute in the "to" context. + /// \returns The equivalent attribute in the "to" context, or the import + /// error. + llvm::Expected Import_New(const Attr *FromAttr); + // FIXME: Remove this version. Attr *Import(const Attr *FromAttr); /// Import the given declaration from the "from" context into the /// "to" context. /// - /// \returns the equivalent declaration in the "to" context, or a NULL type - /// if an error occurred. + /// \returns The equivalent declaration in the "to" context, or the import + /// error. + llvm::Expected Import_New(Decl *FromD); + llvm::Expected Import_New(const Decl *FromD) { + return Import_New(const_cast(FromD)); + } + // FIXME: Remove this version. Decl *Import(Decl *FromD); Decl *Import(const Decl *FromD) { return Import(const_cast(FromD)); @@ -155,104 +228,137 @@ class Attr; /// Return the copy of the given declaration in the "to" context if /// it has already been imported from the "from" context. Otherwise return /// NULL. - Decl *GetAlreadyImportedOrNull(Decl *FromD); + Decl *GetAlreadyImportedOrNull(const Decl *FromD) const; /// Import the given declaration context from the "from" /// AST context into the "to" AST context. /// /// \returns the equivalent declaration context in the "to" - /// context, or a NULL type if an error occurred. - DeclContext *ImportContext(DeclContext *FromDC); + /// context, or error value. + llvm::Expected ImportContext(DeclContext *FromDC); /// Import the given expression from the "from" context into the /// "to" context. /// - /// \returns the equivalent expression in the "to" context, or NULL if - /// an error occurred. + /// \returns The equivalent expression in the "to" context, or the import + /// error. + llvm::Expected Import_New(Expr *FromE); + // FIXME: Remove this version. Expr *Import(Expr *FromE); /// Import the given statement from the "from" context into the /// "to" context. /// - /// \returns the equivalent statement in the "to" context, or NULL if - /// an error occurred. + /// \returns The equivalent statement in the "to" context, or the import + /// error. + llvm::Expected Import_New(Stmt *FromS); + // FIXME: Remove this version. Stmt *Import(Stmt *FromS); /// Import the given nested-name-specifier from the "from" /// context into the "to" context. /// - /// \returns the equivalent nested-name-specifier in the "to" - /// context, or NULL if an error occurred. + /// \returns The equivalent nested-name-specifier in the "to" + /// context, or the import error. + llvm::Expected + Import_New(NestedNameSpecifier *FromNNS); + // FIXME: Remove this version. NestedNameSpecifier *Import(NestedNameSpecifier *FromNNS); - /// Import the given nested-name-specifier from the "from" + /// Import the given nested-name-specifier-loc from the "from" /// context into the "to" context. /// - /// \returns the equivalent nested-name-specifier in the "to" - /// context. + /// \returns The equivalent nested-name-specifier-loc in the "to" + /// context, or the import error. + llvm::Expected + Import_New(NestedNameSpecifierLoc FromNNS); + // FIXME: Remove this version. NestedNameSpecifierLoc Import(NestedNameSpecifierLoc FromNNS); - /// Import the goven template name from the "from" context into the - /// "to" context. + /// Import the given template name from the "from" context into the + /// "to" context, or the import error. + llvm::Expected Import_New(TemplateName From); + // FIXME: Remove this version. TemplateName Import(TemplateName From); /// Import the given source location from the "from" context into /// the "to" context. /// - /// \returns the equivalent source location in the "to" context, or an - /// invalid source location if an error occurred. + /// \returns The equivalent source location in the "to" context, or the + /// import error. + llvm::Expected Import_New(SourceLocation FromLoc); + // FIXME: Remove this version. SourceLocation Import(SourceLocation FromLoc); /// Import the given source range from the "from" context into /// the "to" context. /// - /// \returns the equivalent source range in the "to" context, or an - /// invalid source location if an error occurred. + /// \returns The equivalent source range in the "to" context, or the import + /// error. + llvm::Expected Import_New(SourceRange FromRange); + // FIXME: Remove this version. SourceRange Import(SourceRange FromRange); /// Import the given declaration name from the "from" /// context into the "to" context. /// - /// \returns the equivalent declaration name in the "to" context, - /// or an empty declaration name if an error occurred. + /// \returns The equivalent declaration name in the "to" context, or the + /// import error. + llvm::Expected Import_New(DeclarationName FromName); + // FIXME: Remove this version. DeclarationName Import(DeclarationName FromName); /// Import the given identifier from the "from" context /// into the "to" context. /// - /// \returns the equivalent identifier in the "to" context. + /// \returns The equivalent identifier in the "to" context. Note: It + /// returns nullptr only if the FromId was nullptr. IdentifierInfo *Import(const IdentifierInfo *FromId); /// Import the given Objective-C selector from the "from" /// context into the "to" context. /// - /// \returns the equivalent selector in the "to" context. + /// \returns The equivalent selector in the "to" context, or the import + /// error. + llvm::Expected Import_New(Selector FromSel); + // FIXME: Remove this version. Selector Import(Selector FromSel); /// Import the given file ID from the "from" context into the /// "to" context. /// - /// \returns the equivalent file ID in the source manager of the "to" - /// context. + /// \returns The equivalent file ID in the source manager of the "to" + /// context, or the import error. + llvm::Expected Import_New(FileID); + // FIXME: Remove this version. FileID Import(FileID); /// Import the given C++ constructor initializer from the "from" /// context into the "to" context. /// - /// \returns the equivalent initializer in the "to" context. + /// \returns The equivalent initializer in the "to" context, or the import + /// error. + llvm::Expected + Import_New(CXXCtorInitializer *FromInit); + // FIXME: Remove this version. CXXCtorInitializer *Import(CXXCtorInitializer *FromInit); /// Import the given CXXBaseSpecifier from the "from" context into /// the "to" context. /// - /// \returns the equivalent CXXBaseSpecifier in the source manager of the - /// "to" context. + /// \returns The equivalent CXXBaseSpecifier in the source manager of the + /// "to" context, or the import error. + llvm::Expected + Import_New(const CXXBaseSpecifier *FromSpec); + // FIXME: Remove this version. CXXBaseSpecifier *Import(const CXXBaseSpecifier *FromSpec); /// Import the definition of the given declaration, including all of /// the declarations it contains. - /// - /// This routine is intended to be used + LLVM_NODISCARD llvm::Error ImportDefinition_New(Decl *From); + + // FIXME: Compatibility function. + // Usages of this should be changed to ImportDefinition_New. void ImportDefinition(Decl *From); /// Cope with a name conflict when importing a declaration into the @@ -333,6 +439,13 @@ class Attr; /// equivalent. bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain = true); + + /// Determine the index of a field in its parent record. + /// F should be a field (or indirect field) declaration. + /// \returns The index of the field in its parent context (starting from 0). + /// On error `None` is returned (parent context is non-record). + static llvm::Optional getFieldIndex(Decl *F); + }; } // namespace clang diff --git a/include/clang/AST/ASTImporterLookupTable.h b/include/clang/AST/ASTImporterLookupTable.h new file mode 100644 index 0000000000000..14cafe817ddc8 --- /dev/null +++ b/include/clang/AST/ASTImporterLookupTable.h @@ -0,0 +1,75 @@ +//===- ASTImporterLookupTable.h - ASTImporter specific lookup--*- C++ -*---===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the ASTImporterLookupTable class which implements a +// lookup procedure for the import mechanism. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_ASTIMPORTERLOOKUPTABLE_H +#define LLVM_CLANG_AST_ASTIMPORTERLOOKUPTABLE_H + +#include "clang/AST/DeclBase.h" // lookup_result +#include "clang/AST/DeclarationName.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SetVector.h" + +namespace clang { + +class ASTContext; +class NamedDecl; +class DeclContext; + +// There are certain cases when normal C/C++ lookup (localUncachedLookup) +// does not find AST nodes. E.g.: +// Example 1: +// template +// struct X { +// friend void foo(); // this is never found in the DC of the TU. +// }; +// Example 2: +// // The fwd decl to Foo is not found in the lookupPtr of the DC of the +// // translation unit decl. +// // Here we could find the node by doing a traverse throught the list of +// // the Decls in the DC, but that would not scale. +// struct A { struct Foo *p; }; +// This is a severe problem because the importer decides if it has to create a +// new Decl or not based on the lookup results. +// To overcome these cases we need an importer specific lookup table which +// holds every node and we are not interested in any C/C++ specific visibility +// considerations. Simply, we must know if there is an existing Decl in a +// given DC. Once we found it then we can handle any visibility related tasks. +class ASTImporterLookupTable { + + // We store a list of declarations for each name. + // And we collect these lists for each DeclContext. + // We could have a flat map with (DeclContext, Name) tuple as key, but a two + // level map seems easier to handle. + using DeclList = llvm::SmallSetVector; + using NameMap = llvm::SmallDenseMap; + using DCMap = llvm::DenseMap; + + void add(DeclContext *DC, NamedDecl *ND); + void remove(DeclContext *DC, NamedDecl *ND); + + DCMap LookupTable; + +public: + ASTImporterLookupTable(TranslationUnitDecl &TU); + void add(NamedDecl *ND); + void remove(NamedDecl *ND); + using LookupResult = DeclList; + LookupResult lookup(DeclContext *DC, DeclarationName Name) const; + void dump(DeclContext *DC) const; + void dump() const; +}; + +} // namespace clang + +#endif // LLVM_CLANG_AST_ASTIMPORTERLOOKUPTABLE_H diff --git a/include/clang/AST/ASTStructuralEquivalence.h b/include/clang/AST/ASTStructuralEquivalence.h index d32f87d43e041..f8847505bc72e 100644 --- a/include/clang/AST/ASTStructuralEquivalence.h +++ b/include/clang/AST/ASTStructuralEquivalence.h @@ -15,6 +15,7 @@ #ifndef LLVM_CLANG_AST_ASTSTRUCTURALEQUIVALENCE_H #define LLVM_CLANG_AST_ASTSTRUCTURALEQUIVALENCE_H +#include "clang/AST/DeclBase.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/Optional.h" @@ -114,8 +115,19 @@ struct StructuralEquivalenceContext { private: /// Finish checking all of the structural equivalences. /// - /// \returns true if an error occurred, false otherwise. + /// \returns true if the equivalence check failed (non-equivalence detected), + /// false if equivalence was detected. bool Finish(); + + /// Check for common properties at Finish. + /// \returns true if D1 and D2 may be equivalent, + /// false if they are for sure not. + bool CheckCommonEquivalence(Decl *D1, Decl *D2); + + /// Check for class dependent properties at Finish. + /// \returns true if D1 and D2 may be equivalent, + /// false if they are for sure not. + bool CheckKindSpecificEquivalence(Decl *D1, Decl *D2); }; } // namespace clang diff --git a/include/clang/AST/ASTVector.h b/include/clang/AST/ASTVector.h index 80cd6b7007a6d..51de119f080e5 100644 --- a/include/clang/AST/ASTVector.h +++ b/include/clang/AST/ASTVector.h @@ -18,6 +18,7 @@ #ifndef LLVM_CLANG_AST_ASTVECTOR_H #define LLVM_CLANG_AST_ASTVECTOR_H +#include "clang/AST/ASTContextAllocate.h" #include "llvm/ADT/PointerIntPair.h" #include #include diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h index 20922742f687b..3a319326d269a 100644 --- a/include/clang/AST/Attr.h +++ b/include/clang/AST/Attr.h @@ -14,6 +14,7 @@ #ifndef LLVM_CLANG_AST_ATTR_H #define LLVM_CLANG_AST_ATTR_H +#include "clang/AST/ASTContextAllocate.h" // For Attrs.inc #include "clang/AST/AttrIterator.h" #include "clang/AST/Decl.h" #include "clang/AST/Expr.h" @@ -113,6 +114,19 @@ public: void printPretty(raw_ostream &OS, const PrintingPolicy &Policy) const; }; +class TypeAttr : public Attr { +protected: + TypeAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex, + bool IsLateParsed) + : Attr(AK, R, SpellingListIndex, IsLateParsed) {} + +public: + static bool classof(const Attr *A) { + return A->getKind() >= attr::FirstTypeAttr && + A->getKind() <= attr::LastTypeAttr; + } +}; + class StmtAttr : public Attr { protected: StmtAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex, diff --git a/include/clang/AST/AttrIterator.h b/include/clang/AST/AttrIterator.h index 2087ecc0e70c7..43ad1c9319679 100644 --- a/include/clang/AST/AttrIterator.h +++ b/include/clang/AST/AttrIterator.h @@ -26,25 +26,6 @@ namespace clang { class ASTContext; class Attr; -} // namespace clang - -// Defined in ASTContext.h -void *operator new(size_t Bytes, const clang::ASTContext &C, - size_t Alignment = 8); - -// FIXME: Being forced to not have a default argument here due to redeclaration -// rules on default arguments sucks -void *operator new[](size_t Bytes, const clang::ASTContext &C, - size_t Alignment); - -// It is good practice to pair new/delete operators. Also, MSVC gives many -// warnings if a matching delete overload is not declared, even though the -// throw() spec guarantees it will not be implicitly called. -void operator delete(void *Ptr, const clang::ASTContext &C, size_t); -void operator delete[](void *Ptr, const clang::ASTContext &C, size_t); - -namespace clang { - /// AttrVec - A vector of Attr, which is how they are stored on the AST. using AttrVec = SmallVector; diff --git a/include/clang/AST/AttrVisitor.h b/include/clang/AST/AttrVisitor.h new file mode 100644 index 0000000000000..867f9e7ad18da --- /dev/null +++ b/include/clang/AST/AttrVisitor.h @@ -0,0 +1,76 @@ +//===- AttrVisitor.h - Visitor for Attr subclasses --------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the AttrVisitor interface. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_ATTRVISITOR_H +#define LLVM_CLANG_AST_ATTRVISITOR_H + +#include "clang/AST/Attr.h" + +namespace clang { + +namespace attrvisitor { + +/// A simple visitor class that helps create attribute visitors. +template