/xbmc/visualizations/Vortex/angelscript/angelscript/source/as_scriptfunction.h

http://github.com/xbmc/xbmc · C++ Header · 193 lines · 96 code · 41 blank · 56 comment · 0 complexity · cb161ac10c8b26121db86a23c814f8ef MD5 · raw file

  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2009 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_scriptfunction.h
  25. //
  26. // A container for a compiled script function
  27. //
  28. #ifndef AS_SCRIPTFUNCTION_H
  29. #define AS_SCRIPTFUNCTION_H
  30. #include "as_config.h"
  31. #include "as_string.h"
  32. #include "as_array.h"
  33. #include "as_datatype.h"
  34. #include "as_atomic.h"
  35. BEGIN_AS_NAMESPACE
  36. class asCScriptEngine;
  37. class asCModule;
  38. class asCConfigGroup;
  39. class asCGlobalProperty;
  40. struct asSScriptVariable
  41. {
  42. asCString name;
  43. asCDataType type;
  44. int stackOffset;
  45. };
  46. const int asFUNC_SYSTEM = 0;
  47. const int asFUNC_SCRIPT = 1;
  48. const int asFUNC_INTERFACE = 2;
  49. const int asFUNC_IMPORTED = 3;
  50. const int asFUNC_VIRTUAL = 4;
  51. struct asSSystemFunctionInterface;
  52. // TODO: Need a method for obtaining the function type, so that the application can differenciate between the types
  53. // This should replace the IsClassMethod and IsInterfaceMethod
  54. // TODO: GetModuleName should be removed. A function won't belong to a specific module anymore
  55. // as the function can be removed from the module, but still remain alive. For example
  56. // for dynamically generated functions held by a function pointer.
  57. // TODO: Might be interesting to allow enumeration of accessed global variables, and
  58. // also functions/methods that are being called.
  59. void RegisterScriptFunction(asCScriptEngine *engine);
  60. class asCScriptFunction : public asIScriptFunction
  61. {
  62. public:
  63. // From asIScriptFunction
  64. asIScriptEngine *GetEngine() const;
  65. // Memory management
  66. int AddRef();
  67. int Release();
  68. int GetId() const;
  69. const char *GetModuleName() const;
  70. asIObjectType *GetObjectType() const;
  71. const char *GetObjectName() const;
  72. const char *GetName() const;
  73. const char *GetDeclaration(bool includeObjectName = true) const;
  74. const char *GetScriptSectionName() const;
  75. const char *GetConfigGroup() const;
  76. bool IsClassMethod() const;
  77. bool IsInterfaceMethod() const;
  78. bool IsReadOnly() const;
  79. int GetParamCount() const;
  80. int GetParamTypeId(int index, asDWORD *flags = 0) const;
  81. int GetReturnTypeId() const;
  82. // For JIT compilation
  83. asDWORD *GetByteCode(asUINT *length = 0);
  84. public:
  85. //-----------------------------------
  86. // Internal methods
  87. asCScriptFunction(asCScriptEngine *engine, asCModule *mod, int funcType);
  88. ~asCScriptFunction();
  89. void AddVariable(asCString &name, asCDataType &type, int stackOffset);
  90. int GetSpaceNeededForArguments();
  91. int GetSpaceNeededForReturnValue();
  92. asCString GetDeclarationStr(bool includeObjectName = true) const;
  93. int GetLineNumber(int programPosition);
  94. void ComputeSignatureId();
  95. bool IsSignatureEqual(const asCScriptFunction *func) const;
  96. void JITCompile();
  97. void AddReferences();
  98. void ReleaseReferences();
  99. int GetGlobalVarPtrIndex(int gvarId);
  100. asCConfigGroup *GetConfigGroupByGlobalVarPtrIndex(int index);
  101. asCGlobalProperty *GetPropertyByGlobalVarPtrIndex(int index);
  102. // GC methods
  103. int GetRefCount();
  104. void SetFlag();
  105. bool GetFlag();
  106. void EnumReferences(asIScriptEngine *engine);
  107. void ReleaseAllHandles(asIScriptEngine *engine);
  108. public:
  109. //-----------------------------------
  110. // Properties
  111. asCAtomic refCount;
  112. bool gcFlag;
  113. asCScriptEngine *engine;
  114. asCModule *module;
  115. // Function signature
  116. asCString name;
  117. asCDataType returnType;
  118. asCArray<asCDataType> parameterTypes;
  119. asCArray<asETypeModifiers> inOutFlags;
  120. bool isReadOnly;
  121. asCObjectType *objectType;
  122. int signatureId;
  123. int id;
  124. int funcType;
  125. // Used by asFUNC_SCRIPT
  126. asCArray<asDWORD> byteCode;
  127. asCArray<asCObjectType*> objVariableTypes;
  128. asCArray<int> objVariablePos;
  129. int stackNeeded;
  130. asCArray<int> lineNumbers; // debug info
  131. asCArray<asSScriptVariable*> variables; // debug info
  132. int scriptSectionIdx; // debug info
  133. bool dontCleanUpOnException; // Stub functions don't own the object and parameters
  134. // This array holds pointers to all global variables that the function access.
  135. // The byte code holds an index into this table to refer to a global variable.
  136. asCArray<void*> globalVarPointers;
  137. // Used by asFUNC_VIRTUAL
  138. int vfTableIdx;
  139. // Used by asFUNC_SYSTEM
  140. asSSystemFunctionInterface *sysFuncIntf;
  141. // JIT compiled code of this function
  142. asJITFunction jitFunction;
  143. };
  144. END_AS_NAMESPACE
  145. #endif