Skip to content

Commit b81dede

Browse files
committed
added support for Qt 5.6, especially Q_ENUM declarations
1 parent 89430ab commit b81dede

10 files changed

Lines changed: 71 additions & 7 deletions

File tree

generator/abstractmetabuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,7 @@ AbstractMetaType *AbstractMetaBuilder::translateType(const TypeInfo &_typei, boo
18411841
if (container_type == ContainerTypeEntry::ListContainer
18421842
|| container_type == ContainerTypeEntry::VectorContainer
18431843
|| container_type == ContainerTypeEntry::StringListContainer) {
1844-
Q_ASSERT(meta_type->instantiations().size() == 1);
1844+
//Q_ASSERT(meta_type->instantiations().size() == 1);
18451845
}
18461846
}
18471847

generator/parser/ast.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,8 @@ struct QPropertyAST : public DeclarationAST
875875
struct QEnumsAST : public DeclarationAST
876876
{
877877
DECLARE_AST_NODE(QEnumsAST)
878+
879+
bool isQEnum;
878880
};
879881

880882
template <class _Tp>

generator/parser/binder.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,13 @@ void Binder::visitFunctionDefinition(FunctionDefinitionAST *node)
354354
// node is generated in 'parser.cpp'
355355
while (declarator && declarator->sub_declarator)
356356
declarator = declarator->sub_declarator;
357-
Q_ASSERT(declarator->id);
358-
357+
//Q_ASSERT(declarator->id);
358+
if (!declarator->id) {
359+
std::cerr << "** SHIT" << qPrintable(name_cc.name()) << std::endl
360+
<< "\tdefinition *ignored*"
361+
<< std::endl;
362+
return;
363+
}
359364
CodeModelFinder finder(model(), this);
360365

361366
ScopeModelItem functionScope = finder.resolveScope(declarator->id, scope);
@@ -778,8 +783,12 @@ void Binder::visitQEnums(QEnumsAST *node)
778783
end.position - start.position).split(' ');
779784

780785
ScopeModelItem scope = currentScope();
781-
for (int i=0; i<enum_list.size(); ++i)
786+
for (int i = 0; i < enum_list.size(); ++i) {
787+
//if (node->isQEnum) {
788+
// std::cout << enum_list.at(i).toLatin1().constData() << std::endl;
789+
//}
782790
scope->addEnumsDeclaration(enum_list.at(i));
791+
}
783792
}
784793

785794
void Binder::visitQProperty(QPropertyAST *node)

generator/parser/lexer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,17 @@ void Lexer::scanKeyword6()
14051405
return;
14061406
}
14071407
break;
1408+
case 'Q':
1409+
if (*(cursor + 1) == '_' &&
1410+
*(cursor + 2) == 'E' &&
1411+
*(cursor + 3) == 'N' &&
1412+
*(cursor + 4) == 'U' &&
1413+
*(cursor + 5) == 'M')
1414+
{
1415+
token_stream[(int)index++].kind = Token_Q_ENUM;
1416+
return;
1417+
}
1418+
break;
14081419

14091420
}
14101421
token_stream[(int) index++].kind = Token_identifier;

generator/parser/parser.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ bool Parser::parseDeclaration(DeclarationAST *&node)
463463
case Token_Q_ENUMS:
464464
return parseQ_ENUMS(node);
465465

466+
case Token_Q_ENUM:
467+
return parseQ_ENUM(node);
468+
466469
case Token_template:
467470
case Token_export:
468471
return parseTemplateDeclaration(node);
@@ -1981,6 +1984,10 @@ bool Parser::parseMemberSpecification(DeclarationAST *&node)
19811984
{
19821985
return true;
19831986
}
1987+
else if (parseQ_ENUM(node))
1988+
{
1989+
return true;
1990+
}
19841991

19851992
token_stream.rewind((int) start);
19861993

@@ -4384,13 +4391,39 @@ bool Parser::parseQ_ENUMS(DeclarationAST *&node)
43844391
token_stream.nextToken();
43854392
token_stream.nextToken();
43864393

