diff --git a/.vimrc b/.vimrc new file mode 100644 index 000000000..d5a9f893c --- /dev/null +++ b/.vimrc @@ -0,0 +1 @@ +set expandtab diff --git a/generator/abstractmetabuilder.h b/generator/abstractmetabuilder.h index f4c00b112..5322b76f6 100644 --- a/generator/abstractmetabuilder.h +++ b/generator/abstractmetabuilder.h @@ -127,7 +127,7 @@ class AbstractMetaBuilder bool isEnum(const QStringList &qualified_name); void fixQObjectForScope (TypeDatabase *types, - NamespaceModelItem item); + NamespaceModelItem item); // QtScript QSet qtMetaTypeDeclaredTypeNames() const diff --git a/generator/parser/codemodel.cpp b/generator/parser/codemodel.cpp index 32c67697c..511307e48 100644 --- a/generator/parser/codemodel.cpp +++ b/generator/parser/codemodel.cpp @@ -142,7 +142,9 @@ TypeInfo TypeInfo::combine (const TypeInfo &__lhs, const TypeInfo &__rhs) TypeInfo __result = __lhs; __result.setConstant (__result.isConstant () || __rhs.isConstant ()); + __result.setConstexpr (__result.isConstexpr () || __rhs.isConstexpr ()); __result.setVolatile (__result.isVolatile () || __rhs.isVolatile ()); + __result.setMutable (__result.isMutable () || __rhs.isMutable ()); __result.setReference (__result.isReference () || __rhs.isReference ()); __result.setRvalueReference (__result.isRvalueReference () || __rhs.isRvalueReference ()); __result.setIndirections (__result.indirections () + __rhs.indirections ()); @@ -182,9 +184,15 @@ QString TypeInfo::toString() const if (isConstant()) tmp += QLatin1String(" const"); + if (isConstexpr()) + tmp += QLatin1String(" constexpr"); + if (isVolatile()) tmp += QLatin1String(" volatile"); + if (isMutable()) + tmp += QLatin1String(" mutable"); + if (indirections()) tmp += QString(indirections(), QLatin1Char('*')); @@ -917,6 +925,16 @@ void _MemberModelItem::setConstant(bool isConstant) _M_isConstant = isConstant; } +bool _MemberModelItem::isConstexpr() const +{ + return _M_isConstexpr; +} + +void _MemberModelItem::setConstexpr(bool isConstexpr) +{ + _M_isConstexpr = isConstexpr; +} + bool _MemberModelItem::isVolatile() const { return _M_isVolatile; diff --git a/generator/parser/codemodel.h b/generator/parser/codemodel.h index 6133620b4..06af94f61 100644 --- a/generator/parser/codemodel.h +++ b/generator/parser/codemodel.h @@ -132,9 +132,15 @@ struct TypeInfo bool isConstant() const { return m_flags.m_constant; } void setConstant(bool is) { m_flags.m_constant = is; } + bool isConstexpr() const { return m_flags.m_constexpr; } + void setConstexpr(bool is) { m_flags.m_constexpr = is; } + bool isVolatile() const { return m_flags.m_volatile; } void setVolatile(bool is) { m_flags.m_volatile = is; } + bool isMutable() const { return m_flags.m_mutable; } + void setMutable(bool is) { m_flags.m_mutable = is; } + bool isReference() const { return m_flags.m_reference; } void setReference(bool is) { m_flags.m_reference = is; } @@ -166,19 +172,24 @@ struct TypeInfo private: struct TypeInfo_flags { - uint m_constant: 1; - uint m_volatile: 1; - uint m_reference: 1; - uint m_functionPointer: 1; - uint m_indirections: 6; - inline bool equals(TypeInfo_flags other) const { + uint m_constant: 1; + uint m_constexpr: 1; + uint m_volatile: 1; + uint m_mutable: 1; + uint m_reference: 1; + uint m_functionPointer: 1; + uint m_indirections: 6; + inline bool equals(TypeInfo_flags other) const { + /* m_auto and m_friend don't matter here */ return m_constant == other.m_constant + && m_constexpr == other.m_constexpr && m_volatile == other.m_volatile + && m_mutable == other.m_mutable && m_reference == other.m_reference && m_functionPointer == other.m_functionPointer && m_indirections == other.m_indirections; - } - } m_flags {0, 0, 0, 0, 0}; + } + } m_flags {0, 0, 0, 0, 0, 0, 0}; QStringList m_qualifiedName; QStringList m_arrayElements; @@ -455,6 +466,9 @@ class _MemberModelItem: public _CodeModelItem bool isConstant() const; void setConstant(bool isConstant); + bool isConstexpr() const; + void setConstexpr(bool isConstexpr); + bool isVolatile() const; void setVolatile(bool isVolatile); @@ -504,6 +518,7 @@ class _MemberModelItem: public _CodeModelItem struct { uint _M_isConstant: 1; + uint _M_isConstexpr: 1; uint _M_isVolatile: 1; uint _M_isStatic: 1; uint _M_isAuto: 1; diff --git a/generator/parser/compiler_utils.cpp b/generator/parser/compiler_utils.cpp index 96de701fa..c14f22b40 100644 --- a/generator/parser/compiler_utils.cpp +++ b/generator/parser/compiler_utils.cpp @@ -58,7 +58,9 @@ TypeInfo CompilerUtils::typeDescription(TypeSpecifierAST *type_specifier, Declar TypeInfo typeInfo; typeInfo.setQualifiedName (type_cc.qualifiedName ()); typeInfo.setConstant (type_cc.isConstant ()); + typeInfo.setConstexpr (type_cc.isConstexpr ()); typeInfo.setVolatile (type_cc.isVolatile ()); + typeInfo.setMutable (type_cc.isMutable ()); typeInfo.setReference (decl_cc.isReference ()); typeInfo.setRvalueReference (decl_cc.isRvalueReference ()); typeInfo.setIndirections (decl_cc.indirection ()); diff --git a/generator/parser/lexer.cpp b/generator/parser/lexer.cpp index 672a32066..c5e61441d 100644 --- a/generator/parser/lexer.cpp +++ b/generator/parser/lexer.cpp @@ -1549,6 +1549,20 @@ void Lexer::scanKeyword8() } break; + case 'd': + if (*(cursor + 1) == 'e' && + *(cursor + 2) == 'c' && + *(cursor + 3) == 'l' && + *(cursor + 4) == 't' && + *(cursor + 5) == 'y' && + *(cursor + 6) == 'p' && + *(cursor + 7) == 'e') + { + token_stream[(int) index++].kind = Token_decltype; + return; + } + break; + case 'e': if (*(cursor + 1) == 'x' && *(cursor + 2) == 'p' && @@ -1666,6 +1680,21 @@ void Lexer::scanKeyword9() { switch (*cursor) { + case 'c': + if (*(cursor + 1) == 'o' && + *(cursor + 2) == 'n' && + *(cursor + 3) == 's' && + *(cursor + 4) == 't' && + *(cursor + 5) == 'e' && + *(cursor + 6) == 'x' && + *(cursor + 7) == 'p' && + *(cursor + 8) == 'r') + { + token_stream[(int) index++].kind = Token_constexpr; + return; + } + break; + case 'p': if (*(cursor + 1) == 'r' && *(cursor + 2) == 'o' && diff --git a/generator/parser/list.h b/generator/parser/list.h index 711819246..c7ef9e285 100644 --- a/generator/parser/list.h +++ b/generator/parser/list.h @@ -105,7 +105,7 @@ struct ListNode template inline const ListNode *snoc(const ListNode *list, - const Tp &element, pool *p) + const Tp &element, pool *p) { if (!list) return ListNode::create(element, p); diff --git a/generator/parser/name_compiler.cpp b/generator/parser/name_compiler.cpp index 7e136b4d5..1b70b879e 100644 --- a/generator/parser/name_compiler.cpp +++ b/generator/parser/name_compiler.cpp @@ -127,6 +127,12 @@ void NameCompiler::visitTemplateArgument(TemplateArgumentAST *node) if (type_cc.isConstant()) _M_name.last() += "const "; + /* An id can't be 'constexpr' but it may have a function type in which + * case constexpr could appear. + */ + if (type_cc.isConstexpr()) + _M_name.last() += "constexpr "; + QStringList q = type_cc.qualifiedName (); if (q.count () == 1) diff --git a/generator/parser/parser.cpp b/generator/parser/parser.cpp index 690ba95fd..915e956ac 100644 --- a/generator/parser/parser.cpp +++ b/generator/parser/parser.cpp @@ -248,7 +248,9 @@ bool Parser::skipUntilDeclaration() case Token_export: case Token_const: // cv + case Token_constexpr: // cv case Token_volatile: // cv + case Token_mutable: // cv case Token_public: case Token_protected: @@ -257,6 +259,11 @@ bool Parser::skipUntilDeclaration() case Token_slots: // Qt return true; + case Token_decltype: + case Token___typeof: + reportError("C++11 decltype/__typeof(id|expression) not handled"); + return true; + default: token_stream.nextToken(); } @@ -275,7 +282,11 @@ bool Parser::skipUntilStatement() case '{': case '}': case Token_const: + case Token_constexpr: + case Token_decltype: + case Token___typeof: case Token_volatile: + case Token_mutable: case Token_identifier: case Token_case: case Token_default: @@ -943,7 +954,8 @@ bool Parser::parseCvQualify(const ListNode *&node) int tk; while (0 != (tk = token_stream.lookAhead()) - && (tk == Token_const || tk == Token_volatile)) + && (tk == Token_const || tk == Token_constexpr || + tk == Token_volatile || tk == Token_mutable)) { node = snoc(node, token_stream.cursor(), _M_pool); token_stream.nextToken(); @@ -991,7 +1003,8 @@ bool Parser::parseSimpleTypeSpecifier(TypeSpecifierAST *&node, { ast->integrals = integrals; } - else if (token_stream.lookAhead() == Token___typeof) + else if (token_stream.lookAhead() == Token___typeof || + token_stream.lookAhead() == Token_decltype) { ast->type_of = token_stream.cursor(); token_stream.nextToken(); @@ -1570,7 +1583,7 @@ bool Parser::parseStorageClassSpecifier(const ListNode *&node) while (0 != (tk = token_stream.lookAhead()) && (tk == Token_friend || tk == Token_auto || tk == Token_register || tk == Token_static - || tk == Token_extern || tk == Token_mutable)) + || tk == Token_extern)) { node = snoc(node, token_stream.cursor(), _M_pool); token_stream.nextToken(); @@ -3190,7 +3203,8 @@ bool Parser::parseDeclarationInternal(DeclarationAST *&node) start_decl: token_stream.rewind((int) index); - if (token_stream.lookAhead() == Token_const + if ((token_stream.lookAhead() == Token_const || + token_stream.lookAhead() == Token_constexpr) && token_stream.lookAhead(1) == Token_identifier && token_stream.lookAhead(2) == '=') { diff --git a/generator/parser/parser.h b/generator/parser/parser.h index be5e1bf4e..5c4e4e864 100644 --- a/generator/parser/parser.h +++ b/generator/parser/parser.h @@ -100,10 +100,10 @@ class Parser bool parseEnumSpecifier(TypeSpecifierAST *&node); bool parseEnumerator(EnumeratorAST *&node); bool parseEqualityExpression(ExpressionAST *&node, - bool templArgs = false); + bool templArgs = false); bool parseExceptionSpecification(ExceptionSpecificationAST *&node); bool parseExclusiveOrExpression(ExpressionAST *&node, - bool templArgs = false); + bool templArgs = false); bool parseExpression(ExpressionAST *&node); bool parseExpressionOrDeclarationStatement(StatementAST *&node); bool parseExpressionStatement(StatementAST *&node); @@ -113,7 +113,7 @@ class Parser bool parseFunctionSpecifier(const ListNode *&node); bool parseIfStatement(StatementAST *&node); bool parseInclusiveOrExpression(ExpressionAST *&node, - bool templArgs = false); + bool templArgs = false); bool parseInitDeclarator(InitDeclaratorAST *&node); bool parseInitDeclaratorList(const ListNode *&node); bool parseInitializer(InitializerAST *&node); @@ -122,9 +122,9 @@ class Parser bool parseLinkageBody(LinkageBodyAST *&node); bool parseLinkageSpecification(DeclarationAST *&node); bool parseLogicalAndExpression(ExpressionAST *&node, - bool templArgs = false); + bool templArgs = false); bool parseLogicalOrExpression(ExpressionAST *&node, - bool templArgs = false); + bool templArgs = false); bool parseMemInitializer(MemInitializerAST *&node); bool parseMemInitializerList(const ListNode *&node); bool parseMemberSpecification(DeclarationAST *&node); @@ -148,17 +148,17 @@ class Parser bool parsePtrOperator(PtrOperatorAST *&node); bool parsePtrToMember(PtrToMemberAST *&node); bool parseRelationalExpression(ExpressionAST *&node, - bool templArgs = false); + bool templArgs = false); bool parseShiftExpression(ExpressionAST *&node); bool parseSimpleTypeSpecifier(TypeSpecifierAST *&node, - bool onlyIntegral = false); + bool onlyIntegral = false); bool parseStatement(StatementAST *&node); bool parseStorageClassSpecifier(const ListNode *&node); bool parseStringLiteral(StringLiteralAST *&node); bool parseSwitchStatement(StatementAST *&node); bool parseTemplateArgument(TemplateArgumentAST *&node); bool parseTemplateArgumentList(const ListNode *&node, - bool reportError = true); + bool reportError = true); bool parseTemplateDeclaration(DeclarationAST *&node); bool parseTemplateParameter(TemplateParameterAST *&node); bool parseTemplateParameterList(const ListNode *&node); @@ -173,7 +173,7 @@ class Parser bool parseTypedef(DeclarationAST *&node); bool parseUnaryExpression(ExpressionAST *&node); bool parseUnqualifiedName(UnqualifiedNameAST *&node, - bool parseTemplateId = true); + bool parseTemplateId = true); bool parseUsing(DeclarationAST *&node); bool parseUsingDirective(DeclarationAST *&node); bool parseWhileStatement(StatementAST *&node); diff --git a/generator/parser/rxx_allocator.h b/generator/parser/rxx_allocator.h index 2081bfe51..88d8f7858 100644 --- a/generator/parser/rxx_allocator.h +++ b/generator/parser/rxx_allocator.h @@ -82,20 +82,20 @@ template class rxx_allocator { const size_type bytes = __n * sizeof(_Tp); if (_M_current_block == 0 - || _S_block_size < _M_current_index + bytes) + || _S_block_size < _M_current_index + bytes) { - ++_M_block_index; + ++_M_block_index; - _M_storage = reinterpret_cast - (::realloc(_M_storage, sizeof(char*) * (1 + _M_block_index))); + _M_storage = reinterpret_cast + (::realloc(_M_storage, sizeof(char*) * (1 + _M_block_index))); - _M_current_block = _M_storage[_M_block_index] = reinterpret_cast - (new char[_S_block_size]); + _M_current_block = _M_storage[_M_block_index] = reinterpret_cast + (new char[_S_block_size]); #if defined(RXX_ALLOCATOR_INIT_0) // ### make it a policy - ::memset(_M_current_block, 0, _S_block_size); + ::memset(_M_current_block, 0, _S_block_size); #endif - _M_current_index = 0; + _M_current_index = 0; } pointer p = reinterpret_cast diff --git a/generator/parser/symbol.h b/generator/parser/symbol.h index f9fe13725..d711e0d3a 100644 --- a/generator/parser/symbol.h +++ b/generator/parser/symbol.h @@ -117,8 +117,8 @@ class NameTable NameSymbol *name = _M_storage.value(key); if (!name) { - name = new NameSymbol(str, len); - _M_storage.insert(key, name); + name = new NameSymbol(str, len); + _M_storage.insert(key, name); } return name; diff --git a/generator/parser/tokens.cpp b/generator/parser/tokens.cpp index 07cc10ad9..aa2883ec7 100644 --- a/generator/parser/tokens.cpp +++ b/generator/parser/tokens.cpp @@ -69,8 +69,10 @@ static char const * const _S_token_names[] = { "compl", "concat", "const", + "constexpr", "const_cast", "continue", + "decltype", "decr", "default", "delete", diff --git a/generator/parser/tokens.h b/generator/parser/tokens.h index 6bb944ae0..f762d0354 100644 --- a/generator/parser/tokens.h +++ b/generator/parser/tokens.h @@ -71,8 +71,10 @@ enum TOKEN_KIND Token_compl, Token_concat, Token_const, + Token_constexpr, Token_const_cast, Token_continue, + Token_decltype, Token_decr, Token_default, Token_delete, diff --git a/generator/parser/type_compiler.cpp b/generator/parser/type_compiler.cpp index 4a73a7448..5c5063862 100644 --- a/generator/parser/type_compiler.cpp +++ b/generator/parser/type_compiler.cpp @@ -127,24 +127,14 @@ void TypeCompiler::visitName(NameAST *node) _M_type = name_cc.qualifiedName(); } -QStringList TypeCompiler::cvString() const +bool TypeCompiler::isConstant() const { - QStringList lst; - - foreach (int q, cv()) - { - if (q == Token_const) - lst.append(QLatin1String("const")); - else if (q == Token_volatile) - lst.append(QLatin1String("volatile")); - } - - return lst; + return _M_cv.contains(Token_const); } -bool TypeCompiler::isConstant() const +bool TypeCompiler::isConstexpr() const { - return _M_cv.contains(Token_const); + return _M_cv.contains(Token_constexpr); } bool TypeCompiler::isVolatile() const @@ -152,4 +142,9 @@ bool TypeCompiler::isVolatile() const return _M_cv.contains(Token_volatile); } +bool TypeCompiler::isMutable() const +{ + return _M_cv.contains(Token_mutable); +} + // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/generator/parser/type_compiler.h b/generator/parser/type_compiler.h index 87e51ca99..6b706f503 100644 --- a/generator/parser/type_compiler.h +++ b/generator/parser/type_compiler.h @@ -61,9 +61,9 @@ class TypeCompiler: protected DefaultVisitor inline QList cv() const { return _M_cv; } bool isConstant() const; + bool isConstexpr() const; bool isVolatile() const; - - QStringList cvString() const; + bool isMutable() const; void run(TypeSpecifierAST *node); diff --git a/generator/typesystem.h b/generator/typesystem.h index fe12fd73b..bee5b0fc4 100644 --- a/generator/typesystem.h +++ b/generator/typesystem.h @@ -784,7 +784,7 @@ class ComplexTypeEntry : public TypeEntry public: enum TypeFlag { ForceAbstract = 0x1, - DeleteInMainThread = 0x2, + DeleteInMainThread = 0x2, Deprecated = 0x4 }; typedef QFlags TypeFlags;