QmlJS: Update to new QmlJS parser.

UiPublicMember is now initialized with a statement.
This commit is contained in:
Christian Kamm
2011-05-12 13:25:35 +02:00
parent f8bcd6c615
commit d72bddc7da
30 changed files with 1171 additions and 1080 deletions

View File

@@ -0,0 +1,24 @@
#!/usr/bin/python
import sys
import os
if not len(sys.argv) >= 3:
print("Usage: %s license files..." % os.path.basename(sys.argv[0]))
sys.exit()
licenseFileName = sys.argv[1]
licenseText = ""
with open(licenseFileName, 'r') as f:
licenseText = f.read()
licenseText = licenseText[0:licenseText.find('*/')]
files = sys.argv[2:]
for fileName in files:
with open(fileName, 'r') as f:
text = f.read()
oldEnd = text.find('*/')
if oldEnd == -1:
oldEnd = 0
text = licenseText + text[oldEnd:]
with open(fileName, 'w') as f:
f.write(text)

View File

@@ -12,3 +12,7 @@ done
# export QmlDirParser
perl -p -0777 -i -e 's/QT_BEGIN_NAMESPACE\n\nclass QmlError;\nclass QmlDirParser/#include "qmljsglobal_p.h"\n\nQT_BEGIN_NAMESPACE\n\nclass QmlError;\nclass QML_PARSER_EXPORT QmlDirParser/' qmldirparser_p.h
./changeLicense.py $me/../qmljs_global.h qml*.{cpp,h}
echo "Fix licenses in qmljs.g!"

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
@@ -132,7 +133,7 @@ bool QmlDirParser::parse()
} else if (sections[0] == QLatin1String("plugin")) {
if (sectionCount < 2) {
reportError(lineNumber, -1,
QString::fromUtf8("plugin directive requires 2 arguments, but %1 were provided").arg(sectionCount + 1));
QString::fromUtf8("plugin directive requires one or two arguments, but %1 were provided").arg(sectionCount - 1));
continue;
}
@@ -144,12 +145,22 @@ bool QmlDirParser::parse()
} else if (sections[0] == QLatin1String("internal")) {
if (sectionCount != 3) {
reportError(lineNumber, -1,
QString::fromUtf8("internal types require 2 arguments, but %1 were provided").arg(sectionCount + 1));
QString::fromUtf8("internal types require 2 arguments, but %1 were provided").arg(sectionCount - 1));
continue;
}
Component entry(sections[1], sections[2], -1, -1);
entry.internal = true;
_components.append(entry);
} else if (sections[0] == QLatin1String("typeinfo")) {
if (sectionCount != 2) {
reportError(lineNumber, -1,
QString::fromUtf8("typeinfo requires 1 argument, but %1 were provided").arg(sectionCount - 1));
continue;
}
#ifdef QT_CREATOR
TypeInfo typeInfo(sections[1]);
_typeInfos.append(typeInfo);
#endif
} else if (sectionCount == 2) {
// No version specified (should only be used for relative qmldir files)
@@ -179,7 +190,7 @@ bool QmlDirParser::parse()
}
} else {
reportError(lineNumber, -1,
QString::fromUtf8("a component declaration requires 3 arguments, but %1 were provided").arg(sectionCount + 1));
QString::fromUtf8("a component declaration requires two or three arguments, but %1 were provided").arg(sectionCount));
}
}
@@ -219,4 +230,11 @@ QList<QmlDirParser::Component> QmlDirParser::components() const
return _components;
}
#ifdef QT_CREATOR
QList<QmlDirParser::TypeInfo> QmlDirParser::typeInfos() const
{
return _typeInfos;
}
#endif
QT_END_NAMESPACE

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
@@ -101,6 +102,19 @@ public:
QList<Component> components() const;
QList<Plugin> plugins() const;
#ifdef QT_CREATOR
struct TypeInfo
{
TypeInfo() {}
TypeInfo(const QString &fileName)
: fileName(fileName) {}
QString fileName;
};
QList<TypeInfo> typeInfos() const;
#endif
private:
void reportError(int line, int column, const QString &message);
@@ -110,6 +124,9 @@ private:
QString _source;
QList<Component> _components;
QList<Plugin> _plugins;
#ifdef QT_CREATOR
QList<TypeInfo> _typeInfos;
#endif
unsigned _isParsed: 1;
};

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public

View File

