1 // =================================
   2 // Copyright (c) 2021 Seppo Laakko
   3 // Distributed under the MIT license
   4 // =================================
   5 
   6 #include <sngcm/ast/Statement.hpp>
   7 #include <sngcm/ast/Identifier.hpp>
   8 #include <sngcm/ast/Visitor.hpp>
   9 
  10 namespace sngcm { namespace ast {
  11 
  12 LabelNode::LabelNode(const Span& span_const boost::uuids::uuid& moduleId_) : Node(NodeType::labelNodespan_moduleId_)
  13 {
  14 }
  15 
  16 LabelNode::LabelNode(const Span& span_const boost::uuids::uuid& moduleId_const std::u32string& label_) : Node(NodeType::labelNodespan_moduleId_)label(label_)
  17 {
  18 }
  19 
  20 Node* LabelNode::Clone(CloneContext& cloneContext) const
  21 {
  22     LabelNode* clone = new LabelNode(GetSpan()ModuleId()label);
  23     return clone;
  24 }
  25 
  26 void LabelNode::Accept(Visitor& visitor)
  27 {
  28     visitor.Visit(*this);
  29 }
  30 
  31 void LabelNode::Write(AstWriter& writer)
  32 {
  33     Node::Write(writer);
  34     writer.GetBinaryWriter().Write(label);
  35 }
  36 
  37 void LabelNode::Read(AstReader& reader)
  38 {
  39     Node::Read(reader);
  40     label = reader.GetBinaryReader().ReadUtf32String();
  41 }
  42 
  43 StatementNode::StatementNode(NodeType nodeType_const Span& span_const boost::uuids::uuid& moduleId_) : Node(nodeType_span_moduleId_)
  44 {
  45 }
  46 
  47 void StatementNode::Write(AstWriter& writer)
  48 {
  49     Node::Write(writer);
  50 }
  51 
  52 void StatementNode::Read(AstReader& reader)
  53 {
  54     Node::Read(reader);
  55 }
  56 
  57 LabeledStatementNode::LabeledStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) : StatementNode(NodeType::labeledStatementNodespan_moduleId_)
  58 {
  59 }
  60 
  61 LabeledStatementNode::LabeledStatementNode(const Span& span_const boost::uuids::uuid& moduleId_StatementNode* stmt_) :
  62     StatementNode(NodeType::labeledStatementNodespan_moduleId_)stmt(stmt_)
  63 {
  64     stmt->SetParent(this);
  65 }
  66 
  67 Node* LabeledStatementNode::Clone(CloneContext& cloneContext) const
  68 {
  69     LabeledStatementNode* clone = new LabeledStatementNode(GetSpan()ModuleId()static_cast<StatementNode*>(stmt->Clone(cloneContext)));
  70     clone->SetLabelNode(static_cast<LabelNode*>(labelNode->Clone(cloneContext)));
  71     return clone;
  72 }
  73 
  74 void LabeledStatementNode::Accept(Visitor& visitor)
  75 {
  76     visitor.Visit(*this);
  77 }
  78 
  79 void LabeledStatementNode::Write(AstWriter& writer)
  80 {
  81     StatementNode::Write(writer);
  82     writer.Write(labelNode.get());
  83     writer.Write(stmt.get());
  84 }
  85 
  86 void LabeledStatementNode::Read(AstReader& reader)
  87 {
  88     StatementNode::Read(reader);
  89     labelNode.reset(reader.ReadLabelNode());
  90     labelNode->SetParent(this);
  91     stmt.reset(reader.ReadStatementNode());
  92     stmt->SetParent(this);
  93 }
  94 
  95 void LabeledStatementNode::SetLabelNode(LabelNode* labelNode_)
  96 {
  97     labelNode.reset(labelNode_);
  98     labelNode->SetParent(this);
  99 }
 100 
 101 SyncStatementNode::SyncStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) : StatementNode(NodeType::syncStatementNodespan_moduleId_)
 102 {
 103 }
 104 
 105 Node* SyncStatementNode::Clone(CloneContext& cloneContext) const
 106 {
 107     return new SyncStatementNode(GetSpan()ModuleId());
 108 }
 109 
 110 void SyncStatementNode::Accept(Visitor& visitor)
 111 {
 112     visitor.Visit(*this);
 113 }
 114 
 115 CompoundStatementNode::CompoundStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 116     StatementNode(NodeType::compoundStatementNodespan_moduleId_)statements()beginBraceSpan()endBraceSpan()tracerInserted(false)
 117 {
 118 }
 119 
 120 Node* CompoundStatementNode::Clone(CloneContext& cloneContext) const
 121 {
 122     CompoundStatementNode* clone = new CompoundStatementNode(GetSpan()ModuleId());
 123     int n = statements.Count();
 124     for (int i = 0; i < n; ++i)
 125     {
 126         StatementNode* statement = statements[i];
 127         clone->AddStatement(static_cast<StatementNode*>(statement->Clone(cloneContext)));
 128     }
 129     clone->beginBraceSpan = beginBraceSpan;
 130     clone->endBraceSpan = endBraceSpan;
 131     return clone;
 132 }
 133 
 134 void CompoundStatementNode::Accept(Visitor& visitor)
 135 {
 136     visitor.Visit(*this);
 137 }
 138 
 139 void CompoundStatementNode::Write(AstWriter& writer)
 140 {
 141     StatementNode::Write(writer);
 142     statements.Write(writer);
 143     bool convertExternal = ModuleId() == writer.SpanConversionModuleId();
 144     writer.Write(beginBraceSpanconvertExternal);
 145     writer.Write(endBraceSpanconvertExternal);
 146 }
 147 
 148 void CompoundStatementNode::Read(AstReader& reader)
 149 {
 150     StatementNode::Read(reader);
 151     statements.Read(reader);
 152     statements.SetParent(this);
 153     beginBraceSpan = reader.ReadSpan();
 154     endBraceSpan = reader.ReadSpan();
 155 }
 156 
 157 void CompoundStatementNode::AddStatement(StatementNode* statement)
 158 {
 159     statement->SetParent(this);
 160     statements.Add(statement);
 161 }
 162 
 163 ReturnStatementNode::ReturnStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 164     StatementNode(NodeType::returnStatementNodespan_moduleId_)expression()
 165 {
 166 }
 167 
 168 ReturnStatementNode::ReturnStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* expression_) :
 169     StatementNode(NodeType::returnStatementNodespan_moduleId_)expression(expression_)
 170 {
 171     if (expression)
 172     {
 173         expression->SetParent(this);
 174     }
 175 }
 176 
 177 Node* ReturnStatementNode::Clone(CloneContext& cloneContext) const
 178 {
 179     Node* clonedExpression = nullptr;
 180     if (expression)
 181     {
 182         clonedExpression = expression->Clone(cloneContext);
 183     }
 184     ReturnStatementNode* clone = new ReturnStatementNode(GetSpan()ModuleId()clonedExpression);
 185     return clone;
 186 }
 187 
 188 void ReturnStatementNode::Accept(Visitor& visitor)
 189 {
 190     visitor.Visit(*this);
 191 }
 192 
 193 void ReturnStatementNode::Write(AstWriter& writer)
 194 {
 195     StatementNode::Write(writer);
 196     bool hasExpression = expression != nullptr;
 197     writer.GetBinaryWriter().Write(hasExpression);
 198     if (hasExpression)
 199     {
 200         writer.Write(expression.get());
 201     }
 202 }
 203 
 204 void ReturnStatementNode::Read(AstReader& reader)
 205 {
 206     StatementNode::Read(reader);
 207     bool hasExpression = reader.GetBinaryReader().ReadBool();
 208     if (hasExpression)
 209     {
 210         expression.reset(reader.ReadNode());
 211         expression->SetParent(this);
 212     }
 213 }
 214 
 215 IfStatementNode::IfStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 216     StatementNode(NodeType::ifStatementNodespan_moduleId_)condition()thenS()elseS()
 217 {
 218 }
 219 
 220 IfStatementNode::IfStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* condition_StatementNode* thenS_StatementNode* elseS_) :
 221     StatementNode(NodeType::ifStatementNodespan_moduleId_)condition(condition_)thenS(thenS_)elseS(elseS_)
 222 {
 223     condition->SetParent(this);
 224     thenS->SetParent(this);
 225     if (elseS)
 226     {
 227         elseS->SetParent(this);
 228     }
 229 }
 230 
 231 Node* IfStatementNode::Clone(CloneContext& cloneContext) const
 232 {
 233     StatementNode* clonedElseS = nullptr;
 234     if (elseS)
 235     {
 236         clonedElseS = static_cast<StatementNode*>(elseS->Clone(cloneContext));
 237     }
 238     IfStatementNode* clone = new IfStatementNode(GetSpan()ModuleId()condition->Clone(cloneContext)static_cast<StatementNode*>(thenS->Clone(cloneContext))clonedElseS);
 239     clone->SetLeftParenSpan(leftParenSpan);
 240     clone->SetRightParenSpan(rightParenSpan);
 241     clone->SetElseSpan(elseSpan);
 242     return clone;
 243 }
 244 
 245 void IfStatementNode::Accept(Visitor& visitor)
 246 {
 247     visitor.Visit(*this);
 248 }
 249 
 250 void IfStatementNode::Write(AstWriter& writer)
 251 {
 252     StatementNode::Write(writer);
 253     writer.Write(condition.get());
 254     writer.Write(thenS.get());
 255     bool hasElseS = elseS != nullptr;
 256     writer.GetBinaryWriter().Write(hasElseS);
 257     if (hasElseS)
 258     {
 259         writer.Write(elseS.get());
 260     }
 261     bool convertExternal = ModuleId() == writer.SpanConversionModuleId();
 262     writer.Write(leftParenSpanconvertExternal);
 263     writer.Write(rightParenSpanconvertExternal);
 264     writer.Write(elseSpanconvertExternal);
 265 }
 266 
 267 void IfStatementNode::Read(AstReader& reader)
 268 {
 269     StatementNode::Read(reader);
 270     condition.reset(reader.ReadNode());
 271     condition->SetParent(this);
 272     thenS.reset(reader.ReadStatementNode());
 273     thenS->SetParent(this);
 274     bool hasElseS = reader.GetBinaryReader().ReadBool();
 275     if (hasElseS)
 276     {
 277         elseS.reset(reader.ReadStatementNode());
 278         elseS->SetParent(this);
 279     }
 280     leftParenSpan = reader.ReadSpan();
 281     rightParenSpan = reader.ReadSpan();
 282     elseSpan = reader.ReadSpan();
 283 }
 284 
 285 WhileStatementNode::WhileStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 286     StatementNode(NodeType::whileStatementNodespan_moduleId_)condition()statement()
 287 {
 288 }
 289 
 290 WhileStatementNode::WhileStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* condition_StatementNode* statement_) :
 291     StatementNode(NodeType::whileStatementNodespan_moduleId_)condition(condition_)statement(statement_)
 292 {
 293     condition->SetParent(this);
 294     statement->SetParent(this);
 295 }
 296 
 297 Node* WhileStatementNode::Clone(CloneContext& cloneContext) const
 298 {
 299     WhileStatementNode* clone = new WhileStatementNode(GetSpan()ModuleId()condition->Clone(cloneContext)static_cast<StatementNode*>(statement->Clone(cloneContext)));
 300     clone->SetLeftParenSpan(leftParenSpan);
 301     clone->SetRightParenSpan(rightParenSpan);
 302     return clone;
 303 }
 304 
 305 void WhileStatementNode::Accept(Visitor& visitor)
 306 {
 307     visitor.Visit(*this);
 308 }
 309 
 310 void WhileStatementNode::Write(AstWriter& writer)
 311 {
 312     StatementNode::Write(writer);
 313     writer.Write(condition.get());
 314     writer.Write(statement.get());
 315     bool convertExternal = ModuleId() == writer.SpanConversionModuleId();
 316     writer.Write(leftParenSpanconvertExternal);
 317     writer.Write(rightParenSpanconvertExternal);
 318 }
 319 
 320 void WhileStatementNode::Read(AstReader& reader)
 321 {
 322     StatementNode::Read(reader);
 323     condition.reset(reader.ReadNode());
 324     condition->SetParent(this);
 325     statement.reset(reader.ReadStatementNode());
 326     statement->SetParent(this);
 327     leftParenSpan = reader.ReadSpan();
 328     rightParenSpan = reader.ReadSpan();
 329 }
 330 
 331 DoStatementNode::DoStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 332     StatementNode(NodeType::doStatementNodespan_moduleId_)statement()condition()
 333 {
 334 }
 335 
 336 DoStatementNode::DoStatementNode(const Span& span_const boost::uuids::uuid& moduleId_StatementNode* statement_Node* condition_) :
 337     StatementNode(NodeType::doStatementNodespan_moduleId_)statement(statement_)condition(condition_)
 338 {
 339     statement->SetParent(this);
 340     condition->SetParent(this);
 341 }
 342 
 343 Node* DoStatementNode::Clone(CloneContext& cloneContext) const
 344 {
 345     DoStatementNode* clone = new DoStatementNode(GetSpan()ModuleId()static_cast<StatementNode*>(statement->Clone(cloneContext))condition->Clone(cloneContext));
 346     clone->SetWhileSpan(whileSpan);
 347     clone->SetLeftParenSpan(leftParenSpan);
 348     clone->SetRightParenSpan(rightParenSpan);
 349     return clone;
 350 }
 351 
 352 void DoStatementNode::Accept(Visitor& visitor)
 353 {
 354     visitor.Visit(*this);
 355 }
 356 
 357 void DoStatementNode::Write(AstWriter& writer)
 358 {
 359     StatementNode::Write(writer);
 360     writer.Write(statement.get());
 361     writer.Write(condition.get());
 362     bool convertExternal = ModuleId() == writer.SpanConversionModuleId();
 363     writer.Write(whileSpanconvertExternal);
 364     writer.Write(leftParenSpanconvertExternal);
 365     writer.Write(rightParenSpanconvertExternal);
 366 }
 367 
 368 void DoStatementNode::Read(AstReader& reader)
 369 {
 370     StatementNode::Read(reader);
 371     statement.reset(reader.ReadStatementNode());
 372     statement->SetParent(this);
 373     condition.reset(reader.ReadNode());
 374     condition->SetParent(this);
 375     whileSpan = reader.ReadSpan();
 376     leftParenSpan = reader.ReadSpan();
 377     rightParenSpan = reader.ReadSpan();
 378 }
 379 
 380 ForStatementNode::ForStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 381     StatementNode(NodeType::forStatementNodespan_moduleId_)initS()condition()loopS()actionS()
 382 {
 383 }
 384 
 385 ForStatementNode::ForStatementNode(const Span& span_const boost::uuids::uuid& moduleId_StatementNode* initS_Node* condition_StatementNode* loopS_StatementNode* actionS_) :
 386     StatementNode(NodeType::forStatementNodespan_moduleId_)initS(initS_)condition(condition_)loopS(loopS_)actionS(actionS_)
 387 {
 388     initS->SetParent(this);
 389     if (condition)
 390     {
 391         condition->SetParent(this);
 392     }
 393     if (loopS)
 394     {
 395         loopS->SetParent(this);
 396     }
 397     if (actionS)
 398     {
 399         actionS->SetParent(this);
 400     }
 401 }
 402 
 403 Node* ForStatementNode::Clone(CloneContext& cloneContext) const
 404 {
 405     Node* clonedCondition = nullptr;
 406     if (condition)
 407     {
 408         clonedCondition = condition->Clone(cloneContext);
 409     }
 410     ForStatementNode* clone = new ForStatementNode(GetSpan()ModuleId()static_cast<StatementNode*>(initS->Clone(cloneContext))clonedConditionstatic_cast<StatementNode*>(loopS->Clone(cloneContext))
 411         static_cast<StatementNode*>(actionS->Clone(cloneContext)));
 412     clone->SetLeftParenSpan(leftParenSpan);
 413     clone->SetRightParenSpan(rightParenSpan);
 414     return clone;
 415 }
 416 
 417 void ForStatementNode::Accept(Visitor& visitor)
 418 {
 419     visitor.Visit(*this);
 420 }
 421 
 422 void ForStatementNode::Write(AstWriter& writer)
 423 {
 424     StatementNode::Write(writer);
 425     writer.Write(initS.get());
 426     bool hasCondition = condition != nullptr;
 427     writer.GetBinaryWriter().Write(hasCondition);
 428     if (hasCondition)
 429     {
 430         writer.Write(condition.get());
 431     }
 432     writer.Write(loopS.get());
 433     writer.Write(actionS.get());
 434     bool convertExternal = ModuleId() == writer.SpanConversionModuleId();
 435     writer.Write(leftParenSpanconvertExternal);
 436     writer.Write(rightParenSpanconvertExternal);
 437 }
 438 
 439 void ForStatementNode::Read(AstReader& reader)
 440 {
 441     StatementNode::Read(reader);
 442     initS.reset(reader.ReadStatementNode());
 443     initS->SetParent(this);
 444     bool hasCondition = reader.GetBinaryReader().ReadBool();
 445     if (hasCondition)
 446     {
 447         condition.reset(reader.ReadNode());
 448         condition->SetParent(this);
 449     }
 450     loopS.reset(reader.ReadStatementNode());
 451     loopS->SetParent(this);
 452     actionS.reset(reader.ReadStatementNode());
 453     actionS->SetParent(this);
 454     leftParenSpan = reader.ReadSpan();
 455     rightParenSpan = reader.ReadSpan();
 456 }
 457 
 458 BreakStatementNode::BreakStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) : StatementNode(NodeType::breakStatementNodespan_moduleId_)
 459 {
 460 }
 461 
 462 Node* BreakStatementNode::Clone(CloneContext& cloneContext) const
 463 {
 464     BreakStatementNode* clone = new BreakStatementNode(GetSpan()ModuleId());
 465     return clone;
 466 }
 467 
 468 void BreakStatementNode::Accept(Visitor& visitor)
 469 {
 470     visitor.Visit(*this);
 471 }
 472 
 473 ContinueStatementNode::ContinueStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) : StatementNode(NodeType::continueStatementNodespan_moduleId_)
 474 {
 475 }
 476 
 477 Node* ContinueStatementNode::Clone(CloneContext& cloneContext) const
 478 {
 479     ContinueStatementNode* clone = new ContinueStatementNode(GetSpan()ModuleId());
 480     return clone;
 481 }
 482 
 483 void ContinueStatementNode::Accept(Visitor& visitor)
 484 {
 485     visitor.Visit(*this);
 486 }
 487 
 488 GotoStatementNode::GotoStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 489     StatementNode(NodeType::gotoStatementNodespan_moduleId_)
 490 {
 491 }
 492 
 493 GotoStatementNode::GotoStatementNode(const Span& span_const boost::uuids::uuid& moduleId_const std::u32string& target_) :
 494     StatementNode(NodeType::gotoStatementNodespan_moduleId_)target(target_)
 495 {
 496 }
 497 
 498 Node* GotoStatementNode::Clone(CloneContext& cloneContext) const
 499 {
 500     GotoStatementNode* clone = new GotoStatementNode(GetSpan()ModuleId()target);
 501     return clone;
 502 }
 503 
 504 void GotoStatementNode::Accept(Visitor& visitor)
 505 {
 506     visitor.Visit(*this);
 507 }
 508 
 509 void GotoStatementNode::Write(AstWriter& writer)
 510 {
 511     StatementNode::Write(writer);
 512     writer.GetBinaryWriter().Write(target);
 513 }
 514 
 515 void GotoStatementNode::Read(AstReader& reader)
 516 {
 517     StatementNode::Read(reader);
 518     target = reader.GetBinaryReader().ReadUtf32String();
 519 }
 520 
 521 ConstructionStatementNode::ConstructionStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 522     StatementNode(NodeType::constructionStatementNodespan_moduleId_)typeExpr()id()arguments()assignment(false)empty(false)
 523 {
 524 }
 525 
 526 ConstructionStatementNode::ConstructionStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* typeExpr_IdentifierNode* id_) :
 527     StatementNode(NodeType::constructionStatementNodespan_moduleId_)typeExpr(typeExpr_)id(id_)arguments()assignment(false)empty(false)
 528 {
 529     typeExpr->SetParent(this);
 530     if (id)
 531     {
 532         id->SetParent(this);
 533     }
 534 }
 535 
 536 Node* ConstructionStatementNode::Clone(CloneContext& cloneContext) const
 537 {
 538     ConstructionStatementNode* clone = new ConstructionStatementNode(GetSpan()ModuleId()typeExpr->Clone(cloneContext)static_cast<IdentifierNode*>(id->Clone(cloneContext)));
 539     int n = arguments.Count();
 540     for (int i = 0; i < n; ++i)
 541     {
 542         clone->AddArgument(arguments[i]->Clone(cloneContext));
 543     }
 544     if (assignment) clone->SetAssignment();
 545     if (empty) clone->SetEmpty();
 546     return clone;
 547 }
 548 
 549 void ConstructionStatementNode::Accept(Visitor& visitor)
 550 {
 551     visitor.Visit(*this);
 552 }
 553 
 554 void ConstructionStatementNode::Write(AstWriter& writer)
 555 {
 556     StatementNode::Write(writer);
 557     writer.Write(typeExpr.get());
 558     writer.Write(id.get());
 559     arguments.Write(writer);
 560     writer.GetBinaryWriter().Write(assignment);
 561     writer.GetBinaryWriter().Write(empty);
 562 }
 563 
 564 void ConstructionStatementNode::Read(AstReader& reader)
 565 {
 566     StatementNode::Read(reader);
 567     typeExpr.reset(reader.ReadNode());
 568     typeExpr->SetParent(this);
 569     id.reset(reader.ReadIdentifierNode());
 570     id->SetParent(this);
 571     arguments.Read(reader);
 572     arguments.SetParent(this);
 573     assignment = reader.GetBinaryReader().ReadBool();
 574     empty = reader.GetBinaryReader().ReadBool();
 575 }
 576 
 577 void ConstructionStatementNode::AddArgument(Node* argument)
 578 {
 579     if (argument)
 580     {
 581         argument->SetParent(this);
 582         arguments.Add(argument);
 583     }
 584 }
 585 
 586 DeleteStatementNode::DeleteStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) : StatementNode(NodeType::deleteStatementNodespan_moduleId_)expression()
 587 {
 588 }
 589 
 590 DeleteStatementNode::DeleteStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* expression_) :
 591     StatementNode(NodeType::deleteStatementNodespan_moduleId_)expression(expression_)
 592 {
 593     expression->SetParent(this);
 594 }
 595 
 596 Node* DeleteStatementNode::Clone(CloneContext& cloneContext) const
 597 {
 598     DeleteStatementNode* clone = new DeleteStatementNode(GetSpan()ModuleId()expression->Clone(cloneContext));
 599     return clone;
 600 }
 601 
 602 void DeleteStatementNode::Accept(Visitor& visitor)
 603 {
 604     visitor.Visit(*this);
 605 }
 606 
 607 void DeleteStatementNode::Write(AstWriter& writer)
 608 {
 609     StatementNode::Write(writer);
 610     writer.Write(expression.get());
 611 }
 612 
 613 void DeleteStatementNode::Read(AstReader& reader)
 614 {
 615     StatementNode::Read(reader);
 616     expression.reset(reader.ReadNode());
 617     expression->SetParent(this);
 618 }
 619 
 620 DestroyStatementNode::DestroyStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 621     StatementNode(NodeType::destroyStatementNodespan_moduleId_)expression()
 622 {
 623 }
 624 
 625 DestroyStatementNode::DestroyStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* expression_) :
 626     StatementNode(NodeType::destroyStatementNodespan_moduleId_)expression(expression_)
 627 {
 628     expression->SetParent(this);
 629 }
 630 
 631 Node* DestroyStatementNode::Clone(CloneContext& cloneContext) const
 632 {
 633     DestroyStatementNode* clone = new DestroyStatementNode(GetSpan()ModuleId()expression->Clone(cloneContext));
 634     return clone;
 635 }
 636 
 637 void DestroyStatementNode::Accept(Visitor& visitor)
 638 {
 639     visitor.Visit(*this);
 640 }
 641 
 642 void DestroyStatementNode::Write(AstWriter& writer)
 643 {
 644     StatementNode::Write(writer);
 645     writer.Write(expression.get());
 646 }
 647 
 648 void DestroyStatementNode::Read(AstReader& reader)
 649 {
 650     StatementNode::Read(reader);
 651     expression.reset(reader.ReadNode());
 652     expression->SetParent(this);
 653 }
 654 
 655 AssignmentStatementNode::AssignmentStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 656     StatementNode(NodeType::assignmentStatementNodespan_moduleId_)targetExpr()sourceExpr()
 657 {
 658 }
 659 
 660 AssignmentStatementNode::AssignmentStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* targetExpr_Node* sourceExpr_) :
 661     StatementNode(NodeType::assignmentStatementNodespan_moduleId_)targetExpr(targetExpr_)sourceExpr(sourceExpr_)
 662 {
 663     targetExpr->SetParent(this);
 664     sourceExpr->SetParent(this);
 665 }
 666 
 667 Node* AssignmentStatementNode::Clone(CloneContext& cloneContext) const
 668 {
 669     AssignmentStatementNode* clone = new AssignmentStatementNode(GetSpan()ModuleId()targetExpr->Clone(cloneContext)sourceExpr->Clone(cloneContext));
 670     return clone;
 671 }
 672 
 673 void AssignmentStatementNode::Accept(Visitor& visitor)
 674 {
 675     visitor.Visit(*this);
 676 }
 677 
 678 void AssignmentStatementNode::Write(AstWriter& writer)
 679 {
 680     StatementNode::Write(writer);
 681     writer.Write(targetExpr.get());
 682     writer.Write(sourceExpr.get());
 683 }
 684 
 685 void AssignmentStatementNode::Read(AstReader& reader)
 686 {
 687     StatementNode::Read(reader);
 688     targetExpr.reset(reader.ReadNode());
 689     targetExpr->SetParent(this);
 690     sourceExpr.reset(reader.ReadNode());
 691     sourceExpr->SetParent(this);
 692 }
 693 
 694 ExpressionStatementNode::ExpressionStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 695     StatementNode(NodeType::expressionStatementNodespan_moduleId_)expression()
 696 {
 697 }
 698 
 699 ExpressionStatementNode::ExpressionStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* expression_) :
 700     StatementNode(NodeType::expressionStatementNodespan_moduleId_)expression(expression_)
 701 {
 702     expression->SetParent(this);
 703 }
 704 
 705 Node* ExpressionStatementNode::Clone(CloneContext& cloneContext) const
 706 {
 707     ExpressionStatementNode* clone = new ExpressionStatementNode(GetSpan()ModuleId()expression->Clone(cloneContext));
 708     return clone;
 709 }
 710 
 711 void ExpressionStatementNode::Accept(Visitor& visitor)
 712 {
 713     visitor.Visit(*this);
 714 }
 715 
 716 void ExpressionStatementNode::Write(AstWriter& writer)
 717 {
 718     StatementNode::Write(writer);
 719     writer.Write(expression.get());
 720 }
 721 
 722 void ExpressionStatementNode::Read(AstReader& reader)
 723 {
 724     StatementNode::Read(reader);
 725     expression.reset(reader.ReadNode());
 726     expression->SetParent(this);
 727 }
 728 
 729 EmptyStatementNode::EmptyStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) : StatementNode(NodeType::emptyStatementNodespan_moduleId_)
 730 {
 731 }
 732 
 733 Node* EmptyStatementNode::Clone(CloneContext& cloneContext) const
 734 {
 735     EmptyStatementNode* clone = new EmptyStatementNode(GetSpan()ModuleId());
 736     return clone;
 737 }
 738 
 739 void EmptyStatementNode::Accept(Visitor& visitor)
 740 {
 741     visitor.Visit(*this);
 742 }
 743 
 744 RangeForStatementNode::RangeForStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 745     StatementNode(NodeType::rangeForStatementNodespan_moduleId_)typeExpr()id()container()action()
 746 {
 747 }
 748 
 749 RangeForStatementNode::RangeForStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* typeExpr_IdentifierNode* id_Node* container_StatementNode* action_) :
 750     StatementNode(NodeType::rangeForStatementNodespan_moduleId_)typeExpr(typeExpr_)id(id_)container(container_)action(action_)
 751 {
 752     typeExpr->SetParent(this);
 753     id->SetParent(this);
 754     container->SetParent(this);
 755     action->SetParent(this);
 756 }
 757 
 758 Node* RangeForStatementNode::Clone(CloneContext& cloneContext) const
 759 {
 760     RangeForStatementNode* clone = new RangeForStatementNode(GetSpan()ModuleId()typeExpr->Clone(cloneContext)static_cast<IdentifierNode*>(id->Clone(cloneContext))container->Clone(cloneContext)
 761         static_cast<StatementNode*>(action->Clone(cloneContext)));
 762     clone->SetLeftParenSpan(leftParenSpan);
 763     clone->SetRightParenSpan(rightParenSpan);
 764     clone->SetColonSpan(colonSpan);
 765     return clone;
 766 }
 767 
 768 void RangeForStatementNode::Accept(Visitor& visitor)
 769 {
 770     visitor.Visit(*this);
 771 }
 772 
 773 void RangeForStatementNode::Write(AstWriter& writer)
 774 {
 775     StatementNode::Write(writer);
 776     writer.Write(typeExpr.get());
 777     writer.Write(id.get());
 778     writer.Write(container.get());
 779     writer.Write(action.get());
 780     bool convertExternal = ModuleId() == writer.SpanConversionModuleId();
 781     writer.Write(leftParenSpanconvertExternal);
 782     writer.Write(rightParenSpanconvertExternal);
 783     writer.Write(colonSpanconvertExternal);
 784 }
 785 
 786 void RangeForStatementNode::Read(AstReader& reader)
 787 {
 788     StatementNode::Read(reader);
 789     typeExpr.reset(reader.ReadNode());
 790     typeExpr->SetParent(this);
 791     id.reset(reader.ReadIdentifierNode());
 792     id->SetParent(this);
 793     container.reset(reader.ReadNode());
 794     container->SetParent(this);
 795     action.reset(reader.ReadStatementNode());
 796     action->SetParent(this);
 797     leftParenSpan = reader.ReadSpan();
 798     rightParenSpan = reader.ReadSpan();
 799     colonSpan = reader.ReadSpan();
 800 }
 801 
 802 SwitchStatementNode::SwitchStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 803     StatementNode(NodeType::switchStatementNodespan_moduleId_)condition()cases()defaultS()
 804 {
 805 }
 806 
 807 SwitchStatementNode::SwitchStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* condition_) :
 808     StatementNode(NodeType::switchStatementNodespan_moduleId_)condition(condition_)cases()defaultS()
 809 {
 810     condition->SetParent(this);
 811 }
 812 
 813 Node* SwitchStatementNode::Clone(CloneContext& cloneContext) const
 814 {
 815     SwitchStatementNode* clone = new SwitchStatementNode(GetSpan()ModuleId()condition->Clone(cloneContext));
 816     int n = cases.Count();
 817     for (int i = 0; i < n; ++i)
 818     {
 819         clone->AddCase(static_cast<CaseStatementNode*>(cases[i]->Clone(cloneContext)));
 820     }
 821     if (defaultS)
 822     {
 823         clone->SetDefault(static_cast<DefaultStatementNode*>(defaultS->Clone(cloneContext)));
 824     }
 825     clone->SetLeftParenSpan(leftParenSpan);
 826     clone->SetRightParenSpan(rightParenSpan);
 827     clone->SetBeginBraceSpan(beginBraceSpan);
 828     clone->SetEndBraceSpan(endBraceSpan);
 829     return clone;
 830 }
 831 
 832 void SwitchStatementNode::Accept(Visitor& visitor)
 833 {
 834     visitor.Visit(*this);
 835 }
 836 
 837 void SwitchStatementNode::Write(AstWriter& writer)
 838 {
 839     StatementNode::Write(writer);
 840     writer.Write(condition.get());
 841     cases.Write(writer);
 842     bool hasDefault = defaultS != nullptr;
 843     writer.GetBinaryWriter().Write(hasDefault);
 844     if (hasDefault)
 845     {
 846         writer.Write(defaultS.get());
 847     }
 848     bool convertExternal = ModuleId() == writer.SpanConversionModuleId();
 849     writer.Write(leftParenSpanconvertExternal);
 850     writer.Write(rightParenSpanconvertExternal);
 851     writer.Write(beginBraceSpanconvertExternal);
 852     writer.Write(endBraceSpanconvertExternal);
 853 }
 854 
 855 void SwitchStatementNode::Read(AstReader& reader)
 856 {
 857     StatementNode::Read(reader);
 858     condition.reset(reader.ReadNode());
 859     condition->SetParent(this);
 860     cases.Read(reader);
 861     cases.SetParent(this);
 862     bool hasDefault = reader.GetBinaryReader().ReadBool();
 863     if (hasDefault)
 864     {
 865         defaultS.reset(reader.ReadDefaultStatementNode());
 866         defaultS->SetParent(this);
 867     }
 868     leftParenSpan = reader.ReadSpan();
 869     rightParenSpan = reader.ReadSpan();
 870     beginBraceSpan = reader.ReadSpan();
 871     endBraceSpan = reader.ReadSpan();
 872 }
 873 
 874 void SwitchStatementNode::AddCase(CaseStatementNode* caseS)
 875 {
 876     caseS->SetParent(this);
 877     cases.Add(caseS);
 878 }
 879 
 880 void SwitchStatementNode::SetDefault(DefaultStatementNode* defaultS_)
 881 {
 882     defaultS.reset(defaultS_);
 883     defaultS->SetParent(this);
 884 }
 885 
 886 CaseStatementNode::CaseStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 887     StatementNode(NodeType::caseStatementNodespan_moduleId_)caseExprs()statements()
 888 {
 889 }
 890 
 891 Node* CaseStatementNode::Clone(CloneContext& cloneContext) const
 892 {
 893     CaseStatementNode* clone = new CaseStatementNode(GetSpan()ModuleId());
 894     int ne = caseExprs.Count();
 895     for (int i = 0; i < ne; ++i)
 896     {
 897         clone->AddCaseExpr(caseExprs[i]->Clone(cloneContext));
 898     }
 899     int ns = statements.Count();
 900     for (int i = 0; i < ns; ++i)
 901     {
 902         clone->AddStatement(static_cast<StatementNode*>(statements[i]->Clone(cloneContext)));
 903     }
 904     clone->caseSpans = caseSpans;
 905     return clone;
 906 }
 907 
 908 void CaseStatementNode::Accept(Visitor& visitor)
 909 {
 910     visitor.Visit(*this);
 911 }
 912 
 913 void CaseStatementNode::Write(AstWriter& writer)
 914 {
 915     StatementNode::Write(writer);
 916     caseExprs.Write(writer);
 917     statements.Write(writer);
 918     uint32_t n = static_cast<uint32_t>(caseSpans.size());
 919     writer.GetBinaryWriter().WriteULEB128UInt(n);
 920     bool convertExternal = ModuleId() == writer.SpanConversionModuleId();
 921     for (uint32_t i = 0u; i < n; ++i)
 922     {
 923         writer.Write(caseSpans[i]convertExternal);
 924     }
 925 }
 926 
 927 void CaseStatementNode::Read(AstReader& reader)
 928 {
 929     StatementNode::Read(reader);
 930     caseExprs.Read(reader);
 931     caseExprs.SetParent(this);
 932     statements.Read(reader);
 933     statements.SetParent(this);
 934     uint32_t n = reader.GetBinaryReader().ReadULEB128UInt();
 935     for (uint32_t i = 0u; i < n; ++i)
 936     {
 937         caseSpans.push_back(reader.ReadSpan());
 938     }
 939 }
 940 
 941 void CaseStatementNode::AddCaseExpr(Node* caseExpr)
 942 {
 943     caseExpr->SetParent(this);
 944     caseExprs.Add(caseExpr);
 945 }
 946 
 947 void CaseStatementNode::AddCaseSpan(const Span& caseSpan)
 948 {
 949     caseSpans.push_back(caseSpan);
 950 }
 951 
 952 void CaseStatementNode::AddStatement(StatementNode* statement)
 953 {
 954     statement->SetParent(this);
 955     statements.Add(statement);
 956 }
 957 
 958 DefaultStatementNode::DefaultStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) : StatementNode(NodeType::defaultStatementNodespan_moduleId_)statements()
 959 {
 960 }
 961 
 962 Node* DefaultStatementNode::Clone(CloneContext& cloneContext) const
 963 {
 964     DefaultStatementNode* clone = new DefaultStatementNode(GetSpan()ModuleId());
 965     int n = statements.Count();
 966     for (int i = 0; i < n; ++i)
 967     {
 968         clone->AddStatement(static_cast<StatementNode*>(statements[i]->Clone(cloneContext)));
 969     }
 970     return clone;
 971 }
 972 
 973 void DefaultStatementNode::Accept(Visitor& visitor)
 974 {
 975     visitor.Visit(*this);
 976 }
 977 
 978 void DefaultStatementNode::Write(AstWriter& writer)
 979 {
 980     StatementNode::Write(writer);
 981     statements.Write(writer);
 982 }
 983 
 984 void DefaultStatementNode::Read(AstReader& reader)
 985 {
 986     StatementNode::Read(reader);
 987     statements.Read(reader);
 988     statements.SetParent(this);
 989 }
 990 
 991 void DefaultStatementNode::AddStatement(StatementNode* statement)
 992 {
 993     statement->SetParent(this);
 994     statements.Add(statement);
 995 }
 996 
 997 GotoCaseStatementNode::GotoCaseStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
 998     StatementNode(NodeType::gotoCaseStatementNodespan_moduleId_)caseExpr()
 999 {
1000 }
1001 
1002 GotoCaseStatementNode::GotoCaseStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* caseExpr_) :
1003     StatementNode(NodeType::gotoCaseStatementNodespan_moduleId_)caseExpr(caseExpr_)
1004 {
1005     caseExpr->SetParent(this);
1006 }
1007 
1008 Node* GotoCaseStatementNode::Clone(CloneContext& cloneContext) const
1009 {
1010     GotoCaseStatementNode* clone = new GotoCaseStatementNode(GetSpan()ModuleId()caseExpr->Clone(cloneContext));
1011     return clone;
1012 }
1013 
1014 void GotoCaseStatementNode::Accept(Visitor& visitor)
1015 {
1016     visitor.Visit(*this);
1017 }
1018 
1019 void GotoCaseStatementNode::Write(AstWriter& writer)
1020 {
1021     StatementNode::Write(writer);
1022     writer.Write(caseExpr.get());
1023 }
1024 
1025 void GotoCaseStatementNode::Read(AstReader& reader)
1026 {
1027     StatementNode::Read(reader);
1028     caseExpr.reset(reader.ReadNode());
1029 }
1030 
1031 GotoDefaultStatementNode::GotoDefaultStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) : StatementNode(NodeType::gotoDefaultStatementNodespan_moduleId_)
1032 {
1033 }
1034 
1035 Node* GotoDefaultStatementNode::Clone(CloneContext& cloneContext) const
1036 {
1037     GotoDefaultStatementNode* clone = new GotoDefaultStatementNode(GetSpan()ModuleId());
1038     return clone;
1039 }
1040 
1041 void GotoDefaultStatementNode::Accept(Visitor& visitor)
1042 {
1043     visitor.Visit(*this);
1044 }
1045 
1046 ThrowStatementNode::ThrowStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
1047     StatementNode(NodeType::throwStatementNodespan_moduleId_)expression()
1048 {
1049 }
1050 
1051 ThrowStatementNode::ThrowStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* expression_) :
1052     StatementNode(NodeType::throwStatementNodespan_moduleId_)expression(expression_)
1053 {
1054     if (expression)
1055     {
1056         expression->SetParent(this);
1057     }
1058 }
1059 
1060 Node* ThrowStatementNode::Clone(CloneContext& cloneContext) const
1061 {
1062     Node* clonedExpression = nullptr;
1063     if (expression)
1064     {
1065         clonedExpression = expression->Clone(cloneContext);
1066     }
1067     ThrowStatementNode* clone = new ThrowStatementNode(GetSpan()ModuleId()clonedExpression);
1068     return clone;
1069 }
1070 
1071 void ThrowStatementNode::Accept(Visitor& visitor)
1072 {
1073     visitor.Visit(*this);
1074 }
1075 
1076 void ThrowStatementNode::Write(AstWriter& writer)
1077 {
1078     StatementNode::Write(writer);
1079     bool hasExpression = expression != nullptr;
1080     writer.GetBinaryWriter().Write(hasExpression);
1081     if (hasExpression)
1082     {
1083         writer.Write(expression.get());
1084     }
1085 }
1086 
1087 void ThrowStatementNode::Read(AstReader& reader)
1088 {
1089     StatementNode::Read(reader);
1090     bool hasExpression = reader.GetBinaryReader().ReadBool();
1091     if (hasExpression)
1092     {
1093         expression.reset(reader.ReadNode());
1094         expression->SetParent(this);
1095     }
1096 }
1097 
1098 CatchNode::CatchNode(const Span& span_const boost::uuids::uuid& moduleId_) : Node(NodeType::catchNodespan_moduleId_)typeExpr()id()catchBlock()
1099 {
1100 }
1101 
1102 CatchNode::CatchNode(const Span& span_const boost::uuids::uuid& moduleId_Node* typeExpr_IdentifierNode* id_CompoundStatementNode* catchBlock_) :
1103     Node(NodeType::catchNodespan_moduleId_)typeExpr(typeExpr_)id(id_)catchBlock(catchBlock_)
1104 {
1105     typeExpr->SetParent(this);
1106     if (id)
1107     {
1108         id->SetParent(this);
1109     }
1110     catchBlock->SetParent(this);
1111 }
1112 
1113 Node* CatchNode::Clone(CloneContext& cloneContext) const
1114 {
1115     IdentifierNode* clonedId = nullptr;
1116     if (id)
1117     {
1118         clonedId = static_cast<IdentifierNode*>(id->Clone(cloneContext));
1119     }
1120     CatchNode* clone = new CatchNode(GetSpan()ModuleId()typeExpr->Clone(cloneContext)clonedIdstatic_cast<CompoundStatementNode*>(catchBlock->Clone(cloneContext)));
1121     clone->SetLeftParenSpan(leftParenSpan);
1122     clone->SetRightParenSpan(rightParenSpan);
1123     return clone;
1124 }
1125 
1126 void CatchNode::Accept(Visitor& visitor)
1127 {
1128     visitor.Visit(*this);
1129 }
1130 
1131 void CatchNode::Write(AstWriter& writer)
1132 {
1133     Node::Write(writer);
1134     writer.Write(typeExpr.get());
1135     bool hasId = id != nullptr;
1136     writer.GetBinaryWriter().Write(hasId);
1137     if (hasId)
1138     {
1139         writer.Write(id.get());
1140     }
1141     writer.Write(catchBlock.get());
1142     bool convertExternal = ModuleId() == writer.SpanConversionModuleId();
1143     writer.Write(leftParenSpanconvertExternal);
1144     writer.Write(rightParenSpanconvertExternal);
1145 }
1146 
1147 void CatchNode::Read(AstReader& reader)
1148 {
1149     Node::Read(reader);
1150     typeExpr.reset(reader.ReadNode());
1151     typeExpr->SetParent(this);
1152     bool hasId = reader.GetBinaryReader().ReadBool();
1153     if (hasId)
1154     {
1155         id.reset(reader.ReadIdentifierNode());
1156         id->SetParent(this);
1157     }
1158     catchBlock.reset(reader.ReadCompoundStatementNode());
1159     catchBlock->SetParent(this);
1160     leftParenSpan = reader.ReadSpan();
1161     rightParenSpan = reader.ReadSpan();
1162 }
1163 
1164 TryStatementNode::TryStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
1165     StatementNode(NodeType::tryStatementNodespan_moduleId_)tryBlock()catches()
1166 {
1167 }
1168 
1169 TryStatementNode::TryStatementNode(const Span& span_const boost::uuids::uuid& moduleId_CompoundStatementNode* tryBlock_) :
1170     StatementNode(NodeType::tryStatementNodespan_moduleId_)tryBlock(tryBlock_)catches()
1171 {
1172     tryBlock->SetParent(this);
1173 }
1174 
1175 Node* TryStatementNode::Clone(CloneContext& cloneContext) const
1176 {
1177     TryStatementNode* clone = new TryStatementNode(GetSpan()ModuleId()static_cast<CompoundStatementNode*>(tryBlock->Clone(cloneContext)));
1178     int n = catches.Count();
1179     for (int i = 0; i < n; ++i)
1180     {
1181         clone->AddCatch(static_cast<CatchNode*>(catches[i]->Clone(cloneContext)));
1182     }
1183     return clone;
1184 }
1185 
1186 void TryStatementNode::Accept(Visitor& visitor)
1187 {
1188     visitor.Visit(*this);
1189 }
1190 
1191 void TryStatementNode::Write(AstWriter& writer)
1192 {
1193     StatementNode::Write(writer);
1194     writer.Write(tryBlock.get());
1195     catches.Write(writer);
1196 }
1197 
1198 void TryStatementNode::Read(AstReader& reader)
1199 {
1200     StatementNode::Read(reader);
1201     tryBlock.reset(reader.ReadCompoundStatementNode());
1202     tryBlock->SetParent(this);
1203     catches.Read(reader);
1204     catches.SetParent(this);
1205 }
1206 
1207 void TryStatementNode::AddCatch(CatchNode* catch_)
1208 {
1209     catch_->SetParent(this);
1210     catches.Add(catch_);
1211 }
1212 
1213 AssertStatementNode::AssertStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
1214     StatementNode(NodeType::assertStatementNodespan_moduleId_)assertExpr()
1215 {
1216 }
1217 
1218 AssertStatementNode::AssertStatementNode(const Span& span_const boost::uuids::uuid& moduleId_Node* assertExpr_) :
1219     StatementNode(NodeType::assertStatementNodespan_moduleId_)assertExpr(assertExpr_)
1220 {
1221     assertExpr->SetParent(this);
1222 }
1223 
1224 Node* AssertStatementNode::Clone(CloneContext& cloneContext) const
1225 {
1226     AssertStatementNode* clone = new AssertStatementNode(GetSpan()ModuleId()assertExpr->Clone(cloneContext));
1227     return clone;
1228 }
1229 
1230 void AssertStatementNode::Accept(Visitor& visitor)
1231 {
1232     visitor.Visit(*this);
1233 }
1234 
1235 void AssertStatementNode::Write(AstWriter& writer)
1236 {
1237     StatementNode::Write(writer);
1238     writer.Write(assertExpr.get());
1239 }
1240 
1241 void AssertStatementNode::Read(AstReader& reader)
1242 {
1243     StatementNode::Read(reader);
1244     assertExpr.reset(reader.ReadNode());
1245     assertExpr->SetParent(this);
1246 }
1247 
1248 ConditionalCompilationExpressionNode::ConditionalCompilationExpressionNode(NodeType nodeType_const Span& span_const boost::uuids::uuid& moduleId_) : Node(nodeType_span_moduleId_)
1249 {
1250 }
1251 
1252 ConditionalCompilationBinaryExpressionNode::ConditionalCompilationBinaryExpressionNode(NodeType nodeType_const Span& span_const boost::uuids::uuid& moduleId_) :
1253     ConditionalCompilationExpressionNode(nodeType_span_moduleId_)
1254 {
1255 }
1256 
1257 ConditionalCompilationBinaryExpressionNode::ConditionalCompilationBinaryExpressionNode(NodeType nodeType_const Span& span_const boost::uuids::uuid& moduleId_ConditionalCompilationExpressionNode* left_ConditionalCompilationExpressionNode* right_) :
1258     ConditionalCompilationExpressionNode(nodeType_span_moduleId_)left(left_)right(right_)
1259 {
1260     left->SetParent(this);
1261     right->SetParent(this);
1262 }
1263 
1264 void ConditionalCompilationBinaryExpressionNode::Write(AstWriter& writer)
1265 {
1266     ConditionalCompilationExpressionNode::Write(writer);
1267     writer.Write(left.get());
1268     writer.Write(right.get());
1269 }
1270 
1271 void ConditionalCompilationBinaryExpressionNode::Read(AstReader& reader)
1272 {
1273     ConditionalCompilationExpressionNode::Read(reader);
1274     left.reset(reader.ReadConditionalCompilationExpressionNode());
1275     left->SetParent(this);
1276     right.reset(reader.ReadConditionalCompilationExpressionNode());
1277     right->SetParent(this);
1278 }
1279 
1280 ConditionalCompilationDisjunctionNode::ConditionalCompilationDisjunctionNode(const Span& span_const boost::uuids::uuid& moduleId_) :
1281     ConditionalCompilationBinaryExpressionNode(NodeType::conditionalCompilationDisjunctionNodespan_moduleId_)
1282 {
1283 }
1284 
1285 ConditionalCompilationDisjunctionNode::ConditionalCompilationDisjunctionNode(const Span& span_const boost::uuids::uuid& moduleId_
1286     ConditionalCompilationExpressionNode* left_ConditionalCompilationExpressionNode* right_) :
1287     ConditionalCompilationBinaryExpressionNode(NodeType::conditionalCompilationDisjunctionNodespan_moduleId_left_right_)
1288 {
1289 }
1290 
1291 Node* ConditionalCompilationDisjunctionNode::Clone(CloneContext& cloneContext) const
1292 {
1293     ConditionalCompilationDisjunctionNode* clone = new ConditionalCompilationDisjunctionNode(GetSpan()ModuleId()static_cast<ConditionalCompilationExpressionNode*>(Left()->Clone(cloneContext))static_cast<ConditionalCompilationExpressionNode*>(Right()->Clone(cloneContext)));
1294     return clone;
1295 }
1296 
1297 void ConditionalCompilationDisjunctionNode::Accept(Visitor& visitor)
1298 {
1299     visitor.Visit(*this);
1300 }
1301 
1302 ConditionalCompilationConjunctionNode::ConditionalCompilationConjunctionNode(const Span& span_const boost::uuids::uuid& moduleId_) :
1303     ConditionalCompilationBinaryExpressionNode(NodeType::conditionalCompilationConjunctionNodespan_moduleId_)
1304 {
1305 }
1306 
1307 ConditionalCompilationConjunctionNode::ConditionalCompilationConjunctionNode(const Span& span_const boost::uuids::uuid& moduleId_
1308     ConditionalCompilationExpressionNode* left_ConditionalCompilationExpressionNode* right_) :
1309     ConditionalCompilationBinaryExpressionNode(NodeType::conditionalCompilationConjunctionNodespan_moduleId_left_right_)
1310 {
1311 }
1312 
1313 Node* ConditionalCompilationConjunctionNode::Clone(CloneContext& cloneContext) const
1314 {
1315     ConditionalCompilationConjunctionNode* clone = new ConditionalCompilationConjunctionNode(GetSpan()ModuleId()static_cast<ConditionalCompilationExpressionNode*>(Left()->Clone(cloneContext))static_cast<ConditionalCompilationExpressionNode*>(Right()->Clone(cloneContext)));
1316     return clone;
1317 }
1318 
1319 void ConditionalCompilationConjunctionNode::Accept(Visitor& visitor)
1320 {
1321     visitor.Visit(*this);
1322 }
1323 
1324 ConditionalCompilationNotNode::ConditionalCompilationNotNode(const Span& span_const boost::uuids::uuid& moduleId_) :
1325     ConditionalCompilationExpressionNode(NodeType::conditionalCompilationNotNodespan_moduleId_)
1326 {
1327 }
1328 
1329 ConditionalCompilationNotNode::ConditionalCompilationNotNode(const Span& span_const boost::uuids::uuid& moduleId_ConditionalCompilationExpressionNode* expr_) :
1330     ConditionalCompilationExpressionNode(NodeType::conditionalCompilationNotNodespan_moduleId_)expr(expr_)
1331 {
1332     expr->SetParent(this);
1333 }
1334 
1335 Node* ConditionalCompilationNotNode::Clone(CloneContext& cloneContext) const
1336 {
1337     ConditionalCompilationNotNode* clone = new ConditionalCompilationNotNode(GetSpan()ModuleId()static_cast<ConditionalCompilationExpressionNode*>(expr->Clone(cloneContext)));
1338     return clone;
1339 }
1340 
1341 void ConditionalCompilationNotNode::Accept(Visitor& visitor)
1342 {
1343     visitor.Visit(*this);
1344 }
1345 
1346 void ConditionalCompilationNotNode::Write(AstWriter& writer)
1347 {
1348     ConditionalCompilationExpressionNode::Write(writer);
1349     writer.Write(expr.get());
1350 }
1351 
1352 void ConditionalCompilationNotNode::Read(AstReader& reader)
1353 {
1354     ConditionalCompilationExpressionNode::Read(reader);
1355     expr.reset(reader.ReadConditionalCompilationExpressionNode());
1356     expr->SetParent(this);
1357 }
1358 
1359 ConditionalCompilationPrimaryNode::ConditionalCompilationPrimaryNode(const Span& span_const boost::uuids::uuid& moduleId_) :
1360     ConditionalCompilationExpressionNode(NodeType::conditionalCompilationPrimaryNodespan_moduleId_)
1361 {
1362 }
1363 
1364 ConditionalCompilationPrimaryNode::ConditionalCompilationPrimaryNode(const Span& span_const boost::uuids::uuid& moduleId_const std::u32string& symbol_) :
1365     ConditionalCompilationExpressionNode(NodeType::conditionalCompilationPrimaryNodespan_moduleId_)symbol(symbol_)
1366 {
1367 }
1368 
1369 Node* ConditionalCompilationPrimaryNode::Clone(CloneContext& cloneContext) const
1370 {
1371     ConditionalCompilationPrimaryNode* clone = new ConditionalCompilationPrimaryNode(GetSpan()ModuleId()symbol);
1372     return clone;
1373 }
1374 
1375 void ConditionalCompilationPrimaryNode::Accept(Visitor& visitor)
1376 {
1377     visitor.Visit(*this);
1378 }
1379 
1380 void ConditionalCompilationPrimaryNode::Write(AstWriter& writer)
1381 {
1382     ConditionalCompilationExpressionNode::Write(writer);
1383     writer.GetBinaryWriter().Write(symbol);
1384 }
1385 
1386 void ConditionalCompilationPrimaryNode::Read(AstReader& reader)
1387 {
1388     ConditionalCompilationExpressionNode::Read(reader);
1389     symbol = reader.GetBinaryReader().ReadUtf32String();
1390 }
1391 
1392 ParenthesizedConditionalCompilationExpressionNode::ParenthesizedConditionalCompilationExpressionNode(const Span& span_const boost::uuids::uuid& moduleId_) :
1393     ConditionalCompilationExpressionNode(NodeType::parenthesizedCondCompExpressionNodespan_moduleId_)
1394 {
1395 }
1396 
1397 ParenthesizedConditionalCompilationExpressionNode::ParenthesizedConditionalCompilationExpressionNode(const Span& span_const boost::uuids::uuid& moduleId_ConditionalCompilationExpressionNode* expr_) :
1398     ConditionalCompilationExpressionNode(NodeType::parenthesizedCondCompExpressionNodespan_moduleId_)expr(expr_)
1399 {
1400 }
1401 
1402 Node* ParenthesizedConditionalCompilationExpressionNode::Clone(CloneContext& cloneContext) const
1403 {
1404     ParenthesizedConditionalCompilationExpressionNode* clone = new ParenthesizedConditionalCompilationExpressionNode(GetSpan()ModuleId()static_cast<ConditionalCompilationExpressionNode*>(expr->Clone(cloneContext)));
1405     return clone;
1406 }
1407 
1408 void ParenthesizedConditionalCompilationExpressionNode::Accept(Visitor& visitor)
1409 {
1410     visitor.Visit(*this);
1411 }
1412 
1413 void ParenthesizedConditionalCompilationExpressionNode::Write(AstWriter& writer)
1414 {
1415     ConditionalCompilationExpressionNode::Write(writer);
1416     writer.Write(expr.get());
1417 }
1418 
1419 void ParenthesizedConditionalCompilationExpressionNode::Read(AstReader& reader)
1420 {
1421     ConditionalCompilationExpressionNode::Read(reader);
1422     expr.reset(reader.ReadConditionalCompilationExpressionNode());
1423     expr->SetParent(this);
1424 }
1425 
1426 ConditionalCompilationPartNode::ConditionalCompilationPartNode(const Span& span_const boost::uuids::uuid& moduleId_) : Node(NodeType::conditionalCompilationPartNodespan_moduleId_)
1427 {
1428 }
1429 
1430 ConditionalCompilationPartNode::ConditionalCompilationPartNode(const Span& span_const boost::uuids::uuid& moduleId_ConditionalCompilationExpressionNode* expr_) :
1431     Node(NodeType::conditionalCompilationPartNodespan_moduleId_)expr(expr_)
1432 {
1433     if (expr)
1434     {
1435         expr->SetParent(this);
1436     }
1437 }
1438 
1439 void ConditionalCompilationPartNode::AddStatement(StatementNode* statement)
1440 {
1441     statement->SetParent(this);
1442     statements.Add(statement);
1443 }
1444 
1445 Node* ConditionalCompilationPartNode::Clone(CloneContext& cloneContext) const
1446 {
1447     ConditionalCompilationExpressionNode* clonedIfExpr = nullptr;
1448     if (expr)
1449     {
1450         clonedIfExpr = static_cast<ConditionalCompilationExpressionNode*>(expr->Clone(cloneContext));
1451     }
1452     ConditionalCompilationPartNode* clone = new ConditionalCompilationPartNode(GetSpan()ModuleId()clonedIfExpr);
1453     int n = statements.Count();
1454     for (int i = 0; i < n; ++i)
1455     {
1456         clone->AddStatement(static_cast<StatementNode*>(statements[i]->Clone(cloneContext)));
1457     }
1458     clone->SetKeywordSpan(keywordSpan);
1459     clone->SetLeftParenSpan(leftParenSpan);
1460     clone->SetRightParenSpan(rightParenSpan);
1461     return clone;
1462 }
1463 
1464 void ConditionalCompilationPartNode::Accept(Visitor& visitor)
1465 {
1466     visitor.Visit(*this);
1467 }
1468 
1469 void ConditionalCompilationPartNode::Write(AstWriter& writer)
1470 {
1471     Node::Write(writer);
1472     bool hasExpr = expr != nullptr;
1473     writer.GetBinaryWriter().Write(hasExpr);
1474     if (hasExpr)
1475     {
1476         writer.Write(expr.get());
1477     }
1478     statements.Write(writer);
1479     bool convertExternal = ModuleId() == writer.SpanConversionModuleId();
1480     writer.Write(keywordSpanconvertExternal);
1481     writer.Write(leftParenSpanconvertExternal);
1482     writer.Write(rightParenSpanconvertExternal);
1483 }
1484 
1485 void ConditionalCompilationPartNode::Read(AstReader& reader)
1486 {
1487     Node::Read(reader);
1488     bool hasExpr = reader.GetBinaryReader().ReadBool();
1489     if (hasExpr)
1490     {
1491         expr.reset(reader.ReadConditionalCompilationExpressionNode());
1492         expr->SetParent(this);
1493     }
1494     statements.Read(reader);
1495     statements.SetParent(this);
1496     keywordSpan = reader.ReadSpan();
1497     leftParenSpan = reader.ReadSpan();
1498     rightParenSpan = reader.ReadSpan();
1499 }
1500 
1501 ConditionalCompilationStatementNode::ConditionalCompilationStatementNode(const Span& span_const boost::uuids::uuid& moduleId_) :
1502     StatementNode(NodeType::conditionalCompilationStatementNodespan_moduleId_)ifPart(nullptr)
1503 {
1504 }
1505 
1506 ConditionalCompilationStatementNode::ConditionalCompilationStatementNode(const Span& span_const boost::uuids::uuid& moduleId_ConditionalCompilationExpressionNode* ifExpr_) :
1507     StatementNode(NodeType::conditionalCompilationStatementNodespan_moduleId_)ifPart(new ConditionalCompilationPartNode(span_moduleId_ifExpr_))
1508 {
1509 }
1510 
1511 void ConditionalCompilationStatementNode::AddIfStatement(StatementNode* statement)
1512 {
1513     ifPart->AddStatement(statement);
1514 }
1515 
1516 void ConditionalCompilationStatementNode::AddElifExpr(const Span& spanconst boost::uuids::uuid& moduleId_ConditionalCompilationExpressionNode* expr)
1517 {
1518     elifParts.Add(new ConditionalCompilationPartNode(spanmoduleId_expr));
1519 }
1520 
1521 void ConditionalCompilationStatementNode::AddElifStatement(StatementNode* statement)
1522 {
1523     elifParts[elifParts.Count() - 1]->AddStatement(statement);
1524 }
1525 
1526 void ConditionalCompilationStatementNode::SetElifLeftParenSpan(const Span& span)
1527 {
1528     elifParts[elifParts.Count() - 1]->SetLeftParenSpan(span);
1529 }
1530 
1531 void ConditionalCompilationStatementNode::SetElifRightParenSpan(const Span& span)
1532 {
1533     elifParts[elifParts.Count() - 1]->SetRightParenSpan(span);
1534 }
1535 
1536 void ConditionalCompilationStatementNode::SetElifKeywordSpan(const Span& span)
1537 {
1538     elifParts[elifParts.Count() - 1]->SetKeywordSpan(span);
1539 }
1540 
1541 void ConditionalCompilationStatementNode::AddElseStatement(const Span& spanconst boost::uuids::uuid& moduleId_StatementNode* statement)
1542 {
1543     if (!elsePart)
1544     {
1545         elsePart.reset(new ConditionalCompilationPartNode(spanmoduleId_));
1546     }
1547     elsePart->AddStatement(statement);
1548 }
1549 
1550 Node* ConditionalCompilationStatementNode::Clone(CloneContext& cloneContext) const
1551 {
1552     ConditionalCompilationStatementNode* clone = new ConditionalCompilationStatementNode(GetSpan()ModuleId());
1553     ConditionalCompilationPartNode* clonedIfPart = static_cast<ConditionalCompilationPartNode*>(ifPart->Clone(cloneContext));
1554     clone->ifPart.reset(clonedIfPart);
1555     int n = elifParts.Count();
1556     for (int i = 0; i < n; ++i)
1557     {
1558         ConditionalCompilationPartNode* elifPart = elifParts[i];
1559         ConditionalCompilationPartNode* clonedElifPart = static_cast<ConditionalCompilationPartNode*>(elifPart->Clone(cloneContext));
1560         clone->elifParts.Add(clonedElifPart);
1561     }
1562     if (elsePart)
1563     {
1564         ConditionalCompilationPartNode* clonedElsePart = static_cast<ConditionalCompilationPartNode*>(elsePart->Clone(cloneContext));
1565         clone->elsePart.reset(clonedElsePart);
1566     }
1567     clone->SetEndIfSpan(endifSpan);
1568     return clone;
1569 }
1570 
1571 void ConditionalCompilationStatementNode::Accept(Visitor& visitor)
1572 {
1573     visitor.Visit(*this);
1574 }
1575 
1576 void ConditionalCompilationStatementNode::Write(AstWriter& writer)
1577 {
1578     StatementNode::Write(writer);
1579     writer.Write(ifPart.get());
1580     elifParts.Write(writer);
1581     bool hasElsePart = elsePart != nullptr;
1582     writer.GetBinaryWriter().Write(hasElsePart);
1583     if (hasElsePart)
1584     {
1585         writer.Write(elsePart.get());
1586     }
1587     bool convertExternal = ModuleId() == writer.SpanConversionModuleId();
1588     writer.Write(endifSpanconvertExternal);
1589 }
1590 
1591 void ConditionalCompilationStatementNode::Read(AstReader& reader)
1592 {
1593     StatementNode::Read(reader);
1594     ifPart.reset(reader.ReadConditionalCompilationPartNode());
1595     ifPart->SetParent(this);
1596     elifParts.Read(reader);
1597     elifParts.SetParent(this);
1598     bool hasElsePart = reader.GetBinaryReader().ReadBool();
1599     if (hasElsePart)
1600     {
1601         elsePart.reset(reader.ReadConditionalCompilationPartNode());
1602         elsePart->SetParent(this);
1603     }
1604     endifSpan = reader.ReadSpan();
1605 }
1606 
1607 void ConditionalCompilationStatementNode::SetIfPart(ConditionalCompilationPartNode* ifPart_)
1608 {
1609     ifPart.reset(ifPart_);
1610 }
1611 
1612 void ConditionalCompilationStatementNode::AddElifPart(ConditionalCompilationPartNode* elifPart)
1613 {
1614     elifParts.Add(elifPart);
1615 }
1616 
1617 void ConditionalCompilationStatementNode::SetElsePart(ConditionalCompilationPartNode* elsePart_)
1618 {
1619     elsePart.reset(elsePart_);
1620 }
1621 
1622 } } // namespace sngcm::ast