forked from qt-creator/qt-creator
C++: Recognize C++11 nullptr
Change-Id: I5b7ac8f9b2137ffe9439ada4ec4aeb9cee8e249d Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
16
src/libs/3rdparty/cplusplus/AST.cpp
vendored
16
src/libs/3rdparty/cplusplus/AST.cpp
vendored
@@ -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;
|
||||
}
|
||||
|
||||
|
23
src/libs/3rdparty/cplusplus/AST.h
vendored
23
src/libs/3rdparty/cplusplus/AST.h
vendored
@@ -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:
|
||||
|
7
src/libs/3rdparty/cplusplus/ASTClone.cpp
vendored
7
src/libs/3rdparty/cplusplus/ASTClone.cpp
vendored
@@ -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;
|
||||
|
8
src/libs/3rdparty/cplusplus/ASTMatch0.cpp
vendored
8
src/libs/3rdparty/cplusplus/ASTMatch0.cpp
vendored
@@ -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())
|
||||
|
10
src/libs/3rdparty/cplusplus/ASTMatcher.cpp
vendored
10
src/libs/3rdparty/cplusplus/ASTMatcher.cpp
vendored
@@ -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;
|
||||
|
1
src/libs/3rdparty/cplusplus/ASTMatcher.h
vendored
1
src/libs/3rdparty/cplusplus/ASTMatcher.h
vendored
@@ -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;
|
||||
|
7
src/libs/3rdparty/cplusplus/ASTVisit.cpp
vendored
7
src/libs/3rdparty/cplusplus/ASTVisit.cpp
vendored
@@ -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)) {
|
||||
|
2
src/libs/3rdparty/cplusplus/ASTVisitor.h
vendored
2
src/libs/3rdparty/cplusplus/ASTVisitor.h
vendored
@@ -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 *) {}
|
||||
|
1
src/libs/3rdparty/cplusplus/ASTfwd.h
vendored
1
src/libs/3rdparty/cplusplus/ASTfwd.h
vendored
@@ -134,6 +134,7 @@ class OperatorFunctionIdAST;
|
||||
class ParameterDeclarationAST;
|
||||
class ParameterDeclarationClauseAST;
|
||||
class PointerAST;
|
||||
class PointerLiteralAST;
|
||||
class PointerToMemberAST;
|
||||
class PostIncrDecrAST;
|
||||
class PostfixAST;
|
||||
|
7
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
7
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
@@ -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;
|
||||
|
1
src/libs/3rdparty/cplusplus/Bind.h
vendored
1
src/libs/3rdparty/cplusplus/Bind.h
vendored
@@ -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);
|
||||
|
17
src/libs/3rdparty/cplusplus/Keywords.cpp
vendored
17
src/libs/3rdparty/cplusplus/Keywords.cpp
vendored
@@ -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') {
|
||||
|
17
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
17
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
@@ -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:
|
||||
|
1
src/libs/3rdparty/cplusplus/Parser.h
vendored
1
src/libs/3rdparty/cplusplus/Parser.h
vendored
@@ -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);
|
||||
|
1
src/libs/3rdparty/cplusplus/Token.h
vendored
1
src/libs/3rdparty/cplusplus/Token.h
vendored
@@ -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);
|
||||
|
Reference in New Issue
Block a user