@@ -6,6 +6,7 @@
--
-- Contact: Nokia Corporation (info@qt.nokia.com)
--
--
-- GNU Lesser General Public License Usage
--
-- This file may be used under the terms of the GNU Lesser General Public
@@ -97,6 +98,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
@@ -120,7 +122,6 @@
**
**************************************************************************/
#include <QtCore/QtDebug>
#include <QtGui/QApplication>
@@ -141,6 +142,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
@@ -165,7 +167,6 @@
**************************************************************************/
//
// W A R N I N G
// -------------
@@ -772,19 +773,14 @@ case $rule_number: {
} break;
./
UiObjectMember: UiQualifiedId T_COLON Block ;
/.case $rule_number:./
UiObjectMember: UiQualifiedId T_COLON EmptyStatement ;
/.case $rule_number:./
UiObjectMember: UiQualifiedId T_COLON ExpressionStatement ;
/.case $rule_number:./
UiObjectMember: UiQualifiedId T_COLON IfStatement ; --- ### do we really want if statement in a binding?
/.case $rule_number:./
UiScriptStatement: Block ;
UiScriptStatement: EmptyStatement ;
UiScriptStatement: ExpressionStatement ;
UiScriptStatement: IfStatement ; --- ### do we really want if statement in a binding?
UiObjectMember: UiQualifiedId T_COLON UiScriptStatement ;
/.
case $rule_number:
{
AST::UiScriptBinding *node = makeAstNode<AST::UiScriptBinding> (driver->nodePool(),
sym(1).UiQualifiedId, sym(3).Statement);
@@ -912,51 +908,45 @@ case $rule_number: {
} break;
./
UiObjectMember: T_PROPERTY UiPropertyType JsIdentifier T_COLON Expression T_AUTOMATIC_SEMICOLON ;
UiObjectMember: T_PROPERTY UiPropertyType JsIdentifier T_COLON Expression T_SEMICOLON ;
UiObjectMember: T_PROPERTY UiPropertyType JsIdentifier T_COLON UiScriptStatement ;
/.
case $rule_number: {
AST::UiPublicMember *node = makeAstNode<AST::UiPublicMember> (driver->nodePool(), sym(2).sval, sym(3).sval,
sym(5).Expression);
sym(5).Statement);
node->propertyToken = loc(1);
node->typeToken = loc(2);
node->identifierToken = loc(3);
node->colonToken = loc(4);
node->semicolonToken = loc(6);
sym(1).Node = node;
} break;
./
UiObjectMember: T_READONLY T_PROPERTY UiPropertyType JsIdentifier T_COLON Expression T_AUTOMATIC_SEMICOLON ;
UiObjectMember: T_READONLY T_PROPERTY UiPropertyType JsIdentifier T_COLON Expression T_SEMICOLON ;
UiObjectMember: T_READONLY T_PROPERTY UiPropertyType JsIdentifier T_COLON UiScriptStatement ;
/.
case $rule_number: {
AST::UiPublicMember *node = makeAstNode<AST::UiPublicMember> (driver->nodePool(), sym(3).sval, sym(4).sval,
sym(6).Expression);
sym(6).Statement);
node->isReadonlyMember = true;
node->readonlyToken = loc(1);
node->propertyToken = loc(2);
node->typeToken = loc(3);
node->identifierToken = loc(4);
node->colonToken = loc(5);
node->semicolonToken = loc(7);
sym(1).Node = node;
} break;
./
UiObjectMember: T_DEFAULT T_PROPERTY UiPropertyType JsIdentifier T_COLON Expression T_AUTOMATIC_SEMICOLON ;
UiObjectMember: T_DEFAULT T_PROPERTY UiPropertyType JsIdentifier T_COLON Expression T_SEMICOLON ;
UiObjectMember: T_DEFAULT T_PROPERTY UiPropertyType JsIdentifier T_COLON UiScriptStatement ;
/.
case $rule_number: {
AST::UiPublicMember *node = makeAstNode<AST::UiPublicMember> (driver->nodePool(), sym(3).sval, sym(4).sval,
sym(6).Expression);
sym(6).Statement);
node->isDefaultMember = true;
node->defaultToken = loc(1);
node->propertyToken = loc(2);
node->typeToken = loc(3);
node->identifierToken = loc(4);
node->colonToken = loc(5);
node->semicolonToken = loc(7);
sym(1).Node = node;
} break;
./

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
@@ -826,7 +827,7 @@ void UiFormal::accept0(Visitor *visitor)
void UiPublicMember::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(expression, visitor);
accept(statement, visitor);
accept(binding, visitor);
}

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
@@ -2332,13 +2333,13 @@ public:
UiPublicMember(NameId *memberType,
NameId *name)
: type(Property), typeModifier(0), memberType(memberType), name(name), expression(0), binding(0), isDefaultMember(false), isReadonlyMember(false), parameters(0)
: type(Property), typeModifier(0), memberType(memberType), name(name), statement(0), binding(0), isDefaultMember(false), isReadonlyMember(false), parameters(0)
{ kind = K; }
UiPublicMember(NameId *memberType,
NameId *name,
ExpressionNode *expression)
: type(Property), typeModifier(0), memberType(memberType), name(name), expression(expression), binding(0), isDefaultMember(false), isReadonlyMember(false), parameters(0)
Statement *statement)
: type(Property), typeModifier(0), memberType(memberType), name(name), statement(statement), binding(0), isDefaultMember(false), isReadonlyMember(false), parameters(0)
{ kind = K; }
virtual SourceLocation firstSourceLocation() const
@@ -2366,7 +2367,7 @@ public:
NameId *typeModifier;
NameId *memberType;
NameId *name;
ExpressionNode *expression; // initialized with a JS expression
Statement *statement; // initialized with a JS expression
UiObjectMember *binding; // initialized with a QML object or array.
bool isDefaultMember;
bool isReadonlyMember;

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
@@ -78,12 +79,6 @@ uint qHash(const QmlJS::NameId &id);
} // end of namespace QmlJS
#if defined(Q_CC_MSVC) && _MSC_VER <= 1300
//this ensures that code outside QmlJS can use the hash function
//it also a workaround for some compilers
inline uint qHash(const QmlJS::NameId &nameId) { return QmlJS::qHash(nameId); }
#endif
namespace QmlJS {
class Lexer;

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
@@ -28,7 +29,6 @@
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef QMLJSGLOBAL_P_H
#define QMLJSGLOBAL_P_H
@@ -49,7 +49,7 @@
#else // !QT_CREATOR
# define QT_QML_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
# define QT_QML_END_NAMESPACE QT_END_NAMESPACE
# define QML_PARSER_EXPORT
# define QML_PARSER_EXPORT Q_AUTOTEST_EXPORT
#endif // QT_CREATOR
#endif // QMLJSGLOBAL_P_H

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
@@ -154,15 +155,15 @@ public:
T_XOR = 79,
T_XOR_EQ = 80,
ACCEPT_STATE = 645,
RULE_COUNT = 347,
STATE_COUNT = 646,
ACCEPT_STATE = 640,
RULE_COUNT = 345,
STATE_COUNT = 641,
TERMINAL_COUNT = 101,
NON_TERMINAL_COUNT = 106,
NON_TERMINAL_COUNT = 107,
GOTO_INDEX_OFFSET = 646,
GOTO_INFO_OFFSET = 2714,
GOTO_CHECK_OFFSET = 2714
GOTO_INDEX_OFFSET = 641,
GOTO_INFO_OFFSET = 2787,
GOTO_CHECK_OFFSET = 2787
};
static const char *const spell [];

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,7 @@
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
@@ -225,9 +226,9 @@ protected:
#define J_SCRIPT_REGEXPLITERAL_RULE1 78
#define J_SCRIPT_REGEXPLITERAL_RULE1 76
#define J_SCRIPT_REGEXPLITERAL_RULE2 79
#define J_SCRIPT_REGEXPLITERAL_RULE2 77
QT_QML_END_NAMESPACE

