forked from qt-creator/qt-creator
qmljs: replace dynamic_cast with AST::cast
Change-Id: I94a289f07c444b16b1ca1dc8bc4f7aa690de4312 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
This commit is contained in:
committed by
Marco Benelli
parent
f8a404c258
commit
d2769f3003
@@ -123,7 +123,7 @@ void TypeDescriptionReader::readDocument(UiProgram *ast)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UiObjectDefinition *module = dynamic_cast<UiObjectDefinition *>(ast->members->member);
|
UiObjectDefinition *module = AST::cast<UiObjectDefinition *>(ast->members->member);
|
||||||
if (!module) {
|
if (!module) {
|
||||||
addError(SourceLocation(), tr("Expected document to contain a single object definition."));
|
addError(SourceLocation(), tr("Expected document to contain a single object definition."));
|
||||||
return;
|
return;
|
||||||
@@ -141,9 +141,9 @@ void TypeDescriptionReader::readModule(UiObjectDefinition *ast)
|
|||||||
{
|
{
|
||||||
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
||||||
UiObjectMember *member = it->member;
|
UiObjectMember *member = it->member;
|
||||||
UiObjectDefinition *component = dynamic_cast<UiObjectDefinition *>(member);
|
UiObjectDefinition *component = AST::cast<UiObjectDefinition *>(member);
|
||||||
|
|
||||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
UiScriptBinding *script = AST::cast<UiScriptBinding *>(member);
|
||||||
if (script && (toString(script->qualifiedId) == QStringLiteral("dependencies"))) {
|
if (script && (toString(script->qualifiedId) == QStringLiteral("dependencies"))) {
|
||||||
readDependencies(script);
|
readDependencies(script);
|
||||||
continue;
|
continue;
|
||||||
@@ -184,18 +184,18 @@ void TypeDescriptionReader::addWarning(const SourceLocation &loc, const QString
|
|||||||
|
|
||||||
void TypeDescriptionReader::readDependencies(UiScriptBinding *ast)
|
void TypeDescriptionReader::readDependencies(UiScriptBinding *ast)
|
||||||
{
|
{
|
||||||
ExpressionStatement *stmt = dynamic_cast<ExpressionStatement*>(ast->statement);
|
ExpressionStatement *stmt = AST::cast<ExpressionStatement*>(ast->statement);
|
||||||
if (!stmt) {
|
if (!stmt) {
|
||||||
addError(ast->statement->firstSourceLocation(), tr("Expected dependency definitions"));
|
addError(ast->statement->firstSourceLocation(), tr("Expected dependency definitions"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ArrayLiteral *exp = dynamic_cast<ArrayLiteral *>(stmt->expression);
|
ArrayLiteral *exp = AST::cast<ArrayLiteral *>(stmt->expression);
|
||||||
if (!exp) {
|
if (!exp) {
|
||||||
addError(stmt->expression->firstSourceLocation(), tr("Expected dependency definitions"));
|
addError(stmt->expression->firstSourceLocation(), tr("Expected dependency definitions"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (ElementList *l = exp->elements; l; l = l->next) {
|
for (ElementList *l = exp->elements; l; l = l->next) {
|
||||||
StringLiteral *str = dynamic_cast<StringLiteral *>(l->expression);
|
StringLiteral *str = AST::cast<StringLiteral *>(l->expression);
|
||||||
if (!exp) {
|
if (!exp) {
|
||||||
addWarning(l->expression->firstSourceLocation(),
|
addWarning(l->expression->firstSourceLocation(),
|
||||||
tr("Cannot read dependency: skipping."));
|
tr("Cannot read dependency: skipping."));
|
||||||
@@ -210,8 +210,8 @@ void TypeDescriptionReader::readComponent(UiObjectDefinition *ast)
|
|||||||
|
|
||||||
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
||||||
UiObjectMember *member = it->member;
|
UiObjectMember *member = it->member;
|
||||||
UiObjectDefinition *component = dynamic_cast<UiObjectDefinition *>(member);
|
UiObjectDefinition *component = AST::cast<UiObjectDefinition *>(member);
|
||||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
UiScriptBinding *script = AST::cast<UiScriptBinding *>(member);
|
||||||
if (component) {
|
if (component) {
|
||||||
QString name = toString(component->qualifiedTypeNameId);
|
QString name = toString(component->qualifiedTypeNameId);
|
||||||
if (name == QLatin1String("Property"))
|
if (name == QLatin1String("Property"))
|
||||||
@@ -272,7 +272,7 @@ void TypeDescriptionReader::readModuleApi(UiObjectDefinition *ast)
|
|||||||
|
|
||||||
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
||||||
UiObjectMember *member = it->member;
|
UiObjectMember *member = it->member;
|
||||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
UiScriptBinding *script = AST::cast<UiScriptBinding *>(member);
|
||||||
|
|
||||||
if (script) {
|
if (script) {
|
||||||
const QString name = toString(script->qualifiedId);
|
const QString name = toString(script->qualifiedId);
|
||||||
@@ -311,8 +311,8 @@ void TypeDescriptionReader::readSignalOrMethod(UiObjectDefinition *ast, bool isM
|
|||||||
|
|
||||||
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
||||||
UiObjectMember *member = it->member;
|
UiObjectMember *member = it->member;
|
||||||
UiObjectDefinition *component = dynamic_cast<UiObjectDefinition *>(member);
|
UiObjectDefinition *component = AST::cast<UiObjectDefinition *>(member);
|
||||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
UiScriptBinding *script = AST::cast<UiScriptBinding *>(member);
|
||||||
if (component) {
|
if (component) {
|
||||||
QString name = toString(component->qualifiedTypeNameId);
|
QString name = toString(component->qualifiedTypeNameId);
|
||||||
if (name == QLatin1String("Parameter"))
|
if (name == QLatin1String("Parameter"))
|
||||||
@@ -354,7 +354,7 @@ void TypeDescriptionReader::readProperty(UiObjectDefinition *ast, FakeMetaObject
|
|||||||
|
|
||||||
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
||||||
UiObjectMember *member = it->member;
|
UiObjectMember *member = it->member;
|
||||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
UiScriptBinding *script = AST::cast<UiScriptBinding *>(member);
|
||||||
if (!script) {
|
if (!script) {
|
||||||
addWarning(member->firstSourceLocation(), tr("Expected script binding."));
|
addWarning(member->firstSourceLocation(), tr("Expected script binding."));
|
||||||
continue;
|
continue;
|
||||||
@@ -391,7 +391,7 @@ void TypeDescriptionReader::readEnum(UiObjectDefinition *ast, FakeMetaObject::Pt
|
|||||||
|
|
||||||
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
||||||
UiObjectMember *member = it->member;
|
UiObjectMember *member = it->member;
|
||||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
UiScriptBinding *script = AST::cast<UiScriptBinding *>(member);
|
||||||
if (!script) {
|
if (!script) {
|
||||||
addWarning(member->firstSourceLocation(), tr("Expected script binding."));
|
addWarning(member->firstSourceLocation(), tr("Expected script binding."));
|
||||||
continue;
|
continue;
|
||||||
@@ -416,7 +416,7 @@ void TypeDescriptionReader::readParameter(UiObjectDefinition *ast, FakeMetaMetho
|
|||||||
|
|
||||||
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
|
||||||
UiObjectMember *member = it->member;
|
UiObjectMember *member = it->member;
|
||||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
UiScriptBinding *script = AST::cast<UiScriptBinding *>(member);
|
||||||
if (!script) {
|
if (!script) {
|
||||||
addWarning(member->firstSourceLocation(), tr("Expected script binding."));
|
addWarning(member->firstSourceLocation(), tr("Expected script binding."));
|
||||||
continue;
|
continue;
|
||||||
@@ -450,13 +450,13 @@ QString TypeDescriptionReader::readStringBinding(UiScriptBinding *ast)
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionStatement *expStmt = dynamic_cast<ExpressionStatement *>(ast->statement);
|
ExpressionStatement *expStmt = AST::cast<ExpressionStatement *>(ast->statement);
|
||||||
if (!expStmt) {
|
if (!expStmt) {
|
||||||
addError(ast->statement->firstSourceLocation(), tr("Expected string after colon."));
|
addError(ast->statement->firstSourceLocation(), tr("Expected string after colon."));
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringLiteral *stringLit = dynamic_cast<StringLiteral *>(expStmt->expression);
|
StringLiteral *stringLit = AST::cast<StringLiteral *>(expStmt->expression);
|
||||||
if (!stringLit) {
|
if (!stringLit) {
|
||||||
addError(expStmt->firstSourceLocation(), tr("Expected string after colon."));
|
addError(expStmt->firstSourceLocation(), tr("Expected string after colon."));
|
||||||
return QString();
|
return QString();
|
||||||
@@ -474,14 +474,14 @@ bool TypeDescriptionReader::readBoolBinding(AST::UiScriptBinding *ast)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionStatement *expStmt = dynamic_cast<ExpressionStatement *>(ast->statement);
|
ExpressionStatement *expStmt = AST::cast<ExpressionStatement *>(ast->statement);
|
||||||
if (!expStmt) {
|
if (!expStmt) {
|
||||||
addError(ast->statement->firstSourceLocation(), tr("Expected boolean after colon."));
|
addError(ast->statement->firstSourceLocation(), tr("Expected boolean after colon."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TrueLiteral *trueLit = dynamic_cast<TrueLiteral *>(expStmt->expression);
|
TrueLiteral *trueLit = AST::cast<TrueLiteral *>(expStmt->expression);
|
||||||
FalseLiteral *falseLit = dynamic_cast<FalseLiteral *>(expStmt->expression);
|
FalseLiteral *falseLit = AST::cast<FalseLiteral *>(expStmt->expression);
|
||||||
if (!trueLit && !falseLit) {
|
if (!trueLit && !falseLit) {
|
||||||
addError(expStmt->firstSourceLocation(), tr("Expected true or false after colon."));
|
addError(expStmt->firstSourceLocation(), tr("Expected true or false after colon."));
|
||||||
return false;
|
return false;
|
||||||
@@ -560,20 +560,20 @@ void TypeDescriptionReader::readExports(UiScriptBinding *ast, FakeMetaObject::Pt
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionStatement *expStmt = dynamic_cast<ExpressionStatement *>(ast->statement);
|
ExpressionStatement *expStmt = AST::cast<ExpressionStatement *>(ast->statement);
|
||||||
if (!expStmt) {
|
if (!expStmt) {
|
||||||
addError(ast->statement->firstSourceLocation(), tr("Expected array of strings after colon."));
|
addError(ast->statement->firstSourceLocation(), tr("Expected array of strings after colon."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayLiteral *arrayLit = dynamic_cast<ArrayLiteral *>(expStmt->expression);
|
ArrayLiteral *arrayLit = AST::cast<ArrayLiteral *>(expStmt->expression);
|
||||||
if (!arrayLit) {
|
if (!arrayLit) {
|
||||||
addError(expStmt->firstSourceLocation(), tr("Expected array of strings after colon."));
|
addError(expStmt->firstSourceLocation(), tr("Expected array of strings after colon."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ElementList *it = arrayLit->elements; it; it = it->next) {
|
for (ElementList *it = arrayLit->elements; it; it = it->next) {
|
||||||
StringLiteral *stringLit = dynamic_cast<StringLiteral *>(it->expression);
|
StringLiteral *stringLit = AST::cast<StringLiteral *>(it->expression);
|
||||||
if (!stringLit) {
|
if (!stringLit) {
|
||||||
addError(arrayLit->firstSourceLocation(), tr("Expected array literal with only string literal members."));
|
addError(arrayLit->firstSourceLocation(), tr("Expected array literal with only string literal members."));
|
||||||
return;
|
return;
|
||||||
@@ -606,13 +606,13 @@ void TypeDescriptionReader::readMetaObjectRevisions(UiScriptBinding *ast, FakeMe
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionStatement *expStmt = dynamic_cast<ExpressionStatement *>(ast->statement);
|
ExpressionStatement *expStmt = AST::cast<ExpressionStatement *>(ast->statement);
|
||||||
if (!expStmt) {
|
if (!expStmt) {
|
||||||
addError(ast->statement->firstSourceLocation(), tr("Expected array of numbers after colon."));
|
addError(ast->statement->firstSourceLocation(), tr("Expected array of numbers after colon."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayLiteral *arrayLit = dynamic_cast<ArrayLiteral *>(expStmt->expression);
|
ArrayLiteral *arrayLit = AST::cast<ArrayLiteral *>(expStmt->expression);
|
||||||
if (!arrayLit) {
|
if (!arrayLit) {
|
||||||
addError(expStmt->firstSourceLocation(), tr("Expected array of numbers after colon."));
|
addError(expStmt->firstSourceLocation(), tr("Expected array of numbers after colon."));
|
||||||
return;
|
return;
|
||||||
@@ -650,13 +650,13 @@ void TypeDescriptionReader::readEnumValues(AST::UiScriptBinding *ast, LanguageUt
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionStatement *expStmt = dynamic_cast<ExpressionStatement *>(ast->statement);
|
ExpressionStatement *expStmt = AST::cast<ExpressionStatement *>(ast->statement);
|
||||||
if (!expStmt) {
|
if (!expStmt) {
|
||||||
addError(ast->statement->firstSourceLocation(), tr("Expected object literal after colon."));
|
addError(ast->statement->firstSourceLocation(), tr("Expected object literal after colon."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectLiteral *objectLit = dynamic_cast<ObjectLiteral *>(expStmt->expression);
|
ObjectLiteral *objectLit = AST::cast<ObjectLiteral *>(expStmt->expression);
|
||||||
if (!objectLit) {
|
if (!objectLit) {
|
||||||
addError(expStmt->firstSourceLocation(), tr("Expected object literal after colon."));
|
addError(expStmt->firstSourceLocation(), tr("Expected object literal after colon."));
|
||||||
return;
|
return;
|
||||||
@@ -665,11 +665,11 @@ void TypeDescriptionReader::readEnumValues(AST::UiScriptBinding *ast, LanguageUt
|
|||||||
for (PropertyAssignmentList *it = objectLit->properties; it; it = it->next) {
|
for (PropertyAssignmentList *it = objectLit->properties; it; it = it->next) {
|
||||||
PropertyNameAndValue *assignement = AST::cast<PropertyNameAndValue *>(it->assignment);
|
PropertyNameAndValue *assignement = AST::cast<PropertyNameAndValue *>(it->assignment);
|
||||||
if (assignement) {
|
if (assignement) {
|
||||||
StringLiteralPropertyName *propName = dynamic_cast<StringLiteralPropertyName *>(assignement->name);
|
StringLiteralPropertyName *propName = AST::cast<StringLiteralPropertyName *>(assignement->name);
|
||||||
NumericLiteral *value = dynamic_cast<NumericLiteral *>(assignement->value);
|
NumericLiteral *value = AST::cast<NumericLiteral *>(assignement->value);
|
||||||
UnaryMinusExpression *minus = dynamic_cast<UnaryMinusExpression *>(assignement->value);
|
UnaryMinusExpression *minus = AST::cast<UnaryMinusExpression *>(assignement->value);
|
||||||
if (minus)
|
if (minus)
|
||||||
value = dynamic_cast<NumericLiteral *>(minus->expression);
|
value = AST::cast<NumericLiteral *>(minus->expression);
|
||||||
if (!propName || !value) {
|
if (!propName || !value) {
|
||||||
addError(objectLit->firstSourceLocation(), tr("Expected object literal to contain only 'string: number' elements."));
|
addError(objectLit->firstSourceLocation(), tr("Expected object literal to contain only 'string: number' elements."));
|
||||||
continue;
|
continue;
|
||||||
|
Reference in New Issue
Block a user