blob: dad5e2423f2b361d94d123aac6599c016e202141 [file] [log] [blame]
Chris Lattner8f08cb72007-08-25 06:57:03 +00001//===--- ParseDeclCXX.cpp - C++ Declaration Parsing -----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the C++ Declaration portions of the Parser interfaces.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Parse/Parser.h"
15#include "clang/Parse/Scope.h"
16#include "clang/Basic/Diagnostic.h"
17using namespace clang;
18
19/// ParseNamespace - We know that the current token is a namespace keyword. This
20/// may either be a top level namespace or a block-level namespace alias.
21///
22/// namespace-definition: [C++ 7.3: basic.namespace]
23/// named-namespace-definition
24/// unnamed-namespace-definition
25///
26/// unnamed-namespace-definition:
27/// 'namespace' attributes[opt] '{' namespace-body '}'
28///
29/// named-namespace-definition:
30/// original-namespace-definition
31/// extension-namespace-definition
32///
33/// original-namespace-definition:
34/// 'namespace' identifier attributes[opt] '{' namespace-body '}'
35///
36/// extension-namespace-definition:
37/// 'namespace' original-namespace-name '{' namespace-body '}'
38///
39/// namespace-alias-definition: [C++ 7.3.2: namespace.alias]
40/// 'namespace' identifier '=' qualified-namespace-specifier ';'
41///
42Parser::DeclTy *Parser::ParseNamespace(unsigned Context) {
Chris Lattner04d66662007-10-09 17:33:22 +000043 assert(Tok.is(tok::kw_namespace) && "Not a namespace!");
Chris Lattner8f08cb72007-08-25 06:57:03 +000044 SourceLocation NamespaceLoc = ConsumeToken(); // eat the 'namespace'.
45
46 SourceLocation IdentLoc;
47 IdentifierInfo *Ident = 0;
48
Chris Lattner04d66662007-10-09 17:33:22 +000049 if (Tok.is(tok::identifier)) {
Chris Lattner8f08cb72007-08-25 06:57:03 +000050 Ident = Tok.getIdentifierInfo();
51 IdentLoc = ConsumeToken(); // eat the identifier.
52 }
53
54 // Read label attributes, if present.
55 DeclTy *AttrList = 0;
Chris Lattner04d66662007-10-09 17:33:22 +000056 if (Tok.is(tok::kw___attribute))
Chris Lattner8f08cb72007-08-25 06:57:03 +000057 // FIXME: save these somewhere.
58 AttrList = ParseAttributes();
59
Chris Lattner04d66662007-10-09 17:33:22 +000060 if (Tok.is(tok::equal)) {
Chris Lattner8f08cb72007-08-25 06:57:03 +000061 // FIXME: Verify no attributes were present.
62 // FIXME: parse this.
Chris Lattner04d66662007-10-09 17:33:22 +000063 } else if (Tok.is(tok::l_brace)) {
Chris Lattner8f08cb72007-08-25 06:57:03 +000064 SourceLocation LBrace = ConsumeBrace();
65 // FIXME: push a scope, push a namespace decl.
66
Chris Lattner04d66662007-10-09 17:33:22 +000067 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
Chris Lattnerbae35112007-08-25 18:15:16 +000068 // FIXME capture the decls.
69 ParseExternalDeclaration();
70 }
Chris Lattner8f08cb72007-08-25 06:57:03 +000071
72 SourceLocation RBrace = MatchRHSPunctuation(tok::r_brace, LBrace);
73
74 // FIXME: act on this.
75 } else {
76 unsigned D = Ident ? diag::err_expected_lbrace :
77 diag::err_expected_ident_lbrace;
78 Diag(Tok.getLocation(), D);
79 }
80
81 return 0;
82}