Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit f67606a

Browse files
author
Anders Carlsson
committed
Parse namespace aliases.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67908 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 678dc3b commit f67606a

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

include/clang/Parse/Parser.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,8 @@ class Parser {
997997
DeclTy *ParseUsingDirective(unsigned Context, SourceLocation UsingLoc);
998998
DeclTy *ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc);
999999
DeclTy *ParseStaticAssertDeclaration();
1000-
1000+
DeclTy *ParseNamespaceAlias(SourceLocation AliasLoc, IdentifierInfo *Alias);
1001+
10011002
//===--------------------------------------------------------------------===//
10021003
// C++ 9: classes [class] and C structs/unions.
10031004
TypeTy *ParseClassName(SourceLocation &EndLocation,

lib/Parse/ParseDeclCXX.cpp

+35-4
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ Parser::DeclTy *Parser::ParseNamespace(unsigned Context) {
6060
// FIXME: save these somewhere.
6161
AttrList = ParseAttributes();
6262

63-
if (Tok.is(tok::equal)) {
63+
if (Tok.is(tok::equal))
6464
// FIXME: Verify no attributes were present.
65-
// FIXME: parse this.
66-
} else if (Tok.is(tok::l_brace)) {
67-
65+
return ParseNamespaceAlias(IdentLoc, Ident);
66+
67+
if (Tok.is(tok::l_brace)) {
6868
SourceLocation LBrace = ConsumeBrace();
6969

7070
// Enter a scope for the namespace.
@@ -96,6 +96,37 @@ Parser::DeclTy *Parser::ParseNamespace(unsigned Context) {
9696
return 0;
9797
}
9898

99+
/// ParseNamespaceAlias - Parse the part after the '=' in a namespace
100+
/// alias definition.
101+
///
102+
Parser::DeclTy *Parser::ParseNamespaceAlias(SourceLocation AliasLoc,
103+
IdentifierInfo *Alias) {
104+
assert(Tok.is(tok::equal) && "Not equal token");
105+
106+
ConsumeToken(); // eat the '='.
107+
108+
CXXScopeSpec SS;
109+
// Parse (optional) nested-name-specifier.
110+
ParseOptionalCXXScopeSpecifier(SS);
111+
112+
if (SS.isInvalid() || Tok.isNot(tok::identifier)) {
113+
Diag(Tok, diag::err_expected_namespace_name);
114+
// Skip to end of the definition and eat the ';'.
115+
SkipUntil(tok::semi);
116+
return 0;
117+
}
118+
119+
// Parse identifier.
120+
IdentifierInfo *NamespaceName = Tok.getIdentifierInfo();
121+
SourceLocation NamespaceLoc = ConsumeToken();
122+
123+
// Eat the ';'.
124+
ExpectAndConsume(tok::semi, diag::err_expected_semi_after,
125+
"namespace name", tok::semi);
126+
127+
return 0;
128+
}
129+
99130
/// ParseLinkage - We know that the current token is a string_literal
100131
/// and just before that, that extern was seen.
101132
///

test/Parser/cxx-namespace-alias.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: clang-cc -parse-noop -verify %s
2+
3+
namespace A = B;
4+
5+
namespace A = !; // expected-error {{expected namespace name}}
6+
namespace A = A::!; // expected-error {{expected namespace name}}
7+
8+

0 commit comments

Comments
 (0)