1
2
3
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.start, childSpan.start));
123 SetSpanEnd(std::max(thisSpan.end, childSpan.end));
124 }
125 }
126
127 BinaryNode::BinaryNode(NodeType nodeType, const Span& span_, const boost::uuids::uuid& moduleId_) : Node(nodeType, span_, moduleId_), left(), right()
128 {
129 }
130
131 BinaryNode::BinaryNode(NodeType nodeType, const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_) : Node(nodeType, span_, 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.start, std::min(leftSpan.start, rightSpan.start)));
161 SetSpanEnd(std::max(thisSpan.end, std::max(leftSpan.end, rightSpan.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& span, const boost::uuids::uuid& moduleId) override
180 {
181 return new T(span, moduleId);
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::boolNode, new ConcreteNodeCreator<BoolNode>());
202 Register(NodeType::sbyteNode, new ConcreteNodeCreator<SByteNode>());
203 Register(NodeType::byteNode, new ConcreteNodeCreator<ByteNode>());
204 Register(NodeType::shortNode, new ConcreteNodeCreator<ShortNode>());
205 Register(NodeType::ushortNode, new ConcreteNodeCreator<UShortNode>());
206 Register(NodeType::intNode, new ConcreteNodeCreator<IntNode>());
207 Register(NodeType::uintNode, new ConcreteNodeCreator<UIntNode>());
208 Register(NodeType::longNode, new ConcreteNodeCreator<LongNode>());
209 Register(NodeType::ulongNode, new ConcreteNodeCreator<ULongNode>());
210 Register(NodeType::floatNode, new ConcreteNodeCreator<FloatNode>());
211 Register(NodeType::doubleNode, new ConcreteNodeCreator<DoubleNode>());
212 Register(NodeType::charNode, new ConcreteNodeCreator<CharNode>());
213 Register(NodeType::wcharNode, new ConcreteNodeCreator<WCharNode>());
214 Register(NodeType::ucharNode, new ConcreteNodeCreator<UCharNode>());
215 Register(NodeType::voidNode, new ConcreteNodeCreator<VoidNode>());
216
217 Register(NodeType::booleanLiteralNode, new ConcreteNodeCreator<BooleanLiteralNode>());
218 Register(NodeType::sbyteLiteralNode, new ConcreteNodeCreator<SByteLiteralNode>());
219 Register(NodeType::byteLiteralNode, new ConcreteNodeCreator<ByteLiteralNode>());
220 Register(NodeType::shortLiteralNode, new ConcreteNodeCreator<ShortLiteralNode>());
221 Register(NodeType::ushortLiteralNode, new ConcreteNodeCreator<UShortLiteralNode>());
222 Register(NodeType::intLiteralNode, new ConcreteNodeCreator<IntLiteralNode>());
223 Register(NodeType::uintLiteralNode, new ConcreteNodeCreator<UIntLiteralNode>());
224 Register(NodeType::longLiteralNode, new ConcreteNodeCreator<LongLiteralNode>());
225 Register(NodeType::ulongLiteralNode, new ConcreteNodeCreator<ULongLiteralNode>());
226 Register(NodeType::floatLiteralNode, new ConcreteNodeCreator<FloatLiteralNode>());
227 Register(NodeType::doubleLiteralNode, new ConcreteNodeCreator<DoubleLiteralNode>());
228 Register(NodeType::charLiteralNode, new ConcreteNodeCreator<CharLiteralNode>());
229 Register(NodeType::wcharLiteralNode, new ConcreteNodeCreator<WCharLiteralNode>());
230 Register(NodeType::ucharLiteralNode, new ConcreteNodeCreator<UCharLiteralNode>());
231 Register(NodeType::stringLiteralNode, new ConcreteNodeCreator<StringLiteralNode>());
232 Register(NodeType::wstringLiteralNode, new ConcreteNodeCreator<WStringLiteralNode>());
233 Register(NodeType::ustringLiteralNode, new ConcreteNodeCreator<UStringLiteralNode>());
234 Register(NodeType::nullLiteralNode, new ConcreteNodeCreator<NullLiteralNode>());
235 Register(NodeType::arrayLiteralNode, new ConcreteNodeCreator<ArrayLiteralNode>());
236 Register(NodeType::structuredLiteralNode, new ConcreteNodeCreator<StructuredLiteralNode>());
237
238 Register(NodeType::compileUnitNode, new ConcreteNodeCreator<CompileUnitNode>());
239 Register(NodeType::namespaceNode, new ConcreteNodeCreator<NamespaceNode>());
240 Register(NodeType::aliasNode, new ConcreteNodeCreator<AliasNode>());
241 Register(NodeType::namespaceImportNode, new ConcreteNodeCreator<NamespaceImportNode>());
242 Register(NodeType::identifierNode, new ConcreteNodeCreator<IdentifierNode>());
243 Register(NodeType::templateIdNode, new ConcreteNodeCreator<TemplateIdNode>());
244 Register(NodeType::functionNode, new ConcreteNodeCreator<FunctionNode>());
245 Register(NodeType::classNode, new ConcreteNodeCreator<ClassNode>());
246 Register(NodeType::thisInitializerNode, new ConcreteNodeCreator<ThisInitializerNode>());
247 Register(NodeType::baseInitializerNode, new ConcreteNodeCreator<BaseInitializerNode>());
248 Register(NodeType::memberInitializerNode, new ConcreteNodeCreator<MemberInitializerNode>());
249 Register(NodeType::staticConstructorNode, new ConcreteNodeCreator<StaticConstructorNode>());
250 Register(NodeType::constructorNode, new ConcreteNodeCreator<ConstructorNode>());
251 Register(NodeType::destructorNode, new ConcreteNodeCreator<DestructorNode>());
252 Register(NodeType::memberFunctionNode, new ConcreteNodeCreator<MemberFunctionNode>());
253 Register(NodeType::conversionFunctionNode, new ConcreteNodeCreator<ConversionFunctionNode>());
254 Register(NodeType::memberVariableNode, new ConcreteNodeCreator<MemberVariableNode>());
255 Register(NodeType::interfaceNode, new ConcreteNodeCreator<InterfaceNode>());
256 Register(NodeType::delegateNode, new ConcreteNodeCreator<DelegateNode>());
257 Register(NodeType::classDelegateNode, new ConcreteNodeCreator<ClassDelegateNode>());
258
259 Register(NodeType::parenthesizedConstraintNode, new ConcreteNodeCreator<ParenthesizedConstraintNode>());
260 Register(NodeType::disjunctiveConstraintNode, new ConcreteNodeCreator<DisjunctiveConstraintNode>());
261 Register(NodeType::conjunctiveConstraintNode, new ConcreteNodeCreator<ConjunctiveConstraintNode>());
262 Register(NodeType::whereConstraintNode, new ConcreteNodeCreator<WhereConstraintNode>());
263 Register(NodeType::predicateConstraintNode, new ConcreteNodeCreator<PredicateConstraintNode>());
264 Register(NodeType::isConstraintNode, new ConcreteNodeCreator<IsConstraintNode>());
265 Register(NodeType::multiParamConstraintNode, new ConcreteNodeCreator<MultiParamConstraintNode>());
266 Register(NodeType::typeNameConstraintNode, new ConcreteNodeCreator<TypeNameConstraintNode>());
267 Register(NodeType::constructorConstraintNode, new ConcreteNodeCreator<ConstructorConstraintNode>());
268 Register(NodeType::destructorConstraintNode, new ConcreteNodeCreator<DestructorConstraintNode>());
269 Register(NodeType::memberFunctionConstraintNode, new ConcreteNodeCreator<MemberFunctionConstraintNode>());
270 Register(NodeType::functionConstraintNode, new ConcreteNodeCreator<FunctionConstraintNode>());
271 Register(NodeType::sameConstraintNode, new ConcreteNodeCreator<SameConstraintNode>());
272 Register(NodeType::derivedConstraintNode, new ConcreteNodeCreator<DerivedConstraintNode>());
273 Register(NodeType::convertibleConstraintNode, new ConcreteNodeCreator<ConvertibleConstraintNode>());
274 Register(NodeType::explicitlyConvertibleConstraintNode, new ConcreteNodeCreator<ExplicitlyConvertibleConstraintNode>());
275 Register(NodeType::commonConstraintNode, new ConcreteNodeCreator<CommonConstraintNode>());
276 Register(NodeType::nonreferenceTypeConstraintNode, new ConcreteNodeCreator<NonreferenceTypeConstraintNode>());
277 Register(NodeType::axiomStatementNode, new ConcreteNodeCreator<AxiomStatementNode>());
278 Register(NodeType::axiomNode, new ConcreteNodeCreator<AxiomNode>());
279 Register(NodeType::conceptIdNode, new ConcreteNodeCreator<ConceptIdNode>());
280 Register(NodeType::conceptNode, new ConcreteNodeCreator<ConceptNode>());
281 Register(NodeType::sameConceptNode, new ConcreteNodeCreator<SameConceptNode>());
282 Register(NodeType::derivedConceptNode, new ConcreteNodeCreator<DerivedConceptNode>());
283 Register(NodeType::convertibleConceptNode, new ConcreteNodeCreator<ConvertibleConceptNode>());
284 Register(NodeType::explicitlyConvertibleConceptNode, new ConcreteNodeCreator<ExplicitlyConvertibleConceptNode>());
285 Register(NodeType::commonConceptNode, new ConcreteNodeCreator<CommonConceptNode>());
286 Register(NodeType::nonreferenceTypeConceptNode, new ConcreteNodeCreator<NonreferenceTypeConceptNode>());
287
288 Register(NodeType::labelNode, new ConcreteNodeCreator<LabelNode>());
289 Register(NodeType::labeledStatementNode, new ConcreteNodeCreator<LabeledStatementNode>());
290 Register(NodeType::compoundStatementNode, new ConcreteNodeCreator<CompoundStatementNode>());
291 Register(NodeType::returnStatementNode, new ConcreteNodeCreator<ReturnStatementNode>());
292 Register(NodeType::ifStatementNode, new ConcreteNodeCreator<IfStatementNode>());
293 Register(NodeType::whileStatementNode, new ConcreteNodeCreator<WhileStatementNode>());
294 Register(NodeType::doStatementNode, new ConcreteNodeCreator<DoStatementNode>());
295 Register(NodeType::forStatementNode, new ConcreteNodeCreator<ForStatementNode>());
296 Register(NodeType::breakStatementNode, new ConcreteNodeCreator<BreakStatementNode>());
297 Register(NodeType::continueStatementNode, new ConcreteNodeCreator<ContinueStatementNode>());
298 Register(NodeType::gotoStatementNode, new ConcreteNodeCreator<GotoStatementNode>());
299 Register(NodeType::constructionStatementNode, new ConcreteNodeCreator<ConstructionStatementNode>());
300 Register(NodeType::deleteStatementNode, new ConcreteNodeCreator<DeleteStatementNode>());
301 Register(NodeType::destroyStatementNode, new ConcreteNodeCreator<DestroyStatementNode>());
302 Register(NodeType::assignmentStatementNode, new ConcreteNodeCreator<AssignmentStatementNode>());
303 Register(NodeType::expressionStatementNode, new ConcreteNodeCreator<ExpressionStatementNode>());
304 Register(NodeType::emptyStatementNode, new ConcreteNodeCreator<EmptyStatementNode>());
305 Register(NodeType::rangeForStatementNode, new ConcreteNodeCreator<RangeForStatementNode>());
306 Register(NodeType::switchStatementNode, new ConcreteNodeCreator<SwitchStatementNode>());
307 Register(NodeType::caseStatementNode, new ConcreteNodeCreator<CaseStatementNode>());
308 Register(NodeType::defaultStatementNode, new ConcreteNodeCreator<DefaultStatementNode>());
309 Register(NodeType::gotoCaseStatementNode, new ConcreteNodeCreator<GotoCaseStatementNode>());
310 Register(NodeType::gotoDefaultStatementNode, new ConcreteNodeCreator<GotoDefaultStatementNode>());
311 Register(NodeType::throwStatementNode, new ConcreteNodeCreator<ThrowStatementNode>());
312 Register(NodeType::catchNode, new ConcreteNodeCreator<CatchNode>());
313 Register(NodeType::tryStatementNode, new ConcreteNodeCreator<TryStatementNode>());
314 Register(NodeType::assertStatementNode, new ConcreteNodeCreator<AssertStatementNode>());
315
316 Register(NodeType::typedefNode, new ConcreteNodeCreator<TypedefNode>());
317 Register(NodeType::constantNode, new ConcreteNodeCreator<ConstantNode>());
318 Register(NodeType::enumTypeNode, new ConcreteNodeCreator<EnumTypeNode>());
319 Register(NodeType::enumConstantNode, new ConcreteNodeCreator<EnumConstantNode>());
320 Register(NodeType::parameterNode, new ConcreteNodeCreator<ParameterNode>());
321 Register(NodeType::templateParameterNode, new ConcreteNodeCreator<TemplateParameterNode>());
322
323 Register(NodeType::constNode, new ConcreteNodeCreator<ConstNode>());
324 Register(NodeType::lvalueRefNode, new ConcreteNodeCreator<LValueRefNode>());
325 Register(NodeType::rvalueRefNode, new ConcreteNodeCreator<RValueRefNode>());
326 Register(NodeType::pointerNode, new ConcreteNodeCreator<PointerNode>());
327 Register(NodeType::dotNode, new ConcreteNodeCreator<DotNode>());
328 Register(NodeType::arrowNode, new ConcreteNodeCreator<ArrowNode>());
329 Register(NodeType::arrayNode, new ConcreteNodeCreator<ArrayNode>());
330
331 Register(NodeType::equivalenceNode, new ConcreteNodeCreator<EquivalenceNode>());
332 Register(NodeType::implicationNode, new ConcreteNodeCreator<ImplicationNode>());
333 Register(NodeType::disjunctionNode, new ConcreteNodeCreator<DisjunctionNode>());
334 Register(NodeType::conjunctionNode, new ConcreteNodeCreator<ConjunctionNode>());
335 Register(NodeType::bitOrNode, new ConcreteNodeCreator<BitOrNode>());
336 Register(NodeType::bitXorNode, new ConcreteNodeCreator<BitXorNode>());
337 Register(NodeType::bitAndNode, new ConcreteNodeCreator<BitAndNode>());
338 Register(NodeType::equalNode, new ConcreteNodeCreator<EqualNode>());
339 Register(NodeType::notEqualNode, new ConcreteNodeCreator<NotEqualNode>());
340 Register(NodeType::lessNode, new ConcreteNodeCreator<LessNode>());
341 Register(NodeType::greaterNode, new ConcreteNodeCreator<GreaterNode>());
342 Register(NodeType::lessOrEqualNode, new ConcreteNodeCreator<LessOrEqualNode>());
343 Register(NodeType::greaterOrEqualNode, new ConcreteNodeCreator<GreaterOrEqualNode>());
344 Register(NodeType::shiftLeftNode, new ConcreteNodeCreator<ShiftLeftNode>());
345 Register(NodeType::shiftRightNode, new ConcreteNodeCreator<ShiftRightNode>());
346 Register(NodeType::addNode, new ConcreteNodeCreator<AddNode>());
347 Register(NodeType::subNode, new ConcreteNodeCreator<SubNode>());
348 Register(NodeType::mulNode, new ConcreteNodeCreator<MulNode>());
349 Register(NodeType::divNode, new ConcreteNodeCreator<DivNode>());
350 Register(NodeType::remNode, new ConcreteNodeCreator<RemNode>());
351 Register(NodeType::notNode, new ConcreteNodeCreator<NotNode>());
352 Register(NodeType::unaryPlusNode, new ConcreteNodeCreator<UnaryPlusNode>());
353 Register(NodeType::unaryMinusNode, new ConcreteNodeCreator<UnaryMinusNode>());
354 Register(NodeType::prefixIncrementNode, new ConcreteNodeCreator<PrefixIncrementNode>());
355 Register(NodeType::prefixDecrementNode, new ConcreteNodeCreator<PrefixDecrementNode>());
356 Register(NodeType::complementNode, new ConcreteNodeCreator<ComplementNode>());
357 Register(NodeType::derefNode, new ConcreteNodeCreator<DerefNode>());
358 Register(NodeType::addrOfNode, new ConcreteNodeCreator<AddrOfNode>());
359 Register(NodeType::isNode, new ConcreteNodeCreator<IsNode>());
360 Register(NodeType::asNode, new ConcreteNodeCreator<AsNode>());
361 Register(NodeType::indexingNode, new ConcreteNodeCreator<IndexingNode>());
362 Register(NodeType::invokeNode, new ConcreteNodeCreator<InvokeNode>());
363 Register(NodeType::postfixIncrementNode, new ConcreteNodeCreator<PostfixIncrementNode>());
364 Register(NodeType::postfixDecrementNode, new ConcreteNodeCreator<PostfixDecrementNode>());
365 Register(NodeType::sizeOfNode, new ConcreteNodeCreator<SizeOfNode>());
366 Register(NodeType::typeNameNode, new ConcreteNodeCreator<TypeNameNode>());
367 Register(NodeType::typeIdNode, new ConcreteNodeCreator<TypeIdNode>());
368 Register(NodeType::castNode, new ConcreteNodeCreator<CastNode>());
369 Register(NodeType::constructNode, new ConcreteNodeCreator<ConstructNode>());
370 Register(NodeType::newNode, new ConcreteNodeCreator<NewNode>());
371 Register(NodeType::thisNode, new ConcreteNodeCreator<ThisNode>());
372 Register(NodeType::baseNode, new ConcreteNodeCreator<BaseNode>());
373 Register(NodeType::conditionalCompilationDisjunctionNode, new ConcreteNodeCreator<ConditionalCompilationDisjunctionNode>());
374 Register(NodeType::conditionalCompilationConjunctionNode, new ConcreteNodeCreator<ConditionalCompilationConjunctionNode>());
375 Register(NodeType::conditionalCompilationNotNode, new ConcreteNodeCreator<ConditionalCompilationNotNode>());
376 Register(NodeType::conditionalCompilationPrimaryNode, new ConcreteNodeCreator<ConditionalCompilationPrimaryNode>());
377 Register(NodeType::conditionalCompilationPartNode, new ConcreteNodeCreator<ConditionalCompilationPartNode>());
378 Register(NodeType::parenthesizedCondCompExpressionNode, new ConcreteNodeCreator<ParenthesizedConditionalCompilationExpressionNode>());
379 Register(NodeType::conditionalCompilationStatementNode, new ConcreteNodeCreator<ConditionalCompilationStatementNode>());
380 Register(NodeType::uuidLiteralNode, new ConcreteNodeCreator<UuidLiteralNode>());
381 Register(NodeType::cursorIdNode, new ConcreteNodeCreator<CursorIdNode>());
382 Register(NodeType::parenthesizedExpressionNode, new ConcreteNodeCreator<ParenthesizedExpressionNode>());
383 Register(NodeType::globalVariableNode, new ConcreteNodeCreator<GlobalVariableNode>());
384 Register(NodeType::commentNode, new ConcreteNodeCreator<CommentNode>());
385 Register(NodeType::functionPtrNode, new ConcreteNodeCreator<FunctionPtrNode>());
386 Register(NodeType::attributeNode, new ConcreteNodeCreator<AttributeNode>());
387 Register(NodeType::attributesNode, new ConcreteNodeCreator<AttributesNode>());
388 Register(NodeType::fullInstantiationRequestNode, new ConcreteNodeCreator<FullInstantiationRequestNode>());
389 }
390
391 void NodeFactory::Register(NodeType nodeType, NodeCreator* creator)
392 {
393 creators[static_cast<size_t>(nodeType)] = std::unique_ptr<NodeCreator>(creator);
394 }
395
396 Node* NodeFactory::CreateNode(NodeType nodeType, const Span& span, const 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(span, moduleId);
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 } }