diff options
-rw-r--r-- | Parse/ParseDecl.cpp | 27 | ||||
-rw-r--r-- | Parse/ParseDeclCXX.cpp | 79 | ||||
-rw-r--r-- | Parse/Parser.cpp | 1 | ||||
-rw-r--r-- | clang.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | include/clang/Basic/DiagnosticKinds.def | 2 | ||||
-rw-r--r-- | include/clang/Parse/Parser.h | 7 |
6 files changed, 115 insertions, 5 deletions
diff --git a/Parse/ParseDecl.cpp b/Parse/ParseDecl.cpp index e5c5bb97b2..d1dde24241 100644 --- a/Parse/ParseDecl.cpp +++ b/Parse/ParseDecl.cpp @@ -190,7 +190,28 @@ AttributeList *Parser::ParseAttributes() { /// 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 @@ Parser::DeclTy *Parser::ParseDeclaration(unsigned Context) { 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 diff --git a/Parse/ParseDeclCXX.cpp b/Parse/ParseDeclCXX.cpp new file mode 100644 index 0000000000..50f0c2a28d --- /dev/null +++ b/Parse/ParseDeclCXX.cpp @@ -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; +} diff --git a/Parse/Parser.cpp b/Parse/Parser.cpp index 255b48a7ca..0991675481 100644 --- a/Parse/Parser.cpp +++ b/Parse/Parser.cpp @@ -338,6 +338,7 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() { ConsumeToken(); } return 0; + case tok::kw_namespace: case tok::kw_typedef: // A function definition cannot start with a 'typedef' keyword. return ParseDeclaration(Declarator::FileContext); diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index 0f3d3f2b0a..cb6a73d08b 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -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; }; diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 920ba456eb..00bdd3f44d 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -326,6 +326,8 @@ DIAG(err_expected_ident_lparen, ERROR, "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, diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 97c0ca1d45..81af83ce54 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -364,6 +364,7 @@ private: // 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 @@ private: void ParseDirectDeclarator(Declarator &D); void ParseParenDeclarator(Declarator &D); void ParseBracketDeclarator(Declarator &D); + + //===--------------------------------------------------------------------===// + // C++ 7: Declarations [dcl.dcl] + + DeclTy *ParseNamespace(unsigned Context); + }; } // end namespace clang |