summaryrefslogtreecommitdiff
path: root/src/qml/compiler/qv4compilerscanfunctions.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Merge remote-tracking branch 'origin/5.11' into devLiang Qi2018-05-111-0/+6
|\ | | | | | | | | | | | | | | | | Conflicts: src/qml/compiler/qv4compilerscanfunctions.cpp tools/tools.pro Done-with: Lars Knoll <lars.knoll@qt.io> Change-Id: Ia77ee6ede6fc9760ce5a03d68079579a63e5a02f
* | Give case blocks a proper scopeLars Knoll2018-05-111-0/+12
| | | | | | | | | | Change-Id: Id307c0426e1c9326ac085cebda71934cb5e612e0 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Give for loops a proper block scope for it's lexically declared varsLars Knoll2018-05-111-0/+7
| | | | | | | | | | Change-Id: I71c40d1d061ac3c1c623dbbf8f7967c9ec35c082 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Unify AST for the different 'for' statementsLars Knoll2018-05-111-10/+0
| | | | | | | | | | Change-Id: I70ca83b0ce933d64dad4984a236e48592e989742 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Improve for-in and for-of supportLars Knoll2018-05-111-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | 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-11/+1
| | | | | | | | | | | | | | | | 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-3/+14
| | | | | | | | | | Change-Id: Ib60b56ac6a7111446e01235564a4cf92ad8ad025 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Ensure we have a lexical scope for global codeLars Knoll2018-05-111-14/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This requires a bit more work than simply pushing a new BlockContext for the lexically declared variables, as eval() and the Function constructor operate on the global scope (including the lexically declared names). To fix this introduce Push/PopScriptContext instructions, that create a BlockContext for the lexically declared vars and pushes that one as a global script context that eval and friends use. Change-Id: I0fd0b0f682f82e250545e874fe93978449fe5e46 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix sanity checks when declaring variablesLars Knoll2018-05-021-8/+1
| | | | | | | | | | Change-Id: Ib2968d4da22eab06b8a82eb7697d5e9fce6dc43d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Avoid excessive creation of contextsLars Knoll2018-05-021-0/+6
| | | | | | | | | | | | | | | | Variables do not escape if they are being used from an inner block in the same function. Change-Id: I494861edf9d8a492930797928a3137362082d084 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Cleanup handling of with() statementsLars Knoll2018-05-021-31/+47
| | | | | | | | | | | | | | | | | | | | | | Add a CompilerContext for with, whose only purpose it is to trigger variable lookup by name. This avoids looking up variables declared inside the with() {} block by name and we do not lookup variables outside the with block by name neither anymore. Change-Id: I52e9fb2daa9601f9e5102714c002dc506ad5ed23 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Rework catch context handlingLars Knoll2018-05-021-8/+23
| | | | | | | | | | | | | | | | | | | | | | | | Remove the need for a specialized catch context, instead use a regular block context, that also captures the catched variable. This also removes the need to do lookups by name inside a catch expression. Change-Id: I8b037add7f423922e2a76b4c0da646ca7e25813a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Add support for proper lexical scopingLars Knoll2018-05-021-5/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | This is still to some extend work in progress as lexically scoped for loops won't yet do the right thing. let and const variables are still accessible before they are declared, and the global scope doesn't yet have a proper context for lexically declared variables. Change-Id: Ie39f74a8fccdaead437fbf07f9fc228a444c26ed Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Split out the generation of indices for locals and registersLars Knoll2018-05-021-4/+5
| | | | | | | | | | Change-Id: I0e98ccba9ae3026cd8bfdc4cae100f280b5aa22c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Refactor variable resolvingLars Knoll2018-05-021-3/+35
| | | | | | | | | | | | | | | | | | | | Move variable resolving into the context, and avoid creating ExecutionContext's whereever we can. This prepares things for block scoping, where this becomes rather important to be able to achieve decent performance. Change-Id: Idf3d3c12cf348a2c3da01989c26c8529ceb36c12 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Rename the CompilationMode enum to ContextTypeLars Knoll2018-05-021-7/+8
| | | | | | | | | | | | | | | | | | And make it an enum class. The new name fits better, as it's mainly used to determine the type of the context when parsing. Also already added the 'Block' value that will be needed. Change-Id: I70d963b6a0b22db1a3c607cce6bdd2054b29e000 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix crashes when parsing functions with no parametersSimon Hausmann2018-05-021-5/+5
| | | | | | | | | | | | | | | | | | | | Commit da5fffbd34d8be68f8ee4c649881dbb673c9c0a5 introduced deferencing of the formals parameter list that can be a null pointer if the declared function has no parameters. Change-Id: Id7dce0f78b16266e672f0ae430ee4f979de5734d Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Add support for destructuring variable declarationsLars Knoll2018-04-271-12/+24
| | | | | | | | | | Change-Id: Ia7f894fb61cfa760e253963ab4815d98103cfd9b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Use a PatternElement for VariableDeclarationsLars Knoll2018-04-271-12/+14
| | | | | | | | | | | | | | 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-17/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Added support for generator functions and yield expressions to the ASTLars Knoll2018-04-271-7/+15
| | | | | | | | | | | | | | | | | | 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 arrow functionsLars Knoll2018-04-261-0/+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>
* | Fix crashes when parsing some invalid JSLars Knoll2018-04-251-13/+12
| | | | | | | | | | | | | | | | | | function foo() { let x; function x() {} } would crash. Throw an error instead now. Change-Id: I5e5588deb21c1777be15a6656baefc422d59ff0c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Bring JS grammar in line with ES7 specLars Knoll2018-04-251-20/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-26/+14
| | | | | | | | | | | | | | | | Destructuring objects works, but arrays are not yet supported. Change-Id: I61e917e1964e3c719f71b8f11d194e09dfe288c2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Correctly check for duplicate parameter namesLars Knoll2018-04-251-2/+4
| | | | | | | | | | | | | | | | 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>
* | Add support for ES6 template stringsLars Knoll2018-04-251-0/+11
|/ | | | | | | | | | | | | 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>
* Properly handle redeclarations of variablesLars Knoll2018-04-161-13/+15
| | | | | | | | | | This is only allowed for var type variables. Also fixes an assertion we'd run into with code such as let x; var x; Change-Id: I2588cf37e0964c879c60b4fd292e7d7b5476e322 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix leak of compiler contextsErik Verbruggen2018-04-101-7/+14
| | | | | | | | | | | | | | | Repeatedly entering a context that was entered before would result in leaking the previously entered context. This can happen when compiling child objects in a QML file, which is done recursively. So before compiling the bindings/function in the child object, first the global context and then the QML context are entered. The fix is to re-use the global context, as it's the same anyway for all objects in the same module. And we can remove entering the QML context, because nothing is in there, and we don't put anything in it ever. Change-Id: Ib1c4259d2dec22df46e96edb65bc3d377e52e671 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* use nullptr consistently (clang-tidy)Shawn Rutledge2018-02-261-4/+4
| | | | | | | | | | | | | From now on we prefer nullptr instead of 0 to clarify cases where we are assigning or testing a pointer rather than a numeric zero. Also, replaced cases where 0 was passed as Qt::KeyboardModifiers with Qt::NoModifier (clang-tidy replaced them with nullptr, which waas wrong, so it was just as well to make the tests more readable rather than to revert those lines). Change-Id: I4735d35e4d9f42db5216862ce091429eadc6e65d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Arguments passed to functions should shadow the function nameLars Knoll2018-01-121-5/+9
| | | | | | Task-number: QTBUG-65140 Change-Id: I6c6b24f081b31ef0f16fec9b2024485acec11c2d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Get rid of the hack for named expressionsLars Knoll2017-09-021-6/+7
| | | | | | | | Instead simply use the pointer to the FunctionObject we have in the CallData now. Change-Id: I6d7ed8af22e89e0217bef427110611b661ac7965 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Cleanup argument handling in contextsLars Knoll2017-08-181-2/+11
| | | | | | | | | | | | | | | | | | Fix the compiler to already deal with duplicated argument names. Doing this at runtime was not ideal. Remove the callData member from the context. Instead use the fact that the arguments already followed the locals in the context. Don't copy the thisObject over into the CallContext anymore, it's never used from there anyway. Fix the ordering of names in the internalclass, so that arguments don't require special handling anymore when looking them up by name. Adjust all places that used callData, and related methods. Change-Id: I0bc45e1be3f1fcd38dc3b4f04e91edaf7b9ed103 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Limit the amount of escaping variablesLars Knoll2017-07-041-0/+13
| | | | | | | | | | Calculate more exactly which variables can be referenced from an inner context, and convert all the non escaping ones to temporaries on the stack. Change-Id: I0e33e85b0f6f426ef2812b8ecccee1870492b7b5 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Properly calculate escaping variablesLars Knoll2017-07-041-0/+40
| | | | | Change-Id: Ia9f0b6d3f31bd3a7bd4316ee3f3e9ff977f973b7 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Move Codegen::ScanFunctions into it's own fileLars Knoll2017-07-031-0/+412
Change-Id: I2c6c2fa09bc58a26a350011f5d525ec9f4b89d7f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>