forked from qt-creator/qt-creator
Recognize C++0x rvalue references.
This commit is contained in:
@@ -1513,12 +1513,12 @@ unsigned QualifiedNameAST::lastToken() const
|
||||
|
||||
unsigned ReferenceAST::firstToken() const
|
||||
{
|
||||
return amp_token;
|
||||
return reference_token;
|
||||
}
|
||||
|
||||
unsigned ReferenceAST::lastToken() const
|
||||
{
|
||||
return amp_token + 1;
|
||||
return reference_token + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2748,11 +2748,11 @@ protected:
|
||||
class CPLUSPLUS_EXPORT ReferenceAST: public PtrOperatorAST
|
||||
{
|
||||
public:
|
||||
unsigned amp_token;
|
||||
unsigned reference_token;
|
||||
|
||||
public:
|
||||
ReferenceAST()
|
||||
: amp_token(0)
|
||||
: reference_token(0)
|
||||
{}
|
||||
|
||||
virtual ReferenceAST *asReference() { return this; }
|
||||
|
||||
@@ -1032,7 +1032,7 @@ PointerAST *PointerAST::clone(MemoryPool *pool) const
|
||||
ReferenceAST *ReferenceAST::clone(MemoryPool *pool) const
|
||||
{
|
||||
ReferenceAST *ast = new (pool) ReferenceAST;
|
||||
ast->amp_token = amp_token;
|
||||
ast->reference_token = reference_token;
|
||||
return ast;
|
||||
}
|
||||
|
||||
|
||||
@@ -1725,7 +1725,7 @@ bool ASTMatcher::match(ReferenceAST *node, ReferenceAST *pattern)
|
||||
(void) node;
|
||||
(void) pattern;
|
||||
|
||||
pattern->amp_token = node->amp_token;
|
||||
pattern->reference_token = node->reference_token;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -237,9 +237,11 @@ bool CheckDeclarator::visit(PointerAST *ast)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CheckDeclarator::visit(ReferenceAST *)
|
||||
bool CheckDeclarator::visit(ReferenceAST *ast)
|
||||
{
|
||||
ReferenceType *refTy = control()->referenceType(_fullySpecifiedType);
|
||||
const bool rvalueRef = (tokenKind(ast->reference_token) == T_AMPER_AMPER);
|
||||
|
||||
ReferenceType *refTy = control()->referenceType(_fullySpecifiedType, rvalueRef);
|
||||
FullySpecifiedType ty(refTy);
|
||||
_fullySpecifiedType = ty;
|
||||
return false;
|
||||
|
||||
@@ -307,9 +307,9 @@ public:
|
||||
return pointerTypes.intern(PointerType(elementType));
|
||||
}
|
||||
|
||||
ReferenceType *findOrInsertReferenceType(const FullySpecifiedType &elementType)
|
||||
ReferenceType *findOrInsertReferenceType(const FullySpecifiedType &elementType, bool rvalueRef)
|
||||
{
|
||||
return referenceTypes.intern(ReferenceType(elementType));
|
||||
return referenceTypes.intern(ReferenceType(elementType, rvalueRef));
|
||||
}
|
||||
|
||||
ArrayType *findOrInsertArrayType(const FullySpecifiedType &elementType, unsigned size)
|
||||
@@ -648,8 +648,8 @@ PointerToMemberType *Control::pointerToMemberType(const Name *memberName, const
|
||||
PointerType *Control::pointerType(const FullySpecifiedType &elementType)
|
||||
{ return d->findOrInsertPointerType(elementType); }
|
||||
|
||||
ReferenceType *Control::referenceType(const FullySpecifiedType &elementType)
|
||||
{ return d->findOrInsertReferenceType(elementType); }
|
||||
ReferenceType *Control::referenceType(const FullySpecifiedType &elementType, bool rvalueRef)
|
||||
{ return d->findOrInsertReferenceType(elementType, rvalueRef); }
|
||||
|
||||
ArrayType *Control::arrayType(const FullySpecifiedType &elementType, unsigned size)
|
||||
{ return d->findOrInsertArrayType(elementType, size); }
|
||||
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
PointerType *pointerType(const FullySpecifiedType &elementType);
|
||||
|
||||
/// Returns a Type object of type ReferenceType.
|
||||
ReferenceType *referenceType(const FullySpecifiedType &elementType);
|
||||
ReferenceType *referenceType(const FullySpecifiedType &elementType, bool rvalueRef = false);
|
||||
|
||||
/// Retruns a Type object of type ArrayType.
|
||||
ArrayType *arrayType(const FullySpecifiedType &elementType, unsigned size = 0);
|
||||
|
||||
@@ -154,8 +154,8 @@ bool PointerType::matchType0(const Type *otherType, TypeMatcher *matcher) const
|
||||
FullySpecifiedType PointerType::elementType() const
|
||||
{ return _elementType; }
|
||||
|
||||
ReferenceType::ReferenceType(const FullySpecifiedType &elementType)
|
||||
: _elementType(elementType)
|
||||
ReferenceType::ReferenceType(const FullySpecifiedType &elementType, bool rvalueRef)
|
||||
: _elementType(elementType), _rvalueReference(rvalueRef)
|
||||
{ }
|
||||
|
||||
ReferenceType::~ReferenceType()
|
||||
@@ -166,6 +166,8 @@ bool ReferenceType::isEqualTo(const Type *other) const
|
||||
const ReferenceType *o = other->asReferenceType();
|
||||
if (! o)
|
||||
return false;
|
||||
else if (isRvalueReference() != o->isRvalueReference())
|
||||
return false;
|
||||
return _elementType.isEqualTo(o->_elementType);
|
||||
}
|
||||
|
||||
@@ -183,6 +185,9 @@ bool ReferenceType::matchType0(const Type *otherType, TypeMatcher *matcher) cons
|
||||
FullySpecifiedType ReferenceType::elementType() const
|
||||
{ return _elementType; }
|
||||
|
||||
bool ReferenceType::isRvalueReference() const
|
||||
{ return _rvalueReference; }
|
||||
|
||||
IntegerType::IntegerType(int kind)
|
||||
: _kind(kind)
|
||||
{ }
|
||||
|
||||
@@ -212,10 +212,11 @@ private:
|
||||
class CPLUSPLUS_EXPORT ReferenceType: public Type
|
||||
{
|
||||
public:
|
||||
ReferenceType(const FullySpecifiedType &elementType);
|
||||
ReferenceType(const FullySpecifiedType &elementType, bool rvalueRef);
|
||||
virtual ~ReferenceType();
|
||||
|
||||
FullySpecifiedType elementType() const;
|
||||
bool isRvalueReference() const;
|
||||
|
||||
virtual bool isEqualTo(const Type *other) const;
|
||||
|
||||
@@ -231,6 +232,7 @@ protected:
|
||||
|
||||
private:
|
||||
FullySpecifiedType _elementType;
|
||||
bool _rvalueReference;
|
||||
};
|
||||
|
||||
class CPLUSPLUS_EXPORT ArrayType: public Type
|
||||
|
||||
@@ -197,6 +197,7 @@ Parser::Parser(TranslationUnit *unit)
|
||||
_tokenIndex(1),
|
||||
_templateArguments(0),
|
||||
_qtMocRunEnabled(false),
|
||||
_cxx0xEnabled(true), // C++0x is enabled by default
|
||||
_objCEnabled(false),
|
||||
_inFunctionBody(false),
|
||||
_inObjCImplementationContext(false),
|
||||
@@ -213,6 +214,12 @@ bool Parser::qtMocRunEnabled() const
|
||||
void Parser::setQtMocRunEnabled(bool onoff)
|
||||
{ _qtMocRunEnabled = onoff; }
|
||||
|
||||
bool Parser::cxx0xEnabled() const
|
||||
{ return _cxx0xEnabled; }
|
||||
|
||||
void Parser::isCxxOxEnabled(bool onoff)
|
||||
{ _cxx0xEnabled = onoff; }
|
||||
|
||||
bool Parser::objCEnabled() const
|
||||
{ return _objCEnabled; }
|
||||
|
||||
@@ -1070,9 +1077,9 @@ bool Parser::parseCvQualifiers(SpecifierListAST *&node)
|
||||
bool Parser::parsePtrOperator(PtrOperatorListAST *&node)
|
||||
{
|
||||
DEBUG_THIS_RULE();
|
||||
if (LA() == T_AMPER) {
|
||||
if (LA() == T_AMPER || (_cxx0xEnabled && LA() == T_AMPER_AMPER)) {
|
||||
ReferenceAST *ast = new (_pool) ReferenceAST;
|
||||
ast->amp_token = consumeToken();
|
||||
ast->reference_token = consumeToken();
|
||||
node = new (_pool) PtrOperatorListAST(ast);
|
||||
return true;
|
||||
} else if (LA() == T_STAR) {
|
||||
|
||||
@@ -67,6 +67,9 @@ public:
|
||||
bool qtMocRunEnabled() const;
|
||||
void setQtMocRunEnabled(bool onoff);
|
||||
|
||||
bool cxx0xEnabled() const;
|
||||
void isCxxOxEnabled(bool onoff);
|
||||
|
||||
bool objCEnabled() const;
|
||||
void setObjCEnabled(bool onoff);
|
||||
|
||||
@@ -312,6 +315,7 @@ private:
|
||||
unsigned _tokenIndex;
|
||||
bool _templateArguments: 1;
|
||||
bool _qtMocRunEnabled: 1;
|
||||
bool _cxx0xEnabled: 1;
|
||||
bool _objCEnabled: 1;
|
||||
bool _inFunctionBody: 1;
|
||||
bool _inObjCImplementationContext: 1;
|
||||
|
||||
@@ -116,6 +116,9 @@ bool TypeMatcher::match(const ReferenceType *type, const ReferenceType *otherTyp
|
||||
if (type == otherType)
|
||||
return true;
|
||||
|
||||
else if (type->isRvalueReference() != otherType->isRvalueReference())
|
||||
return false;
|
||||
|
||||
else if (! type->elementType().match(otherType->elementType(), this))
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user