Commit Graph

1579 Commits

Author SHA1 Message Date
Lars Knoll 2d781c4ca4 Cleanup ExecutionEngine::newBuiltinFunction() usages
And change the return type to be GC safe

Change-Id: I6d7513962370fea4072a3d8c6b2c6f2d1705992e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-22 01:06:20 +02:00
Lars Knoll 21198a6761 Don't use Value::emptyValue() anymore.
emptyValue is special and reserved for usage inside the
engine to mark missing values. The main to use cases
are when converting property descriptors, and to mark
holes in array data.

Change-Id: I0ed357e65102b1041bf9a878e6e9a4ae0657523b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-22 01:06:20 +02:00
Lars Knoll e441692b0b Further work towards an exact GC
Add some more convenience in the helper classes
in qscopedvalue_p.h
Make accesses to CallData safer, and change
ExecutionEngine::newObject() to return a safe
pointer.

Change-Id: I980909754ce9681cf6faa1355bab3a1e5d6dd186
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-22 01:06:20 +02:00
Gunnar Sletta a0f8be4021 Animators - Render thread animation system
This introduces 6 new QML types for animating state in the
scene graph when the UI thread is blocked. The QObject property
being animated is updated after the animation completes.

It works also with the "windows" and "basic" render loops, but
offer litte benefit then compared to in the "threaded" case.

Change-Id: Ic19e47c898c0b8bd53e457db922b3c9c457c8147
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-21 22:23:13 +02:00
Simon Hausmann 41f75250d5 Merge branch 'wip/v4' of qtdeclarative into dev
Pull in the remaining bits of the new compiler/vme branch.

Change-Id: I4706011c5eaf35f893d0733c4e130a31ce0ebb66
2013-09-21 09:31:01 +02:00
Antti Piira 200a869441 Add Singleton support for QML
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>
2013-09-21 01:20:55 +02:00
Simon Hausmann 642b2ce0e1 [new compiler] Add support for default properties
When trying to determine the destination property for a binding, properly
fall back to the default property if existent.

Fixes tst_qqmllanguage::simpleContainer

Change-Id: Icb7752f088e92e09f03b1b66f43c882e7089f3cd
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 22:14:55 +02:00
Simon Hausmann 495358cb08 [new compiler] Fix binding evaluations
All created bindings are activated at finalization time and given sub-objects
they're all collected in allCreatedBindings. When populating that, make sure
to populate the right variable before the qSwap.

Change-Id: Ibf5b55aca933c062e1ffcac327214c73a2ae6348
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 22:14:45 +02:00
Simon Hausmann 1c29d63d60 [new compiler] Fix local variable declarations in binding expressions
Always look up locals by name

Change-Id: I2fa14499f6d8749f450bfe2b8a53d684b93bd1dc
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 22:14:30 +02:00
Simon Hausmann 5d7480aff0 [new compiler] Fix crash with remote imports
The import logic keeps pointers to the provided const QQmlImport references,
which means we can't pass references to temporaries when using the new code
path but for now have to keep the import objcts as member.

Change-Id: I75eff8dbe655ed23188f3f62f743a8f987bc709e
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 22:14:19 +02:00
Simon Hausmann 8514652f7d [new compiler] Improve error handling with invalid base types
If we fail to instantiate a composite type, handle it gracefully and
propagate the errors to the caller correctly. Similarly, if we try to
create an uncreatable type, produce an error.

Change-Id: Idce5b567c4f33eff7a97a733606c1e823c6d8297
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 22:14:12 +02:00
Simon Hausmann ba68143c1b [new compiler] Fix JavaScript expressions in composite types
When creating a composite type, we instantiate a nested QQmlObjectCreator
on the QQmlCompiledData of the composite type. It may be that this is
the first time the type is instantiated and the QV4::CompiledData::CompilationUnit
isn't linked into the engine yet. Instead of doing that on the QQmlComponent
side, do it in the QQmlObjectCreator constructor (on demand), so that it
also works for nested builders.

