[cfe-commits] r67908 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseDeclCXX.cpp test/Parser/cxx-namespace-alias.cpp
Anders Carlsson
andersca at mac.com
Fri Mar 27 21:07:17 PDT 2009
Author: andersca
Date: Fri Mar 27 23:07:16 2009
New Revision: 67908
URL: http://llvm.org/viewvc/llvm-project?rev=67908&view=rev
Log:
Parse namespace aliases.
Added:
cfe/trunk/test/Parser/cxx-namespace-alias.cpp
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=67908&r1=67907&r2=67908&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Fri Mar 27 23:07:16 2009
@@ -997,7 +997,8 @@
DeclTy *ParseUsingDirective(unsigned Context, SourceLocation UsingLoc);
DeclTy *ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc);
DeclTy *ParseStaticAssertDeclaration();
-
+ DeclTy *ParseNamespaceAlias(SourceLocation AliasLoc, IdentifierInfo *Alias);
+
//===--------------------------------------------------------------------===//
// C++ 9: classes [class] and C structs/unions.
TypeTy *ParseClassName(SourceLocation &EndLocation,
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=67908&r1=67907&r2=67908&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Fri Mar 27 23:07:16 2009
@@ -60,11 +60,11 @@
// FIXME: save these somewhere.
AttrList = ParseAttributes();
- if (Tok.is(tok::equal)) {
+ if (Tok.is(tok::equal))
// FIXME: Verify no attributes were present.
- // FIXME: parse this.
- } else if (Tok.is(tok::l_brace)) {
-
+ return ParseNamespaceAlias(IdentLoc, Ident);
+
+ if (Tok.is(tok::l_brace)) {
SourceLocation LBrace = ConsumeBrace();
// Enter a scope for the namespace.
@@ -96,6 +96,37 @@
return 0;
}
+/// ParseNamespaceAlias - Parse the part after the '=' in a namespace
+/// alias definition.
+///
+Parser::DeclTy *Parser::ParseNamespaceAlias(SourceLocation AliasLoc,
+ IdentifierInfo *Alias) {
+ assert(Tok.is(tok::equal) && "Not equal token");
+
+ ConsumeToken(); // eat the '='.
+
+ CXXScopeSpec SS;
+ // Parse (optional) nested-name-specifier.
+ ParseOptionalCXXScopeSpecifier(SS);
+
+ if (SS.isInvalid() || Tok.isNot(tok::identifier)) {
+ Diag(Tok, diag::err_expected_namespace_name);
+ // Skip to end of the definition and eat the ';'.
+ SkipUntil(tok::semi);
+ return 0;
+ }
+
+ // Parse identifier.
+ IdentifierInfo *NamespaceName = Tok.getIdentifierInfo();
+ SourceLocation NamespaceLoc = ConsumeToken();
+
+ // Eat the ';'.
+ ExpectAndConsume(tok::semi, diag::err_expected_semi_after,
+ "namespace name", tok::semi);
+
+ return 0;
+}
+
/// ParseLinkage - We know that the current token is a string_literal
/// and just before that, that extern was seen.
///
Added: cfe/trunk/test/Parser/cxx-namespace-alias.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-namespace-alias.cpp?rev=67908&view=auto
==============================================================================
--- cfe/trunk/test/Parser/cxx-namespace-alias.cpp (added)
+++ cfe/trunk/test/Parser/cxx-namespace-alias.cpp Fri Mar 27 23:07:16 2009
@@ -0,0 +1,8 @@
+// RUN: clang-cc -parse-noop -verify %s
+
+namespace A = B;
+
+namespace A = !; // expected-error {{expected namespace name}}
+namespace A = A::!; // expected-error {{expected namespace name}}
+
+
More information about the cfe-commits
mailing list