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 46 BEGIN_AS_NAMESPACE 47 48 class asCScriptEngine; 49 class asCModule; 50 class asCObjectType; 51 class asCEnumType; 52 class asCTypedefType; 53 class asCFuncdefType; 54 struct asSNameSpace; 55 56 // TODO: type: asCPrimitiveType shall be implemented to represent primitives (void, int, double, etc) 57 58 // TODO: type: asCTypeInfo should have an internal virtual method GetBehaviours. For asCObjectType it 59 // should return the beh member. For asCFuncdefType it should return the beh member of 60 // engine->functionBehaviours. This will allow the code that needs the behaviour to handle 61 // both object types and funcdefs the same way 62 63 class asCTypeInfo : public asITypeInfo 64 { 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; GetBaseType()81 asITypeInfo *GetBaseType() const { return 0; } DerivesFrom(const asITypeInfo * objType)82 bool DerivesFrom(const asITypeInfo *objType) const { UNUSED_VAR(objType); return 0; } 83 asDWORD GetFlags() const; 84 asUINT GetSize() const; 85 int GetTypeId() const; 86 int GetSubTypeId(asUINT subtypeIndex = 0) const { UNUSED_VAR(subtypeIndex); return -1; } 87 asITypeInfo *GetSubType(asUINT subtypeIndex = 0) const { UNUSED_VAR(subtypeIndex); return 0; } GetSubTypeCount()88 asUINT GetSubTypeCount() const { return 0; } 89 90 // Interfaces GetInterfaceCount()91 asUINT GetInterfaceCount() const { return 0; } GetInterface(asUINT index)92 asITypeInfo *GetInterface(asUINT index) const { UNUSED_VAR(index); return 0; } Implements(const asITypeInfo * objType)93 bool Implements(const asITypeInfo *objType) const { UNUSED_VAR(objType); return false; } 94 95 // Factories GetFactoryCount()96 asUINT GetFactoryCount() const { return 0; } GetFactoryByIndex(asUINT index)97 asIScriptFunction *GetFactoryByIndex(asUINT index) const { UNUSED_VAR(index); return 0; } GetFactoryByDecl(const char * decl)98 asIScriptFunction *GetFactoryByDecl(const char *decl) const { UNUSED_VAR(decl); return 0; } 99 100 // Methods GetMethodCount()101 asUINT GetMethodCount() const { return 0; } GetMethodByIndex(asUINT index,bool getVirtual)102 asIScriptFunction *GetMethodByIndex(asUINT index, bool getVirtual) const { UNUSED_VAR(index); UNUSED_VAR(getVirtual); return 0; } GetMethodByName(const char * in_name,bool getVirtual)103 asIScriptFunction *GetMethodByName(const char *in_name, bool getVirtual) const { UNUSED_VAR(in_name); UNUSED_VAR(getVirtual); return 0; } GetMethodByDecl(const char * decl,bool getVirtual)104 asIScriptFunction *GetMethodByDecl(const char *decl, bool getVirtual) const { UNUSED_VAR(decl); UNUSED_VAR(getVirtual); return 0; } 105 106 // Properties GetPropertyCount()107 asUINT GetPropertyCount() const { return 0; } 108 int GetProperty(asUINT index, const char **name, int *typeId, bool *isPrivate, bool *isProtected, int *offset, bool *isReference, asDWORD *accessMask, int *compositeOffset, bool *isCompositeIndirect) const; 109 const char *GetPropertyDeclaration(asUINT index, bool includeNamespace = false) const { UNUSED_VAR(index); UNUSED_VAR(includeNamespace); return 0; } 110 111 // Behaviours GetBehaviourCount()112 asUINT GetBehaviourCount() const { return 0; } GetBehaviourByIndex(asUINT index,asEBehaviours * outBehaviour)113 asIScriptFunction *GetBehaviourByIndex(asUINT index, asEBehaviours *outBehaviour) const { UNUSED_VAR(index); UNUSED_VAR(outBehaviour); return 0; } 114 115 // Child types GetChildFuncdefCount()116 asUINT GetChildFuncdefCount() const { return 0; } GetChildFuncdef(asUINT index)117 asITypeInfo *GetChildFuncdef(asUINT index) const { UNUSED_VAR(index); return 0; } GetParentType()118 asITypeInfo *GetParentType() const { return 0; } 119 120 // Enums GetEnumValueCount()121 virtual asUINT GetEnumValueCount() const { return 0; } GetEnumValueByIndex(asUINT index,int * outValue)122 virtual const char *GetEnumValueByIndex(asUINT index, int *outValue) const { UNUSED_VAR(index); if (outValue) *outValue = 0; return 0; } 123 124 // Typedef GetTypedefTypeId()125 virtual int GetTypedefTypeId() const { return asERROR; } 126 127 // Funcdef GetFuncdefSignature()128 virtual asIScriptFunction *GetFuncdefSignature() const { return 0; } 129 130 // User data 131 void *SetUserData(void *data, asPWORD type); 132 void *GetUserData(asPWORD type) const; 133 134 //=========================================== 135 // Internal 136 //=========================================== 137 public: 138 asCTypeInfo(asCScriptEngine *engine); 139 virtual ~asCTypeInfo(); 140 141 // Keep an internal reference counter to separate references coming from 142 // application or script objects and references coming from the script code 143 virtual int AddRefInternal(); 144 virtual int ReleaseInternal(); 145 DestroyInternal()146 virtual void DestroyInternal() {} 147 148 void CleanUserData(); 149 150 bool IsShared() const; 151 152 // These can be safely used on null pointers (which will return null) 153 friend asCObjectType *CastToObjectType(asCTypeInfo *); 154 friend asCEnumType *CastToEnumType(asCTypeInfo *); 155 friend asCTypedefType *CastToTypedefType(asCTypeInfo *); 156 friend asCFuncdefType *CastToFuncdefType(asCTypeInfo *); 157 158 159 asCString name; 160 asSNameSpace *nameSpace; 161 int size; 162 mutable int typeId; 163 asDWORD flags; 164 asDWORD accessMask; 165 166 // Store the script section where the code was declared 167 int scriptSectionIdx; 168 // Store the location where the function was declared (row in the lower 20 bits, and column in the upper 12) 169 int declaredAt; 170 171 asCScriptEngine *engine; 172 asCModule *module; 173 asCArray<asPWORD> userData; 174 175 protected: 176 friend class asCScriptEngine; 177 friend class asCConfigGroup; 178 friend class asCModule; 179 friend class asCObjectType; 180 asCTypeInfo(); 181 182 mutable asCAtomic externalRefCount; 183 asCAtomic internalRefCount; 184 }; 185 186 struct asSEnumValue 187 { 188 asCString name; 189 int value; 190 }; 191 192 class asCEnumType : public asCTypeInfo 193 { 194 public: asCEnumType(asCScriptEngine * engine)195 asCEnumType(asCScriptEngine *engine) : asCTypeInfo(engine) {} 196 ~asCEnumType(); 197 198 asCArray<asSEnumValue*> enumValues; 199 200 asUINT GetEnumValueCount() const; 201 const char *GetEnumValueByIndex(asUINT index, int *outValue) const; 202 203 protected: asCEnumType()204 asCEnumType() : asCTypeInfo() {} 205 }; 206 207 class asCTypedefType : public asCTypeInfo 208 { 209 public: asCTypedefType(asCScriptEngine * engine)210 asCTypedefType(asCScriptEngine *engine) : asCTypeInfo(engine) {} 211 ~asCTypedefType(); 212 213 void DestroyInternal(); 214 215 asCDataType aliasForType; // increase refCount for typeinfo inside datatype 216 217 int GetTypedefTypeId() const; 218 219 protected: asCTypedefType()220 asCTypedefType() : asCTypeInfo() {} 221 }; 222 223 class asCFuncdefType : public asCTypeInfo 224 { 225 public: 226 asCFuncdefType(asCScriptEngine *engine, asCScriptFunction *func); 227 ~asCFuncdefType(); 228 229 asIScriptFunction *GetFuncdefSignature() const; 230 asITypeInfo *GetParentType() const; 231 232 void DestroyInternal(); 233 asCScriptFunction *funcdef; // increases refCount 234 asCObjectType *parentClass; // doesn't increase refCount 235 236 protected: asCFuncdefType()237 asCFuncdefType() : asCTypeInfo(), funcdef(0), parentClass(0) {} 238 }; 239 240 END_AS_NAMESPACE 241 242 #endif 243