View File

@@ -745,6 +745,12 @@ bool Check::visit(ExpressionStatement *ast)
break;
}
}
if (UiPublicMember *member = cast<UiPublicMember *>(p)) {
if (!cast<Block *>(member->statement)) {
ok = true;
break;
}
}
}
}

View File

@@ -3276,7 +3276,7 @@ bool ASTPropertyReference::getSourceLocation(QString *fileName, int *line, int *
const Value *ASTPropertyReference::value(const Context *context) const
{
if (_ast->expression
if (_ast->statement
&& (!_ast->memberType || _ast->memberType->asString() == QLatin1String("variant")
|| _ast->memberType->asString() == QLatin1String("alias"))) {
@@ -3288,11 +3288,11 @@ const Value *ASTPropertyReference::value(const Context *context) const
QmlJS::ScopeBuilder builder(&localContext, doc);
builder.initializeRootScope();
int offset = _ast->expression->firstSourceLocation().begin();
int offset = _ast->statement->firstSourceLocation().begin();
builder.push(ScopeAstPath(doc)(offset));
Evaluate check(&localContext);
return check(_ast->expression);
return check(_ast->statement);
}
if (_ast->memberType)

View File

@@ -330,12 +330,12 @@ void Rewriter::replaceMemberValue(UiObjectMember *propertyMember,
startOffset = arrayBinding->lbracketToken.offset;
endOffset = arrayBinding->rbracketToken.end();
} else if (UiPublicMember *publicMember = AST::cast<UiPublicMember*>(propertyMember)) {
if (publicMember->expression) {
startOffset = publicMember->expression->firstSourceLocation().offset;
if (publicMember->statement) {
startOffset = publicMember->statement->firstSourceLocation().offset;
if (publicMember->semicolonToken.isValid())
endOffset = publicMember->semicolonToken.end();
else
endOffset = publicMember->expression->lastSourceLocation().offset;
endOffset = publicMember->statement->lastSourceLocation().offset;
} else {
startOffset = publicMember->lastSourceLocation().end();
endOffset = startOffset;

View File

@@ -147,12 +147,12 @@ void ChangePropertyVisitor::replaceMemberValue(UiObjectMember *propertyMember, b
startOffset = arrayBinding->lbracketToken.offset;
endOffset = arrayBinding->rbracketToken.end();
} else if (UiPublicMember *publicMember = AST::cast<UiPublicMember*>(propertyMember)) {
if (publicMember->expression) {
startOffset = publicMember->expression->firstSourceLocation().offset;
if (publicMember->statement) {
startOffset = publicMember->statement->firstSourceLocation().offset;
if (publicMember->semicolonToken.isValid())
endOffset = publicMember->semicolonToken.end();
else
endOffset = publicMember->expression->lastSourceLocation().offset;
endOffset = publicMember->statement->lastSourceLocation().offset;
} else {
startOffset = publicMember->lastSourceLocation().end();
endOffset = startOffset;

View File

@@ -202,16 +202,21 @@ static bool isLiteralValue(ExpressionNode *expr)
return false;
}
static bool isLiteralValue(Statement *stmt)
{
ExpressionStatement *exprStmt = cast<ExpressionStatement *>(stmt);
if (exprStmt)
return isLiteralValue(exprStmt->expression);
else
return false;
}
static inline bool isLiteralValue(UiScriptBinding *script)
{
if (!script || !script->statement)
return false;
ExpressionStatement *exprStmt = cast<ExpressionStatement *>(script->statement);
if (exprStmt)
return isLiteralValue(exprStmt->expression);
else
return false;
return isLiteralValue(script->statement);
}
static inline int propertyType(const QString &typeName)
@@ -852,13 +857,13 @@ void TextToModelMerger::syncNode(ModelNode &modelNode,
const QString astName = property->name->asString();
QString astValue;
if (property->expression)
if (property->statement)
astValue = textAt(context->doc(),
property->expression->firstSourceLocation(),
property->expression->lastSourceLocation());
property->statement->firstSourceLocation(),
property->statement->lastSourceLocation());
const QString astType = property->memberType->asString();
AbstractProperty modelProperty = modelNode.property(astName);
if (!property->expression || isLiteralValue(property->expression)) {
if (!property->statement || isLiteralValue(property->statement)) {
const QVariant variantValue = convertDynamicPropertyValueToVariant(astValue, astType);
syncVariantProperty(modelProperty, variantValue, astType, differenceHandler);
} else {

View File

@@ -181,13 +181,13 @@ bool HoverHandler::matchColorItem(const LookupContext::Ptr &lookupContext,
}
} else if (const AST::UiPublicMember *publicMember =
AST::cast<const AST::UiPublicMember *>(member)) {
if (publicMember->name && posIsInSource(pos, publicMember->expression)) {
if (publicMember->name && posIsInSource(pos, publicMember->statement)) {
value = lookupContext->context()->lookup(publicMember->name->asString());
if (const Interpreter::Reference *ref = value->asReference())
value = lookupContext->context()->lookupReference(ref);
color = textAt(qmlDocument,
publicMember->expression->firstSourceLocation(),
publicMember->expression->lastSourceLocation());
publicMember->statement->firstSourceLocation(),
publicMember->statement->lastSourceLocation());
}
}

View File

@@ -523,7 +523,7 @@ QModelIndex QmlOutlineModel::enterPublicMember(AST::UiPublicMember *publicMember
if (publicMember->name)
objectData.insert(Qt::DisplayRole, publicMember->name->asString());
objectData.insert(AnnotationRole, getAnnotation(publicMember->expression));
objectData.insert(AnnotationRole, getAnnotation(publicMember->statement));
objectData.insert(ItemTypeRole, NonElementBindingType);
QmlOutlineItem *item = enterNode(objectData, publicMember, 0, m_icons->publicMemberIcon());