4394+
int firstToken = token_stream.cursor();
4395+
while (token_stream.lookAhead() != ')') {
4396+
token_stream.nextToken();
4397+
}
4398+
QEnumsAST *ast = CreateNode<QEnumsAST>(_M_pool);
4399+
UPDATE_POS(ast, firstToken, token_stream.cursor());
4400+
ast->isQEnum = false;
4401+
node = ast;
4402+
4403+
token_stream.nextToken();
4404+
4405+
return true;
4406+
}
4407+
4408+
bool Parser::parseQ_ENUM(DeclarationAST *&node)
4409+
{
4410+
if (token_stream.lookAhead() != Token_Q_ENUM)
4411+
return false;
4412+
4413+
if (token_stream.lookAhead(1) != '(')
4414+
return false;
4415+
4416+
token_stream.nextToken();
4417+
token_stream.nextToken();
4418+
43874419
int firstToken = token_stream.cursor();
43884420
while (token_stream.lookAhead() != ')') {
43894421
token_stream.nextToken();
43904422
}
43914423
QEnumsAST *ast = CreateNode<QEnumsAST>(_M_pool);
43924424
UPDATE_POS(ast, firstToken, token_stream.cursor());
43934425
node = ast;
4426+
ast->isQEnum = true;
43944427

43954428
token_stream.nextToken();
43964429

generator/parser/parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class Parser
181181

182182
bool parseQ_PROPERTY(DeclarationAST *&node);
183183
bool parseQ_ENUMS(DeclarationAST *&node);
184+
bool parseQ_ENUM(DeclarationAST *&node);
184185

185186
bool skipUntil(int token);
186187
bool skipUntilDeclaration();

generator/parser/tokens.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ static char const * const _S_token_names[] = {
148148
"whitespaces",
149149
"xor",
150150
"xor_eq",
151-
"Q_ENUMS"
151+
"Q_ENUMS",
152+
"Q_ENUM"
152153
};
153154

154155
static char _S_printable[][2] = {

generator/parser/tokens.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ enum TOKEN_KIND
151151
Token_xor,
152152
Token_xor_eq,
153153
Token_Q_ENUMS,
154+
Token_Q_ENUM,
154155
Token_Q_INVOKABLE,
155156

156157
TOKEN_KIND_COUNT

generator/typesystem_core.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
<rejection class="QtConcurrent" function-name="operator|"/>
7171

7272
<rejection class="Qt" enum-name="Modifier"/>
73+
<rejection class="Qt" function-name="qt_getEnumName"/>
74+
<rejection class="Qt" function-name="qt_getEnumMetaObject"/>
7375

7476
<rejection class="QSharedPointer"/>
7577
<rejection class="QWeakPointer"/>
@@ -1580,7 +1582,9 @@
15801582
<object-type name="QSharedMemory"/>
15811583
<object-type name="QMetaObject"/>
15821584
<object-type name="QMetaMethod"/>
1583-
<object-type name="QMetaEnum"/>
1585+
<object-type name="QMetaEnum">
1586+
<modify-function signature="fromType()" remove="all"/>
1587+
</object-type>
15841588
<object-type name="QMetaProperty"/>
15851589
<object-type name="QMetaClassInfo"/>
15861590
<object-type name="QElapsedTimer"/>
@@ -1589,6 +1593,7 @@
15891593
<modify-function signature="hasRegisteredConverterFunction()" remove="all"/>
15901594
<modify-function signature="hasRegisteredDebugStreamOperator()" remove="all"/>
15911595
<modify-function signature="hasRegisteredComparators()" remove="all"/>
1596+
<modify-function signature="registerEqualsComparator()" remove="all"/>
15921597
<modify-function signature="registerComparators()" remove="all"/>
15931598
<modify-function signature="registerConverter()" remove="all"/>
15941599
<modify-function signature="registerDebugStreamOperator()" remove="all"/>

generator/typesystem_gui.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<rejection class="QGradient" function-name="setInterpolationMode"/>
106106
<rejection class="QGradient" function-name="interpolationMode"/>
107107
<rejection class="QAbstractTextDocumentLayout" function-name="handlerForObject"/>
108+
<rejection class="QPixmap" function-name="fromImageInPlace"/>
108109

109110
<enum-type name="QStaticText::PerformanceHint"/>
110111
<enum-type name="QTextBlockFormat::LineHeightTypes"/>
@@ -1625,7 +1626,7 @@ PyObject* constScanLine(QImage* image, int line) {
16251626

16261627
<object-type name="QAbstractButton"/>
16271628

1628-
<object-type name="QStyle">
1629+
<object-type name="QStyle" create-shell="no">
16291630
<modify-function signature="standardIconImplementation(QStyle::StandardPixmap, const QStyleOption *, const QWidget *)const" virtual-slot="yes"/>
16301631
<modify-function signature="layoutSpacingImplementation(QSizePolicy::ControlType, QSizePolicy::ControlType, Qt::Orientation, const QStyleOption *, const QWidget *) const" virtual-slot="yes"/>
16311632
<modify-function signature="itemTextRect(QFontMetrics,QRect,int,bool,QString)const" remove="all"/>

0 commit comments

Comments
 (0)