This is a small patch (my first) which I'm using to test the water for some
other changes in the same vein.

Basically, the Parser constructor was taking a spurious Preprocessor
parameter because the Sema already has a Preprocessor. This is a bug
waiting to happen if a user of this API passes a Preprocessor different
from the one owned by the Sema.

As I am using Clang's APIs for one-off tools (and binding to Lua), I found
a similar situation occurring in a couple other places. The red arrows in
this graph represent the spurious constructor parameters of other classes
http://web.ics.purdue.edu/~silvas/deps.svg . If this patch gets good
feedback I will fix up the other "red arrows" and submit another patch.
Hopefully this will simplify the API for making one-off tools (which is
currently pretty hairy and hard to use).

I basically changed the constructor and then fixed the compilation errors
that resulted from the signature change.

Note: patch produced by `git diff`.

--Sean Silva
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index 0c07621..9879853 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -197,7 +197,7 @@ class Parser : public CodeCompletionHandler {
   IdentifierInfo *getSEHExceptKeyword();
 
 public:
-  Parser(Preprocessor &PP, Sema &Actions);
+  explicit Parser(Sema &Actions);
   ~Parser();
 
   const LangOptions &getLang() const { return PP.getLangOptions(); }
diff --git a/lib/Parse/ParseAST.cpp b/lib/Parse/ParseAST.cpp
index 7e087ef..459e3ee 100644
--- a/lib/Parse/ParseAST.cpp
+++ b/lib/Parse/ParseAST.cpp
@@ -63,7 +63,7 @@ void clang::ParseAST(Sema &S, bool PrintStats) {
 
   ASTConsumer *Consumer = &S.getASTConsumer();
 
-  OwningPtr<Parser> ParseOP(new Parser(S.getPreprocessor(), S));
+  OwningPtr<Parser> ParseOP(new Parser(S));
   Parser &P = *ParseOP.get();
 
   PrettyStackTraceParserEntry CrashInfo(P);
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index 4d8f474..fa415c7 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -31,10 +31,11 @@ IdentifierInfo *Parser::getSEHExceptKeyword() {
   return Ident__except;
 }
 
-Parser::Parser(Preprocessor &pp, Sema &actions)
-  : PP(pp), Actions(actions), Diags(PP.getDiagnostics()),
-    GreaterThanIsOperator(true), ColonIsSacred(false), 
-    InMessageExpression(false), TemplateParameterDepth(0) {
+Parser::Parser(Sema &actions)
+  : PP(actions.getPreprocessor()), Actions(actions),
+    Diags(PP.getDiagnostics()), GreaterThanIsOperator(true),
+    ColonIsSacred(false), InMessageExpression(false),
+    TemplateParameterDepth(0) {
   Tok.setKind(tok::eof);
   Actions.CurScope = 0;
   NumCachedScopes = 0;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to