Commit 3f5dc36a authored by Erik Verbruggen's avatar Erik Verbruggen

C++11: first set of changes for decltype.

Change-Id: I49d6ff7eb1805cd07bdfcb27bb37d4c6cadc9115
Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent 07d335b2
......@@ -4313,3 +4313,33 @@ unsigned StaticAssertDeclarationAST::lastToken() const
return 1;
}
/** \generated */
unsigned DecltypeSpecifierAST::firstToken() const
{
if (decltype_token)
return decltype_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 DecltypeSpecifierAST::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 (decltype_token)
return decltype_token + 1;
return 1;
}
......@@ -156,6 +156,7 @@ public:
virtual DeclarationStatementAST *asDeclarationStatement() { return 0; }
virtual DeclaratorAST *asDeclarator() { return 0; }
virtual DeclaratorIdAST *asDeclaratorId() { return 0; }
virtual DecltypeSpecifierAST *asDecltypeSpecifier() { return 0; }
virtual DeleteExpressionAST *asDeleteExpression() { return 0; }
virtual DestructorNameAST *asDestructorName() { return 0; }
virtual DoStatementAST *asDoStatement() { return 0; }
......@@ -542,6 +543,34 @@ protected:
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT DecltypeSpecifierAST: public SpecifierAST
{
public:
unsigned decltype_token;
unsigned lparen_token;
ExpressionAST *expression;
unsigned rparen_token;
public:
DecltypeSpecifierAST()
: decltype_token(0)
, lparen_token(0)
, expression(0)
, rparen_token(0)
{}
virtual DecltypeSpecifierAST *asDecltypeSpecifier() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual DecltypeSpecifierAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT DeclaratorAST: public AST
{
public:
......
......@@ -93,6 +93,17 @@ TypeofSpecifierAST *TypeofSpecifierAST::clone(MemoryPool *pool) const
return ast;
}
DecltypeSpecifierAST *DecltypeSpecifierAST::clone(MemoryPool *pool) const
{
DecltypeSpecifierAST *ast = new (pool) DecltypeSpecifierAST;
ast->decltype_token = decltype_token;
ast->lparen_token = lparen_token;
if (expression)
ast->expression = expression->clone(pool);
ast->rparen_token = rparen_token;
return ast;
}
DeclaratorAST *DeclaratorAST::clone(MemoryPool *pool) const
{
DeclaratorAST *ast = new (pool) DeclaratorAST;
......
......@@ -80,6 +80,14 @@ bool TypeofSpecifierAST::match0(AST *pattern, ASTMatcher *matcher)
return false;
}
bool DecltypeSpecifierAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (DecltypeSpecifierAST *_other = pattern->asDecltypeSpecifier())
return matcher->match(this, _other);
return false;
}
bool DeclaratorAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (DeclaratorAST *_other = pattern->asDeclarator())
......
......@@ -136,6 +136,25 @@ bool ASTMatcher::match(TypeofSpecifierAST *node, TypeofSpecifierAST *pattern)
return true;
}
bool ASTMatcher::match(DecltypeSpecifierAST *node, DecltypeSpecifierAST *pattern)
{
(void) node;
(void) pattern;
pattern->decltype_token = node->decltype_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(DeclaratorAST *node, DeclaratorAST *pattern)
{
(void) node;
......
......@@ -61,6 +61,7 @@ public:
virtual bool match(DeclarationStatementAST *node, DeclarationStatementAST *pattern);
virtual bool match(DeclaratorAST *node, DeclaratorAST *pattern);
virtual bool match(DeclaratorIdAST *node, DeclaratorIdAST *pattern);
virtual bool match(DecltypeSpecifierAST *node, DecltypeSpecifierAST *pattern);
virtual bool match(DeleteExpressionAST *node, DeleteExpressionAST *pattern);
virtual bool match(DestructorNameAST *node, DestructorNameAST *pattern);
virtual bool match(DoStatementAST *node, DoStatementAST *pattern);
......
......@@ -84,6 +84,13 @@ public:
return __ast;
}
DecltypeSpecifierAST *DecltypeSpecifier(ExpressionAST *expression = 0)
{
DecltypeSpecifierAST *__ast = new (&pool) DecltypeSpecifierAST;
__ast->expression = expression;
return __ast;
}
DeclaratorAST *Declarator(SpecifierListAST *attribute_list = 0, PtrOperatorListAST *ptr_operator_list = 0, CoreDeclaratorAST *core_declarator = 0, PostfixDeclaratorListAST *postfix_declarator_list = 0, SpecifierListAST *post_attribute_list = 0, ExpressionAST *initializer = 0)
{
DeclaratorAST *__ast = new (&pool) DeclaratorAST;
......
......@@ -78,6 +78,14 @@ void TypeofSpecifierAST::accept0(ASTVisitor *visitor)
visitor->endVisit(this);
}
void DecltypeSpecifierAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(expression, visitor);
}
visitor->endVisit(this);
}
void DeclaratorAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......
......@@ -103,6 +103,7 @@ public:
virtual bool visit(DeclarationStatementAST *) { return true; }
virtual bool visit(DeclaratorAST *) { return true; }
virtual bool visit(DeclaratorIdAST *) { return true; }
virtual bool visit(DecltypeSpecifierAST *) { return true; }
virtual bool visit(DeleteExpressionAST *) { return true; }
virtual bool visit(DestructorNameAST *) { return true; }
virtual bool visit(DoStatementAST *) { return true; }
......@@ -245,6 +246,7 @@ public:
virtual void endVisit(DeclarationStatementAST *) {}
virtual void endVisit(DeclaratorAST *) {}
virtual void endVisit(DeclaratorIdAST *) {}
virtual void endVisit(DecltypeSpecifierAST *) {}
virtual void endVisit(DeleteExpressionAST *) {}
virtual void endVisit(DestructorNameAST *) {}
virtual void endVisit(DoStatementAST *) {}
......
......@@ -63,6 +63,7 @@ class DeclarationAST;
class DeclarationStatementAST;
class DeclaratorAST;
class DeclaratorIdAST;
class DecltypeSpecifierAST;
class DeleteExpressionAST;
class DestructorNameAST;
class DoStatementAST;
......
......@@ -2799,6 +2799,12 @@ bool Bind::visit(TypeofSpecifierAST *ast)
return false;
}
bool Bind::visit(DecltypeSpecifierAST *ast)
{
_type = this->expression(ast->expression);
return false;
}
bool Bind::visit(ClassSpecifierAST *ast)
{
// unsigned classkey_token = ast->classkey_token;
......
......@@ -245,6 +245,7 @@ protected:
virtual bool visit(SimpleSpecifierAST *ast);
virtual bool visit(AttributeSpecifierAST *ast);
virtual bool visit(TypeofSpecifierAST *ast);
virtual bool visit(DecltypeSpecifierAST *ast);
virtual bool visit(ClassSpecifierAST *ast);
virtual bool visit(NamedTypeSpecifierAST *ast);
virtual bool visit(ElaboratedTypeSpecifierAST *ast);
......
......@@ -788,7 +788,7 @@ static inline int classify8(const char *s, bool q, bool x) {
if (s[5] == 'y') {
if (s[6] == 'p') {
if (s[7] == 'e') {
return T___TYPEOF;
return T_DECLTYPE;
}
}
}
......@@ -1110,6 +1110,23 @@ static inline int classify10(const char *s, bool q, bool) {
}
}
}
else if (s[2] == 'd') {
if (s[3] == 'e') {
if (s[4] == 'c') {
if (s[5] == 'l') {
if (s[6] == 't') {
if (s[7] == 'y') {
if (s[8] == 'p') {
if (s[9] == 'e') {
return T___DECLTYPE;
}
}
}
}
}
}
}
}
else if (s[2] == 't') {
if (s[3] == 'y') {
if (s[4] == 'p') {
......
......@@ -3483,6 +3483,7 @@ bool Parser::lookAtBuiltinTypeSpecifier() const
case T_DOUBLE:
case T_VOID:
case T_AUTO:
case T_DECLTYPE:
return true;
// [gcc] extensions
case T___TYPEOF__:
......@@ -3579,6 +3580,17 @@ bool Parser::parseBuiltinTypeSpecifier(SpecifierListAST *&node)
parseUnaryExpression(ast->expression);
node = new (_pool) SpecifierListAST(ast);
return true;
} else if (LA() == T_DECLTYPE) {
DecltypeSpecifierAST *ast = new (_pool) DecltypeSpecifierAST;
ast->decltype_token = consumeToken();
match(T_LPAREN, &ast->lparen_token);
if (parseExpression(ast->expression)) {
match(T_RPAREN, &ast->rparen_token);
node = new (_pool) SpecifierListAST(ast);
return true;
}
skipUntilDeclaration();
return true;
} else if (lookAtBuiltinTypeSpecifier()) {
SimpleSpecifierAST *ast = new (_pool) SimpleSpecifierAST;
ast->specifier_token = consumeToken();
......
......@@ -41,7 +41,8 @@ static const char *token_names[] = {
("]"), (")"), (";"), ("*"), ("*="), ("~"), ("~="),
("asm"), ("auto"), ("bool"), ("break"), ("case"), ("catch"), ("char"),
("class"), ("const"), ("const_cast"), ("constexpr"), ("continue"), ("default"),
("class"), ("const"), ("const_cast"), ("constexpr"), ("continue"),
("decltype"), ("default"),
("delete"), ("do"), ("double"), ("dynamic_cast"), ("else"), ("enum"),
("explicit"), ("export"), ("extern"), ("false"), ("float"), ("for"),
("friend"), ("goto"), ("if"), ("inline"), ("int"), ("long"),
......
......@@ -113,6 +113,7 @@ enum Kind {
T_CONST_CAST,
T_CONSTEXPR,
T_CONTINUE,
T_DECLTYPE,
T_DEFAULT,
T_DELETE,
T_DO,
......@@ -245,6 +246,8 @@ enum Kind {
T_TYPEOF = T___TYPEOF__,
T___TYPEOF = T___TYPEOF__,
T___DECLTYPE = T_DECLTYPE,
T___INLINE = T_INLINE,
T___INLINE__ = T_INLINE,
......
......@@ -2031,6 +2031,15 @@ bool FindUsages::visit(TypeofSpecifierAST *ast)
return false;
}
bool FindUsages::visit(DecltypeSpecifierAST *ast)
{
// unsigned typeof_token = ast->typeof_token;
// unsigned lparen_token = ast->lparen_token;
this->expression(ast->expression);
// unsigned rparen_token = ast->rparen_token;
return false;
}
bool FindUsages::visit(ClassSpecifierAST *ast)
{
// unsigned classkey_token = ast->classkey_token;
......
......@@ -265,6 +265,7 @@ protected:
virtual bool visit(SimpleSpecifierAST *ast);
virtual bool visit(AttributeSpecifierAST *ast);
virtual bool visit(TypeofSpecifierAST *ast);
virtual bool visit(DecltypeSpecifierAST *ast);
virtual bool visit(ClassSpecifierAST *ast);
virtual bool visit(NamedTypeSpecifierAST *ast);
virtual bool visit(ElaboratedTypeSpecifierAST *ast);
......
TEMPLATE = lib
TARGET = CPlusPlus
DEFINES += NDEBUG
#DEFINES += NDEBUG
unix:QMAKE_CXXFLAGS_DEBUG += -O2
include(../../qtcreatorlibrary.pri)
......
......@@ -94,6 +94,18 @@ virtual bool visit(TypeofSpecifierAST *ast)
return false;
}
virtual bool visit(DecltypeSpecifierAST *ast)
{
if (ast->decltype_token)
terminal(ast->decltype_token, ast);
if (ast->lparen_token)
terminal(ast->lparen_token, ast);
nonterminal(ast->expression);
if (ast->rparen_token)
terminal(ast->rparen_token, ast);
return false;
}
virtual bool visit(DeclaratorAST *ast)
{
for (SpecifierListAST *iter = ast->attribute_list; iter; iter = iter->next)
......
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