1
2
3
4
5
6 #ifndef CMAJOR_BINDER_JSON_ATTRIBUTE_PROCESSOR_INCLUDED
7 #define CMAJOR_BINDER_JSON_ATTRIBUTE_PROCESSOR_INCLUDED
8 #include <cmajor/binder/AttributeBinder.hpp>
9 #include <cmajor/symbols/FunctionSymbol.hpp>
10 #include <cmajor/symbols/Module.hpp>
11 #include <map>
12
13 namespace cmajor { namespace binder {
14
15 using namespace cmajor::symbols;
16
17 class JsonAttributeProcessor : public AttributeProcessor
18 {
19 public:
20 JsonAttributeProcessor(Module* module_);
21 void TypeCheck(AttributeNode* attribute, Symbol* symbol) override;
22 void GenerateSymbols(AttributeNode* attribute, Symbol* symbol, BoundCompileUnit& boundCompileUnit, ContainerScope* containerScope) override;
23 void GenerateImplementation(AttributeNode* attribute, Symbol* symbol, StatementBinder* statementBinder) override;
24 private:
25 Module* module;
26 std::unordered_map<Symbol*, MemberFunctionSymbol*> jsonCreatorMap;
27 std::unordered_map<Symbol*, ConstructorSymbol*> jsonConstructorMap;
28 std::unordered_map<Symbol*, MemberFunctionSymbol*> toJsonJsonObjectMemberFunctionSymbolMap;
29 std::unordered_map<Symbol*, MemberFunctionSymbol*> toJsonObjectMemberFunctionSymbolMap;
30 void GenerateMemberVariableJsonFieldNames(ClassTypeSymbol* classTypeSymbol);
31 void CheckMemberVariableJsonFieldNames(ClassTypeSymbol* classTypeSymbol, std::std::map<std::u32string, AttributeNode*>&memberVariableFieldNames);
32 void GenerateJsonCreatorFunctionSymbol(AttributeNode* attribute, ClassTypeSymbol* classTypeSymbol);
33 void GenerateJsonConstructorSymbol(AttributeNode* attribute, ClassTypeSymbol* classTypeSymbol);
34 void GenerateToJsonJsonObjectSymbol(AttributeNode* attribute, ClassTypeSymbol* classTypeSymbol);
35 void GenerateToJsonSymbol(AttributeNode* attribute, ClassTypeSymbol* classTypeSymbol, BoundCompileUnit& boundCompileUnit, ContainerScope* containerScope);
36 void GenerateJsonConstructorImplementation(AttributeNode* attribute, ClassTypeSymbol* classTypeSymbol, ConstructorSymbol* jsonConstructorSymbol, StatementBinder* statementBinder);
37 void GenerateJsonCreatorImplementation(AttributeNode* attribute, ClassTypeSymbol* classTypeSymbol, MemberFunctionSymbol* jsonCreatorFunctionSymbol, StatementBinder* statementBinder);
38 void GenerateToJsonJsonObjectImplementation(AttributeNode* attribute, ClassTypeSymbol* classTypeSymbol, MemberFunctionSymbol* toJsonJsonObjectMemberFunctionSymbol, StatementBinder* statementBinder);
39 void GenerateToJsonImplementation(AttributeNode* attribute, ClassTypeSymbol* classTypeSymbol, MemberFunctionSymbol* toJsonMemberFunctionSymbol, StatementBinder* statementBinder);
40 };
41
42 class JsonFieldNameAttributeProcessor : public AttributeProcessor
43 {
44 public:
45 JsonFieldNameAttributeProcessor();
46 void TypeCheck(AttributeNode* attribute, Symbol* symbol) override;
47 };
48
49 } }
50
51 #endif // CMAJOR_BINDER_JSON_ATTRIBUTE_PROCESSOR_INCLUDED