1
2
3
4
5
6 #include <cmajor/binder/BoundClass.hpp>
7 #include <cmajor/binder/BoundNodeVisitor.hpp>
8 #include <cmajor/binder/BoundFunction.hpp>
9 #include <cmajor/symbols/Exception.hpp>
10
11 namespace cmajor { namespace binder {
12
13 BoundClass::BoundClass(ClassTypeSymbol* classTypeSymbol_) :
14 BoundNode(classTypeSymbol_->GetSpan(), classTypeSymbol_->SourceModuleId(), BoundNodeType::boundClass), classTypeSymbol(classTypeSymbol_), inlineFunctionContainer(false)
15 {
16 }
17
18 void BoundClass::Accept(BoundNodeVisitor& visitor)
19 {
20 visitor.Visit(*this);
21 }
22
23 void BoundClass::Load(Emitter& emitter, OperationFlags flags)
24 {
25 throw Exception("cannot load from class", GetSpan(), ModuleId());
26 }
27
28 void BoundClass::Store(Emitter& emitter, OperationFlags flags)
29 {
30 throw Exception("cannot store to class", GetSpan(), ModuleId());
31 }
32
33 void BoundClass::AddMember(std::std::unique_ptr<BoundNode>&&member)
34 {
35 members.push_back(std::move(member));
36 }
37
38 bool BoundClass::ContainsSourceFunctions() const
39 {
40 for (const auto& member : members)
41 {
42 if (member->GetBoundNodeType() == BoundNodeType::boundFunction)
43 {
44 BoundFunction* boundFunction = static_cast<BoundFunction*>(member.get());
45 if (boundFunction->GetFunctionSymbol()->HasSource())
46 {
47 return true;
48 }
49 }
50 }
51 return false;
52 }
53
54 } }