diff options
author | Gabor Marton <gabor.marton@ericsson.com> | 2019-07-01 15:37:07 +0000 |
---|---|---|
committer | Gabor Marton <gabor.marton@ericsson.com> | 2019-07-01 15:37:07 +0000 |
commit | 91dc12c934ac8b6828f9553d52cd43c3007caa2a (patch) | |
tree | 0e3f3004ab003eb781cf22a58e26d96594332549 /include/clang/AST | |
parent | 44f7b2cea9a2ae54023740cf1a8c067d6b0e090a (diff) | |
download | clang-91dc12c934ac8b6828f9553d52cd43c3007caa2a.tar.gz |
[ASTImporter] Mark erroneous nodes in shared st
Summary:
Now we store the errors for the Decls in the "to" context too. For
that, however, we have to put these errors in a shared state (among all
the ASTImporter objects which handle the same "to" context but different
"from" contexts).
After a series of imports from different "from" TUs we have a "to" context
which may have erroneous nodes in it. (Remember, the AST is immutable so
there is no way to delete a node once we had created it and we realized
the error later.) All these erroneous nodes are marked in
ASTImporterSharedState::ImportErrors. Clients of the ASTImporter may
use this as an input. E.g. the static analyzer engine may not try to
analyze a function if that is marked as erroneous (it can be queried via
ASTImporterSharedState::getImportDeclErrorIfAny()).
Reviewers: a_sidorin, a.sidorin, shafik
Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62376
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364785 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/AST')
-rw-r--r-- | include/clang/AST/ASTImporter.h | 12 | ||||
-rw-r--r-- | include/clang/AST/ASTImporterSharedState.h | 80 |
2 files changed, 83 insertions, 9 deletions
diff --git a/include/clang/AST/ASTImporter.h b/include/clang/AST/ASTImporter.h index e0089bb702..21b1bbbfd7 100644 --- a/include/clang/AST/ASTImporter.h +++ b/include/clang/AST/ASTImporter.h @@ -32,8 +32,8 @@ namespace clang { class ASTContext; +class ASTImporterSharedState; class Attr; -class ASTImporterLookupTable; class CXXBaseSpecifier; class CXXCtorInitializer; class Decl; @@ -209,13 +209,7 @@ class TypeSourceInfo; }; 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; + std::shared_ptr<ASTImporterSharedState> SharedState = nullptr; /// The path which we go through during the import of a given AST node. ImportPathTy ImportPath; @@ -311,7 +305,7 @@ class TypeSourceInfo; ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, - ASTImporterLookupTable *LookupTable = nullptr); + std::shared_ptr<ASTImporterSharedState> SharedState = nullptr); virtual ~ASTImporter(); diff --git a/include/clang/AST/ASTImporterSharedState.h b/include/clang/AST/ASTImporterSharedState.h new file mode 100644 index 0000000000..e384950590 --- /dev/null +++ b/include/clang/AST/ASTImporterSharedState.h @@ -0,0 +1,80 @@ +//===- ASTImporterSharedState.h - ASTImporter specific state --*- 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 ASTImporter specific state, which may be shared +// amongst several ASTImporter objects. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H +#define LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H + +#include "clang/AST/ASTImporterLookupTable.h" +#include "llvm/ADT/DenseMap.h" +// FIXME We need this because of ImportError. +#include "clang/AST/ASTImporter.h" + +namespace clang { + +class TranslationUnitDecl; + +/// Importer specific state, which may be shared amongst several ASTImporter +/// objects. +class ASTImporterSharedState { + + /// Pointer to the import specific lookup table. + std::unique_ptr<ASTImporterLookupTable> LookupTable; + + /// Mapping from the already-imported declarations in the "to" + /// context to the error status of the import of that declaration. + /// This map contains only the declarations that were not correctly + /// imported. The same declaration may or may not be included in + /// ImportedFromDecls. This map is updated continuously during imports and + /// never cleared (like ImportedFromDecls). + llvm::DenseMap<Decl *, ImportError> ImportErrors; + + // FIXME put ImportedFromDecls here! + // And from that point we can better encapsulate the lookup table. + +public: + ASTImporterSharedState() = default; + + ASTImporterSharedState(TranslationUnitDecl &ToTU) { + LookupTable = llvm::make_unique<ASTImporterLookupTable>(ToTU); + } + + ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); } + + void addDeclToLookup(Decl *D) { + if (LookupTable) + if (auto *ND = dyn_cast<NamedDecl>(D)) + LookupTable->add(ND); + } + + void removeDeclFromLookup(Decl *D) { + if (LookupTable) + if (auto *ND = dyn_cast<NamedDecl>(D)) + LookupTable->remove(ND); + } + + llvm::Optional<ImportError> getImportDeclErrorIfAny(Decl *ToD) const { + auto Pos = ImportErrors.find(ToD); + if (Pos != ImportErrors.end()) + return Pos->second; + else + return Optional<ImportError>(); + } + + void setImportDeclError(Decl *To, ImportError Error) { + ImportErrors[To] = Error; + } +}; + +} // namespace clang +#endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H |