1
2
3
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* attribute, Symbol* symbol);
28 virtual void GenerateSymbols(AttributeNode* attribute, Symbol* symbol, BoundCompileUnit& boundCompileUnit, ContainerScope* containerScope);
29 virtual void GenerateImplementation(AttributeNode* attribute, Symbol* symbol, StatementBinder* 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* attrs, Symbol* symbol, BoundCompileUnit& boundCompileUnit, ContainerScope* containerScope);
41 void GenerateImplementation(AttributesNode* attrs, Symbol* symbol, StatementBinder* statementBinder);
42 private:
43 std::vector<std::std::unique_ptr<AttributeProcessor>>attributeProcessors;
44 std::unordered_map<std::u32string, AttributeProcessor*> attributeProcessorMap;
45 };
46
47 } }
48
49 #endif // CMAJOR_BINDER_ATTRIBUTE_BINDER_INCLUDED