[cfe-commits] r41400 - in /cfe/trunk: Parse/ParseDecl.cpp Parse/ParseDeclCXX.cpp Parse/Parser.cpp clang.xcodeproj/project.pbxproj include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Parser.h

Chris Lattner sabre at nondot.org
Fri Aug 24 23:57:03 PDT 2007


Author: lattner
Date: Sat Aug 25 01:57:03 2007
New Revision: 41400

URL: http://llvm.org/viewvc/llvm-project?rev=41400&view=rev
Log:
refactor enough of the top-level parsing logic to parse and
ignore 'namespace foo {}'


Added:
    cfe/trunk/Parse/ParseDeclCXX.cpp
Modified:
    cfe/trunk/Parse/ParseDecl.cpp
    cfe/trunk/Parse/Parser.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseDecl.cpp?rev=41400&r1=41399&r2=41400&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/Parse/ParseDecl.cpp Sat Aug 25 01:57:03 2007
@@ -190,7 +190,28 @@
 /// ParseDeclaration - Parse a full 'declaration', which consists of
 /// declaration-specifiers, some number of declarators, and a semicolon.
 /// 'Context' should be a Declarator::TheContext value.
+///
+///       declaration: [C99 6.7]
+///         block-declaration ->
+///           simple-declaration
+///           others                   [FIXME]
+/// [C++]   namespace-definition
+///         others... [FIXME]
+///
 Parser::DeclTy *Parser::ParseDeclaration(unsigned Context) {
+  switch (Tok.getKind()) {
+  case tok::kw_namespace:
+    return ParseNamespace(Context);
+  default:
+    return ParseSimpleDeclaration(Context);
+  }
+}
+
+///       simple-declaration: [C99 6.7: declaration] [C++ 7p1: dcl.dcl]
+///         declaration-specifiers init-declarator-list[opt] ';'
+///[C90/C++]init-declarator-list ';'                             [TODO]
+/// [OMP]   threadprivate-directive                              [TODO]
+Parser::DeclTy *Parser::ParseSimpleDeclaration(unsigned Context) {
   // Parse the common declaration-specifiers piece.
   DeclSpec DS;
   ParseDeclarationSpecifiers(DS);
@@ -208,16 +229,12 @@
   return ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo);
 }
 
+
 /// ParseInitDeclaratorListAfterFirstDeclarator - Parse 'declaration' after
 /// parsing 'declaration-specifiers declarator'.  This method is split out this
 /// way to handle the ambiguity between top-level function-definitions and
 /// declarations.
 ///
-///       declaration: [C99 6.7]
-///         declaration-specifiers init-declarator-list[opt] ';' [TODO]
-/// [!C99]  init-declarator-list ';'                             [TODO]
-/// [OMP]   threadprivate-directive                              [TODO]
-///
 ///       init-declarator-list: [C99 6.7]
 ///         init-declarator
 ///         init-declarator-list ',' init-declarator

Added: cfe/trunk/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseDeclCXX.cpp?rev=41400&view=auto

==============================================================================
--- cfe/trunk/Parse/ParseDeclCXX.cpp (added)
+++ cfe/trunk/Parse/ParseDeclCXX.cpp Sat Aug 25 01:57:03 2007
@@ -0,0 +1,79 @@
+//===--- ParseDeclCXX.cpp - C++ Declaration Parsing -----------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file implements the C++ Declaration portions of the Parser interfaces.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Parse/Parser.h"
+#include "clang/Parse/Scope.h"
+#include "clang/Basic/Diagnostic.h"
+using namespace clang;
+
+/// ParseNamespace - We know that the current token is a namespace keyword. This
+/// may either be a top level namespace or a block-level namespace alias.
+///
+///       namespace-definition: [C++ 7.3: basic.namespace]
+///         named-namespace-definition
+///         unnamed-namespace-definition
+///
+///       unnamed-namespace-definition:
+///         'namespace' attributes[opt] '{' namespace-body '}'
+///
+///       named-namespace-definition:
+///         original-namespace-definition
+///         extension-namespace-definition
+///
+///       original-namespace-definition:
+///         'namespace' identifier attributes[opt] '{' namespace-body '}'
+///
+///       extension-namespace-definition:
+///         'namespace' original-namespace-name '{' namespace-body '}'
+///  
+///       namespace-alias-definition:  [C++ 7.3.2: namespace.alias]
+///         'namespace' identifier '=' qualified-namespace-specifier ';'
+///
+Parser::DeclTy *Parser::ParseNamespace(unsigned Context) {
+  assert(Tok.getKind() == tok::kw_namespace && "Not a namespace!");
+  SourceLocation NamespaceLoc = ConsumeToken();  // eat the 'namespace'.
+  
+  SourceLocation IdentLoc;
+  IdentifierInfo *Ident = 0;
+  
+  if (Tok.getKind() == tok::identifier) {
+    Ident = Tok.getIdentifierInfo();
+    IdentLoc = ConsumeToken();  // eat the identifier.
+  }
+  
+  // Read label attributes, if present.
+  DeclTy *AttrList = 0;
+  if (Tok.getKind() == tok::kw___attribute)
+    // FIXME: save these somewhere.
+    AttrList = ParseAttributes();
+  
+  if (Tok.getKind() == tok::equal) {
+    // FIXME: Verify no attributes were present.
+    // FIXME: parse this.
+  } else if (Tok.getKind() == tok::l_brace) {
+    SourceLocation LBrace = ConsumeBrace();
+    // FIXME: push a scope, push a namespace decl.
+    
+    // FIXME: Parse namespace-body
+    
+    SourceLocation RBrace = MatchRHSPunctuation(tok::r_brace, LBrace);
+    
+    // FIXME: act on this.
+  } else {
+    unsigned D = Ident ? diag::err_expected_lbrace : 
+                         diag::err_expected_ident_lbrace;
+    Diag(Tok.getLocation(), D);
+  }
+  
+  return 0;
+}

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

