PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  5   This software is provided 'as-is', without any express or implied 
  6   warranty. In no event will the authors be held liable for any 
  7   damages arising from the use of this software.
  8
  9   Permission is granted to anyone to use this software for any 
 10   purpose, including commercial applications, and to alter it and 
 11   redistribute it freely, subject to the following restrictions:
 12
 13   1. The origin of this software must not be misrepresented; you 
 14      must not claim that you wrote the original software. If you use
 15      this software in a product, an acknowledgment in the product 
 16      documentation would be appreciated but is not required.
 17
 18   2. Altered source versions must be plainly marked as such, and 
 19      must not be misrepresented as being the original software.
 20
 21   3. This notice may not be removed or altered from any source 
 22      distribution.
 23
 24   The original version of this library can be located at:
 25   http://www.angelcode.com/angelscript/
 26
 27   Andreas Jonsson
 28   andreas@angelcode.com
 29*/
 30
 31
 32//
 33// as_scriptfunction.h
 34//
 35// A container for a compiled script function
 36//
 37
 38
 39
 40#ifndef AS_SCRIPTFUNCTION_H
 41#define AS_SCRIPTFUNCTION_H
 42
 43#include "as_config.h"
 44#include "as_string.h"
 45#include "as_array.h"
 46#include "as_datatype.h"
 47#include "as_atomic.h"
 48
 49BEGIN_AS_NAMESPACE
 50
 51class asCScriptEngine;
 52class asCModule;
 53class asCConfigGroup;
 54class asCGlobalProperty;
 55
 56struct asSScriptVariable
 57{
 58	asCString name;
 59	asCDataType type;
 60	int stackOffset;
 61};
 62
 63const int asFUNC_SYSTEM    = 0;
 64const int asFUNC_SCRIPT    = 1;
 65const int asFUNC_INTERFACE = 2;
 66const int asFUNC_IMPORTED  = 3;
 67const int asFUNC_VIRTUAL   = 4;
 68
 69struct asSSystemFunctionInterface;
 70
 71// TODO: Need a method for obtaining the function type, so that the application can differenciate between the types
 72//       This should replace the IsClassMethod and IsInterfaceMethod
 73
 74// TODO: GetModuleName should be removed. A function won't belong to a specific module anymore
 75//       as the function can be removed from the module, but still remain alive. For example
 76//       for dynamically generated functions held by a function pointer.
 77
 78// TODO: Might be interesting to allow enumeration of accessed global variables, and 
 79//       also functions/methods that are being called.
 80
 81void RegisterScriptFunction(asCScriptEngine *engine);
 82
 83class asCScriptFunction : public asIScriptFunction
 84{
 85public:
 86	// From asIScriptFunction
 87	asIScriptEngine     *GetEngine() const;
 88
 89	// Memory management
 90	int AddRef();
 91	int Release();
 92
 93	int                  GetId() const;
 94	const char          *GetModuleName() const;
 95	asIObjectType       *GetObjectType() const;
 96	const char          *GetObjectName() const;
 97	const char          *GetName() const;
 98	const char          *GetDeclaration(bool includeObjectName = true) const;
 99	const char          *GetScriptSectionName() const;
100	const char          *GetConfigGroup() const;
101
102	bool                 IsClassMethod() const;
103	bool                 IsInterfaceMethod() const;
104	bool                 IsReadOnly() const;
105
106	int                  GetParamCount() const;
107	int                  GetParamTypeId(int index, asDWORD *flags = 0) const;
108	int                  GetReturnTypeId() const;
109
110	// For JIT compilation
111	asDWORD             *GetByteCode(asUINT *length = 0);
112
113public:
114	//-----------------------------------
115	// Internal methods
116
117	asCScriptFunction(asCScriptEngine *engine, asCModule *mod, int funcType);
118	~asCScriptFunction();
119
120	void      AddVariable(asCString &name, asCDataType &type, int stackOffset);
121
122	int       GetSpaceNeededForArguments();
123	int       GetSpaceNeededForReturnValue();
124	asCString GetDeclarationStr(bool includeObjectName = true) const;
125	int       GetLineNumber(int programPosition);
126	void      ComputeSignatureId();
127	bool      IsSignatureEqual(const asCScriptFunction *func) const;
128
129    void      JITCompile();
130
131	void      AddReferences();
132	void      ReleaseReferences();
133
134	int                GetGlobalVarPtrIndex(int gvarId);
135	asCConfigGroup    *GetConfigGroupByGlobalVarPtrIndex(int index);
136	asCGlobalProperty *GetPropertyByGlobalVarPtrIndex(int index);
137
138	// GC methods
139	int  GetRefCount();
140	void SetFlag();
141	bool GetFlag();
142	void EnumReferences(asIScriptEngine *engine);
143	void ReleaseAllHandles(asIScriptEngine *engine);
144
145public:
146	//-----------------------------------
147	// Properties
148
149	asCAtomic                    refCount;
150	bool                         gcFlag;
151	asCScriptEngine             *engine;
152	asCModule                   *module;
153
154	// Function signature
155	asCString                    name;
156	asCDataType                  returnType;
157	asCArray<asCDataType>        parameterTypes;
158	asCArray<asETypeModifiers>   inOutFlags;
159	bool                         isReadOnly;
160	asCObjectType               *objectType;
161	int                          signatureId;
162
163	int                          id;
164
165	int                          funcType;
166
167	// Used by asFUNC_SCRIPT
168	asCArray<asDWORD>            byteCode;
169	asCArray<asCObjectType*>     objVariableTypes;
170	asCArray<int>	             objVariablePos;
171	int                          stackNeeded;
172	asCArray<int>                lineNumbers;      // debug info
173	asCArray<asSScriptVariable*> variables;        // debug info
174	int                          scriptSectionIdx; // debug info
175	bool                         dontCleanUpOnException;   // Stub functions don't own the object and parameters
176
177	// This array holds pointers to all global variables that the function access.
178	// The byte code holds an index into this table to refer to a global variable.
179	asCArray<void*>              globalVarPointers;
180
181	// Used by asFUNC_VIRTUAL
182	int                          vfTableIdx;
183
184	// Used by asFUNC_SYSTEM
185	asSSystemFunctionInterface  *sysFuncIntf;
186
187    // JIT compiled code of this function
188    asJITFunction                jitFunction;
189};
190
191END_AS_NAMESPACE
192
193#endif