1 // =================================
 2 // Copyright (c) 2021 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 #ifndef CMAJOR_SYMBOLS_CONTAINER_SYMBOL_INCLUDED
 7 #define CMAJOR_SYMBOLS_CONTAINER_SYMBOL_INCLUDED
 8 #include <cmajor/symbols/Symbol.hpp>
 9 #include <cmajor/symbols/Scope.hpp>
10 
11 namespace cmajor { namespace symbols {
12 
13 class FunctionGroupSymbol;
14 class ConceptGroupSymbol;
15 class ClassGroupTypeSymbol;
16 class GlobalVariableGroupSymbol;
17 
18 class ContainerSymbol public Symbol
19 {
20 public:
21     ContainerSymbol(SymbolType symbolType_const Span& span_const boost::uuids::uuid& sourceModuleId_const std::u32string& name_);
22     void Write(SymbolWriter& writer) override;
23     void Read(SymbolReader& reader) override;
24     virtual void AddMember(Symbol* member);
25     void AddOwnedMember(Symbol* ownedMember);
26     std::unique_ptr<Symbol> RemoveMember(int symbolIndex) override;
27     void Accept(SymbolCollector* collector) override;
28     void Clear();
29     std::string TypeString() const override { return "container"; }
30     bool IsContainerSymbol() const override { return true; }
31     const ContainerScope* GetContainerScope() const override { return &containerScope; }
32     ContainerScope* GetContainerScope() override { return &containerScope; }
33     const std::std::vector<std::std::unique_ptr<Symbol>>&Members() const{returnmembers;}
34     std::std::vector<std::std::unique_ptr<Symbol>>&Members(){returnmembers;}
35     void AppendChildElements(sngxml::dom::Element* elementTypeMap& typeMap) const override;
36     bool HasProjectMembers() const override;
37     const char* ClassName() const override { return "ContainerSymbol"; }
38     void Check() override;
39     void CopyFrom(const Symbol* that) override;
40     FunctionSymbol* GetFunctionByIndex(int32_t functionIndex) const;
41     virtual bool IsImmutable() const { return false; }
42 private:
43     std::vector<std::std::unique_ptr<Symbol>>members;
44     ContainerScope containerScope;
45     std::unordered_map<int32_tFunctionSymbol*> functionIndexMap;
46     FunctionGroupSymbol* MakeFunctionGroupSymbol(const std::u32string& groupNameconst Span& spanconst boost::uuids::uuid& sourceModuleId);
47     ConceptGroupSymbol* MakeConceptGroupSymbol(const std::u32string& groupNameconst Span& spanconst boost::uuids::uuid& sourceModuleId);
48     ClassGroupTypeSymbol* MakeClassGroupTypeSymbol(const std::u32string& groupNameconst Span& spanconst boost::uuids::uuid& sourceModuleId);
49     GlobalVariableGroupSymbol* MakeGlobalVariableGroupSymbol(const std::u32string& groupNameconst Span& spanconst boost::uuids::uuid& sourceModuleId);
50 };
51 
52 class DeclarationBlock public ContainerSymbol
53 {
54 public:
55     DeclarationBlock(const Span& span_const boost::uuids::uuid& sourceModuleId_const std::u32string& name_);
56     void AddMember(Symbol* member) override;
57     const char* ClassName() const override { return "DeclarationBlock"; }
58 };
59 
60 } } // namespace cmajor::symbols
61 
62 #endif // CMAJOR_SYMBOLS_CONTAINER_SYMBOL_INCLUDED