1 // =================================
  2 // Copyright (c) 2021 Seppo Laakko
  3 // Distributed under the MIT license
  4 // =================================
  5 
  6 #include <sngcm/ast/Node.hpp>
  7 #include <sngcm/ast/AstWriter.hpp>
  8 #include <sngcm/ast/AstReader.hpp>
  9 #include <sngcm/ast/BasicType.hpp>
 10 #include <sngcm/ast/Literal.hpp>
 11 #include <sngcm/ast/CompileUnit.hpp>
 12 #include <sngcm/ast/Identifier.hpp>
 13 #include <sngcm/ast/Typedef.hpp>
 14 #include <sngcm/ast/Constant.hpp>
 15 #include <sngcm/ast/Enumeration.hpp>
 16 #include <sngcm/ast/TypeExpr.hpp>
 17 #include <sngcm/ast/Expression.hpp>
 18 #include <sngcm/ast/Parameter.hpp>
 19 #include <sngcm/ast/Template.hpp>
 20 #include <sngcm/ast/Delegate.hpp>
 21 #include <sngcm/ast/Statement.hpp>
 22 #include <sngcm/ast/Function.hpp>
 23 #include <sngcm/ast/Class.hpp>
 24 #include <sngcm/ast/Interface.hpp>
 25 #include <sngcm/ast/Concept.hpp>
 26 #include <sngcm/ast/GlobalVariable.hpp>
 27 #include <sngcm/ast/Comment.hpp>
 28 #include <boost/uuid/nil_generator.hpp>
 29 #include <algorithm>
 30 
 31 namespace sngcm { namespace ast {
 32 
 33 const char* nodeTypeStr[] =
 34 {
 35     "boolNode""sbyteNode""byteNode""shortNode""ushortNode""intNode""uintNode""longNode""ulongNode""floatNode""doubleNode""charNode""wcharNode""ucharNode""voidNode"
 36     "booleanLiteralNode""sbyteLiteralNode""byteLiteralNode""shortLiteralNode""ushortLiteralNode""intLiteralNode""uintLiteralNode""longLiteralNode""ulongLiteralNode"
 37     "floatLiteralNode""doubleLiteralNode""charLiteralNode""wcharLiteralNode""ucharLiteralNode""stringLiteralNode""wstringLiteralNode""ustringLiteralNode""nullLiteralNode""arrayLiteralNode"
 38     "structuredLiteralNode"
 39     "compileUnitNode""namespaceNode""aliasNode""namespaceImportNode""identifierNode""templateIdNode""functionNode"
 40     "classNode""thisInitializerNode""baseInitializerNode""memberInitializerNode""staticConstructorNode""constructorNode""destructorNode""memberFunctionNode""conversionFunctionNode"
 41     "memberVariableNode"
 42     "interfaceNode""delegateNode""classDelegateNode"
 43     "parenthesizedConstraintNode""disjunctiveConstraintNode""conjunctiveConstraintNode""whereConstraintNode""predicateConstraintNode""isConstraintNode""multiParamConstraintNode""typeNameConstraintNode"
 44     "constructorConstraintNode""destructorConstraintNode""memberFunctionConstraintNode""functionConstraintNode"
 45     "sameConstraintNode""derivedConstraintNode""convertibleConstraintNode""explicitlyConvertibleConstraintNode""commonConstraintNode""nonreferenceTypeConstraintNode"
 46     "axiomStatementNode""axiomNode""conceptIdNode""conceptNode"
 47     "sameConceptNode""derivedConceptNode""convertibleConceptNode""ecxplicitlyConvertibleConceptNode""commonConceptNode""nonreferenceTypeConceptNode"
 48     "labelNode""compoundStatementNode""returnStatementNode""ifStatementNode""whileStatementNode""doStatementNode""forStatementNode""breakStatementNode""continueStatementNode"
 49     "gotoStatementNode""constructionStatementNode""deleteStatementNode""destroyStatementNode""assignmentStatementNode""expressionStatementNode""emptyStatementNode"
 50     "rangeForStatementNode""switchStatementNode""caseStatementNode""defaultStatementNode""gotoCaseStatementNode"
 51     "gotoDefaultStatementNode""throwStatementNode""catchNode""tryStatementNode""assertStatementNode"
 52     "typedefNode""constantNode""enumTypeNode""enumConstantNode""parameterNode""templateParameterNode"
 53     "constNode""refNode""arrayNode"
 54     "dotNode""arrowNode""equivalenceNode""implicationNode""disjunctionNode""conjunctionNode""bitOrNode""bitXorNode""bitAndNode""equalNode""notEqualNode""lessNode""greaterNode"
 55     "lessOrEqualNode""greaterOrEqualNode""shiftLeftNode""shiftRightNode"
 56     "addNode""subNode""mulNode""divNode""remNode""notNode""unaryPlusNode""unaryMinusNode""prefixIncrementNode""prefixDecrementNode""complementNode""derefNode""addrOfNode"
 57     "isNode""asNode""indexingNode""invokeNode""postfixIncrementNode""postfixDecrementNode""sizeOfNode""typeNameNode""typeIdNode""castNode""constructNode""newNode""thisNode""baseNode"
 58     "conditionalCompilationDisjunctionNode""conditionalCompilationConjunctionNode""conditionalCompilationNotNode""conditionalCompilationPrimaryNode""conditionalCompilationPartNode"
 59     "conditionalCompilationStatementNode""uuidLiteralNode""cursorIdNode""parenthesizedExpressionNode""globalVariableNode""parenthesizedCondCompExpressionNode""labeledStatementNode"
 60     "commentNode""functionPtrNode""syncNode""syncStatementNode""attributeNode""attributesNode""fullInstantiationRequestNode"
 61     "maxNode"
 62 };
 63 
 64 std::string NodeTypeStr(NodeType nodeType)
 65 {
 66     return nodeTypeStr[static_cast<size_t>(nodeType)];
 67 }
 68 
 69 Node::Node(NodeType nodeType_const Span& span_const boost::uuids::uuid& moduleId_) : nodeType(nodeType_)span(span_)moduleId(moduleId_)parent(nullptr)lexerFlags()
 70 {
 71 }
 72 
 73 Node::~Node()
 74 {
 75 }
 76 
 77 void Node::SetParent(Node* parent_)
 78 {
 79      parent = parent_;
 80 }
 81 
 82 void Node::Write(AstWriter& writer)
 83 {
 84 }
 85 
 86 void Node::Read(AstReader& reader)
 87 {
 88 }
 89 
 90 void Node::SetFullSpan()
 91 {
 92 }
 93 
 94 UnaryNode::UnaryNode(NodeType nodeType_const Span& span_const boost::uuids::uuid& moduleId_) : Node(nodeType_span_moduleId_)subject()
 95 {
 96 }
 97 
 98 UnaryNode::UnaryNode(NodeType nodeType_const Span& span_const boost::uuids::uuid& moduleId_Node* subject_) : Node(nodeType_span_moduleId_)subject(subject_)
 99 {
100 }
101 
102 void UnaryNode::Write(AstWriter& writer)
103 {
104     Node::Write(writer);
105     writer.Write(subject.get());
106 }
107 
108 void UnaryNode::Read(AstReader& reader)
109 {
110     Node::Read(reader);
111     subject.reset(reader.ReadNode());
112     subject->SetParent(this);
113 }
114 
115 void UnaryNode::SetFullSpan()
116 {
117     if (subject)
118     {
119         const Span& thisSpan = GetSpan();
120         subject->SetFullSpan();
121         const Span& childSpan = subject->GetSpan();
122         SetSpanStart(std::min(thisSpan.startchildSpan.start));
123         SetSpanEnd(std::max(thisSpan.endchildSpan.end));
124     }
125 }
126 
127 BinaryNode::BinaryNode(NodeType nodeTypeconst Span& span_const boost::uuids::uuid& moduleId_) : Node(nodeTypespan_moduleId_)left()right()
128 {
129 }
130 
131 BinaryNode::BinaryNode(NodeType nodeTypeconst Span& span_const boost::uuids::uuid& moduleId_Node* left_Node* right_) : Node(nodeTypespan_moduleId_)left(left_)right(right_)
132 {
133     left->SetParent(this);
134     right->SetParent(this);
135 }
136 
137 void BinaryNode::Write(AstWriter& writer)
138 {
139     Node::Write(writer);
140     writer.Write(left.get());
141     writer.Write(right.get());
142 }
143 
144 void BinaryNode::Read(AstReader& reader)
145 {
146     Node::Read(reader);
147     left.reset(reader.ReadNode());
148     left->SetParent(this);
149     right.reset(reader.ReadNode());
150     right->SetParent(this);
151 }
152 
153 void BinaryNode::SetFullSpan()
154 {
155     const Span& thisSpan = GetSpan();
156     left->SetFullSpan();
157     right->SetFullSpan();
158     const Span& leftSpan = left->GetSpan();
159     const Span& rightSpan = right->GetSpan();
160     SetSpanStart(std::min(thisSpan.startstd::min(leftSpan.startrightSpan.start)));
161     SetSpanEnd(std::max(thisSpan.endstd::max(leftSpan.endrightSpan.end)));
162 }
163 
164 NodeCreator::NodeCreator()
165 {
166 }
167 
168 NodeCreator::~NodeCreator()
169 {
170 }
171 
172 template<typename T>
173 class ConcreteNodeCreator public NodeCreator
174 {
175 public:
176     ConcreteNodeCreator() : NodeCreator() {}
177     ConcreteNodeCreator(const ConcreteNodeCreator&) = delete;
178     ConcreteNodeCreator& operator=(const ConcreteNodeCreator&) = delete;
179     Node* CreateNode(const Span& spanconst boost::uuids::uuid& moduleId) override
180     {
181         return new T(spanmoduleId);
182     }
183 };
184 
185 std::unique_ptr<NodeFactory> NodeFactory::instance;
186 
187 void NodeFactory::Init()
188 {
189     instance.reset(new NodeFactory());
190 }
191 
192 void NodeFactory::Done()
193 {
194     instance.reset();
195 }
196 
197 NodeFactory::NodeFactory()
198 {
199     creators.resize(static_cast<size_t>(NodeType::maxNode));
200 
201     Register(NodeType::boolNodenew ConcreteNodeCreator<BoolNode>());
202     Register(NodeType::sbyteNodenew ConcreteNodeCreator<SByteNode>());
203     Register(NodeType::byteNodenew ConcreteNodeCreator<ByteNode>());
204     Register(NodeType::shortNodenew ConcreteNodeCreator<ShortNode>());
205     Register(NodeType::ushortNodenew ConcreteNodeCreator<UShortNode>());
206     Register(NodeType::intNodenew ConcreteNodeCreator<IntNode>());
207     Register(NodeType::uintNodenew ConcreteNodeCreator<UIntNode>());
208     Register(NodeType::longNodenew ConcreteNodeCreator<LongNode>());
209     Register(NodeType::ulongNodenew ConcreteNodeCreator<ULongNode>());
210     Register(NodeType::floatNodenew ConcreteNodeCreator<FloatNode>());
211     Register(NodeType::doubleNodenew ConcreteNodeCreator<DoubleNode>());
212     Register(NodeType::charNodenew ConcreteNodeCreator<CharNode>());
213     Register(NodeType::wcharNodenew ConcreteNodeCreator<WCharNode>());
214     Register(NodeType::ucharNodenew ConcreteNodeCreator<UCharNode>());
215     Register(NodeType::voidNodenew ConcreteNodeCreator<VoidNode>());
216 
217     Register(NodeType::booleanLiteralNodenew ConcreteNodeCreator<BooleanLiteralNode>());
218     Register(NodeType::sbyteLiteralNodenew ConcreteNodeCreator<SByteLiteralNode>());
219     Register(NodeType::byteLiteralNodenew ConcreteNodeCreator<ByteLiteralNode>());
220     Register(NodeType::shortLiteralNodenew ConcreteNodeCreator<ShortLiteralNode>());
221     Register(NodeType::ushortLiteralNodenew ConcreteNodeCreator<UShortLiteralNode>());
222     Register(NodeType::intLiteralNodenew ConcreteNodeCreator<IntLiteralNode>());
223     Register(NodeType::uintLiteralNodenew ConcreteNodeCreator<UIntLiteralNode>());
224     Register(NodeType::longLiteralNodenew ConcreteNodeCreator<LongLiteralNode>());
225     Register(NodeType::ulongLiteralNodenew ConcreteNodeCreator<ULongLiteralNode>());
226     Register(NodeType::floatLiteralNodenew ConcreteNodeCreator<FloatLiteralNode>());
227     Register(NodeType::doubleLiteralNodenew ConcreteNodeCreator<DoubleLiteralNode>());
228     Register(NodeType::charLiteralNodenew ConcreteNodeCreator<CharLiteralNode>());
229     Register(NodeType::wcharLiteralNodenew ConcreteNodeCreator<WCharLiteralNode>());
230     Register(NodeType::ucharLiteralNodenew ConcreteNodeCreator<UCharLiteralNode>());
231     Register(NodeType::stringLiteralNodenew ConcreteNodeCreator<StringLiteralNode>());
232     Register(NodeType::wstringLiteralNodenew ConcreteNodeCreator<WStringLiteralNode>());
233     Register(NodeType::ustringLiteralNodenew ConcreteNodeCreator<UStringLiteralNode>());
234     Register(NodeType::nullLiteralNodenew ConcreteNodeCreator<NullLiteralNode>());
235     Register(NodeType::arrayLiteralNodenew ConcreteNodeCreator<ArrayLiteralNode>());
236     Register(NodeType::structuredLiteralNodenew ConcreteNodeCreator<StructuredLiteralNode>());
237 
238     Register(NodeType::compileUnitNodenew ConcreteNodeCreator<CompileUnitNode>());
239     Register(NodeType::namespaceNodenew ConcreteNodeCreator<NamespaceNode>());
240     Register(NodeType::aliasNodenew ConcreteNodeCreator<AliasNode>());
241     Register(NodeType::namespaceImportNodenew ConcreteNodeCreator<NamespaceImportNode>());
242     Register(NodeType::identifierNodenew ConcreteNodeCreator<IdentifierNode>());
243     Register(NodeType::templateIdNodenew ConcreteNodeCreator<TemplateIdNode>());
244     Register(NodeType::functionNodenew ConcreteNodeCreator<FunctionNode>());
245     Register(NodeType::classNodenew ConcreteNodeCreator<ClassNode>());
246     Register(NodeType::thisInitializerNodenew ConcreteNodeCreator<ThisInitializerNode>());
247     Register(NodeType::baseInitializerNodenew ConcreteNodeCreator<BaseInitializerNode>());
248     Register(NodeType::memberInitializerNodenew ConcreteNodeCreator<MemberInitializerNode>());
249     Register(NodeType::staticConstructorNodenew ConcreteNodeCreator<StaticConstructorNode>());
250     Register(NodeType::constructorNodenew ConcreteNodeCreator<ConstructorNode>());
251     Register(NodeType::destructorNodenew ConcreteNodeCreator<DestructorNode>());
252     Register(NodeType::memberFunctionNodenew ConcreteNodeCreator<MemberFunctionNode>());
253     Register(NodeType::conversionFunctionNodenew ConcreteNodeCreator<ConversionFunctionNode>());
254     Register(NodeType::memberVariableNodenew ConcreteNodeCreator<MemberVariableNode>());
255     Register(NodeType::interfaceNodenew ConcreteNodeCreator<InterfaceNode>());
256     Register(NodeType::delegateNodenew ConcreteNodeCreator<DelegateNode>());
257     Register(NodeType::classDelegateNodenew ConcreteNodeCreator<ClassDelegateNode>());
258 
259     Register(NodeType::parenthesizedConstraintNodenew ConcreteNodeCreator<ParenthesizedConstraintNode>());
260     Register(NodeType::disjunctiveConstraintNodenew ConcreteNodeCreator<DisjunctiveConstraintNode>());
261     Register(NodeType::conjunctiveConstraintNodenew ConcreteNodeCreator<ConjunctiveConstraintNode>());
262     Register(NodeType::whereConstraintNodenew ConcreteNodeCreator<WhereConstraintNode>());
263     Register(NodeType::predicateConstraintNodenew ConcreteNodeCreator<PredicateConstraintNode>());
264     Register(NodeType::isConstraintNodenew ConcreteNodeCreator<IsConstraintNode>());
265     Register(NodeType::multiParamConstraintNodenew ConcreteNodeCreator<MultiParamConstraintNode>());
266     Register(NodeType::typeNameConstraintNodenew ConcreteNodeCreator<TypeNameConstraintNode>());
267     Register(NodeType::constructorConstraintNodenew ConcreteNodeCreator<ConstructorConstraintNode>());
268     Register(NodeType::destructorConstraintNodenew ConcreteNodeCreator<DestructorConstraintNode>());
269     Register(NodeType::memberFunctionConstraintNodenew ConcreteNodeCreator<MemberFunctionConstraintNode>());
270     Register(NodeType::functionConstraintNodenew ConcreteNodeCreator<FunctionConstraintNode>());
271     Register(NodeType::sameConstraintNodenew ConcreteNodeCreator<SameConstraintNode>());
272     Register(NodeType::derivedConstraintNodenew ConcreteNodeCreator<DerivedConstraintNode>());
273     Register(NodeType::convertibleConstraintNodenew ConcreteNodeCreator<ConvertibleConstraintNode>());
274     Register(NodeType::explicitlyConvertibleConstraintNodenew ConcreteNodeCreator<ExplicitlyConvertibleConstraintNode>());
275     Register(NodeType::commonConstraintNodenew ConcreteNodeCreator<CommonConstraintNode>());
276     Register(NodeType::nonreferenceTypeConstraintNodenew ConcreteNodeCreator<NonreferenceTypeConstraintNode>());
277     Register(NodeType::axiomStatementNodenew ConcreteNodeCreator<AxiomStatementNode>());
278     Register(NodeType::axiomNodenew ConcreteNodeCreator<AxiomNode>());
279     Register(NodeType::conceptIdNodenew ConcreteNodeCreator<ConceptIdNode>());
280     Register(NodeType::conceptNodenew ConcreteNodeCreator<ConceptNode>());
281     Register(NodeType::sameConceptNodenew ConcreteNodeCreator<SameConceptNode>());
282     Register(NodeType::derivedConceptNodenew ConcreteNodeCreator<DerivedConceptNode>());
283     Register(NodeType::convertibleConceptNodenew ConcreteNodeCreator<ConvertibleConceptNode>());
284     Register(NodeType::explicitlyConvertibleConceptNodenew ConcreteNodeCreator<ExplicitlyConvertibleConceptNode>());
285     Register(NodeType::commonConceptNodenew ConcreteNodeCreator<CommonConceptNode>());
286     Register(NodeType::nonreferenceTypeConceptNodenew ConcreteNodeCreator<NonreferenceTypeConceptNode>());
287 
288     Register(NodeType::labelNodenew ConcreteNodeCreator<LabelNode>());
289     Register(NodeType::labeledStatementNodenew ConcreteNodeCreator<LabeledStatementNode>());
290     Register(NodeType::compoundStatementNodenew ConcreteNodeCreator<CompoundStatementNode>());
291     Register(NodeType::returnStatementNodenew ConcreteNodeCreator<ReturnStatementNode>());
292     Register(NodeType::ifStatementNodenew ConcreteNodeCreator<IfStatementNode>());
293     Register(NodeType::whileStatementNodenew ConcreteNodeCreator<WhileStatementNode>());
294     Register(NodeType::doStatementNodenew ConcreteNodeCreator<DoStatementNode>());
295     Register(NodeType::forStatementNodenew ConcreteNodeCreator<ForStatementNode>());
296     Register(NodeType::breakStatementNodenew ConcreteNodeCreator<BreakStatementNode>());
297     Register(NodeType::continueStatementNodenew ConcreteNodeCreator<ContinueStatementNode>());
298     Register(NodeType::gotoStatementNodenew ConcreteNodeCreator<GotoStatementNode>());
299     Register(NodeType::constructionStatementNodenew ConcreteNodeCreator<ConstructionStatementNode>());
300     Register(NodeType::deleteStatementNodenew ConcreteNodeCreator<DeleteStatementNode>());
301     Register(NodeType::destroyStatementNodenew ConcreteNodeCreator<DestroyStatementNode>());
302     Register(NodeType::assignmentStatementNodenew ConcreteNodeCreator<AssignmentStatementNode>());
303     Register(NodeType::expressionStatementNodenew ConcreteNodeCreator<ExpressionStatementNode>());
304     Register(NodeType::emptyStatementNodenew ConcreteNodeCreator<EmptyStatementNode>());
305     Register(NodeType::rangeForStatementNodenew ConcreteNodeCreator<RangeForStatementNode>());
306     Register(NodeType::switchStatementNodenew ConcreteNodeCreator<SwitchStatementNode>());
307     Register(NodeType::caseStatementNodenew ConcreteNodeCreator<CaseStatementNode>());
308     Register(NodeType::defaultStatementNodenew ConcreteNodeCreator<DefaultStatementNode>());
309     Register(NodeType::gotoCaseStatementNodenew ConcreteNodeCreator<GotoCaseStatementNode>());
310     Register(NodeType::gotoDefaultStatementNodenew ConcreteNodeCreator<GotoDefaultStatementNode>());
311     Register(NodeType::throwStatementNodenew ConcreteNodeCreator<ThrowStatementNode>());
312     Register(NodeType::catchNodenew ConcreteNodeCreator<CatchNode>());
313     Register(NodeType::tryStatementNodenew ConcreteNodeCreator<TryStatementNode>());
314     Register(NodeType::assertStatementNodenew ConcreteNodeCreator<AssertStatementNode>());
315 
316     Register(NodeType::typedefNodenew ConcreteNodeCreator<TypedefNode>());
317     Register(NodeType::constantNodenew ConcreteNodeCreator<ConstantNode>());
318     Register(NodeType::enumTypeNodenew ConcreteNodeCreator<EnumTypeNode>());
319     Register(NodeType::enumConstantNodenew ConcreteNodeCreator<EnumConstantNode>());
320     Register(NodeType::parameterNodenew ConcreteNodeCreator<ParameterNode>());
321     Register(NodeType::templateParameterNodenew ConcreteNodeCreator<TemplateParameterNode>());
322 
323     Register(NodeType::constNodenew ConcreteNodeCreator<ConstNode>());
324     Register(NodeType::lvalueRefNodenew ConcreteNodeCreator<LValueRefNode>());
325     Register(NodeType::rvalueRefNodenew ConcreteNodeCreator<RValueRefNode>());
326     Register(NodeType::pointerNodenew ConcreteNodeCreator<PointerNode>());
327     Register(NodeType::dotNodenew ConcreteNodeCreator<DotNode>());
328     Register(NodeType::arrowNodenew ConcreteNodeCreator<ArrowNode>());
329     Register(NodeType::arrayNodenew ConcreteNodeCreator<ArrayNode>());
330 
331     Register(NodeType::equivalenceNodenew ConcreteNodeCreator<EquivalenceNode>());
332     Register(NodeType::implicationNodenew ConcreteNodeCreator<ImplicationNode>());
333     Register(NodeType::disjunctionNodenew ConcreteNodeCreator<DisjunctionNode>());
334     Register(NodeType::conjunctionNodenew ConcreteNodeCreator<ConjunctionNode>());
335     Register(NodeType::bitOrNodenew ConcreteNodeCreator<BitOrNode>());
336     Register(NodeType::bitXorNodenew ConcreteNodeCreator<BitXorNode>());
337     Register(NodeType::bitAndNodenew ConcreteNodeCreator<BitAndNode>());
338     Register(NodeType::equalNodenew ConcreteNodeCreator<EqualNode>());
339     Register(NodeType::notEqualNodenew ConcreteNodeCreator<NotEqualNode>());
340     Register(NodeType::lessNodenew ConcreteNodeCreator<LessNode>());
341     Register(NodeType::greaterNodenew ConcreteNodeCreator<GreaterNode>());
342     Register(NodeType::lessOrEqualNodenew ConcreteNodeCreator<LessOrEqualNode>());
343     Register(NodeType::greaterOrEqualNodenew ConcreteNodeCreator<GreaterOrEqualNode>());
344     Register(NodeType::shiftLeftNodenew ConcreteNodeCreator<ShiftLeftNode>());
345     Register(NodeType::shiftRightNodenew ConcreteNodeCreator<ShiftRightNode>());
346     Register(NodeType::addNodenew ConcreteNodeCreator<AddNode>());
347     Register(NodeType::subNodenew ConcreteNodeCreator<SubNode>());
348     Register(NodeType::mulNodenew ConcreteNodeCreator<MulNode>());
349     Register(NodeType::divNodenew ConcreteNodeCreator<DivNode>());
350     Register(NodeType::remNodenew ConcreteNodeCreator<RemNode>());
351     Register(NodeType::notNodenew ConcreteNodeCreator<NotNode>());
352     Register(NodeType::unaryPlusNodenew ConcreteNodeCreator<UnaryPlusNode>());
353     Register(NodeType::unaryMinusNodenew ConcreteNodeCreator<UnaryMinusNode>());
354     Register(NodeType::prefixIncrementNodenew ConcreteNodeCreator<PrefixIncrementNode>());
355     Register(NodeType::prefixDecrementNodenew ConcreteNodeCreator<PrefixDecrementNode>());
356     Register(NodeType::complementNodenew ConcreteNodeCreator<ComplementNode>());
357     Register(NodeType::derefNodenew ConcreteNodeCreator<DerefNode>());
358     Register(NodeType::addrOfNodenew ConcreteNodeCreator<AddrOfNode>());
359     Register(NodeType::isNodenew ConcreteNodeCreator<IsNode>());
360     Register(NodeType::asNodenew ConcreteNodeCreator<AsNode>());
361     Register(NodeType::indexingNodenew ConcreteNodeCreator<IndexingNode>());
362     Register(NodeType::invokeNodenew ConcreteNodeCreator<InvokeNode>());
363     Register(NodeType::postfixIncrementNodenew ConcreteNodeCreator<PostfixIncrementNode>());
364     Register(NodeType::postfixDecrementNodenew ConcreteNodeCreator<PostfixDecrementNode>());
365     Register(NodeType::sizeOfNodenew ConcreteNodeCreator<SizeOfNode>());
366     Register(NodeType::typeNameNodenew ConcreteNodeCreator<TypeNameNode>());
367     Register(NodeType::typeIdNodenew ConcreteNodeCreator<TypeIdNode>());
368     Register(NodeType::castNodenew ConcreteNodeCreator<CastNode>());
369     Register(NodeType::constructNodenew ConcreteNodeCreator<ConstructNode>());
370     Register(NodeType::newNodenew ConcreteNodeCreator<NewNode>());
371     Register(NodeType::thisNodenew ConcreteNodeCreator<ThisNode>());
372     Register(NodeType::baseNodenew ConcreteNodeCreator<BaseNode>());
373     Register(NodeType::conditionalCompilationDisjunctionNodenew ConcreteNodeCreator<ConditionalCompilationDisjunctionNode>());
374     Register(NodeType::conditionalCompilationConjunctionNodenew ConcreteNodeCreator<ConditionalCompilationConjunctionNode>());
375     Register(NodeType::conditionalCompilationNotNodenew ConcreteNodeCreator<ConditionalCompilationNotNode>());
376     Register(NodeType::conditionalCompilationPrimaryNodenew ConcreteNodeCreator<ConditionalCompilationPrimaryNode>());
377     Register(NodeType::conditionalCompilationPartNodenew ConcreteNodeCreator<ConditionalCompilationPartNode>());
378     Register(NodeType::parenthesizedCondCompExpressionNodenew ConcreteNodeCreator<ParenthesizedConditionalCompilationExpressionNode>());
379     Register(NodeType::conditionalCompilationStatementNodenew ConcreteNodeCreator<ConditionalCompilationStatementNode>());
380     Register(NodeType::uuidLiteralNodenew ConcreteNodeCreator<UuidLiteralNode>());
381     Register(NodeType::cursorIdNodenew ConcreteNodeCreator<CursorIdNode>());
382     Register(NodeType::parenthesizedExpressionNodenew ConcreteNodeCreator<ParenthesizedExpressionNode>());
383     Register(NodeType::globalVariableNodenew ConcreteNodeCreator<GlobalVariableNode>());
384     Register(NodeType::commentNodenew ConcreteNodeCreator<CommentNode>());
385     Register(NodeType::functionPtrNodenew ConcreteNodeCreator<FunctionPtrNode>());
386     Register(NodeType::attributeNodenew ConcreteNodeCreator<AttributeNode>());
387     Register(NodeType::attributesNodenew ConcreteNodeCreator<AttributesNode>());
388     Register(NodeType::fullInstantiationRequestNodenew ConcreteNodeCreator<FullInstantiationRequestNode>());
389 }
390 
391 void NodeFactory::Register(NodeType nodeTypeNodeCreator* creator)
392 {
393     creators[static_cast<size_t>(nodeType)] = std::unique_ptr<NodeCreator>(creator);
394 }
395 
396 Node* NodeFactory::CreateNode(NodeType nodeTypeconst Span& spanconst boost::uuids::uuid& moduleId)
397 {
398     const std::std::unique_ptr<NodeCreator>&creator=creators[static_cast<size_t>(nodeType)];
399     if (creator)
400     {
401         Node* value = creator->CreateNode(spanmoduleId);
402         if (value)
403         {
404             return value;
405         }
406         else
407         {
408             throw std::runtime_error("could not create node");
409         }
410     }
411     else
412     {
413         throw std::runtime_error("no creator for node type '" + NodeTypeStr(nodeType) + "'");
414     }
415 }
416 
417 void NodeInit()
418 {
419     NodeFactory::Init();
420 }
421 
422 void NodeDone()
423 {
424     NodeFactory::Done();
425 }
426 
427 } } // namespace sngcm::ast