42 #include "private/qdeclarativescriptparser_p.h" 44 #include "private/qdeclarativeparser_p.h" 51 #include "private/qdeclarativerewrite_p.h" 54 #include <QCoreApplication> 75 struct StateStack :
public QStack<State>
84 const State &state = top();
86 State s(state.property->getValue(location),
87 state.property->getValue(location)->getProperty(name.
toUtf8()));
92 state.object->getProperty(name.
toUtf8()));
102 virtual ~ProcessAST();
136 const State state()
const;
140 QString qualifiedNameId()
const;
170 StateStack _stateStack;
180 ProcessAST::~ProcessAST()
192 AST::Node::acceptChild(node,
this);
197 if (_stateStack.isEmpty())
200 return _stateStack.back();
205 return state().object;
208 Property *ProcessAST::currentProperty()
const 210 return state().property;
213 QString ProcessAST::qualifiedNameId()
const 241 bool isType = !objectType.
isEmpty() &&
243 (lastTypeDot >= 0 && objectType.
at(lastTypeDot+1).
isUpper()));
245 int propertyCount = 0;
248 _stateStack.pushProperty(name->name->asString(),
252 if (!onAssignment && propertyCount && currentProperty() && currentProperty()->values.count()) {
257 _parser->_errors <<
error;
263 if(propertyCount || !currentObject()) {
268 _parser->_errors <<
error;
276 _stateStack.pushProperty(objectType, loc);
285 QString resolvableObjectType = objectType;
286 if (lastTypeDot >= 0)
297 _scope.append(resolvableObjectType);
298 obj->
typeName = qualifiedNameId().toUtf8();
313 while (propertyCount--)
318 if (! _parser->tree()) {
319 _parser->setTree(obj);
321 const State state = _stateStack.top();
325 if (state.property) {
326 state.property->addValue(v);
328 Property *defaultProp = state.object->getDefaultProperty();
339 _stateStack.pushObject(obj);
397 if (!
import.qualifier.at(0).isUpper()) {
402 _parser->_errors <<
error;
410 _parser->_errors <<
error;
416 for (
int ii = 0; ii < _parser->_imports.count(); ++ii) {
420 if ((isScript || otherIsScript) &&
import.qualifier == other.
qualifier) {
425 _parser->_errors <<
error;
435 _parser->_errors <<
error;
446 _parser->_errors <<
error;
451 import.location =
location(startLoc, endLoc);
454 _parser->_imports <<
import;
461 const struct TypeNameToType {
465 } propTypeNameToTypes[] = {
466 {
"int", Object::DynamicProperty::Int,
"int" },
467 {
"bool", Object::DynamicProperty::Bool,
"bool" },
468 {
"double", Object::DynamicProperty::Real,
"double" },
469 {
"real", Object::DynamicProperty::Real,
"qreal" },
471 {
"url", Object::DynamicProperty::Url,
"QUrl" },
479 {
"date", Object::DynamicProperty::DateTime,
"QDateTime" },
480 {
"variant", Object::DynamicProperty::Variant,
"QVariant" }
482 const int propTypeNameToTypesCount =
sizeof(propTypeNameToTypes) /
483 sizeof(propTypeNameToTypes[0]);
485 if(node->
type == AST::UiPublicMember::Signal) {
494 const char *qtType = 0;
495 for(
int ii = 0; !qtType && ii < propTypeNameToTypesCount; ++ii) {
496 if(
QLatin1String(propTypeNameToTypes[ii].name) == memberType)
497 qtType = propTypeNameToTypes[ii].qtName;
505 _parser->_errors <<
error;
514 _stateStack.top().object->dynamicSignals << signal;
519 bool typeFound =
false;
523 type = Object::DynamicProperty::Alias;
527 for(
int ii = 0; !typeFound && ii < propTypeNameToTypesCount; ++ii) {
528 if(
QLatin1String(propTypeNameToTypes[ii].name) == memberType) {
529 type = propTypeNameToTypes[ii].type;
534 if (!typeFound && memberType.
at(0).
isUpper()) {
539 type = Object::DynamicProperty::Custom;
541 type = Object::DynamicProperty::CustomList;
547 _parser->_errors <<
error;
556 _parser->_errors <<
error;
565 _parser->_errors <<
error;
574 _parser->_errors <<
error;
580 property.type =
type;
581 if (type >= Object::DynamicProperty::Custom) {
583 _parser->findOrCreateType(memberType);
586 property.customType = memberType.
toUtf8();
587 property.name = name.
toUtf8();
592 property.defaultValue =
new Property;
593 property.defaultValue->parent = _stateStack.top().object;
594 property.defaultValue->location =
601 property.defaultValue->values << value;
604 _stateStack.top().object->dynamicProperties <<
property;
623 defineObjectBinding( 0,
false, objectType,
649 }
else if (expr->
kind == AST::Node::Kind_TrueLiteral) {
651 }
else if (expr->
kind == AST::Node::Kind_FalseLiteral) {
671 int propertyCount = 0;
675 _stateStack.pushProperty(name->name->asString(),
681 if (prop->
values.count()) {
686 _parser->_errors <<
error;
693 primitive = getVariant(stmt->expression);
702 v->
value = primitive;
708 while (propertyCount--)
720 commas.
append(
it->commaToken.offset);
730 int propertyCount = 0;
734 _stateStack.pushProperty(name->name->asString(),
740 if (prop->
values.count()) {
745 _parser->_errors <<
error;
758 while (propertyCount--)
771 slot.
location =
location(funDecl->firstSourceLocation(), funDecl->lastSourceLocation());
782 QString body = textAt(loc, funDecl->rbraceToken);
783 slot.
name = funDecl->name->asString().toUtf8();
792 _parser->_errors <<
error;
815 : nodePool(filename, &engine) {}
829 #ifndef QT_NO_TEXTCODEC 860 ProcessAST process(
this);
861 process(code, parser.
ast());
895 for (
int ii = 0; ii < n; ++ii)
943 if (pragmaValue == library) {
953 #define CHECK_LINE if(l.currentLineNo() != startLine) return rv; 954 #define CHECK_TOKEN(t) if (token != QDeclarativeJSGrammar:: t) return rv; 999 while (*current != QDeclarativeJSGrammar::EOF_SYMBOL) {
1000 if (*current == token)
1011 QDeclarativeParser::Object::ScriptBlock::Pragmas &pragmas = rv.
pragmas;
1020 int token = l.
lex();
1045 if (!file.endsWith(js))
1074 import.qualifier = importId;
1129 import.version = version;
1130 import.qualifier = importId;
enum QDeclarativeJS::AST::UiPublicMember::@102 type
const QString asString() const
int characterCount() const
#define QT_END_NAMESPACE
This macro expands to.
void setDescription(const QString &)
Sets the error description.
const QChar at(int i) const
Returns the character at the given index position in the string.
virtual SourceLocation firstSourceLocation() const
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
void setTree(QDeclarativeParser::Object *tree)
#define it(className, varName)
SourceLocation lbracketToken
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
QList< TypeReference * > referencedTypes() const
virtual SourceLocation firstSourceLocation() const
UiParameterList * finish()
UiQualifiedId * importUri
QList< int > listCommaPositions
QString & replace(int i, int len, QChar after)
The QByteArray class provides an array of bytes.
UiObjectInitializer * initializer
void setCodec(QTextCodec *codec)
Sets the codec for this stream to codec.
static bool isUriToken(int token)
virtual SourceLocation firstSourceLocation() const =0
void setColumn(int)
Sets the error column number.
static const int uriTokens[]
QList< TypeReference * > _refTypes
QList< QDeclarativeError > errors() const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QStack class is a template class that provides a stack.
int count(const T &t) const
Returns the number of occurrences of value in the list.
UiQualifiedId * qualifiedTypeNameId
SourceLocation importToken
SourceLocation importIdToken
QList< Import > imports() const
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
virtual SourceLocation lastSourceLocation() const =0
AST::UiProgram * ast() const
QList< QByteArray > parameterNames
LocationRange listValueRange
static QDeclarativeParser::Object::ScriptBlock::Pragmas extractPragmas(QString &)
The QChar class provides a 16-bit Unicode character.
QChar * data()
Returns a pointer to the data stored in the QString.
SourceLocation rbracketToken
virtual SourceLocation firstSourceLocation() const =0
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
QList< QByteArray > parameterTypes
static JavaScriptMetaData extractMetaData(QString &)
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QList< DynamicSlot > dynamicSlots
UiObjectInitializer * initializer
ExpressionNode * expression
const QChar * characterBuffer() const
SourceLocation semicolonToken
virtual bool visit(UiProgram *)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QList< QDeclarativeParser::Object * > refObjects
virtual SourceLocation lastSourceLocation() const =0
The QStringList class provides a list of strings.
static const char * data(const QByteArray &arr)
TypeReference * findOrCreateType(const QString &name)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
SourceLocation readonlyToken
SourceLocation typeModifierToken
The QDeclarativeError class encapsulates a QML error.
void clear()
Removes all items from the list.
The State element defines configurations of objects and properties.
SourceLocation identifierToken
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
bool isUpper() const
Returns true if the character is an uppercase letter, i.
~QDeclarativeScriptParser()
void setLine(int)
Sets the error line number.
SourceLocation fileNameToken
virtual void endVisit(UiProgram *)
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
virtual SourceLocation lastSourceLocation() const
QList< QDeclarativeError > _errors
SourceLocation rbraceToken
void addOnValue(Value *v)
QString & append(QChar c)
void setUrl(const QUrl &)
Sets the url for the file that caused this error.
The QTextStream class provides a convenient interface for reading and writing text.
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QDeclarativeScriptParser()
QList< QByteArray > parameterNames
static QTestResult::TestLocation location
bool parse(const QByteArray &data, const QUrl &url=QUrl())
UiQualifiedId * qualifiedTypeNameId
UiObjectMemberList * members
QString readAll()
Reads the entire content of the stream, and returns it as a QString.
UiQualifiedId * qualifiedId
QDeclarativeScriptParserJsASTData * data
void accept(AST::Node *node)
static void replaceWithSpace(QString &str, int idx, int n)
QDeclarativeParser::Object * root
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
UiQualifiedId * qualifiedId
static const KeyPair *const end
virtual SourceLocation firstSourceLocation() const
QDeclarativeScriptParserJsASTData(const QString &filename)
virtual SourceLocation lastSourceLocation() const
QList< DiagnosticMessage > diagnosticMessages() const
static QString fileName(const QString &fileUrl)
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
SourceLocation versionToken
QDeclarativeParser::Object * tree() const
UiParameterList * parameters
UiArrayMemberList * members
UiQualifiedId * qualifiedId
void setCode(const QString &c, int lineno)
int currentLineNo() const