1 // =================================
 2 // Copyright (c) 2021 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 #ifndef CMAJOR_BINDER_ATTRIBUTE_BINDER_INCLUDED
 7 #define CMAJOR_BINDER_ATTRIBUTE_BINDER_INCLUDED
 8 #include <cmajor/binder/BinderApi.hpp>
 9 #include <sngcm/ast/Attribute.hpp>
10 #include <cmajor/symbols/Symbol.hpp>
11 #include <unordered_map>
12 
13 namespace cmajor { namespace binder {
14 
15 using namespace sngcm::ast;
16 using namespace cmajor::symbols;
17 class BoundCompileUnit;
18 
19 class StatementBinder;
20 
21 class AttributeProcessor 
22 {
23 public:
24     AttributeProcessor(const std::u32string& attributeName_);
25     virtual ~AttributeProcessor();
26     const std::u32string& AttributeName() const { return attributeName; }
27     virtual void TypeCheck(AttributeNode* attributeSymbol* symbol);
28     virtual void GenerateSymbols(AttributeNode* attributeSymbol* symbolBoundCompileUnit& boundCompileUnitContainerScope* containerScope);
29     virtual void GenerateImplementation(AttributeNode* attributeSymbol* symbolStatementBinder* statementBinder);
30 private:
31     std::u32string attributeName;
32 };
33 
34 class AttributeBinder 
35 {
36 public:
37     AttributeBinder(Module* module);
38     AttributeBinder(const AttributeBinder&) = delete;
39     AttributeBinder& operator=(const AttributeBinder&) = delete;
40     void BindAttributes(AttributesNode* attrsSymbol* symbolBoundCompileUnit& boundCompileUnitContainerScope* containerScope);
41     void GenerateImplementation(AttributesNode* attrsSymbol* symbolStatementBinder* statementBinder);
42 private:
43     std::vector<std::std::unique_ptr<AttributeProcessor>>attributeProcessors;
44     std::unordered_map<std::u32stringAttributeProcessor*> attributeProcessorMap;
45 };
46 
47 } } // namespace cmajor::binder
48 
49 #endif // CMAJOR_BINDER_ATTRIBUTE_BINDER_INCLUDED