aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compilerscanfunctions_p.h
Commit message (Collapse)AuthorAgeFilesLines
* Port QtDeclarative from QStringRef to QStringViewKarsten Heimrich2020-06-161-1/+1
| | | | | | | | 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>
* Restore offset/length in QQmlJS::DiagnosticMessageSimon Hausmann2020-03-021-1/+1
| | | | | | | | | | | | 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>
* Support top level generator functionsFabian Kosmale2019-07-231-1/+1
| | | | | | | | | | | | | 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>
* Split compiler and runtime more clearlyUlf Hermann2019-07-111-1/+1
| | | | | | | | 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>
* Disentangle includes and namespacesUlf Hermann2019-07-111-49/+50
| | | | | | | | Avoid using namespace in headers and include only the headers we actually need. Change-Id: I526a0f874dc09b07693fd87070665be396d3b637 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Unify the JavaScript parsing recursion checksUlf Hermann2019-03-151-5/+2
| | | | | | | | | | | | | 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>
* QMLJS: Have ScanFunctions iterate over ArrayPattern nodesErik Verbruggen2019-02-051-0/+1
| | | | | | | | | | | | Like Codegen, have ScanFunctions iterate over the elements in an ArrayPattern, instead of recursing over the tail of the element list. This prevents running out of (native) stack, or hitting the recursion check limiter. Change-Id: I8203af3119ad50f19000a215af42649d9bcb3784 Fixes: QTBUG-73425 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* JS: Limit expression and statement nesting levelErik Verbruggen2018-11-291-0/+5
| | | | | | | | | This is to prevent extremely deeply nested expressions and statements make the code-generator run out of (native) stack space. Task-number: QTBUG-71087 Change-Id: I8e1a20a361bff3e49101e535754546475a63ca18 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix new.target access from eval()Lars Knoll2018-09-071-0/+1
| | | | | Change-Id: I1855eb303225d1784b019f8eebab0ad8bf2cdf5e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Always generate a context if an inner function uses superLars Knoll2018-09-041-0/+1
| | | | | Change-Id: I4215c215a28da6855d946dec8727c0c4f0acb933 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add initial basic support for ES6 modulesSimon Hausmann2018-08-091-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Get rid of TemporaryAssignmentSimon Hausmann2018-07-171-1/+2
| | | | | | | We can use QScopedValueRollback from QtCore for the same purpose. Change-Id: I5ca37a52bde5469cdb76928913835140241d42b1 Reviewed-by: Erik Verbruggen <erik.verbruggen@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>
* Add basic support for EcmaScript classesYulong Bai2018-06-261-0/+3
| | | | | | | | | | | | | | | | Most of the class creation is done inside the runtime in the CreateClass method. Added a corresponding instruction to the interpreter and jit. The compiled data now contains an array of classes containing the compile time generated layout of the class. Currently, classes without an explicit constructor and classes with inheritance are not supported. Done-with: Yulong Bai <yulong.bai@qt.io> Change-Id: I0185dcc1e3b0b8f44deff74e44a8262fc646aa9e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Remove some dead codeLars Knoll2018-06-211-2/+0
| | | | | | | maxNumberOfArguments isn't used anymore. Change-Id: Ibb891101b971b4b0b01be7897e6d1490e1dde62c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Set the name of the context as early as possibleLars Knoll2018-05-231-1/+1
| | | | | | | | | | We used to set the name later on when calling Codegen::defineFunction(), but this is too late in some cases, especially when using the name to determine if this function could be a QML signal handler. Change-Id: Ie620a65ac8f17906cd9eba338cbdd3563004375d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Give case blocks a proper scopeLars Knoll2018-05-111-0/+3
| | | | | 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/+1
| | | | | Change-Id: I71c40d1d061ac3c1c623dbbf8f7967c9ec35c082 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Unify AST for the different 'for' statementsLars Knoll2018-05-111-1/+0
| | | | | Change-Id: I70ca83b0ce933d64dad4984a236e48592e989742 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Improve for-in and for-of supportLars Knoll2018-05-111-0/+2
| | | | | | | | | | | | 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-1/+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>
* Cleanup handling of with() statementsLars Knoll2018-05-021-2/+3
| | | | | | | | | | | 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-1/+3
| | | | | | | | | | | | 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-0/+1
| | | | | | | | | | | | | 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>
* Rename the CompilationMode enum to ContextTypeLars Knoll2018-05-021-4/+4
| | | | | | | | | 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>
* Use a PatternElement for VariableDeclarationsLars Knoll2018-04-271-1/+1
| | | | | | | 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-2/+2
| | | | | | | | | | | | | | | | | 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-2/+2
| | | | | | | | | | | | 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-1/+1
| | | | | | | | | 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>
* Fix crashes when parsing some invalid JSLars Knoll2018-04-251-2/+2
| | | | | | | | | 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-2/+2
| | | | | | | | | | | | | | | | | | | | | | | 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-1/+0
| | | | | | | | Destructuring objects works, but arrays are not yet supported. Change-Id: I61e917e1964e3c719f71b8f11d194e09dfe288c2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add support for ES6 template stringsLars Knoll2018-04-251-0/+1
| | | | | | | | | | | | | 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>
* Fix leak of compiler contextsErik Verbruggen2018-04-101-3/+4
| | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | 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-1/+1
| | | | | | 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-4/+4
| | | | | | | | 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>
* Limit the amount of escaping variablesLars Knoll2017-07-041-0/+1
| | | | | | | | | | 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/+1
| | | | | Change-Id: Ia9f0b6d3f31bd3a7bd4316ee3f3e9ff977f973b7 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Move Codegen::ScanFunctions into it's own fileLars Knoll2017-07-031-0/+158
Change-Id: I2c6c2fa09bc58a26a350011f5d525ec9f4b89d7f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>