PageRenderTime 94ms CodeModel.GetById 82ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/xbmc/xbmc
C++ Header | 213 lines | 107 code | 41 blank | 65 comment | 0 complexity | 63ded9d0aadfb78e4da14d37867f22c7 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//
 34// as_module.h
 35//
 36// A class that holds a script module
 37//
 38
 39#ifndef AS_MODULE_H
 40#define AS_MODULE_H
 41
 42#include "as_config.h"
 43#include "as_atomic.h"
 44#include "as_string.h"
 45#include "as_array.h"
 46#include "as_datatype.h"
 47#include "as_scriptfunction.h"
 48#include "as_property.h"
 49
 50BEGIN_AS_NAMESPACE
 51
 52// TODO: import: Remove this when the imported functions are removed
 53const int FUNC_IMPORTED = 0x40000000;
 54
 55class asCScriptEngine;
 56class asCCompiler;
 57class asCBuilder;
 58class asCContext;
 59class asCConfigGroup;
 60
 61struct sBindInfo
 62{
 63	asCScriptFunction *importedFunctionSignature;
 64	asCString		   importFromModule;
 65	int                boundFunctionId;
 66};
 67
 68struct sObjectTypePair
 69{
 70	asCObjectType *a;
 71	asCObjectType *b;
 72};
 73
 74// TODO: import: Remove function imports. When I have implemented function 
 75//               pointers the function imports should be deprecated.
 76
 77// TODO: Need a separate interface for compiling scripts. The asIScriptCompiler
 78//       will have a target module, and will allow the compilation of an entire
 79//       script or just individual functions within the scope of the module
 80// 
 81//       With this separation it will be possible to compile the library without
 82//       the compiler, thus giving a much smaller binary executable.
 83
 84
 85class asCModule : public asIScriptModule
 86{
 87//-------------------------------------------
 88// Public interface
 89//--------------------------------------------
 90public:
 91	virtual asIScriptEngine *GetEngine();
 92	virtual void             SetName(const char *name);
 93	virtual const char      *GetName();
 94
 95	// Compilation
 96	virtual int  AddScriptSection(const char *name, const char *code, size_t codeLength, int lineOffset);
 97	virtual int  Build();
 98	virtual int  CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD reserved, asIScriptFunction **outFunc);
 99	virtual int  CompileGlobalVar(const char *sectionName, const char *code, int lineOffset);
100
101	// Script functions
102	virtual int                GetFunctionCount();
103	virtual int                GetFunctionIdByIndex(int index);
104	virtual int                GetFunctionIdByName(const char *name);
105	virtual int                GetFunctionIdByDecl(const char *decl);
106	virtual asIScriptFunction *GetFunctionDescriptorByIndex(int index);
107	virtual asIScriptFunction *GetFunctionDescriptorById(int funcId);
108	virtual int                RemoveFunction(int funcId);
109
110	// Script global variables
111	virtual int         ResetGlobalVars();
112	virtual int         GetGlobalVarCount();
113	virtual int         GetGlobalVarIndexByName(const char *name);
114	virtual int         GetGlobalVarIndexByDecl(const char *decl);
115	virtual const char *GetGlobalVarDeclaration(int index);
116	virtual const char *GetGlobalVarName(int index);
117	virtual int         GetGlobalVarTypeId(int index, bool *isConst);
118	virtual void       *GetAddressOfGlobalVar(int index);
119	virtual int         RemoveGlobalVar(int index);
120
121	// Type identification
122	virtual int            GetObjectTypeCount();
123	virtual asIObjectType *GetObjectTypeByIndex(asUINT index);
124	virtual int            GetTypeIdByDecl(const char *decl);
125
126	// Enums
127	virtual int         GetEnumCount();
128	virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId);
129	virtual int         GetEnumValueCount(int enumTypeId);
130	virtual const char *GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue);
131
132	// Typedefs
133	virtual int         GetTypedefCount();
134	virtual const char *GetTypedefByIndex(asUINT index, int *typeId);
135
136	// Dynamic binding between modules
137	virtual int         GetImportedFunctionCount();
138	virtual int         GetImportedFunctionIndexByDecl(const char *decl);
139	virtual const char *GetImportedFunctionDeclaration(int importIndex);
140	virtual const char *GetImportedFunctionSourceModule(int importIndex);
141	virtual int         BindImportedFunction(int index, int sourceID);
142	virtual int         UnbindImportedFunction(int importIndex);
143	virtual int         BindAllImportedFunctions();
144	virtual int         UnbindAllImportedFunctions();
145
146	// Bytecode Saving/Loading
147	virtual int SaveByteCode(asIBinaryStream *out);
148	virtual int LoadByteCode(asIBinaryStream *in);
149
150//-----------------------------------------------
151// Internal
152//-----------------------------------------------
153	asCModule(const char *name, asCScriptEngine *engine);
154	~asCModule();
155
156//protected:
157	friend class asCScriptEngine;
158	friend class asCBuilder;
159	friend class asCCompiler;
160	friend class asCContext;
161	friend class asCRestore;
162
163	void InternalReset();
164
165	int  CallInit();
166	void CallExit();
167
168    void JITCompile();
169
170	int  AddScriptFunction(int sectionIdx, int id, const char *name, const asCDataType &returnType, asCDataType *params, asETypeModifiers *inOutFlags, int paramCount, bool isInterface, asCObjectType *objType = 0, bool isConstMethod = false, bool isGlobalFunction = false);
171	int  AddScriptFunction(asCScriptFunction *func);
172	int  AddImportedFunction(int id, const char *name, const asCDataType &returnType, asCDataType *params, asETypeModifiers *inOutFlags, int paramCount, const asCString &moduleName);
173
174	int  GetNextImportedFunctionId();
175
176	void ResolveInterfaceIds();
177	bool AreInterfacesEqual(asCObjectType *a, asCObjectType *b, asCArray<sObjectTypePair> &equals);
178	bool AreTypesEqual(const asCDataType &a, const asCDataType &b, asCArray<sObjectTypePair> &equals);
179
180	asCScriptFunction *GetImportedFunction(int funcId);
181
182	asCObjectType *GetObjectType(const char *type);
183
184	asCGlobalProperty *AllocateGlobalProperty(const char *name, const asCDataType &dt);
185
186
187	asCString name;
188
189	asCScriptEngine *engine;
190	asCBuilder      *builder;
191
192	// This array holds all functions, class members, factories, etc that were compiled with the module
193	asCArray<asCScriptFunction *>  scriptFunctions;
194	// This array holds global functions declared in the module
195	asCArray<asCScriptFunction *>  globalFunctions;
196	// This array holds imported functions in the module
197	asCArray<sBindInfo *>          bindInformations;
198
199	// This array holds the global variables declared in the script
200	asCArray<asCGlobalProperty *>  scriptGlobals;
201	bool                           isGlobalVarInitialized;
202
203	// This array holds class and interface types
204	asCArray<asCObjectType*>       classTypes;
205	// This array holds enum types
206	asCArray<asCObjectType*>       enumTypes;
207	// This array holds typedefs
208	asCArray<asCObjectType*>       typeDefs;
209};
210
211END_AS_NAMESPACE
212
213#endif