aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser
Commit message (Collapse)AuthorAgeFilesLines
* Remove duplicate add of qqmljsengine_p.h to HEADERS in parser.priFawzi Mohamed2020-03-031-2/+1
| | | | | Change-Id: I6848575df79be5f84e55e1e9ae9282216424afeb Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Get rid of extra spaceFawzi Mohamed2020-03-031-1/+1
| | | | | | Change-Id: I11e5c9e95974e89f2fd1571ca4b97a0f2ac3309a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Restore offset/length in QQmlJS::DiagnosticMessageSimon Hausmann2020-03-027-118/+29
| | | | | | | | | | | | This is needed in a few places outside of declarative, so this change restores the loc member in DiagnosticMessage and moves QQmlJS::AST::SourceLocation into common's QQmlJS namespace/directory. QQmlError is unaffected and retains only line/column. Amends d4d197d06279f9257647628f7e1ccc9ec763a6bb Change-Id: Ifb9d344228e3c6e9e26fc4fe112686f9336ea2b2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add UiAnnotation for annotation objectsFawzi Mohamed2020-02-125-8/+49
| | | | | | | | | | This is a partial patch that is fuilly fixed with the following one (big restructure) because it needs extra visit methods, and that leads to conflicts, but I think it gets lost if merged with the next one. Change-Id: I54331a47a5c7faaf78a97e580825d1feec5adf92 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Introduce BaseVisitorFawzi Mohamed2020-02-125-467/+801
| | | | | | | | | | Base Visitor is an abstract visitor that has all visit methods abstract, subclassing this one gets an error if some visit method is not implemented (dumper and reformatter for example will gain from this. Change-Id: I3f8cfeb6fc0ef917acf725bbe1c293d761304287 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Put Ui visitors togetherFawzi Mohamed2020-02-121-3/+2
| | | | | | | | | | UiRequired is not with all Ui Vistors and introduced with a // Ui comment. Move it there for consistency. Change-Id: I51315ad380fd50998e7efe095c873d14a5ae7a97 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Remove unused AST::ModuleItemFawzi Mohamed2020-02-122-4/+0
| | | | | | | | | ModuleItem is unused we should either remove it or make it a used abstract superclass like UiObjectMember. Here we remove it. Change-Id: Icfcebd450e09ebe324a99728613eea0348b980ac Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Make UiObjectDefinition uniformFawzi Mohamed2020-02-121-4/+5
| | | | | | | | attributes are always at the end of AST objects, move them there also for UiObjectDefinition. Change-Id: I7630b1c40627913c3e7e46e752acf1d80203ce63 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Mark non visited AST partsFawzi Mohamed2020-02-121-0/+13
| | | | | | | Add a commented out accept call for the non visited fields in accept0 Change-Id: Icb1ab0c77440f4c3eae5404bff2cf71086f96a2f Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add annotations to ASTFawzi Mohamed2020-02-125-5/+68
| | | | | | | | | | | | | | | | | | | | Annotations are added to UiObjectMember. This makes it easy to find the annotations of any UiObjectMember through the annotations attribute. The clean AST approach would add an UiAnnotatedObjectMember that contains both the annotation list and an UiObjectMember, but that makes finding the annotation more difficult. The annotations are not visited by default, if one wants to dump them before the current object the simplest way is to use the preVisit and use .uiObjectMemberCast(). Depending on how we use annotation we could change the current approach. Task-number: QTBUG-81714 Change-Id: I543a2cfe5157bcc86de6de9faebde9aea22974eb Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Required properties: Allow retroactive require specificationFabian Kosmale2020-01-315-2/+48
| | | | | | | | It is now possible to mark a property of a parent class as required in the child by writing required <propertyName> Change-Id: I9e9d58c7b5c00577b056e905b39744b2fa359ea0 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* add annotations to QMLFawzi Mohamed2020-01-312-5/+79
| | | | | | | | | | | | | | | | | A QML Annotation is a Qml Object declaration prepended with @. The name of the annotation is restricted to a dot separated list of non keyword identifiers. Annotations can be put before an Object definition, or any object member declaration: bindings, property declarations, function declarations. This patch, aside parsing the annotations does absolutely nothing, the list of annotations is discarded and never touches the AST. [ChangeLog][QML] Add Qml Annotations Task-number: QTBUG-81714 Change-Id: I4d79559a0d1fb23acaf482d0ef8f7d106dbf099d Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Required properties: Allow required default propertiesFabian Kosmale2020-01-291-0/+25
| | | | | | | | | This was already possible from C++, this change adds the required changes to the grammar to allow declaring required default properties in QML. Change-Id: I76cb4d70e573bf161676da8295ab257fe95ed4ae Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Long live QML inline componentsFabian Kosmale2020-01-236-24/+94
| | | | | | | | | | | | | | | | | | | | | | | | | | | | [ChangeLog][QtQml] It is now possible to declare new QML components in a QML file via the component keyword. They can be used just as if they were declared in another file, with the only difference that the type name needs to be prefixed with the name of the containing type outside of the file were the inline component has been declared. Notably, inline components are not closures: In the following example, the output would be 42 // MyItem.qml Item { property int i: 33 component IC: Item { Component.onCompleted: console.log(i) } } // user.qml Item { property int i: 42 MyItem.IC {} } Fixes: QTBUG-79382 Change-Id: I6a5ffc43f093a76323f435cfee9bab217781b8f5 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qml/parser: Implement nullish coalescingMaximilian Goldstein2019-12-053-5/+49
| | | | | | | | | | Implements the '??' operator as specified in https://github.com/tc39/proposal-nullish-coalescing. Also adds a few tests. Task-number: QTBUG-77926 Change-Id: I3993450c192d11bf1ade0662d945c1553b4c6976 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add (and ignore for now) type assertions to QMLUlf Hermann2019-11-272-0/+15
| | | | | | | | | | You can write "(something as Foo)" to give hints to any tools that you expect something to be a Foo at this place. This is not a conversion and ignored at runtime for now. Eventually the compiler will verify that the type assertions are plausible and error out if they aren't. Change-Id: I21c8705bb387f7ab2cbc153293dbf477663afe87 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Consider the semicolon as part of expression statementsUlf Hermann2019-11-182-5/+21
| | | | | | | | | | | | | | | | | | | | | | When asked for lastSourceLocation() we should always return the semicolon token. In order for that to work, the semicolon token needs to be valid in all cases. In the case of object literals as expressions for properties we neither accepted nor synthesized a semicolon as delimiter. Add an optional semicolon that we can then also use as end of the expression statement. Furthermore, this triggered a silent rule conflict for ImportSpecifier, which for some reason did not arise before: IdentifierReference could resolve to both ImpordBinding and IdentifierName, causing ambiguity in the grammar, and ultimately caused parse failues when parsing an import statement. This is now resolved by explicitly telling the parser to prefer shifting. Initial-patch-by: Ulf Hermann <ulf.hermann@qt.io> Change-Id: Iaec29c452b577312248a17cb48f005f4fc0bd8c4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Remove QQmlJS::AST::UiImport::versionTokenUlf Hermann2019-10-102-9/+1
| | | | | | | | It was incorrectly parsed in case of "as Foo", and it was mostly unused. Change-Id: Ie833a8eb247108cb7bcd6ca3e6f3e5df614461cf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* V4: Provide an environment variable to disable runtime stack size checksUlf Hermann2019-09-172-1/+13
| | | | | | | | | | | | | | | | | | | | | | With QV4_CRASH_ON_STACKOVERFLOW set you can use up all the stack provided by the operating system to parse and execute JavaScript. Once the stack space is exhausted the program crashes like it would in case of a C++ stack overflow. We cannot reliably determine either the maximum stack size or the amount of stack space currently in use at runtime. Therefore, the guards we usually put in place are necessarily conservative. [ChangeLog][QtQml] There is now an option to disable the (necessarily) conservative stack size checks when parsing and executing JavaScript. If the environment variable QV4_CRASH_ON_STACKOVERFLOW is set, JavaScript stack overflows crash the program the same way C++ stack overflows do. On the flip side, more stack space is made available that way. Task-number: QTBUG-74087 Change-Id: I5e9d9ec6c0c9c6258c31d9e2d04a5c1819fbf400 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Introduce required properties to QMLFabian Kosmale2019-09-093-2/+32
| | | | | | | | | | | | | | | | | | | [ChangeLog][QtQml] "required" is now a (contextual) keyword in QML, and users can mark properties with it to specify that those properties must be set when the component gets instantiated. This can be done either declaratively via standard property bindings from QML, or imperatively by using the functions to set initial properties (QQmlCompoent::setInitalProperties and related functions in C++, Qt.createObject, Loader.setSource,... in QML/JS). Logic has been added to QQmlComponent::create and the various QQmlIncubator classes to verify that the required properties were set. If properties marked as required are not set, a warning will be printed at runtime, and the component will not be created. Change-Id: I8e38227fc8f173b053b689c1597dc7fd40e835e7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* qqmljs.g: deduplicate rulesFabian Kosmale2019-09-061-76/+32
| | | | | Change-Id: I9b6a9f95b838bbbf015c7619ae3a8828836e4178 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2019-09-052-42/+50
|\ | | | | | | Change-Id: Icc46cb06ac1dbe7097d11bc0db5813eb39fbf758
| * Allow semicolon after property declarationFabian Kosmale2019-09-031-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | Most of the rules already had Semicolon at the end, however it was missing for UiScriptStatement, list properties and UiObjectInitializer. This change fixes the regression from 5.11.3 to 5.12.0, and keeps the behavior consistent. Fixes: QTBUG-77954 Change-Id: I45ef35fab399e3f971444b96d4a9ec6a99e29e09 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
| * Visit lists iteratively when parsing QMLUlf Hermann2019-09-021-35/+38
| | | | | | | | | | | | | | Change-Id: I243d12b75a07ac04560b444c326bff77d0dc642c Fixes: QTBUG-74087 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | qqmljs.g: reduce number of conflictsFabian Kosmale2019-09-032-62/+91
| | | | | | | | | | | | | | | | | | | | | | | | First, let the lexer create a T_FUNCTION_STAR token for "function *", which makes the job of the parser significantly easier. Then, by using GeneratorDeclaration instead of GeneratorExpression, we can avoid the conflicts between UiObjectMember and PrimaryExpression Change-Id: Ib08918e3977ed1a80cdea0948da80bf37886f7de Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | Visit lists iteratively when determining source locations in QMLFabian Kosmale2019-09-031-17/+44
| | | | | | | | | | Change-Id: I35d44de09f9d4133eb82490a1edb57eb374ff2f1 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | qqmljs.g: reduce number of conflictsFabian Kosmale2019-08-291-0/+1
|/ | | | | | | | | | | | | Use right associativity to tell the parser to shift directly when encountering an else statement. This is the wanted behavior, as the "else" should be associated with the last "if" statement. This removes one more shift/reduce conflict in the grammar. See also https://stackoverflow.com/a/12734499 (qlalr behaves like Bison/Yacc here). Change-Id: Id29f00b5a2862fdb3399e4c8a183eda2ed328ba4 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Support top level generator functionsFabian Kosmale2019-07-232-2/+10
| | | | | | | | | | | | | Extends grammar to support generator functions in QML components and adjusts codegen accordingly The corresponding test case must be blacklisted in tst_qmlmin, as qmlmin cannot handle yield statements Fixes: QTBUG-77096 Change-Id: I47d45dd56289cdf073b41932a585259d3052de04 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* QML Grammar: deduplicate semicolon rulesFabian Kosmale2019-07-151-52/+29
| | | | | | | | | | There were quite a few rules which were essentially the same, only differing in whether they matched T_SEMICOLON or T_AUTOMATIC_SEMICOLON By introducing a new rule, we can match both at the same time Change-Id: I46391e310e44ffa8bea03304a9c0726ffc872211 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Split compiler and runtime more clearlyUlf Hermann2019-07-111-1/+0
| | | | | | | | Provide different export macros and different top level headers for each, don't include runtime headers from compiler sources. Change-Id: I7dc3f8c95839a00a871ba045ec65af87123154be Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix parsing of qml signals with multiple new-style type parametersSimon Hausmann2019-07-101-5/+17
| | | | | | | | | | | Amends 0844d1db03410ac88b4ce6b16f68a073b030b248. The modified examples show that the rule of multiple parameters was missing (with the colon) and the single entry colon rule must also come first in order to identify the use correctly. Change-Id: Ic625e2d4b7b0282e6f2289c8be347c36fe81e4c5 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add support for type script QML signal parameter declarationsSimon Hausmann2019-07-092-2/+14
| | | | | | | | | | | | | | | | We support signal(int param) but we should also support signal(param: int) for consistency with the syntax now supported for functions. Change-Id: Ic064bbaac45024d3663562819f3c1f3f4a918a56 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add support for C++ accessible typed parameters and return types in qml ↵Simon Hausmann2019-07-092-0/+29
| | | | | | | | | | | | functions These can be declared using the new typescript-like syntax and using type names that are also used for signal parameters and property types. This merely affects their signature on the C++ side and allows the corresponding invocation. Change-Id: Icaed4ee0dc7aa71330f99d96e073a2a63d409bbe Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Allow all basic QML types for type annotationsSimon Hausmann2019-07-091-0/+9
| | | | | | | | In particular this permits the JS reserved keywords such as "int" or "double". Change-Id: Ice29e3696d8cba2121ef487cd0b099dd8b082022 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Collect type information for function parametersSimon Hausmann2019-07-092-5/+10
| | | | | | Change-Id: Ia9ba819ce77eee7e582cf90aacf5baa4813d9fca Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix internal boundNames() API to expose optional typesSimon Hausmann2019-07-092-12/+34
| | | | | | | This allows extracting the type information for variable declarations. Change-Id: I1241df3b27ae292b83392d5caaa1587caafa46a3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add basic type annotation support for QML functions to the grammarSimon Hausmann2019-07-095-96/+345
| | | | | | | | | | | | | | | | | | | | | | | | | Inspired by TypeScript syntax, allow optional type annotations in the style of ": <name of type>" in for the parameters of functions and their return type. These annotations are not used at the moment, so by default we produce an error message when encountering them in the AST. In addition their usage is limited to functions declared in the QML scope. All other uses attempt to produce readable syntax errors. So for example this is okay: Item { function blah(param: string) string { ... } } And this is not okay: // some file.js function blah(param: string) : string { ... } Change-Id: I12d20b4e2ce92e01108132975a06cfd13ba4a254 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Move the memory pool into the common codeUlf Hermann2019-07-085-260/+5
| | | | | | | We need it in both, the compiler and the runtime. Change-Id: Iffacb9d150bf9eef6ef477bfd427dbac9bf49359 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* extend grammar for better version parsing supportFabian Kosmale2019-07-047-13/+136
| | | | | | | | | | | | | | | | | | Be more strict in parsing version numbers This also makes it easier to access the version number in other places using the Visitor interface, like (soon) the linter and avoids reparsing the text twice. Potential disadvantages: previously allowed import statements will rejected at parse time, e.g. import QtQuick 0b10 Potential further advantage: Weird import statements like import QtQuick 0b10 will be rejected earlier Change-Id: Ifcd187b79a90952bc964c688afa4ea9b158e5109 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Simplify errors and diagnosticsUlf Hermann2019-06-144-76/+51
| | | | | | | | | | | | | | | | We only need two classes to describe all possible diagnostics: * A low-level private POD DiagnosticMessage. This is easily copied and passed around internally. It doesn't need to adhere to a stable API and it doesn't carry any extra baggage. * The high-level public QQmlError with its stable interface. This can internally also use a DiagnosticMessage as storage. Change-Id: I52be88d9b5d9855a661b8032b01eedb43a0fb0b3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Merge remote-tracking branch 'origin/5.12' into 5.13Qt Forward Merge Bot2019-06-061-0/+45
|\ | | | | | | Change-Id: I59cb196ab17ed8504b33db01d827052eb6891efa
| * Parser: Accept templated readonly propertiesUlf Hermann2019-05-311-0/+45
| | | | | | | | | | | | Change-Id: I37d313e3156a44eb4487b1be007aa93ace18d882 Fixes: QTBUG-76018 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Merge remote-tracking branch 'origin/5.12' into 5.13Qt Forward Merge Bot2019-05-261-4/+0
|\| | | | | | | Change-Id: I208cd36d2b7add94f36e4d86cf0c790a1e4a7e86
| * Don't add local for anonymous function's "name"Ulf Hermann2019-05-211-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | Instead, populate their "name" property directly from the surrounding object pattern if applicable, without adding locals. This fixes some ecmascript tests where functions were assigned to the key "eval" in an object. The JS engine then rejected that because you shouldn't use eval in strict mode. That should be close enough to test for regressions. Fixes: QTBUG-75880 Change-Id: Iacc45a3f7b0eb90cddc6ecf6d2bada616d2cf355 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* | Eliminate QT_QML_BEGIN_NAMESPACE and QT_QML_END_NAMESPACEShawn Rutledge2019-03-2213-30/+26
| | | | | | | | | | | | | | These are equivalent to the usual namespace macros. Change-Id: I3891397511e29694fe508414e77eb8483b877e03 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | Merge remote-tracking branch 'origin/5.12' into 5.13Qt Forward Merge Bot2019-03-185-29/+58
|\| | | | | | | | | | | | | Conflicts: src/qml/compiler/qv4codegen.cpp Change-Id: I66b7db42bf208855889094ace0267326595ce03c
| * Unify the JavaScript parsing recursion checksUlf Hermann2019-03-154-14/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | We only need to check in one central location and we can allow for more recursion. 4k recursions seem tolerable. A common default for stack sizes is 8MB. Each recursion step takes up to 1k stack space in debug mode. So, exhausting this would burn about half of the available stack size. We don't report the exact source location in this case as finding the source location may itself trigger a deep recursion. Fixes: QTBUG-74087 Change-Id: I43e6e20b322f6035c7136a6f381230ec285c30ae Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
| * Save some stack space during code generationUlf Hermann2019-03-142-18/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Result objects are rather large, 96 bytes here. In a recursive algorithm such as our parser, we should not keep too many of them on the stack. Also, the size of Reference can be reduced by employing a bit field rather than a number of booleans. Also, try to convince the compiler to inline the accept() functions. The extra stack frames those create are unnecessary. Task-number: QTBUG-74087 Change-Id: I5c064491172366bb0abef99ffe9314080401a7d1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Merge remote-tracking branch 'origin/5.12' into 5.13Qt Forward Merge Bot2019-02-201-2/+6
|\| | | | | | | Change-Id: I69c3e6610ff590d9c18f386fc17ed2e429b58d26
| * QML: Don't crash the parser on certain kinds of bad inputUlf Hermann2019-02-181-2/+6
| | | | | | | | | | | | Fixes: QTBUG-72734 Change-Id: I92146ec517c6a26a67e13830618e137f2a3021c2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>