1 // =================================
 2 // Copyright (c) 2021 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 #ifndef CMAJOR_SYMBOLS_SYMBOL_READER_INCLUDED
 7 #define CMAJOR_SYMBOLS_SYMBOL_READER_INCLUDED
 8 #include <cmajor/symbols/SymbolsApi.hpp>
 9 #include <sngcm/ast/AstReader.hpp>
10 #include <vector>
11 
12 namespace cmajor { namespace symbols {
13 
14 using namespace sngcm::ast;
15 
16 class Symbol;
17 class ArrayTypeSymbol;
18 class DerivedTypeSymbol;
19 class ClassTemplateSpecializationSymbol;
20 struct TypeOrConceptRequest;
21 struct FunctionRequest;
22 class SymbolTable;
23 class Module;
24 class FunctionSymbol;
25 class ClassTypeSymbol;
26 class ParameterSymbol;
27 
28 class SymbolReader 
29 {
30 public:
31     SymbolReader(const std::string& fileName_);
32     AstReader& GetAstReader() { return astReader; }
33     BinaryReader& GetBinaryReader() { return astReader.GetBinaryReader(); }
34     Symbol* ReadSymbol(Symbol* parent);
35     ArrayTypeSymbol* ReadArrayTypeSymbol(Symbol* parent);
36     DerivedTypeSymbol* ReadDerivedTypeSymbol(Symbol* parent);
37     ClassTemplateSpecializationSymbol* ReadClassTemplateSpecializationSymbol(Symbol* parent);
38     ParameterSymbol* ReadParameterSymbol(Symbol* parent);
39     void SetSymbolTable(SymbolTable* symbolTable_) { symbolTable = symbolTable_; }
40     SymbolTable* GetSymbolTable() const { return symbolTable; }
41     void SetModule(Module* module_) { module = module_; }
42     Module* GetModule() const { return module; }
43     void SetConversionsTarget(std::std::vector<FunctionSymbol*>*conversionsTarget){conversions = conversionsTarget;}
44     void SetArrayTypesTarget(std::std::vector<ArrayTypeSymbol*>*arrayTypesTarget){arrayTypes = arrayTypesTarget;}
45     void SetDerivedTypesTarget(std::std::vector<DerivedTypeSymbol*>*derivedTypesTarget){derivedTypes = derivedTypesTarget;}
46     void SetClassTemplateSpecializationTarget(std::std::vector<ClassTemplateSpecializationSymbol*>*classTemplateSpecializationTarget){classTemplateSpecializations = classTemplateSpecializationTarget;}
47     void SetTypeAndConceptRequestTarget(std::std::vector<TypeOrConceptRequest>*typeAndConceptRequestTarget){typeAndConceptRequests = typeAndConceptRequestTarget;}
48     void SetFunctionRequestTarget(std::std::vector<FunctionRequest>*functionRequestTarget){functionRequests = functionRequestTarget;}
49     void AddConversion(FunctionSymbol* conversion);
50     void AddArrayType(ArrayTypeSymbol* arrayType);
51     void AddDerivedType(DerivedTypeSymbol* derivedType);
52     void AddClassTemplateSpecialization(ClassTemplateSpecializationSymbol* classTemplateSpecialization);
53     void AddTypeOrConceptRequest(TypeOrConceptRequest&& typeOrConceptRequest);
54     void AddFunctionRequest(FunctionRequest&& functionRequest);
55     bool SetProjectBit() const { return setProjectBit; }
56     void SetProjectBitForSymbols() { setProjectBit = true; }
57     void SetRootModule(Module* rootModule_) { rootModule = rootModule_; }
58     Module* RootModuleId() const { return rootModule; }
59 private:
60     AstReader astReader;
61     SymbolTable* symbolTable;
62     Module* module;
63     Module* rootModule;
64     std::std::vector<FunctionSymbol*>*conversions;
65     std::std::vector<ArrayTypeSymbol*>*arrayTypes;
66     std::std::vector<DerivedTypeSymbol*>*derivedTypes;
67     std::std::vector<ClassTemplateSpecializationSymbol*>*classTemplateSpecializations;
68     std::std::vector<TypeOrConceptRequest>*typeAndConceptRequests;
69     std::std::vector<FunctionRequest>*functionRequests;
70     bool setProjectBit;
71     bool symbolsCached;
72 };
73 
74 } } // namespace cmajor::symbols
75 
76 #endif // CMAJOR_SYMBOLS_SYMBOL_READER_INCLUDED