ScummVM API documentation
as_datatype.h
1 /*
2  AngelCode Scripting Library
3  Copyright (c) 2003-2016 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_datatype.h
34 //
35 // This class describes the datatype for expressions during compilation
36 //
37 
38 
39 
40 #ifndef AS_DATATYPE_H
41 #define AS_DATATYPE_H
42 
43 #include "as_tokendef.h"
44 #include "as_string.h"
45 
46 BEGIN_AS_NAMESPACE
47 
48 struct asSTypeBehaviour;
49 class asCScriptEngine;
50 class asCTypeInfo;
51 class asCScriptFunction;
52 class asCModule;
53 class asCObjectType;
54 class asCEnumType;
55 struct asSNameSpace;
56 
57 // TODO: refactor: Reference should not be part of the datatype. This should be stored separately, e.g. in asCExprValue
58 // MakeReference, MakeReadOnly, IsReference, IsReadOnly should be removed
59 
60 class asCDataType {
61 public:
62  asCDataType();
63  asCDataType(const asCDataType &);
64  ~asCDataType();
65 
66  bool IsValid() const;
67 
68  asCString Format(asSNameSpace *currNs, bool includeNamespace = false) const;
69 
70  static asCDataType CreatePrimitive(eTokenType tt, bool isConst);
71  static asCDataType CreateType(asCTypeInfo *ti, bool isConst);
72  static asCDataType CreateAuto(bool isConst);
73  static asCDataType CreateObjectHandle(asCTypeInfo *ot, bool isConst);
74  static asCDataType CreateNullHandle();
75 
76  int MakeHandle(bool b, bool acceptHandleForScope = false);
77  int MakeArray(asCScriptEngine *engine, asCModule *requestingModule);
78  int MakeReference(bool b);
79  int MakeReadOnly(bool b);
80  int MakeHandleToConst(bool b);
81  void SetIfHandleThenConst(bool b) {
82  ifHandleThenConst = b;
83  }
84  bool HasIfHandleThenConst() const {
85  return ifHandleThenConst;
86  }
87 
88  bool IsTemplate() const;
89  bool IsScriptObject() const;
90  bool IsPrimitive() const;
91  bool IsMathType() const;
92  bool IsObject() const;
93  bool IsReference() const {
94  return isReference;
95  }
96  bool IsAuto() const {
97  return isAuto;
98  }
99  bool IsReadOnly() const;
100  bool IsIntegerType() const;
101  bool IsUnsignedType() const;
102  bool IsFloatType() const;
103  bool IsDoubleType() const;
104  bool IsBooleanType() const;
105  bool IsObjectHandle() const {
106  return isObjectHandle;
107  }
108  bool IsHandleToAuto() const {
109  return isAuto && isObjectHandle;
110  }
111  bool IsHandleToConst() const;
112  bool IsArrayType() const;
113  bool IsEnumType() const;
114  bool IsAnyType() const {
115  return tokenType == ttQuestion;
116  }
117  bool IsHandleToAsHandleType() const {
118  return isHandleToAsHandleType;
119  }
120  bool IsAbstractClass() const;
121  bool IsInterface() const;
122  bool IsFuncdef() const;
123 
124  bool IsObjectConst() const;
125 
126  bool IsEqualExceptRef(const asCDataType &) const;
127  bool IsEqualExceptRefAndConst(const asCDataType &) const;
128  bool IsEqualExceptConst(const asCDataType &) const;
129  bool IsNullHandle() const;
130 
131  bool SupportHandles() const;
132  bool CanBeInstantiated() const;
133  bool CanBeCopied() const;
134 
135  bool operator ==(const asCDataType &) const;
136  bool operator !=(const asCDataType &) const;
137 
138  asCDataType GetSubType(asUINT subtypeIndex = 0) const;
139  eTokenType GetTokenType() const {
140  return tokenType;
141  }
142  asCTypeInfo *GetTypeInfo() const {
143  return typeInfo;
144  }
145 
146  int GetSizeOnStackDWords() const;
147  int GetSizeInMemoryBytes() const;
148  int GetSizeInMemoryDWords() const;
149 #ifdef WIP_16BYTE_ALIGN
150  int GetAlignment() const;
151 #endif
152 
153  void SetTokenType(eTokenType tt) {
154  tokenType = tt;
155  }
156  void SetTypeInfo(asCTypeInfo *ti) {
157  typeInfo = ti;
158  }
159 
160  asCDataType &operator =(const asCDataType &);
161 
162  asSTypeBehaviour *GetBehaviour() const;
163 
164 protected:
165  // Base object type
166  eTokenType tokenType;
167 
168  // Behaviour type
169  asCTypeInfo *typeInfo;
170 
171  // Top level
172  bool isReference: 1;
173  bool isReadOnly: 1;
174  bool isObjectHandle: 1;
175  bool isConstHandle: 1;
176  bool isAuto: 1;
177  bool isHandleToAsHandleType: 1; // Used by the compiler to know how to initialize the object
178  bool ifHandleThenConst: 1; // Used when creating template instances to determine if a handle should be const or not
179  char dummy: 1;
180 };
181 
182 END_AS_NAMESPACE
183 
184 #endif
Definition: as_module.h:93
Definition: as_typeinfo.h:64
Definition: as_scriptfunction.h:146
Definition: as_objecttype.h:100
Definition: as_namespace.h:39
Definition: as_typeinfo.h:263
Definition: as_datatype.h:60
Definition: as_objecttype.h:52
Definition: as_scriptengine.h:64
Definition: as_string.h:41