Commit dd429907 authored by Erik Verbruggen's avatar Erik Verbruggen

C++11: handle noexcept specifications.

Change-Id: I7da3affea2758b2e01124105e2521e1f2c5f6678
Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent a2f9ee87
......@@ -1161,7 +1161,7 @@ unsigned ExceptionDeclarationAST::lastToken() const
}
/** \generated */
unsigned ExceptionSpecificationAST::firstToken() const
unsigned DynamicExceptionSpecificationAST::firstToken() const
{
if (throw_token)
return throw_token;
......@@ -1178,7 +1178,7 @@ unsigned ExceptionSpecificationAST::firstToken() const
}
/** \generated */
unsigned ExceptionSpecificationAST::lastToken() const
unsigned DynamicExceptionSpecificationAST::lastToken() const
{
if (rparen_token)
return rparen_token + 1;
......@@ -4239,3 +4239,33 @@ unsigned PointerLiteralAST::lastToken() const
return 1;
}
/** \generated */
unsigned NoExceptSpecificationAST::firstToken() const
{
if (noexcept_token)
return noexcept_token;
if (lparen_token)
return lparen_token;
if (expression)
if (unsigned candidate = expression->firstToken())
return candidate;
if (rparen_token)
return rparen_token;
return 0;
}
/** \generated */
unsigned NoExceptSpecificationAST::lastToken() const
{
if (rparen_token)
return rparen_token + 1;
if (expression)
if (unsigned candidate = expression->lastToken())
return candidate;
if (lparen_token)
return lparen_token + 1;
if (noexcept_token)
return noexcept_token + 1;
return 1;
}
......@@ -159,6 +159,7 @@ public:
virtual DeleteExpressionAST *asDeleteExpression() { return 0; }
virtual DestructorNameAST *asDestructorName() { return 0; }
virtual DoStatementAST *asDoStatement() { return 0; }
virtual DynamicExceptionSpecificationAST *asDynamicExceptionSpecification() { return 0; }
virtual ElaboratedTypeSpecifierAST *asElaboratedTypeSpecifier() { return 0; }
virtual EmptyDeclarationAST *asEmptyDeclaration() { return 0; }
virtual EnumSpecifierAST *asEnumSpecifier() { return 0; }
......@@ -196,6 +197,7 @@ public:
virtual NewInitializerAST *asNewInitializer() { return 0; }
virtual NewPlacementAST *asNewPlacement() { return 0; }
virtual NewTypeIdAST *asNewTypeId() { return 0; }
virtual NoExceptSpecificationAST *asNoExceptSpecification() { return 0; }
virtual NumericLiteralAST *asNumericLiteral() { return 0; }
virtual ObjCClassDeclarationAST *asObjCClassDeclaration() { return 0; }
virtual ObjCClassForwardDeclarationAST *asObjCClassForwardDeclaration() { return 0; }
......@@ -1681,6 +1683,17 @@ protected:
class CPLUSPLUS_EXPORT ExceptionSpecificationAST: public AST
{
public:
ExceptionSpecificationAST()
{}
virtual ExceptionSpecificationAST *asExceptionSpecification() { return this; }
virtual ExceptionSpecificationAST *clone(MemoryPool *pool) const = 0;
};
class CPLUSPLUS_EXPORT DynamicExceptionSpecificationAST: public ExceptionSpecificationAST
{
public:
unsigned throw_token;
unsigned lparen_token;
......@@ -1689,7 +1702,7 @@ public:
unsigned rparen_token;
public:
ExceptionSpecificationAST()
DynamicExceptionSpecificationAST()
: throw_token(0)
, lparen_token(0)
, dot_dot_dot_token(0)
......@@ -1697,12 +1710,40 @@ public:
, rparen_token(0)
{}
virtual ExceptionSpecificationAST *asExceptionSpecification() { return this; }
virtual DynamicExceptionSpecificationAST *asDynamicExceptionSpecification() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual DynamicExceptionSpecificationAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT NoExceptSpecificationAST: public ExceptionSpecificationAST
{
public:
unsigned noexcept_token;
unsigned lparen_token;
ExpressionAST *expression;
unsigned rparen_token;
public:
NoExceptSpecificationAST()
: noexcept_token(0)
, lparen_token(0)
, expression(0)
, rparen_token(0)
{}
virtual NoExceptSpecificationAST *asNoExceptSpecification() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual ExceptionSpecificationAST *clone(MemoryPool *pool) const;
virtual NoExceptSpecificationAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
......
......@@ -578,9 +578,9 @@ ExceptionDeclarationAST *ExceptionDeclarationAST::clone(MemoryPool *pool) const
return ast;
}
ExceptionSpecificationAST *ExceptionSpecificationAST::clone(MemoryPool *pool) const
DynamicExceptionSpecificationAST *DynamicExceptionSpecificationAST::clone(MemoryPool *pool) const
{
ExceptionSpecificationAST *ast = new (pool) ExceptionSpecificationAST;
DynamicExceptionSpecificationAST *ast = new (pool) DynamicExceptionSpecificationAST;
ast->throw_token = throw_token;
ast->lparen_token = lparen_token;
ast->dot_dot_dot_token = dot_dot_dot_token;
......@@ -591,6 +591,17 @@ ExceptionSpecificationAST *ExceptionSpecificationAST::clone(MemoryPool *pool) co
return ast;
}
NoExceptSpecificationAST *NoExceptSpecificationAST::clone(MemoryPool *pool) const
{
NoExceptSpecificationAST *ast = new (pool) NoExceptSpecificationAST;
ast->noexcept_token = noexcept_token;
ast->lparen_token = lparen_token;
if (expression)
ast->expression = expression->clone(pool);
ast->rparen_token = rparen_token;
return ast;
}
ExpressionOrDeclarationStatementAST *ExpressionOrDeclarationStatementAST::clone(MemoryPool *pool) const
{
ExpressionOrDeclarationStatementAST *ast = new (pool) ExpressionOrDeclarationStatementAST;
......
......@@ -400,9 +400,17 @@ bool ExceptionDeclarationAST::match0(AST *pattern, ASTMatcher *matcher)
return false;
}
bool ExceptionSpecificationAST::match0(AST *pattern, ASTMatcher *matcher)
bool DynamicExceptionSpecificationAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (ExceptionSpecificationAST *_other = pattern->asExceptionSpecification())
if (DynamicExceptionSpecificationAST *_other = pattern->asDynamicExceptionSpecification())
return matcher->match(this, _other);
return false;
}
bool NoExceptSpecificationAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (NoExceptSpecificationAST *_other = pattern->asNoExceptSpecification())
return matcher->match(this, _other);
return false;
......
......@@ -968,7 +968,7 @@ bool ASTMatcher::match(ExceptionDeclarationAST *node, ExceptionDeclarationAST *p
return true;
}
bool ASTMatcher::match(ExceptionSpecificationAST *node, ExceptionSpecificationAST *pattern)
bool ASTMatcher::match(DynamicExceptionSpecificationAST *node, DynamicExceptionSpecificationAST *pattern)
{
(void) node;
(void) pattern;
......@@ -989,6 +989,25 @@ bool ASTMatcher::match(ExceptionSpecificationAST *node, ExceptionSpecificationAS
return true;
}
bool ASTMatcher::match(NoExceptSpecificationAST *node, NoExceptSpecificationAST *pattern)
{
(void) node;
(void) pattern;
pattern->noexcept_token = node->noexcept_token;
pattern->lparen_token = node->lparen_token;
if (! pattern->expression)
pattern->expression = node->expression;
else if (! AST::match(node->expression, pattern->expression, this))
return false;
pattern->rparen_token = node->rparen_token;
return true;
}
bool ASTMatcher::match(ExpressionOrDeclarationStatementAST *node, ExpressionOrDeclarationStatementAST *pattern)
{
(void) node;
......
......@@ -64,12 +64,12 @@ public:
virtual bool match(DeleteExpressionAST *node, DeleteExpressionAST *pattern);
virtual bool match(DestructorNameAST *node, DestructorNameAST *pattern);
virtual bool match(DoStatementAST *node, DoStatementAST *pattern);
virtual bool match(DynamicExceptionSpecificationAST *node, DynamicExceptionSpecificationAST *pattern);
virtual bool match(ElaboratedTypeSpecifierAST *node, ElaboratedTypeSpecifierAST *pattern);
virtual bool match(EmptyDeclarationAST *node, EmptyDeclarationAST *pattern);
virtual bool match(EnumSpecifierAST *node, EnumSpecifierAST *pattern);
virtual bool match(EnumeratorAST *node, EnumeratorAST *pattern);
virtual bool match(ExceptionDeclarationAST *node, ExceptionDeclarationAST *pattern);
virtual bool match(ExceptionSpecificationAST *node, ExceptionSpecificationAST *pattern);
virtual bool match(ExpressionOrDeclarationStatementAST *node, ExpressionOrDeclarationStatementAST *pattern);
virtual bool match(ExpressionStatementAST *node, ExpressionStatementAST *pattern);
virtual bool match(ForStatementAST *node, ForStatementAST *pattern);
......@@ -99,6 +99,7 @@ public:
virtual bool match(NewInitializerAST *node, NewInitializerAST *pattern);
virtual bool match(NewPlacementAST *node, NewPlacementAST *pattern);
virtual bool match(NewTypeIdAST *node, NewTypeIdAST *pattern);
virtual bool match(NoExceptSpecificationAST *node, NoExceptSpecificationAST *pattern);
virtual bool match(NumericLiteralAST *node, NumericLiteralAST *pattern);
virtual bool match(ObjCClassDeclarationAST *node, ObjCClassDeclarationAST *pattern);
virtual bool match(ObjCClassForwardDeclarationAST *node, ObjCClassForwardDeclarationAST *pattern);
......
......@@ -390,13 +390,20 @@ public:
return __ast;
}
ExceptionSpecificationAST *ExceptionSpecification(ExpressionListAST *type_id_list = 0)
DynamicExceptionSpecificationAST *DynamicExceptionSpecification(ExpressionListAST *type_id_list = 0)
{
ExceptionSpecificationAST *__ast = new (&pool) ExceptionSpecificationAST;
DynamicExceptionSpecificationAST *__ast = new (&pool) DynamicExceptionSpecificationAST;
__ast->type_id_list = type_id_list;
return __ast;
}
NoExceptSpecificationAST *NoExceptSpecification(ExpressionAST *expression = 0)
{
NoExceptSpecificationAST *__ast = new (&pool) NoExceptSpecificationAST;
__ast->expression = expression;
return __ast;
}
ExpressionOrDeclarationStatementAST *ExpressionOrDeclarationStatement(ExpressionStatementAST *expression = 0, DeclarationStatementAST *declaration = 0)
{
ExpressionOrDeclarationStatementAST *__ast = new (&pool) ExpressionOrDeclarationStatementAST;
......
......@@ -424,7 +424,7 @@ void ExceptionDeclarationAST::accept0(ASTVisitor *visitor)
visitor->endVisit(this);
}
void ExceptionSpecificationAST::accept0(ASTVisitor *visitor)
void DynamicExceptionSpecificationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(type_id_list, visitor);
......@@ -432,6 +432,14 @@ void ExceptionSpecificationAST::accept0(ASTVisitor *visitor)
visitor->endVisit(this);
}
void NoExceptSpecificationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(expression, visitor);
}
visitor->endVisit(this);
}
void ExpressionOrDeclarationStatementAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......
......@@ -106,12 +106,12 @@ public:
virtual bool visit(DeleteExpressionAST *) { return true; }
virtual bool visit(DestructorNameAST *) { return true; }
virtual bool visit(DoStatementAST *) { return true; }
virtual bool visit(DynamicExceptionSpecificationAST *) { return true; }
virtual bool visit(ElaboratedTypeSpecifierAST *) { return true; }
virtual bool visit(EmptyDeclarationAST *) { return true; }
virtual bool visit(EnumSpecifierAST *) { return true; }
virtual bool visit(EnumeratorAST *) { return true; }
virtual bool visit(ExceptionDeclarationAST *) { return true; }
virtual bool visit(ExceptionSpecificationAST *) { return true; }
virtual bool visit(ExpressionOrDeclarationStatementAST *) { return true; }
virtual bool visit(ExpressionStatementAST *) { return true; }
virtual bool visit(ForStatementAST *) { return true; }
......@@ -141,6 +141,7 @@ public:
virtual bool visit(NewInitializerAST *) { return true; }
virtual bool visit(NewPlacementAST *) { return true; }
virtual bool visit(NewTypeIdAST *) { return true; }
virtual bool visit(NoExceptSpecificationAST *) { return true; }
virtual bool visit(NumericLiteralAST *) { return true; }
virtual bool visit(ObjCClassDeclarationAST *) { return true; }
virtual bool visit(ObjCClassForwardDeclarationAST *) { return true; }
......@@ -246,12 +247,12 @@ public:
virtual void endVisit(DeleteExpressionAST *) {}
virtual void endVisit(DestructorNameAST *) {}
virtual void endVisit(DoStatementAST *) {}
virtual void endVisit(DynamicExceptionSpecificationAST *) {}
virtual void endVisit(ElaboratedTypeSpecifierAST *) {}
virtual void endVisit(EmptyDeclarationAST *) {}
virtual void endVisit(EnumSpecifierAST *) {}
virtual void endVisit(EnumeratorAST *) {}
virtual void endVisit(ExceptionDeclarationAST *) {}
virtual void endVisit(ExceptionSpecificationAST *) {}
virtual void endVisit(ExpressionOrDeclarationStatementAST *) {}
virtual void endVisit(ExpressionStatementAST *) {}
virtual void endVisit(ForStatementAST *) {}
......@@ -281,6 +282,7 @@ public:
virtual void endVisit(NewInitializerAST *) {}
virtual void endVisit(NewPlacementAST *) {}
virtual void endVisit(NewTypeIdAST *) {}
virtual void endVisit(NoExceptSpecificationAST *) {}
virtual void endVisit(NumericLiteralAST *) {}
virtual void endVisit(ObjCClassDeclarationAST *) {}
virtual void endVisit(ObjCClassForwardDeclarationAST *) {}
......
......@@ -66,6 +66,7 @@ class DeclaratorIdAST;
class DeleteExpressionAST;
class DestructorNameAST;
class DoStatementAST;
class DynamicExceptionSpecificationAST;
class ElaboratedTypeSpecifierAST;
class EmptyDeclarationAST;
class EnumSpecifierAST;
......@@ -103,6 +104,7 @@ class NewExpressionAST;
class NewInitializerAST;
class NewPlacementAST;
class NewTypeIdAST;
class NoExceptSpecificationAST;
class NumericLiteralAST;
class ObjCClassDeclarationAST;
class ObjCClassForwardDeclarationAST;
......
......@@ -473,7 +473,7 @@ void Bind::enumerator(EnumeratorAST *ast, Enum *symbol)
}
}
bool Bind::visit(ExceptionSpecificationAST *ast)
bool Bind::visit(DynamicExceptionSpecificationAST *ast)
{
(void) ast;
assert(!"unreachable");
......@@ -487,11 +487,15 @@ FullySpecifiedType Bind::exceptionSpecification(ExceptionSpecificationAST *ast,
if (! ast)
return type;
// unsigned throw_token = ast->throw_token;
// unsigned lparen_token = ast->lparen_token;
// unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
for (ExpressionListAST *it = ast->type_id_list; it; it = it->next) {
ExpressionTy value = this->expression(it->value);
if (DynamicExceptionSpecificationAST *dyn = ast->asDynamicExceptionSpecification()) {
// unsigned throw_token = ast->throw_token;
// unsigned lparen_token = ast->lparen_token;
// unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
for (ExpressionListAST *it = dyn->type_id_list; it; it = it->next) {
/*ExpressionTy value =*/ this->expression(it->value);
}
} else if (NoExceptSpecificationAST *no = ast->asNoExceptSpecification()) {
/*ExpressionTy value =*/ this->expression(no->expression);
}
// unsigned rparen_token = ast->rparen_token;
return type;
......
......@@ -119,7 +119,7 @@ protected:
virtual bool visit(BaseSpecifierAST *ast);
virtual bool visit(CtorInitializerAST *ast);
virtual bool visit(EnumeratorAST *ast);
virtual bool visit(ExceptionSpecificationAST *ast);
virtual bool visit(DynamicExceptionSpecificationAST *ast);
virtual bool visit(MemInitializerAST *ast);
virtual bool visit(NestedNameSpecifierAST *ast);
virtual bool visit(NewPlacementAST *ast);
......
......@@ -814,6 +814,23 @@ static inline int classify8(const char *s, bool q, bool x) {
}
}
}
else if (x && s[0] == 'n') {
if (s[1] == 'o') {
if (s[2] == 'e') {
if (s[3] == 'x') {
if (s[4] == 'c') {
if (s[5] == 'e') {
if (s[6] == 'p') {
if (s[7] == 't') {
return T_NOEXCEPT;
}
}
}
}
}
}
}
}
else if (s[0] == 'o') {
if (s[1] == 'p') {
if (s[2] == 'e') {
......
......@@ -2313,7 +2313,7 @@ bool Parser::parseExceptionSpecification(ExceptionSpecificationAST *&node)
{
DEBUG_THIS_RULE();
if (LA() == T_THROW) {
ExceptionSpecificationAST *ast = new (_pool) ExceptionSpecificationAST;
DynamicExceptionSpecificationAST *ast = new (_pool) DynamicExceptionSpecificationAST;
ast->throw_token = consumeToken();
if (LA() == T_LPAREN)
ast->lparen_token = consumeToken();
......@@ -2325,6 +2325,14 @@ bool Parser::parseExceptionSpecification(ExceptionSpecificationAST *&node)
ast->rparen_token = consumeToken();
node = ast;
return true;
} else if (_cxx0xEnabled && LA() == T_NOEXCEPT) {
NoExceptSpecificationAST *ast = new (_pool) NoExceptSpecificationAST;
ast->noexcept_token = consumeToken();
if (LA() == T_LPAREN && parseConstantExpression(ast->expression)) {
match(T_RPAREN, &ast->rparen_token);
}
node = ast;
return true;
}
return false;
}
......
......@@ -45,7 +45,8 @@ static const char *token_names[] = {
("delete"), ("do"), ("double"), ("dynamic_cast"), ("else"), ("enum"),
("explicit"), ("export"), ("extern"), ("false"), ("float"), ("for"),
("friend"), ("goto"), ("if"), ("inline"), ("int"), ("long"),
("mutable"), ("namespace"), ("new"), ("nullptr"), ("operator"), ("private"),
("mutable"), ("namespace"), ("new"), ("noexcept"),
("nullptr"), ("operator"), ("private"),
("protected"), ("public"), ("register"), ("reinterpret_cast"),
("return"), ("short"), ("signed"), ("sizeof"), ("static"),
("static_cast"), ("struct"), ("switch"), ("template"), ("this"),
......
......@@ -135,6 +135,7 @@ enum Kind {
T_MUTABLE,
T_NAMESPACE,
T_NEW,
T_NOEXCEPT,
T_NULLPTR,
T_OPERATOR,
T_PRIVATE,
......
......@@ -511,7 +511,7 @@ void FindUsages::enumerator(EnumeratorAST *ast)
this->expression(ast->expression);
}
bool FindUsages::visit(ExceptionSpecificationAST *ast)
bool FindUsages::visit(DynamicExceptionSpecificationAST *ast)
{
(void) ast;
Q_ASSERT(!"unreachable");
......@@ -523,13 +523,17 @@ void FindUsages::exceptionSpecification(ExceptionSpecificationAST *ast)
if (! ast)
return;
// unsigned throw_token = ast->throw_token;
// unsigned lparen_token = ast->lparen_token;
// unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
for (ExpressionListAST *it = ast->type_id_list; it; it = it->next) {
this->expression(it->value);
if (DynamicExceptionSpecificationAST *dyn = ast->asDynamicExceptionSpecification()) {
// unsigned throw_token = ast->throw_token;
// unsigned lparen_token = ast->lparen_token;
// unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
for (ExpressionListAST *it = dyn->type_id_list; it; it = it->next) {
this->expression(it->value);
}
// unsigned rparen_token = ast->rparen_token;
} else if (NoExceptSpecificationAST *no = ast->asNoExceptSpecification()) {
this->expression(no->expression);
}
// unsigned rparen_token = ast->rparen_token;
}
bool FindUsages::visit(MemInitializerAST *ast)
......
......@@ -138,7 +138,7 @@ protected:
virtual bool visit(BaseSpecifierAST *ast);
virtual bool visit(CtorInitializerAST *ast);
virtual bool visit(EnumeratorAST *ast);
virtual bool visit(ExceptionSpecificationAST *ast);
virtual bool visit(DynamicExceptionSpecificationAST *ast);
virtual bool visit(MemInitializerAST *ast);
virtual bool visit(NestedNameSpecifierAST *ast);
virtual bool visit(NewPlacementAST *ast);
......
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