Commit 13dd213f authored by Erik Verbruggen's avatar Erik Verbruggen

C++11: handle inline namespaces.

Change-Id: Iafdcd5bc72d9724e217767ae9c216be4363cc0d3
Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent c27a463f
......@@ -1817,6 +1817,8 @@ unsigned NamedTypeSpecifierAST::lastToken() const
/** \generated */
unsigned NamespaceAST::firstToken() const
{
if (inline_token)
return inline_token;
if (namespace_token)
return namespace_token;
if (identifier_token)
......@@ -1843,6 +1845,8 @@ unsigned NamespaceAST::lastToken() const
return identifier_token + 1;
if (namespace_token)
return namespace_token + 1;
if (inline_token)
return inline_token + 1;
return 1;
}
......
......@@ -2223,6 +2223,7 @@ protected:
class CPLUSPLUS_EXPORT NamespaceAST: public DeclarationAST
{
public:
unsigned inline_token;
unsigned namespace_token;
unsigned identifier_token;
SpecifierListAST *attribute_list;
......@@ -2233,7 +2234,8 @@ public: // annotations
public:
NamespaceAST()
: namespace_token(0)
: inline_token(0)
, namespace_token(0)
, identifier_token(0)
, attribute_list(0)
, linkage_body(0)
......
......@@ -810,6 +810,7 @@ TemplateIdAST *TemplateIdAST::clone(MemoryPool *pool) const
NamespaceAST *NamespaceAST::clone(MemoryPool *pool) const
{
NamespaceAST *ast = new (pool) NamespaceAST;
ast->inline_token = inline_token;
ast->namespace_token = namespace_token;
ast->identifier_token = identifier_token;
for (SpecifierListAST *iter = attribute_list, **ast_iter = &ast->attribute_list;
......
......@@ -1368,6 +1368,8 @@ bool ASTMatcher::match(NamespaceAST *node, NamespaceAST *pattern)
(void) node;
(void) pattern;
pattern->inline_token = node->inline_token;
pattern->namespace_token = node->namespace_token;
pattern->identifier_token = node->identifier_token;
......
......@@ -2123,6 +2123,7 @@ bool Bind::visit(NamespaceAST *ast)
Namespace *ns = control()->newNamespace(sourceLocation, namespaceName);
ns->setStartOffset(tokenAt(sourceLocation).end()); // the scope starts after the namespace or the identifier token.
ns->setEndOffset(tokenAt(ast->lastToken() - 1).end());
ns->setInline(ast->inline_token != 0);
ast->symbol = ns;
_scope->addMember(ns);
......
......@@ -621,6 +621,11 @@ bool Parser::parseDeclaration(DeclarationAST *&node)
consumeToken();
break;
case T_INLINE:
if (_cxx0xEnabled && LA(2) == T_NAMESPACE)
return parseNamespace(node);
// else: intentionally fall-through
default: {
if (_objCEnabled && LA() == T___ATTRIBUTE__) {
const unsigned start = cursor();
......@@ -706,12 +711,18 @@ bool Parser::parseLinkageBody(DeclarationAST *&node)
bool Parser::parseNamespace(DeclarationAST *&node)
{
DEBUG_THIS_RULE();
if (LA() != T_NAMESPACE)
if (LA() != T_NAMESPACE && !(_cxx0xEnabled && LA() == T_INLINE && LA(2) == T_NAMESPACE))
return false;
unsigned inline_token = 0;
if (cxx0xEnabled() && LA() == T_INLINE)
inline_token = consumeToken();
unsigned namespace_token = consumeToken();
if (LA() == T_IDENTIFIER && LA(2) == T_EQUAL) {
if (inline_token)
warning(inline_token, "namespace alias cannot be inline");
NamespaceAliasDefinitionAST *ast =
new (_pool) NamespaceAliasDefinitionAST;
ast->namespace_token = namespace_token;
......@@ -724,6 +735,7 @@ bool Parser::parseNamespace(DeclarationAST *&node)
}
NamespaceAST *ast = new (_pool) NamespaceAST;
ast->inline_token = inline_token;
ast->namespace_token = namespace_token;
if (LA() == T_IDENTIFIER)
ast->identifier_token = consumeToken();
......
......@@ -555,10 +555,12 @@ bool Template::matchType0(const Type *otherType, TypeMatcher *matcher) const
Namespace::Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
: Scope(translationUnit, sourceLocation, name)
, _isInline(false)
{ }
Namespace::Namespace(Clone *clone, Subst *subst, Namespace *original)
: Scope(clone, subst, original)
, _isInline(original->_isInline)
{ }
Namespace::~Namespace()
......
......@@ -445,10 +445,19 @@ public:
virtual Namespace *asNamespaceType()
{ return this; }
bool isInline() const
{ return _isInline; }
void setInline(bool onoff)
{ _isInline = onoff; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
virtual void accept0(TypeVisitor *visitor);
virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
private:
bool _isInline;
};
class CPLUSPLUS_EXPORT BaseClass: public Symbol
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment