[PATCH] Allow compiler invocation to have a previously set Preprocessor and ASTContext

Neil Henning llvm at neil-henning.co.uk
Wed Sep 11 02:26:30 PDT 2013


CompilerInvocation can have a previously set FileManager and 
SourceManager, but not a Preprocessor or ASTContext. This stops Clang 
drivers from being able to declare their own Preprocessor and ASTContext 
before calling using FrontendAction's BeginSourceFile to compile.

This patch allows a Preprocessor or ASTContext to previously have been set.

Any comments would be appreciated,
-Neil Henning.

Patch (also attached);
> Index: lib/Frontend/FrontendAction.cpp
> ===================================================================
> --- lib/Frontend/FrontendAction.cpp    (revision 190499)
> +++ lib/Frontend/FrontendAction.cpp    (working copy)
> @@ -265,7 +265,8 @@
>    }
>
>    // Set up the preprocessor.
> -  CI.createPreprocessor();
> +  if(!CI.hasPreprocessor())
> +    CI.createPreprocessor();
>
>    // Inform the diagnostic client we are processing a source file.
>    CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(),
> @@ -279,7 +280,8 @@
>    // Create the AST context and consumer unless this is a 
> preprocessor only
>    // action.
>    if (!usesPreprocessorOnly()) {
> -    CI.createASTContext();
> +    if(!CI.hasASTContext())
> +      CI.createASTContext();
>
>      OwningPtr<ASTConsumer> Consumer(
>                                     CreateWrappedASTConsumer(CI, 
> InputFile));

-------------- next part --------------
Index: lib/Frontend/FrontendAction.cpp
===================================================================
--- lib/Frontend/FrontendAction.cpp	(revision 190499)
+++ lib/Frontend/FrontendAction.cpp	(working copy)
@@ -265,7 +265,8 @@
   }
 
   // Set up the preprocessor.
-  CI.createPreprocessor();
+  if(!CI.hasPreprocessor())
+    CI.createPreprocessor();
 
   // Inform the diagnostic client we are processing a source file.
   CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(),
@@ -279,7 +280,8 @@
   // Create the AST context and consumer unless this is a preprocessor only
   // action.
   if (!usesPreprocessorOnly()) {
-    CI.createASTContext();
+    if(!CI.hasASTContext())
+      CI.createASTContext();
 
     OwningPtr<ASTConsumer> Consumer(
                                    CreateWrappedASTConsumer(CI, InputFile));


More information about the cfe-commits mailing list