Change-Id: I614bbae4ef6da5a5960cc64b40b092663e1bd810
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 22:14:04 +02:00
Simon Hausmann 6213d26cc0 [new compiler] Fix signal handlers on own properties
When compiling signal handler expressions we need to determine the parameters.
We first try to look up the signal in the base meta-object. For our own
QML type itself we don't have a meta-object yet and so we extract the information
about which parameters the signals have from the parsed AST's signal declarations.

For signal handlers on declared properties we need to "synthesize" the
signal (myPropertyChanged) as well, with an empty parameter list.

Change-Id: Iecfe7bc7a9979d57586cbd9434bb9eb2f38a2c7b
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 22:13:31 +02:00
Simon Hausmann 57919fe200 Merge branch 'wip/v4' of qtdeclarative into dev
This brings in the infrastructure for the new compilation of QML and JS
in the loader thread and the new VME replacement for creating objects
in the GUI thread.

Change-Id: Ib8127c10f5cb3ad238e57469723d031ab765a79b
2013-09-20 16:48:32 +02:00
Simon Hausmann 3123a22ae6 [new compiler] Initial support for alias properties
Aliases are resolved at "compile time", not rough JS expressions. This is
done right after we determined the scope of components in the QML file,
which is also where we collect object ids (that aliases use).

Change-Id: If5702337f2cca08d17f196c3b2fde3bbdfea5b3c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:49 +02:00
Simon Hausmann 4c953b1592 [new compiler] Fix scope object for binding expressions in signal handlers of attached objects
In populateInstance the QObject instance to populate with properties, etc. may
not necessarily be the scope object (in qml lookup terms), so it needs to be provided
as a separate parameter.

Change-Id: I05db123c249e8582469bcfb76f56eb3f7bfbc4a2
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:43 +02:00
Simon Hausmann 57f7545f67 Fix destruction of QV4::CompiledData::CompilationUnit objects
Now that we store them per QML file, they live in the type cache and
can outlive the engine. Therefore the engine needs to free to unlink
any remaining units upon destruction. This needs to be done after the
"death" of the memory manager, which is likely to sweep away any
function objects that also hold a reference to the compilation units.

Change-Id: I3968d5995289e8d2bc1e3abbb1f8be88a0ab4e03
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:39 +02:00
Simon Hausmann 064c2f8f0d [new compiler] Implement dependency type availability checking
Change-Id: I9c2c69dbf88574cbce85898b2b54654445cdb552
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:37 +02:00
Simon Hausmann 1c730fd4b3 [new compiler] Fix crash with non-existent attached property objects
Produce an error message as expected by auto-tests.

Change-Id: I28caf2ac20692e2e3b055a61289bb02372047a65
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:34 +02:00
Simon Hausmann 4d0812e4bd [new compiler] Fix crash with empty function bodies
Change defineFunction back to taking AST::SourceElements for the body (how it
was originally)

Then in the new compiler, do the same "function->body ? function->body->elements
: 0" dance for function expressions and for binding expressions, synthesize the
AST::SourceElements.

Change-Id: Iaedb15925a6bb8482cde2b371a6e781477252435
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:31 +02:00
Simon Hausmann 6c461e9c8c [new compiler] Fix off-by-a-few in meta object creator
When reserving space for the methods, properties and signals, take into account
that each property for example also adds a notify signal. The calculation is
the same as in the older compiler.

Change-Id: I84f38d7c3016261a844d188978428ed021e7f9b8
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:27 +02:00
Simon Hausmann c392069685 Allow delayed deallocation in the executable memory allocator
Allow for allocations to outlive the allocator itself. When the allocator dies,
it invalidates any remaining non-free allocations, making them safe to delete
later.

Change-Id: I6c71cddbbd5dcaff1ad50f3991a3c710d4f96737
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:24 +02:00
Simon Hausmann 8c3f133bc3 [new compiler] Correctly handle attempts to set invalid group properties
Don't crash, bail out with an error message (expected by tst_qqmllanguage)

Change-Id: I357281d009d92c4b0248ba648c88e20334aabb5b
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:21 +02:00
Simon Hausmann 0615bced19 Fix crash in QV4::CompiledData::CompilationUnit
Don't crash when a CompilationUnit is created, never linked into an engine but instead
deleted (because there was an error elsewhere compililing the rest of QML
before it could reach the link-to-engine stage)

Change-Id: Iff535009b6b4d1fc4004987c98730251a3a7d8d8
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:17 +02:00
Simon Hausmann 5f6ae3598e [new compiler] Initial support for composite types
Change-Id: I01030814a978d8a52a086b0389fe62af42a4bbba
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:14 +02:00
Simon Hausmann 8d441936d2 [new compiler] Initial support for components
We use a dedicated pass through the objects in QV4::CompiledData::QmlUnit to determine
which objects are QQmlComponents. We remember their object indices as well as to which
component other objects belong to (if any).

Change-Id: I97929c57e2ccb2fd380d612002d128359c4bc253
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:10 +02:00
Simon Hausmann c5a8d5b331 [new compiler] Improve error handling and sanity checking for object ids
Disallow properties called id.foo.bar as well as id: Object {}

Change-Id: I3e31875a5863b5b4d4f9f7dd6c74d337eea3dfb2
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:59 +02:00
Simon Hausmann 9702c226ed [new compiler] Fix id parsing
id: foo;

produces a statement on the right hand side that includes the semicolon.
Strip it off - reduce expression statements similar to setBindingValue.

Change-Id: I22a02ce364a309b4364476166402f8284e01ef98
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:56 +02:00
Simon Hausmann 975efc4030 [new compiler] Fix function-local variable declarations
Make sure to call defineFunction with FunctionCode as compile mode when
compiling functions or signal handler functions, to assign an index to local
variables.

Change-Id: I8948840dba68ce6293a87c55d3386df69d5f6a5c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:53 +02:00
Simon Hausmann 1e1dde6a54 [new compiler] Cleanups
Collect code for collecting errors and string access for different compile
passes (vme creation, qobject creation) in a QQmlCompilePass base class.

Change-Id: Ib2119e730ce7d3181599ba29da12273f041f2b70
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:49 +02:00
Simon Hausmann 6b5177a756 [new compiler] Cleanups
Make the v4 context to use for binding expressions/functions/signal handlers
a member variable instead of a function parameter, as it doesn't change
frequently.

Change-Id: I8a73bbc3f37c116d29172d5c935c66ecf2f67a38
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:46 +02:00
Simon Hausmann f7cd6238ad [new compiler] Finish support for initializing list properties
Setting a value on a list property is always just appending to the list instead
of replacing it. Based on that, initializing list properties with multiple
items is done with one binding per item to the same list property. So

    myList: [ Item{}, Item{} ]

is mapped to

    myList: Item {}
    myList: Item {}

Change-Id: Iadc048ab3a8d73ac824aa6b2ae5dec33731fa362
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:43 +02:00
Simon Hausmann 2b832d2018 [new compiler] Add initial support for assigning single objects to list properties
Just like in the old VME, setting a value to a list property appends instead of
replacing.

Change-Id: Ie70bf45c6badba6cac09248dc2e41ec6a6a7538b
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:39 +02:00
Simon Hausmann b26c950826 [new compiler] Implement setting object properties
This includes assigning to interface properties, variants that hold QObject
pointers and regular QObject <> QObject assignments (assuming that they are
compatible)

Change-Id: Icd82c672e6899c6bfeb7f0ec758a81f8b70275ab
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:36 +02:00
Simon Hausmann 896d63dc10 [new compiler] Cleanup attached and group property determination
Determine when a qualified identifier signifies an attached property or a group
property in one place and set the Binding::Type accordingly.

This simplifies the object builder code, too.

Change-Id: I9f572441e9b5b43338752b848649fbd507cabe4c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:33 +02:00
Simon Hausmann d847bf07a2 [new compiler] Fix timing of binding enabling
Enabling bindings right before emitting Component.onComplete

Change-Id: I4cc330f5e59b326368c617f16a7d4fd51b6c50db
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:30 +02:00
Simon Hausmann 21a7409446 [new compiler] Implement remaining literal binding value assignments
Ported over the code from genLiteralAssignment and testLiteralAssignment
to converting the AST type (string, bool, number) to the expected property
meta-type.

