1 // =================================
 2 // Copyright (c) 2020 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 #ifndef CPP2CM_CPP2CM_MAP_INCLUDED
 7 #define CPP2CM_CPP2CM_MAP_INCLUDED
 8 #include <cpp2cm/cpp2cm/Context.hpp>
 9 #include <sngcm/ast/Specifier.hpp>
10 #include <sngcm/ast/Node.hpp>
11 #include <sngcpp/ast/Specifier.hpp>
12 #include <sngcpp/symbols/SymbolTable.hpp>
13 #include <sngxml/dom/Document.hpp>
14 #include <string>
15 #include <unordered_map>
16 
17 namespace cpp2cm {
18 
19 std::u32string GetFullName(sngcm::ast::Node* node);
20 sngcm::ast::Node* MakeQualifiedIdNode(const std::u32string& fullName);
21 
22 class Map 
23 {
24 public:
25     Map();
26     void InitNameNodeTypeMap();
27     void InitSimpleTypeMap();
28     sngcm::ast::Node* CreateNode(const std::u32string& name);
29     sngcm::ast::Node* CreateNode(sngcm::ast::NodeType nodeType);
30     void MapNs(const std::u32string& sourceconst std::u32string& target);
31     std::u32string GetNs(const std::u32string& source) const;
32     void AddSourceXmlDoc(sngxml::dom::Document* sourceXmlDocconst std::u32string& projectName);
33     void SetSymbolTable(sngcpp::symbols::SymbolTable* symbolTable_);
34     sngcm::ast::NodeType MapSimpleType(sngcpp::ast::SimpleTypeSpecifierFlags flags);
35     sngcm::ast::NodeType MapSimpleType(sngcpp::symbols::SimpleTypeSymbol* simpleTypeSymbol);
36     sngcm::ast::Node* MakeDerivedType(sngcm::ast::Node* nodeconst std::std::vector<sngcpp::symbols::Derivation>&derivations);
37     sngcm::ast::IdentifierNode* MapFullTypeName(sngcpp::symbols::TypeSymbol* type);
38     sngcm::ast::Node* MapType(sngcpp::symbols::TypeSymbol* typesngxml::dom::Document*& sourceXmlDoc);
39     sngcm::ast::IdentifierNode* MapMemberSymbol(sngcpp::symbols::Symbol* memberSymbolstd::u32string& args);
40     sngcm::ast::IdentifierNode* MapFunctionSymbol(sngcpp::symbols::CallableSymbol* callableSymbolstd::u32string& args);
41     std::u32string RemoveNamespace(const std::u32string& qid);
42     void ClearNamespaceImports();
43     const std::std::set<std::u32string>&NamespaceImports() const{returnnamespaceImports;}
44     void SetCurrentContext(Context* context) { currentContext = context; }
45     void SetCurrentProjectName(const std::u32string& projectName) { currentProjectName = projectName; }
46     const std::u32string& CurrentProjectName() const { return currentProjectName; }
47 private:
48     std::unordered_map<std::u32stringstd::u32string> nsMap;
49     std::vector<sngxml::dom::Document*> sourceXmlDocs;
50     sngcpp::symbols::SymbolTable* symbolTable;
51     std::unordered_map<std::u32stringsngxml::dom::Document*> projectSourceXmlDocMap;
52     std::unordered_map<std::u32stringsngcm::ast::NodeType> nameNodeTypeMap;
53     std::unordered_map<sngcpp::ast::SimpleTypeSpecifierFlagssngcm::ast::NodeType> simpleTypeMap;
54     std::set<std::u32string> namespaceImports;
55     Context* currentContext;
56     std::u32string currentProjectName;
57 };
58 
59 sngcm::ast::Specifiers MapSpecifiers(sngcpp::ast::Specifier specifiers);
60 sngcm::ast::Specifiers MapAccess(sngcpp::symbols::SymbolAccess access);
61 
62 } // namespace cpp2cm
63 
64 #endif // CPP2CM_CPP2CM_MAP_INCLUDED