aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser/qqmljsastvisitor_p.h
Commit message (Collapse)AuthorAgeFilesLines
* QMLJSASTVisitor. Add JSVisitorDmitrii Akshintsev2024-02-141-0/+24
| | | | | | | | | | | | This proxy visitor is helpful to be used in the cases where traversing only JS AST Nodes is needed, for example when formatting plain JS files This also allows to get rid of some of the same trivial implementations. Task-number: QTBUG-117849 Change-Id: If7d8086032f286b0cc7559df7f0f0ab9869bd12e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* Use X-Macro for AST-visitor declarationSami Shalayel2023-04-121-650/+133
| | | | | | | | | Use the X-Macro to simplify the AST-Visitor and BaseVisitor definitions. Task-number: QTBUG-92876 Change-Id: I8f20490ae551a27a50cd037eb705baac3673eba5 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Kill TypeArgument(List)Sami Shalayel2023-04-121-6/+0
| | | | | | | | | | | Remove the forward declarations of TypeArgument(List) and its uses. This amends e89a06753c772bd96b3299e03b2f7ad78ffc9fb9 that removed TypeArgument(List)'s definition while leaving its forward declarations and uses around. Change-Id: I1a3e27ce18611beaf84b7c59e01a622f9e7f2477 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QML: Allow pragmas with multiple valuesUlf Hermann2023-02-221-0/+4
| | | | | | | | | 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>
* Parser: Simplify argument "lists" for type annotationsUlf Hermann2022-10-191-4/+4
| | | | | | | | | | 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>
* 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>
* Fix 'as' binary operation using invalid typesMaximilian Goldstein2020-05-201-0/+6
| | | | | | | Fixes: QTBUG-81392 Change-Id: Ic83091c547a7854b7fa86b44d93c575bd7426bae Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add UiAnnotation for annotation objectsFawzi Mohamed2020-02-121-0/+4
| | | | | | | | | | 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-234/+565
| | | | | | | | | | 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-121-3/+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>
* Add annotations to ASTFawzi Mohamed2020-02-121-0/+2
| | | | | | | | | | | | | | | | | | | | 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-311-0/+3
| | | | | | | | 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>
* Long live QML inline componentsFabian Kosmale2020-01-231-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | [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>
* Add basic type annotation support for QML functions to the grammarSimon Hausmann2019-07-091-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* extend grammar for better version parsing supportFabian Kosmale2019-07-041-0/+2
| | | | | | | | | | | | | | | | | | 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>
* Eliminate QT_QML_BEGIN_NAMESPACE and QT_QML_END_NAMESPACEShawn Rutledge2019-03-221-2/+2
| | | | | | | These are equivalent to the usual namespace macros. Change-Id: I3891397511e29694fe508414e77eb8483b877e03 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Unify the JavaScript parsing recursion checksUlf Hermann2019-03-151-1/+35
| | | | | | | | | | | | | 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>
* Fix module dependency handlingSimon Hausmann2018-08-141-3/+0
| | | | | | | | | | | | | | | | | | | | | The evaluation of a module can have side-effects by modifying the global object or objects in it. Therefore even a seemingly empty import such as import "./foo.js" needs to be listed in the module requests. It's also important that they are evaluated in the order of declaration. Therefore we collect all module requests separately - even those that don't have import variables to process. This patch also ensures that the export and import declarations are visited in the correct order, by unifying both AST nodes to be hooked into the statement list. The fact that we connect the module list items into a statement list is solely an artifact of re-using defineFunction() which takes a StatementList as body. Change-Id: I75dc357b2aecfc324d9a9fe66952eff1ec1dfd8a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Simplify parsing of pragma directivesLars Knoll2018-08-011-2/+0
| | | | | | | | We only support 'pragma Singleton' currently, so there is no need to parse the right hand side of pragma as a member expression. Change-Id: Ic0dcbedb52cb58db2fd1cc099f14fd399b7162e3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Build AST nodes when parsing ES6 modulesSimon Hausmann2018-07-311-0/+42
| | | | | | | | | | | | | This introduces the structures in the AST that allow for the extraction of imports, exports as well as location of tokens. The ModuleItemList as entry point is special with regards to the statements (so not import/export declarations) in the sense that the statement list contained in ModuleItemList::item is not linked yet between different ModuleItemList instances. Change-Id: If553a6ebaf53d5f3cf755c8327d3fe0ea7db68c2 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Properly distinguish between class expressions and declarationsLars Knoll2018-06-261-0/+3
| | | | | | | | Introduce both types in the AST, and handle them properly in the code generator. Change-Id: I754ac0976de69009bdb8b203d890e4ec0ad03b30 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Unify AST for the different 'for' statementsLars Knoll2018-05-111-3/+0
| | | | | Change-Id: I70ca83b0ce933d64dad4984a236e48592e989742 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Unify ForeachStatement and LocalForeachStatement in the ASTLars Knoll2018-05-111-3/+0
| | | | | | | | This saves quite some duplicated code, but requires a bit of care when iterating over the AST. Change-Id: Ic530de4be8b36b4079c9d544b4b77982c3b8be60 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Use a PatternElement for VariableDeclarationsLars Knoll2018-04-271-3/+0
| | | | | | | Required to get proper destructuring working. Change-Id: I99fc20a9f1bace1fe3981d88ce5466f9c8d98245 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Rework the AST for Literals and destructuring expressionsLars Knoll2018-04-271-28/+10
| | | | | | | | | | | | | | | | | Array/ObjectLiterals and destructuring expressions are syntactically very similar. In some cases (when using a destructuring expression as the lhs of an assigment), the parser needs to convert the literal into a destructuring expression. To support these, use the same data structures for both in the AST. Those Patterns can be converted with little additional work from a Literal to an AssignmentPattern and be used in all places where we need destructuring in addition to literals. Change-Id: I177599b46eab0f6e8cb2a40c3b3b11ed00a07d6a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Rename Array/ObjectLiteral to Array/ObjectPattern in the ASTLars Knoll2018-04-271-4/+4
| | | | | | | | | | | | To get a consistent representation in the AST, we need to unify the AST that is generated by theObjectLiterals, ObjectBindingPattern and ObjectAssignmentPattern rules in the grammar. Like this we can avoid having to reparse part of the source code, and instead replace this with consistency checks once we know which of the three grammars are supposed to apply. Change-Id: Ib90f521f9595db6bcad446e40de9b912bab3da7c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add support for 'class' to the ASTLars Knoll2018-04-271-0/+6
| | | | | Change-Id: I2a9e8fb847dfa45ca77ee43e14f39f2b2def5792 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Added support for generator functions and yield expressions to the ASTLars Knoll2018-04-271-0/+3
| | | | | | | | | Some smaller changes to the codegen are included as well to ensure that we catch all uses of generators and properly throw an unimplemented error on them for now. Change-Id: Ib915a0e862e128644ff00dfe989507783c912c66 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add support for 'super' and 'new.target' to the ASTLars Knoll2018-04-261-0/+3
| | | | | | | Codegen will still throw a Syntax error on it though. Change-Id: I292dd166ad8cb4a62f2bcfa9637bdc76cf95bb51 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add partial support for computed property namesLars Knoll2018-04-261-0/+3
| | | | | | | | Computed property names currently work in object literals and destructuring arguments. Change-Id: I9dc5bc61b45139ef1836072695ea2fe1ce4994ae Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Bring JS grammar in line with ES7 specLars Knoll2018-04-251-14/+8
| | | | | | | | | | | | | | | | | | | | | | | This basically updates all grammar rules in the qqmljs.g file to be in line with the ES7 specification. Some special handling for the lookahead rules appearing in the spec was needed and is implemented through empty lookahead rules in the grammar, that might push an additional token into the token stream. Renamed some classes in the AST to be in line with the names used in ES7, and removed some other ones (SourceElements) that are no longer used. The ES7 grammar rules contain lots of variations of the base rules (with In/Return/Yield/Default suffixes). With the exception of the In and Default rules, these are implemented through state tracking in the parser and lexer. Change-Id: I4017d97cd050ed816c1dad11833e882cba30801a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Partially support binding patternsLars Knoll2018-04-251-0/+12
| | | | | | | | Destructuring objects works, but arrays are not yet supported. Change-Id: I61e917e1964e3c719f71b8f11d194e09dfe288c2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Implement support for tagged templatesLars Knoll2018-04-251-0/+3
| | | | | | | Get Foo`...` to work as intended by the spec. Change-Id: If6ccdd7486d3c983c177a3e126e3a661e210a8ae Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add support for ES6 template stringsLars Knoll2018-04-251-0/+3
| | | | | | | | | | | | | This requires a bit of bookeeping in the lexer, as we can have arbitrary expressions inside the ${...}. To make this work, keep a stack of template states, in which we count the unclosed braces to match up with the correct closing brace. Implements support for `...`. Expressions of the type Foo`...` and Foo()`...` will come in follow-up commits. Change-Id: Ia332796cfb77895583d0093732e6f56c8b0662c9 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add support for enum declarations in QMLMichael Brasser2017-07-131-0/+4
| | | | | | | | | | | | | | | | | Enums can be declared with the following syntax: enum MyEnum { Value1, Value2 } Grammar changes done by Simon Hausmann. [ChangeLog][QtQml] Enums can now be declared directly in QML. Task-number: QTBUG-14861 Change-Id: Ic6b6e032651d01ee2ecf9d5ce5734976cb3ad7ab Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Updated license headersJani Heikkinen2016-01-191-14/+20
| | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: Ic36f1a0a1436fe6ac6eeca8c2375a79857e9cb12 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Update copyright headersJani Heikkinen2015-02-121-7/+7
| | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Change-Id: I61120571787870c0ed17066afb31779b1e6e30e9 Reviewed-by: Iikka Eklund <iikka.eklund@theqtcompany.com>
* Update license headers and add new licensesJani Heikkinen2014-08-251-19/+11
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 & LICENSE.GPLv2 - Removed LICENSE.GPL Change-Id: I84a565e2e0caa3b76bf291a7d188a57a4b00e1b0 Reviewed-by: Jani Heikkinen <jani.heikkinen@digia.com>
* Add Singleton support for QMLAntti Piira2013-09-211-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This introduces Singleton support for QML (Composite Singleton). For now, the Singleton support is only availabe for QML types in modules or (remote and local) directories with qmldir file. However, in the future this support may be expanded to arbitrary QML file imports without by leaving out the qmldir requirement. You define a QML type as a Singleton with the following two steps: 1. By adding a pragma Singleton to a type's QML file: pragma Singleton The pragma and import statements can be mixed and their order does not matter. Singleton is the only supported pragma for now. Others will generate errors. 2. By specifying a qmldir file for the directory of your imported type and prepending the type with "singleton" keyword as follows: singleton TestTypeSingleton TestTypeSingleton.qml Alternatively you may specify a qmldir file for a module and specify your type as a singleton as follows: singleton TestTypeSingleton 1.0 TestTypeSingleton.qml Composite Singletons may be included in a module and may be used with a local namespace qualifier when imported with: "import xxx as NameSpace" A singleton instance is created at first use and stored into the QmlEngine (one instance per engine) and eventually released by the engine's destructor. CompositeSingletonType has a dual nature and will return true to both isComposite() and isSingleton() calls. In most cases its enough to check for just isComposite() or isSingleton(). However, there is a isCompositeSingleton() available as well. I used "qlalr --no-debug --no-lines --qt qqmljs.g" to generate the qqmljsparser and qqmljsgrammar files from qqmljs.g. Unit tests are included. Change-Id: I91b303612c5e132143b325b9a8f982e9355bc90e Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
* Move the parser folder from src/qml/qml to src/qmlLars Knoll2013-08-081-0/+337
Change-Id: I5e5684f5b98b00f791ade99c4cb6bc2ed880ad6a Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>