[cfe-commits] r39133 - in /cfe/cfe/trunk: AST/Sema.h Driver/PrintParserCallbacks.cpp Driver/clang.cpp Driver/clang.h Parse/ParseStmt.cpp Parse/Parser.cpp Sema/Sema.h include/clang/Parse/Action.h include/clang/Parse/Parser.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:27:53 PDT 2007


Author: sabre
Date: Wed Jul 11 11:27:52 2007
New Revision: 39133

URL: http://llvm.org/viewvc/llvm-project?rev=39133&view=rev
Log:
start factoring actions into two flavors: minimal and semantic actions.

Modified:
    cfe/cfe/trunk/AST/Sema.h
    cfe/cfe/trunk/Driver/PrintParserCallbacks.cpp
    cfe/cfe/trunk/Driver/clang.cpp
    cfe/cfe/trunk/Driver/clang.h
    cfe/cfe/trunk/Parse/ParseStmt.cpp
    cfe/cfe/trunk/Parse/Parser.cpp
    cfe/cfe/trunk/Sema/Sema.h
    cfe/cfe/trunk/include/clang/Parse/Action.h
    cfe/cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/cfe/trunk/AST/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.h?rev=39133&r1=39132&r2=39133&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Sema.h (original)
+++ cfe/cfe/trunk/AST/Sema.h Wed Jul 11 11:27:52 2007
@@ -26,7 +26,7 @@
 /// builds AST nodes for the code being parsed.  Clients can either use this
 /// unmodified or subclass it and overload methods to do more specialized
 /// things.
-class ASTBuilder : public Action {
+class ASTBuilder : public SemanticAction {
   Preprocessor &PP;
   
   /// LastInGroupList - This vector is populated when there are multiple

Modified: cfe/cfe/trunk/Driver/PrintParserCallbacks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/PrintParserCallbacks.cpp?rev=39133&r1=39132&r2=39133&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/PrintParserCallbacks.cpp (original)
+++ cfe/cfe/trunk/Driver/PrintParserCallbacks.cpp Wed Jul 11 11:27:52 2007
@@ -52,6 +52,6 @@
   };
 }
 
