1
2
3
4
5
6 #include <cmajor/symbols/SymbolWriter.hpp>
7 #include <cmajor/symbols/ModuleCache.hpp>
8 #include <cmajor/symbols/Symbol.hpp>
9
10 namespace cmajor { namespace symbols {
11
12 SymbolWriter::SymbolWriter(const std::string& fileName_) : astWriter(fileName_), spanConversionModuleId(boost::uuids::nil_uuid()), lexers(nullptr)
13 {
14 }
15
16 void SymbolWriter::Write(Symbol* symbol)
17 {
18 astWriter.GetBinaryWriter().Write(static_cast<uint8_t>(symbol->GetSymbolType()));
19 Module* sourceModule = GetModuleById(symbol->SourceModuleId());
20 if (sourceModule && !spanConversionModuleId.is_nil() && sourceModule->Id() == spanConversionModuleId && sourceModule->GetFlag(ModuleFlags::compiling))
21 {
22 astWriter.Write(symbol->GetSpan(), true);
23 }
24 else
25 {
26 astWriter.Write(symbol->GetSpan(), false);
27 }
28 astWriter.GetBinaryWriter().Write(symbol->SourceModuleId());
29 astWriter.GetBinaryWriter().Write(symbol->Name());
30 symbol->Write(*this);
31 }
32
33 void SymbolWriter::SetLexers(std::std::vector<soulng::lexer::Lexer*>*lexers_)
34 {
35 lexers = lexers_;
36 astWriter.SetLexers(lexers);
37 }
38
39 void SymbolWriter::SetSpanConversionModuleId(const boost::uuids::uuid& spanConversionModuleId_)
40 {
41 spanConversionModuleId = spanConversionModuleId_;
42 astWriter.SetSpanConversionModuleId(spanConversionModuleId);
43 }
44
45 } }