aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser/qqmljsast_p.h
Commit message (Collapse)AuthorAgeFilesLines
* Add file locations for Pragma keyword, id and the valuesSemih Yavuz2024-04-111-0/+1
| | | | | | | | | | | | | | | | | | Add missing identifier token location in the grammar file. Implement the missing file location regions for Pragma dom element. Those regions are the way to get source location of the corresponding dom element in the Dom API. It is needed in semantic highlighting implementation. Adding new region breaks a few of the pragma completions tests since it changes the closest item found and this makes the assumption that colon region exist wrong . Fix it by passing the Pragma element instead of the subelements of it to insidePragmaCompletion function. This guarantees that we find the ColonTokenRegion in the current item. Task-number: QTBUG-123775 Task-number: QTBUG-120000 Change-Id: I2759412810ce125d6ee36bb0d70509a859667266 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlls: completions in variable declarationsSami Shalayel2023-12-051-1/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add the equal token sourcelocation into a ScriptPattern. This is somewhat cumbersome because the parser has no direct access to it. Instead, create a new ExpressionNode type called InitializerExpression: it contains an ExpressionNode and an equaltoken, and is populated in the parser for Initializer and Initializer_In rules. It also implements some pure virtual methods to not be abstract, and has its own Kind_InitializerExpression. The PatternElement constructor extracts the location of the equaltoken from the InitializerExpression in its constructor, and saves it in its new member equaltoken. Later on, the Dom constructor will be able to add the location of the equal token to the Dom, such that qmlls's completion can decide whether or not completion is required in variable declaration statements. With this commit, qmlls will provide completions only after the above mentioned equal token. The explanation is in a comment in qqmllsutils, but the rough idea is that everything before the '=' is a variable name (so it should not be in use yet, to avoid shadowing and confusing QML programs) and that everything behind a '=' is a default value that can be any arbitrary expression in JS. This default value can be a method name, a property name, etc, so provide completion at this place. Also takes care of completions inside of deconstructions nested inside variable declarations. Task-number: QTBUG-117445 Change-Id: Ie58ffda4de9636796a9a690537affef85ede398d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlls: fix completions on qualified identifiersSami Shalayel2023-11-161-0/+1
| | | | | | | | | | | | | | | | | | | | Typing `someProperty.x` would propose methods and properties that do not exist in someProperty in qmlls. Add the operator sourcelocation inside the BinaryExpression so that qmlls can distinguish if currently working on the left or right hand side of the binary expression. Also fix the resolveExpressionType call to not use the last bit of the qualified identifier: in `console.l`, only resolve up to `console` and ignore the `l` bit that might not have been spelled out completely. Previously, the resolution step would fail because of the `l` and no completion would get generated. Task-number: QTBUG-117445 Change-Id: I5929d7153d5b9f5104efd1b88d24d76e0d7a514a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* qmlls: add completion for pragmasSami Shalayel2023-09-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | To be able to decide how a pragma is completed, one needs to know if we are before or after the ':', for example in 'pragma NativeMethodehavior: AcceptThisObject', one needs to know if we are completing the pragma names or the pragma values. For this, add a sourcelocation for the colon in AST::UiPragma in the parser, and pass it on in the FileLocations so the sourcelocation of the colon, when existing, can be accessed from the DomItem. Once the position of the colon is known, the names or values for the pragmas can be completed. To easily obtain the position of the colon of a DomItem, move some code from the Binding completion into a static helper to reuse it for pragmas. Also fix some typos in the warning messages about invalid pragmas in qqmljsimportvisitor. Task-number: QTBUG-116899 Change-Id: Ib20bb6aa50e9b8dc5830f426d0ca9719693c0a15 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlls: highlight names inside of inline component definitionsSami Shalayel2023-08-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of highlighting the base type of the inline component, highlight the name of the inline component, e.g. highlight 'C' in ``` component C: Item {} ``` instead of 'Item'. This requires changing QQmlLSUtils::findTypeDefinitionOf's signature to return a QQmlLSUtilsLocation instead of a DomItem. QQmlLSUtils::findDefinitionOf already returns a QQmlLSUtilsLocation. Also, the QQmlJS::UiInlineComponent parser class did not know about its identifier token. Add it, so the corresponding DomItem knows where its identifier lies. Fix the tests that finds definitions of inline components by removing the QEXPECT_FAIL and adjusting the column numbers. Also simplify the test by removing the "name" that is not related to the actual test. Fix other failing tests by setting their QEXPECT_FAIL at the right place (they fail earlier because of this change, when looking for the type definition of int for example). Change-Id: I00b2f73c2357b7e7fb74619bbc7b948e67619420 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlls: find definitions of function parametersSami Shalayel2023-06-051-2/+4
| | | | | | | | | | | | | | | Function parameter definitions in the QQmlJSScope were lacking their source location, such that asking the definition of a parameter always returned the location of the first parameter. Fix it by writing the proper Location in the QQmlJSScope. This requires adding the location information to BoundName(s). Also added some tests. Task-number: QTBUG-111409 Change-Id: Ieb6155f120ca24e899af4b3824cab561788d008b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* QmlDom: support function parameters and coSami Shalayel2023-06-021-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement function parameters for function definitions in the Dom, as otherwise the unused scriptelements in the stack will make the following script element construction fail. Also implement all the dom elements required by function parameters. Instead of filling in only the script element for the defaultValues, (and failing when encountering more complex expressions), add a ScriptExpression that can model more complex expressions in the argument (including default value, deconstruction, type annotations, etc.) in the Dom::MethodParameter class and leave the pre-existing defaultValue as is for now. Requirements for successful function parameter construction: * Add support for JS arrays and JS objects literals in the Dom. These ones are required to model parameter deconstruction, e.g. to pick certain list elements or object properties from the argument object/array * Fix the iteration order for PatternElementLists and PatternPropertyLists, as both are required for the JS arrays and objects * Add all kind of property names (used in JS object literals and JS object deconstruction) as literals in qqmldomastcreator. * JS array and object deconstruction happened to reveal a bug for VariableDeclarations, fix it (because you can use deconstruction in variable declarations) + add tests for that. * Support Type annotations in the Dom: this means that type annotations for methods are also created and also needs to be collected. Add a field returnType in Dom::MethodInfo for this. * Make sure that all QQmlJSScope's in the Dom are wrapped in optionals (because they are null when the semantic analysis option is not passed) and adapt the getters to it. Task-number: QTBUG-92876 Change-Id: I81df66989e833c9acd75f854b49dcc15b0729e99 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Allow pragmas with multiple valuesUlf Hermann2023-02-221-3/+44
| | | | | | | | | This will be needed in follow-up changes. Task-number: QTBUG-94807 Change-Id: I6243ea31290251c30dd0aceaae878568bc1c0525 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QmlCompiler: Fix recognition of builtin list typesUlf Hermann2022-12-151-4/+4
| | | | | | | | | | | | | Previously all list types used as arguments or return types for methods had to be looked up via the imports. However, builtin types are not part of the imports at run time. Therefore, recognize list types already early on, when generating the IR. This is the same way we do it for property types and it allows us to easily identify lists of builtins. Pick-to: 6.5 Fixes: QTBUG-109147 Change-Id: I91fa9c8fc99c1e0155cc5db5faddd928ca7fabbc Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Parser: Simplify argument "lists" for type annotationsUlf Hermann2022-10-191-44/+21
| | | | | | | | | | There can in fact only be one type argument, and we don't need a finish() method. In fact the finish() method didn't return the type argument at all. Task-number: QTBUG-107171 Change-Id: Ifb7d85ca42a38d37da71b6453b458c7ec10cd64d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qml: fix TypeArgumentListFawzi Mohamed2022-10-191-1/+1
| | | | | | | | | | | | | | | | | | All type annotations in qml did drop any typeArgument due to a bug in TypeArgumentList: instead of keeping a circular list that is inverted while building, and finally transformed in the inverse in the finish() method, it kept a singly linked list and the finish method would return a nullptr. Fix the formatting and indenting of type annotations now that they work. Pick-to: 6.4 Task-number: QTBUG-107171 Change-Id: I9deff83d328c5c0784a4104e406036a435278945 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Explicitly include qtaggedpointer.hIvan Solovev2022-07-011-0/+1
| | | | | | | | | | It is now transitively included from qversionnumber.h (via qmetatype.h), but that will change soon. Pick-to: 6.4 Task-number: QTBUG-102350 Change-Id: Ida458c446ca241f3f603628eb9b2d15c0a546b3e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlast: add missing tokens for enum declarationMoody Liu2022-06-241-0/+2
| | | | | | | this adds possibility for qmlls to highlight an enum name Change-Id: If802bfa3afd8bdcd5eed894fce50bad5907464bf Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQmlJS::AST: Do not dereference nullptr to get static AST kindUlf Hermann2022-06-151-2/+4
| | | | | | | | Coverity-Id: 394805 Change-Id: I7fe8994d28fe9d13a4c441a5c527aeb77ce78b6c Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Use SPDX license identifiersLucie Gérard2022-06-111-38/+2
| | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Pick-to: 6.4 Task-number: QTBUG-67283 Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* QML/AST: Remove dead codeFabian Kosmale2021-11-261-6/+0
| | | | | | | | The qmldevtools library is no more, therefore we can resolve the TODO and remove the method that only existed for it. Change-Id: I685d9305e4b42a34ade56baccce0ec2e49cbcf4a Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Clean up property attributes (2/2)Fabian Kosmale2021-11-171-19/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit introduces a new AST node for property attributes (currently required, default and readonly). That node is not integrated into our visitors, as it is only meant as an internal implementaion detail of UiPublicMember. All information stored in it is meant to be accessed by UiPublicMember's methods (see also the note below). We use an union of SourceLocation and a node pointer to only pay the overhead of the new node for properties; signals simply store the signal token. The grammar is rewritten with a new UiPropertyAttributes rule, which avoids quite a bit of duplication in various rules, which had to deal with the combinatorial explosion of attributes. Some parse errors are now turned into semantic errors instead (readonly without initializer, required with initializer). By centralizing the handling of attributes in the grammar, we now can easily support e.g. default properties with a list initializer. As part of this restructuring, UiPublicMember's firstSourceLocation is fixed to ensure that we actually return the first source location, independent of the order in which the attributes are written. Note: In theory, we would not need to make UiPropertyAttributes an AST node. It could be a simple data class. However, the parser currently assumes that every pointer in its parser stack is an AST node, and touching that part would be a larger undertaking. As we use a pool allocator, the cost is not that high (though we use more memory from the pool then we would strictly need to). Change-Id: Ia1d9fd7a6553d443cc57bc3d773f5be0aebe0e0e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Clean up property attributes (1/2)Fabian Kosmale2021-11-171-14/+25
| | | | | | | | | | | | Instead of directly accessing the attribute related members of UiPublicMember, we access them via a function. Moreover, we remove some redundancy: A property is readonly/default/required if and only if the corresponding token is valid. Thus we can drop the boolean members. Change-Id: I22f15b2b037e857d2f9d3167cb761cba9516a135 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add a Pragma for list assign behaviorUlf Hermann2021-10-131-2/+3
| | | | | | | | | | [ChangeLog][QtQml] You can now specify the list property assignment behavior in QML using the "ListPropertyAssignBehavior" pragma. This is analogous to the macros you can use in C++. Fixes: QTBUG-93642 Change-Id: I9bdcf198031f1e24891f947b0990a3253d29a998 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Treat substitution free template string literals as string bindingsFabian Kosmale2021-07-231-0/+1
| | | | | | | | | | | | Before this change, they were treated as script bindings, which are less efficient, and could not be used in ListElement. Fixes: QTBUG-95139 Pick-to: 6.2 Change-Id: Ic66052c7f58b3ffdf1b7c0c169f42b4f99df62a1 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QQmlJSAst: Silence CodeChecker warningFabian Kosmale2021-05-031-1/+1
| | | | | | | It is an invariant that any UiArrayBinding has a qualifiedId. Change-Id: I62a68f90db39caffc4b97634d8d51317a367b61d Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
* Implement optional chainingMaximilian Goldstein2021-04-131-0/+4
| | | | | | | | | | | | | | | | | This change implements optional chaining (https://github.com/tc39/proposal-optional-chaining) by adding a new type of optional lookup with an offset to the end of a chain. If `undefined` or `null` is encountered during an access marked as optional, we jump to that end offset. Features: - Full support for all kinds of optional chain - With some codegen overhead but zero overhead during normal non-optional FieldMemberExpression resolution - Properly retains this contexts and does not need to resolve anything twice (this has been an issue previously) - No extra AST structures, just flags for existing ones [ChangeLog][QtQml] Added support for optional chaining (https://github.com/tc39/proposal-optional-chaining) Fixes: QTBUG-77926 Change-Id: I9a41cdc4ca272066c79c72b9b22206498a546843 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QV4CompilerScanFunctions: Silence code checker warningFabian Kosmale2021-03-301-2/+5
| | | | | | | | | | | | The AST is constructed in such a way that having exportAll set always implies that a fromClause exists. Also, clean up exportAll: We do not need a separate member to track it. Its value is fully determined by the presence of fromClause and exportsClause. Thus, replace it with a function. Change-Id: Ib7db2bbaf326ecc36a7f4a2986a7c1fb54db6cd5 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML: Warn about usage of injected signal parametersUlf Hermann2021-02-121-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | You should declare functions with formal parameters if you want to use parameters passed by the signal. We need to generate two different warnings because there are two code paths by which such parameters are injected. If we compile with qmlcachegen, it simply inserts a lookup instruction in to the byte code. This lookup then triggers our special hack expressly made for signal parameters. If we don't compile using qmlcachegen, a function declaration with formal parameters is synthesized. We mark those formal parameters as injected and warn if we see one of them used. [ChangeLog][QML][Important Behavior Changes] The automatic injection of signal parameters into signal handlers is deprecated. This is because we cannot determine the names of the signal parameters at compile time. Furthermore, also for human readers it is difficult to discern between arguments, context properties, properties of the current object, and properties of the root object of the component. Requiring the signal parameters to be explicitly named resolves some of this confusion. You can turn the deprecation warning off using the "qt.qml.compiler" and "qt.qml.context" logging categories. Task-number: QTBUG-89943 Pick-to: 6.1 Change-Id: If0a5082adb735a73efd793868b3a55bc7d694cbe Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Port QtDeclarative from QStringRef to QStringViewKarsten Heimrich2020-06-161-73/+73
| | | | | | | | Task-number: QTBUG-84319 Change-Id: I2dcfb8a2db98282c7a1acdad1e6f4f949f26df15 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Fix 'as' binary operation using invalid typesMaximilian Goldstein2020-05-201-0/+21
| | | | | | | Fixes: QTBUG-81392 Change-Id: Ic83091c547a7854b7fa86b44d93c575bd7426bae Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Allow partial and absent version specifiers in import statementsUlf Hermann2020-03-171-0/+5
| | | | | | | | | | An import statement without version specifier imports the latest version available, one with only a major version imports the latest minor version from that major version. Task-number: QTBUG-71278 Change-Id: I43907ae4e1052be533039d545de5391c41d38307 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Merge remote-tracking branch 'origin/5.15' into devQt Forward Merge Bot2020-03-091-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/qml/compiler/qqmlirbuilder_p.h src/qml/qml/qqmlpropertycachecreator_p.h src/qmltyperegistrar/qmltypesclassdescription.cpp src/qmltyperegistrar/qmltypesclassdescription.h src/qmltyperegistrar/qmltypescreator.cpp src/quick/items/qquicktext_p.h src/quick/util/qquickvaluetypes_p.h Change-Id: Ic209741592e7b85820bf3845722023a190ebc1c5
| * 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>
* | Merge remote-tracking branch 'origin/5.15' into devQt Forward Merge Bot2020-02-171-123/+188
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/imports/qtqml/plugin.cpp src/qml/qml/qqml.h src/qml/qml/qqmlmetatype.cpp src/qml/qml/qqmlmetatype_p.h src/qml/qml/qqmltypeloader.cpp src/qml/types/qqmlbind.cpp src/quick/items/qquickitemsmodule.cpp tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp Change-Id: I52548938a582cb6510271ed4bc3a9aa0c3c11df6
| * Add UiAnnotation for annotation objectsFawzi Mohamed2020-02-121-3/+27
| | | | | | | | | | | | | | | | | | | | 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-121-118/+118
| | | | | | | | | | | | | | | | | | | | 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>
| * 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>
| * Add annotations to ASTFawzi Mohamed2020-02-121-2/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge remote-tracking branch 'origin/5.15' into devSimon Hausmann2020-02-031-1/+24
|\| | | | | | | | | | | | | | | Conflicts: src/qml/common/qv4compileddata_p.h tests/auto/qml/qmlmin/tst_qmlmin.cpp Change-Id: Ieabc9e0729630de6a8644024d11b765f35199f29
| * Required properties: Allow retroactive require specificationFabian Kosmale2020-01-311-1/+24
| | | | | | | | | | | | | | | | 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>
* | Use QTypeRevision for all versions and revisionsUlf Hermann2020-02-031-3/+6
|/ | | | | | | | | | | | | | In many places we carry major and minor versions or revisions that are loosely coupled to minor versions. As the Qt minor version resets now, we need to handle these things more systematically. In particular, we need to add a "major" part to revisions. QTypeRevision can express the current major/minor pairs more efficiently and can also be used to add a major version to revisions. This change does not change the semantics, yet, but only replaces the types. Change-Id: Ie58ba8114d7e4c6427f0f28716deee71995c0d24 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Long live QML inline componentsFabian Kosmale2020-01-231-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | [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-051-0/+1
| | | | | | | | | | 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-271-0/+1
| | | | | | | | | | 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-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | 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-101-1/+0
| | | | | | | | 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-171-1/+7
| | | | | | | | | | | | | | | | | | | | | | 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-091-0/+5
| | | | | | | | | | | | | | | | | | | [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>
* 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>
* Support top level generator functionsFabian Kosmale2019-07-231-2/+2
| | | | | | | | | | | | | 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>
* Add support for type script QML signal parameter declarationsSimon Hausmann2019-07-091-2/+3
| | | | | | | | | | | | | | | | 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-091-0/+4
| | | | | | | | | | | | 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>
* Collect type information for function parametersSimon Hausmann2019-07-091-1/+6
| | | | | | 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-091-5/+27
| | | | | | | This allows extracting the type information for variable declarations. Change-Id: I1241df3b27ae292b83392d5caaa1587caafa46a3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>