Commit 0e4deaba authored by Nikolai Kosjar's avatar Nikolai Kosjar

C++: Parse MEMBER in Q_PROPERTY()

MEMBER was added in Qt5.

Task-number: QTCREATORBUG-10068

Change-Id: Ic6c15a0e5ee8981ab98e4c12fc1521dc281b731f
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent c5dfcce9
......@@ -2002,6 +2002,8 @@ bool Bind::visit(QtPropertyDeclarationAST *ast)
flags |= QtPropertyDeclaration::ReadFunction;
} else if (name == "WRITE") {
flags |= QtPropertyDeclaration::WriteFunction;
} else if (name == "MEMBER") {
flags |= QtPropertyDeclaration::MemberVariable;
} else if (name == "RESET") {
flags |= QtPropertyDeclaration::ResetFunction;
} else if (name == "NOTIFY") {
......
......@@ -2138,16 +2138,17 @@ bool Parser::parseAccessDeclaration(DeclarationAST *&node)
/*
Q_PROPERTY(type name
READ getFunction
[WRITE setFunction]
[RESET resetFunction]
[NOTIFY notifySignal]
[DESIGNABLE bool]
[SCRIPTABLE bool]
[STORED bool]
[USER bool]
[CONSTANT]
[FINAL])
(READ getFunction [WRITE setFunction]
| MEMBER memberName [(READ getFunction | WRITE setFunction)])
[RESET resetFunction]
[NOTIFY notifySignal]
[REVISION int]
[DESIGNABLE bool]
[SCRIPTABLE bool]
[STORED bool]
[USER bool]
[CONSTANT]
[FINAL])
Note that "type" appears to be any valid type. So these are valid:
Q_PROPERTY(const char *zoo READ zoo)
......@@ -2155,7 +2156,8 @@ bool Parser::parseAccessDeclaration(DeclarationAST *&node)
Furthermore, the only restriction on the order of the items in between the
parenthesis is that the type is the first parameter and the name comes after
the type.
the type. Especially, there seems to be no restriction on the READ/WRITE/MEMBER
order.
*/
bool Parser::parseQtPropertyDeclaration(DeclarationAST *&node)
{
......@@ -2201,6 +2203,7 @@ bool Parser::parseQtPropertyDeclaration(DeclarationAST *&node)
switch (peekAtQtContextKeyword()) {
case Token_READ:
case Token_WRITE:
case Token_MEMBER:
case Token_RESET:
case Token_NOTIFY:
case Token_REVISION:
......
......@@ -63,7 +63,20 @@ static inline int classify5(const char *s) {
}
static inline int classify6(const char *s) {
if (s[0] == 'N') {
if (s[0] == 'M') {
if (s[1] == 'E') {
if (s[2] == 'M') {
if (s[3] == 'B') {
if (s[4] == 'E') {
if (s[5] == 'R') {
return Token_MEMBER;
}
}
}
}
}
}
else if (s[0] == 'N') {
if (s[1] == 'O') {
if (s[2] == 'T') {
if (s[3] == 'I') {
......
......@@ -18,7 +18,8 @@ enum {
Token_CONSTANT,
Token_DESIGNABLE,
Token_SCRIPTABLE,
Token_REVISION
Token_REVISION,
Token_MEMBER
};
CPLUSPLUS_EXPORT int classifyQtContextKeyword(const char *s, int n);
......
......@@ -556,18 +556,19 @@ public:
NoFlags = 0,
ReadFunction = 1 << 0,
WriteFunction = 1 << 1,
ResetFunction = 1 << 2,
NotifyFunction = 1 << 3,
DesignableFlag = 1 << 4,
DesignableFunction = 1 << 5,
ScriptableFlag = 1 << 6,
ScriptableFunction = 1 << 7,
StoredFlag = 1 << 8,
StoredFunction = 1 << 9,
UserFlag = 1 << 10,
UserFunction = 1 << 11,
ConstantFlag = 1 << 12,
FinalFlag = 1 << 13
MemberVariable = 1 << 2,
ResetFunction = 1 << 3,
NotifyFunction = 1 << 4,
DesignableFlag = 1 << 5,
DesignableFunction = 1 << 6,
ScriptableFlag = 1 << 7,
ScriptableFunction = 1 << 8,
StoredFlag = 1 << 9,
StoredFunction = 1 << 10,
UserFlag = 1 << 11,
UserFunction = 1 << 12,
ConstantFlag = 1 << 13,
FinalFlag = 1 << 14
};
public:
......
......@@ -152,6 +152,10 @@ private slots:
void cpp_constructor_multiple_args();
void cpp_constructor_function_try_catch();
// Q_PROPERTY
void cpp_qproperty();
void cpp_qproperty_data();
// objc++
void objc_simple_class();
void objc_attributes_followed_by_at_keyword();
......@@ -1235,6 +1239,39 @@ void tst_AST::cpp_constructor_function_try_catch()
QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0);
}
void tst_AST::cpp_qproperty()
{
QFETCH(QByteArray, source);
QVERIFY(!source.isEmpty());
const QByteArray sourceWithinClass = "class C { " + source + " };";
QSharedPointer<TranslationUnit> unit(parseDeclaration(sourceWithinClass, false, true));
QVERIFY(unit->ast());
QCOMPARE(diag.errorCount, 0);
}
void tst_AST::cpp_qproperty_data()
{
QTest::addColumn<QByteArray>("source");
QTest::newRow("read-final")
<< QByteArray("Q_PROPERTY(bool focus READ hasFocus FINAL)");
QTest::newRow("read-write-final")
<< QByteArray("Q_PROPERTY(bool focus READ hasFocus WRITE setFocus FINAL)");
QTest::newRow("member-final")
<< QByteArray("Q_PROPERTY(bool focus MEMBER m_focus FINAL)");
QTest::newRow("member-read-final")
<< QByteArray("Q_PROPERTY(bool focus MEMBER m_focus READ m_focus FINAL)");
QTest::newRow("member-read-write-final")
<< QByteArray("Q_PROPERTY(bool focus MEMBER m_focus READ hasFocus WRITE setFocus FINAL)");
QTest::newRow("all")
<< QByteArray("Q_PROPERTY(bool focus MEMBER m_focus READ hasFocus WRITE setFocus"
" RESET resetFocus NOTIFY focusChanged REVISION 1 DESIGNABLE true"
" SCRIPTABLE true STORED true USER true CONSTANT FINAL)");
}
void tst_AST::objc_simple_class()
{
QSharedPointer<TranslationUnit> unit(parseDeclaration("\n"
......
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