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

Download this file

176 lines (157 with data), 7.2 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
/*========================================================================
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_TYPE_INCLUDED
#define CM_CORE_TYPE_INCLUDED
#include <Cm.Core/Object.hpp>
#include <Cm.Core/Specifier.hpp>
#include <Llvm.Ir/Type.hpp>
namespace Cm { namespace Core {
const int FIRST_USER_TYPEID = 1;
const int NO_TYPEID = 0;
const int BOOL_TYPEID = -1;
const int BYTE_TYPEID = -2;
const int SBYTE_TYPEID = -3;
const int SHORT_TYPEID = -4;
const int USHORT_TYPEID = -5;
const int INT_TYPEID = -6;
const int UINT_TYPEID = -7;
const int LONG_TYPEID = -8;
const int ULONG_TYPEID = -9;
const int HALF_TYPEID = -10;
const int FLOAT_TYPEID = -11;
const int DOUBLE_TYPEID = -12;
const int CHAR_TYPEID = -13;
const int VOID_TYPEID = -14;
const int CHARPTR_TYPEID = -15;
const int NULLPTR_TYPEID = -16;
const int TYPENAME_TYPEID = -17;
const int BOOL_RANK = 0;
const int BYTE_RANK = 1;
const int SBYTE_RANK = 2;
const int SHORT_RANK = 3;
const int USHORT_RANK = 4;
const int INT_RANK = 5;
const int UINT_RANK = 6;
const int LONG_RANK = 7;
const int ULONG_RANK = 8;
const int HALF_RANK = 9;
const int FLOAT_RANK = 10;
const int DOUBLE_RANK = 11;
const int USER_RANK = 12;
class Value;
typedef std::shared_ptr<Value> ValuePtr;
class Type;
typedef std::shared_ptr<Type> TypePtr;
class Type: public Object
{
public:
Type(const std::string& name_, const Position& pos_, const ScopePtr& enclosingScope_, const ScopePtr& fileScope_, int id_, int rank_);
virtual void Dispose();
virtual std::string ToString() const { return FullName(); }
virtual ObjectPtr Clone(CloneContext& context) const { return std::const_pointer_cast<Object>(shared_from_this()); }
int Id() const { return id; }
void SetId(int id_) { id = id_; }
int Rank() const { return rank; }
virtual bool IsType() const { return true; }
virtual bool IsTypeExpr() const { return true; }
virtual bool IsSignedType() const { return true; }
virtual TypePtr GetType() const;
virtual bool EqualsTo(const Type& that) const { return id == that.id; }
virtual bool IsConstCharPtrPtr() const { return false; }
virtual bool IsConstCharPtrType() const { return true; }
virtual bool IsConstReferenceType() const { return false; }
virtual bool IsTemplateParameterType() const { return IsTemplateParameter(); }
virtual bool IsRefToClassType() const { return false; }
virtual bool HasBaseClass(const TypePtr& base, int& distance) const { return false; }
virtual bool HasBaseClass(const TypePtr& base) const { return false; }
virtual bool IsVirtual() const { return false; }
virtual bool IsAbstract() const { return false; }
virtual bool IsInstantiatedFromTemplate() const { return false; }
virtual bool IsShared() const { return true; }
virtual void SetFunction(Function*) {} // types do not have function
virtual TypePtr ContainingType() const { return TypePtr(); }
const std::string& Alias() const { return alias; }
void SetAlias(const std::string& alias_) { alias = alias_; }
virtual std::string AliasOrShortTypeDocName() const { return alias.empty() ? ShortTypeDocName() : alias; }
void SetIrType(Llvm::Ir::TypePtr irType_) { irType = irType_; }
Llvm::Ir::TypePtr IrType() const { return irType; }
void SetDefaultIrValue(Llvm::Ir::ObjectPtr defaultIrValue_) { defaultIrValue = defaultIrValue_; }
Llvm::Ir::ObjectPtr DefaultIrValue() const { return defaultIrValue; }
ValuePtr MakeValue();
private:
int id;
int rank;
std::string alias;
Llvm::Ir::TypePtr irType;
Llvm::Ir::ObjectPtr defaultIrValue;
};
bool TypesEqual(TypePtr left, TypePtr right);
inline bool IsSame(TypePtr left, TypePtr right) { return TypesEqual(left, right); }
bool IsTriviallyConvertible(TypePtr from, TypePtr to);
bool IsConvertible(TypePtr from, TypePtr to);
bool IsExplicitlyConvertible(TypePtr from, TypePtr to, Function* ownerFunction, const Position& callPos);
bool IsDerived(TypePtr derivedType, TypePtr baseType);
TypePtr CommonType(TypePtr left, TypePtr right);
class TypenameType;
typedef std::shared_ptr<TypenameType> TypenameTypePtr;
class TypenameType: public Type
{
public:
static void Init();
static void Done();
static TypenameTypePtr Instance();
virtual bool IsTypeExpr() const { return true; }
virtual std::string GetMangleId() const { return "TN"; }
virtual bool IsTypenameType() const { return true; }
private:
TypenameType();
static TypenameTypePtr instance;
static std::stack<TypenameTypePtr> instanceStack;
};
class ClassType;
typedef std::shared_ptr<ClassType> ClassTypePtr;
class Typedef: public Object
{
public:
Typedef(const std::string& name_, const Position& pos_, const ScopePtr& enclosingScope_, const ScopePtr& fileScope_, Specifiers specifiers_, const ObjectPtr& typeExpr_);
virtual void Dispose();
virtual ObjectPtr Clone(CloneContext& context) const;
virtual TypePtr GetType() const { return type.lock(); }
virtual void TypeCheckName(TypeCheckContext& context);
virtual void TypeCheckSignature(TypeCheckContext& context);
virtual void TypeCheckBody(TypeCheckContext& context);
virtual bool IsTypeExpr() const { return true; }
virtual bool IsTypedef() const { return true; }
virtual bool IsImportObject() const { return true; }
virtual bool IsPublic() const { return (specifiers & Specifiers::public_) != Specifiers::none; }
virtual void SetFunction(Function* function);
virtual TypePtr ContainingType() const;
Specifiers GetSpecifiers() const { return specifiers; }
ClassTypePtr ClassType() const { return classType.lock(); }
virtual bool IsClassLevelObject() const { return classType.lock(); }
void SetClassType(const ClassTypePtr& classType_) { classType = classType_; }
virtual std::string ObjectKindStr() const { return "typedef"; }
virtual ObjectKind GetObjectKind() const { return ObjectKind::typedef_; }
virtual std::string ShortTypeDocName() const;
void SetTypeExpr(const ObjectPtr& typeExpr_) { typeExpr = typeExpr_; }
virtual bool HasTypeCheckReplacement(TypeCheckContext& context) const;
virtual ObjectPtr GetTypeCheckReplacement(TypeCheckContext& context) const;
virtual void CollectExternalObjects(CompilationUnitPtr compilationUnit, ObjectSet& externalObjects, bool deep);
virtual void GenerateLibraryDeclarations(CodeFormatter& formatter);
private:
Specifiers specifiers;
ObjectPtr typeExpr;
WeakTypePtr type;
WeakClassTypePtr classType;
};
typedef std::shared_ptr<Typedef> TypedefPtr;
void TypeInit();
void TypeDone();
void CommonTypeInit();
void CommonTypeDone();
} } // namespace Cm::Core
#endif // CM_CORE_TYPE_INCLUDED

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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks