Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qv4codegen_p.h
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant
4
5
#
ifndef
QV4CODEGEN_P_H
6
#
define
QV4CODEGEN_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an
13
// implementation detail. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
<
private
/
qqmljsastvisitor_p
.
h
>
20
#
include
<
private
/
qqmljsengine_p
.
h
>
21
#
include
<
private
/
qqmljsast_p
.
h
>
22
#
include
<
private
/
qqmljsdiagnosticmessage_p
.
h
>
23
#
include
<
private
/
qv4compiler_p
.
h
>
24
#
include
<
private
/
qv4compilercontext_p
.
h
>
25
#
include
<
private
/
qv4util_p
.
h
>
26
#
include
<
private
/
qv4bytecodegenerator_p
.
h
>
27
#
include
<
private
/
qv4calldata_p
.
h
>
28
29
#
include
<
QtCore
/
qsharedpointer
.
h
>
30
#
include
<
QtCore
/
qxpfunctional
.
h
>
31
32
#
include
<
stack
>
33
34
QT_BEGIN_NAMESPACE
35
36
namespace
QV4
{
37
38
namespace
Moth
{
39
struct
Instruction
;
40
}
41
42
namespace
CompiledData
{
43
struct
CompilationUnit
;
44
}
45
46
namespace
Compiler
{
47
48
struct
ControlFlow
;
49
struct
ControlFlowCatch
;
50
struct
ControlFlowFinally
;
51
52
class
Q_QML_COMPILER_EXPORT
CodegenWarningInterface
53
{
54
public
:
55
virtual
void
reportVarUsedBeforeDeclaration
(
const
QString
&
name
,
const
QString
&
fileName
,
56
QQmlJS
::
SourceLocation
declarationLocation
,
57
QQmlJS
::
SourceLocation
accessLocation
);
58
virtual
void
reportFunctionUsedBeforeDeclaration
(
const
QString
&
name
,
const
QString
&
fileName
,
59
QQmlJS
::
SourceLocation
declarationLocation
,
60
QQmlJS
::
SourceLocation
accessLocation
);
61
virtual
void
reportParserWarnings
(
const
QString
&
fileName
,
QQmlJS
::
SourceLocation
location
,
62
const
QString
&
message
)
63
{
64
qWarning
(
"%s:%d : %s"
,
qPrintable
(
fileName
),
location
.
startLine
,
qPrintable
(
message
));
65
}
66
67
virtual
void
reportSyntaxWarnings
(
QSpan
<
const
QQmlJS
::
DiagnosticMessage
>) { }
68
69
virtual
void
reportCompileError
(
const
QString
&
fileName
,
const
QQmlJS
::
DiagnosticMessage
&
error
)
70
{
71
qWarning
(
"%s:%d : %s"
,
qPrintable
(
fileName
),
error
.
loc
.
startLine
,
72
qPrintable
(
error
.
message
));
73
}
74
75
virtual
void
reportError
(
const
QString
&
message
) {
qWarning
(
"%s"
,
qPrintable
(
message
)); }
76
77
virtual
QQmlJS
::
AST
::
Visitor
*
unreachableVisitor
() {
return
nullptr
; }
78
virtual
~
CodegenWarningInterface
() =
default
;
79
};
80
81
inline
CodegenWarningInterface
*
defaultCodegenWarningInterface
()
82
{
83
static
CodegenWarningInterface iface;
84
return
&iface;
85
}
86
87
class
Q_QML_COMPILER_EXPORT
Codegen
:
protected
QQmlJS
::
AST
::
Visitor
88
{
89
protected
:
90
using
BytecodeGenerator
=
QV4
::
Moth
::
BytecodeGenerator
;
91
using
Instruction
=
QV4
::
Moth
::
Instruction
;
92
public
:
93
Codegen
(
QV4
::
Compiler
::
JSUnitGenerator
*
jsUnitGenerator
,
bool
strict
,
94
CodegenWarningInterface
*
iface
=
defaultCodegenWarningInterface
(),
95
bool
storeSourceLocations
=
false
);
96
97
static
bool
isNameGlobal
(
QAnyStringView
name
);
98
static
bool
isNameKeyword
(
QAnyStringView
name
);
99
static
void
forEachGlobalName
(
qxp
::
function_ref
<
void
(
QLatin1StringView
)> &&
handler
);
100
101
void
generateFromProgram
(
102
const
QString
&
sourceCode
,
QQmlJS
::
AST
::
Program
*
ast
,
Module
*
module
,
103
ContextType
contextType
=
ContextType
::
Global
);
104
105
void
generateFromModule
(
const
QString
&
sourceCode
,
QQmlJS
::
AST
::
ESModule
*
ast
,
Module
*
module
);
106
void
generateFromModule
(
const
Value
&
value
,
Module
*
module
);
107
108
public
:
109
class
VolatileMemoryLocationScanner
;
110
class
VolatileMemoryLocations
{
111
friend
VolatileMemoryLocationScanner
;
112
bool
allVolatile
=
false
;
113
QList
<
QStringView
>
specificLocations
;
114
public
:
115
bool
isVolatile
(
QStringView
name
) {
116
if
(
allVolatile
)
117
return
true
;
118
return
specificLocations
.
contains
(
name
);
119
}
120
121
void
add
(
QStringView
name
) {
if
(!
allVolatile
)
specificLocations
.
append
(
name
); }
122
void
setAllVolatile
() {
allVolatile
=
true
; }
123
};
124
class
RValue
{
125
Codegen
*
codegen
;
126
enum
Type
{
127
Invalid
,
128
Accumulator
,
129
StackSlot
,
130
Const
131
}
type
;
132
union
{
133
Moth
::
StackSlot
theStackSlot
;
134
QV4
::
ReturnedValue
constant
;
135
};
136
137
public
:
138
static
RValue
fromStackSlot
(
Codegen
*
codegen
,
Moth
::
StackSlot
stackSlot
) {
139
RValue
r
;
140
r
.
codegen
=
codegen
;
141
r
.
type
=
StackSlot
;
142
r
.
theStackSlot
=
stackSlot
;
143
return
r
;
144
}
145
static
RValue
fromAccumulator
(
Codegen
*
codegen
) {
146
RValue
r
;
147
r
.
codegen
=
codegen
;
148
r
.
type
=
Accumulator
;
149
return
r
;
150
}
151
static
RValue
fromConst
(
Codegen
*
codegen
,
QV4
::
ReturnedValue
value
) {
152
RValue
r
;
153
r
.
codegen
=
codegen
;
154
r
.
type
=
Const
;
155
r
.
constant
=
value
;
156
return
r
;
157
}
158
159
bool
operator
==(
const
RValue
&
other
)
const
;
160
161
bool
isValid
()
const
{
return
type
!=
Invalid
; }
162
bool
isAccumulator
()
const
{
return
type
==
Accumulator
; }
163
bool
isStackSlot
()
const
{
return
type
==
StackSlot
; }
164
bool
isConst
()
const
{
return
type
==
Const
; }
165
166
Moth
::
StackSlot
stackSlot
()
const
{
167
Q_ASSERT
(
isStackSlot
());
168
return
theStackSlot
;
169
}
170
171
QV4
::
ReturnedValue
constantValue
()
const
{
172
Q_ASSERT
(
isConst
());
173
return
constant
;
174
}
175
176
Q_REQUIRED_RESULT
RValue
storeOnStack
()
const
;
177
void
loadInAccumulator
()
const
;
178
};
179
struct
Reference
{
180
enum
Type
{
181
Invalid
,
182
Accumulator
,
183
Super
,
184
SuperProperty
,
185
StackSlot
,
186
ScopedLocal
,
187
Name
,
188
Member
,
189
Subscript
,
190
Import
,
191
LastLValue
=
Import
,
192
Const
193
}
type
=
Invalid
;
194
195
bool
isLValue
()
const
{
return
!
isReadonly
&&
type
>
Accumulator
; }
196
197
Reference
(
Codegen
*
cg
,
Type
t
=
Invalid
) :
Reference
()
198
{
199
type
=
t
;
200
codegen
=
cg
;
201
}
202
203
Reference
(
const
QString
&
name
=
QString
()) :
204
constant
(0),
205
name
(
name
),
206
isArgOrEval
(
false
),
207
isReadonly
(
false
),
208
isReferenceToConst
(
false
),
209
requiresTDZCheck
(
false
),
210
subscriptRequiresTDZCheck
(
false
),
211
stackSlotIsLocalOrArgument
(
false
),
212
isVolatile
(
false
),
213
global
(
false
),
214
qmlGlobal
(
false
),
215
throwsReferenceError
(
false
),
216
subscriptLoadedForCall
(
false
),
217
isOptional
(
false
),
218
hasSavedCallBaseSlot
(
false
)
219
{}
220
221
Reference
(
const
Reference
&) =
default
;
222
Reference
(
Reference
&&) =
default
;
223
Reference
&
operator
=(
const
Reference
&) =
default
;
224
Reference
&
operator
=(
Reference
&&) =
default
;
225
226
bool
operator
==(
const
Reference
&
other
)
const
;
227
bool
operator
!=(
const
Reference
&
other
)
const
228
{
return
!(*
this
==
other
); }
229
230
bool
isValid
()
const
{
return
type
!=
Invalid
; }
231
bool
loadTriggersSideEffect
()
const
{
232
switch
(
type
) {
233
case
Name
:
234
case
Member
:
235
case
Subscript
:
236
case
SuperProperty
:
237
return
true
;
238
default
:
239
return
requiresTDZCheck
;
240
}
241
}
242
bool
isConstant
()
const
{
return
type
==
Const
; }
243
bool
isAccumulator
()
const
{
return
type
==
Accumulator
; }
244
bool
isSuper
()
const
{
return
type
==
Super
; }
245
bool
isSuperProperty
()
const
{
return
type
==
SuperProperty
; }
246
bool
isStackSlot
()
const
{
return
type
==
StackSlot
; }
247
bool
isRegister
()
const
{
248
return
isStackSlot
();
249
}
250
251
static
Reference
fromAccumulator
(
Codegen
*
cg
) {
252
return
Reference
(
cg
,
Accumulator
);
253
}
254
static
Reference
fromSuper
(
Codegen
*
cg
) {
255
return
Reference
(
cg
,
Super
);
256
}
257
static
Reference
fromStackSlot
(
Codegen
*
cg
,
int
tempIndex
= -1,
bool
isLocal
=
false
) {
258
Reference
r
(
cg
,
StackSlot
);
259
if
(
tempIndex
== -1)
260
tempIndex
=
cg
->
bytecodeGenerator
->
newRegister
();
261
r
.
theStackSlot
=
Moth
::
StackSlot
::
createRegister
(
tempIndex
);
262
r
.
stackSlotIsLocalOrArgument
=
isLocal
;
263
return
r
;
264
}
265
static
Reference
fromScopedLocal
(
Codegen
*
cg
,
int
index
,
int
scope
) {
266
Reference
r
(
cg
,
ScopedLocal
);
267
r
.
index
=
index
;
268
r
.
scope
=
scope
;
269
return
r
;
270
}
271
static
Reference
fromImport
(
Codegen
*
cg
,
int
index
) {
272
Reference
r
(
cg
,
Import
);
273
r
.
index
=
index
;
274
return
r
;
275
}
276
static
Reference
fromName
(
Codegen
*
cg
,
const
QString
&
name
) {
277
Reference
r
(
cg
,
Name
);
278
r
.
name
=
name
;
279
return
r
;
280
}
281
static
Reference
282
fromMember
(
const
Reference
&
baseRef
,
const
QString
&
name
,
283
QQmlJS
::
SourceLocation
sourceLocation
=
QQmlJS
::
SourceLocation
(),
284
bool
isOptional
=
false
,
285
std
::
vector
<
Moth
::
BytecodeGenerator
::
Jump
> *
optionalChainJumpsToPatch
=
nullptr
)
286
{
287
Q_ASSERT
(
baseRef
.
isValid
());
288
Reference
r
(
baseRef
.
codegen
,
Member
);
289
r
.
propertyBase
=
baseRef
.
asRValue
();
290
r
.
propertyNameIndex
=
r
.
codegen
->
registerString
(
name
);
291
r
.
requiresTDZCheck
=
baseRef
.
requiresTDZCheck
;
292
r
.
sourceLocation
=
sourceLocation
;
293
r
.
optionalChainJumpsToPatch
=
optionalChainJumpsToPatch
;
294
r
.
isOptional
=
isOptional
;
295
return
r
;
296
}
297
static
Reference
fromSuperProperty
(
const
Reference
&
property
) {
298
Q_ASSERT
(
property
.
isStackSlot
());
299
Reference
r
(
property
.
codegen
,
SuperProperty
);
300
r
.
property
=
property
.
stackSlot
();
301
r
.
subscriptRequiresTDZCheck
=
property
.
requiresTDZCheck
;
302
return
r
;
303
}
304
static
Reference
fromSubscript
(
const
Reference
&
baseRef
,
const
Reference
&
subscript
) {
305
Q_ASSERT
(
baseRef
.
isStackSlot
());
306
Reference
r
(
baseRef
.
codegen
,
Subscript
);
307
r
.
elementBase
=
baseRef
.
stackSlot
();
308
r
.
elementSubscript
=
subscript
.
asRValue
();
309
r
.
requiresTDZCheck
=
baseRef
.
requiresTDZCheck
;
310
r
.
subscriptRequiresTDZCheck
=
subscript
.
requiresTDZCheck
;
311
return
r
;
312
}
313
static
Reference
fromConst
(
Codegen
*
cg
,
QV4
::
ReturnedValue
constant
) {
314
Reference
r
(
cg
,
Const
);
315
r
.
constant
=
constant
;
316
r
.
isReadonly
=
true
;
317
return
r
;
318
}
319
static
Reference
fromThis
(
Codegen
*
cg
) {
320
Reference
r
=
fromStackSlot
(
cg
,
CallData
::
This
);
321
r
.
isReadonly
=
true
;
322
// ### Optimize this. Functions that are not derived constructors or arrow functions can't have an
323
// empty this object
324
r
.
requiresTDZCheck
=
true
;
325
return
r
;
326
}
327
328
RValue
asRValue
()
const
;
329
Reference
asLValue
()
const
;
330
331
Q_REQUIRED_RESULT
static
Reference
storeConstOnStack
(
Codegen
*
cg
,
QV4
::
ReturnedValue
constant
)
332
{
return
Reference
::
fromConst
(
cg
,
constant
).
storeOnStack
(); }
333
334
static
void
storeConstOnStack
(
Codegen
*
cg
,
QV4
::
ReturnedValue
constant
,
int
stackSlot
)
335
{
Reference
::
fromConst
(
cg
,
constant
).
storeOnStack
(
stackSlot
); }
336
337
Q_REQUIRED_RESULT
Reference
storeOnStack
()
const
;
338
void
storeOnStack
(
int
tempIndex
)
const
;
339
Q_REQUIRED_RESULT
Reference
storeRetainAccumulator
()
const
;
340
Reference
storeConsumeAccumulator
()
const
;
341
342
Q_REQUIRED_RESULT
Reference
baseObject
()
const
;
343
344
bool
storeWipesAccumulator
()
const
;
345
void
loadInAccumulator
()
const
;
346
347
int
nameAsIndex
()
const
{
348
Q_ASSERT
(
type
==
Name
);
349
return
codegen
->
registerString
(
name
);
350
}
351
352
Moth
::
StackSlot
stackSlot
()
const
{
353
if
(
Q_UNLIKELY
(!
isStackSlot
()))
354
Q_UNREACHABLE
();
355
return
theStackSlot
;
356
}
357
358
void
tdzCheck
()
const
359
{
360
if
(
isAccumulator
())
361
tdzCheck
(
requiresTDZCheck
,
throwsReferenceError
);
362
else
if
(
isStackSlot
())
363
tdzCheckStackSlot
(
stackSlot
(),
requiresTDZCheck
,
throwsReferenceError
);
364
}
365
366
void
checkTDZBeforeAssignment
()
const
;
367
368
union
{
369
Moth
::
StackSlot
theStackSlot
;
370
QV4
::
ReturnedValue
constant
;
371
struct
{
// Scoped arguments/Local
372
int
index
;
373
int
scope
;
374
};
375
struct
{
376
RValue
propertyBase
;
377
int
propertyNameIndex
;
378
};
379
struct
{
380
Moth
::
StackSlot
elementBase
;
381
union
{
382
RValue
elementSubscript
;
383
Moth
::
StackSlot
element
;
384
};
385
};
386
Moth
::
StackSlot
property
;
// super property
387
};
388
QString
name
;
389
Codegen
*
codegen
=
nullptr
;
390
391
quint32
isArgOrEval
:1;
392
quint32
isReadonly
:1;
393
quint32
isReferenceToConst
:1;
394
quint32
requiresTDZCheck
:1;
395
quint32
subscriptRequiresTDZCheck
:1;
396
quint32
stackSlotIsLocalOrArgument
:1;
397
quint32
isVolatile
:1;
398
quint32
global
:1;
399
quint32
qmlGlobal
:1;
400
quint32
throwsReferenceError
:1;
401
quint32
subscriptLoadedForCall
:1;
402
quint32
isOptional
: 1;
403
quint32
hasSavedCallBaseSlot
: 1;
404
QQmlJS
::
SourceLocation
sourceLocation
=
QQmlJS
::
SourceLocation
();
405
std
::
vector
<
Moth
::
BytecodeGenerator
::
Jump
> *
optionalChainJumpsToPatch
=
nullptr
;
406
int
savedCallBaseSlot
= -1;
407
int
savedCallPropertyNameIndex
= -1;
408
409
private
:
410
void
storeAccumulator
()
const
;
411
Reference
doStoreOnStack
(
int
tempIndex
)
const
;
412
void
tdzCheck
(
bool
requiresCheck
,
bool
throwsReferenceError
)
const
;
413
void
tdzCheckStackSlot
(
414
Moth
::
StackSlot
slot
,
bool
requiresCheck
,
bool
throwsReferenceError
)
const
;
415
};
416
417
struct
RegisterScope
{
418
RegisterScope
(
Codegen
*
cg
)
419
:
generator
(
cg
->
bytecodeGenerator
),
420
regCountForScope
(
generator
->
currentReg
) {}
421
~
RegisterScope
() {
422
generator
->
currentReg
=
regCountForScope
;
423
}
424
BytecodeGenerator
*
generator
;
425
int
regCountForScope
;
426
};
427
428
struct
ObjectPropertyValue
{
429
ObjectPropertyValue
() {}
430
431
Reference
rvalue
;
432
int
getter
= -1;
// index in _module->functions or -1 if not set
433
int
setter
= -1;
434
uint
keyAsIndex
=
UINT_MAX
;
435
436
bool
hasGetter
()
const
{
return
getter
>= 0; }
437
bool
hasSetter
()
const
{
return
setter
>= 0; }
438
};
439
protected
:
440
441
enum
Format
{
ex
,
cx
,
nx
};
442
class
Result
{
443
Reference
_result
;
444
445
const
BytecodeGenerator
::
Label
*
_iftrue
=
nullptr
;
446
const
BytecodeGenerator
::
Label
*
_iffalse
=
nullptr
;
447
Format
_format
=
ex
;
448
Format
_requested
;
449
bool
_trueBlockFollowsCondition
=
false
;
450
451
public
:
452
explicit
Result
(
const
QString
&
name
)
453
:
_result
(
name
)
454
,
_requested
(
ex
)
455
{}
456
457
explicit
Result
(
const
Reference
&
lrvalue
)
458
:
_result
(
lrvalue
)
459
,
_requested
(
ex
)
460
{}
461
462
explicit
Result
(
Format
requested
=
ex
)
463
:
_requested
(
requested
) {}
464
465
explicit
Result
(
const
BytecodeGenerator
::
Label
*
iftrue
,
466
const
BytecodeGenerator
::
Label
*
iffalse
,
467
bool
trueBlockFollowsCondition
)
468
:
_iftrue
(
iftrue
)
469
,
_iffalse
(
iffalse
)
470
,
_requested
(
cx
)
471
,
_trueBlockFollowsCondition
(
trueBlockFollowsCondition
)
472
{
473
Q_ASSERT
(
iftrue
);
474
Q_ASSERT
(
iffalse
);
475
}
476
477
const
BytecodeGenerator
::
Label
*
iftrue
()
const
{
478
Q_ASSERT
(
_requested
==
cx
);
479
return
_iftrue
;
480
}
481
482
const
BytecodeGenerator
::
Label
*
iffalse
()
const
{
483
Q_ASSERT
(
_requested
==
cx
);
484
return
_iffalse
;
485
}
486
487
Format
format
()
const
{
488
return
_format
;
489
}
490
491
bool
accept
(
Format
f
)
492
{
493
if
(
_requested
==
f
) {
494
_format
=
f
;
495
return
true
;
496
}
497
return
false
;
498
}
499
500
bool
trueBlockFollowsCondition
()
const
{
501
return
_trueBlockFollowsCondition
;
502
}
503
504
const
Reference
&
result
()
const
{
505
return
_result
;
506
}
507
508
void
setResult
(
const
Reference
&
result
) {
509
_result
=
result
;
510
}
511
512
void
setResult
(
Reference
&&
result
) {
513
_result
=
std
::
move
(
result
);
514
}
515
516
void
clearResultName
() {
517
_result
.
name
.
clear
();
518
}
519
};
520
521
void
enterContext
(
QQmlJS
::
AST
::
Node
*
node
);
522
int
leaveContext
();
523
public
:
524
Context
*
enterBlock
(
QQmlJS
::
AST
::
Node
*
node
);
525
int
leaveBlock
() {
return
leaveContext
(); }
526
protected
:
527
void
leaveLoop
();
528
529
enum
UnaryOperation
{
530
UPlus
,
531
UMinus
,
532
PreIncrement
,
533
PreDecrement
,
534
PostIncrement
,
535
PostDecrement
,
536
Not
,
537
Compl
538
};
539
540
Reference
unop
(
UnaryOperation
op
,
const
Reference
&
expr
);
541
542
void
addCJump
();
543
544
public
:
545
int
registerString
(
const
QString
&
name
) {
546
return
jsUnitGenerator
->
registerString
(
name
);
547
}
548
int
registerConstant
(
QV4
::
ReturnedValue
v
)
549
{
550
return
jsUnitGenerator
->
registerConstant
(
v
);
551
}
552
int
registerGetterLookup
(
int
nameIndex
,
JSUnitGenerator
::
LookupMode
mode
)
553
{
554
return
jsUnitGenerator
->
registerGetterLookup
(
nameIndex
,
mode
);
555
}
556
int
registerSetterLookup
(
int
nameIndex
)
557
{
558
return
jsUnitGenerator
->
registerSetterLookup
(
nameIndex
);
559
}
560
int
registerGlobalGetterLookup
(
int
nameIndex
,
JSUnitGenerator
::
LookupMode
mode
)
561
{
562
return
jsUnitGenerator
->
registerGlobalGetterLookup
(
nameIndex
,
mode
);
563
}
564
int
registerQmlContextPropertyGetterLookup
(
int
nameIndex
,
JSUnitGenerator
::
LookupMode
mode
)
565
{
566
return
jsUnitGenerator
->
registerQmlContextPropertyGetterLookup
(
nameIndex
,
mode
);
567
}
568
569
// Returns index in _module->functions
570
int
defineFunction
(
const
QString
&
name
,
QQmlJS
::
AST
::
Node
*
ast
,
571
QQmlJS
::
AST
::
FormalParameterList
*
formals
,
572
QQmlJS
::
AST
::
StatementList
*
body
);
573
574
protected
:
575
void
statement
(
QQmlJS
::
AST
::
Statement
*
ast
);
576
void
statement
(
QQmlJS
::
AST
::
ExpressionNode
*
ast
);
577
void
condition
(
QQmlJS
::
AST
::
ExpressionNode
*
ast
,
const
BytecodeGenerator
::
Label
*
iftrue
,
578
const
BytecodeGenerator
::
Label
*
iffalse
,
579
bool
trueBlockFollowsCondition
);
580
581
inline
Reference
expression
(
QQmlJS
::
AST
::
ExpressionNode
*
ast
,
const
QString
&
name
=
QString
())
582
{
583
if
(!
ast
||
hasError
())
584
return
Reference
();
585
586
pushExpr
(
name
);
587
ast
->
accept
(
this
);
588
return
popResult
();
589
}
590
591
inline
void
accept
(
QQmlJS
::
AST
::
Node
*
node
)
592
{
593
if
(!
hasError
() &&
node
)
594
node
->
accept
(
this
);
595
}
596
597
void
program
(
QQmlJS
::
AST
::
Program
*
ast
);
598
void
statementList
(
QQmlJS
::
AST
::
StatementList
*
ast
);
599
void
variableDeclaration
(
QQmlJS
::
AST
::
PatternElement
*
ast
);
600
void
variableDeclarationList
(
QQmlJS
::
AST
::
VariableDeclarationList
*
ast
);
601
602
Reference
targetForPatternElement
(
QQmlJS
::
AST
::
PatternElement
*
p
);
603
Reference
referenceForFormalParameter
(
int
argIndex
);
604
void
initializeAndDestructureBindingElement
(
QQmlJS
::
AST
::
PatternElement
*
e
,
const
Reference
&
baseRef
=
Reference
(),
bool
isDefinition
=
false
);
605
void
destructurePropertyList
(
const
Reference
&
object
,
QQmlJS
::
AST
::
PatternPropertyList
*
bindingList
,
bool
isDefinition
=
false
);
606
void
destructureElementList
(
const
Reference
&
array
,
QQmlJS
::
AST
::
PatternElementList
*
bindingList
,
bool
isDefinition
=
false
);
607
void
destructurePattern
(
QQmlJS
::
AST
::
Pattern
*
p
,
const
Reference
&
rhs
);
608
609
Reference
referenceForPropertyName
(
const
Codegen
::
Reference
&
object
,
QQmlJS
::
AST
::
PropertyName
*
name
);
610
611
void
emitReturn
(
const
Reference
&
expr
);
612
613
// nodes
614
bool
visit
(
QQmlJS
::
AST
::
ArgumentList
*
ast
)
override
;
615
bool
visit
(
QQmlJS
::
AST
::
CaseBlock
*
ast
)
override
;
616
bool
visit
(
QQmlJS
::
AST
::
CaseClause
*
ast
)
override
;
617
bool
visit
(
QQmlJS
::
AST
::
CaseClauses
*
ast
)
override
;
618
bool
visit
(
QQmlJS
::
AST
::
Catch
*
ast
)
override
;
619
bool
visit
(
QQmlJS
::
AST
::
DefaultClause
*
ast
)
override
;
620
bool
visit
(
QQmlJS
::
AST
::
Elision
*
ast
)
override
;
621
bool
visit
(
QQmlJS
::
AST
::
Finally
*
ast
)
override
;
622
bool
visit
(
QQmlJS
::
AST
::
FormalParameterList
*
ast
)
override
;
623
bool
visit
(
QQmlJS
::
AST
::
Program
*
ast
)
override
;
624
bool
visit
(
QQmlJS
::
AST
::
StatementList
*
ast
)
override
;
625
bool
visit
(
QQmlJS
::
AST
::
UiArrayMemberList
*
ast
)
override
;
626
bool
visit
(
QQmlJS
::
AST
::
UiImport
*
ast
)
override
;
627
bool
visit
(
QQmlJS
::
AST
::
UiHeaderItemList
*
ast
)
override
;
628
bool
visit
(
QQmlJS
::
AST
::
UiPragmaValueList
*
ast
)
override
;
629
bool
visit
(
QQmlJS
::
AST
::
UiPragma
*
ast
)
override
;
630
bool
visit
(
QQmlJS
::
AST
::
UiObjectInitializer
*
ast
)
override
;
631
bool
visit
(
QQmlJS
::
AST
::
UiObjectMemberList
*
ast
)
override
;
632
bool
visit
(
QQmlJS
::
AST
::
UiParameterList
*
ast
)
override
;
633
bool
visit
(
QQmlJS
::
AST
::
UiProgram
*
ast
)
override
;
634
bool
visit
(
QQmlJS
::
AST
::
UiQualifiedId
*
ast
)
override
;
635
bool
visit
(
QQmlJS
::
AST
::
VariableDeclarationList
*
ast
)
override
;
636
637
bool
visit
(
QQmlJS
::
AST
::
PatternElement
*
ast
)
override
;
638
bool
visit
(
QQmlJS
::
AST
::
PatternElementList
*
ast
)
override
;
639
bool
visit
(
QQmlJS
::
AST
::
PatternProperty
*
ast
)
override
;
640
bool
visit
(
QQmlJS
::
AST
::
PatternPropertyList
*
ast
)
override
;
641
642
bool
visit
(
QQmlJS
::
AST
::
ExportDeclaration
*
ast
)
override
;
643
644
bool
visit
(
QQmlJS
::
AST
::
TypeAnnotation
*
ast
)
override
;
645
646
// expressions
647
bool
visit
(
QQmlJS
::
AST
::
ArrayPattern
*
ast
)
override
;
648
bool
visit
(
QQmlJS
::
AST
::
ArrayMemberExpression
*
ast
)
override
;
649
bool
visit
(
QQmlJS
::
AST
::
BinaryExpression
*
ast
)
override
;
650
bool
visit
(
QQmlJS
::
AST
::
CallExpression
*
ast
)
override
;
651
void
endVisit
(
QQmlJS
::
AST
::
CallExpression
*
ast
)
override
;
652
bool
visit
(
QQmlJS
::
AST
::
CommaExpression
*
ast
)
override
;
653
bool
visit
(
QQmlJS
::
AST
::
ConditionalExpression
*
ast
)
override
;
654
bool
visit
(
QQmlJS
::
AST
::
DeleteExpression
*
ast
)
override
;
655
void
endVisit
(
QQmlJS
::
AST
::
DeleteExpression
*
ast
)
override
;
656
bool
visit
(
QQmlJS
::
AST
::
FalseLiteral
*
ast
)
override
;
657
bool
visit
(
QQmlJS
::
AST
::
SuperLiteral
*
ast
)
override
;
658
bool
visit
(
QQmlJS
::
AST
::
FieldMemberExpression
*
ast
)
override
;
659
void
endVisit
(
QQmlJS
::
AST
::
FieldMemberExpression
*
ast
)
override
;
660
bool
visit
(
QQmlJS
::
AST
::
TaggedTemplate
*
ast
)
override
;
661
bool
visit
(
QQmlJS
::
AST
::
FunctionExpression
*
ast
)
override
;
662
bool
visit
(
QQmlJS
::
AST
::
IdentifierExpression
*
ast
)
override
;
663
bool
visit
(
QQmlJS
::
AST
::
NestedExpression
*
ast
)
override
;
664
bool
visit
(
QQmlJS
::
AST
::
NewExpression
*
ast
)
override
;
665
bool
visit
(
QQmlJS
::
AST
::
NewMemberExpression
*
ast
)
override
;
666
bool
visit
(
QQmlJS
::
AST
::
NotExpression
*
ast
)
override
;
667
bool
visit
(
QQmlJS
::
AST
::
NullExpression
*
ast
)
override
;
668
bool
visit
(
QQmlJS
::
AST
::
NumericLiteral
*
ast
)
override
;
669
bool
visit
(
QQmlJS
::
AST
::
ObjectPattern
*
ast
)
override
;
670
bool
visit
(
QQmlJS
::
AST
::
PostDecrementExpression
*
ast
)
override
;
671
bool
visit
(
QQmlJS
::
AST
::
PostIncrementExpression
*
ast
)
override
;
672
bool
visit
(
QQmlJS
::
AST
::
PreDecrementExpression
*
ast
)
override
;
673
bool
visit
(
QQmlJS
::
AST
::
PreIncrementExpression
*
ast
)
override
;
674
bool
visit
(
QQmlJS
::
AST
::
RegExpLiteral
*
ast
)
override
;
675
bool
visit
(
QQmlJS
::
AST
::
StringLiteral
*
ast
)
override
;
676
bool
visit
(
QQmlJS
::
AST
::
TemplateLiteral
*
ast
)
override
;
677
bool
visit
(
QQmlJS
::
AST
::
ThisExpression
*
ast
)
override
;
678
bool
visit
(
QQmlJS
::
AST
::
TildeExpression
*
ast
)
override
;
679
bool
visit
(
QQmlJS
::
AST
::
TrueLiteral
*
ast
)
override
;
680
bool
visit
(
QQmlJS
::
AST
::
TypeOfExpression
*
ast
)
override
;
681
bool
visit
(
QQmlJS
::
AST
::
UnaryMinusExpression
*
ast
)
override
;
682
bool
visit
(
QQmlJS
::
AST
::
UnaryPlusExpression
*
ast
)
override
;
683
bool
visit
(
QQmlJS
::
AST
::
VoidExpression
*
ast
)
override
;
684
bool
visit
(
QQmlJS
::
AST
::
FunctionDeclaration
*
ast
)
override
;
685
bool
visit
(
QQmlJS
::
AST
::
YieldExpression
*
ast
)
override
;
686
bool
visit
(
QQmlJS
::
AST
::
ClassExpression
*
ast
)
override
;
687
bool
visit
(
QQmlJS
::
AST
::
ClassDeclaration
*
ast
)
override
;
688
689
// statements
690
bool
visit
(
QQmlJS
::
AST
::
Block
*
ast
)
override
;
691
bool
visit
(
QQmlJS
::
AST
::
BreakStatement
*
ast
)
override
;
692
bool
visit
(
QQmlJS
::
AST
::
ContinueStatement
*
ast
)
override
;
693
bool
visit
(
QQmlJS
::
AST
::
DebuggerStatement
*
ast
)
override
;
694
bool
visit
(
QQmlJS
::
AST
::
DoWhileStatement
*
ast
)
override
;
695
bool
visit
(
QQmlJS
::
AST
::
EmptyStatement
*
ast
)
override
;
696
bool
visit
(
QQmlJS
::
AST
::
ExpressionStatement
*
ast
)
override
;
697
bool
visit
(
QQmlJS
::
AST
::
ForEachStatement
*
ast
)
override
;
698
bool
visit
(
QQmlJS
::
AST
::
ForStatement
*
ast
)
override
;
699
bool
visit
(
QQmlJS
::
AST
::
IfStatement
*
ast
)
override
;
700
bool
visit
(
QQmlJS
::
AST
::
LabelledStatement
*
ast
)
override
;
701
bool
visit
(
QQmlJS
::
AST
::
ReturnStatement
*
ast
)
override
;
702
bool
visit
(
QQmlJS
::
AST
::
SwitchStatement
*
ast
)
override
;
703
bool
visit
(
QQmlJS
::
AST
::
ThrowStatement
*
ast
)
override
;
704
bool
visit
(
QQmlJS
::
AST
::
TryStatement
*
ast
)
override
;
705
bool
visit
(
QQmlJS
::
AST
::
VariableStatement
*
ast
)
override
;
706
bool
visit
(
QQmlJS
::
AST
::
WhileStatement
*
ast
)
override
;
707
bool
visit
(
QQmlJS
::
AST
::
WithStatement
*
ast
)
override
;
708
709
// ui object members
710
bool
visit
(
QQmlJS
::
AST
::
UiArrayBinding
*
ast
)
override
;
711
bool
visit
(
QQmlJS
::
AST
::
UiObjectBinding
*
ast
)
override
;
712
bool
visit
(
QQmlJS
::
AST
::
UiObjectDefinition
*
ast
)
override
;
713
bool
visit
(
QQmlJS
::
AST
::
UiPublicMember
*
ast
)
override
;
714
bool
visit
(
QQmlJS
::
AST
::
UiScriptBinding
*
ast
)
override
;
715
bool
visit
(
QQmlJS
::
AST
::
UiSourceElement
*
ast
)
override
;
716
717
bool
throwSyntaxErrorOnEvalOrArgumentsInStrictMode
(
const
Reference
&
r
,
718
const
QQmlJS
::
SourceLocation
&
loc
);
719
virtual
void
throwSyntaxError
(
const
QQmlJS
::
SourceLocation
&
loc
,
const
QString
&
detail
);
720
virtual
void
throwReferenceError
(
const
QQmlJS
::
SourceLocation
&
loc
,
const
QString
&
detail
);
721
void
throwRecursionDepthError
()
override
722
{
723
throwSyntaxError
(
QQmlJS
::
SourceLocation
(),
724
QStringLiteral
(
"Maximum statement or expression depth exceeded"
));
725
}
726
727
public
:
728
enum
ErrorType
{
729
NoError
,
730
SyntaxError
,
731
ReferenceError
732
};
733
734
ErrorType
errorType
()
const
{
return
_errorType
; }
735
bool
hasError
()
const
{
return
_errorType
!=
NoError
; }
736
QQmlJS
::
DiagnosticMessage
error
()
const
;
737
QUrl
url
()
const
;
738
739
Reference
binopHelper
(
QQmlJS
::
AST
::
BinaryExpression
*
ast
,
QSOperator
::
Op
oper
,
Reference
&
left
,
740
Reference
&
right
);
741
Reference
jumpBinop
(
QSOperator
::
Op
oper
,
Reference
&
left
,
Reference
&
right
);
742
struct
Arguments
{
int
argc
;
int
argv
;
bool
hasSpread
; };
743
Arguments
pushArgs
(
QQmlJS
::
AST
::
ArgumentList
*
args
);
744
void
handleCall
(
Reference
&
base
,
Arguments
calldata
,
int
slotForFunction
,
int
slotForThisObject
,
bool
optional
=
false
);
745
746
Arguments
pushTemplateArgs
(
QQmlJS
::
AST
::
TemplateLiteral
*
args
);
747
bool
handleTaggedTemplate
(
Reference
base
,
QQmlJS
::
AST
::
TaggedTemplate
*
ast
);
748
void
createTemplateObject
(
QQmlJS
::
AST
::
TemplateLiteral
*
t
);
749
750
void
setUseFastLookups
(
bool
b
) {
useFastLookups
=
b
; }
751
752
void
handleTryCatch
(
QQmlJS
::
AST
::
TryStatement
*
ast
);
753
void
handleTryFinally
(
QQmlJS
::
AST
::
TryStatement
*
ast
);
754
755
756
Reference
referenceForName
(
757
const
QString
&
name
,
bool
lhs
,
758
const
QQmlJS
::
SourceLocation
&
accessLocation
=
QQmlJS
::
SourceLocation
());
759
760
QQmlRefPointer
<
QV4
::
CompiledData
::
CompilationUnit
>
generateCompilationUnit
(
761
bool
generateUnitData
=
true
);
762
static
QQmlRefPointer
<
QV4
::
CompiledData
::
CompilationUnit
>
compileModule
(
763
Moth
::
DebugInstructionPass
debugInstructionPass
,
const
QString
&
url
,
764
const
QString
&
sourceCode
,
const
QDateTime
&
sourceTimeStamp
,
QList
<
QQmlJS
::
DiagnosticMessage
> *
diagnostics
);
765
766
static
const
QV4
::
CompiledData
::
Unit
*
generateNativeModuleUnitData
(
767
Moth
::
DebugInstructionPass
debugInstructionPass
,
const
QString
&
url
,
768
const
QV4
::
Value
&
value
);
769
770
Context
*
currentContext
()
const
{
return
_context
; }
771
BytecodeGenerator
*
generator
()
const
{
return
bytecodeGenerator
; }
772
773
void
loadClosure
(
int
index
);
774
775
Module
*
module
()
const
{
return
_module
; }
776
777
BytecodeGenerator
::
Label
returnLabel
() {
778
if
(!
_returnLabel
)
779
_returnLabel
=
new
BytecodeGenerator
::
Label
(
bytecodeGenerator
->
newLabel
());
780
return
*
_returnLabel
;
781
}
782
783
protected
:
784
friend
class
ScanFunctions
;
785
friend
struct
ControlFlow
;
786
friend
struct
ControlFlowCatch
;
787
friend
struct
ControlFlowFinally
;
788
789
inline
void
setExprResult
(
const
Reference
&
result
) {
m_expressions
.
back
().
setResult
(
result
); }
790
inline
void
setExprResult
(
Reference
&&
result
) {
m_expressions
.
back
().
setResult
(
std
::
move
(
result
)); }
791
inline
Reference
exprResult
()
const
{
return
m_expressions
.
back
().
result
(); }
792
inline
void
clearExprResultName
() {
m_expressions
.
back
().
clearResultName
(); }
793
794
inline
bool
exprAccept
(
Format
f
) {
return
m_expressions
.
back
().
accept
(
f
); }
795
796
inline
const
Result
&
currentExpr
()
const
{
return
m_expressions
.
back
(); }
797
798
inline
void
pushExpr
(
Result
&&
expr
) {
m_expressions
.
push_back
(
std
::
move
(
expr
)); }
799
inline
void
pushExpr
(
const
Result
&
expr
) {
m_expressions
.
push_back
(
expr
); }
800
inline
void
pushExpr
(
const
QString
&
name
=
QString
()) {
m_expressions
.
emplace_back
(
name
); }
801
802
inline
Result
popExpr
()
803
{
804
const
Result
result
=
m_expressions
.
back
();
805
m_expressions
.
pop_back
();
806
return
result
;
807
}
808
809
inline
Reference
popResult
() {
810
const
Reference
result
=
m_expressions
.
back
().
result
();
811
m_expressions
.
pop_back
();
812
return
result
;
813
}
814
815
std
::
vector
<
Result
>
m_expressions
;
816
VolatileMemoryLocations
_volatileMemoryLocations
;
817
Module
*
_module
;
818
int
_returnAddress
;
819
Context
*
_context
;
820
Context
*
_functionContext
=
nullptr
;
821
QQmlJS
::
AST
::
LabelledStatement
*
_labelledStatement
;
822
QV4
::
Compiler
::
JSUnitGenerator
*
jsUnitGenerator
;
823
BytecodeGenerator
*
bytecodeGenerator
=
nullptr
;
824
Moth
::
BytecodeGenerator
::
Label
*
_returnLabel
=
nullptr
;
825
bool
_strictMode
;
826
bool
useFastLookups
=
true
;
827
bool
requiresReturnValue
=
false
;
828
bool
insideSwitch
=
false
;
829
bool
inFormalParameterList
=
false
;
830
bool
_tailCallsAreAllowed
=
true
;
831
bool
storeSourceLocations
=
false
;
832
833
struct
OptionalChainState
834
{
835
QQmlJS
::
AST
::
Node
*
tailNodeOfChain
=
nullptr
;
836
std
::
vector
<
Moth
::
BytecodeGenerator
::
Jump
>
jumpsToPatch
;
837
bool
actuallyHasOptionals
=
false
;
838
};
839
using
OptionalChainStates
=
std
::
stack
<
OptionalChainState
,
std
::
vector
<
OptionalChainState
>>;
840
841
QSet
<
QQmlJS
::
AST
::
Node
*>
m_seenOptionalChainNodes
;
842
OptionalChainStates
*
m_optionalChainsStates
=
nullptr
;
843
844
ControlFlow
*
controlFlow
=
nullptr
;
845
846
bool
_fileNameIsUrl
;
847
ErrorType
_errorType
=
NoError
;
848
QQmlJS
::
DiagnosticMessage
_error
;
849
CodegenWarningInterface
*
_interface
;
850
851
class
TailCallBlocker
852
{
853
public
:
854
TailCallBlocker
(
Codegen
*
cg
,
bool
onoff
=
false
)
855
:
_cg
(
cg
)
856
,
_saved
(
_cg
->
_tailCallsAreAllowed
)
857
,
_onoff
(
onoff
)
858
{
_cg
->
_tailCallsAreAllowed
=
onoff
; }
859
860
~
TailCallBlocker
()
861
{
_cg
->
_tailCallsAreAllowed
=
_saved
; }
862
863
void
unblock
()
const
864
{
_cg
->
_tailCallsAreAllowed
=
_saved
; }
865
866
void
reblock
()
const
867
{
_cg
->
_tailCallsAreAllowed
=
_onoff
; }
868
869
private
:
870
Codegen
*
_cg
;
871
bool
_saved
;
872
bool
_onoff
;
873
};
874
875
private
:
876
Q_DISABLE_COPY
(
Codegen
)
877
VolatileMemoryLocations
scanVolatileMemoryLocations
(
QQmlJS
::
AST
::
Node
*
ast
);
878
void
handleConstruct
(
const
Reference
&
base
,
QQmlJS
::
AST
::
ArgumentList
*
args
);
879
void
throwError
(
ErrorType
errorType
,
const
QQmlJS
::
SourceLocation
&
loc
,
880
const
QString
&
detail
);
881
bool
traverseOptionalChain
(
QQmlJS
::
AST
::
Node
*
node
);
882
void
optionalChainFinalizer
(
const
Reference
&
expressionResult
,
bool
tailOfChain
,
883
bool
isDeleteExpression
=
false
);
884
Reference
loadSubscriptForCall
(
const
Reference
&
base
);
885
void
generateThrowException
(
const
QString
&
type
,
const
QString
&
text
=
QString
());
886
};
887
888
}
889
890
}
891
892
QT_END_NAMESPACE
893
894
#
endif
// QV4CODEGEN_P_H
QV4::Compiler::Codegen::VolatileMemoryLocationScanner
Definition
qv4codegen.cpp:4338
QV4::Compiler::Codegen::VolatileMemoryLocationScanner::throwRecursionDepthError
void throwRecursionDepthError() override
Definition
qv4codegen.cpp:4418
QV4::Compiler::Codegen::VolatileMemoryLocationScanner::VolatileMemoryLocationScanner
VolatileMemoryLocationScanner(Codegen *parent)
Definition
qv4codegen.cpp:4343
QV4::Compiler::Codegen::VolatileMemoryLocationScanner::scan
Codegen::VolatileMemoryLocations scan(AST::Node *s)
Definition
qv4codegen.cpp:4348
QV4::Compiler::Codegen::VolatileMemoryLocationScanner::visit
bool visit(ArrayMemberExpression *) override
Definition
qv4codegen.cpp:4354
QV4::Compiler::CodegenWarningInterface
Definition
qv4codegen_p.h:53
QV4::Compiler::Codegen
Definition
qv4codegen_p.h:88
QV4::CompiledData
Definition
qv4compileddata.cpp:22
QV4::Compiler
Definition
qv4compiler_p.h:40
QV4::Compiler::defaultCodegenWarningInterface
CodegenWarningInterface * defaultCodegenWarningInterface()
Definition
qv4codegen_p.h:81
QV4::Moth
Definition
qv4debuginstructions.cpp:10
QV4
Definition
qjsvalue.h:24
Q_STATIC_LOGGING_CATEGORY
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
completionStatement
static Node * completionStatement(StatementList *list)
Definition
qv4codegen.cpp:569
completionState
static CompletionState completionState(StatementList *list)
Definition
qv4codegen.cpp:548
baseOp
static QSOperator::Op baseOp(int op)
Definition
qv4codegen.cpp:1433
CompletionState
CompletionState
Definition
qv4codegen.cpp:542
CompletionState::Empty
@ Empty
Definition
qv4codegen.cpp:543
CompletionState::EmptyAbrupt
@ EmptyAbrupt
Definition
qv4codegen.cpp:544
CompletionState::NonEmpty
@ NonEmpty
Definition
qv4codegen.cpp:545
setJumpOutLocation
static void setJumpOutLocation(QV4::Moth::BytecodeGenerator *bytecodeGenerator, const Statement *body, const SourceLocation &fallback)
Definition
qv4codegen.cpp:62
s_globalNames
static constexpr const QLatin1StringView s_globalNames[]
Definition
qv4codegen.cpp:119
QV4::CompiledData::CompilationUnit::IdToObjectMap
QMap< int, int > IdToObjectMap
Definition
qv4compileddata_p.h:1555
QV4::Compiler::ControlFlowCatch
Definition
qv4compilercontrolflow_p.h:301
QV4::Compiler::ControlFlowFinally
Definition
qv4compilercontrolflow_p.h:362
QV4::Compiler::ControlFlow
Definition
qv4compilercontrolflow_p.h:29
QV4::Moth::Instruction
Definition
qv4instr_moth_p.h:655
qtdeclarative
src
qml
compiler
qv4codegen_p.h
Generated on
for Qt by
1.18.0