diff options
author | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-05-17 09:15:22 +0000 |
---|---|---|
committer | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-05-17 09:15:22 +0000 |
commit | f70d28b1f458c79aa70bcf85111c35442588d01e (patch) | |
tree | de438d94812f0d8644a9f32ffb0db46f7e5a78d2 | |
parent | 75cfa341567851509f916db580927a958487b4dc (diff) | |
download | bcm5719-llvm-f70d28b1f458c79aa70bcf85111c35442588d01e.tar.gz bcm5719-llvm-f70d28b1f458c79aa70bcf85111c35442588d01e.zip |
Revert https://reviews.llvm.org/D46050 and https://reviews.llvm.org/D45815
Windows line endings.
Requires proper resubmission.
llvm-svn: 332585
-rw-r--r-- | clang/include/clang-c/Index.h | 22 | ||||
-rw-r--r-- | clang/include/clang/Frontend/ASTUnit.h | 64 | ||||
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 83 | ||||
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 16 | ||||
-rw-r--r-- | clang/test/Index/complete-and-plugins.c | 6 | ||||
-rw-r--r-- | clang/test/Parser/skip-function-bodies.h | 3 | ||||
-rw-r--r-- | clang/test/Parser/skip-function-bodies.mm | 37 | ||||
-rw-r--r-- | clang/tools/c-index-test/c-index-test.c | 14 | ||||
-rw-r--r-- | clang/tools/libclang/CIndex.cpp | 24 |
9 files changed, 105 insertions, 164 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 4e6fcce8adf..3fee13a40b4 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -1321,21 +1321,13 @@ enum CXTranslationUnit_Flags { */ CXTranslationUnit_KeepGoing = 0x200, - /**
- * Sets the preprocessor in a mode for parsing a single file only.
- */
- CXTranslationUnit_SingleFileParse = 0x400,
-
- /**
- * \brief Used in combination with CXTranslationUnit_SkipFunctionBodies to
- * constrain the skipping of function bodies to the preamble.
- *
- * The function bodies of the main file are not skipped.
- */
- CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 0x800,
-};
-
-/**
+ /** + * Sets the preprocessor in a mode for parsing a single file only. + */ + CXTranslationUnit_SingleFileParse = 0x400 +}; + +/** * Returns the set of flags that is suitable for parsing a translation * unit that is being edited. * diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index 8ce4492b371..af67dd1aedc 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -78,15 +78,12 @@ class TargetInfo; namespace vfs { class FileSystem; -
-} // namespace vfs
-
-/// \brief Enumerates the available scopes for skipping function bodies.
-enum class SkipFunctionBodiesScope { None, Preamble, PreambleAndMainFile };
-
-/// Utility class for loading a ASTContext from an AST file.
-class ASTUnit {
-public:
+ +} // namespace vfs + +/// Utility class for loading a ASTContext from an AST file. +class ASTUnit { +public: struct StandaloneFixIt { std::pair<unsigned, unsigned> RemoveRange; std::pair<unsigned, unsigned> InsertFromRange; @@ -348,15 +345,12 @@ private: unsigned CurrentTopLevelHashValue = 0; /// Bit used by CIndex to mark when a translation unit may be in an - /// inconsistent state, and is not safe to free.
- unsigned UnsafeToFree : 1;
-
- /// \brief Enumerator specifying the scope for skipping function bodies.
- SkipFunctionBodiesScope SkipFunctionBodies = SkipFunctionBodiesScope::None;
-
- /// Cache any "global" code-completion results, so that we can avoid
- /// recomputing them with each completion.
- void CacheCodeCompletionResults();
+ /// inconsistent state, and is not safe to free. + unsigned UnsafeToFree : 1; + + /// Cache any "global" code-completion results, so that we can avoid + /// recomputing them with each completion. + void CacheCodeCompletionResults(); /// Clear out and deallocate void ClearCachedCompletionResults(); @@ -366,13 +360,13 @@ private: bool Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps, std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer, IntrusiveRefCntPtr<vfs::FileSystem> VFS); -
- std::unique_ptr<llvm::MemoryBuffer> getMainBufferWithPrecompiledPreamble(
- std::shared_ptr<PCHContainerOperations> PCHContainerOps,
- CompilerInvocation &PreambleInvocationIn,
- IntrusiveRefCntPtr<vfs::FileSystem> VFS, bool AllowRebuild = true,
- unsigned MaxLines = 0);
- void RealizeTopLevelDeclsFromPreamble();
+ + std::unique_ptr<llvm::MemoryBuffer> getMainBufferWithPrecompiledPreamble( + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + const CompilerInvocation &PreambleInvocationIn, + IntrusiveRefCntPtr<vfs::FileSystem> VFS, bool AllowRebuild = true, + unsigned MaxLines = 0); + void RealizeTopLevelDeclsFromPreamble(); /// Transfers ownership of the objects (like SourceManager) from /// \param CI to this ASTUnit. @@ -804,17 +798,15 @@ public: ArrayRef<RemappedFile> RemappedFiles = None, bool RemappedFilesKeepOriginalName = true, unsigned PrecompilePreambleAfterNParses = 0, - TranslationUnitKind TUKind = TU_Complete,
- bool CacheCodeCompletionResults = false,
- bool IncludeBriefCommentsInCodeCompletion = false,
- bool AllowPCHWithCompilerErrors = false,
- SkipFunctionBodiesScope SkipFunctionBodies =
- SkipFunctionBodiesScope::None,
- bool SingleFileParse = false, bool UserFilesAreVolatile = false,
- bool ForSerialization = false,
- llvm::Optional<StringRef> ModuleFormat = llvm::None,
- std::unique_ptr<ASTUnit> *ErrAST = nullptr,
- IntrusiveRefCntPtr<vfs::FileSystem> VFS = nullptr);
+ TranslationUnitKind TUKind = TU_Complete, + bool CacheCodeCompletionResults = false, + bool IncludeBriefCommentsInCodeCompletion = false, + bool AllowPCHWithCompilerErrors = false, bool SkipFunctionBodies = false, + bool SingleFileParse = false, + bool UserFilesAreVolatile = false, bool ForSerialization = false, + llvm::Optional<StringRef> ModuleFormat = llvm::None, + std::unique_ptr<ASTUnit> *ErrAST = nullptr, + IntrusiveRefCntPtr<vfs::FileSystem> VFS = nullptr); /// Reparse the source files using the same command-line options that /// were originally used to produce this translation unit. diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 0ce7adb620e..9b672d97551 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1268,13 +1268,13 @@ makeStandaloneDiagnostic(const LangOptions &LangOpts, /// \returns If the precompiled preamble can be used, returns a newly-allocated /// buffer that should be used in place of the main file when doing so. /// Otherwise, returns a NULL pointer. -std::unique_ptr<llvm::MemoryBuffer>
-ASTUnit::getMainBufferWithPrecompiledPreamble(
- std::shared_ptr<PCHContainerOperations> PCHContainerOps,
- CompilerInvocation &PreambleInvocationIn,
- IntrusiveRefCntPtr<vfs::FileSystem> VFS, bool AllowRebuild,
- unsigned MaxLines) {
- auto MainFilePath =
+std::unique_ptr<llvm::MemoryBuffer> +ASTUnit::getMainBufferWithPrecompiledPreamble( + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + const CompilerInvocation &PreambleInvocationIn, + IntrusiveRefCntPtr<vfs::FileSystem> VFS, bool AllowRebuild, + unsigned MaxLines) { + auto MainFilePath = PreambleInvocationIn.getFrontendOpts().Inputs[0].getFile(); std::unique_ptr<llvm::MemoryBuffer> MainFileBuffer = getBufferForFileHandlingRemapping(PreambleInvocationIn, VFS.get(), @@ -1335,24 +1335,15 @@ ASTUnit::getMainBufferWithPrecompiledPreamble( &NewPreambleDiagsStandalone); // We did not previously compute a preamble, or it can't be reused anyway. - SimpleTimer PreambleTimer(WantTiming);
- PreambleTimer.setOutput("Precompiling preamble");
-
- const bool PreviousSkipFunctionBodies =
- PreambleInvocationIn.getFrontendOpts().SkipFunctionBodies;
- if (SkipFunctionBodies == SkipFunctionBodiesScope::Preamble)
- PreambleInvocationIn.getFrontendOpts().SkipFunctionBodies = true;
-
- llvm::ErrorOr<PrecompiledPreamble> NewPreamble = PrecompiledPreamble::Build(
- PreambleInvocationIn, MainFileBuffer.get(), Bounds, *Diagnostics, VFS,
- PCHContainerOps, /*StoreInMemory=*/false, Callbacks);
-
- PreambleInvocationIn.getFrontendOpts().SkipFunctionBodies =
- PreviousSkipFunctionBodies;
-
- if (NewPreamble) {
- Preamble = std::move(*NewPreamble);
- PreambleRebuildCounter = 1;
+ SimpleTimer PreambleTimer(WantTiming); + PreambleTimer.setOutput("Precompiling preamble"); + + llvm::ErrorOr<PrecompiledPreamble> NewPreamble = PrecompiledPreamble::Build( + PreambleInvocationIn, MainFileBuffer.get(), Bounds, *Diagnostics, VFS, + PCHContainerOps, /*StoreInMemory=*/false, Callbacks); + if (NewPreamble) { + Preamble = std::move(*NewPreamble); + PreambleRebuildCounter = 1; } else { switch (static_cast<BuildPreambleError>(NewPreamble.getError().value())) { case BuildPreambleError::CouldntCreateTempFile: @@ -1697,13 +1688,13 @@ ASTUnit *ASTUnit::LoadFromCommandLine( std::shared_ptr<PCHContainerOperations> PCHContainerOps, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, StringRef ResourceFilesPath, bool OnlyLocalDecls, bool CaptureDiagnostics, - ArrayRef<RemappedFile> RemappedFiles, bool RemappedFilesKeepOriginalName,
- unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind,
- bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion,
- bool AllowPCHWithCompilerErrors, SkipFunctionBodiesScope SkipFunctionBodies,
- bool SingleFileParse, bool UserFilesAreVolatile, bool ForSerialization,
- llvm::Optional<StringRef> ModuleFormat, std::unique_ptr<ASTUnit> *ErrAST,
- IntrusiveRefCntPtr<vfs::FileSystem> VFS) {
+ ArrayRef<RemappedFile> RemappedFiles, bool RemappedFilesKeepOriginalName, + unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind, + bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion, + bool AllowPCHWithCompilerErrors, bool SkipFunctionBodies, + bool SingleFileParse, bool UserFilesAreVolatile, bool ForSerialization, + llvm::Optional<StringRef> ModuleFormat, std::unique_ptr<ASTUnit> *ErrAST, + IntrusiveRefCntPtr<vfs::FileSystem> VFS) { assert(Diags.get() && "no DiagnosticsEngine was provided"); SmallVector<StoredDiagnostic, 4> StoredDiagnostics; @@ -1730,14 +1721,13 @@ ASTUnit *ASTUnit::LoadFromCommandLine( PPOpts.AllowPCHWithCompilerErrors = AllowPCHWithCompilerErrors; PPOpts.SingleFileParseMode = SingleFileParse; - // Override the resources path.
- CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
-
- CI->getFrontendOpts().SkipFunctionBodies =
- SkipFunctionBodies == SkipFunctionBodiesScope::PreambleAndMainFile;
-
- if (ModuleFormat)
- CI->getHeaderSearchOpts().ModuleFormat = ModuleFormat.getValue();
+ // Override the resources path. + CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath; + + CI->getFrontendOpts().SkipFunctionBodies = SkipFunctionBodies; + + if (ModuleFormat) + CI->getHeaderSearchOpts().ModuleFormat = ModuleFormat.getValue(); // Create the AST unit. std::unique_ptr<ASTUnit> AST; @@ -1757,13 +1747,12 @@ ASTUnit *ASTUnit::LoadFromCommandLine( AST->TUKind = TUKind; AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults; AST->IncludeBriefCommentsInCodeCompletion - = IncludeBriefCommentsInCodeCompletion;
- AST->UserFilesAreVolatile = UserFilesAreVolatile;
- AST->Invocation = CI;
- AST->SkipFunctionBodies = SkipFunctionBodies;
- if (ForSerialization)
- AST->WriterData.reset(new ASTWriterData(*AST->PCMCache));
- // Zero out now to ease cleanup during crash recovery.
+ = IncludeBriefCommentsInCodeCompletion; + AST->UserFilesAreVolatile = UserFilesAreVolatile; + AST->Invocation = CI; + if (ForSerialization) + AST->WriterData.reset(new ASTWriterData(*AST->PCMCache)); + // Zero out now to ease cleanup during crash recovery. CI = nullptr; Diags = nullptr; diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 1ebc37310de..e4fb022c2a1 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -150,16 +150,12 @@ FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, return nullptr; // If there are no registered plugins we don't need to wrap the consumer - if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end())
- return Consumer;
-
- // If this is a code completion run, avoid invoking the plugin consumers
- if (CI.hasCodeCompletionConsumer())
- return Consumer;
-
- // Collect the list of plugins that go before the main action (in Consumers)
- // or after it (in AfterConsumers)
- std::vector<std::unique_ptr<ASTConsumer>> Consumers;
+ if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end()) + return Consumer; + + // Collect the list of plugins that go before the main action (in Consumers) + // or after it (in AfterConsumers) + std::vector<std::unique_ptr<ASTConsumer>> Consumers; std::vector<std::unique_ptr<ASTConsumer>> AfterConsumers; for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(), ie = FrontendPluginRegistry::end(); diff --git a/clang/test/Index/complete-and-plugins.c b/clang/test/Index/complete-and-plugins.c deleted file mode 100644 index 60c9214018b..00000000000 --- a/clang/test/Index/complete-and-plugins.c +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: c-index-test -code-completion-at=%s:7:1 -load %llvmshlibdir/PrintFunctionNames%pluginext -add-plugin print-fns %s | FileCheck %s
-// REQUIRES: plugins, examples
-// CHECK: macro definition:{{.*}}
-// CHECK-NOT: top-level-decl: "x"
-
-void x();
diff --git a/clang/test/Parser/skip-function-bodies.h b/clang/test/Parser/skip-function-bodies.h deleted file mode 100644 index 250026cd62d..00000000000 --- a/clang/test/Parser/skip-function-bodies.h +++ /dev/null @@ -1,3 +0,0 @@ -int header1(int t) {
- return t;
-}
diff --git a/clang/test/Parser/skip-function-bodies.mm b/clang/test/Parser/skip-function-bodies.mm index b2fe485a1d5..e5b7b2adf83 100644 --- a/clang/test/Parser/skip-function-bodies.mm +++ b/clang/test/Parser/skip-function-bodies.mm @@ -1,7 +1,7 @@ -#include "skip-function-bodies.h"
-
-class A {
- class B {};
+// RUN: env CINDEXTEST_SKIP_FUNCTION_BODIES=1 c-index-test -test-load-source all %s | FileCheck %s + +class A { + class B {}; public: A() { @@ -24,13 +24,12 @@ public: @end void J() { - class K {};
-}
-
-// RUN: env CINDEXTEST_SKIP_FUNCTION_BODIES=1 c-index-test -test-load-source all %s | FileCheck %s
-// CHECK: skip-function-bodies.mm:3:7: ClassDecl=A:3:7 (Definition) Extent=[3:1 - 14:2]
-// CHECK: skip-function-bodies.mm:4:9: ClassDecl=B:4:9 (Definition) Extent=[4:3 - 4:13]
-// CHECK: skip-function-bodies.mm:6:1: CXXAccessSpecifier=:6:1 (Definition) Extent=[6:1 - 6:8]
+ class K {}; +} + +// CHECK: skip-function-bodies.mm:3:7: ClassDecl=A:3:7 (Definition) Extent=[3:1 - 14:2] +// CHECK: skip-function-bodies.mm:4:9: ClassDecl=B:4:9 (Definition) Extent=[4:3 - 4:13] +// CHECK: skip-function-bodies.mm:6:1: CXXAccessSpecifier=:6:1 (Definition) Extent=[6:1 - 6:8] // CHECK: skip-function-bodies.mm:7:3: CXXConstructor=A:7:3 (default constructor) Extent=[7:3 - 7:6] // CHECK-NOT: skip-function-bodies.mm:8:12: StructDecl=C:8:12 (Definition) Extent=[8:5 - 10:6] // CHECK-NOT: skip-function-bodies.mm:9:12: CXXMethod=d:9:12 (Definition) Extent=[9:7 - 9:18] @@ -41,16 +40,6 @@ void J() { // CHECK: skip-function-bodies.mm:19:17: ObjCImplementationDecl=F:19:17 (Definition) Extent=[19:1 - 24:2] // CHECK: skip-function-bodies.mm:20:10: ObjCInstanceMethodDecl=G:20:10 Extent=[20:1 - 20:13] // CHECK-NOT: skip-function-bodies.mm:21:13: TypedefDecl=H:21:13 (Definition) Extent=[21:3 - 21:14] -// CHECK-NOT: skip-function-bodies.mm:21:11: TypeRef=class A:3:7 Extent=[21:11 - 21:12]
-// CHECK: skip-function-bodies.mm:26:6: FunctionDecl=J:26:6 Extent=[26:1 - 26:9]
-// CHECK-NOT: skip-function-bodies.mm:27:9: ClassDecl=K:27:9 (Definition) Extent=[27:3 - 27:13]
-
-// RUN: env CINDEXTEST_EDITING=1 \
-// RUN: CINDEXTEST_CREATE_PREAMBLE_ON_FIRST_PARSE=1 \
-// RUN: CINDEXTEST_SKIP_FUNCTION_BODIES=1 \
-// RUN: CINDEXTEST_LIMIT_SKIP_FUNCTION_BODIES_TO_PREAMBLE=1 \
-// RUN: c-index-test -test-load-source all %s | FileCheck -check-prefix=CHECK-PREAMBLE %s
-// CHECK-PREAMBLE: skip-function-bodies.h:1:5: FunctionDecl=header1:1:5 Extent=[1:1 - 1:19]
-// CHECK-PREAMBLE-NOT: skip-function-bodies.h:2:3: ReturnStmt= Extent=[2:3 - 2:11]
-// CHECK-PREAMBLE: skip-function-bodies.mm:8:12: StructDecl=C:8:12 (Definition) Extent=[8:5 - 10:6]
-// CHECK-PREAMBLE: skip-function-bodies.mm:9:12: CXXMethod=d:9:12 (Definition) Extent=[9:7 - 9:18]
+// CHECK-NOT: skip-function-bodies.mm:21:11: TypeRef=class A:3:7 Extent=[21:11 - 21:12] +// CHECK: skip-function-bodies.mm:26:6: FunctionDecl=J:26:6 Extent=[26:1 - 26:9] +// CHECK-NOT: skip-function-bodies.mm:27:9: ClassDecl=K:27:9 (Definition) Extent=[27:3 - 27:13] diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 828cb98c1f9..d57ac4f9f6c 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -79,14 +79,12 @@ static unsigned getDefaultParsingOptions() { if (getenv("CINDEXTEST_COMPLETION_BRIEF_COMMENTS")) options |= CXTranslationUnit_IncludeBriefCommentsInCodeCompletion; if (getenv("CINDEXTEST_CREATE_PREAMBLE_ON_FIRST_PARSE")) - options |= CXTranslationUnit_CreatePreambleOnFirstParse;
- if (getenv("CINDEXTEST_KEEP_GOING"))
- options |= CXTranslationUnit_KeepGoing;
- if (getenv("CINDEXTEST_LIMIT_SKIP_FUNCTION_BODIES_TO_PREAMBLE"))
- options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble;
-
- return options;
-}
+ options |= CXTranslationUnit_CreatePreambleOnFirstParse; + if (getenv("CINDEXTEST_KEEP_GOING")) + options |= CXTranslationUnit_KeepGoing; + + return options; +} static void ModifyPrintingPolicyAccordingToEnv(CXPrintingPolicy Policy) { struct Mapping { diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 9b682da71ea..c348506545d 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -3377,21 +3377,15 @@ clang_parseTranslationUnit_Impl(CXIndex CIdx, const char *source_filename, = (options & (CXTranslationUnit_Incomplete | CXTranslationUnit_SingleFileParse))? TU_Prefix : TU_Complete; bool CacheCodeCompletionResults - = options & CXTranslationUnit_CacheCompletionResults;
- bool IncludeBriefCommentsInCodeCompletion
- = options & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
- bool SingleFileParse = options & CXTranslationUnit_SingleFileParse;
- bool ForSerialization = options & CXTranslationUnit_ForSerialization;
- SkipFunctionBodiesScope SkipFunctionBodies = SkipFunctionBodiesScope::None;
- if (options & CXTranslationUnit_SkipFunctionBodies) {
- SkipFunctionBodies =
- (options & CXTranslationUnit_LimitSkipFunctionBodiesToPreamble)
- ? SkipFunctionBodiesScope::Preamble
- : SkipFunctionBodiesScope::PreambleAndMainFile;
- }
-
- // Configure the diagnostics.
- IntrusiveRefCntPtr<DiagnosticsEngine>
+ = options & CXTranslationUnit_CacheCompletionResults; + bool IncludeBriefCommentsInCodeCompletion + = options & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion; + bool SkipFunctionBodies = options & CXTranslationUnit_SkipFunctionBodies; + bool SingleFileParse = options & CXTranslationUnit_SingleFileParse; + bool ForSerialization = options & CXTranslationUnit_ForSerialization; + + // Configure the diagnostics. + IntrusiveRefCntPtr<DiagnosticsEngine> Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions)); if (options & CXTranslationUnit_KeepGoing) |