Commit 057fad64 authored by Leandro Melo's avatar Leandro Melo

C++: Recognize C++11 nullptr

Change-Id: I5b7ac8f9b2137ffe9439ada4ec4aeb9cee8e249d
Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent 64d579dc
......@@ -4219,3 +4219,19 @@ unsigned AttributeSpecifierAST::lastToken() const
return 1;
}
/** \generated */
unsigned PointerLiteralAST::firstToken() const
{
if (literal_token)
return literal_token;
return 0;
}
/** \generated */
unsigned PointerLiteralAST::lastToken() const
{
if (literal_token)
return literal_token + 1;
return 1;
}
......@@ -227,6 +227,7 @@ public:
virtual ParameterDeclarationAST *asParameterDeclaration() { return 0; }
virtual ParameterDeclarationClauseAST *asParameterDeclarationClause() { return 0; }
virtual PointerAST *asPointer() { return 0; }
virtual PointerLiteralAST *asPointerLiteral() { return 0; }
virtual PointerToMemberAST *asPointerToMember() { return 0; }
virtual PostIncrDecrAST *asPostIncrDecr() { return 0; }
virtual PostfixAST *asPostfix() { return 0; }
......@@ -2904,6 +2905,28 @@ protected:
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT PointerLiteralAST: public ExpressionAST
{
public:
unsigned literal_token;
public:
PointerLiteralAST()
: literal_token(0)
{}
virtual PointerLiteralAST *asPointerLiteral() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual PointerLiteralAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT NumericLiteralAST: public ExpressionAST
{
public:
......
......@@ -1092,6 +1092,13 @@ SizeofExpressionAST *SizeofExpressionAST::clone(MemoryPool *pool) const
return ast;
}
PointerLiteralAST *PointerLiteralAST::clone(MemoryPool *pool) const
{
PointerLiteralAST *ast = new (pool) PointerLiteralAST;
ast->literal_token = literal_token;
return ast;
}
NumericLiteralAST *NumericLiteralAST::clone(MemoryPool *pool) const
{
NumericLiteralAST *ast = new (pool) NumericLiteralAST;
......
......@@ -752,6 +752,14 @@ bool SizeofExpressionAST::match0(AST *pattern, ASTMatcher *matcher)
return false;
}
bool PointerLiteralAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (PointerLiteralAST *_other = pattern->asPointerLiteral())
return matcher->match(this, _other);
return false;
}
bool NumericLiteralAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (NumericLiteralAST *_other = pattern->asNumericLiteral())
......
......@@ -1839,6 +1839,16 @@ bool ASTMatcher::match(SizeofExpressionAST *node, SizeofExpressionAST *pattern)
return true;
}
bool ASTMatcher::match(PointerLiteralAST *node, PointerLiteralAST *pattern)
{
(void) node;
(void) pattern;
pattern->literal_token = node->literal_token;
return true;
}
bool ASTMatcher::match(NumericLiteralAST *node, NumericLiteralAST *pattern)
{
(void) node;
......
......@@ -130,6 +130,7 @@ public:
virtual bool match(ParameterDeclarationAST *node, ParameterDeclarationAST *pattern);
virtual bool match(ParameterDeclarationClauseAST *node, ParameterDeclarationClauseAST *pattern);
virtual bool match(PointerAST *node, PointerAST *pattern);
virtual bool match(PointerLiteralAST *node, PointerLiteralAST *pattern);
virtual bool match(PointerToMemberAST *node, PointerToMemberAST *pattern);
virtual bool match(PostIncrDecrAST *node, PostIncrDecrAST *pattern);
virtual bool match(QtEnumDeclarationAST *node, QtEnumDeclarationAST *pattern);
......
......@@ -721,6 +721,12 @@ public:
return __ast;
}
PointerLiteralAST *PointerLiteral()
{
PointerLiteralAST *__ast = new (&pool) PointerLiteralAST;
return __ast;
}
NumericLiteralAST *NumericLiteral()
{
NumericLiteralAST *__ast = new (&pool) NumericLiteralAST;
......
......@@ -799,6 +799,13 @@ void SizeofExpressionAST::accept0(ASTVisitor *visitor)
visitor->endVisit(this);
}
void PointerLiteralAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
}
visitor->endVisit(this);
}
void NumericLiteralAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......
......@@ -172,6 +172,7 @@ public:
virtual bool visit(ParameterDeclarationAST *) { return true; }
virtual bool visit(ParameterDeclarationClauseAST *) { return true; }
virtual bool visit(PointerAST *) { return true; }
virtual bool visit(PointerLiteralAST *) { return true; }
virtual bool visit(PointerToMemberAST *) { return true; }
virtual bool visit(PostIncrDecrAST *) { return true; }
virtual bool visit(QtEnumDeclarationAST *) { return true; }
......@@ -311,6 +312,7 @@ public:
virtual void endVisit(ParameterDeclarationAST *) {}
virtual void endVisit(ParameterDeclarationClauseAST *) {}
virtual void endVisit(PointerAST *) {}
virtual void endVisit(PointerLiteralAST *) {}
virtual void endVisit(PointerToMemberAST *) {}
virtual void endVisit(PostIncrDecrAST *) {}
virtual void endVisit(QtEnumDeclarationAST *) {}
......
......@@ -134,6 +134,7 @@ class OperatorFunctionIdAST;
class ParameterDeclarationAST;
class ParameterDeclarationClauseAST;
class PointerAST;
class PointerLiteralAST;
class PointerToMemberAST;
class PostIncrDecrAST;
class PostfixAST;
......
......@@ -1594,6 +1594,13 @@ bool Bind::visit(SizeofExpressionAST *ast)
return false;
}
bool Bind::visit(PointerLiteralAST *ast)
{
(void) ast;
// unsigned literal_token = ast->literal_token;
return false;
}
bool Bind::visit(NumericLiteralAST *ast)
{
(void) ast;
......
......@@ -183,6 +183,7 @@ protected:
virtual bool visit(TypenameCallExpressionAST *ast);
virtual bool visit(TypeConstructorCallAST *ast);
virtual bool visit(SizeofExpressionAST *ast);
virtual bool visit(PointerLiteralAST *ast);
virtual bool visit(NumericLiteralAST *ast);
virtual bool visit(BoolLiteralAST *ast);
virtual bool visit(ThisExpressionAST *ast);
......
......@@ -530,7 +530,7 @@ static inline int classify6(const char *s, bool q, bool) {
return T_IDENTIFIER;
}
static inline int classify7(const char *s, bool q, bool) {
static inline int classify7(const char *s, bool q, bool x) {
if (s[0] == '_') {
if (s[1] == '_') {
if (s[2] == 'a') {
......@@ -587,6 +587,21 @@ static inline int classify7(const char *s, bool q, bool) {
}
}
}
else if (x && s[0] == 'n') {
if (s[1] == 'u') {
if (s[2] == 'l') {
if (s[3] == 'l') {
if (s[4] == 'p') {
if (s[5] == 't') {
if (s[6] == 'r') {
return T_NULLPTR;
}
}
}
}
}
}
}
else if (s[0] == 'p') {
if (s[1] == 'r') {
if (s[2] == 'i') {
......
......@@ -3865,6 +3865,18 @@ bool Parser::parseNumericLiteral(ExpressionAST *&node)
return false;
}
bool Parser::parsePointerLiteral(ExpressionAST *&node)
{
DEBUG_THIS_RULE();
if (LA() == T_NULLPTR) {
PointerLiteralAST *ast = new (_pool) PointerLiteralAST;
ast->literal_token = consumeToken();
node = ast;
return true;
}
return false;
}
bool Parser::parseThisExpression(ExpressionAST *&node)
{
DEBUG_THIS_RULE();
......@@ -3885,6 +3897,11 @@ bool Parser::parsePrimaryExpression(ExpressionAST *&node)
case T_WIDE_STRING_LITERAL:
return parseStringLiteral(node);
case T_NULLPTR:
if (_cxx0xEnabled)
return parsePointerLiteral(node);
// fall-through
case T_CHAR_LITERAL: // ### FIXME don't use NumericLiteral for chars
case T_WIDE_CHAR_LITERAL:
case T_NUMERIC_LITERAL:
......
......@@ -153,6 +153,7 @@ public:
bool parseThisExpression(ExpressionAST *&node);
bool parseBoolLiteral(ExpressionAST *&node);
bool parseNumericLiteral(ExpressionAST *&node);
bool parsePointerLiteral(ExpressionAST *&node);
bool parseStringLiteral(ExpressionAST *&node);
bool parseSwitchStatement(StatementAST *&node);
bool parseTemplateArgument(ExpressionAST *&node);
......
......@@ -135,6 +135,7 @@ enum Kind {
T_MUTABLE,
T_NAMESPACE,
T_NEW,
T_NULLPTR,
T_OPERATOR,
T_PRIVATE,
T_PROTECTED,
......
......@@ -1351,6 +1351,13 @@ bool FindUsages::visit(SizeofExpressionAST *ast)
return false;
}
bool FindUsages::visit(PointerLiteralAST *ast)
{
(void) ast;
// unsigned literal_token = ast->literal_token;
return false;
}
bool FindUsages::visit(NumericLiteralAST *ast)
{
(void) ast;
......
......@@ -202,6 +202,7 @@ protected:
virtual bool visit(TypenameCallExpressionAST *ast);
virtual bool visit(TypeConstructorCallAST *ast);
virtual bool visit(SizeofExpressionAST *ast);
virtual bool visit(PointerLiteralAST *ast);
virtual bool visit(NumericLiteralAST *ast);
virtual bool visit(BoolLiteralAST *ast);
virtual bool visit(ThisExpressionAST *ast);
......
......@@ -273,6 +273,13 @@ bool ResolveExpression::visit(SizeofExpressionAST *)
return false;
}
bool ResolveExpression::visit(PointerLiteralAST *)
{
FullySpecifiedType ty(control()->integerType(IntegerType::Int)); // Handling as Int.
addResult(ty, _scope);
return false;
}
bool ResolveExpression::visit(NumericLiteralAST *ast)
{
const Token &tk = tokenAt(ast->literal_token);
......
......@@ -91,6 +91,7 @@ protected:
virtual bool visit(TypenameCallExpressionAST *ast);
virtual bool visit(TypeConstructorCallAST *ast);
virtual bool visit(SizeofExpressionAST *ast);
virtual bool visit(PointerLiteralAST *ast);
virtual bool visit(NumericLiteralAST *ast);
virtual bool visit(BoolLiteralAST *ast);
virtual bool visit(ThisExpressionAST *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