Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlirbuilder.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
6
7#include <private/qduplicatetracker_p.h>
8#include <private/qv4staticvalue_p.h>
9#include <private/qv4compileddata_p.h>
10#include <private/qqmljsparser_p.h>
11#include <private/qqmljslexer_p.h>
12#include <private/qv4compilerscanfunctions_p.h>
13#include <QCoreApplication>
14#include <QCryptographicHash>
15#include <QtCore/qtyperevision.h>
16
17#include <cmath>
18#include <iterator>
19
20QT_USE_NAMESPACE
21
22using namespace Qt::StringLiterals;
23
24static const quint32 emptyStringIndex = 0;
25using namespace QmlIR;
26using namespace QQmlJS;
27
28#define COMPILE_EXCEPTION(...)
29 {
30 recordError(__VA_ARGS__);
31 if (!shouldContinue())
32 return false;
33 }
34
35void Object::simplifyRequiredProperties() {
36 // if a property of the current object was marked as required
37 // do not store that information in the ExtraData
38 // but rather mark the property as required
39 QSet<int> required;
40 for (auto it = this->requiredPropertyExtraDataBegin(); it != this->requiredPropertyExtraDataEnd(); ++it)
41 required.insert(it->nameIndex);
42 if (required.isEmpty())
43 return;
44 for (auto it = this->propertiesBegin(); it != this->propertiesEnd(); ++it) {
45 auto requiredIt = required.find(it->nameIndex());
46 if (requiredIt != required.end()) {
47 it->setIsRequired(true);
48 required.erase(requiredIt);
49 }
50 }
51 QmlIR::RequiredPropertyExtraData *prev = nullptr;
52 auto current = this->requiredPropertyExtraDatas->first;
53 while (current) {
54 if (required.contains(current->nameIndex))
55 prev = current;
56 else
57 requiredPropertyExtraDatas->unlink(prev, current);
58 current = current->next;
59 }
60}
61
62/*!
63 \internal
64
65 Reorders the alias data within the linked list of this object so that
66 aliases targeting other aliases on the same object come after their
67 targets. This ensures that dependencies are resolved and appended to
68 the property cache first, which is necessary because the runtime
69 assumes that the property cache position matches the alias table index.
70
71 Only considers same-object dependencies (where the alias's idIndex
72 resolves to idNameIndex). Cross-object dependencies are handled by
73 the multi-pass resolution in QQmlCOmponentAndAliasResolver.
74*/
75void Object::sortAliasDependencies(const Document *doc, QList<QQmlJS::DiagnosticMessage> *errors)
76{
77 using AliasArray = QVarLengthArray<Alias *, 8>;
78
79 AliasArray ordered;
80 ordered.reserve(aliasCount());
81
82 // if the default property is an alias, we need to later update the default property index
83 Alias *defaultPropertyAlias = nullptr;
84 qsizetype aliasCounter = 0;
85
86 // Collect aliases as nodes in a graph. Non-local ones are already ordered.
87 AliasArray nodes;
88 for (Alias *a = firstAlias(); a; ++aliasCounter, a = a->next) {
89 if (defaultPropertyIsAlias && aliasCounter == indexOfDefaultPropertyOrAlias) {
90 defaultPropertyAlias = a;
91 }
92 if (a->idIndex() == idNameIndex && idNameIndex != 0)
93 nodes.append(a);
94 else
95 ordered.append(a);
96 }
97
98 // Nothing to sort here.
99 if (nodes.isEmpty())
100 return;
101
102 // Collect dependencies as edges between nodes
103 QVarLengthArray<qsizetype, 8> edges(nodes.size(), -1);
104 for (qsizetype i = 0, end = nodes.size(); i < end; ++i) {
105 const QStringView propValue = doc->stringAt(nodes[i]->propertyNameIndex());
106 const int dotIdx = propValue.indexOf(QLatin1Char('.'));
107 const QStringView targetName = dotIdx != -1 ? propValue.left(dotIdx) : propValue;
108 if (targetName.isEmpty())
109 continue;
110
111 for (qsizetype j = 0; j < end; ++j) {
112 if (j != i && doc->stringAt(nodes[j]->nameIndex()) == targetName) {
113 edges[i] = j;
114 break;
115 }
116 }
117 }
118
119 // Simple DFS-based topological sort
120 for (qsizetype i = 0, end = nodes.size(); i < end; ++i) {
121 // Skip already inserted nodes
122 if (nodes[i] == nullptr)
123 continue;
124
125 // Follow the dependency chain to find the root.
126 QVarLengthArray<qsizetype, 8> chain;
127 for (qsizetype j = edges[i]; j != -1 && nodes[j]; j = edges[j]) {
128 if (!chain.contains(j)) {
129 chain.append(j);
130 continue;
131 }
132
133 QDuplicateTracker<QString> aliasNames;
134 for (qsizetype duplicate : chain) {
135 const QString name = doc->stringAt(nodes[duplicate]->nameIndex());
136 if (aliasNames.hasSeen(name))
137 continue;
138 const QV4::CompiledData::Location &location = nodes[duplicate]->location();
139 QQmlJS::DiagnosticMessage error;
140 error.loc.startLine = location.line();
141 error.loc.startColumn = location.column();
142 error.loc.offset = QQmlJS::SourceLocation::offsetFrom(doc->code, location.line(),
143 location.column());
144 error.message = QStringLiteral("Alias \"%1\" is part of an alias cycle").arg(name);
145 error.type = QQmlJS::DiagnosticCategory::AliasCycle;
146 errors->append(std::move(error));
147 }
148 return;
149 }
150
151 // Emit in reverse (dependency first)
152 for (qsizetype k = chain.size() - 1; k >= 0; --k)
153 ordered.append(std::exchange(nodes[chain[k]], nullptr));
154 ordered.append(std::exchange(nodes[i], nullptr));
155 }
156
157 // Apply the sorted order to the alias list.
158 setFirstAlias(ordered[0]);
159
160 for (qsizetype i = 0, end = ordered.size() - 1; i < end; ++i)
161 ordered[i]->next = ordered[i + 1];
162 ordered.last()->next = nullptr;
163 if (defaultPropertyAlias) {
164 auto it = std::find(ordered.constBegin(), ordered.constEnd(), defaultPropertyAlias);
165 indexOfDefaultPropertyOrAlias = std::distance(ordered.constBegin(), it);
166 }
167}
168
169bool Parameter::initType(
170 QV4::CompiledData::ParameterType *paramType,
171 const QString &typeName, int typeNameIndex,
172 QV4::CompiledData::ParameterType::Flag listFlag)
173{
174 auto builtinType = stringToBuiltinType(typeName);
175 if (builtinType == QV4::CompiledData::CommonType::Invalid) {
176 if (typeName.isEmpty()) {
177 paramType->set(listFlag, 0);
178 return false;
179 }
180 Q_ASSERT(quint32(typeNameIndex) < (1u << 31));
181 paramType->set(listFlag, typeNameIndex);
182 } else {
183 Q_ASSERT(quint32(builtinType) < (1u << 31));
184 paramType->set(listFlag | QV4::CompiledData::ParameterType::Common,
185 static_cast<quint32>(builtinType));
186 }
187 return true;
188}
189
190QV4::CompiledData::CommonType Parameter::stringToBuiltinType(const QString &typeName)
191{
192 static const struct TypeNameToType {
193 const char *name;
194 size_t nameLength;
195 QV4::CompiledData::CommonType type;
196 } propTypeNameToTypes[] = {
197 { "void", strlen("void"), QV4::CompiledData::CommonType::Void },
198 { "int", strlen("int"), QV4::CompiledData::CommonType::Int },
199 { "bool", strlen("bool"), QV4::CompiledData::CommonType::Bool },
200 { "double", strlen("double"), QV4::CompiledData::CommonType::Real },
201 { "real", strlen("real"), QV4::CompiledData::CommonType::Real },
202 { "string", strlen("string"), QV4::CompiledData::CommonType::String },
203 { "url", strlen("url"), QV4::CompiledData::CommonType::Url },
204 { "date", strlen("date"), QV4::CompiledData::CommonType::DateTime },
205 { "regexp", strlen("regexp"), QV4::CompiledData::CommonType::RegExp },
206 { "rect", strlen("rect"), QV4::CompiledData::CommonType::Rect },
207 { "point", strlen("point"), QV4::CompiledData::CommonType::Point },
208 { "size", strlen("size"), QV4::CompiledData::CommonType::Size },
209 { "variant", strlen("variant"), QV4::CompiledData::CommonType::Var },
210 { "var", strlen("var"), QV4::CompiledData::CommonType::Var }
211 };
212 static const int propTypeNameToTypesCount = sizeof(propTypeNameToTypes) /
213 sizeof(propTypeNameToTypes[0]);
214
215 for (int typeIndex = 0; typeIndex < propTypeNameToTypesCount; ++typeIndex) {
216 const TypeNameToType *t = propTypeNameToTypes + typeIndex;
217 if (typeName == QLatin1String(t->name, static_cast<int>(t->nameLength))) {
218 return t->type;
219 }
220 }
221 return QV4::CompiledData::CommonType::Invalid;
222}
223
224void Object::init(QQmlJS::MemoryPool *pool, int typeNameIndex, int idIndex,
225 const QV4::CompiledData::Location &loc)
226{
227 Q_ASSERT(loc.line() > 0 && loc.column() > 0);
228 inheritedTypeNameIndex = typeNameIndex;
229 location = loc;
230 idNameIndex = idIndex;
231 indexOfDefaultPropertyOrAlias = -1;
232 defaultPropertyIsAlias = false;
233 isComponent = false;
234 flags = QV4::CompiledData::Object::NoFlag;
235 properties = pool->New<PoolList<Property> >();
236 aliases = pool->New<PoolList<Alias> >();
237 qmlEnums = pool->New<PoolList<Enum>>();
238 qmlSignals = pool->New<PoolList<Signal> >();
239 bindings = pool->New<PoolList<Binding> >();
240 functions = pool->New<PoolList<Function> >();
241 functionsAndExpressions = pool->New<PoolList<CompiledFunctionOrExpression> >();
242 inlineComponents = pool->New<PoolList<InlineComponent>>();
243 requiredPropertyExtraDatas = pool->New<PoolList<RequiredPropertyExtraData>>();
244 declarationsOverride = nullptr;
245}
246
247bool IRBuilder::sanityCheckFunctionNames(Object *obj)
248{
249#define EMIT_COMPILE_EXCEPTION(...)
250 do {
251 COMPILE_EXCEPTION(__VA_ARGS__);
252 success = false;
253 } while (false);
254
255 bool success = true;
256 QSet<int> functionNames;
257 for (auto functionit = obj->functionsBegin(); functionit != obj->functionsEnd(); ++functionit) {
258 Function *f = functionit.ptr;
259 QQmlJS::SourceLocation errorLocation;
260 errorLocation.startLine = f->location.line();
261 errorLocation.startColumn = f->location.column();
262 const QString name = stringAt(f->nameIndex);
263 if (f->isQmlFunction) {
264 if (functionNames.contains(f->nameIndex)) {
266 errorLocation,
267 tr("Duplicated method name \"%1\", \"%1\" is already a method.").arg(name),
268 DiagnosticCategory::DuplicatedName);
269 } else {
270 functionNames.insert(f->nameIndex);
271 }
272 }
273
274 for (auto signalit = obj->signalsBegin(); signalit != obj->signalsEnd(); ++signalit) {
275 QmlIR::Signal *s = signalit.ptr;
276 if (s->nameIndex == f->nameIndex) {
278 errorLocation,
279 tr("Duplicated method name \"%1\", \"%1\" is already a signal.").arg(name),
280 DiagnosticCategory::DuplicatedName);
281 }
282 }
283
284 Q_ASSERT(!f->isQmlFunction || !name.isEmpty());
285 if (!name.isEmpty() && name.at(0).isUpper()) {
286 EMIT_COMPILE_EXCEPTION(errorLocation,
287 tr("Method names cannot begin with an upper case letter"));
288 }
289 if (QV4::Compiler::Codegen::isNameGlobal(name))
290 EMIT_COMPILE_EXCEPTION(errorLocation, tr("Illegal method name"));
291 }
292 return success;
293#undef EMIT_COMPILE_EXCEPTION
294}
295
296QString Object::appendEnum(Enum *enumeration)
297{
298 Object *target = declarationsOverride;
299 if (!target)
300 target = this;
301
302 for (Enum *e = qmlEnums->first; e; e = e->next) {
303 if (e->nameIndex == enumeration->nameIndex)
304 return tr("Duplicate scoped enum name");
305 }
306
307 target->qmlEnums->append(enumeration);
308 return QString(); // no error
309}
310
311QString Object::appendSignal(Signal *signal)
312{
313 Object *target = declarationsOverride;
314 if (!target)
315 target = this;
316
317 for (Signal *s = qmlSignals->first; s; s = s->next) {
318 if (s->nameIndex == signal->nameIndex)
319 return tr("Duplicated signal name \"%1\", \"%1\" is already a signal.");
320 }
321
322 target->qmlSignals->append(signal);
323 return QString(); // no error
324}
325
326QString Object::appendProperty(Property *prop, const QString &propertyName, bool isDefaultProperty,
327 const QQmlJS::SourceLocation &defaultToken,
328 QQmlJS::SourceLocation *errorLocation,
329 QQmlJS::DiagnosticCategory *errorCategory)
330{
331 Object *target = declarationsOverride;
332 if (!target)
333 target = this;
334
335 for (Property *p = target->properties->first; p; p = p->next)
336 if (p->nameIndex() == prop->nameIndex()) {
337 *errorCategory = DiagnosticCategory::DuplicatedName;
338 return tr("Duplicated property name \"%1\", \"%1\" is already a property.")
339 .arg(propertyName);
340 }
341
342 for (Alias *a = target->aliases->first; a; a = a->next)
343 if (a->nameIndex() == prop->nameIndex()) {
344 *errorCategory = DiagnosticCategory::DuplicatedName;
345 return tr("Duplicated property name \"%1\", \"%1\" is already an alias.")
346 .arg(propertyName);
347 }
348
349 if (propertyName.constData()->isUpper())
350 return tr("Property names cannot begin with an upper case letter");
351
352 const int index = target->properties->append(prop);
353 if (isDefaultProperty) {
354 if (target->indexOfDefaultPropertyOrAlias != -1) {
355 *errorLocation = defaultToken;
356 *errorCategory = DiagnosticCategory::DuplicatedName;
357 return tr("Duplicate default property");
358 }
359 target->indexOfDefaultPropertyOrAlias = index;
360 }
361 return QString(); // no error
362}
363
364QString Object::appendAlias(Alias *alias, const QString &aliasName, bool isDefaultProperty, const QQmlJS::SourceLocation &defaultToken, QQmlJS::SourceLocation *errorLocation)
365{
366 Object *target = declarationsOverride;
367 if (!target)
368 target = this;
369
370 const auto aliasWithSameName = std::find_if(target->aliases->begin(), target->aliases->end(), [&alias](const Alias &targetAlias){
371 return targetAlias.nameIndex() == alias->nameIndex();
372 });
373 if (aliasWithSameName != target->aliases->end())
374 return tr("Duplicate alias name");
375
376 const auto aliasSameAsProperty = std::find_if(target->properties->begin(), target->properties->end(), [&alias](const Property &targetProp){
377 return targetProp.nameIndex() == alias->nameIndex();
378 });
379
380 if (aliasSameAsProperty != target->properties->end())
381 return tr("Alias has same name as existing property");
382
383 if (aliasName.constData()->isUpper())
384 return tr("Alias names cannot begin with an upper case letter");
385
386 const int index = target->aliases->append(alias);
387
388 if (isDefaultProperty) {
389 if (target->indexOfDefaultPropertyOrAlias != -1) {
390 *errorLocation = defaultToken;
391 return tr("Duplicate default property");
392 }
393 target->indexOfDefaultPropertyOrAlias = index;
394 target->defaultPropertyIsAlias = true;
395 }
396
397 return QString(); // no error
398}
399
400void Object::appendFunction(QmlIR::Function *f)
401{
402 // Unlike properties, a function definition inside a grouped property does not go into
403 // the surrounding object. It's been broken since the Qt 5 era, and the semantics
404 // seems super confusing, so it wouldn't make sense to support that.
405 Q_ASSERT(!declarationsOverride);
406 functions->append(f);
407}
408
409void Object::appendInlineComponent(InlineComponent *ic)
410{
411 inlineComponents->append(ic);
412}
413
414void Object::appendRequiredPropertyExtraData(RequiredPropertyExtraData *extraData)
415{
416 requiredPropertyExtraDatas->append(extraData);
417}
418
419QString Object::appendBinding(Binding *b, bool isListBinding)
420{
421 const bool bindingToDefaultProperty = (b->propertyNameIndex == quint32(0));
422 if (!isListBinding
423 && !bindingToDefaultProperty
424 && b->type() != QV4::CompiledData::Binding::Type_GroupedProperty
425 && b->type() != QV4::CompiledData::Binding::Type_AttachedProperty
426 && !b->hasFlag(QV4::CompiledData::Binding::IsOnAssignment)) {
427 Binding *existing = findBinding(b->propertyNameIndex);
428 if (existing
429 && existing->type() != QV4::CompiledData::Binding::Type_GroupedProperty
430 && existing->type() != QV4::CompiledData::Binding::Type_AttachedProperty
431 && !existing->hasFlag(QV4::CompiledData::Binding::IsOnAssignment)) {
432 return tr("Duplicate binding on property '%1'");
433 }
434 }
435 if (bindingToDefaultProperty)
436 bindings->append(b);
437 else
438 bindings->prepend(b);
439 return QString(); // no error
440}
441
442Binding *Object::findBinding(quint32 nameIndex) const
443{
444 for (Binding *b = bindings->first; b; b = b->next)
445 if (b->propertyNameIndex == nameIndex)
446 return b;
447 return nullptr;
448}
449
450QString Object::bindingAsString(Document *doc, int scriptIndex) const
451{
452 CompiledFunctionOrExpression *foe = functionsAndExpressions->slowAt(scriptIndex);
453 QQmlJS::AST::Node *node = foe->node;
454 if (QQmlJS::AST::ExpressionStatement *exprStmt = QQmlJS::AST::cast<QQmlJS::AST::ExpressionStatement *>(node))
455 node = exprStmt->expression;
456 QQmlJS::SourceLocation start = node->firstSourceLocation();
457 QQmlJS::SourceLocation end = node->lastSourceLocation();
458 return doc->code.mid(start.offset, end.offset + end.length - start.offset);
459}
460
461QStringList Signal::parameterStringList(const QV4::Compiler::StringTableGenerator *stringPool) const
462{
463 QStringList result;
464 result.reserve(parameters->count);
465 for (Parameter *param = parameters->first; param; param = param->next)
466 result << stringPool->stringForIndex(param->nameIndex);
467 return result;
468}
469
470Document::Document(const QString &fileName, const QString &finalUrl,
471 QV4::Moth::DebugInstructionPass debugInstructionPass)
472 : jsModule(fileName, finalUrl, debugInstructionPass)
473 , program(nullptr)
474 , jsGenerator(&jsModule)
475{
476}
477
478bool Document::parse(const QString &sourceCode, const QString &url,
479 QV4::Compiler::CodegenWarningInterface *wInterface)
480{
481 const QQmlJS::Parser::Result parsed = QQmlJS::Parser::parseCode(
482 &jsParserEngine, sourceCode, QQmlJS::Parser::Goal::QmlDocument);
483
484 bool hasErrors = false;
485 for (const QQmlJS::DiagnosticMessage &message : parsed.diagnosticMessages) {
486 if (message.isWarning()) {
487 wInterface->reportParserWarnings(url, message.loc, message.message);
488 } else {
489 wInterface->reportCompileError(url, message);
490 hasErrors = true;
491 }
492 }
493
494 if (!parsed.success || hasErrors)
495 return false;
496
497 code = sourceCode;
498 program = QQmlJS::AST::cast<QQmlJS::AST::UiProgram *>(parsed.rootNode);
499 Q_ASSERT(program);
500 return true;
501}
502
503ScriptDirectivesCollector::ScriptDirectivesCollector(Document *doc)
504 : document(doc)
505 , engine(&doc->jsParserEngine)
506 , jsGenerator(&doc->jsGenerator)
507{
508}
509
510void ScriptDirectivesCollector::pragmaLibrary()
511{
512 document->jsModule.unitFlags |= QV4::CompiledData::Unit::IsSharedLibrary;
513}
514
515void ScriptDirectivesCollector::importFile(const QString &jsfile, const QString &module, int lineNumber, int column)
516{
517 QV4::CompiledData::Import *import = engine->pool()->New<QV4::CompiledData::Import>();
518 import->type = QV4::CompiledData::Import::ImportScript;
519 import->uriIndex = jsGenerator->registerString(jsfile);
520 import->qualifierIndex = jsGenerator->registerString(module);
521 import->location.set(lineNumber, column);
522 document->imports << import;
523}
524
525void ScriptDirectivesCollector::importModule(const QString &uri, const QString &version, const QString &module, int lineNumber, int column)
527 QV4::CompiledData::Import *import = engine->pool()->New<QV4::CompiledData::Import>();
528 import->type = QV4::CompiledData::Import::ImportLibrary;
529 import->uriIndex = jsGenerator->registerString(uri);
530 import->version = IRBuilder::extractVersion(version);
531 import->qualifierIndex = jsGenerator->registerString(module);
532 import->location.set(lineNumber, column);
533 document->imports << import;
535
536IRBuilder::IRBuilder(FailureMode failureMode)
537 : _object(nullptr)
538 , _propertyDeclaration(nullptr)
539 , pool(nullptr)
540 , jsGenerator(nullptr)
541 , m_failureMode(failureMode)
542{
543}
544
545bool IRBuilder::generateFromQml(Document *output,
546 QV4::Compiler::CodegenWarningInterface *wInterface)
547{
548 Q_ASSERT(output->program);
549 QQmlJS::AST::UiProgram *program = output->program;
550 const QString &code = output->code;
551
552 qSwap(_imports, output->imports);
553 qSwap(_pragmas, output->pragmas);
554 qSwap(_objects, output->objects);
555 this->pool = output->jsParserEngine.pool();
556 this->jsGenerator = &output->jsGenerator;
557
558 Q_ASSERT(registerString(QString()) == emptyStringIndex);
559
560 sourceCode = code;
561
562 auto reportErrors = qScopeGuard([parserWarnings = errors.size(), this, wInterface] {
563 wInterface->reportSyntaxWarnings(QSpan(errors.begin() + parserWarnings, errors.end()));
564 });
565 accept(program->headers);
566
567 if (program->members->next) {
568 QQmlJS::SourceLocation loc = program->members->next->firstSourceLocation();
569 recordError(loc, QCoreApplication::translate("QQmlParser", "Unexpected object definition"));
570 if (!shouldContinue())
571 return false;
572 }
573
574 QQmlJS::AST::UiObjectDefinition *rootObject = QQmlJS::AST::cast<QQmlJS::AST::UiObjectDefinition*>(program->members->member);
575 Q_ASSERT(rootObject);
576 int rootObjectIndex = -1;
577 if (defineQMLObject(&rootObjectIndex, rootObject)) {
578 Q_ASSERT(rootObjectIndex == 0);
579 }
580
581 qSwap(_imports, output->imports);
582 qSwap(_pragmas, output->pragmas);
583 qSwap(_objects, output->objects);
584
585 for (Object *object: std::as_const(output->objects)) {
586 object->simplifyRequiredProperties();
587
588 // Reorder aliases so that same-object dependencies come before their
589 // dependents. This later ensures the property cache ordering matches
590 // the alias table, which the runtime relies on.
591 object->sortAliasDependencies(output, &errors);
592 }
593
594 return errors.isEmpty();
595}
596
597bool IRBuilder::visit(QQmlJS::AST::UiProgram *)
598{
599 Q_ASSERT(!"should not happen");
600 return false;
601}
602
603bool IRBuilder::visit(QQmlJS::AST::UiObjectDefinition *node)
604{
605 // The grammar can't distinguish between two different definitions here:
606 // Item { ... }
607 // versus
608 // font { ... }
609 // The former is a new binding with no property name and "Item" as type name,
610 // and the latter is a binding to the font property with no type name but
611 // only initializer.
612
613 QQmlJS::AST::UiQualifiedId *lastId = node->qualifiedTypeNameId;
614 while (lastId->next)
615 lastId = lastId->next;
616 bool isType = lastId->name.data()->isUpper();
617 if (isType) {
618 int idx = 0;
619 if (!defineQMLObject(&idx, node))
620 return false;
621 const QQmlJS::SourceLocation nameLocation = node->qualifiedTypeNameId->identifierToken;
622 appendBinding(nameLocation, nameLocation, emptyStringIndex, idx);
623 } else {
624 int idx = 0;
625 const QQmlJS::SourceLocation location = node->qualifiedTypeNameId->firstSourceLocation();
626 if (!defineQMLObject(
627 &idx, /*qualfied type name id*/nullptr,
628 { location.startLine, location.startColumn }, node->initializer,
629 /*declarations should go here*/_object)) {
630 return false;
631 }
632 appendBinding(node->qualifiedTypeNameId, idx);
633 }
634 return false;
635}
636
637bool IRBuilder::visit(QQmlJS::AST::UiInlineComponent *ast)
638{
639 int idx = -1;
640 if (insideInlineComponent) {
641 recordError(ast->firstSourceLocation(), QLatin1String("Nested inline components are not supported"));
642 if (!shouldContinue())
643 return false;
644 }
645 if (inlineComponentsNames.contains(ast->name.toString())) {
646 recordError(ast->firstSourceLocation(),
647 QLatin1String("Inline component names must be unique per file"),
648 QQmlJS::DiagnosticCategory::DuplicateInlineComponent);
649 if (!shouldContinue())
650 return false;
651 } else {
652 inlineComponentsNames.insert(ast->name.toString());
653 }
654 {
655 QScopedValueRollback<bool> rollBack {insideInlineComponent, true};
656 if (!defineQMLObject(&idx, ast->component))
657 return false;
658 }
659 Q_ASSERT(idx > 0);
660 Object* definedObject = _objects.at(idx);
661 definedObject->flags |= QV4::CompiledData::Object::IsInlineComponentRoot;
662 definedObject->flags |= QV4::CompiledData::Object::IsPartOfInlineComponent;
663 auto inlineComponent = New<InlineComponent>();
664 inlineComponent->nameIndex = registerString(ast->name.toString());
665 inlineComponent->objectIndex = idx;
666 auto location = ast->firstSourceLocation();
667 inlineComponent->location.set(location.startLine, location.startColumn);
668 _object->appendInlineComponent(inlineComponent);
669 return false;
670}
671
672bool IRBuilder::visit(QQmlJS::AST::UiObjectBinding *node)
673{
674 int idx = 0;
675 const QQmlJS::SourceLocation location = node->qualifiedTypeNameId->firstSourceLocation();
676 if (!defineQMLObject(&idx, node->qualifiedTypeNameId,
677 { location.startLine, location.startColumn }, node->initializer)) {
678 return false;
679 }
680 appendBinding(node->qualifiedId, idx, node->hasOnToken);
681 return false;
682}
683
684bool IRBuilder::visit(QQmlJS::AST::UiScriptBinding *node)
685{
686 appendBinding(node->qualifiedId, node->statement, node);
687 return false;
688}
689
690bool IRBuilder::visit(QQmlJS::AST::UiArrayBinding *node)
691{
692 const QQmlJS::SourceLocation qualifiedNameLocation = node->qualifiedId->identifierToken;
693 Object *object = nullptr;
694 QQmlJS::AST::UiQualifiedId *name = node->qualifiedId;
695 if (!resolveQualifiedId(&name, &object))
696 return false;
697
698 qSwap(_object, object);
699
700 const int propertyNameIndex = registerString(name->name.toString());
701
702 if (bindingsTarget()->findBinding(propertyNameIndex) != nullptr) {
703 recordError(name->identifierToken,
704 "Duplicate binding on property '%1'"_L1.arg(stringAt(propertyNameIndex)),
705 QQmlJS::DiagnosticCategory::DuplicatePropertyBinding);
706 if (!shouldContinue())
707 return false;
708 }
709
710 QVarLengthArray<QQmlJS::AST::UiArrayMemberList *, 16> memberList;
711 QQmlJS::AST::UiArrayMemberList *member = node->members;
712 while (member) {
713 memberList.append(member);
714 member = member->next;
715 }
716 for (int i = memberList.size() - 1; i >= 0; --i) {
717 member = memberList.at(i);
718 QQmlJS::AST::UiObjectDefinition *def = QQmlJS::AST::cast<QQmlJS::AST::UiObjectDefinition*>(member->member);
719
720 int idx = 0;
721 if (!defineQMLObject(&idx, def))
722 return false;
723 appendBinding(qualifiedNameLocation, name->identifierToken, propertyNameIndex, idx, /*isListItem*/ true);
724 }
725
726 qSwap(_object, object);
727 return false;
728}
729
730void IRBuilder::accept(QQmlJS::AST::Node *node)
731{
732 QQmlJS::AST::Node::accept(node, this);
733}
734
735bool IRBuilder::defineQMLObject(
736 int *objectIndex, QQmlJS::AST::UiQualifiedId *qualifiedTypeNameId,
737 const QV4::CompiledData::Location &location, QQmlJS::AST::UiObjectInitializer *initializer,
738 Object *declarationsOverride)
739{
740 if (QQmlJS::AST::UiQualifiedId *lastName = qualifiedTypeNameId) {
741 while (lastName->next)
742 lastName = lastName->next;
743 if (!lastName->name.constData()->isUpper()) {
744 recordError(lastName->identifierToken, tr("Expected type name"));
745 if (!shouldContinue())
746 return false;
747 }
748 }
749
750 Object *obj = New<Object>();
751
752 _objects.append(obj);
753 *objectIndex = _objects.size() - 1;
754 qSwap(_object, obj);
755
756 _object->init(pool, registerString(asString(qualifiedTypeNameId)), emptyStringIndex, location);
757 _object->declarationsOverride = declarationsOverride;
758 if (insideInlineComponent) {
759 _object->flags |= QV4::CompiledData::Object::IsPartOfInlineComponent;
760 }
761
762 // A new object is also a boundary for property declarations.
763 Property *declaration = nullptr;
764 qSwap(_propertyDeclaration, declaration);
765
766 accept(initializer);
767
768 qSwap(_propertyDeclaration, declaration);
769
770 qSwap(_object, obj);
771
772 if (!errors.isEmpty() && !shouldContinue())
773 return false;
774
775 if (!sanityCheckFunctionNames(obj))
776 return false;
777
778 return true;
779}
780
781bool IRBuilder::visit(QQmlJS::AST::UiImport *node)
782{
783 QString uri;
784 QV4::CompiledData::Import *import = New<QV4::CompiledData::Import>();
785
786 if (!node->fileName.isNull()) {
787 uri = node->fileName.toString();
788
789 if (uri.endsWith(QLatin1String(".js")) || uri.endsWith(QLatin1String(".mjs"))) {
790 import->type = QV4::CompiledData::Import::ImportScript;
791 } else {
792 import->type = QV4::CompiledData::Import::ImportFile;
793 }
794 } else {
795 import->type = QV4::CompiledData::Import::ImportLibrary;
796 uri = asString(node->importUri);
797 }
798
799 import->qualifierIndex = emptyStringIndex;
800
801 // Qualifier
802 if (!node->importId.isNull()) {
803 QString qualifier = node->importId.toString();
804 if (!qualifier.at(0).isUpper()) {
805 recordError(
806 node->importIdToken,
807 QCoreApplication::translate(
808 "QQmlParser",
809 "Invalid import qualifier '%1': must start with an uppercase letter")
810 .arg(qualifier),
811 DiagnosticCategory::Import);
812 if (!shouldContinue())
813 return false;
814 }
815 if (qualifier == QLatin1String("Qt")) {
816 recordError(node->importIdToken, QCoreApplication::translate("QQmlParser","Reserved name \"Qt\" cannot be used as an qualifier"));
817 if (!shouldContinue())
818 return false;
819 }
820 import->qualifierIndex = registerString(qualifier);
821
822 // Check for script qualifier clashes
823 bool isScript = import->type == QV4::CompiledData::Import::ImportScript;
824 for (int ii = 0; ii < _imports.size(); ++ii) {
825 const QV4::CompiledData::Import *other = _imports.at(ii);
826 bool otherIsScript = other->type == QV4::CompiledData::Import::ImportScript;
827
828 if ((isScript || otherIsScript) && qualifier == jsGenerator->stringForIndex(other->qualifierIndex)) {
829 recordError(node->importIdToken, QCoreApplication::translate("QQmlParser","Script import qualifiers must be unique."));
830 if (!shouldContinue())
831 return false;
832 }
833 }
834
835 } else if (import->type == QV4::CompiledData::Import::ImportScript) {
836 recordError(node->fileNameToken, QCoreApplication::translate("QQmlParser","Script import requires a qualifier"));
837 if (!shouldContinue())
838 return false;
839 }
840
841 if (node->version) {
842 import->version = node->version->version;
843 } else {
844 // Otherwise initialize the major and minor version to invalid to signal "latest".
845 import->version = QTypeRevision();
846 }
847
848 import->location.set(node->importToken.startLine, node->importToken.startColumn);
849
850 import->uriIndex = registerString(uri);
851
852 _imports.append(import);
853
854 return false;
855}
856
857
858template<typename Argument>
860{
861 static bool run(IRBuilder *builder, QQmlJS::AST::UiPragma *node, Pragma *pragma)
862 {
863 Q_ASSERT(builder);
864 Q_ASSERT(node);
865 Q_ASSERT(pragma);
866
867 bool isValid = true;
868 if (!isUnique(builder)) {
869 builder->recordError(
870 node->pragmaToken, QCoreApplication::translate(
871 "QQmlParser", "Multiple %1 pragmas found").arg(name()));
872 if (!builder->shouldContinue())
873 return false;
874 isValid = false;
875 }
876
877 pragma->type = type();
878
879 if (QQmlJS::AST::UiPragmaValueList *bad = assign(pragma, node->values)) {
880 builder->recordError(
881 node->pragmaToken, QCoreApplication::translate(
882 "QQmlParser", "Unknown %1 '%2' in pragma").arg(name(), bad->value));
883 if (!builder->shouldContinue())
884 return false;
885 isValid = false;
886 }
887
888 return isValid;
889 }
890
891private:
892 static constexpr Pragma::PragmaType type()
893 {
900 } else if constexpr (std::is_same_v<Argument, Pragma::NativeMethodBehaviorValue>) {
902 } else if constexpr (std::is_same_v<Argument, Pragma::ValueTypeBehaviorValue>) {
904 }
905
907 }
908
909 template<typename F>
912 {
913 for (QQmlJS::AST::UiPragmaValueList *i = input; i; i = i->next) {
914 if (!process(i->value))
915 return i;
916 }
917 return nullptr;
918 }
919
922 {
923 // We could use QMetaEnum here to make the code more compact,
924 // but it's probably more expensive.
925
928 if (value == "Unbound"_L1) {
930 return true;
931 }
932 if (value == "Bound"_L1) {
934 return true;
935 }
936 return false;
937 });
940 if (value == "Append"_L1) {
942 return true;
943 }
944 if (value == "Replace"_L1) {
946 return true;
947 }
948 if (value == "ReplaceIfNotDefault"_L1) {
950 return true;
951 }
952 return false;
953 });
956 if (value == "Ignored"_L1) {
958 return true;
959 }
960 if (value == "Enforced"_L1) {
962 return true;
963 }
964 return false;
965 });
966 } else if constexpr (std::is_same_v<Argument, Pragma::NativeMethodBehaviorValue>) {
968 if (value == "AcceptThisObject"_L1) {
970 return true;
971 }
972 if (value == "RejectThisObject"_L1) {
974 return true;
975 }
976 return false;
977 });
978 } else if constexpr (std::is_same_v<Argument, Pragma::ValueTypeBehaviorValue>) {
981 const auto setFlag = [pragma](Pragma::ValueTypeBehaviorValue flag, bool value) {
984 .setFlag(flag, value).toInt();
985 };
986
987 if (value == "Reference"_L1) {
988 setFlag(Pragma::Copy, false);
989 return true;
990 }
991 if (value == "Copy"_L1) {
992 setFlag(Pragma::Copy, true);
993 return true;
994 }
995
996 if (value == "Inaddressable"_L1) {
997 setFlag(Pragma::Addressable, false);
998 return true;
999 }
1000 if (value == "Addressable"_L1) {
1001 setFlag(Pragma::Addressable, true);
1002 return true;
1003 }
1004
1005 if (value == "Inassertable"_L1) {
1006 setFlag(Pragma::Assertable, false);
1007 return true;
1008 }
1009 if (value == "Assertable"_L1) {
1010 setFlag(Pragma::Assertable, true);
1011 return true;
1012 }
1013
1014 return false;
1015 });
1016 }
1017
1018 Q_UNREACHABLE_RETURN(nullptr);
1019 }
1020
1021 static bool isUnique(const IRBuilder *builder)
1022 {
1023 for (const Pragma *prev : builder->_pragmas) {
1024 if (prev->type == type())
1025 return false;
1026 }
1027 return true;
1028 };
1029
1030 static QLatin1StringView name()
1031 {
1032 switch (type()) {
1033 case Pragma::ListPropertyAssignBehavior:
1034 return "list property assign behavior"_L1;
1035 case Pragma::ComponentBehavior:
1036 return "component behavior"_L1;
1037 case Pragma::FunctionSignatureBehavior:
1038 return "function signature behavior"_L1;
1039 case Pragma::NativeMethodBehavior:
1040 return "native method behavior"_L1;
1041 case Pragma::ValueTypeBehavior:
1042 return "value type behavior"_L1;
1043 default:
1044 break;
1045 }
1046 Q_UNREACHABLE_RETURN(QLatin1StringView());
1047 }
1048};
1049
1050bool IRBuilder::visit(QQmlJS::AST::UiPragma *node)
1051{
1052 Pragma *pragma = New<Pragma>();
1053 bool isValid = true;
1054
1055 if (!node->name.isNull()) {
1056 if (node->name == "Singleton"_L1) {
1057 pragma->type = Pragma::Singleton;
1058 } else if (node->name == "Strict"_L1) {
1059 pragma->type = Pragma::Strict;
1060 } else if (node->name == "ComponentBehavior"_L1) {
1061 if (!PragmaParser<Pragma::ComponentBehaviorValue>::run(this, node, pragma)) {
1062 if (!shouldContinue())
1063 return false;
1064 isValid = false;
1065 }
1066 } else if (node->name == "ListPropertyAssignBehavior"_L1) {
1067 if (!PragmaParser<Pragma::ListPropertyAssignBehaviorValue>::run(this, node, pragma)) {
1068 if (!shouldContinue())
1069 return false;
1070 isValid = false;
1071 }
1072 } else if (node->name == "FunctionSignatureBehavior"_L1) {
1073 if (!PragmaParser<Pragma::FunctionSignatureBehaviorValue>::run(this, node, pragma)) {
1074 if (!shouldContinue())
1075 return false;
1076 isValid = false;
1077 }
1078 } else if (node->name == "NativeMethodBehavior"_L1) {
1079 if (!PragmaParser<Pragma::NativeMethodBehaviorValue>::run(this, node, pragma)) {
1080 if (!shouldContinue())
1081 return false;
1082 isValid = false;
1083 }
1084 } else if (node->name == "ValueTypeBehavior"_L1) {
1085 if (!PragmaParser<Pragma::ValueTypeBehaviorValue>::run(this, node, pragma)) {
1086 if (!shouldContinue())
1087 return false;
1088 isValid = false;
1089 }
1090 } else if (node->name == "Translator"_L1) {
1091 pragma->type = Pragma::Translator;
1092 pragma->translationContextIndex = registerString(node->values->value.toString());
1093
1094 } else {
1095 recordError(node->pragmaToken, QCoreApplication::translate(
1096 "QQmlParser", "Unknown pragma '%1'").arg(node->name));
1097 if (!shouldContinue())
1098 return false;
1099 isValid = false;
1100 }
1101 } else {
1102 recordError(node->pragmaToken, QCoreApplication::translate(
1103 "QQmlParser", "Empty pragma found"));
1104 if (!shouldContinue())
1105 return false;
1106 isValid = false;
1107 }
1108
1109 if (isValid) {
1110 pragma->location.set(node->pragmaToken.startLine, node->pragmaToken.startColumn);
1111 _pragmas.append(pragma);
1112 }
1113
1114 return false;
1115}
1116
1117static QStringList astNodeToStringList(QQmlJS::AST::Node *node)
1118{
1119 if (node->kind == QQmlJS::AST::Node::Kind_IdentifierExpression) {
1120 QString name =
1121 static_cast<QQmlJS::AST::IdentifierExpression *>(node)->name.toString();
1122 return QStringList() << name;
1123 } else if (node->kind == QQmlJS::AST::Node::Kind_FieldMemberExpression) {
1124 QQmlJS::AST::FieldMemberExpression *expr = static_cast<QQmlJS::AST::FieldMemberExpression *>(node);
1125
1126 QStringList rv = astNodeToStringList(expr->base);
1127 if (rv.isEmpty())
1128 return rv;
1129 rv.append(expr->name.toString());
1130 return rv;
1131 }
1132 return QStringList();
1133}
1134
1135bool IRBuilder::visit(QQmlJS::AST::UiEnumDeclaration *node)
1136{
1137 Enum *enumeration = New<Enum>();
1138 bool isValid = true;
1139 QString enumName = node->name.toString();
1140 enumeration->nameIndex = registerString(enumName);
1141
1142 if (enumName.at(0).isLower()) {
1143 COMPILE_EXCEPTION(node->enumToken, tr("Scoped enum names must begin with an upper case letter"));
1144 isValid = false;
1145 }
1146
1147 enumeration->location.set(node->enumToken.startLine, node->enumToken.startColumn);
1148
1149 enumeration->enumValues = New<PoolList<EnumValue>>();
1150
1151 QQmlJS::AST::UiEnumMemberList *e = node->members;
1152 while (e) {
1153 EnumValue *enumValue = New<EnumValue>();
1154 QString member = e->member.toString();
1155 enumValue->nameIndex = registerString(member);
1156 bool isValueValid = true;
1157 if (member.at(0).isLower()) {
1158 COMPILE_EXCEPTION(e->memberToken, tr("Enum names must begin with an upper case letter"));
1159 isValueValid = false;
1160 }
1161
1162 double part;
1163 if (std::modf(e->value, &part) != 0.0) {
1164 COMPILE_EXCEPTION(e->valueToken, tr("Enum value must be an integer"));
1165 isValueValid = false;
1166 }
1167 if (e->value > std::numeric_limits<qint32>::max()
1168 || e->value < std::numeric_limits<qint32>::min()) {
1169 COMPILE_EXCEPTION(e->valueToken, tr("Enum value out of range"));
1170 isValueValid = false;
1171 }
1172 if (isValueValid) {
1173 enumValue->value = e->value;
1174 enumeration->enumValues->append(enumValue);
1175 } else {
1176 isValid = false;
1177 }
1178
1179 e = e->next;
1180 }
1181
1182 QString error;
1183 if (isValid)
1184 error = _object->appendEnum(enumeration);
1185 if (!error.isEmpty()) {
1186 recordError(node->enumToken, error);
1187 if (!shouldContinue())
1188 return false;
1189 }
1190
1191 return false;
1192}
1193
1194
1195bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node)
1196{
1197 if (node->type == QQmlJS::AST::UiPublicMember::Signal) {
1198 Signal *signal = New<Signal>();
1199 bool isValid = true;
1200 const QString signalName = node->name.toString();
1201 signal->nameIndex = registerString(signalName);
1202
1203 QQmlJS::SourceLocation loc = node->typeToken;
1204 signal->location.set(loc.startLine, loc.startColumn);
1205
1206 signal->parameters = New<PoolList<Parameter> >();
1207
1208 QQmlJS::AST::UiParameterList *p = node->parameters;
1209 while (p) {
1210 if (!p->type) {
1211 recordError(node->typeToken, QCoreApplication::translate("QQmlParser","Expected parameter type"));
1212 if (!shouldContinue())
1213 return false;
1214 isValid = false;
1215 p = p->next;
1216 continue;
1217 }
1218
1219 Parameter *param = New<Parameter>();
1220 param->nameIndex = registerString(p->name.toString());
1221 if (!Parameter::initType(
1222 &param->type, [this](const QString &str) { return registerString(str); },
1223 p->type)) {
1224 QString errStr = QCoreApplication::translate("QQmlParser","Invalid signal parameter type: ");
1225 errStr.append(p->type->toString());
1226 recordError(node->typeToken, errStr);
1227 if (!shouldContinue())
1228 return false;
1229 isValid = false;
1230 p = p->next;
1231 continue;
1232 }
1233 signal->parameters->append(param);
1234 p = p->next;
1235 }
1236
1237 for (const QChar &ch : signalName) {
1238 if (ch.isLower())
1239 break;
1240 if (ch.isUpper()) {
1241 COMPILE_EXCEPTION(node->identifierToken,
1242 tr("Signal names cannot begin with an upper case letter"));
1243 isValid = false;
1244 break;
1245 }
1246 }
1247
1248 if (QV4::Compiler::Codegen::isNameGlobal(signalName)) {
1249 COMPILE_EXCEPTION(node->identifierToken, tr("Illegal signal name"));
1250 isValid = false;
1251 }
1252
1253 QString error;
1254 if (isValid)
1255 error = _object->appendSignal(signal);
1256 if (!error.isEmpty()) {
1257 recordError(node->identifierToken, error.arg(stringAt(signal->nameIndex)));
1258 if (!shouldContinue())
1259 return false;
1260 }
1261 } else {
1262 QString memberType = asString(node->memberType);
1263 if (memberType == QLatin1String("alias")) {
1264 return appendAlias(node);
1265 } else {
1266 QStringView name = node->name;
1267 bool isValid = true;
1268
1269 Property *property = New<Property>();
1270 property->setIsReadOnly(node->isReadonly());
1271 property->setIsRequired(node->isRequired());
1272 property->setIsVirtual(node->isVirtual());
1273 property->setIsOverride(node->isOverride());
1274 property->setIsFinal(node->isFinal());
1275
1276 const QV4::CompiledData::CommonType builtinPropertyType
1277 = Parameter::stringToBuiltinType(memberType);
1278 if (builtinPropertyType != QV4::CompiledData::CommonType::Invalid)
1279 property->setCommonType(builtinPropertyType);
1280 else
1281 property->setTypeNameIndex(registerString(memberType));
1282
1283 QStringView typeModifier = node->typeModifier;
1284 if (typeModifier == QLatin1String("list")) {
1285 property->setIsList(true);
1286 } else if (!typeModifier.isEmpty()) {
1287 recordError(node->typeModifierToken, QCoreApplication::translate("QQmlParser","Invalid property type modifier"));
1288 if (!shouldContinue())
1289 return false;
1290 isValid = false;
1291 }
1292
1293 const QString propName = name.toString();
1294 property->setNameIndex(registerString(propName));
1295
1296 QQmlJS::SourceLocation loc = node->firstSourceLocation();
1297 property->location.set(loc.startLine, loc.startColumn);
1298
1299 QQmlJS::SourceLocation errorLocation;
1300 QQmlJS::DiagnosticCategory errorCategory = QQmlJS::DiagnosticCategory::Syntax;
1301 QString error;
1302
1303 if (QV4::Compiler::Codegen::isNameGlobal(propName))
1304 error = tr("Illegal property name");
1305 else if (isValid)
1306 error = _object->appendProperty(property, propName, node->isDefaultMember(),
1307 node->defaultToken(), &errorLocation,
1308 &errorCategory);
1309
1310 if (!error.isEmpty()) {
1311 if (errorLocation.startLine == 0)
1312 errorLocation = node->identifierToken;
1313
1314 recordError(errorLocation, error, errorCategory);
1315 if (!shouldContinue())
1316 return false;
1317 isValid = false;
1318 }
1319
1320 if (isValid) {
1321 qSwap(_propertyDeclaration, property);
1322 if (node->binding) {
1323 // process QML-like initializers (e.g. property Object o: Object {})
1324 QQmlJS::AST::Node::accept(node->binding, this);
1325 } else if (node->statement) {
1326 if (!isRedundantNullInitializerForPropertyDeclaration(_propertyDeclaration,
1327 node->statement)) {
1328 appendBinding(node->identifierToken, node->identifierToken,
1329 _propertyDeclaration->nameIndex(), node->statement, node);
1330 }
1331 }
1332 qSwap(_propertyDeclaration, property);
1333 }
1334 }
1335 }
1336
1337 return false;
1338}
1339
1340void IRBuilder::registerFunctionExpr(QQmlJS::AST::FunctionExpression *fexp, IsQmlFunction isQmlFunction)
1341{
1342 CompiledFunctionOrExpression *foe = New<CompiledFunctionOrExpression>();
1343 foe->node = fexp;
1344 foe->parentNode = fexp;
1345 foe->nameIndex = registerString(fexp->name.toString());
1346 foe->isQmlFunction = isQmlFunction == IsQmlFunction::Yes;
1347 const int index = _object->functionsAndExpressions->append(foe);
1348
1349 Function *f = New<Function>();
1350 QQmlJS::SourceLocation loc = fexp->identifierToken;
1351 f->location.set(loc.startLine, loc.startColumn);
1352 f->index = index;
1353 f->nameIndex = registerString(fexp->name.toString());
1354 f->isQmlFunction = isQmlFunction == IsQmlFunction::Yes;
1355
1356 const auto idGenerator = [this](const QString &str) { return registerString(str); };
1357
1358 Parameter::initType(
1359 &f->returnType, idGenerator,
1360 fexp->typeAnnotation ? fexp->typeAnnotation->type : nullptr);
1361
1362 const QQmlJS::AST::BoundNames formals = fexp->formals ? fexp->formals->formals()
1363 : QQmlJS::AST::BoundNames();
1364 int formalsCount = formals.size();
1365 f->formals.allocate(pool, formalsCount);
1366
1367 int i = 0;
1368 for (const auto &arg : formals) {
1369 Parameter *functionParameter = &f->formals[i];
1370 functionParameter->nameIndex = registerString(arg.id);
1371 Parameter::initType(
1372 &functionParameter->type, idGenerator,
1373 arg.typeAnnotation.isNull() ? nullptr : arg.typeAnnotation->type);
1374 ++i;
1375 }
1376
1377 _object->appendFunction(f);
1378}
1379
1380bool IRBuilder::visit(QQmlJS::AST::UiSourceElement *node)
1381{
1382 if (QQmlJS::AST::FunctionExpression *funDecl = node->sourceElement->asFunctionDefinition()) {
1383 if (_object->declarationsOverride) {
1384 // See Object::appendFunction() for why.
1385 recordError(node->firstSourceLocation(),
1386 QCoreApplication::translate(
1387 "QQmlParser", "Function declaration inside grouped property"));
1388 if (!shouldContinue())
1389 return false;
1390 } else {
1391 registerFunctionExpr(funDecl, IsQmlFunction::Yes);
1392 }
1393 } else {
1394 recordError(node->firstSourceLocation(), QCoreApplication::translate("QQmlParser","JavaScript declaration outside Script element"));
1395 }
1396 return false;
1397}
1398
1399bool IRBuilder::visit(AST::UiRequired *ast)
1400{
1401 auto extraData = New<RequiredPropertyExtraData>();
1402 extraData->nameIndex = registerString(ast->name.toString());
1403 _object->appendRequiredPropertyExtraData(extraData);
1404 return false;
1405}
1406
1407QString IRBuilder::asString(QQmlJS::AST::UiQualifiedId *node)
1408{
1409 QString s;
1410
1411 for (QQmlJS::AST::UiQualifiedId *it = node; it; it = it->next) {
1412 s.append(it->name);
1413
1414 if (it->next)
1415 s.append(QLatin1Char('.'));
1416 }
1417
1418 return s;
1419}
1420
1421QStringView IRBuilder::asStringRef(QQmlJS::AST::Node *node)
1422{
1423 if (!node)
1424 return QStringView();
1425
1426 return textRefAt(node->firstSourceLocation(), node->lastSourceLocation());
1427}
1428
1429QTypeRevision IRBuilder::extractVersion(QStringView string)
1430{
1431 if (string.isEmpty())
1432 return QTypeRevision();
1433
1434 const int dot = string.indexOf(QLatin1Char('.'));
1435 return (dot < 0)
1436 ? QTypeRevision::fromMajorVersion(string.toInt())
1437 : QTypeRevision::fromVersion(string.left(dot).toInt(), string.mid(dot + 1).toInt());
1438}
1439
1440QStringView IRBuilder::textRefAt(const QQmlJS::SourceLocation &first, const QQmlJS::SourceLocation &last) const
1441{
1442 return QStringView(sourceCode).mid(first.offset, last.offset + last.length - first.offset);
1443}
1444
1445void IRBuilder::setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST::Statement *statement, QQmlJS::AST::Node *parentNode)
1446{
1447 QQmlJS::SourceLocation loc = statement->firstSourceLocation();
1448 binding->valueLocation.set(loc.startLine, loc.startColumn);
1449 binding->setType(QV4::CompiledData::Binding::Type_Invalid);
1450 if (_propertyDeclaration && _propertyDeclaration->isReadOnly())
1451 binding->setFlag(QV4::CompiledData::Binding::InitializerForReadOnlyDeclaration);
1452
1453 QQmlJS::AST::ExpressionStatement *exprStmt = QQmlJS::AST::cast<QQmlJS::AST::ExpressionStatement *>(statement);
1454 if (exprStmt) {
1455 QQmlJS::AST::ExpressionNode * const expr = exprStmt->expression;
1456 if (QQmlJS::AST::StringLiteral *lit = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(expr)) {
1457 binding->setType(QV4::CompiledData::Binding::Type_String);
1458 binding->stringIndex = registerString(lit->value.toString());
1459 } else if (QQmlJS::AST::TemplateLiteral *templateLit = QQmlJS::AST::cast<QQmlJS::AST::TemplateLiteral *>(expr);
1460 templateLit && templateLit->hasNoSubstitution) {
1461 // A template literal without substitution is just a string.
1462 // With substitution, it could however be an arbitrarily complex expression
1463 binding->setType(QV4::CompiledData::Binding::Type_String);
1464 binding->stringIndex = registerString(templateLit->value.toString());
1465 } else if (expr->kind == QQmlJS::AST::Node::Kind_TrueLiteral) {
1466 binding->setType(QV4::CompiledData::Binding::Type_Boolean);
1467 binding->value.b = true;
1468 } else if (expr->kind == QQmlJS::AST::Node::Kind_FalseLiteral) {
1469 binding->setType(QV4::CompiledData::Binding::Type_Boolean);
1470 binding->value.b = false;
1471 } else if (QQmlJS::AST::NumericLiteral *lit = QQmlJS::AST::cast<QQmlJS::AST::NumericLiteral *>(expr)) {
1472 binding->setType(QV4::CompiledData::Binding::Type_Number);
1473 binding->value.constantValueIndex = jsGenerator->registerConstant(QV4::Encode(lit->value));
1474 } else if (QQmlJS::AST::CallExpression *call = QQmlJS::AST::cast<QQmlJS::AST::CallExpression *>(expr)) {
1475 if (QQmlJS::AST::IdentifierExpression *base = QQmlJS::AST::cast<QQmlJS::AST::IdentifierExpression *>(call->base)) {
1476 tryGeneratingTranslationBinding(base->name, call->arguments, binding);
1477 // If it wasn't a translation binding, a normal script binding will be generated
1478 // below.
1479 }
1480 } else if (QQmlJS::AST::cast<QQmlJS::AST::FunctionExpression *>(expr)) {
1481 binding->setFlag(QV4::CompiledData::Binding::IsFunctionExpression);
1482 } else if (QQmlJS::AST::UnaryMinusExpression *unaryMinus = QQmlJS::AST::cast<QQmlJS::AST::UnaryMinusExpression *>(expr)) {
1483 if (QQmlJS::AST::NumericLiteral *lit = QQmlJS::AST::cast<QQmlJS::AST::NumericLiteral *>(unaryMinus->expression)) {
1484 binding->setType(QV4::CompiledData::Binding::Type_Number);
1485 binding->value.constantValueIndex = jsGenerator->registerConstant(QV4::Encode(-lit->value));
1486 }
1487 } else if (QQmlJS::AST::cast<QQmlJS::AST::NullExpression *>(expr)) {
1488 binding->setType(QV4::CompiledData::Binding::Type_Null);
1489 binding->value.nullMarker = 0;
1490 }
1491 }
1492
1493 // Do binding instead
1494 if (binding->type() == QV4::CompiledData::Binding::Type_Invalid) {
1495 binding->setType(QV4::CompiledData::Binding::Type_Script);
1496
1497 CompiledFunctionOrExpression *expr = New<CompiledFunctionOrExpression>();
1498 expr->node = statement;
1499 expr->parentNode = parentNode;
1500 expr->nameIndex = registerString(QLatin1String("expression for ")
1501 + stringAt(binding->propertyNameIndex));
1502 expr->isQmlFunction = false;
1503 const int index = bindingsTarget()->functionsAndExpressions->append(expr);
1504 binding->value.compiledScriptIndex = index;
1505 // We don't need to store the binding script as string, except for script strings
1506 // and types with custom parsers. Those will be added later in the compilation phase.
1507 // Except that we cannot recover the string when cachegen runs; we need to therefore retain
1508 // "undefined" and "[]" (for QQmlListModel). Any other "special" strings (for the various
1509 // literals) are already handled above
1510 QQmlJS::AST::Node *nodeForString = statement;
1511 if (exprStmt)
1512 nodeForString = exprStmt->expression;
1513 const QStringView source = asStringRef(nodeForString);
1514 if (source == u"undefined") {
1515 binding->stringIndex = registerString(u"undefined"_s);
1516 } else if (qualifiedEnumDot(source) != -1) {
1517 binding->stringIndex = registerString(source.toString());
1518 } else if (const auto *arrayPattern =
1519 QQmlJS::AST::cast<QQmlJS::AST::ArrayPattern *>(nodeForString);
1520 arrayPattern && !arrayPattern->elements) {
1521 binding->stringIndex = registerString(u"[]"_s);
1522 } else {
1523 binding->stringIndex = emptyStringIndex;
1524 }
1525 }
1526}
1527
1528void IRBuilder::tryGeneratingTranslationBinding(QStringView base, AST::ArgumentList *args, QV4::CompiledData::Binding *binding)
1529{
1530 const auto registerString = [&](QStringView string) {
1531 return jsGenerator->registerString(string.toString()) ;
1532 };
1533
1534 const auto finalizeTranslationData = [&](
1535 QV4::CompiledData::Binding::Type type,
1536 QV4::CompiledData::TranslationData translationData) {
1537 binding->setType(type);
1538 if (type == QV4::CompiledData::Binding::Type_Translation
1539 || type == QV4::CompiledData::Binding::Type_TranslationById) {
1540 binding->value.translationDataIndex = jsGenerator->registerTranslation(translationData);
1541 } else if (type == QV4::CompiledData::Binding::Type_String) {
1542 binding->stringIndex = translationData.number;
1543 }
1544 };
1545
1546 tryGeneratingTranslationBindingBase(
1547 base, args,
1548 registerString, registerString, registerString, finalizeTranslationData);
1549}
1550
1551void IRBuilder::appendBinding(QQmlJS::AST::UiQualifiedId *name, QQmlJS::AST::Statement *value, QQmlJS::AST::Node *parentNode)
1552{
1553 const QQmlJS::SourceLocation qualifiedNameLocation = name->identifierToken;
1554 Object *object = nullptr;
1555 if (!resolveQualifiedId(&name, &object))
1556 return;
1557 if (_object == object && name->name == QLatin1String("id")) {
1558 setId(name->identifierToken, value);
1559 return;
1560 }
1561 qSwap(_object, object);
1562 appendBinding(qualifiedNameLocation, name->identifierToken, registerString(name->name.toString()), value, parentNode);
1563 qSwap(_object, object);
1564}
1565
1566void IRBuilder::appendBinding(QQmlJS::AST::UiQualifiedId *name, int objectIndex, bool isOnAssignment)
1567{
1568 const QQmlJS::SourceLocation qualifiedNameLocation = name->identifierToken;
1569 Object *object = nullptr;
1570 if (!resolveQualifiedId(&name, &object, isOnAssignment))
1571 return;
1572 qSwap(_object, object);
1573 appendBinding(qualifiedNameLocation, name->identifierToken, registerString(name->name.toString()), objectIndex, /*isListItem*/false, isOnAssignment);
1574 qSwap(_object, object);
1575}
1576
1577void IRBuilder::appendBinding(const QQmlJS::SourceLocation &qualifiedNameLocation, const QQmlJS::SourceLocation &nameLocation, quint32 propertyNameIndex,
1578 QQmlJS::AST::Statement *value, QQmlJS::AST::Node *parentNode)
1579{
1580 Binding *binding = New<Binding>();
1581 binding->propertyNameIndex = propertyNameIndex;
1582 binding->offset = nameLocation.offset;
1583 binding->location.set(nameLocation.startLine, nameLocation.startColumn);
1584 binding->clearFlags();
1585 setBindingValue(binding, value, parentNode);
1586 QString error = bindingsTarget()->appendBinding(binding, /*isListBinding*/false);
1587 if (!error.isEmpty()) {
1588 recordError(qualifiedNameLocation, error.arg(stringAt(propertyNameIndex)),
1589 QQmlJS::DiagnosticCategory::DuplicatePropertyBinding);
1590 }
1591}
1592
1593void IRBuilder::appendBinding(const QQmlJS::SourceLocation &qualifiedNameLocation, const QQmlJS::SourceLocation &nameLocation, quint32 propertyNameIndex, int objectIndex, bool isListItem, bool isOnAssignment)
1594{
1595 if (stringAt(propertyNameIndex) == QLatin1String("id")) {
1596 recordError(nameLocation, tr("Invalid component id specification"));
1597 if (!shouldContinue())
1598 return;
1599 } else {
1600 Binding *binding = New<Binding>();
1601 binding->propertyNameIndex = propertyNameIndex;
1602 binding->offset = nameLocation.offset;
1603 binding->location.set(nameLocation.startLine, nameLocation.startColumn);
1604
1605 const Object *obj = _objects.at(objectIndex);
1606 binding->valueLocation = obj->location;
1607
1608 binding->clearFlags();
1609
1610 if (_propertyDeclaration && _propertyDeclaration->isReadOnly())
1611 binding->setFlag(Binding::InitializerForReadOnlyDeclaration);
1612
1613 // No type name on the initializer means it must be a grouped property
1614 if (_objects.at(objectIndex)->inheritedTypeNameIndex == emptyStringIndex)
1615 binding->setType(Binding::Type_GroupedProperty);
1616 else
1617 binding->setType(Binding::Type_Object);
1618
1619 if (isOnAssignment)
1620 binding->setFlag(Binding::IsOnAssignment);
1621 if (isListItem)
1622 binding->setFlag(Binding::IsListItem);
1623
1624 binding->value.objectIndex = objectIndex;
1625 QString error = bindingsTarget()->appendBinding(binding, isListItem);
1626 if (!error.isEmpty())
1627 recordError(qualifiedNameLocation, error.arg(stringAt(propertyNameIndex)),
1628 QQmlJS::DiagnosticCategory::DuplicatePropertyBinding);
1629 }
1630}
1631
1632bool IRBuilder::appendAlias(QQmlJS::AST::UiPublicMember *node)
1633{
1634 Alias *alias = New<Alias>();
1635 bool isValid = true;
1636 alias->setIsReadOnly(node->isReadonly());
1637
1638 const QString propName = node->name.toString();
1639 alias->setNameIndex(registerString(propName));
1640
1641 QQmlJS::SourceLocation loc = node->firstSourceLocation();
1642 alias->setLocation({loc.startLine, loc.startColumn});
1643
1644 alias->setPropertyNameIndex(emptyStringIndex);
1645
1646 if (!node->statement && !node->binding) {
1647 COMPILE_EXCEPTION(loc, tr("No property alias location"));
1648 isValid = false;
1649 }
1650
1651 QQmlJS::SourceLocation rhsLoc;
1652 if (node->binding)
1653 rhsLoc = node->binding->firstSourceLocation();
1654 else if (node->statement)
1655 rhsLoc = node->statement->firstSourceLocation();
1656 else
1657 rhsLoc = node->semicolonToken;
1658 alias->setReferenceLocation({rhsLoc.startLine, rhsLoc.startColumn});
1659
1660 QStringList aliasReference;
1661
1662 if (isValid) {
1663 if (QQmlJS::AST::ExpressionStatement *stmt =
1664 QQmlJS::AST::cast<QQmlJS::AST::ExpressionStatement *>(node->statement)) {
1665 aliasReference = astNodeToStringList(stmt->expression);
1666 if (aliasReference.isEmpty()) {
1667 if (isStatementNodeScript(node->statement)) {
1669 rhsLoc,
1670 tr("Invalid alias reference. An alias reference must be specified as "
1671 "<id>, <id>.<property> or <id>.<value property>.<property>"));
1672 } else {
1673 COMPILE_EXCEPTION(rhsLoc, tr("Invalid alias location"));
1674 }
1675 isValid = false;
1676 }
1677 } else {
1678 COMPILE_EXCEPTION(rhsLoc,
1679 tr("Invalid alias reference. An alias reference must be specified as "
1680 "<id>, <id>.<property> or <id>.<value property>.<property>"));
1681 isValid = false;
1682 }
1683 }
1684
1685 if (isValid && (aliasReference.size() < 1 || aliasReference.size() > 3)) {
1686 COMPILE_EXCEPTION(rhsLoc, tr("Invalid alias reference. An alias reference must be specified as <id>, <id>.<property> or <id>.<value property>.<property>"));
1687 isValid = false;
1688 }
1689
1690 if (isValid)
1691 alias->setIdIndex(registerString(aliasReference.first()));
1692
1693 QString propertyValue = aliasReference.value(1);
1694 if (aliasReference.size() == 3)
1695 propertyValue += QLatin1Char('.') + aliasReference.at(2);
1696 alias->setPropertyNameIndex(registerString(propertyValue));
1697
1698 QQmlJS::SourceLocation errorLocation;
1699 QString error;
1700
1701 if (QV4::Compiler::Codegen::isNameGlobal(propName)) {
1702 error = tr("Illegal property name");
1703 } else if (isValid) {
1704 error = _object->appendAlias(alias, propName, node->isDefaultMember(), node->defaultToken(),
1705 &errorLocation);
1706 }
1707
1708 if (!error.isEmpty()) {
1709 if (errorLocation.startLine == 0)
1710 errorLocation = node->identifierToken;
1711
1712 recordError(errorLocation, error);
1713 if (!shouldContinue())
1714 return false;
1715 }
1716
1717 return false;
1718}
1719
1720Object *IRBuilder::bindingsTarget() const
1721{
1722 if (_propertyDeclaration && _object->declarationsOverride)
1723 return _object->declarationsOverride;
1724 return _object;
1725}
1726
1727bool IRBuilder::setId(const QQmlJS::SourceLocation &idLocation, QQmlJS::AST::Statement *value)
1728{
1729 QQmlJS::SourceLocation loc = value->firstSourceLocation();
1730 QStringView str;
1731
1732 QQmlJS::AST::Node *node = value;
1733 if (QQmlJS::AST::ExpressionStatement *stmt = QQmlJS::AST::cast<QQmlJS::AST::ExpressionStatement *>(node)) {
1734 if (QQmlJS::AST::StringLiteral *lit = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(stmt->expression)) {
1735 str = lit->value;
1736 node = nullptr;
1737 } else
1738 node = stmt->expression;
1739 } else {
1740 COMPILE_EXCEPTION(loc, tr("id must be followed by an identifier"));
1741 return false; // don't emit more warnings about the id being not an id
1742 }
1743
1744 if (node && str.isEmpty())
1745 str = asStringRef(node);
1746
1747 bool isValid = !str.isEmpty();
1748 if (!isValid) {
1749 COMPILE_EXCEPTION(loc, tr( "Invalid empty ID"));
1750 } else {
1751 QChar ch = str.at(0);
1752 if (ch.isLetter() && !ch.isLower()) {
1753 recordError(loc, tr("Id must start with a lower case letter or an '_'"),
1754 QQmlJS::DiagnosticCategory::Syntax);
1755 if (!shouldContinue())
1756 return false;
1757 isValid = false;
1758 }
1759
1760 QChar u(QLatin1Char('_'));
1761 if (!ch.isLetter() && ch != u) {
1762 COMPILE_EXCEPTION(loc, tr( "IDs must start with a letter or underscore"));
1763 isValid = false;
1764 }
1765
1766 for (int ii = 1; ii < str.size(); ++ii) {
1767 ch = str.at(ii);
1768 if (!ch.isLetterOrNumber() && ch != u) {
1769 COMPILE_EXCEPTION(loc, tr( "IDs must contain only letters, numbers, and underscores"));
1770 isValid = false;
1771 break;
1772 }
1773 }
1774
1775 QString idQString(str.toString());
1776 if (QV4::Compiler::Codegen::isNameGlobal(idQString)) {
1777 COMPILE_EXCEPTION(loc, tr( "ID illegally masks global JavaScript property"));
1778 isValid = false;
1779 }
1780
1781 if (_object->idNameIndex != emptyStringIndex) {
1782 recordError(idLocation,
1783 u"Found a duplicated id. id %1 was first declared at %2:%3"_s.arg(
1784 str, QString::number(_object->locationOfIdProperty.line()),
1785 QString::number(_object->locationOfIdProperty.column())),
1786 QQmlJS::DiagnosticCategory::SyntaxDuplicateIds);
1787 if (!shouldContinue())
1788 return false;
1789 isValid = false;
1790 }
1791
1792 if (isValid) {
1793 _object->idNameIndex = registerString(idQString);
1794 _object->locationOfIdProperty.set(idLocation.startLine, idLocation.startColumn);
1795 }
1796 }
1797
1798 return isValid;
1799}
1800
1801bool IRBuilder::resolveQualifiedId(QQmlJS::AST::UiQualifiedId **nameToResolve, Object **object, bool onAssignment)
1802{
1803 QQmlJS::AST::UiQualifiedId *qualifiedIdElement = *nameToResolve;
1804
1805 if (qualifiedIdElement->name == QLatin1String("id") && qualifiedIdElement->next)
1806 COMPILE_EXCEPTION(qualifiedIdElement->identifierToken, tr( "Invalid use of id property"));
1807
1808 // If it's a namespace, prepend the qualifier and we'll resolve it later to the correct type.
1809 QString currentName = qualifiedIdElement->name.toString();
1810 if (qualifiedIdElement->next) {
1811 for (const QV4::CompiledData::Import* import : std::as_const(_imports))
1812 if (import->qualifierIndex != emptyStringIndex
1813 && stringAt(import->qualifierIndex) == currentName) {
1814 qualifiedIdElement = qualifiedIdElement->next;
1815 currentName += QLatin1Char('.') + qualifiedIdElement->name;
1816
1817 if (!qualifiedIdElement->name.data()->isUpper())
1818 COMPILE_EXCEPTION(qualifiedIdElement->firstSourceLocation(), tr("Expected type name"));
1819
1820 break;
1821 }
1822 }
1823
1824 *object = _object;
1825 while (qualifiedIdElement->next) {
1826 const quint32 propertyNameIndex = registerString(currentName);
1827 const bool isAttachedProperty = qualifiedIdElement->name.data()->isUpper();
1828
1829 Binding *binding = (*object)->findBinding(propertyNameIndex);
1830 if (binding) {
1831 if (isAttachedProperty) {
1832 if (!binding->isAttachedProperty())
1833 binding = nullptr;
1834 } else if (!binding->isGroupedProperty()) {
1835 binding = nullptr;
1836 }
1837 }
1838 if (!binding) {
1839 binding = New<Binding>();
1840 binding->propertyNameIndex = propertyNameIndex;
1841 binding->offset = qualifiedIdElement->identifierToken.offset;
1842 binding->location.set(qualifiedIdElement->identifierToken.startLine,
1843 qualifiedIdElement->identifierToken.startColumn);
1844 binding->valueLocation.set(qualifiedIdElement->next->identifierToken.startLine,
1845 qualifiedIdElement->next->identifierToken.startColumn);
1846 binding->clearFlags();
1847
1848 if (onAssignment)
1849 binding->setFlag(QV4::CompiledData::Binding::IsOnAssignment);
1850
1851 if (isAttachedProperty)
1852 binding->setType(QV4::CompiledData::Binding::Type_AttachedProperty);
1853 else
1854 binding->setType(QV4::CompiledData::Binding::Type_GroupedProperty);
1855
1856 int objIndex = 0;
1857 if (!defineQMLObject(&objIndex, nullptr, binding->location, nullptr, nullptr))
1858 return false;
1859 binding->value.objectIndex = objIndex;
1860
1861 QString error = (*object)->appendBinding(binding, /*isListBinding*/false);
1862 if (!error.isEmpty()) {
1863 recordError(qualifiedIdElement->identifierToken,
1864 error.arg(stringAt(propertyNameIndex)),
1865 QQmlJS::DiagnosticCategory::DuplicatePropertyBinding);
1866 if (!shouldContinue())
1867 return false;
1868 }
1869 *object = _objects.at(objIndex);
1870 } else {
1871 Q_ASSERT(binding->isAttachedProperty() || binding->isGroupedProperty());
1872 *object = _objects.at(binding->value.objectIndex);
1873 }
1874
1875 qualifiedIdElement = qualifiedIdElement->next;
1876 if (qualifiedIdElement)
1877 currentName = qualifiedIdElement->name.toString();
1878 }
1879 *nameToResolve = qualifiedIdElement;
1880 return true;
1881}
1882
1883void IRBuilder::recordError(const QQmlJS::SourceLocation &location, const QString &description)
1884{
1885 QQmlJS::DiagnosticMessage error;
1886 error.loc = location;
1887 error.message = description;
1888 errors << error;
1889}
1890
1891void IRBuilder::recordError(const QQmlJS::SourceLocation &location, const QString &description,
1892 QQmlJS::DiagnosticCategory category)
1893{
1894 QQmlJS::DiagnosticMessage error;
1895 error.loc = location;
1896 error.message = description;
1897 error.type = category;
1898 errors << error;
1899}
1900
1901bool IRBuilder::isStatementNodeScript(QQmlJS::AST::Statement *statement)
1902{
1903 if (QQmlJS::AST::ExpressionStatement *stmt = QQmlJS::AST::cast<QQmlJS::AST::ExpressionStatement *>(statement)) {
1904 QQmlJS::AST::ExpressionNode *expr = stmt->expression;
1905 if (QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(expr))
1906 return false;
1907 else if (expr->kind == QQmlJS::AST::Node::Kind_TrueLiteral)
1908 return false;
1909 else if (expr->kind == QQmlJS::AST::Node::Kind_FalseLiteral)
1910 return false;
1911 else if (QQmlJS::AST::cast<QQmlJS::AST::NumericLiteral *>(expr))
1912 return false;
1913 else {
1914
1915 if (QQmlJS::AST::UnaryMinusExpression *unaryMinus = QQmlJS::AST::cast<QQmlJS::AST::UnaryMinusExpression *>(expr)) {
1916 if (QQmlJS::AST::cast<QQmlJS::AST::NumericLiteral *>(unaryMinus->expression)) {
1917 return false;
1918 }
1919 }
1920 }
1921 }
1922
1923 return true;
1924}
1925
1926bool IRBuilder::isRedundantNullInitializerForPropertyDeclaration(Property *property, QQmlJS::AST::Statement *statement)
1927{
1928 if (property->isCommonType() || property->isList())
1929 return false;
1930 QQmlJS::AST::ExpressionStatement *exprStmt = QQmlJS::AST::cast<QQmlJS::AST::ExpressionStatement *>(statement);
1931 if (!exprStmt)
1932 return false;
1933 QQmlJS::AST::ExpressionNode * const expr = exprStmt->expression;
1934 return QQmlJS::AST::cast<QQmlJS::AST::NullExpression *>(expr);
1935}
1936
1937void QmlUnitGenerator::generate(Document &output)
1938{
1939 using namespace QV4::CompiledData;
1940
1941 output.jsGenerator.stringTable.registerString(output.jsModule.fileName);
1942 output.jsGenerator.stringTable.registerString(output.jsModule.finalUrl);
1943
1944 Unit *jsUnit = nullptr;
1945
1946 if (!output.javaScriptCompilationUnit)
1947 output.javaScriptCompilationUnit.adopt(new QV4::CompiledData::CompilationUnit);
1948
1949 // We may already have unit data if we're loading an ahead-of-time generated cache file.
1950 if (output.javaScriptCompilationUnit->unitData()) {
1951 jsUnit = const_cast<Unit *>(output.javaScriptCompilationUnit->unitData());
1952 output.javaScriptCompilationUnit->dynamicStrings
1953 = output.jsGenerator.stringTable.allStrings();
1954 } else {
1955 Unit *createdUnit;
1956 jsUnit = createdUnit = output.jsGenerator.generateUnit();
1957
1958 // enable flag if we encountered pragma Singleton
1959 for (Pragma *p : std::as_const(output.pragmas)) {
1960 switch (p->type) {
1961 case Pragma::Singleton:
1962 createdUnit->flags |= Unit::IsSingleton;
1963 break;
1964 case Pragma::Strict:
1965 createdUnit->flags |= Unit::IsStrict;
1966 break;
1967 case Pragma::ComponentBehavior:
1968 // ### Qt7: Change the default to Bound by reverting the meaning of the flag.
1969 switch (p->componentBehavior) {
1970 case Pragma::Bound:
1971 createdUnit->flags |= Unit::ComponentsBound;
1972 break;
1973 case Pragma::Unbound:
1974 // this is the default
1975 break;
1976 }
1977 break;
1978 case Pragma::ListPropertyAssignBehavior:
1979 switch (p->listPropertyAssignBehavior) {
1980 case Pragma::Replace:
1981 createdUnit->flags |= Unit::ListPropertyAssignReplace;
1982 break;
1983 case Pragma::ReplaceIfNotDefault:
1984 createdUnit->flags |= Unit::ListPropertyAssignReplaceIfNotDefault;
1985 break;
1986 case Pragma::Append:
1987 // this is the default
1988 break;
1989 }
1990 break;
1991 case Pragma::FunctionSignatureBehavior:
1992 switch (p->functionSignatureBehavior) {
1993 case Pragma::Enforced:
1994 break;
1995 case Pragma::Ignored:
1996 createdUnit->flags |= Unit::FunctionSignaturesIgnored;
1997 break;
1998 }
1999 break;
2000 case Pragma::NativeMethodBehavior:
2001 switch (p->nativeMethodBehavior) {
2002 case Pragma::AcceptThisObject:
2003 createdUnit->flags |= Unit::NativeMethodsAcceptThisObject;
2004 break;
2005 case Pragma::RejectThisObject:
2006 // this is the default;
2007 break;
2008 }
2009 break;
2010 case Pragma::ValueTypeBehavior:
2011 if (Pragma::ValueTypeBehaviorValues(p->valueTypeBehavior)
2012 .testFlag(Pragma::Copy)) {
2013 createdUnit->flags |= Unit::ValueTypesCopied;
2014 }
2015 if (Pragma::ValueTypeBehaviorValues(p->valueTypeBehavior)
2016 .testFlag(Pragma::Addressable)) {
2017 createdUnit->flags |= Unit::ValueTypesAddressable;
2018 }
2019 if (Pragma::ValueTypeBehaviorValues(p->valueTypeBehavior)
2020 .testFlag(Pragma::Assertable)) {
2021 createdUnit->flags |= Unit::ValueTypesAssertable;
2022 }
2023 break;
2024 case Pragma::Translator:
2025 if (createdUnit->translationTableSize)
2026 if (quint32_le *index = createdUnit->translationContextIndex())
2027 *index = p->translationContextIndex;
2028 break;
2029 }
2030 }
2031
2032 createdUnit->sourceFileIndex = output.jsGenerator.stringTable.getStringId(output.jsModule.fileName);
2033 createdUnit->finalUrlIndex = output.jsGenerator.stringTable.getStringId(output.jsModule.finalUrl);
2034 }
2035
2036 // No more new strings after this point, we're calculating offsets.
2037 output.jsGenerator.stringTable.freeze();
2038
2039 const uint importSize = uint(sizeof(QV4::CompiledData::Import)) * output.imports.size();
2040 const uint objectOffsetTableSize = output.objects.size() * uint(sizeof(quint32));
2041
2042 QHash<const Object*, quint32> objectOffsets;
2043
2044 const unsigned int objectOffset = sizeof(QV4::CompiledData::QmlUnit) + importSize;
2045 uint nextOffset = objectOffset + objectOffsetTableSize;
2046 for (Object *o : std::as_const(output.objects)) {
2047 objectOffsets.insert(o, nextOffset);
2048 nextOffset += QV4::CompiledData::Object::calculateSizeExcludingSignalsAndEnums(o->functionCount(), o->propertyCount(), o->aliasCount(), o->enumCount(), o->signalCount(), o->bindingCount(), o->inlineComponentCount(), o->requiredPropertyExtraDataCount());
2049
2050 int signalTableSize = 0;
2051 for (const Signal *s = o->firstSignal(); s; s = s->next)
2052 signalTableSize += QV4::CompiledData::Signal::calculateSize(s->parameters->count);
2053
2054 nextOffset += signalTableSize;
2055
2056 int enumTableSize = 0;
2057 for (const Enum *e = o->firstEnum(); e; e = e->next)
2058 enumTableSize += QV4::CompiledData::Enum::calculateSize(e->enumValues->count);
2059
2060 nextOffset += enumTableSize;
2061 }
2062
2063 const uint totalSize = nextOffset;
2064 char *data = (char*)malloc(totalSize);
2065 memset(data, 0, totalSize);
2066 QV4::CompiledData::QmlUnit *qmlUnit = reinterpret_cast<QV4::CompiledData::QmlUnit *>(data);
2067 qmlUnit->offsetToImports = sizeof(*qmlUnit);
2068 qmlUnit->nImports = output.imports.size();
2069 qmlUnit->offsetToObjects = objectOffset;
2070 qmlUnit->nObjects = output.objects.size();
2071
2072 // write imports
2073 char *importPtr = data + qmlUnit->offsetToImports;
2074 for (const QV4::CompiledData::Import *imp : std::as_const(output.imports)) {
2075 QV4::CompiledData::Import *importToWrite = reinterpret_cast<QV4::CompiledData::Import*>(importPtr);
2076 *importToWrite = *imp;
2077 importPtr += sizeof(QV4::CompiledData::Import);
2078 }
2079
2080 // write objects
2081 quint32_le *objectTable = reinterpret_cast<quint32_le*>(data + qmlUnit->offsetToObjects);
2082 for (int i = 0; i < output.objects.size(); ++i) {
2083 const Object *o = output.objects.at(i);
2084 char * const objectPtr = data + objectOffsets.value(o);
2085 *objectTable++ = objectOffsets.value(o);
2086
2087 QV4::CompiledData::Object *objectToWrite = reinterpret_cast<QV4::CompiledData::Object*>(objectPtr);
2088 objectToWrite->inheritedTypeNameIndex = o->inheritedTypeNameIndex;
2089 objectToWrite->indexOfDefaultPropertyOrAlias = o->indexOfDefaultPropertyOrAlias;
2090 objectToWrite->setHasAliasAsDefaultProperty(o->defaultPropertyIsAlias);
2091 objectToWrite->setFlags(QV4::CompiledData::Object::Flags(o->flags));
2092 objectToWrite->idNameIndex = o->idNameIndex;
2093 objectToWrite->location = o->location;
2094 objectToWrite->locationOfIdProperty = o->locationOfIdProperty;
2095
2096 quint32 nextOffset = sizeof(QV4::CompiledData::Object);
2097
2098 objectToWrite->nFunctions = o->functionCount();
2099 objectToWrite->offsetToFunctions = nextOffset;
2100 nextOffset += objectToWrite->nFunctions * sizeof(quint32);
2101
2102 objectToWrite->nProperties = o->propertyCount();
2103 objectToWrite->offsetToProperties = nextOffset;
2104 nextOffset += objectToWrite->nProperties * sizeof(QV4::CompiledData::Property);
2105
2106 objectToWrite->nAliases = o->aliasCount();
2107 objectToWrite->offsetToAliases = nextOffset;
2108 nextOffset += objectToWrite->nAliases * sizeof(QV4::CompiledData::Alias);
2109
2110 objectToWrite->nEnums = o->enumCount();
2111 objectToWrite->offsetToEnums = nextOffset;
2112 nextOffset += objectToWrite->nEnums * sizeof(quint32);
2113
2114 objectToWrite->nSignals = o->signalCount();
2115 objectToWrite->offsetToSignals = nextOffset;
2116 nextOffset += objectToWrite->nSignals * sizeof(quint32);
2117
2118 objectToWrite->nBindings = o->bindingCount();
2119 objectToWrite->offsetToBindings = nextOffset;
2120 nextOffset += objectToWrite->nBindings * sizeof(QV4::CompiledData::Binding);
2121
2122 objectToWrite->nInlineComponents = o->inlineComponentCount();
2123 objectToWrite->offsetToInlineComponents = nextOffset;
2124 nextOffset += objectToWrite->nInlineComponents * sizeof (QV4::CompiledData::InlineComponent);
2125
2126 objectToWrite->nRequiredPropertyExtraData = o->requiredPropertyExtraDataCount();
2127 objectToWrite->offsetToRequiredPropertyExtraData = nextOffset;
2128 nextOffset += objectToWrite->nRequiredPropertyExtraData * sizeof(QV4::CompiledData::RequiredPropertyExtraData);
2129
2130 quint32_le *functionsTable = reinterpret_cast<quint32_le *>(objectPtr + objectToWrite->offsetToFunctions);
2131 for (const Function *f = o->firstFunction(); f; f = f->next)
2132 *functionsTable++ = o->runtimeFunctionIndices.at(f->index);
2133
2134 char *propertiesPtr = objectPtr + objectToWrite->offsetToProperties;
2135 for (const Property *p = o->firstProperty(); p; p = p->next) {
2136 QV4::CompiledData::Property *propertyToWrite = reinterpret_cast<QV4::CompiledData::Property*>(propertiesPtr);
2137 *propertyToWrite = *p;
2138 propertiesPtr += sizeof(QV4::CompiledData::Property);
2139 }
2140
2141 char *aliasesPtr = objectPtr + objectToWrite->offsetToAliases;
2142 for (const Alias *a = o->firstAlias(); a; a = a->next) {
2143 QV4::CompiledData::Alias *aliasToWrite = reinterpret_cast<QV4::CompiledData::Alias*>(aliasesPtr);
2144 *aliasToWrite = *a;
2145 aliasesPtr += sizeof(QV4::CompiledData::Alias);
2146 }
2147
2148 char *bindingPtr = objectPtr + objectToWrite->offsetToBindings;
2149 bindingPtr = writeBindings(bindingPtr, o);
2150 Q_ASSERT((bindingPtr - objectToWrite->offsetToBindings - objectPtr) / sizeof(QV4::CompiledData::Binding) == unsigned(o->bindingCount()));
2151
2152 quint32_le *signalOffsetTable = reinterpret_cast<quint32_le *>(objectPtr + objectToWrite->offsetToSignals);
2153 quint32 signalTableSize = 0;
2154 char *signalPtr = objectPtr + nextOffset;
2155 for (const Signal *s = o->firstSignal(); s; s = s->next) {
2156 *signalOffsetTable++ = signalPtr - objectPtr;
2157 QV4::CompiledData::Signal *signalToWrite = reinterpret_cast<QV4::CompiledData::Signal*>(signalPtr);
2158
2159 signalToWrite->nameIndex = s->nameIndex;
2160 signalToWrite->location = s->location;
2161 signalToWrite->nParameters = s->parameters->count;
2162
2163 QV4::CompiledData::Parameter *parameterToWrite = reinterpret_cast<QV4::CompiledData::Parameter*>(signalPtr + sizeof(*signalToWrite));
2164 for (Parameter *param = s->parameters->first; param; param = param->next, ++parameterToWrite)
2165 *parameterToWrite = *param;
2166
2167 int size = QV4::CompiledData::Signal::calculateSize(s->parameters->count);
2168 signalTableSize += size;
2169 signalPtr += size;
2170 }
2171 nextOffset += signalTableSize;
2172
2173 quint32_le *enumOffsetTable = reinterpret_cast<quint32_le*>(objectPtr + objectToWrite->offsetToEnums);
2174 char *enumPtr = objectPtr + nextOffset;
2175 for (const Enum *e = o->firstEnum(); e; e = e->next) {
2176 *enumOffsetTable++ = enumPtr - objectPtr;
2177 QV4::CompiledData::Enum *enumToWrite = reinterpret_cast<QV4::CompiledData::Enum*>(enumPtr);
2178
2179 enumToWrite->nameIndex = e->nameIndex;
2180 enumToWrite->location = e->location;
2181 enumToWrite->nEnumValues = e->enumValues->count;
2182
2183 QV4::CompiledData::EnumValue *enumValueToWrite = reinterpret_cast<QV4::CompiledData::EnumValue*>(enumPtr + sizeof(*enumToWrite));
2184 for (EnumValue *enumValue = e->enumValues->first; enumValue; enumValue = enumValue->next, ++enumValueToWrite)
2185 *enumValueToWrite = *enumValue;
2186
2187 int size = QV4::CompiledData::Enum::calculateSize(e->enumValues->count);
2188 enumPtr += size;
2189 }
2190
2191 char *inlineComponentPtr = objectPtr + objectToWrite->offsetToInlineComponents;
2192 for (auto it = o->inlineComponentsBegin(); it != o->inlineComponentsEnd(); ++it) {
2193 const InlineComponent *ic = it.ptr;
2194 QV4::CompiledData::InlineComponent *icToWrite = reinterpret_cast<QV4::CompiledData::InlineComponent*>(inlineComponentPtr);
2195 *icToWrite = *ic;
2196 inlineComponentPtr += sizeof(QV4::CompiledData::InlineComponent);
2197 }
2198
2199 char *requiredPropertyExtraDataPtr = objectPtr + objectToWrite->offsetToRequiredPropertyExtraData;
2200 for (auto it = o->requiredPropertyExtraDataBegin(); it != o->requiredPropertyExtraDataEnd(); ++it) {
2201 const RequiredPropertyExtraData *extraData = it.ptr;
2202 QV4::CompiledData::RequiredPropertyExtraData *extraDataToWrite = reinterpret_cast<QV4::CompiledData::RequiredPropertyExtraData*>(requiredPropertyExtraDataPtr);
2203 *extraDataToWrite = *extraData;
2204 requiredPropertyExtraDataPtr += sizeof(QV4::CompiledData::RequiredPropertyExtraData);
2205 }
2206 }
2207
2208 if (!output.javaScriptCompilationUnit->unitData()) {
2209 // Combine the qml data into the general unit data.
2210 jsUnit = static_cast<QV4::CompiledData::Unit *>(realloc(jsUnit, jsUnit->unitSize + totalSize));
2211 jsUnit->offsetToQmlUnit = jsUnit->unitSize;
2212 jsUnit->unitSize += totalSize;
2213 memcpy(jsUnit->qmlUnit(), qmlUnit, totalSize);
2214 free(qmlUnit);
2215 QV4::Compiler::JSUnitGenerator::generateUnitChecksum(jsUnit);
2216 qmlUnit = jsUnit->qmlUnit();
2217 }
2218
2219 static const bool showStats = qEnvironmentVariableIsSet("QML_SHOW_UNIT_STATS");
2220 if (showStats) {
2221 qDebug() << "Generated QML unit that is" << totalSize << "bytes big contains:";
2222 qDebug() << " " << jsUnit->functionTableSize << "functions";
2223 qDebug() << " " << jsUnit->unitSize << "for JS unit";
2224 qDebug() << " " << importSize << "for imports";
2225 qDebug() << " " << nextOffset - objectOffset - objectOffsetTableSize << "for" << qmlUnit->nObjects << "objects";
2226 quint32 totalBindingCount = 0;
2227 for (quint32 i = 0; i < qmlUnit->nObjects; ++i)
2228 totalBindingCount += qmlUnit->objectAt(i)->nBindings;
2229 qDebug() << " " << totalBindingCount << "bindings";
2230 quint32 totalCodeSize = 0;
2231 for (quint32 i = 0; i < jsUnit->functionTableSize; ++i)
2232 totalCodeSize += jsUnit->functionAt(i)->codeSize;
2233 qDebug() << " " << totalCodeSize << "bytes total byte code";
2234 qDebug() << " " << jsUnit->stringTableSize << "strings";
2235 quint32 totalStringSize = 0;
2236 for (quint32 i = 0; i < jsUnit->stringTableSize; ++i)
2237 totalStringSize += QV4::CompiledData::String::calculateSize(jsUnit->stringAtInternal(i));
2238 qDebug() << " " << totalStringSize << "bytes total strings";
2239 }
2240
2241 output.javaScriptCompilationUnit->setUnitData(
2242 jsUnit, qmlUnit, output.jsModule.fileName, output.jsModule.finalUrl);
2243}
2244
2245char *QmlUnitGenerator::writeBindings(char *bindingPtr, const Object *o) const
2246{
2247 for (const Binding *b = o->firstBinding(); b; b = b->next) {
2248 QV4::CompiledData::Binding *bindingToWrite = reinterpret_cast<QV4::CompiledData::Binding*>(bindingPtr);
2249 *bindingToWrite = *b;
2250 if (b->type() == QV4::CompiledData::Binding::Type_Script)
2251 bindingToWrite->value.compiledScriptIndex = o->runtimeFunctionIndices.at(b->value.compiledScriptIndex);
2252 bindingPtr += sizeof(QV4::CompiledData::Binding);
2253 }
2254 return bindingPtr;
2255}
2256
2257JSCodeGen::JSCodeGen(
2258 Document *document, QV4::Compiler::CodegenWarningInterface *iface,
2259 bool storeSourceLocations)
2260 : QV4::Compiler::Codegen(&document->jsGenerator, /*strict mode*/ false, iface,
2261 storeSourceLocations),
2262 document(document)
2263{
2264 _module = &document->jsModule;
2265 _fileNameIsUrl = true;
2266}
2267
2268QList<int> JSCodeGen::generateJSCodeForFunctionsAndBindings(
2269 const QList<CompiledFunctionOrExpression> &functions)
2270{
2271 auto qmlName = [&](const CompiledFunctionOrExpression &c) {
2272 if (c.nameIndex != 0)
2273 return document->stringAt(c.nameIndex);
2274 else
2275 return QStringLiteral("%qml-expression-entry");
2276 };
2277 QList<int> runtimeFunctionIndices(functions.size());
2278
2279 QV4::Compiler::ScanFunctions scan(this, document->code, QV4::Compiler::ContextType::Global);
2280 scan.enterGlobalEnvironment(QV4::Compiler::ContextType::Binding);
2281 for (const CompiledFunctionOrExpression &f : functions) {
2282 Q_ASSERT(f.node != document->program);
2283 Q_ASSERT(f.parentNode && f.parentNode != document->program);
2284 auto function = f.node->asFunctionDefinition();
2285
2286 if (function) {
2287 if (!f.isQmlFunction)
2288 continue;
2289 scan.enterQmlFunction(function);
2290 } else {
2291 Q_ASSERT(f.node != f.parentNode);
2292 scan.enterEnvironment(f.parentNode, QV4::Compiler::ContextType::Binding, qmlName(f));
2293 }
2294
2295 /* We do not want to visit the whole function, as we already called enterQmlFunction
2296 However, there might be a function defined as a default argument of the function.
2297 That needs to be considered, too, so we call handleTopLevelFunctionFormals to
2298 deal with them.
2299 */
2300 scan.handleTopLevelFunctionFormals(function);
2301 scan.scanWithoutEscapingVariables(function ? function->body : f.node);
2302 scan.leaveEnvironment();
2303 }
2304 scan.calcEscapingVariablesForNewContexts();
2305 scan.leaveEnvironment();
2306
2307 if (hasError())
2308 return QList<int>();
2309
2310 _context = nullptr;
2311
2312 for (int i = 0; i < functions.size(); ++i) {
2313 const CompiledFunctionOrExpression &qmlFunction = functions.at(i);
2314 QQmlJS::AST::Node *node = qmlFunction.node;
2315 Q_ASSERT(node != document->program);
2316
2317 QQmlJS::AST::FunctionExpression *function = node->asFunctionDefinition();
2318
2319 QString name;
2320 if (function)
2321 name = function->name.toString();
2322 else
2323 name = qmlName(qmlFunction);
2324
2325 QQmlJS::AST::StatementList *body;
2326 if (function) {
2327 body = function->body;
2328 } else {
2329 // Synthesize source elements.
2330 QQmlJS::MemoryPool *pool = document->jsParserEngine.pool();
2331
2332 QQmlJS::AST::Statement *stmt = node->statementCast();
2333 if (!stmt) {
2334 Q_ASSERT(node->expressionCast());
2335 QQmlJS::AST::ExpressionNode *expr = node->expressionCast();
2336 stmt = new (pool) QQmlJS::AST::ExpressionStatement(expr);
2337 }
2338 body = new (pool) QQmlJS::AST::StatementList(stmt);
2339 body = body->finish();
2340 }
2341
2342 int idx = defineFunction(name, function ? function : qmlFunction.parentNode,
2343 function ? function->formals : nullptr, body);
2344 runtimeFunctionIndices[i] = idx;
2345 }
2346
2347 return runtimeFunctionIndices;
2348}
2349
2350bool JSCodeGen::generateRuntimeFunctions(QmlIR::Object *object)
2351{
2352 if (object->functionsAndExpressions->count == 0)
2353 return true;
2354
2355 QList<QmlIR::CompiledFunctionOrExpression> functionsToCompile;
2356 functionsToCompile.reserve(object->functionsAndExpressions->count);
2357 for (QmlIR::CompiledFunctionOrExpression *foe = object->functionsAndExpressions->first; foe;
2358 foe = foe->next) {
2359 functionsToCompile << *foe;
2360 }
2361
2362 const auto runtimeFunctionIndices = generateJSCodeForFunctionsAndBindings(functionsToCompile);
2363 if (hasError())
2364 return false;
2365
2366 object->runtimeFunctionIndices.allocate(document->jsParserEngine.pool(),
2367 runtimeFunctionIndices);
2368 return true;
2369}
#define COMPILE_EXCEPTION(...)
static const quint32 emptyStringIndex
static QStringList astNodeToStringList(QQmlJS::AST::Node *node)
#define EMIT_COMPILE_EXCEPTION(...)
static bool run(IRBuilder *builder, QQmlJS::AST::UiPragma *node, Pragma *pragma)
PoolList< Parameter > * parameters
QStringList parameterStringList(const QV4::Compiler::StringTableGenerator *stringPool) const