17#include <private/qqmljsastvisitor_p.h>
18#include <private/qqmljsengine_p.h>
19#include <private/qqmljsast_p.h>
20#include <private/qqmljsdiagnosticmessage_p.h>
21#include <private/qv4compiler_p.h>
22#include <private/qv4compilercontext_p.h>
23#include <private/qv4util_p.h>
24#include <private/qv4bytecodegenerator_p.h>
25#include <private/qv4calldata_p.h>
27#include <QtCore/qsharedpointer.h>
38namespace CompiledData {
39struct CompilationUnit;
45struct ControlFlowCatch;
46struct ControlFlowFinally;
71 bool storeSourceLocations =
false);
90 bool allVolatile =
false;
91 QList<QStringView> specificLocations;
96 return specificLocations.contains(
name);
120 r.theStackSlot = stackSlot;
126 r.type = Accumulator;
155 void loadInAccumulator()
const;
186 isReferenceToConst(
false),
187 requiresTDZCheck(
false),
188 subscriptRequiresTDZCheck(
false),
189 stackSlotIsLocalOrArgument(
false),
193 throwsReferenceError(
false),
194 subscriptLoadedForCall(
false),
196 hasSavedCallBaseSlot(
false)
206 {
return !(*
this ==
other); }
217 return requiresTDZCheck;
226 return isStackSlot();
239 r.theStackSlot = Moth::StackSlot::createRegister(tempIndex);
240 r.stackSlotIsLocalOrArgument = isLocal;
262 bool isOptional =
false,
263 std::vector<Moth::BytecodeGenerator::Jump> *optionalChainJumpsToPatch =
nullptr)
267 r.propertyBase = baseRef.asRValue();
268 r.propertyNameIndex =
r.codegen->registerString(
name);
269 r.requiresTDZCheck = baseRef.requiresTDZCheck;
270 r.sourceLocation = sourceLocation;
271 r.optionalChainJumpsToPatch = optionalChainJumpsToPatch;
272 r.isOptional = isOptional;
278 r.property =
property.stackSlot();
279 r.subscriptRequiresTDZCheck =
property.requiresTDZCheck;
285 r.elementBase = baseRef.stackSlot();
286 r.elementSubscript = subscript.asRValue();
287 r.requiresTDZCheck = baseRef.requiresTDZCheck;
288 r.subscriptRequiresTDZCheck = subscript.requiresTDZCheck;
298 Reference r = fromStackSlot(cg, CallData::This);
302 r.requiresTDZCheck =
true;
310 {
return Reference::fromConst(cg,
constant).storeOnStack(); }
313 { Reference::fromConst(cg,
constant).storeOnStack(stackSlot); }
316 void storeOnStack(
int tempIndex)
const;
318 Reference storeConsumeAccumulator()
const;
322 bool storeWipesAccumulator()
const;
323 void loadInAccumulator()
const;
327 return codegen->registerString(
name);
339 tdzCheck(requiresTDZCheck, throwsReferenceError);
340 else if (isStackSlot())
341 tdzCheckStackSlot(stackSlot(), requiresTDZCheck, throwsReferenceError);
381 std::vector<Moth::BytecodeGenerator::Jump> *optionalChainJumpsToPatch =
nullptr;
382 int savedCallBaseSlot = -1;
383 int savedCallPropertyNameIndex = -1;
386 void storeAccumulator()
const;
387 Reference doStoreOnStack(
int tempIndex)
const;
388 void tdzCheck(
bool requiresCheck,
bool throwsReferenceError)
const;
389 void tdzCheckStackSlot(
390 Moth::StackSlot slot,
bool requiresCheck,
bool throwsReferenceError)
const;
396 regCountForScope(
generator->currentReg) {}
398 generator->currentReg = regCountForScope;
425 bool _trueBlockFollowsCondition =
false;
439 : _requested(requested) {}
443 bool trueBlockFollowsCondition)
447 , _trueBlockFollowsCondition(trueBlockFollowsCondition)
469 if (_requested ==
f) {
477 return _trueBlockFollowsCondition;
489 _result = std::move(
result);
516 Reference unop(UnaryOperation op,
const Reference &expr);
554 const BytecodeGenerator::Label *iffalse,
555 bool trueBlockFollowsCondition);
559 if (!ast || hasError())
569 if (!hasError() && node)
579 void initializeAndDestructureBindingElement(
QQmlJS::AST::PatternElement *e,
const Reference &baseRef = Reference(),
bool isDefinition =
false);
586 void emitReturn(
const Reference &expr);
692 bool throwSyntaxErrorOnEvalOrArgumentsInStrictMode(
const Reference &
r,
699 QStringLiteral(
"Maximum statement or expression depth exceeded"));
719 void handleCall(
Reference &
base,
Arguments calldata,
int slotForFunction,
int slotForThisObject,
bool optional =
false);
731 Reference referenceForName(
735 QQmlRefPointer<QV4::CompiledData::CompilationUnit> generateCompilationUnit(
736 bool generateUnitData =
true);
737 static QQmlRefPointer<QV4::CompiledData::CompilationUnit> compileModule(
739 const QDateTime &sourceTimeStamp, QList<QQmlJS::DiagnosticMessage> *diagnostics);
744 void loadClosure(
int index);
751 return *_returnLabel;
755 m_globalNames = globalNames;
758 static const char *s_globalNames[];
775 inline void pushExpr(
Result &&expr) { m_expressions.push_back(std::move(expr)); }
782 m_expressions.pop_back();
788 m_expressions.pop_back();
803 bool useFastLookups =
true;
804 bool requiresReturnValue =
false;
805 bool insideSwitch =
false;
806 bool inFormalParameterList =
false;
807 bool functionEndsWithReturn =
false;
808 bool _tailCallsAreAllowed =
true;
809 bool storeSourceLocations =
false;
816 bool actuallyHasOptionals =
false;
833 , _saved(_cg->_tailCallsAreAllowed)
835 { _cg->_tailCallsAreAllowed = onoff; }
838 { _cg->_tailCallsAreAllowed = _saved; }
841 { _cg->_tailCallsAreAllowed = _saved; }
844 { _cg->_tailCallsAreAllowed = _onoff; }
859 void optionalChainFinalizer(
const Reference &expressionResult,
bool tailOfChain,
860 bool isDeleteExpression =
false);
861 Reference loadSubscriptForCall(
const Reference &
base);
\inmodule QtCore\reentrant
void accept(BaseVisitor *visitor)
\macro QT_RESTRICTED_CAST_FROM_ASCII
void clear()
Clears the contents of the string and makes it null.
virtual ~CodegenWarningInterface()=default
Moth::StackSlot theStackSlot
static RValue fromStackSlot(Codegen *codegen, Moth::StackSlot stackSlot)
static RValue fromAccumulator(Codegen *codegen)
QV4::ReturnedValue constantValue() const
bool isAccumulator() const
static RValue fromConst(Codegen *codegen, QV4::ReturnedValue value)
QV4::ReturnedValue constant
Moth::StackSlot stackSlot() const
void setResult(const Reference &result)
Result(Format requested=ex)
bool trueBlockFollowsCondition() const
const BytecodeGenerator::Label * iffalse() const
const Reference & result() const
Result(const BytecodeGenerator::Label *iftrue, const BytecodeGenerator::Label *iffalse, bool trueBlockFollowsCondition)
Result(const QString &name)
Result(const Reference &lrvalue)
const BytecodeGenerator::Label * iftrue() const
void setResult(Reference &&result)
TailCallBlocker(Codegen *cg, bool onoff=false)
bool isVolatile(QStringView name)
void add(QStringView name)
void setUseFastLookups(bool b)
QQmlJS::AST::LabelledStatement * _labelledStatement
QSet< QString > m_globalNames
VolatileMemoryLocations _volatileMemoryLocations
CodegenWarningInterface * _interface
BytecodeGenerator * bytecodeGenerator
Context * currentContext() const
void accept(QQmlJS::AST::Node *node)
int registerString(const QString &name)
int registerConstant(QV4::ReturnedValue v)
int registerQmlContextPropertyGetterLookup(int nameIndex, JSUnitGenerator::LookupMode mode)
bool exprAccept(Format f)
void clearExprResultName()
QV4::Compiler::JSUnitGenerator * jsUnitGenerator
BytecodeGenerator::Label returnLabel()
int registerGetterLookup(int nameIndex, JSUnitGenerator::LookupMode mode)
void setExprResult(Reference &&result)
QSet< QQmlJS::AST::Node * > m_seenOptionalChainNodes
void pushExpr(const QString &name=QString())
int registerSetterLookup(int nameIndex)
void setExprResult(const Reference &result)
int registerGlobalGetterLookup(int nameIndex, JSUnitGenerator::LookupMode mode)
ErrorType errorType() const
std::vector< Result > m_expressions
void setGlobalNames(const QSet< QString > &globalNames)
QQmlJS::DiagnosticMessage _error
void pushExpr(Result &&expr)
const Result & currentExpr() const
Reference expression(QQmlJS::AST::ExpressionNode *ast, const QString &name=QString())
std::stack< OptionalChainState > m_optionalChainsStates
BytecodeGenerator * generator() const
void pushExpr(const Result &expr)
void throwRecursionDepthError() override
Reference exprResult() const
std::list< QString >::iterator Name
Combined button and popup list for selecting options.
CodegenWarningInterface * defaultCodegenWarningInterface()
#define Q_REQUIRED_RESULT
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
#define QStringLiteral(str)
#define Q_QML_COMPILER_EXPORT
static const QV4::Value & constant(Function *function, int index)
QRandomGenerator generator(sseq)
QUrl url("example.com")
[constructor-url-reference]
std::vector< Moth::BytecodeGenerator::Jump > jumpsToPatch
static Reference fromScopedLocal(Codegen *cg, int index, int scope)
Reference(Reference &&)=default
static Reference fromImport(Codegen *cg, int index)
quint32 isReferenceToConst
Moth::StackSlot stackSlot() const
bool loadTriggersSideEffect() const
bool isAccumulator() const
static void storeConstOnStack(Codegen *cg, QV4::ReturnedValue constant, int stackSlot)
quint32 hasSavedCallBaseSlot
static Reference fromConst(Codegen *cg, QV4::ReturnedValue constant)
Reference(const Reference &)=default
static Reference fromName(Codegen *cg, const QString &name)
static Reference fromMember(const Reference &baseRef, const QString &name, QQmlJS::SourceLocation sourceLocation=QQmlJS::SourceLocation(), bool isOptional=false, std::vector< Moth::BytecodeGenerator::Jump > *optionalChainJumpsToPatch=nullptr)
bool isSuperProperty() const
static Reference fromAccumulator(Codegen *cg)
Reference(Codegen *cg, Type t=Invalid)
static Reference fromSuperProperty(const Reference &property)
static Reference fromStackSlot(Codegen *cg, int tempIndex=-1, bool isLocal=false)
Moth::StackSlot theStackSlot
QV4::ReturnedValue constant
Moth::StackSlot elementBase
quint32 stackSlotIsLocalOrArgument
quint32 subscriptLoadedForCall
static Reference fromSubscript(const Reference &baseRef, const Reference &subscript)
static Q_REQUIRED_RESULT Reference storeConstOnStack(Codegen *cg, QV4::ReturnedValue constant)
Reference(const QString &name=QString())
quint32 subscriptRequiresTDZCheck
bool operator!=(const Reference &other) const
static Reference fromThis(Codegen *cg)
quint32 throwsReferenceError
static Reference fromSuper(Codegen *cg)
BytecodeGenerator * generator
RegisterScope(Codegen *cg)
int registerGlobalGetterLookup(int nameIndex, LookupMode mode)
int registerSetterLookup(const QString &name)
int registerQmlContextPropertyGetterLookup(int nameIndex, LookupMode mode)
int registerConstant(ReturnedValue v)
int registerGetterLookup(const QString &name, LookupMode mode)
int registerString(const QString &str)