aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser/qqmljsast_p.h
Commit message (Collapse)AuthorAgeFilesLines
* 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-3/+8
| | | | | | | | | | | | | 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-141-3/+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>
* Pass the raw string value to template literalsLars Knoll2018-11-021-2/+3
| | | | | | | | They are required for spec compliance of tagged templates. Change-Id: I8ef8e2314843f07a02d204394400f3f3894f8f91 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Correctly create methods for functions in object literalsLars Knoll2018-08-311-0/+1
| | | | | | | | | | Methods behave slightly different than normal functions as they have a home object and define how super property access is being done. To implement this correctly, we need to create these methods during object initialization time. Change-Id: Ib3f670c8790b882c6472de786938ca4f0b73f66f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix usage of const in for declarationsSimon Hausmann2018-08-151-0/+1
| | | | | | | | | | | | | | | We correctly produce a syntax error for a const declaration that is without an initialize, such as const x; but we have to make an exception if it's part of a for declaration, such as for (const x of [1, 2, 3]) Change-Id: Iab86d73f2edc1f3deaf62f0f43f8b04789696b65 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Simplify ES module body handlingSimon Hausmann2018-08-141-52/+2
| | | | | | | | | Now that ImportDeclaration and ExportDeclaration are also statements in the AST, we can get rid of the ModuleItemList in the AST. We keep it in the grammar, but map it to a statement list. Change-Id: I4cab29fe9b075e88454fe3b194126f728000856a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix module dependency handlingSimon Hausmann2018-08-141-2/+2
| | | | | | | | | | | | | | | | | | | | | 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>
* Fix multi variable module import listsSimon Hausmann2018-08-141-1/+1
| | | | | | | | Select the correct head when finishing the linked list for ImportList AST nodes. Change-Id: I34ae2ccfd0e969dbd92ce2458de019bb02046aa5 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix support for default exports in modulesSimon Hausmann2018-08-101-4/+4
| | | | | | | | | | | Default export declarations require a binding setup step at run-time, so we hook it into the ESModule's statement list to make it visible to the code gen visitor. We also reserve local slot zero for the default export. Change-Id: Ie064caad0422b92cfdadbd7d94db72a05e95c0cc Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Add initial basic support for ES6 modulesSimon Hausmann2018-08-091-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The entry point from the parsing perspective into modules is not QV4::Script but QV4::ExecutionEngine::compileModule. For convenience, the ESModule AST node gets a body, which is the statement list connected between the ModuleItemList items that are not import/export declarations. The QV4::Module allocates a call context where the exported variables are stored as named locals. This will also become the module namespace object. The imports in turn is an array of value pointers that point into the locals array of the context of the imported modules. The default module loading in ExecutionEngine assumes the accessibility of module urls via QFile (so local file system or resource). This is what qmljs also uses and QJSEngine as well via public API in the future. The test runner compiles the modules manually and injects them, because they need to be compiled together with the test harness code. The QML type loader will the mechanism for injection in the future for module imports from .qml files. Change-Id: I93be9cfe54c651fdbd08c5e1d22d58f47284e54f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Simplify parsing of pragma directivesLars Knoll2018-08-011-42/+3
| | | | | | | | 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/+466
| | | | | | | | | | | | | 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>
* Merge remote-tracking branch 'origin/5.11' into devQt Forward Merge Bot2018-07-161-1/+1
|\ | | | | | | | | | | | | | | Conflicts: src/quick/items/qquickloader.cpp tests/auto/quick/qquickanimations/tst_qquickanimations.cpp Change-Id: I0cb9f637d24ccd0ecfb50c455cc210119f744b02
| * Fix conversion of numeric literals in the AST to stringsSimon Hausmann2018-07-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | After commit 91f3687ee51db83d9018bd61c3fbc736c6e9912e in qtbase, QString::number includes a zero padding in the exponent that breaks compliance with the ECMAScript tests. Instead of QString::number, we have to use a QLocale instance that turns off the padding of the exponent. Change-Id: Ib8c63bc501cadca026c52359006628f6c271ba6d Task-number: QTBUG-69432 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* | Fix naming of classes in class expressionsLars Knoll2018-07-031-1/+5
| | | | | | | | | | | | | | | | As with function expressions, class expressions also get an implicitly defined name if they are directly assigned to a named variable. Change-Id: I5fda9d74c1c299107f15b82245333b54ca6d8917 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Properly distinguish between class expressions and declarationsLars Knoll2018-06-261-0/+14
| | | | | | | | | | | | | | | | 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>
* | Fix string memory leak in JavaScript ASTSimon Hausmann2018-06-251-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Commit 02252ae08d introduced a QString member in a JS memory pool class, which leaks unfortunately as the pool is not designed to call destructors of allocated types. Typically strings in the AST are derived from input and therefore a QStringRef is fine. The bindingIdentifier in the PatterElement however is sometimes synthesized, so a separate storage for dynamically allocated strings in the memory pool allows for using QStringRef again. Change-Id: I94d090df653d784c554452722b3b759031e4735b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* | Fix more issues with destructuringLars Knoll2018-06-211-7/+9
| | | | | | | | | | | | | | | | | | | | Fix destructuring targets that are complex lhs expressions. There are still some failures remaining, but this fixes another larger chunk of test cases. Change-Id: Icf08f42d7c70d4e81be5d5d2e27ebe6249d25467 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix handling of elisions in destructuring expressionsLars Knoll2018-06-211-9/+0
| | | | | | | | | | | | | | | | We need to iterator over elisions at the end, as those could trigger side effects by calling iterator.next() Change-Id: Ieb5fa3562b6e60fdf179fa228510b2eeaaf9da30 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Unify AST for the different 'for' statementsLars Knoll2018-05-111-29/+4
| | | | | | | | | | Change-Id: I70ca83b0ce933d64dad4984a236e48592e989742 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Improve for-in and for-of supportLars Knoll2018-05-111-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | Create a Block scope per iteration as defined in the ES spec. So closures created inside the loop will remember the iteration variable at that loop iteration. Add support for destructuring of the left hand side expression or declaration. Change-Id: Id06ef94e2a4b93646827da4f6ce922eb436e5a31 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Unify ForeachStatement and LocalForeachStatement in the ASTLars Knoll2018-05-111-34/+7
| | | | | | | | | | | | | | | | 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>
* | Support destructuring inside catch()Lars Knoll2018-05-111-4/+4
| | | | | | | | | | Change-Id: Ib60b56ac6a7111446e01235564a4cf92ad8ad025 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Add some basic support for for-of loopsLars Knoll2018-05-091-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | The support is basically at the same level as for for-in at the moment. Currently unimplemented: * Destructuring * Proper lexical scoping * calling iterator.throw()/return() when required Change-Id: If193ce0b054c4315fc16b7e174334a31b2730dcf Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix destructuring of arrow function parametersLars Knoll2018-05-021-0/+8
| | | | | | | | | | Change-Id: I64b49ae77ecd81eafb320cda04a1a7bf4b2dc90c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Properly set names of most anonymous functionsLars Knoll2018-05-021-0/+10
| | | | | | | | | | | | | | | | In ES6, anonymous functions assigned to a variable/property with a known name, inherit the name of that variable/property. Change-Id: I79479b9358b24d610e3e696eb19fe0ec4aee15d1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Support destructuring assignmentsLars Knoll2018-04-271-19/+34
| | | | | | | | | | | | | | | | Not everything works yet, but basic destructuring assignments do. Change-Id: I5f74691fd6458092ecfde9d1a8a802f99fc57b9e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Use a PatternElement for VariableDeclarationsLars Knoll2018-04-271-42/+21
| | | | | | | | | | | | | | 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-338/+152
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-15/+15
| | | | | | | | | | | | | | | | | | | | | | | | 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/+66
| | | | | | | | | | 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/+24
| | | | | | | | | | | | | | | | | | 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>
* | smaller cleanupLars Knoll2018-04-271-4/+5
| | | | | | | | | | | | | | | | The VariableDeclaration constructor shouldn't specify the scope of the declared variable. Change-Id: I1368cec7c5cb8535e169c0fc20d3be4e69368b47 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Add support for '...' in arguments lists to the ASTLars Knoll2018-04-271-0/+1
| | | | | | | | | | | | | | No support in the codegen yet. Change-Id: I9998d7abae086660fc0457c65b6d9050933a428f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Add support for ... in ArrayLiterals to the ASTLars Knoll2018-04-271-0/+1
| | | | | | | | | | | | | | The codegen still throws a syntax error for now. Change-Id: I8134b27d6153f6d6df81a9bafc7ae9d573085b73 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Implement support for the ** and **= operatorsLars Knoll2018-04-261-0/+2
| | | | | | | | | | Change-Id: I58a21e70fdd040175b52465d6ba52e7fceaf6398 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Add support for 'super' and 'new.target' to the ASTLars Knoll2018-04-261-0/+21
| | | | | | | | | | | | | | 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-1/+26
| | | | | | | | | | | | | | | | Computed property names currently work in object literals and destructuring arguments. Change-Id: I9dc5bc61b45139ef1836072695ea2fe1ce4994ae Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix length property of Function objectsLars Knoll2018-04-261-2/+18
| | | | | | | | | | | | | | | | | | | | | | According to ES6, the length property is the number of required arguments, ie. the number of arguments until the first arg that has adefault parameter. Also fix a crash when parsing a parameterlist with a trailing comma. Change-Id: I4f6b2be4feae7b513388be66b43b160bb3cc77f1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Add support for arrow functionsLars Knoll2018-04-261-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Arrow parameter lists are tricky and require some reparsing by the standard to avoid conflicts in the parser with expression statements. Add an IsArrowFunction flag to the CompiledData::Function. This information is required in the runtime, when creating Function objects, as it does influence their behaviour in subtle ways. Change-Id: I298801b091f98e30a9269d3c77d9ff94e519dabc Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Bring JS grammar in line with ES7 specLars Knoll2018-04-251-185/+127
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Support for destructuring arraysLars Knoll2018-04-251-4/+28
| | | | | | | | | | | | | | | | add support for destructuring of arrays when passing arguments to functions. Change-Id: I19feb39aa3ae520ec7591d49d1b14ceaa78783c6 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Partially support binding patternsLars Knoll2018-04-251-21/+159
| | | | | | | | | | | | | | | | Destructuring objects works, but arrays are not yet supported. Change-Id: I61e917e1964e3c719f71b8f11d194e09dfe288c2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Some renamingLars Knoll2018-04-251-2/+2
| | | | | | | | | | | | | | | | Rename defaultExpression to initializer, and the fix the spelling of Initialiser to Initializer. Change-Id: I049039a742bdb77cb5f6beab9a28ff3b6f47a605 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Correctly check for duplicate parameter namesLars Knoll2018-04-251-0/+12
| | | | | | | | | | | | | | | | Those are not allowed as soon as we have default values for parameters or rest arguments. Change-Id: I7dec826c37e6045e4dd1f6b0adb90301efe33daf Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | ES6: add support for default arguments for function parametersLars Knoll2018-04-251-3/+10
| | | | | | | | | | | | | | | | | | The parser can also handle rest parameters correctly, this will however require some additional work in the runtime to support it correctly. Change-Id: Ib6f4d27683774966b2d2aac075494d2f5066d2a2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Implement support for tagged templatesLars Knoll2018-04-251-0/+23
| | | | | | | | | | | | | | 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/+24
|/ | | | | | | | | | | | | 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>
* init variables where they are declared when possible (clang-tidy)Shawn Rutledge2018-02-261-6/+5
| | | | | | | | clang-tidy -p compile_commands.json $file -checks='-*,modernize-use-default-member-init,readability-redundant-member-init' -config='{CheckOptions: [{key: modernize-use-default-member-init.UseAssignment, value: "1"}]}' -header-filter='qtdeclarative' -fix Change-Id: I705f3235ff129ba68b0d8dad54a083e29fcead5f Reviewed-by: Johan Helsing <johan.helsing@qt.io>