2014-10-27 18:43:09 -04:00
|
|
|
/*
|
|
|
|
AngelCode Scripting Library
|
2021-11-04 16:43:10 -04:00
|
|
|
Copyright (c) 2003-2020 Andreas Jonsson
|
2014-10-27 18:43:09 -04:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you
|
|
|
|
must not claim that you wrote the original software. If you use
|
|
|
|
this software in a product, an acknowledgment in the product
|
|
|
|
documentation would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
|
|
|
|
The original version of this library can be located at:
|
|
|
|
http://www.angelcode.com/angelscript/
|
|
|
|
|
|
|
|
Andreas Jonsson
|
|
|
|
andreas@angelcode.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// as_compiler.h
|
|
|
|
//
|
|
|
|
// The class that does the actual compilation of the functions
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef AS_COMPILER_H
|
|
|
|
#define AS_COMPILER_H
|
|
|
|
|
|
|
|
#include "as_config.h"
|
|
|
|
|
|
|
|
#ifndef AS_NO_COMPILER
|
|
|
|
|
|
|
|
#include "as_builder.h"
|
|
|
|
#include "as_scriptfunction.h"
|
|
|
|
#include "as_variablescope.h"
|
|
|
|
#include "as_bytecode.h"
|
|
|
|
#include "as_array.h"
|
|
|
|
#include "as_datatype.h"
|
|
|
|
|
|
|
|
BEGIN_AS_NAMESPACE
|
|
|
|
|
2017-11-20 08:02:33 -05:00
|
|
|
// This class represents the value of an expression as evaluated by the compiler.
|
|
|
|
// It holds information such as the type of the value, stack offset for a local
|
|
|
|
// variable, value of constants, whether the value can be modified (i.e. lvalue), etc.
|
|
|
|
struct asCExprValue
|
|
|
|
{
|
|
|
|
asCExprValue();
|
|
|
|
void Set(const asCDataType &dataType);
|
|
|
|
|
|
|
|
void SetVariable(const asCDataType &dataType, int stackOffset, bool isTemporary);
|
|
|
|
void SetConstantB(const asCDataType &dataType, asBYTE value);
|
|
|
|
void SetConstantQW(const asCDataType &dataType, asQWORD value);
|
|
|
|
void SetConstantDW(const asCDataType &dataType, asDWORD value);
|
|
|
|
void SetConstantW(const asCDataType &dataType, asWORD value);
|
|
|
|
void SetConstantF(const asCDataType &dataType, float value);
|
|
|
|
void SetConstantD(const asCDataType &dataType, double value);
|
|
|
|
void SetConstantB(asBYTE value);
|
|
|
|
void SetConstantW(asWORD value);
|
|
|
|
void SetConstantQW(asQWORD value);
|
|
|
|
void SetConstantDW(asDWORD value);
|
|
|
|
void SetConstantF(float value);
|
|
|
|
void SetConstantD(double value);
|
|
|
|
asBYTE GetConstantB();
|
|
|
|
asWORD GetConstantW();
|
|
|
|
asQWORD GetConstantQW();
|
|
|
|
asDWORD GetConstantDW();
|
|
|
|
float GetConstantF();
|
|
|
|
double GetConstantD();
|
|
|
|
|
|
|
|
void SetConstantData(const asCDataType &dataType, asQWORD value);
|
|
|
|
asQWORD GetConstantData();
|
|
|
|
|
|
|
|
void SetNullConstant();
|
|
|
|
void SetUndefinedFuncHandle(asCScriptEngine *engine);
|
|
|
|
void SetVoid();
|
|
|
|
void SetDummy();
|
|
|
|
|
|
|
|
bool IsUndefinedFuncHandle() const;
|
|
|
|
bool IsNullConstant() const;
|
|
|
|
bool IsVoid() const;
|
|
|
|
|
|
|
|
asCDataType dataType;
|
|
|
|
bool isLValue : 1; // Can this value be updated in assignment, or increment operators, etc
|
|
|
|
bool isTemporary : 1;
|
|
|
|
bool isConstant : 1;
|
|
|
|
bool isVariable : 1;
|
|
|
|
bool isExplicitHandle : 1;
|
|
|
|
bool isRefToLocal : 1; // The reference may be to a local variable
|
2021-11-04 16:43:10 -04:00
|
|
|
bool isRefSafe : 1; // the life-time of the ref is guaranteed for the duration of the access
|
2017-11-20 08:02:33 -05:00
|
|
|
short dummy : 9;
|
|
|
|
short stackOffset;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// These values must not be accessed directly in order to avoid problems with endianess.
|
|
|
|
// Use the appropriate accessor methods instead
|
|
|
|
union
|
|
|
|
{
|
|
|
|
asQWORD qwordValue;
|
|
|
|
double doubleValue;
|
|
|
|
asDWORD dwordValue;
|
|
|
|
float floatValue;
|
|
|
|
asWORD wordValue;
|
|
|
|
asBYTE byteValue;
|
|
|
|
};
|
|
|
|
};
|
2014-10-27 18:43:09 -04:00
|
|
|
|
2017-11-20 08:02:33 -05:00
|
|
|
struct asCExprContext;
|
|
|
|
|
|
|
|
// This class holds information for arguments that needs to be
|
|
|
|
// cleaned up after the result of a function has been evaluated.
|
2014-10-27 18:43:09 -04:00
|
|
|
struct asSDeferredParam
|
|
|
|
{
|
|
|
|
asSDeferredParam() {argNode = 0; origExpr = 0;}
|
|
|
|
|
|
|
|
asCScriptNode *argNode;
|
2017-11-20 08:02:33 -05:00
|
|
|
asCExprValue argType;
|
2014-10-27 18:43:09 -04:00
|
|
|
int argInOutFlags;
|
2017-11-20 08:02:33 -05:00
|
|
|
asCExprContext *origExpr;
|
2014-10-27 18:43:09 -04:00
|
|
|
};
|
|
|
|
|
2017-11-20 08:02:33 -05:00
|
|
|
// TODO: refactor: asCExprContext should have indicators to inform where the value is,
|
2014-10-27 18:43:09 -04:00
|
|
|
// i.e. if the reference to an object is pushed on the stack or not, etc
|
|
|
|
|
2017-11-20 08:02:33 -05:00
|
|
|
// This class holds information about an expression that is being evaluated, e.g.
|
|
|
|
// the current bytecode, ambiguous symbol names, property accessors, etc.
|
|
|
|
struct asCExprContext
|
2014-10-27 18:43:09 -04:00
|
|
|
{
|
2017-11-20 08:02:33 -05:00
|
|
|
asCExprContext(asCScriptEngine *engine);
|
|
|
|
~asCExprContext();
|
|
|
|
void Clear();
|
|
|
|
bool IsClassMethod() const;
|
|
|
|
bool IsGlobalFunc() const;
|
|
|
|
void SetLambda(asCScriptNode *funcDecl);
|
|
|
|
bool IsLambda() const;
|
|
|
|
void SetVoidExpression();
|
|
|
|
bool IsVoidExpression() const;
|
|
|
|
void Merge(asCExprContext *after);
|
2021-11-04 16:43:10 -04:00
|
|
|
void Copy(asCExprContext *other);
|
|
|
|
void SetAnonymousInitList(asCScriptNode *initList, asCScriptCode *script);
|
2017-11-20 08:02:33 -05:00
|
|
|
bool IsAnonymousInitList() const;
|
2014-10-27 18:43:09 -04:00
|
|
|
|
|
|
|
asCByteCode bc;
|
2017-11-20 08:02:33 -05:00
|
|
|
asCExprValue type;
|
2014-10-27 18:43:09 -04:00
|
|
|
int property_get;
|
|
|
|
int property_set;
|
2016-02-17 23:07:55 -05:00
|
|
|
bool property_const; // If the object that is being accessed through property accessor is read-only
|
|
|
|
bool property_handle; // If the property accessor is called on an object stored in a handle
|
|
|
|
bool property_ref; // If the property accessor is called on a reference
|
|
|
|
bool isVoidExpression; // Set to true if the expression is an explicit 'void', e.g. used to ignore out parameters in func calls
|
|
|
|
bool isCleanArg; // Set to true if the expression has only been initialized with default constructor
|
2017-11-20 08:02:33 -05:00
|
|
|
asCExprContext *property_arg;
|
2014-10-27 18:43:09 -04:00
|
|
|
asCArray<asSDeferredParam> deferredParams;
|
|
|
|
asCScriptNode *exprNode;
|
2017-11-20 08:02:33 -05:00
|
|
|
asCExprContext *origExpr;
|
2021-11-04 16:43:10 -04:00
|
|
|
asCScriptCode *origCode;
|
2014-10-27 18:43:09 -04:00
|
|
|
// TODO: cleanup: use ambiguousName and an enum to say if it is a method, global func, or enum value
|
|
|
|
asCString methodName;
|
|
|
|
asCString enumValue;
|
2021-11-04 16:43:10 -04:00
|
|
|
asSNameSpace *symbolNamespace; // The namespace in which the ambiguous symbol was found
|
2017-11-20 08:02:33 -05:00
|
|
|
bool isAnonymousInitList; // Set to true if the expression is an init list for which the type has not yet been determined
|
2014-10-27 18:43:09 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct asSOverloadCandidate
|
|
|
|
{
|
|
|
|
asSOverloadCandidate() : funcId(0), cost(0) {}
|
2017-11-20 08:02:33 -05:00
|
|
|
asSOverloadCandidate(int _id, asUINT _cost) : funcId(_id), cost(_cost) {}
|
2014-10-27 18:43:09 -04:00
|
|
|
int funcId;
|
|
|
|
asUINT cost;
|
|
|
|
};
|
|
|
|
|
2015-05-11 19:40:43 -04:00
|
|
|
struct asSNamedArgument
|
|
|
|
{
|
|
|
|
asCString name;
|
2017-11-20 08:02:33 -05:00
|
|
|
asCExprContext *ctx;
|
2015-05-11 19:40:43 -04:00
|
|
|
asUINT match;
|
|
|
|
};
|
|
|
|
|
2014-10-27 18:43:09 -04:00
|
|
|
enum EImplicitConv
|
|
|
|
{
|
|
|
|
asIC_IMPLICIT_CONV,
|
|
|
|
asIC_EXPLICIT_REF_CAST,
|
|
|
|
asIC_EXPLICIT_VAL_CAST
|
|
|
|
};
|
|
|
|
|
|
|
|
enum EConvCost
|
|
|
|
{
|
|
|
|
asCC_NO_CONV = 0,
|
|
|
|
asCC_CONST_CONV = 1,
|
2017-11-20 08:02:33 -05:00
|
|
|
asCC_ENUM_SAME_SIZE_CONV = 2,
|
|
|
|
asCC_ENUM_DIFF_SIZE_CONV = 3,
|
|
|
|
asCC_PRIMITIVE_SIZE_CONV = 4,
|
|
|
|
asCC_SIGNED_CONV = 5,
|
|
|
|
asCC_INT_FLOAT_CONV = 6,
|
|
|
|
asCC_REF_CONV = 7,
|
|
|
|
asCC_OBJ_TO_PRIMITIVE_CONV = 8,
|
|
|
|
asCC_TO_OBJECT_CONV = 9,
|
|
|
|
asCC_VARIABLE_CONV = 10
|
2014-10-27 18:43:09 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class asCCompiler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
asCCompiler(asCScriptEngine *engine);
|
|
|
|
~asCCompiler();
|
|
|
|
|
|
|
|
int CompileFunction(asCBuilder *builder, asCScriptCode *script, asCArray<asCString> ¶meterNames, asCScriptNode *func, asCScriptFunction *outFunc, sClassDeclaration *classDecl);
|
|
|
|
int CompileDefaultConstructor(asCBuilder *builder, asCScriptCode *script, asCScriptNode *node, asCScriptFunction *outFunc, sClassDeclaration *classDecl);
|
|
|
|
int CompileFactory(asCBuilder *builder, asCScriptCode *script, asCScriptFunction *outFunc);
|
|
|
|
int CompileGlobalVariable(asCBuilder *builder, asCScriptCode *script, asCScriptNode *expr, sGlobalVariableDescription *gvar, asCScriptFunction *outFunc);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class asCBuilder;
|
|
|
|
|
|
|
|
void Reset(asCBuilder *builder, asCScriptCode *script, asCScriptFunction *outFunc);
|
|
|
|
|
|
|
|
// Statements
|
|
|
|
void CompileStatementBlock(asCScriptNode *block, bool ownVariableScope, bool *hasReturn, asCByteCode *bc);
|
|
|
|
void CompileDeclaration(asCScriptNode *decl, asCByteCode *bc);
|
|
|
|
void CompileStatement(asCScriptNode *statement, bool *hasReturn, asCByteCode *bc);
|
|
|
|
void CompileIfStatement(asCScriptNode *node, bool *hasReturn, asCByteCode *bc);
|
|
|
|
void CompileSwitchStatement(asCScriptNode *node, bool *hasReturn, asCByteCode *bc);
|
|
|
|
void CompileCase(asCScriptNode *node, asCByteCode *bc);
|
|
|
|
void CompileForStatement(asCScriptNode *node, asCByteCode *bc);
|
|
|
|
void CompileWhileStatement(asCScriptNode *node, asCByteCode *bc);
|
|
|
|
void CompileDoWhileStatement(asCScriptNode *node, asCByteCode *bc);
|
|
|
|
void CompileBreakStatement(asCScriptNode *node, asCByteCode *bc);
|
|
|
|
void CompileContinueStatement(asCScriptNode *node, asCByteCode *bc);
|
|
|
|
void CompileReturnStatement(asCScriptNode *node, asCByteCode *bc);
|
|
|
|
void CompileExpressionStatement(asCScriptNode *node, asCByteCode *bc);
|
2021-11-04 16:43:10 -04:00
|
|
|
void CompileTryCatch(asCScriptNode *node, bool *hasReturn, asCByteCode *bc);
|
2014-10-27 18:43:09 -04:00
|
|
|
|
|
|
|
// Expressions
|
2017-11-20 08:02:33 -05:00
|
|
|
int CompileAssignment(asCScriptNode *expr, asCExprContext *out);
|
|
|
|
int CompileCondition(asCScriptNode *expr, asCExprContext *out);
|
|
|
|
int CompileExpression(asCScriptNode *expr, asCExprContext *out);
|
|
|
|
int CompilePostFixExpression(asCArray<asCScriptNode *> *postfix, asCExprContext *out);
|
|
|
|
int CompileExpressionTerm(asCScriptNode *node, asCExprContext *out);
|
|
|
|
int CompileExpressionPreOp(asCScriptNode *node, asCExprContext *out);
|
|
|
|
int CompileExpressionPostOp(asCScriptNode *node, asCExprContext *out);
|
|
|
|
int CompileExpressionValue(asCScriptNode *node, asCExprContext *out);
|
|
|
|
int CompileFunctionCall(asCScriptNode *node, asCExprContext *out, asCObjectType *objectType, bool objIsConst, const asCString &scope = "");
|
|
|
|
int CompileConstructCall(asCScriptNode *node, asCExprContext *out);
|
|
|
|
int CompileConversion(asCScriptNode *node, asCExprContext *out);
|
|
|
|
int CompileOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken, bool leftToRight = true);
|
|
|
|
void CompileOperatorOnHandles(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken);
|
|
|
|
void CompileMathOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken);
|
|
|
|
void CompileBitwiseOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken);
|
|
|
|
void CompileComparisonOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken);
|
|
|
|
void CompileBooleanOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken);
|
|
|
|
bool CompileOverloadedDualOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, bool leftToRight, asCExprContext *out, bool isHandle = false, eTokenType opToken = ttUnrecognizedToken);
|
|
|
|
int CompileOverloadedDualOperator2(asCScriptNode *node, const char *methodName, asCExprContext *l, asCExprContext *r, bool leftToRight, asCExprContext *out, bool specificReturn = false, const asCDataType &returnType = asCDataType::CreatePrimitive(ttVoid, false));
|
|
|
|
|
|
|
|
void CompileInitList(asCExprValue *var, asCScriptNode *node, asCByteCode *bc, int isVarGlobOrMem);
|
2015-05-11 19:40:43 -04:00
|
|
|
int CompileInitListElement(asSListPatternNode *&patternNode, asCScriptNode *&valueNode, int bufferTypeId, short bufferVar, asUINT &bufferSize, asCByteCode &byteCode, int &elementsInSubList);
|
2021-11-04 16:43:10 -04:00
|
|
|
int CompileAnonymousInitList(asCScriptNode *listNode, asCExprContext *ctx, const asCDataType &dt);
|
2014-10-27 18:43:09 -04:00
|
|
|
|
2015-05-11 19:40:43 -04:00
|
|
|
int CallDefaultConstructor(const asCDataType &type, int offset, bool isObjectOnHeap, asCByteCode *bc, asCScriptNode *node, int isVarGlobOrMem = 0, bool derefDest = false);
|
2017-11-20 08:02:33 -05:00
|
|
|
int CallCopyConstructor(asCDataType &type, int offset, bool isObjectOnHeap, asCByteCode *bc, asCExprContext *arg, asCScriptNode *node, bool isGlobalVar = false, bool derefDestination = false);
|
2014-10-27 18:43:09 -04:00
|
|
|
void CallDestructor(asCDataType &type, int offset, bool isObjectOnHeap, asCByteCode *bc);
|
2017-11-20 08:02:33 -05:00
|
|
|
int CompileArgumentList(asCScriptNode *node, asCArray<asCExprContext *> &args, asCArray<asSNamedArgument> &namedArgs);
|
|
|
|
int CompileDefaultAndNamedArgs(asCScriptNode *node, asCArray<asCExprContext*> &args, int funcId, asCObjectType *type, asCArray<asSNamedArgument> *namedArgs = 0);
|
|
|
|
asUINT MatchFunctions(asCArray<int> &funcs, asCArray<asCExprContext*> &args, asCScriptNode *node, const char *name, asCArray<asSNamedArgument> *namedArgs = NULL, asCObjectType *objectType = NULL, bool isConstMethod = false, bool silent = false, bool allowObjectConstruct = true, const asCString &scope = "");
|
2021-11-04 16:43:10 -04:00
|
|
|
int CompileVariableAccess(const asCString &name, const asCString &scope, asCExprContext *ctx, asCScriptNode *errNode, bool isOptional = false, asCObjectType *objType = 0);
|
2014-10-27 18:43:09 -04:00
|
|
|
void CompileMemberInitialization(asCByteCode *bc, bool onlyDefaults);
|
2017-11-20 08:02:33 -05:00
|
|
|
bool CompileAutoType(asCDataType &autoType, asCExprContext &compiledCtx, asCScriptNode *exprNode, asCScriptNode *errNode);
|
|
|
|
bool CompileInitialization(asCScriptNode *node, asCByteCode *bc, const asCDataType &type, asCScriptNode *errNode, int offset, asQWORD *constantValue, int isVarGlobOrMem, asCExprContext *preCompiled = 0);
|
|
|
|
void CompileInitAsCopy(asCDataType &type, int offset, asCByteCode *bc, asCExprContext *arg, asCScriptNode *node, bool derefDestination);
|
2014-10-27 18:43:09 -04:00
|
|
|
|
|
|
|
// Helper functions
|
2016-02-17 23:07:55 -05:00
|
|
|
void ConvertToPostFix(asCScriptNode *expr, asCArray<asCScriptNode *> &postfix);
|
2021-11-04 16:43:10 -04:00
|
|
|
int ProcessPropertyGetAccessor(asCExprContext *ctx, asCScriptNode *node);
|
2017-11-20 08:02:33 -05:00
|
|
|
int ProcessPropertySetAccessor(asCExprContext *ctx, asCExprContext *arg, asCScriptNode *node);
|
|
|
|
int ProcessPropertyGetSetAccessor(asCExprContext *ctx, asCExprContext *lctx, asCExprContext *rctx, eTokenType op, asCScriptNode *errNode);
|
|
|
|
int FindPropertyAccessor(const asCString &name, asCExprContext *ctx, asCScriptNode *node, asSNameSpace *ns, bool isThisAccess = false);
|
|
|
|
int FindPropertyAccessor(const asCString &name, asCExprContext *ctx, asCExprContext *arg, asCScriptNode *node, asSNameSpace *ns, bool isThisAccess = false);
|
|
|
|
void PrepareTemporaryVariable(asCScriptNode *node, asCExprContext *ctx, bool forceOnHeap = false);
|
|
|
|
void PrepareOperand(asCExprContext *ctx, asCScriptNode *node);
|
|
|
|
void PrepareForAssignment(asCDataType *lvalue, asCExprContext *rvalue, asCScriptNode *node, bool toTemporary, asCExprContext *lvalueExpr = 0);
|
|
|
|
int PerformAssignment(asCExprValue *lvalue, asCExprValue *rvalue, asCByteCode *bc, asCScriptNode *node);
|
|
|
|
bool IsVariableInitialized(asCExprValue *type, asCScriptNode *node);
|
|
|
|
void Dereference(asCExprContext *ctx, bool generateCode);
|
|
|
|
bool CompileRefCast(asCExprContext *ctx, const asCDataType &to, bool isExplicit, asCScriptNode *node, bool generateCode = true);
|
|
|
|
asUINT MatchArgument(asCArray<int> &funcs, asCArray<asSOverloadCandidate> &matches, const asCExprContext *argExpr, int paramNum, bool allowObjectConstruct = true);
|
|
|
|
int MatchArgument(asCScriptFunction *desc, const asCExprContext *argExpr, int paramNum, bool allowObjectConstruct = true);
|
|
|
|
void PerformFunctionCall(int funcId, asCExprContext *out, bool isConstructor = false, asCArray<asCExprContext*> *args = 0, asCObjectType *objTypeForConstruct = 0, bool useVariable = false, int varOffset = 0, int funcPtrVar = 0);
|
|
|
|
void MoveArgsToStack(int funcId, asCByteCode *bc, asCArray<asCExprContext *> &args, bool addOneToOffset);
|
2021-11-04 16:43:10 -04:00
|
|
|
int MakeFunctionCall(asCExprContext *ctx, int funcId, asCObjectType *objectType, asCArray<asCExprContext*> &args, asCScriptNode *node, bool useVariable = false, int stackOffset = 0, int funcPtrVar = 0);
|
|
|
|
int PrepareFunctionCall(int funcId, asCByteCode *bc, asCArray<asCExprContext *> &args);
|
2017-11-20 08:02:33 -05:00
|
|
|
void AfterFunctionCall(int funcId, asCArray<asCExprContext*> &args, asCExprContext *ctx, bool deferAll);
|
|
|
|
void ProcessDeferredParams(asCExprContext *ctx);
|
|
|
|
int PrepareArgument(asCDataType *paramType, asCExprContext *ctx, asCScriptNode *node, bool isFunction = false, int refType = 0, bool isMakingCopy = false);
|
2021-11-04 16:43:10 -04:00
|
|
|
int PrepareArgument2(asCExprContext *ctx, asCExprContext *arg, asCDataType *paramType, bool isFunction = false, int refType = 0, bool isMakingCopy = false);
|
2017-11-20 08:02:33 -05:00
|
|
|
bool IsLValue(asCExprValue &type);
|
|
|
|
int DoAssignment(asCExprContext *out, asCExprContext *lctx, asCExprContext *rctx, asCScriptNode *lexpr, asCScriptNode *rexpr, eTokenType op, asCScriptNode *opNode);
|
|
|
|
void MergeExprBytecode(asCExprContext *before, asCExprContext *after);
|
|
|
|
void MergeExprBytecodeAndType(asCExprContext *before, asCExprContext *after);
|
2014-10-27 18:43:09 -04:00
|
|
|
void FilterConst(asCArray<int> &funcs, bool removeConst = true);
|
2017-11-20 08:02:33 -05:00
|
|
|
void ConvertToVariable(asCExprContext *ctx);
|
|
|
|
void ConvertToVariableNotIn(asCExprContext *ctx, asCExprContext *exclude);
|
|
|
|
void ConvertToTempVariable(asCExprContext *ctx);
|
|
|
|
void ConvertToTempVariableNotIn(asCExprContext *ctx, asCExprContext *exclude);
|
|
|
|
void ConvertToReference(asCExprContext *ctx);
|
|
|
|
void PushVariableOnStack(asCExprContext *ctx, bool asReference);
|
2014-10-27 18:43:09 -04:00
|
|
|
void DestroyVariables(asCByteCode *bc);
|
|
|
|
asSNameSpace *DetermineNameSpace(const asCString &scope);
|
|
|
|
int SetupParametersAndReturnVariable(asCArray<asCString> ¶meterNames, asCScriptNode *func);
|
|
|
|
|
2021-11-04 16:43:10 -04:00
|
|
|
enum SYMBOLTYPE
|
|
|
|
{
|
|
|
|
SL_NOMATCH,
|
|
|
|
SL_LOCALCONST,
|
|
|
|
SL_LOCALVAR,
|
|
|
|
SL_THISPTR,
|
|
|
|
SL_CLASSPROPACCESS,
|
|
|
|
SL_CLASSPROP,
|
|
|
|
SL_CLASSMETHOD,
|
|
|
|
SL_CLASSTYPE,
|
|
|
|
SL_GLOBALPROPACCESS,
|
|
|
|
SL_GLOBALCONST,
|
|
|
|
SL_GLOBALVAR,
|
|
|
|
SL_GLOBALFUNC,
|
|
|
|
SL_GLOBALTYPE,
|
|
|
|
SL_ENUMVAL,
|
|
|
|
SL_ERROR = -1
|
|
|
|
};
|
|
|
|
|
|
|
|
SYMBOLTYPE SymbolLookup(const asCString &name, const asCString &scope, asCObjectType *objType, asCExprContext *outResult);
|
|
|
|
SYMBOLTYPE SymbolLookupLocalVar(const asCString &name, asCExprContext *outResult);
|
|
|
|
SYMBOLTYPE SymbolLookupMember(const asCString &name, asCObjectType *objType, asCExprContext *outResult);
|
|
|
|
|
2017-11-20 08:02:33 -05:00
|
|
|
void DetermineSingleFunc(asCExprContext *ctx, asCScriptNode *node);
|
2014-10-27 18:43:09 -04:00
|
|
|
|
|
|
|
// Returns the cost of the conversion (the sum of the EConvCost performed)
|
2017-11-20 08:02:33 -05:00
|
|
|
asUINT ImplicitConversion(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode = true, bool allowObjectConstruct = true);
|
|
|
|
asUINT ImplicitConvPrimitiveToPrimitive(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode = true);
|
|
|
|
asUINT ImplicitConvObjectToPrimitive(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode = true);
|
|
|
|
asUINT ImplicitConvPrimitiveToObject(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode = true, bool allowObjectConstruct = true);
|
|
|
|
asUINT ImplicitConvObjectToObject(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode = true, bool allowObjectConstruct = true);
|
|
|
|
asUINT ImplicitConvObjectRef(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode);
|
|
|
|
asUINT ImplicitConvObjectValue(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode);
|
|
|
|
void ImplicitConversionConstant(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType);
|
|
|
|
void ImplicitConvObjectToBestMathType(asCExprContext *ctx, asCScriptNode *node);
|
|
|
|
asUINT ImplicitConvLambdaToFunc(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode = true);
|
2014-10-27 18:43:09 -04:00
|
|
|
|
|
|
|
void LineInstr(asCByteCode *bc, size_t pos);
|
|
|
|
|
|
|
|
asUINT ProcessStringConstant(asCString &str, asCScriptNode *node, bool processEscapeSequences = true);
|
|
|
|
void ProcessHeredocStringConstant(asCString &str, asCScriptNode *node);
|
|
|
|
int GetPrecedence(asCScriptNode *op);
|
|
|
|
void Error(const asCString &msg, asCScriptNode *node);
|
|
|
|
void Warning(const asCString &msg, asCScriptNode *node);
|
|
|
|
void Information(const asCString &msg, asCScriptNode *node);
|
2015-05-11 19:40:43 -04:00
|
|
|
void PrintMatchingFuncs(asCArray<int> &funcs, asCScriptNode *node, asCObjectType *inType = 0);
|
2014-10-27 18:43:09 -04:00
|
|
|
void AddVariableScope(bool isBreakScope = false, bool isContinueScope = false);
|
|
|
|
void RemoveVariableScope();
|
|
|
|
void FinalizeFunction();
|
|
|
|
|
|
|
|
asCByteCode byteCode;
|
|
|
|
|
|
|
|
bool hasCompileErrors;
|
|
|
|
|
|
|
|
int nextLabel;
|
2016-02-17 23:07:55 -05:00
|
|
|
int numLambdas;
|
2014-10-27 18:43:09 -04:00
|
|
|
|
2016-02-17 23:07:55 -05:00
|
|
|
asCVariableScope *variables;
|
|
|
|
asCBuilder *builder;
|
|
|
|
asCScriptEngine *engine;
|
|
|
|
asCScriptCode *script;
|
2014-10-27 18:43:09 -04:00
|
|
|
asCScriptFunction *outFunc;
|
|
|
|
|
2016-02-17 23:07:55 -05:00
|
|
|
bool m_isConstructor;
|
|
|
|
bool m_isConstructorCalled;
|
|
|
|
sClassDeclaration *m_classDecl;
|
|
|
|
sGlobalVariableDescription *m_globalVar;
|
2014-10-27 18:43:09 -04:00
|
|
|
|
|
|
|
asCArray<int> breakLabels;
|
|
|
|
asCArray<int> continueLabels;
|
|
|
|
|
2021-11-04 16:43:10 -04:00
|
|
|
int AllocateVariable(const asCDataType &type, bool isTemporary, bool forceOnHeap = false, bool asReference = false);
|
2017-11-20 08:02:33 -05:00
|
|
|
int AllocateVariableNotIn(const asCDataType &type, bool isTemporary, bool forceOnHeap, asCExprContext *ctx);
|
2014-10-27 18:43:09 -04:00
|
|
|
int GetVariableOffset(int varIndex);
|
|
|
|
int GetVariableSlot(int varOffset);
|
|
|
|
void DeallocateVariable(int pos);
|
2017-11-20 08:02:33 -05:00
|
|
|
void ReleaseTemporaryVariable(asCExprValue &t, asCByteCode *bc);
|
2014-10-27 18:43:09 -04:00
|
|
|
void ReleaseTemporaryVariable(int offset, asCByteCode *bc);
|
|
|
|
bool IsVariableOnHeap(int offset);
|
|
|
|
|
|
|
|
// This ordered array indicates the type of each variable
|
|
|
|
asCArray<asCDataType> variableAllocations;
|
|
|
|
|
|
|
|
// This ordered array indicates which variables are temporaries or not
|
|
|
|
asCArray<bool> variableIsTemporary;
|
|
|
|
|
|
|
|
// This unordered array gives the offsets of all temporary variables, whether currently allocated or not
|
|
|
|
asCArray<int> tempVariableOffsets;
|
|
|
|
|
|
|
|
// This ordered array indicated if the variable is on the heap or not
|
|
|
|
asCArray<bool> variableIsOnHeap;
|
|
|
|
|
|
|
|
// This unordered array gives the indexes of the currently unused variables
|
|
|
|
asCArray<int> freeVariables;
|
|
|
|
|
|
|
|
// This array holds the offsets of the currently allocated temporary variables
|
|
|
|
asCArray<int> tempVariables;
|
|
|
|
|
|
|
|
// This array holds the indices of variables that must not be used in an allocation
|
|
|
|
asCArray<int> reservedVariables;
|
|
|
|
|
2017-11-20 08:02:33 -05:00
|
|
|
// This array holds the string constants that were allocated during the compilation,
|
|
|
|
// so they can be released upon completion, whether the compilation was successful or not.
|
|
|
|
asCArray<void*> usedStringConstants;
|
|
|
|
|
2021-11-04 16:43:10 -04:00
|
|
|
// This array holds the nodes that have been allocated temporarily
|
|
|
|
asCArray<asCScriptNode*> nodesToFreeUponComplete;
|
|
|
|
|
2014-10-27 18:43:09 -04:00
|
|
|
bool isCompilingDefaultArg;
|
|
|
|
bool isProcessingDeferredParams;
|
2016-02-17 23:07:55 -05:00
|
|
|
int noCodeOutput;
|
2014-10-27 18:43:09 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
END_AS_NAMESPACE
|
|
|
|
|
|
|
|
#endif // AS_NO_COMPILER
|
|
|
|
|
|
|
|
#endif
|