Change-Id: I709b97efdd741dbc4217ee0b9712de58dd32b82d
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:27 +02:00
Simon Hausmann d071acf7ff [new compiler] Initial support for attached properties
Attached properties are implemented similarly to group properties, except that
the object operated on isn't a QQmlValueType from a property (i.e. font) but the
QObject that implements the attached properties.

Change-Id: If73751162c191c65512ca1bddadd6270e6e33793
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:23 +02:00
Simon Hausmann 269e29fdf3 [new compiler] Add support for finalization callbacks
This is needed for Component.onCompleted (the signal emission) as well
as the private finalization callback API in QQmlEngine, used by QtQuick.

The creator - similar to the VME - tracks the attached properties object
of QQmlComponent through a linked list.

Change-Id: I8ada94009a7ce2078feefd359485657626c300fb
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:20 +02:00
Simon Hausmann b4b4a64680 [new compiler] Initial implementation of signal handler support
Signal handlers start out in the parser as binding expressions. A new
SignalHandlerConverter converts the bindings then so that the expression is
turned into a function declaration where the function parameters match the
parameters of the signal.

Change-Id: I3ea5aa3b80a6ee3b095c6841c63c3e3bb0b47e4f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:18 +02:00
Simon Hausmann 4a59984e0d [new compiler] Avoid type reference lookups with empty strings
For example when declaring

    signal mySignal(string blah)

then we don't need to try to "resolve" the type "string".

Change-Id: I80924ebf244c6b8e2827d19f9c78faf93031fe15
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:15 +02:00
Simon Hausmann 7def3cfb31 [new compiler] Fix function and binding expression setup
Binding expressions and QML used to be set up so that they were written
as function closure:

    (function(...) {
      expression here
    })

and then evaluated inside qml scope. With the new setup we do that closure
setup manually now.

For that we have to define a dummy outter "context scope" function in the
codegen, that will later be used to look up the context ids.

Change-Id: I0656419d67a1728451fcd46f402b03979f118b0b
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:12 +02:00
Simon Hausmann 5c4c912391 Cleanup: Fold CompiledData::Value into CompiledData::Binding
Value isn't needed anywhere else

Change-Id: Ib12d85332a6096e6232a790a7e6fd63961329e3b
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:09 +02:00
Simon Hausmann 3ec5aae38e [new compiler] Add support for id properties
Change-Id: Idb4a0ad06f6cbe5d040da075a8f43d067a27ebc4
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:05 +02:00
Simon Hausmann 6042327dee [new compiler] Initial support for group properties
This implements support for "font.pixelSize: 24" for example. The representation
in the compile data structure is so that font.pixelSize is short-hand for

font {
    pixelSize: 24
}

which means that inside the braces is a complete object initializer. For that
initializer we create a dedicated CompiledData::Object, which however has its
type name empty. When populating the outer instance then, the "font" property
is read as QQmlValueType (a QObject) and instead of creating a new QObject we
use that value type as instance to run the rest of the QML object initializer
(everything in braces).

Change-Id: Ic0a37ac77ab88f582546b9c09a3d06a07726420b
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:26:01 +02:00
Erik Verbruggen 3ea14e269b V4: fixes after ReturnValue and ValueRef introduction.
Change-Id: I072cd7168aca4163af560c0b65e8527ddf55e26b
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 12:43:01 +02:00
Erik Verbruggen 09ccfa798a V4 interpreter: inline add/sub/mul on numbers.
Change-Id: I36d000acef9426b842847691372e9a786b9a45e8
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 12:42:48 +02:00
Erik Verbruggen 565c9b7661 V4 interpreter: add hints for unop/binop targets
Change-Id: Ic1230170a89557ad25f0e37261f98819a42a2b47
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 12:42:41 +02:00
Erik Verbruggen 857b135d77 V4 JIT: generate inline code for more binops.
Bitwise-and, shift left, and shift-right.

Change-Id: Ifa949c60261054218797302673822f480f47bd6e
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 12:42:33 +02:00
Erik Verbruggen d33fe17cd1 V4 IR: rename ObjectType to VarType
The ObjectType was a misnomer: it was used to indicate that the
expression could have multiple types, or that the type could not be
inferred statically.

Change-Id: Ic48a0cd1dd7ae7bfafd361e0c9792ab161417039
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 12:42:25 +02:00