2007-08-25 10:57:03 +04:00
|
|
|
//===--- 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) {
|
2007-10-09 21:33:22 +04:00
|
|
|
assert(Tok.is(tok::kw_namespace) && "Not a namespace!");
|
2007-08-25 10:57:03 +04:00
|
|
|
SourceLocation NamespaceLoc = ConsumeToken(); // eat the 'namespace'.
|
|
|
|
|
|
|
|
SourceLocation IdentLoc;
|
|
|
|
IdentifierInfo *Ident = 0;
|
|
|
|
|
2007-10-09 21:33:22 +04:00
|
|
|
if (Tok.is(tok::identifier)) {
|
2007-08-25 10:57:03 +04:00
|
|
|
Ident = Tok.getIdentifierInfo();
|
|
|
|
IdentLoc = ConsumeToken(); // eat the identifier.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read label attributes, if present.
|
|
|
|
DeclTy *AttrList = 0;
|
2007-10-09 21:33:22 +04:00
|
|
|
if (Tok.is(tok::kw___attribute))
|
2007-08-25 10:57:03 +04:00
|
|
|
// FIXME: save these somewhere.
|
|
|
|
AttrList = ParseAttributes();
|
|
|
|
|
2007-10-09 21:33:22 +04:00
|
|
|
if (Tok.is(tok::equal)) {
|
2007-08-25 10:57:03 +04:00
|
|
|
// FIXME: Verify no attributes were present.
|
|
|
|
// FIXME: parse this.
|
2007-10-09 21:33:22 +04:00
|
|
|
} else if (Tok.is(tok::l_brace)) {
|
2007-08-25 10:57:03 +04:00
|
|
|
SourceLocation LBrace = ConsumeBrace();
|
|
|
|
// FIXME: push a scope, push a namespace decl.
|
|
|
|
|
2007-10-09 21:33:22 +04:00
|
|
|
while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
|
2007-08-25 22:15:16 +04:00
|
|
|
// FIXME capture the decls.
|
|
|
|
ParseExternalDeclaration();
|
|
|
|
}
|
2007-08-25 10:57:03 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|