[r368]: cmajor++ / Cm / Cm.Core / MemberFunction.hpp Maximize Restore History

Download this file

MemberFunction.hpp    176 lines (160 with data), 9.5 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_MEMBERFUNCTION_INCLUDED
#define CM_CORE_MEMBERFUNCTION_INCLUDED
#include <Cm.Core/Initializer.hpp>
namespace Cm { namespace Core {
class MemberFunction: public Function
{
public:
MemberFunction(const std::string& name_, const Position& pos_, const ScopePtr& enclosingScope_, const ScopePtr& fileScope_,
const std::string& functionSetName_, Specifiers specifiers_, const ClassTypePtr& classType);
virtual void Dispose();
virtual ObjectPtr Clone(CloneContext& context) const;
virtual std::string ObjectKindStr() const { return FunctionSetName() == "operator=" ? "assignment" : "function"; }
virtual ObjectKind GetObjectKind() const { return FunctionSetName() == "operator=" ? ObjectKind::assignment : ObjectKind::function; }
virtual bool IsMemberFunction() const { return true; }
virtual bool IsMember() const { return true; }
virtual bool IsAssignment() const;
virtual bool IsVirtualAbstractOrOverride() const { return (GetSpecifiers() & Specifiers::virtuality) != Specifiers::none; }
virtual bool IsVirtual() const { return (GetSpecifiers() & Specifiers::virtual_) != Specifiers::none; }
virtual bool IsAbstract() const { return (GetSpecifiers() & Specifiers::abstract_) != Specifiers::none; }
virtual bool IsSuppressed() const { return (GetSpecifiers() & Specifiers::suppress) != Specifiers::none; }
virtual bool IsDefault() const { return (GetSpecifiers() & Specifiers::default_) != Specifiers::none; }
virtual bool IsOverride() const { return (GetSpecifiers() & Specifiers::override_) != Specifiers::none; }
virtual bool IsStatic() const { return (GetSpecifiers() & Specifiers::static_) != Specifiers::none; }
virtual bool IsExternal() const { return (GetSpecifiers() & Specifiers::external) != Specifiers::none; }
virtual bool IsClassLevelObject() const { return true; }
virtual bool IsArchetype() const;
virtual bool IsConversionFunction() const;
virtual bool IsConst() const { return isConst; }
void SetVirtual();
virtual ClassTypePtr GetClassType() const { return classType.lock(); }
void SetClassType(ClassTypePtr classType_) { classType = classType_; }
void SetConst() { isConst = true; }
void SetVirtualFunctionTableIndex(int index) { vtblIndex = index; }
int VirtualFunctionTableIndex() const { return vtblIndex; }
virtual void TypeCheckSignature(TypeCheckContext& context);
virtual void TypeCheckBody(TypeCheckContext& context);
virtual void CollectExternalObjects(CompilationUnitPtr compilationUnit);
const FunctionPtrSet& Overrides() const { return overrides; }
void AddToOverrides(const FunctionPtr& f) { overrides.insert(f); }
virtual std::string GetParsingName() const;
FunctionPtr GetBaseClassMember() const { return baseClassMember; }
void SetBaseClassMember(const FunctionPtr& baseClassMember_) { baseClassMember = baseClassMember_; }
virtual std::string ShortDocName() const;
virtual std::string AliasOrShortTypeDocName() const;
virtual std::string SyntaxName() const;
virtual bool BelongsToTemplate() const;
virtual void Generate(Ir& ir, GenResult& result);
virtual FunctionCallPtr GetStaticConstructorCall() const { return staticCtorCall; }
virtual GenResult GenerateStaticConstructorCall(Ir& ir, GenFlags flags);
virtual bool HasThisVariable() const { return true; }
void SetBodySource(CompoundStatementPtr bodySource_) { bodySource = bodySource_; }
void SetMemberIndex(int memberIndex_) { memberIndex = memberIndex_; }
int GetMemberIndex() const { return memberIndex; }
virtual void Instantiate(TypeCheckContext& context);
CompoundStatementPtr BodySource() const { return bodySource; }
void SetInitializerSource(const InitializerList& initializerSource_);
const InitializerList& InitializerSource() const { return initializerSource; }
virtual InitializerList Initializers() const { return InitializerList(); }
private:
WeakClassTypePtr classType;
bool isConst;
int vtblIndex;
FunctionPtr baseClassMember;
FunctionPtrSet overrides;
FunctionCallPtr staticCtorCall;
CompoundStatementPtr bodySource;
InitializerList initializerSource;
int memberIndex;
};
typedef std::shared_ptr<MemberFunction> MemberFunctionPtr;
class Constructor: public MemberFunction
{
public:
Constructor(const std::string& name_, const Position& pos_, const ScopePtr& enclosingScope_, const ScopePtr& fileScope_,
Specifiers specifiers_, const ClassTypePtr& classType_);
virtual void Dispose();
virtual std::string ObjectKindStr() const { return "constructor"; }
virtual ObjectKind GetObjectKind() const { return ObjectKind::constructor; }
void SetContent(const InitializerList& initializers_, const ParameterList& parameters_, const CompoundStatementPtr& body_);
virtual ObjectPtr Clone(CloneContext& context) const;
virtual bool IsConstructor() const { return true; }
virtual bool IsClassConstructor() const { return true; }
virtual bool IsDefaultConstructor() const;
virtual void TypeCheckSignature(TypeCheckContext& context);
virtual void TypeCheckBody(TypeCheckContext& context);
ScopePtr InitializerScope() const { return initializerScope; }
void SetInitializerScope(const ScopePtr& initializerScope_) { initializerScope = initializerScope_; }
virtual std::string ShortDocName() const;
virtual std::string AliasOrShortTypeDocName() const;
virtual std::string SyntaxName() const;
virtual FunctionCallPtr GetStaticConstructorCall() const { return staticCtorCall; }
virtual GenResult GenerateStaticConstructorCall(Ir& ir, GenFlags flags);
virtual InitializerList Initializers() const { return initializers; }
void SetInitializers(const InitializerList& initializers_);
private:
InitializerPtr classInitializer;
InitializerList initializers;
void GenerateInitializationStatement(TypeCheckContext& context);
ScopePtr initializerScope;
FunctionCallPtr staticCtorCall;
};
typedef std::shared_ptr<Constructor> ConstructorPtr;
class StaticConstructor: public MemberFunction
{
public:
StaticConstructor(const std::string& name_, const Position& pos_, const ScopePtr& enclosingScope_, const ScopePtr& fileScope_,
Specifiers specifiers_, const ClassTypePtr& classType_);
virtual std::string ObjectKindStr() const { return "constructor"; }
virtual ObjectKind GetObjectKind() const { return ObjectKind::constructor; }
virtual void Dispose();
void SetContent(const InitializerList& initializers_, const CompoundStatementPtr& body_);
virtual ObjectPtr Clone(CloneContext& context) const;
virtual bool IsStaticConstructor() const { return true; }
virtual void TypeCheckSignature(TypeCheckContext& context);
virtual void TypeCheckBody(TypeCheckContext& context);
ScopePtr InitializerScope() const { return initializerScope; }
void SetInitializerScope(const ScopePtr& initializerScope_) { initializerScope = initializerScope_; }
virtual bool HasThisVariable() const { return false; }
virtual InitializerList Initializers() const { return initializers; }
void SetInitializers(const InitializerList& initializers_);
private:
InitializerPtr baseClassInitializer;
InitializerList initializers;
void GenerateInitializationStatement();
ScopePtr initializerScope;
};
typedef std::shared_ptr<StaticConstructor> StaticConstructorPtr;
class DestructorBase: public MemberFunction
{
public:
DestructorBase(const std::string& name_, const Position& pos_, const ScopePtr& enclosignScope_, const ScopePtr& fileScope_, Specifiers specifiers_, const ClassTypePtr& classType_);
virtual std::string ObjectKindStr() const { return "destructor"; }
virtual ObjectKind GetObjectKind() const { return ObjectKind::destructor; }
virtual bool IsDestructor() const { return true; }
virtual std::string ShortDocName() const;
virtual std::string AliasOrShortTypeDocName() const;
virtual std::string SyntaxName() const;
virtual bool HasThisVariable() const { return false; }
};
class Destructor: public DestructorBase
{
public:
Destructor(const std::string& name_, const Position& pos_, const ScopePtr& enclosignScope_, const ScopePtr& fileScope_,
Specifiers specifiers_, const ClassTypePtr& classType_);
void SetContent(const ParameterList& parameters_, const CompoundStatementPtr& body_);
void SetContent(const ParameterList& parameters_, const CompoundStatementPtr& body_, bool cloning);
virtual ObjectPtr Clone(CloneContext& context) const;
virtual void TypeCheckSignature(TypeCheckContext& context);
virtual void TypeCheckBody(TypeCheckContext& context);
virtual bool HasThisVariable() const { return true; }
};
typedef std::shared_ptr<Destructor> DestructorPtr;
} } // namespace Cm::Core
#endif // CM_CORE_MEMBERFUNCTION_INCLUDED