aboutsummaryrefslogtreecommitdiffstats
path: root/include/clang/CrossTU
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-08-20 20:50:49 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-08-20 20:50:49 +0000
commit2298981669bf3bd63335a4be179bc0f96823a8f4 (patch)
tree1cbe2eb27f030d2d70b80ee5ca3c86bee7326a9f /include/clang/CrossTU
parent9a83721404652cea39e9f02ae3e3b5c964602a5c (diff)
downloadsrc-2298981669bf3bd63335a4be179bc0f96823a8f4.tar.gz
src-2298981669bf3bd63335a4be179bc0f96823a8f4.zip
Vendor import of stripped clang trunk r366426 (just before thevendor/clang/clang-trunk-r366426
Notes
Notes: svn path=/vendor/clang/dist/; revision=351280 svn path=/vendor/clang/clang-trunk-r366426/; revision=351281; tag=vendor/clang/clang-trunk-r366426
Diffstat (limited to 'include/clang/CrossTU')
-rw-r--r--include/clang/CrossTU/CrossTUDiagnostic.h7
-rw-r--r--include/clang/CrossTU/CrossTranslationUnit.h67
2 files changed, 47 insertions, 27 deletions
diff --git a/include/clang/CrossTU/CrossTUDiagnostic.h b/include/clang/CrossTU/CrossTUDiagnostic.h
index 56c83a5ad25c..95a648a56082 100644
--- a/include/clang/CrossTU/CrossTUDiagnostic.h
+++ b/include/clang/CrossTU/CrossTUDiagnostic.h
@@ -1,9 +1,8 @@
//===--- CrossTUDiagnostic.h - Diagnostics for Cross TU ---------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// 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
//
//===----------------------------------------------------------------------===//
diff --git a/include/clang/CrossTU/CrossTranslationUnit.h b/include/clang/CrossTU/CrossTranslationUnit.h
index 52e3ae27490f..d64329cdff3e 100644
--- a/include/clang/CrossTU/CrossTranslationUnit.h
+++ b/include/clang/CrossTU/CrossTranslationUnit.h
@@ -1,9 +1,8 @@
//===--- CrossTranslationUnit.h - -------------------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// 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
//
//===----------------------------------------------------------------------===//
//
@@ -15,7 +14,7 @@
#ifndef LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H
#define LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H
-#include "clang/AST/ASTImporterLookupTable.h"
+#include "clang/AST/ASTImporterSharedState.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -29,6 +28,7 @@ class ASTImporter;
class ASTUnit;
class DeclContext;
class FunctionDecl;
+class VarDecl;
class NamedDecl;
class TranslationUnitDecl;
@@ -44,7 +44,9 @@ enum class index_error_code {
failed_to_get_external_ast,
failed_to_generate_usr,
triple_mismatch,
- lang_mismatch
+ lang_mismatch,
+ lang_dialect_mismatch,
+ load_threshold_reached
};
class IndexError : public llvm::ErrorInfo<IndexError> {
@@ -87,6 +89,9 @@ parseCrossTUIndex(StringRef IndexPath, StringRef CrossTUDir);
std::string createCrossTUIndexString(const llvm::StringMap<std::string> &Index);
+// Returns true if the variable or any field of a record variable is const.
+bool containsConst(const VarDecl *VD, const ASTContext &ACtx);
+
/// This class is used for tools that requires cross translation
/// unit capability.
///
@@ -102,16 +107,16 @@ public:
CrossTranslationUnitContext(CompilerInstance &CI);
~CrossTranslationUnitContext();
- /// This function loads a function definition from an external AST
- /// file and merge it into the original AST.
+ /// This function loads a function or variable definition from an
+ /// external AST file and merges it into the original AST.
///
- /// This method should only be used on functions that have no definitions in
+ /// This method should only be used on functions that have no definitions or
+ /// variables that have no initializer in
/// the current translation unit. A function definition with the same
/// declaration will be looked up in the index file which should be in the
/// \p CrossTUDir directory, called \p IndexName. In case the declaration is
/// found in the index the corresponding AST file will be loaded and the
- /// definition of the function will be merged into the original AST using
- /// the AST Importer.
+ /// definition will be merged into the original AST using the AST Importer.
///
/// \return The declaration with the definition will be returned.
/// If no suitable definition is found in the index file or multiple
@@ -121,17 +126,20 @@ public:
llvm::Expected<const FunctionDecl *>
getCrossTUDefinition(const FunctionDecl *FD, StringRef CrossTUDir,
StringRef IndexName, bool DisplayCTUProgress = false);
+ llvm::Expected<const VarDecl *>
+ getCrossTUDefinition(const VarDecl *VD, StringRef CrossTUDir,
+ StringRef IndexName, bool DisplayCTUProgress = false);
- /// This function loads a function definition from an external AST
- /// file.
+ /// This function loads a definition from an external AST file.
///
- /// A function definition with the same declaration will be looked up in the
+ /// A definition with the same declaration will be looked up in the
/// index file which should be in the \p CrossTUDir directory, called
/// \p IndexName. In case the declaration is found in the index the
- /// corresponding AST file will be loaded.
+ /// corresponding AST file will be loaded. If the number of TUs imported
+ /// reaches \p CTULoadTreshold, no loading is performed.
///
/// \return Returns a pointer to the ASTUnit that contains the definition of
- /// the looked up function or an Error.
+ /// the looked up name or an Error.
/// The returned pointer is never a nullptr.
///
/// Note that the AST files should also be in the \p CrossTUDir.
@@ -146,27 +154,40 @@ public:
///
/// \return Returns the resulting definition or an error.
llvm::Expected<const FunctionDecl *> importDefinition(const FunctionDecl *FD);
+ llvm::Expected<const VarDecl *> importDefinition(const VarDecl *VD);
- /// Get a name to identify a function.
+ /// Get a name to identify a named decl.
static std::string getLookupName(const NamedDecl *ND);
/// Emit diagnostics for the user for potential configuration errors.
void emitCrossTUDiagnostics(const IndexError &IE);
private:
- void lazyInitLookupTable(TranslationUnitDecl *ToTU);
+ void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
ASTImporter &getOrCreateASTImporter(ASTContext &From);
- const FunctionDecl *findFunctionInDeclContext(const DeclContext *DC,
- StringRef LookupFnName);
+ template <typename T>
+ llvm::Expected<const T *> getCrossTUDefinitionImpl(const T *D,
+ StringRef CrossTUDir,
+ StringRef IndexName,
+ bool DisplayCTUProgress);
+ template <typename T>
+ const T *findDefInDeclContext(const DeclContext *DC,
+ StringRef LookupName);
+ template <typename T>
+ llvm::Expected<const T *> importDefinitionImpl(const T *D);
llvm::StringMap<std::unique_ptr<clang::ASTUnit>> FileASTUnitMap;
- llvm::StringMap<clang::ASTUnit *> FunctionASTUnitMap;
- llvm::StringMap<std::string> FunctionFileMap;
+ llvm::StringMap<clang::ASTUnit *> NameASTUnitMap;
+ llvm::StringMap<std::string> NameFileMap;
llvm::DenseMap<TranslationUnitDecl *, std::unique_ptr<ASTImporter>>
ASTUnitImporterMap;
CompilerInstance &CI;
ASTContext &Context;
- std::unique_ptr<ASTImporterLookupTable> LookupTable;
+ std::shared_ptr<ASTImporterSharedState> ImporterSharedSt;
+ /// \p CTULoadTreshold should serve as an upper limit to the number of TUs
+ /// imported in order to reduce the memory footprint of CTU analysis.
+ const unsigned CTULoadThreshold;
+ unsigned NumASTLoaded{0u};
};
} // namespace cross_tu