-Action *llvm::clang::CreatePrintParserActionsAction() {
+MinimalAction *llvm::clang::CreatePrintParserActionsAction() {
   return new ParserPrintActions();
 }

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39133&r1=39132&r2=39133&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:27:52 2007
@@ -774,7 +774,7 @@
 // Basic Parser driver
 //===----------------------------------------------------------------------===//
 
-static void ParseFile(Preprocessor &PP, Action *PA, unsigned MainFileID) {
+static void ParseFile(Preprocessor &PP, MinimalAction *PA, unsigned MainFileID){
   Parser P(PP, *PA);
   PP.EnterSourceFile(MainFileID, 0, true);
   

Modified: cfe/cfe/trunk/Driver/clang.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.h?rev=39133&r1=39132&r2=39133&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.h (original)
+++ cfe/cfe/trunk/Driver/clang.h Wed Jul 11 11:27:52 2007
@@ -18,7 +18,7 @@
 namespace clang {
 class Preprocessor;
 class LangOptions;
-class Action;
+class MinimalAction;
 class TargetInfo;
 class Diagnostic;
 
@@ -28,7 +28,7 @@
 
 /// CreatePrintParserActionsAction - Return the actions implementation that
 /// implements the -parse-print-callbacks option.
-Action *CreatePrintParserActionsAction();
+MinimalAction *CreatePrintParserActionsAction();
 
 /// CreateTargetInfo - Return the set of target info objects as specified by
 /// the -arch command line option.

Modified: cfe/cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseStmt.cpp?rev=39133&r1=39132&r2=39133&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseStmt.cpp Wed Jul 11 11:27:52 2007
@@ -179,9 +179,8 @@
 ///         expression[opt] ';'
 ///
 Parser::StmtResult Parser::ParseIdentifierStatement(bool OnlyStatement) {
-  IdentifierInfo *II = Tok.getIdentifierInfo();
-  assert(Tok.getKind() == tok::identifier && II && "Not an identifier!");
-  II=II; // FIXME: SILENCE WARNING UNTIL THIS IS USED.
+  assert(Tok.getKind() == tok::identifier && Tok.getIdentifierInfo() &&
+         "Not an identifier!");
 
   LexerToken IdentTok = Tok;  // Save the whole token.
   ConsumeToken();  // eat the identifier.
@@ -211,6 +210,7 @@
     DeclSpec DS;
     
     // FIXME: Add the typedef name to the start of the decl-specs.
+    
     // ParseDeclarationSpecifiers will continue from there.
     ParseDeclarationSpecifiers(DS);
 

Modified: cfe/cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/Parser.cpp?rev=39133&r1=39132&r2=39133&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:27:52 2007
@@ -17,8 +17,20 @@
 using namespace llvm;
 using namespace clang;
 
-Parser::Parser(Preprocessor &pp, Action &actions)
-  : PP(pp), Actions(actions), Diags(PP.getDiagnostics()) {
+Parser::Parser(Preprocessor &pp, MinimalAction &MinActions)
+  : PP(pp), Actions(MinActions), Diags(PP.getDiagnostics()) {
+  MinimalActions = &MinActions;
+  SemaActions = 0;
+  Tok.setKind(tok::eof);
+  CurScope = 0;
+  
+  ParenCount = BracketCount = BraceCount = 0;
+}
+
+Parser::Parser(Preprocessor &pp, SemanticAction &SemanticActions)
+  : PP(pp), Actions(SemanticActions), Diags(PP.getDiagnostics()) {
+  MinimalActions = 0;
+  SemaActions = &SemanticActions;
   Tok.setKind(tok::eof);
   CurScope = 0;
   

Modified: cfe/cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.h?rev=39133&r1=39132&r2=39133&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.h (original)
+++ cfe/cfe/trunk/Sema/Sema.h Wed Jul 11 11:27:52 2007
@@ -26,7 +26,7 @@
 /// builds AST nodes for the code being parsed.  Clients can either use this
 /// unmodified or subclass it and overload methods to do more specialized
 /// things.
-class ASTBuilder : public Action {
+class ASTBuilder : public SemanticAction {
   Preprocessor &PP;
   
   /// LastInGroupList - This vector is populated when there are multiple

Modified: cfe/cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Action.h?rev=39133&r1=39132&r2=39133&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Action.h Wed Jul 11 11:27:52 2007
@@ -275,12 +275,31 @@
   }
 };
 
+/// MinimalAction - Minimal actions are used by light-weight clients of the
+/// parser that do not need name resolution or significant semantic analysis to
+/// be performed.  The actions implemented here are in the form of unresolved
+/// identifiers.  By using a simpler interface than the SemanticAction class,
+/// the parser doesn't have to build complex data structures and thus runs more
+/// quickly.
+class MinimalAction : public Action {
+public:
+};
+
+/// SemanticAction - Clients the implement this interface expect Decl nodes to 
+/// be created, name lookup to be performed, and full semantic analysis of the
+/// source program to be performed.
+class SemanticAction : public Action {
+public:
+  
+};
+
+
 
 /// EmptyAction - This is a simple (bare-minimum) implementation of the Action
 /// class, which only keeps track of which typedefs are in-scope.  This class is
 /// useful to subclass if clients want to implement some actions without having
 /// to reimplement all of the scoping rules.
-class EmptyAction : public Action {
+class EmptyAction : public MinimalAction {
 public:
   /// isTypeName - This looks at the IdentifierInfo::FETokenInfo field to
   /// determine whether the name is a typedef or not in this scope.
@@ -299,9 +318,11 @@
   virtual DeclTy *ParsedClassDeclaration(Scope *S,
                                          IdentifierInfo **IdentList,
                                          unsigned NumElts);
-
-};
   
+};
+
+
+
 }  // end namespace clang
 }  // end namespace llvm
 

Modified: cfe/cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Parser.h?rev=39133&r1=39132&r2=39133&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:27:52 2007
@@ -29,16 +29,29 @@
 ///
 class Parser {
   Preprocessor &PP;
-  Action &Actions;
-  Diagnostic &Diags;
-  Scope *CurScope;
-  unsigned short ParenCount, BracketCount, BraceCount;
   
   /// Tok - The current token we are peeking head.  All parsing methods assume
   /// that this is valid.
   LexerToken Tok;
+  
+  unsigned short ParenCount, BracketCount, BraceCount;
+
+  /// Actions - These are the callbacks we invoke as we parse various constructs
+  /// in the file.  This refers to the common base class between MinimalActions
+  /// and SemaActions for those uses that don't matter.
+  Action &Actions;
+  
+  /// MinimalActions/SemaActions - Exactly one of these two pointers is non-null
+  /// depending on whether the client of the parser wants semantic analysis,
+  /// name binding, and Decl creation performed or not.
+  MinimalAction  *MinimalActions;
+  SemanticAction *SemaActions;
+  
+  Scope *CurScope;
+  Diagnostic &Diags;
 public:
-  Parser(Preprocessor &PP, Action &Actions);
+  Parser(Preprocessor &PP, MinimalAction &MinActions);
+  Parser(Preprocessor &PP, SemanticAction &SemaActions);
   ~Parser();
 
   const LangOptions &getLang() const { return PP.getLangOptions(); }





More information about the cfe-commits mailing list