==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Sat Aug 25 01:57:03 2007
@@ -338,6 +338,7 @@
       ConsumeToken();
     }
     return 0;
+  case tok::kw_namespace:
   case tok::kw_typedef:
     // A function definition cannot start with a 'typedef' keyword.
     return ParseDeclaration(Declarator::FileContext);

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=41400&r1=41399&r2=41400&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Sat Aug 25 01:57:03 2007
@@ -29,6 +29,7 @@
 		DE1F22030A7D852A00FBF588 /* Parser.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE1F22020A7D852A00FBF588 /* Parser.h */; };
 		DE224FF80C7AA98800D370A5 /* CGExprComplex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE224FF70C7AA98800D370A5 /* CGExprComplex.cpp */; };
 		DE2252700C7E82D000D370A5 /* CGExprScalar.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE22526F0C7E82D000D370A5 /* CGExprScalar.cpp */; };
+		DE2255FC0C8004E600D370A5 /* ParseDeclCXX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE2255FB0C8004E600D370A5 /* ParseDeclCXX.cpp */; };
 		DE344AB80AE5DF6D00DBC861 /* HeaderSearch.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE344AB70AE5DF6D00DBC861 /* HeaderSearch.h */; };
 		DE344B540AE5E46C00DBC861 /* HeaderSearch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE344B530AE5E46C00DBC861 /* HeaderSearch.cpp */; };
 		DE3450D70AEB543100DBC861 /* DirectoryLookup.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE3450D60AEB543100DBC861 /* DirectoryLookup.h */; };
@@ -224,6 +225,7 @@
 		DE1F22020A7D852A00FBF588 /* Parser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Parser.h; path = clang/Parse/Parser.h; sourceTree = "<group>"; };
 		DE224FF70C7AA98800D370A5 /* CGExprComplex.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = CGExprComplex.cpp; path = CodeGen/CGExprComplex.cpp; sourceTree = "<group>"; };
 		DE22526F0C7E82D000D370A5 /* CGExprScalar.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = CGExprScalar.cpp; path = CodeGen/CGExprScalar.cpp; sourceTree = "<group>"; };
+		DE2255FB0C8004E600D370A5 /* ParseDeclCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseDeclCXX.cpp; path = Parse/ParseDeclCXX.cpp; sourceTree = "<group>"; };
 		DE344AB70AE5DF6D00DBC861 /* HeaderSearch.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = HeaderSearch.h; sourceTree = "<group>"; };
 		DE344B530AE5E46C00DBC861 /* HeaderSearch.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = HeaderSearch.cpp; sourceTree = "<group>"; };
 		DE3450D60AEB543100DBC861 /* DirectoryLookup.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DirectoryLookup.h; sourceTree = "<group>"; };
@@ -401,6 +403,7 @@
 				DE06D42F0A8BB52D0050E87E /* Parser.cpp */,
 				DE3460040AFDCC6500DBC861 /* ParseInit.cpp */,
 				DE34600E0AFDCCCE00DBC861 /* ParseDecl.cpp */,
+				DE2255FB0C8004E600D370A5 /* ParseDeclCXX.cpp */,
 				DE3460120AFDCCDA00DBC861 /* ParseExpr.cpp */,
 				DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */,
 				DE34600A0AFDCCBF00DBC861 /* ParseStmt.cpp */,
@@ -712,6 +715,7 @@
 				DEC63B1A0C7B940200DBF169 /* CFG.cpp in Sources */,
 				DE2252700C7E82D000D370A5 /* CGExprScalar.cpp in Sources */,
 				35260CA50C7F75C000D66CE9 /* ExprCXX.cpp in Sources */,
+				DE2255FC0C8004E600D370A5 /* ParseDeclCXX.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=41400&r1=41399&r2=41400&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Sat Aug 25 01:57:03 2007
@@ -326,6 +326,8 @@
      "expected identifier or '('")
 DIAG(err_expected_ident_lbrace, ERROR,
      "expected identifier or '{'")
+DIAG(err_expected_lbrace, ERROR,
+     "expected '{'")
 DIAG(err_expected_rparen, ERROR,
      "expected ')'")
 DIAG(err_expected_rsquare, ERROR,

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sat Aug 25 01:57:03 2007
@@ -364,6 +364,7 @@
   // C99 6.7: Declarations.
   
   DeclTy *ParseDeclaration(unsigned Context);
+  DeclTy *ParseSimpleDeclaration(unsigned Context);
   DeclTy *ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D);
   void ParseDeclarationSpecifiers(DeclSpec &DS);
   void ParseSpecifierQualifierList(DeclSpec &DS);
@@ -391,6 +392,12 @@
   void ParseDirectDeclarator(Declarator &D);
   void ParseParenDeclarator(Declarator &D);
   void ParseBracketDeclarator(Declarator &D);
+  
+  //===--------------------------------------------------------------------===//
+  // C++ 7: Declarations [dcl.dcl]
+  
+  DeclTy *ParseNamespace(unsigned Context);
+
 };
 
 }  // end namespace clang





More information about the cfe-commits mailing list