as_compiler.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2020 Andreas Jonsson
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any
  6. damages arising from the use of this software.
  7. Permission is granted to anyone to use this software for any
  8. purpose, including commercial applications, and to alter it and
  9. redistribute it freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you
  11. must not claim that you wrote the original software. If you use
  12. this software in a product, an acknowledgment in the product
  13. documentation would be appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and
  15. must not be misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source
  17. distribution.
  18. The original version of this library can be located at:
  19. http://www.angelcode.com/angelscript/
  20. Andreas Jonsson
  21. andreas@angelcode.com
  22. */
  23. //
  24. // as_compiler.h
  25. //
  26. // The class that does the actual compilation of the functions
  27. //
  28. #ifndef AS_COMPILER_H
  29. #define AS_COMPILER_H
  30. #include "as_config.h"
  31. #ifndef AS_NO_COMPILER
  32. #include "as_builder.h"
  33. #include "as_scriptfunction.h"
  34. #include "as_variablescope.h"
  35. #include "as_bytecode.h"
  36. #include "as_array.h"
  37. #include "as_datatype.h"
  38. BEGIN_AS_NAMESPACE
  39. // This class represents the value of an expression as evaluated by the compiler.
  40. // It holds information such as the type of the value, stack offset for a local
  41. // variable, value of constants, whether the value can be modified (i.e. lvalue), etc.
  42. struct asCExprValue
  43. {
  44. asCExprValue();
  45. void Set(const asCDataType &dataType);
  46. void SetVariable(const asCDataType &dataType, int stackOffset, bool isTemporary);
  47. void SetConstantB(const asCDataType &dataType, asBYTE value);
  48. void SetConstantQW(const asCDataType &dataType, asQWORD value);
  49. void SetConstantDW(const asCDataType &dataType, asDWORD value);
  50. void SetConstantW(const asCDataType &dataType, asWORD value);
  51. void SetConstantF(const asCDataType &dataType, float value);
  52. void SetConstantD(const asCDataType &dataType, double value);
  53. void SetConstantB(asBYTE value);
  54. void SetConstantW(asWORD value);
  55. void SetConstantQW(asQWORD value);
  56. void SetConstantDW(asDWORD value);
  57. void SetConstantF(float value);
  58. void SetConstantD(double value);
  59. asBYTE GetConstantB();
  60. asWORD GetConstantW();
  61. asQWORD GetConstantQW();
  62. asDWORD GetConstantDW();
  63. float GetConstantF();
  64. double GetConstantD();
  65. void SetConstantData(const asCDataType &dataType, asQWORD value);
  66. asQWORD GetConstantData();
  67. void SetNullConstant();
  68. void SetUndefinedFuncHandle(asCScriptEngine *engine);
  69. void SetVoid();
  70. void SetDummy();
  71. bool IsUndefinedFuncHandle() const;
  72. bool IsNullConstant() const;
  73. bool IsVoid() const;
  74. asCDataType dataType;
  75. bool isLValue : 1; // Can this value be updated in assignment, or increment operators, etc
  76. bool isTemporary : 1;
  77. bool isConstant : 1;
  78. bool isVariable : 1;
  79. bool isExplicitHandle : 1;
  80. bool isRefToLocal : 1; // The reference may be to a local variable
  81. bool isRefSafe : 1; // the life-time of the ref is guaranteed for the duration of the access
  82. short dummy : 9;
  83. short stackOffset;
  84. private:
  85. // These values must not be accessed directly in order to avoid problems with endianess.
  86. // Use the appropriate accessor methods instead
  87. union
  88. {
  89. asQWORD qwordValue;
  90. double doubleValue;
  91. asDWORD dwordValue;
  92. float floatValue;
  93. asWORD wordValue;
  94. asBYTE byteValue;
  95. };
  96. };
  97. struct asCExprContext;
  98. // This class holds information for arguments that needs to be
  99. // cleaned up after the result of a function has been evaluated.
  100. struct asSDeferredParam
  101. {
  102. asSDeferredParam() {argNode = 0; origExpr = 0;}
  103. asCScriptNode *argNode;
  104. asCExprValue argType;
  105. int argInOutFlags;
  106. asCExprContext *origExpr;
  107. };
  108. // TODO: refactor: asCExprContext should have indicators to inform where the value is,
  109. // i.e. if the reference to an object is pushed on the stack or not, etc
  110. // This class holds information about an expression that is being evaluated, e.g.
  111. // the current bytecode, ambiguous symbol names, property accessors, etc.
  112. struct asCExprContext
  113. {
  114. asCExprContext(asCScriptEngine *engine);
  115. ~asCExprContext();
  116. void Clear();
  117. bool IsClassMethod() const;
  118. bool IsGlobalFunc() const;
  119. void SetLambda(asCScriptNode *funcDecl);
  120. bool IsLambda() const;
  121. void SetVoidExpression();
  122. bool IsVoidExpression() const;
  123. void Merge(asCExprContext *after);
  124. void Copy(asCExprContext *other);
  125. void SetAnonymousInitList(asCScriptNode *initList, asCScriptCode *script);
  126. bool IsAnonymousInitList() const;
  127. asCByteCode bc;
  128. asCExprValue type;
  129. int property_get;
  130. int property_set;
  131. bool property_const; // If the object that is being accessed through property accessor is read-only
  132. bool property_handle; // If the property accessor is called on an object stored in a handle
  133. bool property_ref; // If the property accessor is called on a reference
  134. bool isVoidExpression; // Set to true if the expression is an explicit 'void', e.g. used to ignore out parameters in func calls
  135. bool isCleanArg; // Set to true if the expression has only been initialized with default constructor
  136. asCExprContext *property_arg;
  137. asCArray<asSDeferredParam> deferredParams;
  138. asCScriptNode *exprNode;
  139. asCExprContext *origExpr;
  140. asCScriptCode *origCode;
  141. // TODO: cleanup: use ambiguousName and an enum to say if it is a method, global func, or enum value
  142. asCString methodName;
  143. asCString enumValue;
  144. asSNameSpace *symbolNamespace; // The namespace in which the ambiguous symbol was found
  145. bool isAnonymousInitList; // Set to true if the expression is an init list for which the type has not yet been determined
  146. };
  147. struct asSOverloadCandidate
  148. {
  149. asSOverloadCandidate() : funcId(0), cost(0) {}
  150. asSOverloadCandidate(int _id, asUINT _cost) : funcId(_id), cost(_cost) {}
  151. int funcId;
  152. asUINT cost;
  153. };
  154. struct asSNamedArgument
  155. {
  156. asCString name;
  157. asCExprContext *ctx;
  158. asUINT match;
  159. };
  160. enum EImplicitConv
  161. {
  162. asIC_IMPLICIT_CONV,
  163. asIC_EXPLICIT_REF_CAST,
  164. asIC_EXPLICIT_VAL_CAST
  165. };
  166. enum EConvCost
  167. {
  168. asCC_NO_CONV = 0,
  169. asCC_CONST_CONV = 1,
  170. asCC_ENUM_SAME_SIZE_CONV = 2,
  171. asCC_ENUM_DIFF_SIZE_CONV = 3,
  172. asCC_PRIMITIVE_SIZE_CONV = 4,
  173. asCC_SIGNED_CONV = 5,
  174. asCC_INT_FLOAT_CONV = 6,
  175. asCC_REF_CONV = 7,
  176. asCC_OBJ_TO_PRIMITIVE_CONV = 8,
  177. asCC_TO_OBJECT_CONV = 9,
  178. asCC_VARIABLE_CONV = 10
  179. };
  180. class asCCompiler
  181. {
  182. public:
  183. asCCompiler(asCScriptEngine *engine);
  184. ~asCCompiler();
  185. int CompileFunction(asCBuilder *builder, asCScriptCode *script, asCArray<asCString> &parameterNames, asCScriptNode *func, asCScriptFunction *outFunc, sClassDeclaration *classDecl);
  186. int CompileDefaultConstructor(asCBuilder *builder, asCScriptCode *script, asCScriptNode *node, asCScriptFunction *outFunc, sClassDeclaration *classDecl);
  187. int CompileFactory(asCBuilder *builder, asCScriptCode *script, asCScriptFunction *outFunc);
  188. int CompileGlobalVariable(asCBuilder *builder, asCScriptCode *script, asCScriptNode *expr, sGlobalVariableDescription *gvar, asCScriptFunction *outFunc);
  189. protected:
  190. friend class asCBuilder;
  191. void Reset(asCBuilder *builder, asCScriptCode *script, asCScriptFunction *outFunc);
  192. // Statements
  193. void CompileStatementBlock(asCScriptNode *block, bool ownVariableScope, bool *hasReturn, asCByteCode *bc);
  194. void CompileDeclaration(asCScriptNode *decl, asCByteCode *bc);
  195. void CompileStatement(asCScriptNode *statement, bool *hasReturn, asCByteCode *bc);
  196. void CompileIfStatement(asCScriptNode *node, bool *hasReturn, asCByteCode *bc);
  197. void CompileSwitchStatement(asCScriptNode *node, bool *hasReturn, asCByteCode *bc);
  198. void CompileCase(asCScriptNode *node, asCByteCode *bc);
  199. void CompileForStatement(asCScriptNode *node, asCByteCode *bc);
  200. void CompileWhileStatement(asCScriptNode *node, asCByteCode *bc);
  201. void CompileDoWhileStatement(asCScriptNode *node, asCByteCode *bc);
  202. void CompileBreakStatement(asCScriptNode *node, asCByteCode *bc);
  203. void CompileContinueStatement(asCScriptNode *node, asCByteCode *bc);
  204. void CompileReturnStatement(asCScriptNode *node, asCByteCode *bc);
  205. void CompileExpressionStatement(asCScriptNode *node, asCByteCode *bc);
  206. void CompileTryCatch(asCScriptNode *node, bool *hasReturn, asCByteCode *bc);
  207. // Expressions
  208. int CompileAssignment(asCScriptNode *expr, asCExprContext *out);
  209. int CompileCondition(asCScriptNode *expr, asCExprContext *out);
  210. int CompileExpression(asCScriptNode *expr, asCExprContext *out);
  211. int CompilePostFixExpression(asCArray<asCScriptNode *> *postfix, asCExprContext *out);
  212. int CompileExpressionTerm(asCScriptNode *node, asCExprContext *out);
  213. int CompileExpressionPreOp(asCScriptNode *node, asCExprContext *out);
  214. int CompileExpressionPostOp(asCScriptNode *node, asCExprContext *out);
  215. int CompileExpressionValue(asCScriptNode *node, asCExprContext *out);
  216. int CompileFunctionCall(asCScriptNode *node, asCExprContext *out, asCObjectType *objectType, bool objIsConst, const asCString &scope = "");
  217. int CompileConstructCall(asCScriptNode *node, asCExprContext *out);
  218. int CompileConversion(asCScriptNode *node, asCExprContext *out);
  219. int CompileOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken, bool leftToRight = true);
  220. void CompileOperatorOnHandles(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken);
  221. void CompileMathOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken);
  222. void CompileBitwiseOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken);
  223. void CompileComparisonOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken);
  224. void CompileBooleanOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken);
  225. bool CompileOverloadedDualOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, bool leftToRight, asCExprContext *out, bool isHandle = false, eTokenType opToken = ttUnrecognizedToken);
  226. 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));
  227. void CompileInitList(asCExprValue *var, asCScriptNode *node, asCByteCode *bc, int isVarGlobOrMem);
  228. int CompileInitListElement(asSListPatternNode *&patternNode, asCScriptNode *&valueNode, int bufferTypeId, short bufferVar, asUINT &bufferSize, asCByteCode &byteCode, int &elementsInSubList);
  229. int CompileAnonymousInitList(asCScriptNode *listNode, asCExprContext *ctx, const asCDataType &dt);
  230. int CallDefaultConstructor(const asCDataType &type, int offset, bool isObjectOnHeap, asCByteCode *bc, asCScriptNode *node, int isVarGlobOrMem = 0, bool derefDest = false);
  231. int CallCopyConstructor(asCDataType &type, int offset, bool isObjectOnHeap, asCByteCode *bc, asCExprContext *arg, asCScriptNode *node, bool isGlobalVar = false, bool derefDestination = false);
  232. void CallDestructor(asCDataType &type, int offset, bool isObjectOnHeap, asCByteCode *bc);
  233. int CompileArgumentList(asCScriptNode *node, asCArray<asCExprContext *> &args, asCArray<asSNamedArgument> &namedArgs);
  234. int CompileDefaultAndNamedArgs(asCScriptNode *node, asCArray<asCExprContext*> &args, int funcId, asCObjectType *type, asCArray<asSNamedArgument> *namedArgs = 0);
  235. 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 = "");
  236. int CompileVariableAccess(const asCString &name, const asCString &scope, asCExprContext *ctx, asCScriptNode *errNode, bool isOptional = false, asCObjectType *objType = 0);
  237. void CompileMemberInitialization(asCByteCode *bc, bool onlyDefaults);
  238. bool CompileAutoType(asCDataType &autoType, asCExprContext &compiledCtx, asCScriptNode *exprNode, asCScriptNode *errNode);
  239. bool CompileInitialization(asCScriptNode *node, asCByteCode *bc, const asCDataType &type, asCScriptNode *errNode, int offset, asQWORD *constantValue, int isVarGlobOrMem, asCExprContext *preCompiled = 0);
  240. void CompileInitAsCopy(asCDataType &type, int offset, asCByteCode *bc, asCExprContext *arg, asCScriptNode *node, bool derefDestination);
  241. // Helper functions
  242. void ConvertToPostFix(asCScriptNode *expr, asCArray<asCScriptNode *> &postfix);
  243. int ProcessPropertyGetAccessor(asCExprContext *ctx, asCScriptNode *node);
  244. int ProcessPropertySetAccessor(asCExprContext *ctx, asCExprContext *arg, asCScriptNode *node);
  245. int ProcessPropertyGetSetAccessor(asCExprContext *ctx, asCExprContext *lctx, asCExprContext *rctx, eTokenType op, asCScriptNode *errNode);
  246. int FindPropertyAccessor(const asCString &name, asCExprContext *ctx, asCScriptNode *node, asSNameSpace *ns, bool isThisAccess = false);
  247. int FindPropertyAccessor(const asCString &name, asCExprContext *ctx, asCExprContext *arg, asCScriptNode *node, asSNameSpace *ns, bool isThisAccess = false);
  248. void PrepareTemporaryVariable(asCScriptNode *node, asCExprContext *ctx, bool forceOnHeap = false);
  249. void PrepareOperand(asCExprContext *ctx, asCScriptNode *node);
  250. void PrepareForAssignment(asCDataType *lvalue, asCExprContext *rvalue, asCScriptNode *node, bool toTemporary, asCExprContext *lvalueExpr = 0);
  251. int PerformAssignment(asCExprValue *lvalue, asCExprValue *rvalue, asCByteCode *bc, asCScriptNode *node);
  252. bool IsVariableInitialized(asCExprValue *type, asCScriptNode *node);
  253. void Dereference(asCExprContext *ctx, bool generateCode);
  254. bool CompileRefCast(asCExprContext *ctx, const asCDataType &to, bool isExplicit, asCScriptNode *node, bool generateCode = true);
  255. asUINT MatchArgument(asCArray<int> &funcs, asCArray<asSOverloadCandidate> &matches, const asCExprContext *argExpr, int paramNum, bool allowObjectConstruct = true);
  256. int MatchArgument(asCScriptFunction *desc, const asCExprContext *argExpr, int paramNum, bool allowObjectConstruct = true);
  257. 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);
  258. void MoveArgsToStack(int funcId, asCByteCode *bc, asCArray<asCExprContext *> &args, bool addOneToOffset);
  259. int MakeFunctionCall(asCExprContext *ctx, int funcId, asCObjectType *objectType, asCArray<asCExprContext*> &args, asCScriptNode *node, bool useVariable = false, int stackOffset = 0, int funcPtrVar = 0);
  260. int PrepareFunctionCall(int funcId, asCByteCode *bc, asCArray<asCExprContext *> &args);
  261. void AfterFunctionCall(int funcId, asCArray<asCExprContext*> &args, asCExprContext *ctx, bool deferAll);
  262. void ProcessDeferredParams(asCExprContext *ctx);
  263. int PrepareArgument(asCDataType *paramType, asCExprContext *ctx, asCScriptNode *node, bool isFunction = false, int refType = 0, bool isMakingCopy = false);
  264. int PrepareArgument2(asCExprContext *ctx, asCExprContext *arg, asCDataType *paramType, bool isFunction = false, int refType = 0, bool isMakingCopy = false);
  265. bool IsLValue(asCExprValue &type);
  266. int DoAssignment(asCExprContext *out, asCExprContext *lctx, asCExprContext *rctx, asCScriptNode *lexpr, asCScriptNode *rexpr, eTokenType op, asCScriptNode *opNode);
  267. void MergeExprBytecode(asCExprContext *before, asCExprContext *after);
  268. void MergeExprBytecodeAndType(asCExprContext *before, asCExprContext *after);
  269. void FilterConst(asCArray<int> &funcs, bool removeConst = true);
  270. void ConvertToVariable(asCExprContext *ctx);
  271. void ConvertToVariableNotIn(asCExprContext *ctx, asCExprContext *exclude);
  272. void ConvertToTempVariable(asCExprContext *ctx);
  273. void ConvertToTempVariableNotIn(asCExprContext *ctx, asCExprContext *exclude);
  274. void ConvertToReference(asCExprContext *ctx);
  275. void PushVariableOnStack(asCExprContext *ctx, bool asReference);
  276. void DestroyVariables(asCByteCode *bc);
  277. asSNameSpace *DetermineNameSpace(const asCString &scope);
  278. int SetupParametersAndReturnVariable(asCArray<asCString> &parameterNames, asCScriptNode *func);
  279. enum SYMBOLTYPE
  280. {
  281. SL_NOMATCH,
  282. SL_LOCALCONST,
  283. SL_LOCALVAR,
  284. SL_THISPTR,
  285. SL_CLASSPROPACCESS,
  286. SL_CLASSPROP,
  287. SL_CLASSMETHOD,
  288. SL_CLASSTYPE,
  289. SL_GLOBALPROPACCESS,
  290. SL_GLOBALCONST,
  291. SL_GLOBALVAR,
  292. SL_GLOBALFUNC,
  293. SL_GLOBALTYPE,
  294. SL_ENUMVAL,
  295. SL_ERROR = -1
  296. };
  297. SYMBOLTYPE SymbolLookup(const asCString &name, const asCString &scope, asCObjectType *objType, asCExprContext *outResult);
  298. SYMBOLTYPE SymbolLookupLocalVar(const asCString &name, asCExprContext *outResult);
  299. SYMBOLTYPE SymbolLookupMember(const asCString &name, asCObjectType *objType, asCExprContext *outResult);
  300. void DetermineSingleFunc(asCExprContext *ctx, asCScriptNode *node);
  301. // Returns the cost of the conversion (the sum of the EConvCost performed)
  302. asUINT ImplicitConversion(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode = true, bool allowObjectConstruct = true);
  303. asUINT ImplicitConvPrimitiveToPrimitive(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode = true);
  304. asUINT ImplicitConvObjectToPrimitive(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode = true);
  305. asUINT ImplicitConvPrimitiveToObject(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode = true, bool allowObjectConstruct = true);
  306. asUINT ImplicitConvObjectToObject(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode = true, bool allowObjectConstruct = true);
  307. asUINT ImplicitConvObjectRef(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode);
  308. asUINT ImplicitConvObjectValue(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode);
  309. void ImplicitConversionConstant(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType);
  310. void ImplicitConvObjectToBestMathType(asCExprContext *ctx, asCScriptNode *node);
  311. asUINT ImplicitConvLambdaToFunc(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode = true);
  312. void LineInstr(asCByteCode *bc, size_t pos);
  313. asUINT ProcessStringConstant(asCString &str, asCScriptNode *node, bool processEscapeSequences = true);
  314. void ProcessHeredocStringConstant(asCString &str, asCScriptNode *node);
  315. int GetPrecedence(asCScriptNode *op);
  316. void Error(const asCString &msg, asCScriptNode *node);
  317. void Warning(const asCString &msg, asCScriptNode *node);
  318. void Information(const asCString &msg, asCScriptNode *node);
  319. void PrintMatchingFuncs(asCArray<int> &funcs, asCScriptNode *node, asCObjectType *inType = 0);
  320. void AddVariableScope(bool isBreakScope = false, bool isContinueScope = false);
  321. void RemoveVariableScope();
  322. void FinalizeFunction();
  323. asCByteCode byteCode;
  324. bool hasCompileErrors;
  325. int nextLabel;
  326. int numLambdas;
  327. asCVariableScope *variables;
  328. asCBuilder *builder;
  329. asCScriptEngine *engine;
  330. asCScriptCode *script;
  331. asCScriptFunction *outFunc;
  332. bool m_isConstructor;
  333. bool m_isConstructorCalled;
  334. sClassDeclaration *m_classDecl;
  335. sGlobalVariableDescription *m_globalVar;
  336. asCArray<int> breakLabels;
  337. asCArray<int> continueLabels;
  338. int AllocateVariable(const asCDataType &type, bool isTemporary, bool forceOnHeap = false, bool asReference = false);
  339. int AllocateVariableNotIn(const asCDataType &type, bool isTemporary, bool forceOnHeap, asCExprContext *ctx);
  340. int GetVariableOffset(int varIndex);
  341. int GetVariableSlot(int varOffset);
  342. void DeallocateVariable(int pos);
  343. void ReleaseTemporaryVariable(asCExprValue &t, asCByteCode *bc);
  344. void ReleaseTemporaryVariable(int offset, asCByteCode *bc);
  345. bool IsVariableOnHeap(int offset);
  346. // This ordered array indicates the type of each variable
  347. asCArray<asCDataType> variableAllocations;
  348. // This ordered array indicates which variables are temporaries or not
  349. asCArray<bool> variableIsTemporary;
  350. // This unordered array gives the offsets of all temporary variables, whether currently allocated or not
  351. asCArray<int> tempVariableOffsets;
  352. // This ordered array indicated if the variable is on the heap or not
  353. asCArray<bool> variableIsOnHeap;
  354. // This unordered array gives the indexes of the currently unused variables
  355. asCArray<int> freeVariables;
  356. // This array holds the offsets of the currently allocated temporary variables
  357. asCArray<int> tempVariables;
  358. // This array holds the indices of variables that must not be used in an allocation
  359. asCArray<int> reservedVariables;
  360. // This array holds the string constants that were allocated during the compilation,
  361. // so they can be released upon completion, whether the compilation was successful or not.
  362. asCArray<void*> usedStringConstants;
  363. // This array holds the nodes that have been allocated temporarily
  364. asCArray<asCScriptNode*> nodesToFreeUponComplete;
  365. bool isCompilingDefaultArg;
  366. bool isProcessingDeferredParams;
  367. int noCodeOutput;
  368. };
  369. END_AS_NAMESPACE
  370. #endif // AS_NO_COMPILER
  371. #endif