[r302]: cmajor++ / Cm / Cm.Core / Object.hpp  Maximize  Restore  History

Download this file

341 lines (326 with data), 17.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*========================================================================
Copyright (c) 2012-2013 Seppo Laakko
http://sourceforge.net/projects/cmajor/
Distributed under the GNU General Public License, version 3 (GPLv3).
(See accompanying LICENSE.txt or http://www.gnu.org/licenses/gpl.html)
========================================================================*/
#ifndef CM_CORE_OBJECT_INCLUDED
#define CM_CORE_OBJECT_INCLUDED
#include <Cm.Core/Argument.hpp>
#include <Llvm.Ir/Object.hpp>
#include <Soul.Parsing/Position.hpp>
#include <Soul.Util/TextUtils.hpp>
#include <Soul.Util/CodeFormatter.hpp>
#include <memory>
#include <map>
#include <set>
#include <stack>
namespace Cm { namespace Core {
class Object;
typedef std::shared_ptr<Object> ObjectPtr;
struct ObjectLess
{
bool operator()(ObjectPtr left, ObjectPtr right) const;
};
typedef std::weak_ptr<Object> WeakObjectPtr;
typedef std::set<ObjectPtr, ObjectLess> ObjectSet;
using Soul::Util::CodeFormatter;
using Soul::Parsing::Position;
class Scope;
typedef std::shared_ptr<Scope> ScopePtr;
typedef std::weak_ptr<Scope> WeakScopePtr;
class ObjectStack;
class Statement;
enum class GenFlags;
class GenResult;
class Ir;
typedef std::shared_ptr<Statement> StatementPtr;
class CompoundStatement;
typedef std::shared_ptr<CompoundStatement> CompoundStatementPtr;
class LocalVariable;
typedef std::shared_ptr<LocalVariable> LocalVariablePtr;
typedef std::weak_ptr<LocalVariable> WeakLocalVariablePtr;
typedef std::vector<LocalVariablePtr> LocalVariableList;
typedef std::vector<ObjectPtr> ExpressionList;
class ConstructionStatement;
typedef std::shared_ptr<ConstructionStatement> ConstructionStatementPtr;
typedef std::weak_ptr<ConstructionStatement> WeakConstructionStatementPtr;
class Function;
typedef std::shared_ptr<Function> FunctionPtr;
class Type;
typedef std::shared_ptr<Type> TypePtr;
typedef std::weak_ptr<Type> WeakTypePtr;
typedef std::set<FunctionPtr> FunctionPtrSet;
typedef FunctionPtrSet::const_iterator FunctionPtrSetIt;
class CloneContext;
class TypeCheckContext;
class ClassType;
typedef std::shared_ptr<ClassType> ClassTypePtr;
typedef std::weak_ptr<ClassType> WeakClassTypePtr;
typedef std::set<ClassTypePtr> ClassSet;
class Library;
typedef std::shared_ptr<Library> LibraryPtr;
class SubstituteContext;
class AssemblyObject;
typedef std::shared_ptr<AssemblyObject> AssemblyObjectPtr;
class CompilationUnit;
typedef std::shared_ptr<CompilationUnit> CompilationUnitPtr;
typedef std::weak_ptr<CompilationUnit> WeakCompilationUnitPtr;
class DestructionStack;
typedef std::shared_ptr<DestructionStack> DestructionStackPtr;
class BoundTemplateParameter;
typedef std::shared_ptr<BoundTemplateParameter> BoundTemplateParameterPtr;
typedef std::map<std::string, BoundTemplateParameterPtr> BoundTemplateParamMap;
typedef BoundTemplateParamMap::const_iterator BoundTemplateParamMapIt;
class Concept;
typedef std::shared_ptr<Concept> ConceptPtr;
enum class ObjectKind
{
namespace_,
external_constant,
constant,
value,
enumeration,
typedef_,
class_,
delegate_,
constructor,
assignment,
destructor,
function,
variable,
object
};
enum class TypeCheckingPhase { not_typechecked, typechecking_started, typechecking_complete };
const int compoundExit = -1;
const int noExitEntry = -2;
class Object: public std::enable_shared_from_this<Object>
{
public:
Object(const std::string& name_, const Position& pos_, const ScopePtr& enclosingScope_, const ScopePtr& fileScope_);
virtual ~Object();
virtual void Dispose();
bool Disposed() const { return disposed; }
virtual ObjectPtr Clone(CloneContext& context) const = 0;
const std::string& Name() const { return name; }
void SetName(const std::string& newName);
virtual std::string FullName() const;
virtual std::string FullNameWithConstraint() const { return FullName(); }
virtual std::string FullTypeName() const { return FullName(); }
virtual std::string ArchetypeName() const { return FullName(); }
std::string ScopeName() const;
virtual const std::string& BaseName() const { return Name(); }
virtual std::string GetMangleId() const { return name; }
const Position& Pos() const { return pos; }
ScopePtr EnclosingScope() const { return enclosingScope.lock(); }
ScopePtr FileScope() const;
std::set<ScopePtr>& ImportScopes() { return importScopes; }
bool IsImportedTo(const ScopePtr& scope) const;
void AddImportScope(const ScopePtr& importScope_) { importScopes.insert(importScope_); }
void AddImportScopes(const std::set<ScopePtr>& importScopes_);
void SetEnclosingScope(const ScopePtr& enclosingScope_) { enclosingScope = enclosingScope_; }
bool TypeCheckingStarted() const { return typeCheckingPhase != TypeCheckingPhase::not_typechecked; }
bool TypeCheckingComplete() const { return typeCheckingPhase == TypeCheckingPhase::typechecking_complete; }
void SetTypeCheckingPhase(TypeCheckingPhase phase) { typeCheckingPhase = phase; }
bool TypeChecking() const { return typeChecking; }
void TypeCheck(TypeCheckContext& context);
virtual void AddToScope();
virtual void TypeCheckName(TypeCheckContext& context);
virtual void TypeCheckSignature(TypeCheckContext& context);
virtual void TypeCheckBody(TypeCheckContext& context);
virtual ArgumentCategory GetArgumentCategory() const { return ArgumentCategory::rvalue; }
virtual ObjectPtr Instantiate(ExpressionList& templateArguments, TypeCheckContext& context);
virtual bool Bind(const TypePtr& argumentType, const ScopePtr& scope, ExpressionList& templateArguments, int& unifications, FunctionPtr& conversion) { return false; }
virtual ExpressionList TemplateArguments() const { return ExpressionList(); }
Argument GetArgument() const { return Argument(GetType(), GetArgumentCategory()); }
Argument GetArgument(ArgumentCategory category) const { return Argument(GetType(), category); }
virtual TypePtr GetType() const { return TypePtr(); }
virtual ObjectPtr GetTypeExpr() const { return std::const_pointer_cast<Object>(shared_from_this()); }
virtual TypePtr GetBaseType() const { return GetType(); }
virtual ObjectPtr GetBaseTypeExpr() const { return std::const_pointer_cast<Object>(shared_from_this()); }
virtual bool IsScopedObject() const { return false; }
virtual ScopePtr GetScope() const;
virtual bool IsNamespace() const { return false; }
virtual bool IsNamespaceImport() const { return false; }
virtual bool IsAlias() const { return false; }
virtual bool IsImportObject() const { return false; }
virtual bool IsName() const { return false; }
virtual bool IsTemplateName() const { return false; }
virtual bool IsValue() const { return false; }
virtual bool IsBoolValue() const { return false; }
virtual bool IsIntValue() const { return false; }
virtual bool IsDoubleValue() const { return false; }
virtual bool IsCharValue() const { return false; }
virtual bool IsStringValue() const { return false; }
virtual bool IsEnumerationValue() const { return false; }
virtual bool IsVariable() const { return false; }
virtual bool IsLocalVariable() const { return false; }
virtual bool IsMemberVariable() const { return false; }
virtual bool IsStaticVariable() const { return false; }
virtual bool IsThisVariable() const { return false; }
virtual bool IsThatVariable() const { return false; }
virtual bool IsThisAccess() const { return false; }
virtual bool IsBaseAccess() const { return false; }
virtual bool IsConstant() const { return false; }
virtual bool IsType() const { return false; }
virtual bool IsBasicType() const { return false; }
virtual bool IsBoolType() const { return false; }
virtual bool IsByteType() const { return false; }
virtual bool IsSByteType() const { return false; }
virtual bool IsShortType() const { return false; }
virtual bool IsUShortType() const { return false; }
virtual bool IsIntType() const { return false; }
virtual bool IsUIntType() const { return false; }
virtual bool IsLongType() const { return false; }
virtual bool IsULongType() const { return false; }
virtual bool IsHalfType() const { return false; }
virtual bool IsFloatType() const { return false; }
virtual bool IsDoubleType() const { return false; }
virtual bool IsCharType() const { return false; }
virtual bool IsEnumeratedType() const { return false; }
virtual bool IsIntegralType() const { return false; }
virtual bool IsFloatingPointType() const { return false; }
virtual bool IsScalarType() const { return false; }
virtual bool IsComplexType() const { return false; }
virtual bool IsVoidType() const { return false; }
virtual bool IsParameter() const { return false; }
virtual bool IsTemplateParameter() const { return false; }
virtual bool IsConcept() const { return false; }
virtual bool IsConceptSet() const { return false; }
virtual bool IsConceptSetLink() const { return false; }
virtual bool IsDerivedType() const { return false; }
virtual bool IsConstType() const { return false; }
virtual bool IsReferenceType() const { return false; }
virtual bool IsPointerType() const { return false; }
virtual bool IsConstReferenceType() const { return false; }
virtual bool IsConstReferenceTypeExpr() const { return false; }
virtual bool IsNullPtrType() const { return false; }
virtual bool IsGenericPtrType() const { return false; }
virtual bool IsClassType() const { return false; }
virtual bool IsClassTemplateReference() const { return false; }
virtual bool IsDelegateType() const { return false; }
virtual bool IsFunctionType() const { return false; }
virtual bool IsClassDelegateType() const { return false; }
virtual bool IsTypenameType() const { return false; }
virtual bool IsBoundTemplateParameter() const { return false; }
virtual bool IsBoundTemplateParameterLink() const { return false; }
virtual bool IsTypedef() const { return false; }
virtual bool IsPostfixExpr() const { return false; }
virtual bool IsFunctionSet() const { return false; }
virtual bool IsFunctionSetLink() const { return false; }
virtual bool IsFunction() const { return false; }
virtual bool IsFunctionTemplateReference() const { return false; }
virtual bool IsExternalFunction() const { return false; }
virtual bool IsMemberFunction() const { return false; }
virtual bool IsFunctionSetType() const { return false; }
virtual bool IsTemplate() const { return false; }
virtual bool IsConstrained() const { return false; }
virtual bool IsFunctionTemplateInstance() const { return false; }
virtual bool IsStaticConstructor() const { return false; }
virtual bool IsClassTemplateInstance() const { return false; }
virtual bool IsTypenameObject() const { return false; }
virtual bool IsUserTypeFunction() const { return false; }
virtual bool IsBuiltInAddrOf() const { return false; }
virtual bool IsMember() const { return false; }
virtual bool IsPtrMember() const { return false; }
virtual bool IsThisMember() const { return false; }
virtual bool IsFunctionSetObject() const { return false; }
virtual bool IsFunctionObject() const { return false; }
virtual bool IsBoolExpr() const { return false; }
virtual bool IsTypeExpr() const { return false; }
virtual bool IsInvokeExpr() const { return false; }
virtual bool IsDerefExpr() const { return false; }
virtual bool IsAddressOfExpr() const { return false; }
virtual bool IsIntegralConstantExpression() const { return false; }
virtual bool IsTrue() const { return false; }
virtual bool IsFalse() const { return false; }
virtual bool IsConstExpr() const { return false; }
virtual bool IsConstantMember() const { return false; }
virtual bool IsConversion() const { return false; }
virtual bool HasTrivialDestructor() const { return true; }
virtual bool HasTrivialMemberDestructors() const { return true; }
virtual bool IsAbstract() const { return false; }
virtual bool IsSuppressed() const { return false; }
virtual bool IsDefault() const { return false; }
virtual bool IsStatic() const { return false; }
virtual bool IsExternal() const { return false; }
virtual bool IsPublic() const { return false; }
virtual bool IsExplicit() const { return false; }
virtual bool IsClassLevelObject() const { return false; }
virtual bool IsLibraryObject() const { return false; }
virtual bool IsArchetype() const { return false; }
virtual bool IsProperArchetype() const { return false; }
virtual bool IsShared() const { return false; }
virtual bool IsPrefixIncDecExpr() const { return false; }
virtual const std::string& GetTypeName() const { return name; }
virtual std::string ToString() const { return name; }
CompoundStatement* Compound() const;
virtual void SetCompound(CompoundStatement* compound_);
virtual void CollectLocalVariables(LocalVariableList& vars);
virtual void GenerateDestructionStatements(DestructionStackPtr destructionStack);
Function* GetFunction() const { return function; }
virtual void SetFunction(Function* function_);
bool NameComputed() const { return nameComputed; }
virtual std::string ObjectKindStr() const { return "object"; }
virtual ObjectKind GetObjectKind() const { return ObjectKind::object; }
virtual std::string DocName() const { return FullName(); }
virtual std::string TypeDocName() const { return DocName(); }
virtual std::string ShortDocName() const { return Name(); }
virtual std::string ShortTypeDocName() const { return ShortDocName(); }
virtual std::string AliasOrShortTypeDocName() const { return ShortTypeDocName(); }
virtual std::string SyntaxName() const { return ShortDocName(); }
virtual bool HasTypeCheckReplacement(TypeCheckContext& context) const { return false; }
virtual ObjectPtr GetTypeCheckReplacement(TypeCheckContext& context) const { return ObjectPtr(); }
virtual ClassTypePtr GetClassType() const;
bool AddedToScope() const { return addedToScope; }
void SetAddedToScope() { addedToScope = true; }
void SetIrObject(Llvm::Ir::ObjectPtr irObject_) { irObject = irObject_; }
void SetLibrary(LibraryPtr library_) { library = library_; }
LibraryPtr GetLibrary() const { return library; }
virtual void SetCompilationUnit(CompilationUnitPtr compilationUnit_) { compilationUnit = compilationUnit_; }
CompilationUnitPtr GetCompilationUnit() const { return compilationUnit.lock(); }
void SetCompilationUnitInstantiatedFrom(CompilationUnitPtr compilationUnitInstantiatedFrom_) { compilationUnitInstantiatedFrom = compilationUnitInstantiatedFrom_; }
CompilationUnitPtr GetCompilationUnitInstantiatedFrom() const { return compilationUnitInstantiatedFrom.lock(); }
Llvm::Ir::ObjectPtr GetIrObject() const { return irObject; }
virtual GenResult Gen(Ir& ir, GenFlags flags);
virtual void Generate(Ir& ir, GenResult& result);
virtual void GenerateIntermediateCode(CodeFormatter& formatter);
virtual void CollectExternalObjects(CompilationUnitPtr compilationUnit, ObjectSet& externalObjects, bool deep);
virtual void GenerateExternalDeclaration(CodeFormatter& formatter);
virtual void GenerateLibraryDeclarations(CodeFormatter& formatter);
virtual void Evaluate(ObjectStack& stack);
void SetIndex(int index_) { index = index_; }
int GetIndex() const { return index; }
virtual void WriteToTemplateRepository(CodeFormatter& formatter);
bool ExternalObjectsCollected(CompilationUnitPtr compilationUnit) const;
virtual ObjectPtr SubstituteTemplateParams(const BoundTemplateParamMap& boundTemplateParamMap, bool& substituted);
virtual std::string InstanceFileName() const { return TypeDocName(); }
virtual void SetInstanceFileName(const std::string& instanceFileName);
void AddArchetypes(const ExpressionList& archetypes_, ConceptPtr concept);
virtual void CheckIfCanThrow(bool& canThrow, TypeCheckContext& context);
virtual void Print(CodeFormatter& formatter);
virtual void AddArgumentsToContext(TypeCheckContext& context) {}
private:
bool disposed;
std::string name;
Position pos;
WeakScopePtr enclosingScope;
WeakScopePtr fileScope;
std::set<ScopePtr> importScopes;
bool nameComputed;
TypeCheckingPhase typeCheckingPhase;
bool typeChecking;
CompoundStatement* compound;
Function* function;
bool addedToScope;
LibraryPtr library;
Llvm::Ir::ObjectPtr irObject;
WeakCompilationUnitPtr compilationUnit;
WeakCompilationUnitPtr compilationUnitInstantiatedFrom;
int index;
std::set<CompilationUnitPtr> externalCompilationUnits;
ExpressionList archetypes;
std::vector<ConceptPtr> concepts;
};
} } // namespace Cm::Core
#endif // CM_CORE_OBJECT_INCLUDED

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks