[cfe-commits] r38936 - in /cfe/cfe/trunk: AST/ASTStreamer.cpp Parse/Parser.cpp Sema/ASTStreamer.cpp include/clang/Parse/Parser.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:25:59 PDT 2007


Author: sabre
Date: Wed Jul 11 11:25:58 2007
New Revision: 38936

URL: http://llvm.org/viewvc/llvm-project?rev=38936&view=rev
Log:
Hook up more of the ASTStreamer

Modified:
    cfe/cfe/trunk/AST/ASTStreamer.cpp
    cfe/cfe/trunk/Parse/Parser.cpp
    cfe/cfe/trunk/Sema/ASTStreamer.cpp
    cfe/cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/cfe/trunk/AST/ASTStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/ASTStreamer.cpp?rev=38936&r1=38935&r2=38936&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/ASTStreamer.cpp (original)
+++ cfe/cfe/trunk/AST/ASTStreamer.cpp Wed Jul 11 11:25:58 2007
@@ -30,13 +30,21 @@
       : P(PP, Builder) {
       PP.EnterSourceFile(MainFileID, 0, true);
       
-      // Parsing the specified input file.
-      P.ParseTranslationUnit();
+      // Initialize the parser.
+      P.Initialize();
     }
     
     /// ReadTopLevelDecl - Parse and return the next top-level declaration.
     Decl *ReadTopLevelDecl() {
-      return 0;
+      Parser::DeclTy *Result;
+      if (P.ParseTopLevelDecl(Result))
+        return 0;
+      Result = (Decl*)1; // FIXME!
+      return (Decl*)Result;
+    }
+    
+    ~ASTStreamer() {
+      P.Finalize();
     }
   };
 }

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

==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:25:58 2007
@@ -195,18 +195,16 @@
 // C99 6.9: External Definitions.
 //===----------------------------------------------------------------------===//
 
-/// ParseTranslationUnit:
-///       translation-unit: [C99 6.9]
-///         external-declaration 
-///         translation-unit external-declaration 
-void Parser::ParseTranslationUnit() {
+/// Initialize - Warm up the parser.
+///
+void Parser::Initialize() {
   // Prime the lexer look-ahead.
   ConsumeToken();
   
   // Create the global scope, install it as the current scope.
   assert(CurScope == 0 && "A scope is already active?");
   EnterScope();
-
+  
   
   // Install builtin types.
   // TODO: Move this someplace more useful.
@@ -217,23 +215,47 @@
     
     // TODO: add a 'TST_builtin' type?
     DS.TypeSpecType = DeclSpec::TST_typedef;
-
+    
     Declarator D(DS, Declarator::FileContext);
     D.SetIdentifier(PP.getIdentifierInfo("__builtin_va_list"),SourceLocation());
     Actions.ParseDeclarator(SourceLocation(), CurScope, D, 0);
   }
   
-  
   if (Tok.getKind() == tok::eof)  // Empty source file is an extension.
     Diag(diag::ext_empty_source_file);
+}
+
+/// ParseTopLevelDecl - Parse one top-level declaration, return whatever the
+/// action tells us to.  This returns true if the EOF was encountered.
+bool Parser::ParseTopLevelDecl(DeclTy*& Result) {
+  Result = 0;
+  if (Tok.getKind() == tok::eof) return true;
   
-  while (Tok.getKind() != tok::eof)
-    ParseExternalDeclaration();
-  
+  ParseExternalDeclaration();
+  return false;
+}
+
+/// Finalize - Shut down the parser.
+///
+void Parser::Finalize() {
   ExitScope();
   assert(CurScope == 0 && "Scope imbalance!");
 }
 
+/// ParseTranslationUnit:
+///       translation-unit: [C99 6.9]
+///         external-declaration 
+///         translation-unit external-declaration 
+void Parser::ParseTranslationUnit() {
+  Initialize();
+  
+  DeclTy *Res;
+  while (!ParseTopLevelDecl(Res))
+    /*parse them all*/;
+  
+  Finalize();
+}
+
 /// ParseExternalDeclaration:
 ///       external-declaration: [C99 6.9]
 ///         function-definition        [TODO]

Modified: cfe/cfe/trunk/Sema/ASTStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/ASTStreamer.cpp?rev=38936&r1=38935&r2=38936&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/ASTStreamer.cpp (original)
+++ cfe/cfe/trunk/Sema/ASTStreamer.cpp Wed Jul 11 11:25:58 2007
@@ -30,13 +30,21 @@
       : P(PP, Builder) {
       PP.EnterSourceFile(MainFileID, 0, true);
       
-      // Parsing the specified input file.
-      P.ParseTranslationUnit();
+      // Initialize the parser.
+      P.Initialize();
     }
     
     /// ReadTopLevelDecl - Parse and return the next top-level declaration.
     Decl *ReadTopLevelDecl() {
-      return 0;
+      Parser::DeclTy *Result;
+      if (P.ParseTopLevelDecl(Result))
+        return 0;
+      Result = (Decl*)1; // FIXME!
+      return (Decl*)Result;
+    }
+    
+    ~ASTStreamer() {
+      P.Finalize();
     }
   };
 }

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=38936&r1=38935&r2=38936&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:25:58 2007
@@ -46,16 +46,25 @@
   // Type forwarding.  All of these are statically 'void*', but they may all be
   // different actual classes based on the actions in place.
   typedef Action::ExprTy ExprTy;
+  typedef Action::DeclTy DeclTy;
   
   // Parsing methods.
+  
+  /// ParseTranslationUnit - All in one method that initializes parses, and
+  /// shuts down the parser.
   void ParseTranslationUnit();
   
-  struct ExprResult {
-    ExprTy *Val;
-    bool isInvalid;
-    
-    ExprResult(bool Invalid = false) : Val(0), isInvalid(Invalid) {}
-  };
+  /// Initialize - Warm up the parser.
+  ///
+  void Initialize();
+  
+  /// ParseTopLevelDecl - Parse one top-level declaration, return whatever the
+  /// action tells us to.  This returns true if the EOF was encountered.
+  bool ParseTopLevelDecl(DeclTy*& Result);
+  
+  /// Finalize - Shut down the parser.
+  ///
+  void Finalize();
   
 private:
   //===--------------------------------------------------------------------===//
@@ -209,6 +218,13 @@
   
   //===--------------------------------------------------------------------===//
   // C99 6.5: Expressions.
+
+  struct ExprResult {
+    ExprTy *Val;
+    bool isInvalid;
+    
+    ExprResult(bool Invalid = false) : Val(0), isInvalid(Invalid) {}
+  };
   
   ExprResult ParseExpression();
   ExprResult ParseConstantExpression();





More information about the cfe-commits mailing list