ScummVM API documentation
as_typeinfo.h
1 /*
2  AngelCode Scripting Library
3  Copyright (c) 2003-2017 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_typeinfo.h
34 //
35 
36 
37 
38 #ifndef AS_TYPEINFO_H
39 #define AS_TYPEINFO_H
40 
41 #include "as_config.h"
42 #include "as_string.h"
43 #include "as_atomic.h"
44 #include "as_datatype.h"
45 #include "as_memory.h"
46 
47 BEGIN_AS_NAMESPACE
48 
49 class asCScriptEngine;
50 class asCModule;
51 class asCObjectType;
52 class asCEnumType;
53 class asCTypedefType;
54 class asCFuncdefType;
55 struct asSNameSpace;
56 
57 // TODO: type: asCPrimitiveType shall be implemented to represent primitives (void, int, double, etc)
58 
59 // TODO: type: asCTypeInfo should have an internal virtual method GetBehaviours. For asCObjectType it
60 // should return the beh member. For asCFuncdefType it should return the beh member of
61 // engine->functionBehaviours. This will allow the code that needs the behaviour to handle
62 // both object types and funcdefs the same way
63 
64 class asCTypeInfo : public asITypeInfo {
65 public:
66  //=====================================
67  // From asITypeInfo
68  //=====================================
69  asIScriptEngine *GetEngine() const;
70  const char *GetConfigGroup() const;
71  asDWORD GetAccessMask() const;
72  asIScriptModule *GetModule() const;
73 
74  // Memory management
75  int AddRef() const;
76  int Release() const;
77 
78  // Type info
79  const char *GetName() const;
80  const char *GetNamespace() const;
81  asITypeInfo *GetBaseType() const {
82  return 0;
83  }
84  bool DerivesFrom(const asITypeInfo *objType) const {
85  UNUSED_VAR(objType);
86  return 0;
87  }
88  asDWORD GetFlags() const;
89  asUINT GetSize() const;
90  int GetTypeId() const;
91  int GetSubTypeId(asUINT subtypeIndex = 0) const {
92  UNUSED_VAR(subtypeIndex);
93  return -1;
94  }
95  asITypeInfo *GetSubType(asUINT subtypeIndex = 0) const {
96  UNUSED_VAR(subtypeIndex);
97  return 0;
98  }
99  asUINT GetSubTypeCount() const {
100  return 0;
101  }
102 
103  // Interfaces
104  asUINT GetInterfaceCount() const {
105  return 0;
106  }
107  asITypeInfo *GetInterface(asUINT index) const {
108  UNUSED_VAR(index);
109  return 0;
110  }
111  bool Implements(const asITypeInfo *objType) const {
112  UNUSED_VAR(objType);
113  return false;
114  }
115 
116  // Factories
117  asUINT GetFactoryCount() const {
118  return 0;
119  }
120  asIScriptFunction *GetFactoryByIndex(asUINT index) const {
121  UNUSED_VAR(index);
122  return 0;
123  }
124  asIScriptFunction *GetFactoryByDecl(const char *decl) const {
125  UNUSED_VAR(decl);
126  return 0;
127  }
128 
129  // Methods
130  asUINT GetMethodCount() const {
131  return 0;
132  }
133  asIScriptFunction *GetMethodByIndex(asUINT index, bool getVirtual) const {
134  UNUSED_VAR(index);
135  UNUSED_VAR(getVirtual);
136  return 0;
137  }
138  asIScriptFunction *GetMethodByName(const char *in_name, bool getVirtual) const {
139  UNUSED_VAR(in_name);
140  UNUSED_VAR(getVirtual);
141  return 0;
142  }
143  asIScriptFunction *GetMethodByDecl(const char *decl, bool getVirtual) const {
144  UNUSED_VAR(decl);
145  UNUSED_VAR(getVirtual);
146  return 0;
147  }
148 
149  // Properties
150  asUINT GetPropertyCount() const {
151  return 0;
152  }
153  int GetProperty(asUINT index, const char **name, int *typeId, bool *isPrivate, bool *isProtected, int *offset, bool *isReference, asDWORD *accessMask, int *compositeOffset, bool *isCompositeIndirect) const;
154  const char *GetPropertyDeclaration(asUINT index, bool includeNamespace = false) const {
155  UNUSED_VAR(index);
156  UNUSED_VAR(includeNamespace);
157  return 0;
158  }
159 
160  // Behaviours
161  asUINT GetBehaviourCount() const {
162  return 0;
163  }
164  asIScriptFunction *GetBehaviourByIndex(asUINT index, asEBehaviours *outBehaviour) const {
165  UNUSED_VAR(index);
166  UNUSED_VAR(outBehaviour);
167  return 0;
168  }
169 
170  // Child types
171  asUINT GetChildFuncdefCount() const {
172  return 0;
173  }
174  asITypeInfo *GetChildFuncdef(asUINT index) const {
175  UNUSED_VAR(index);
176  return 0;
177  }
178  asITypeInfo *GetParentType() const {
179  return 0;
180  }
181 
182  // Enums
183  virtual asUINT GetEnumValueCount() const {
184  return 0;
185  }
186  virtual const char *GetEnumValueByIndex(asUINT index, int *outValue) const {
187  UNUSED_VAR(index);
188  if (outValue) *outValue = 0;
189  return 0;
190  }
191 
192  // Typedef
193  virtual int GetTypedefTypeId() const {
194  return asERROR;
195  }
196 
197  // Funcdef
198  virtual asIScriptFunction *GetFuncdefSignature() const {
199  return 0;
200  }
201 
202  // User data
203  void *SetUserData(void *data, asPWORD type);
204  void *GetUserData(asPWORD type) const;
205 
206  //===========================================
207  // Internal
208  //===========================================
209 public:
210  asCTypeInfo(asCScriptEngine *engine);
211  virtual ~asCTypeInfo();
212 
213  // Keep an internal reference counter to separate references coming from
214  // application or script objects and references coming from the script code
215  virtual int AddRefInternal();
216  virtual int ReleaseInternal();
217 
218  virtual void DestroyInternal() {}
219 
220  void CleanUserData();
221 
222  bool IsShared() const;
223 
224  // These can be safely used on null pointers (which will return null)
225  friend asCObjectType *CastToObjectType(asCTypeInfo *);
226  friend asCEnumType *CastToEnumType(asCTypeInfo *);
227  friend asCTypedefType *CastToTypedefType(asCTypeInfo *);
228  friend asCFuncdefType *CastToFuncdefType(asCTypeInfo *);
229 
230 
231  asCString name;
232  asSNameSpace *nameSpace;
233  int size;
234  mutable int typeId;
235  asDWORD flags;
236  asDWORD accessMask;
237 
238  // Store the script section where the code was declared
239  int scriptSectionIdx;
240  // Store the location where the function was declared (row in the lower 20 bits, and column in the upper 12)
241  int declaredAt;
242 
243  asCScriptEngine *engine;
244  asCModule *module;
245  asCArray<asPWORD> userData;
246 
247 protected:
248  friend class asCScriptEngine;
249  friend class asCConfigGroup;
250  friend class asCModule;
251  friend class asCObjectType;
252  asCTypeInfo();
253 
254  mutable asCAtomic externalRefCount;
255  asCAtomic internalRefCount;
256 };
257 
258 struct asSEnumValue {
259  asCString name;
260  int value;
261 };
262 
263 class asCEnumType : public asCTypeInfo {
264 public:
265  asCEnumType(asCScriptEngine *_engine) : asCTypeInfo(_engine) {}
266  ~asCEnumType();
267 
268  asCArray<asSEnumValue *> enumValues;
269 
270  asUINT GetEnumValueCount() const;
271  const char *GetEnumValueByIndex(asUINT index, int *outValue) const;
272 
273 protected:
274  asCEnumType() : asCTypeInfo() {}
275 };
276 
277 class asCTypedefType : public asCTypeInfo {
278 public:
279  asCTypedefType(asCScriptEngine *_engine) : asCTypeInfo(_engine) {}
280  ~asCTypedefType();
281 
282  void DestroyInternal();
283 
284  asCDataType aliasForType; // increase refCount for typeinfo inside datatype
285 
286  int GetTypedefTypeId() const;
287 
288 protected:
289  asCTypedefType() : asCTypeInfo() {}
290 };
291 
292 class asCFuncdefType : public asCTypeInfo {
293 public:
295  ~asCFuncdefType();
296 
297  asIScriptFunction *GetFuncdefSignature() const;
298  asITypeInfo *GetParentType() const;
299 
300  void DestroyInternal();
301  asCScriptFunction *funcdef; // increases refCount
302  asCObjectType *parentClass; // doesn't increase refCount
303 
304 protected:
305  asCFuncdefType() : asCTypeInfo(), funcdef(0), parentClass(0) {}
306 };
307 
308 END_AS_NAMESPACE
309 
310 #endif
Definition: as_typeinfo.h:258
Definition: as_module.h:93
Definition: angelscript.h:1083
Definition: as_typeinfo.h:64
Definition: angelscript.h:793
Definition: as_scriptfunction.h:146
Definition: as_objecttype.h:100
Definition: as_namespace.h:39
Definition: as_configgroup.h:50
Definition: as_typeinfo.h:263
Definition: as_atomic.h:49
Definition: as_datatype.h:60
Definition: as_typeinfo.h:277
Definition: as_typeinfo.h:292
Definition: as_scriptengine.h:64
Definition: angelscript.h:639
Definition: angelscript.h:1011
Definition: as_string.h:41