1 // =================================
 2 // Copyright (c) 2021 Seppo Laakko
 3 // Distributed under the MIT license
 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* attributeSymbol* symbol) override;
22     void GenerateSymbols(AttributeNode* attributeSymbol* symbolBoundCompileUnit& boundCompileUnitContainerScope* containerScope) override;
23     void GenerateImplementation(AttributeNode* attributeSymbol* symbolStatementBinder* 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* classTypeSymbolstd::std::map<std::u32stringAttributeNode*>&memberVariableFieldNames);
32     void GenerateJsonCreatorFunctionSymbol(AttributeNode* attributeClassTypeSymbol* classTypeSymbol);
33     void GenerateJsonConstructorSymbol(AttributeNode* attributeClassTypeSymbol* classTypeSymbol);
34     void GenerateToJsonJsonObjectSymbol(AttributeNode* attributeClassTypeSymbol* classTypeSymbol);
35     void GenerateToJsonSymbol(AttributeNode* attributeClassTypeSymbol* classTypeSymbolBoundCompileUnit& boundCompileUnitContainerScope* containerScope);
36     void GenerateJsonConstructorImplementation(AttributeNode* attributeClassTypeSymbol* classTypeSymbolConstructorSymbol* jsonConstructorSymbolStatementBinder* statementBinder);
37     void GenerateJsonCreatorImplementation(AttributeNode* attributeClassTypeSymbol* classTypeSymbolMemberFunctionSymbol* jsonCreatorFunctionSymbolStatementBinder* statementBinder);
38     void GenerateToJsonJsonObjectImplementation(AttributeNode* attributeClassTypeSymbol* classTypeSymbolMemberFunctionSymbol* toJsonJsonObjectMemberFunctionSymbolStatementBinder* statementBinder);
39     void GenerateToJsonImplementation(AttributeNode* attributeClassTypeSymbol* classTypeSymbolMemberFunctionSymbol* toJsonMemberFunctionSymbolStatementBinder* statementBinder);
40 };
41 
42 class JsonFieldNameAttributeProcessor public AttributeProcessor
43 {
44 public:
45     JsonFieldNameAttributeProcessor();
46     void TypeCheck(AttributeNode* attributeSymbol* symbol) override;
47 };
48 
49 } } // namespace cmajor::binder
50 
51 #endif // CMAJOR_BINDER_JSON_ATTRIBUTE_PROCESSOR_INCLUDED