Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
f717a7df
Commit
f717a7df
authored
Feb 23, 2010
by
Christian Kamm
Browse files
Add Qml type checks for assigning literals to properties.
Done-with: Erik Verbruggen
parent
b1522ba5
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/libs/qmljs/qmljscheck.cpp
View file @
f717a7df
...
...
@@ -33,8 +33,9 @@
#include
"qmljsevaluate.h"
#include
"parser/qmljsast_p.h"
#include
<QtGui/QApplication>
#include
<QtCore/QDebug>
#include
<QtCore/QCoreApplication>
#include
<QtGui/QApplication>
namespace
QmlJS
{
namespace
Messages
{
...
...
@@ -125,17 +126,48 @@ void Check::visitQmlObject(Node *ast, UiQualifiedId *typeId,
_scopeBuilder
.
pop
();
}
void
Check
::
errorOnWrongRhs
(
const
SourceLocation
&
loc
,
const
Value
*
lhsValue
)
{
if
(
lhsValue
->
asBooleanValue
())
{
error
(
loc
,
QCoreApplication
::
translate
(
"QmlJS::Check"
,
"boolean value expected"
));
}
else
if
(
lhsValue
->
asNumberValue
())
{
error
(
loc
,
QCoreApplication
::
translate
(
"QmlJS::Check"
,
"numerical value expected"
));
}
else
if
(
lhsValue
->
asStringValue
())
{
error
(
loc
,
QCoreApplication
::
translate
(
"QmlJS::Check"
,
"string value expected"
));
}
}
bool
Check
::
visit
(
UiScriptBinding
*
ast
)
{
const
Value
*
lhsValue
=
checkScopeObjectMember
(
ast
->
qualifiedId
);
if
(
lhsValue
)
{
// ### Fix the evaluator to accept statements!
if
(
ExpressionStatement
*
expStmt
=
cast
<
ExpressionStatement
*>
(
ast
->
statement
))
{
Evaluate
evaluator
(
&
_context
);
const
Value
*
rhsValue
=
evaluator
(
expStmt
->
expression
);
ExpressionNode
*
expr
=
expStmt
->
expression
;
const
SourceLocation
loc
=
locationFromRange
(
expStmt
->
firstSourceLocation
(),
expStmt
->
lastSourceLocation
());
checkPropertyAssignment
(
loc
,
lhsValue
,
rhsValue
,
expStmt
->
expression
);
// Qml is particularly strict with literals
if
(
cast
<
StringLiteral
*>
(
expr
)
&&
!
lhsValue
->
asStringValue
())
{
errorOnWrongRhs
(
loc
,
lhsValue
);
}
else
if
((
expr
->
kind
==
Node
::
Kind_TrueLiteral
||
expr
->
kind
==
Node
::
Kind_FalseLiteral
)
&&
!
lhsValue
->
asBooleanValue
())
{
errorOnWrongRhs
(
loc
,
lhsValue
);
}
else
if
(
cast
<
NumericLiteral
*>
(
expr
)
&&
!
lhsValue
->
asNumberValue
())
{
errorOnWrongRhs
(
loc
,
lhsValue
);
}
else
if
(
UnaryMinusExpression
*
unaryMinus
=
cast
<
UnaryMinusExpression
*>
(
expr
))
{
if
(
cast
<
NumericLiteral
*>
(
unaryMinus
->
expression
)
&&
!
lhsValue
->
asNumberValue
())
{
errorOnWrongRhs
(
loc
,
lhsValue
);
}
}
else
{
Evaluate
evaluator
(
&
_context
);
const
Value
*
rhsValue
=
evaluator
(
expr
);
checkPropertyAssignment
(
loc
,
lhsValue
,
rhsValue
,
expr
);
}
}
}
...
...
src/libs/qmljs/qmljscheck.h
View file @
f717a7df
...
...
@@ -61,6 +61,7 @@ private:
const
Interpreter
::
Value
*
lhsValue
,
const
Interpreter
::
Value
*
rhsValue
,
QmlJS
::
AST
::
ExpressionNode
*
ast
);
void
errorOnWrongRhs
(
const
AST
::
SourceLocation
&
loc
,
const
Interpreter
::
Value
*
lhsValue
);
void
warning
(
const
AST
::
SourceLocation
&
loc
,
const
QString
&
message
);
void
error
(
const
AST
::
SourceLocation
&
loc
,
const
QString
&
message
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment