<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi Manuel,</div><div class=""><br class=""></div><div class="">Apologies, I will start a RFC giving more context. Also I’ll ask for feedback for another preprocessor change related to this I’d propose as follow-up.</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Jun 9, 2017, at 3:07 AM, Manuel Klimek <<a href="mailto:klimek@google.com" class="">klimek@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hey ho,<div class=""><br class=""></div><div class="">this looks like a really cool new feature, and the CL looks good to me; I was wondering whether in the future we can send CLs like this through pre-commit review, or have an RFC email thread. If you have more stuff landing, a single RFC email thread describing how the features work together would also be super useful, as it makes it easier to follow along the patches later.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">/Manuel</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Fri, Jun 9, 2017 at 3:21 AM Argyrios Kyrtzidis via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: akirtzidis<br class="">
Date: Thu Jun 8 20:20:48 2017<br class="">
New Revision: 305044<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=305044&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=305044&view=rev</a><br class="">
Log:<br class="">
[libclang] Introduce a new parsing option 'CXTranslationUnit_SingleFileParse' that puts preprocessor in a mode for parsing a single file only.<br class="">
<br class="">
This is useful for parsing a single file, as a fast/inaccurate 'mode' that can still provide declarations from the file, like the classes and their methods.<br class="">
<br class="">
Added:<br class="">
cfe/trunk/test/Index/singe-file-parse.m<br class="">
Modified:<br class="">
cfe/trunk/include/clang-c/Index.h<br class="">
cfe/trunk/include/clang/Frontend/ASTUnit.h<br class="">
cfe/trunk/include/clang/Lex/PreprocessorOptions.h<br class="">
cfe/trunk/lib/Frontend/ASTUnit.cpp<br class="">
cfe/trunk/lib/Lex/PPDirectives.cpp<br class="">
cfe/trunk/tools/c-index-test/c-index-test.c<br class="">
cfe/trunk/tools/libclang/CIndex.cpp<br class="">
<br class="">
Modified: cfe/trunk/include/clang-c/Index.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=305044&r1=305043&r2=305044&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=305044&r1=305043&r2=305044&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/include/clang-c/Index.h (original)<br class="">
+++ cfe/trunk/include/clang-c/Index.h Thu Jun 8 20:20:48 2017<br class="">
@@ -32,7 +32,7 @@<br class="">
* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.<br class="">
*/<br class="">
#define CINDEX_VERSION_MAJOR 0<br class="">
-#define CINDEX_VERSION_MINOR 42<br class="">
+#define CINDEX_VERSION_MINOR 43<br class="">
<br class="">
#define CINDEX_VERSION_ENCODE(major, minor) ( \<br class="">
((major) * 10000) \<br class="">
@@ -1234,7 +1234,12 @@ enum CXTranslationUnit_Flags {<br class="">
* purposes of an IDE, this is undesirable behavior and as much information<br class="">
* as possible should be reported. Use this flag to enable this behavior.<br class="">
*/<br class="">
- CXTranslationUnit_KeepGoing = 0x200<br class="">
+ CXTranslationUnit_KeepGoing = 0x200,<br class="">
+<br class="">
+ /**<br class="">
+ * \brief Sets the preprocessor in a mode for parsing a single file only.<br class="">
+ */<br class="">
+ CXTranslationUnit_SingleFileParse = 0x400<br class="">
};<br class="">
<br class="">
/**<br class="">
<br class="">
Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=305044&r1=305043&r2=305044&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=305044&r1=305043&r2=305044&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)<br class="">
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Thu Jun 8 20:20:48 2017<br class="">
@@ -871,6 +871,7 @@ public:<br class="">
bool CacheCodeCompletionResults = false,<br class="">
bool IncludeBriefCommentsInCodeCompletion = false,<br class="">
bool AllowPCHWithCompilerErrors = false, bool SkipFunctionBodies = false,<br class="">
+ bool SingleFileParse = false,<br class="">
bool UserFilesAreVolatile = false, bool ForSerialization = false,<br class="">
llvm::Optional<StringRef> ModuleFormat = llvm::None,<br class="">
std::unique_ptr<ASTUnit> *ErrAST = nullptr,<br class="">
<br class="">
Modified: cfe/trunk/include/clang/Lex/PreprocessorOptions.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorOptions.h?rev=305044&r1=305043&r2=305044&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorOptions.h?rev=305044&r1=305043&r2=305044&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/include/clang/Lex/PreprocessorOptions.h (original)<br class="">
+++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h Thu Jun 8 20:20:48 2017<br class="">
@@ -95,6 +95,9 @@ public:<br class="">
/// If given, a PTH cache file to use for speeding up header parsing.<br class="">
std::string TokenCache;<br class="">
<br class="">
+ /// When enabled, preprocessor is in a mode for parsing a single file only.<br class="">
+ bool SingleFileParseMode = false;<br class="">
+<br class="">
/// \brief True if the SourceManager should report the original file name for<br class="">
/// contents of files that were remapped to other files. Defaults to true.<br class="">
bool RemappedFilesKeepOriginalName;<br class="">
@@ -181,6 +184,7 @@ public:<br class="">
ImplicitPCHInclude.clear();<br class="">
ImplicitPTHInclude.clear();<br class="">
TokenCache.clear();<br class="">
+ SingleFileParseMode = false;<br class="">
RetainRemappedFileBuffers = true;<br class="">
PrecompiledPreambleBytes.first = 0;<br class="">
PrecompiledPreambleBytes.second = 0;<br class="">
<br class="">
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=305044&r1=305043&r2=305044&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=305044&r1=305043&r2=305044&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)<br class="">
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Thu Jun 8 20:20:48 2017<br class="">
@@ -1982,7 +1982,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(<br class="">
unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind,<br class="">
bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion,<br class="">
bool AllowPCHWithCompilerErrors, bool SkipFunctionBodies,<br class="">
- bool UserFilesAreVolatile, bool ForSerialization,<br class="">
+ bool SingleFileParse, bool UserFilesAreVolatile, bool ForSerialization,<br class="">
llvm::Optional<StringRef> ModuleFormat, std::unique_ptr<ASTUnit> *ErrAST,<br class="">
IntrusiveRefCntPtr<vfs::FileSystem> VFS) {<br class="">
assert(Diags.get() && "no DiagnosticsEngine was provided");<br class="">
@@ -2011,6 +2011,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(<br class="">
PPOpts.RemappedFilesKeepOriginalName = RemappedFilesKeepOriginalName;<br class="">
PPOpts.AllowPCHWithCompilerErrors = AllowPCHWithCompilerErrors;<br class="">
PPOpts.GeneratePreamble = PrecompilePreambleAfterNParses != 0;<br class="">
+ PPOpts.SingleFileParseMode = SingleFileParse;<br class="">
<br class="">
// Override the resources path.<br class="">
CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;<br class="">
<br class="">
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=305044&r1=305043&r2=305044&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=305044&r1=305043&r2=305044&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)<br class="">
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Thu Jun 8 20:20:48 2017<br class="">
@@ -30,6 +30,7 @@<br class="">
#include "clang/Lex/PPCallbacks.h"<br class="">
#include "clang/Lex/Pragma.h"<br class="">
#include "clang/Lex/Preprocessor.h"<br class="">
+#include "clang/Lex/PreprocessorOptions.h"<br class="">
#include "clang/Lex/PTHLexer.h"<br class="">
#include "clang/Lex/Token.h"<br class="">
#include "llvm/ADT/ArrayRef.h"<br class="">
@@ -1845,10 +1846,13 @@ void Preprocessor::HandleIncludeDirectiv<br class="">
// we've imported or already built.<br class="">
bool ShouldEnter = true;<br class="">
<br class="">
+ if (PPOpts->SingleFileParseMode)<br class="">
+ ShouldEnter = false;<br class="">
+<br class="">
// Determine whether we should try to import the module for this #include, if<br class="">
// there is one. Don't do so if precompiled module support is disabled or we<br class="">
// are processing this module textually (because we're building the module).<br class="">
- if (File && SuggestedModule && getLangOpts().Modules &&<br class="">
+ if (ShouldEnter && File && SuggestedModule && getLangOpts().Modules &&<br class="">
SuggestedModule.getModule()->getTopLevelModuleName() !=<br class="">
getLangOpts().CurrentModule) {<br class="">
// If this include corresponds to a module but that module is<br class="">
<br class="">
Added: cfe/trunk/test/Index/singe-file-parse.m<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/singe-file-parse.m?rev=305044&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/singe-file-parse.m?rev=305044&view=auto</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/test/Index/singe-file-parse.m (added)<br class="">
+++ cfe/trunk/test/Index/singe-file-parse.m Thu Jun 8 20:20:48 2017<br class="">
@@ -0,0 +1,11 @@<br class="">
+// RUN: c-index-test -single-file-parse %s | FileCheck %s<br class="">
+<br class="">
+#include <stdint.h><br class="">
+<br class="">
+// CHECK-NOT: TypedefDecl=intptr_t<br class="">
+<br class="">
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=MyCls<br class="">
+@interface MyCls<br class="">
+// CHECK: [[@LINE+1]]:8: ObjCInstanceMethodDecl=some_meth<br class="">
+-(void)some_meth;<br class="">
+@end<br class="">
<br class="">
Modified: cfe/trunk/tools/c-index-test/c-index-test.c<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=305044&r1=305043&r2=305044&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=305044&r1=305043&r2=305044&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)<br class="">
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Jun 8 20:20:48 2017<br class="">
@@ -1850,6 +1850,34 @@ int perform_test_reparse_source(int argc<br class="">
return result;<br class="">
}<br class="">
<br class="">
+static int perform_single_file_parse(const char *filename) {<br class="">
+ CXIndex Idx;<br class="">
+ CXTranslationUnit TU;<br class="">
+ enum CXErrorCode Err;<br class="">
+ int result;<br class="">
+<br class="">
+ Idx = clang_createIndex(/* excludeDeclsFromPCH */1,<br class="">
+ /* displayDiagnostics=*/1);<br class="">
+<br class="">
+ Err = clang_parseTranslationUnit2(Idx, filename,<br class="">
+ /*command_line_args=*/NULL,<br class="">
+ /*num_command_line_args=*/0,<br class="">
+ /*unsaved_files=*/NULL,<br class="">
+ /*num_unsaved_files=*/0,<br class="">
+ CXTranslationUnit_SingleFileParse, &TU);<br class="">
+ if (Err != CXError_Success) {<br class="">
+ fprintf(stderr, "Unable to load translation unit!\n");<br class="">
+ describeLibclangFailure(Err);<br class="">
+ clang_disposeIndex(Idx);<br class="">
+ return 1;<br class="">
+ }<br class="">
+<br class="">
+ result = perform_test_load(Idx, TU, /*filter=*/"all", /*prefix=*/NULL, FilteredPrintingVisitor, /*PostVisit=*/NULL,<br class="">
+ /*CommentSchemaFile=*/NULL);<br class="">
+ clang_disposeIndex(Idx);<br class="">
+ return result;<br class="">
+}<br class="">
+<br class="">
/******************************************************************************/<br class="">
/* Logic for testing clang_getCursor(). */<br class="">
/******************************************************************************/<br class="">
@@ -4439,6 +4467,8 @@ int cindextest_main(int argc, const char<br class="">
return perform_test_load_source(argc - 3, argv + 3, argv[2], I,<br class="">
postVisit);<br class="">
}<br class="">
+ else if (argc >= 3 && strcmp(argv[1], "-single-file-parse") == 0)<br class="">
+ return perform_single_file_parse(argv[2]);<br class="">
else if (argc >= 4 && strcmp(argv[1], "-test-file-scan") == 0)<br class="">
return perform_file_scan(argv[2], argv[3],<br class="">
argc >= 5 ? argv[4] : 0);<br class="">
<br class="">
Modified: cfe/trunk/tools/libclang/CIndex.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=305044&r1=305043&r2=305044&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=305044&r1=305043&r2=305044&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/tools/libclang/CIndex.cpp (original)<br class="">
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Jun 8 20:20:48 2017<br class="">
@@ -3300,12 +3300,14 @@ clang_parseTranslationUnit_Impl(CXIndex<br class="">
options & CXTranslationUnit_CreatePreambleOnFirstParse;<br class="">
// FIXME: Add a flag for modules.<br class="">
TranslationUnitKind TUKind<br class="">
- = (options & CXTranslationUnit_Incomplete)? TU_Prefix : TU_Complete;<br class="">
+ = (options & (CXTranslationUnit_Incomplete |<br class="">
+ CXTranslationUnit_SingleFileParse))? TU_Prefix : TU_Complete;<br class="">
bool CacheCodeCompletionResults<br class="">
= options & CXTranslationUnit_CacheCompletionResults;<br class="">
bool IncludeBriefCommentsInCodeCompletion<br class="">
= options & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;<br class="">
bool SkipFunctionBodies = options & CXTranslationUnit_SkipFunctionBodies;<br class="">
+ bool SingleFileParse = options & CXTranslationUnit_SingleFileParse;<br class="">
bool ForSerialization = options & CXTranslationUnit_ForSerialization;<br class="">
<br class="">
// Configure the diagnostics.<br class="">
@@ -3390,7 +3392,7 @@ clang_parseTranslationUnit_Impl(CXIndex<br class="">
/*CaptureDiagnostics=*/true, *RemappedFiles.get(),<br class="">
/*RemappedFilesKeepOriginalName=*/true, PrecompilePreambleAfterNParses,<br class="">
TUKind, CacheCodeCompletionResults, IncludeBriefCommentsInCodeCompletion,<br class="">
- /*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies,<br class="">
+ /*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies, SingleFileParse,<br class="">
/*UserFilesAreVolatile=*/true, ForSerialization,<br class="">
CXXIdx->getPCHContainerOperations()->getRawReader().getFormat(),<br class="">
&ErrUnit));<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
cfe-commits mailing list<br class="">
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank" class="">cfe-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></body></html>