libqasm
library for handling cQASM files
cqasm-v1-semantic-gen.cpp
Go to the documentation of this file.
1 
5 #include "cqasm-annotations.hpp"
7 
8 namespace cqasm {
9 namespace v1 {
10 namespace semantic {
11 
15 void Node::dump(std::ostream &out, int indent) {
16  auto dumper = Dumper(out, indent);
17  visit(dumper);
18 }
19 
24 void Node::dump_seq(std::ostream &out, int indent) {
25  ::tree::base::PointerMap ids;
26  ids.enable_exceptions = false;
27  ids.add_ref(*this);
28  find_reachable(ids);
29  auto dumper = Dumper(out, indent, &ids);
30  visit(dumper);
31 }
32 
38  return nullptr;
39 }
40 
45 const Annotated *Node::as_annotated() const {
46  return nullptr;
47 }
48 
54  return nullptr;
55 }
56 
62  return nullptr;
63 }
64 
70  return nullptr;
71 }
72 
77 const Block *Node::as_block() const {
78  return nullptr;
79 }
80 
86  return nullptr;
87 }
88 
94  return nullptr;
95 }
96 
102  return nullptr;
103 }
104 
109 const Bundle *Node::as_bundle() const {
110  return nullptr;
111 }
112 
118  return nullptr;
119 }
120 
126  return nullptr;
127 }
128 
134  return nullptr;
135 }
136 
142  return nullptr;
143 }
144 
150  return nullptr;
151 }
152 
158  return nullptr;
159 }
160 
166  return nullptr;
167 }
168 
173 const ForLoop *Node::as_for_loop() const {
174  return nullptr;
175 }
176 
182  return nullptr;
183 }
184 
190  return nullptr;
191 }
192 
198  return nullptr;
199 }
200 
206  return nullptr;
207 }
208 
214  return nullptr;
215 }
216 
221 const IfElse *Node::as_if_else() const {
222  return nullptr;
223 }
224 
230  return nullptr;
231 }
232 
238  return nullptr;
239 }
240 
246  return nullptr;
247 }
248 
254  return nullptr;
255 }
256 
262  return nullptr;
263 }
264 
270  return nullptr;
271 }
272 
278  return nullptr;
279 }
280 
285 const Mapping *Node::as_mapping() const {
286  return nullptr;
287 }
288 
294  return nullptr;
295 }
296 
301 const Program *Node::as_program() const {
302  return nullptr;
303 }
304 
310  return nullptr;
311 }
312 
318  return nullptr;
319 }
320 
326  return nullptr;
327 }
328 
334  return nullptr;
335 }
336 
342  return nullptr;
343 }
344 
350  return nullptr;
351 }
352 
358  return nullptr;
359 }
360 
366  return nullptr;
367 }
368 
374  return nullptr;
375 }
376 
382  return nullptr;
383 }
384 
390  return nullptr;
391 }
392 
397 const Variable *Node::as_variable() const {
398  return nullptr;
399 }
400 
406  return nullptr;
407 }
408 
413 const Version *Node::as_version() const {
414  return nullptr;
415 }
416 
422  return nullptr;
423 }
424 
430  return nullptr;
431 }
432 
436 std::shared_ptr<Node> Node::deserialize(
437  const ::tree::cbor::MapReader &map,
438  ::tree::base::IdentifierMap &ids
439 ) {
440  auto type = map.at("@t").as_string();
441  if (type == "AnnotationData") return AnnotationData::deserialize(map, ids);
442  if (type == "Block") return Block::deserialize(map, ids);
443  if (type == "BreakStatement") return BreakStatement::deserialize(map, ids);
444  if (type == "Bundle") return Bundle::deserialize(map, ids);
445  if (type == "BundleExt") return BundleExt::deserialize(map, ids);
446  if (type == "ContinueStatement") return ContinueStatement::deserialize(map, ids);
447  if (type == "ErrorModel") return ErrorModel::deserialize(map, ids);
448  if (type == "ForLoop") return ForLoop::deserialize(map, ids);
449  if (type == "ForeachLoop") return ForeachLoop::deserialize(map, ids);
450  if (type == "GotoInstruction") return GotoInstruction::deserialize(map, ids);
451  if (type == "IfElse") return IfElse::deserialize(map, ids);
452  if (type == "IfElseBranch") return IfElseBranch::deserialize(map, ids);
453  if (type == "Instruction") return Instruction::deserialize(map, ids);
454  if (type == "Mapping") return Mapping::deserialize(map, ids);
455  if (type == "Program") return Program::deserialize(map, ids);
456  if (type == "RepeatUntilLoop") return RepeatUntilLoop::deserialize(map, ids);
457  if (type == "SetInstruction") return SetInstruction::deserialize(map, ids);
458  if (type == "Subcircuit") return Subcircuit::deserialize(map, ids);
459  if (type == "Variable") return Variable::deserialize(map, ids);
460  if (type == "Version") return Version::deserialize(map, ids);
461  if (type == "WhileLoop") return WhileLoop::deserialize(map, ids);
462  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
463 }
464 
469  : annotations(annotations)
470 {}
471 
477  return dynamic_cast<Annotated*>(this);
478 }
479 
485  return dynamic_cast<const Annotated*>(this);
486 }
487 
491 std::shared_ptr<Annotated> Annotated::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
492  auto type = map.at("@t").as_string();
493  if (type == "ErrorModel") return ErrorModel::deserialize(map, ids);
494  if (type == "Instruction") return Instruction::deserialize(map, ids);
495  if (type == "SetInstruction") return SetInstruction::deserialize(map, ids);
496  if (type == "GotoInstruction") return GotoInstruction::deserialize(map, ids);
497  if (type == "Bundle") return Bundle::deserialize(map, ids);
498  if (type == "BundleExt") return BundleExt::deserialize(map, ids);
499  if (type == "IfElse") return IfElse::deserialize(map, ids);
500  if (type == "ForLoop") return ForLoop::deserialize(map, ids);
501  if (type == "ForeachLoop") return ForeachLoop::deserialize(map, ids);
502  if (type == "WhileLoop") return WhileLoop::deserialize(map, ids);
503  if (type == "RepeatUntilLoop") return RepeatUntilLoop::deserialize(map, ids);
504  if (type == "BreakStatement") return BreakStatement::deserialize(map, ids);
505  if (type == "ContinueStatement") return ContinueStatement::deserialize(map, ids);
506  if (type == "Subcircuit") return Subcircuit::deserialize(map, ids);
507  if (type == "Mapping") return Mapping::deserialize(map, ids);
508  if (type == "Variable") return Variable::deserialize(map, ids);
509  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
510 }
511 
516  : interface(interface), operation(operation), operands(operands)
517 {}
518 
522 void AnnotationData::find_reachable(::tree::base::PointerMap &map) const {
523  (void)map;
524  operands.find_reachable(map);
525 }
526 
530 void AnnotationData::check_complete(const ::tree::base::PointerMap &map) const {
531  (void)map;
532  operands.check_complete(map);
533 }
534 
540 }
541 
545 void AnnotationData::visit_internal(VisitorBase &visitor, void *retval) {
546  visitor.raw_visit_annotation_data(*this, retval);
547 }
548 
554  return dynamic_cast<AnnotationData*>(this);
555 }
556 
562  return dynamic_cast<const AnnotationData*>(this);
563 }
564 
569  return cqasm::tree::make<AnnotationData>(*this);
570 }
571 
576  auto node = cqasm::tree::make<AnnotationData>(*this);
577  node->operands = this->operands.clone();
578  return node;
579 }
580 
584 bool AnnotationData::equals(const Node &rhs) const {
585  if (rhs.type() != NodeType::AnnotationData) return false;
586  auto rhsc = dynamic_cast<const AnnotationData&>(rhs);
587  if (this->interface != rhsc.interface) return false;
588  if (this->operation != rhsc.operation) return false;
589  if (!this->operands.equals(rhsc.operands)) return false;
590  return true;
591 }
592 
596 bool AnnotationData::operator==(const Node &rhs) const {
597  if (rhs.type() != NodeType::AnnotationData) return false;
598  auto rhsc = dynamic_cast<const AnnotationData&>(rhs);
599  if (this->interface != rhsc.interface) return false;
600  if (this->operation != rhsc.operation) return false;
601  if (this->operands != rhsc.operands) return false;
602  return true;
603 }
604 
609  ::tree::cbor::MapWriter &map,
610  const ::tree::base::PointerMap &ids
611 ) const {
612  (void)ids;
613  map.append_string("@t", "AnnotationData");
614  auto submap = map.append_map("interface");
615  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(interface, submap);
616  submap.close();
617  submap = map.append_map("operation");
618  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(operation, submap);
619  submap.close();
620  submap = map.append_map("operands");
621  operands.serialize(submap, ids);
622  submap.close();
623  serialize_annotations(map);
624 }
625 
629 std::shared_ptr<AnnotationData> AnnotationData::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
630  (void)ids;
631  auto type = map.at("@t").as_string();
632  if (type != "AnnotationData") {
633  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
634  }
635  auto node = std::make_shared<AnnotationData>(
636  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at("interface").as_map()),
637  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at("operation").as_map()),
638  Any<cqasm::v1::values::Node>(map.at("operands").as_map(), ids)
639  );
640  node->deserialize_annotations(map);
641  return node;
642 }
643 
647 Block::Block(const Any<Statement> &statements)
648  : statements(statements)
649 {}
650 
654 void Block::find_reachable(::tree::base::PointerMap &map) const {
655  (void)map;
656  statements.find_reachable(map);
657 }
658 
662 void Block::check_complete(const ::tree::base::PointerMap &map) const {
663  (void)map;
664  statements.check_complete(map);
665 }
666 
671  return NodeType::Block;
672 }
673 
677 void Block::visit_internal(VisitorBase &visitor, void *retval) {
678  visitor.raw_visit_block(*this, retval);
679 }
680 
686  return dynamic_cast<Block*>(this);
687 }
688 
693 const Block *Block::as_block() const {
694  return dynamic_cast<const Block*>(this);
695 }
696 
701  return cqasm::tree::make<Block>(*this);
702 }
703 
708  auto node = cqasm::tree::make<Block>(*this);
709  node->statements = this->statements.clone();
710  return node;
711 }
712 
716 bool Block::equals(const Node &rhs) const {
717  if (rhs.type() != NodeType::Block) return false;
718  auto rhsc = dynamic_cast<const Block&>(rhs);
719  if (!this->statements.equals(rhsc.statements)) return false;
720  return true;
721 }
722 
726 bool Block::operator==(const Node &rhs) const {
727  if (rhs.type() != NodeType::Block) return false;
728  auto rhsc = dynamic_cast<const Block&>(rhs);
729  if (this->statements != rhsc.statements) return false;
730  return true;
731 }
732 
737  ::tree::cbor::MapWriter &map,
738  const ::tree::base::PointerMap &ids
739 ) const {
740  (void)ids;
741  map.append_string("@t", "Block");
742  auto submap = map.append_map("statements");
743  statements.serialize(submap, ids);
744  submap.close();
745  serialize_annotations(map);
746 }
747 
751 std::shared_ptr<Block> Block::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
752  (void)ids;
753  auto type = map.at("@t").as_string();
754  if (type != "Block") {
755  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
756  }
757  auto node = std::make_shared<Block>(
758  Any<Statement>(map.at("statements").as_map(), ids)
759  );
760  node->deserialize_annotations(map);
761  return node;
762 }
763 
768  : Annotated(annotations)
769 {}
770 
776  return dynamic_cast<Statement*>(this);
777 }
778 
784  return dynamic_cast<const Statement*>(this);
785 }
786 
790 std::shared_ptr<Statement> Statement::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
791  auto type = map.at("@t").as_string();
792  if (type == "BundleExt") return BundleExt::deserialize(map, ids);
793  if (type == "IfElse") return IfElse::deserialize(map, ids);
794  if (type == "ForLoop") return ForLoop::deserialize(map, ids);
795  if (type == "ForeachLoop") return ForeachLoop::deserialize(map, ids);
796  if (type == "WhileLoop") return WhileLoop::deserialize(map, ids);
797  if (type == "RepeatUntilLoop") return RepeatUntilLoop::deserialize(map, ids);
798  if (type == "BreakStatement") return BreakStatement::deserialize(map, ids);
799  if (type == "ContinueStatement") return ContinueStatement::deserialize(map, ids);
800  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
801 }
802 
807  : Statement(annotations)
808 {}
809 
815  return dynamic_cast<Structured*>(this);
816 }
817 
823  return dynamic_cast<const Structured*>(this);
824 }
825 
829 std::shared_ptr<Structured> Structured::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
830  auto type = map.at("@t").as_string();
831  if (type == "IfElse") return IfElse::deserialize(map, ids);
832  if (type == "ForLoop") return ForLoop::deserialize(map, ids);
833  if (type == "ForeachLoop") return ForeachLoop::deserialize(map, ids);
834  if (type == "WhileLoop") return WhileLoop::deserialize(map, ids);
835  if (type == "RepeatUntilLoop") return RepeatUntilLoop::deserialize(map, ids);
836  if (type == "BreakStatement") return BreakStatement::deserialize(map, ids);
837  if (type == "ContinueStatement") return ContinueStatement::deserialize(map, ids);
838  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
839 }
840 
845  : Structured(annotations)
846 {}
847 
851 void BreakStatement::find_reachable(::tree::base::PointerMap &map) const {
852  (void)map;
853  annotations.find_reachable(map);
854 }
855 
859 void BreakStatement::check_complete(const ::tree::base::PointerMap &map) const {
860  (void)map;
861  annotations.check_complete(map);
862 }
863 
869 }
870 
874 void BreakStatement::visit_internal(VisitorBase &visitor, void *retval) {
875  visitor.raw_visit_break_statement(*this, retval);
876 }
877 
883  return dynamic_cast<BreakStatement*>(this);
884 }
885 
891  return dynamic_cast<const BreakStatement*>(this);
892 }
893 
898  return cqasm::tree::make<BreakStatement>(*this);
899 }
900 
905  auto node = cqasm::tree::make<BreakStatement>(*this);
906  node->annotations = this->annotations.clone();
907  return node;
908 }
909 
913 bool BreakStatement::equals(const Node &rhs) const {
914  if (rhs.type() != NodeType::BreakStatement) return false;
915  auto rhsc = dynamic_cast<const BreakStatement&>(rhs);
916  if (!this->annotations.equals(rhsc.annotations)) return false;
917  return true;
918 }
919 
923 bool BreakStatement::operator==(const Node &rhs) const {
924  if (rhs.type() != NodeType::BreakStatement) return false;
925  auto rhsc = dynamic_cast<const BreakStatement&>(rhs);
926  if (this->annotations != rhsc.annotations) return false;
927  return true;
928 }
929 
934  ::tree::cbor::MapWriter &map,
935  const ::tree::base::PointerMap &ids
936 ) const {
937  (void)ids;
938  map.append_string("@t", "BreakStatement");
939  auto submap = map.append_map("annotations");
940  annotations.serialize(submap, ids);
941  submap.close();
942  serialize_annotations(map);
943 }
944 
948 std::shared_ptr<BreakStatement> BreakStatement::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
949  (void)ids;
950  auto type = map.at("@t").as_string();
951  if (type != "BreakStatement") {
952  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
953  }
954  auto node = std::make_shared<BreakStatement>(
955  Any<AnnotationData>(map.at("annotations").as_map(), ids)
956  );
957  node->deserialize_annotations(map);
958  return node;
959 }
960 
965  : Annotated(annotations), items(items)
966 {}
967 
971 void Bundle::find_reachable(::tree::base::PointerMap &map) const {
972  (void)map;
973  items.find_reachable(map);
974  annotations.find_reachable(map);
975 }
976 
980 void Bundle::check_complete(const ::tree::base::PointerMap &map) const {
981  (void)map;
982  items.check_complete(map);
983  annotations.check_complete(map);
984 }
985 
990  return NodeType::Bundle;
991 }
992 
996 void Bundle::visit_internal(VisitorBase &visitor, void *retval) {
997  visitor.raw_visit_bundle(*this, retval);
998 }
999 
1005  return dynamic_cast<Bundle*>(this);
1006 }
1007 
1012 const Bundle *Bundle::as_bundle() const {
1013  return dynamic_cast<const Bundle*>(this);
1014 }
1015 
1020  return cqasm::tree::make<Bundle>(*this);
1021 }
1022 
1027  auto node = cqasm::tree::make<Bundle>(*this);
1028  node->items = this->items.clone();
1029  node->annotations = this->annotations.clone();
1030  return node;
1031 }
1032 
1036 bool Bundle::equals(const Node &rhs) const {
1037  if (rhs.type() != NodeType::Bundle) return false;
1038  auto rhsc = dynamic_cast<const Bundle&>(rhs);
1039  if (!this->items.equals(rhsc.items)) return false;
1040  if (!this->annotations.equals(rhsc.annotations)) return false;
1041  return true;
1042 }
1043 
1047 bool Bundle::operator==(const Node &rhs) const {
1048  if (rhs.type() != NodeType::Bundle) return false;
1049  auto rhsc = dynamic_cast<const Bundle&>(rhs);
1050  if (this->items != rhsc.items) return false;
1051  if (this->annotations != rhsc.annotations) return false;
1052  return true;
1053 }
1054 
1059  ::tree::cbor::MapWriter &map,
1060  const ::tree::base::PointerMap &ids
1061 ) const {
1062  (void)ids;
1063  map.append_string("@t", "Bundle");
1064  auto submap = map.append_map("items");
1065  items.serialize(submap, ids);
1066  submap.close();
1067  submap = map.append_map("annotations");
1068  annotations.serialize(submap, ids);
1069  submap.close();
1070  serialize_annotations(map);
1071 }
1072 
1076 std::shared_ptr<Bundle> Bundle::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1077  (void)ids;
1078  auto type = map.at("@t").as_string();
1079  if (type != "Bundle") {
1080  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1081  }
1082  auto node = std::make_shared<Bundle>(
1083  Many<Instruction>(map.at("items").as_map(), ids),
1084  Any<AnnotationData>(map.at("annotations").as_map(), ids)
1085  );
1086  node->deserialize_annotations(map);
1087  return node;
1088 }
1089 
1094  : Statement(annotations), items(items)
1095 {}
1096 
1100 void BundleExt::find_reachable(::tree::base::PointerMap &map) const {
1101  (void)map;
1102  items.find_reachable(map);
1103  annotations.find_reachable(map);
1104 }
1105 
1109 void BundleExt::check_complete(const ::tree::base::PointerMap &map) const {
1110  (void)map;
1111  items.check_complete(map);
1112  annotations.check_complete(map);
1113 }
1114 
1119  return NodeType::BundleExt;
1120 }
1121 
1125 void BundleExt::visit_internal(VisitorBase &visitor, void *retval) {
1126  visitor.raw_visit_bundle_ext(*this, retval);
1127 }
1128 
1134  return dynamic_cast<BundleExt*>(this);
1135 }
1136 
1142  return dynamic_cast<const BundleExt*>(this);
1143 }
1144 
1149  return cqasm::tree::make<BundleExt>(*this);
1150 }
1151 
1156  auto node = cqasm::tree::make<BundleExt>(*this);
1157  node->items = this->items.clone();
1158  node->annotations = this->annotations.clone();
1159  return node;
1160 }
1161 
1165 bool BundleExt::equals(const Node &rhs) const {
1166  if (rhs.type() != NodeType::BundleExt) return false;
1167  auto rhsc = dynamic_cast<const BundleExt&>(rhs);
1168  if (!this->items.equals(rhsc.items)) return false;
1169  if (!this->annotations.equals(rhsc.annotations)) return false;
1170  return true;
1171 }
1172 
1176 bool BundleExt::operator==(const Node &rhs) const {
1177  if (rhs.type() != NodeType::BundleExt) return false;
1178  auto rhsc = dynamic_cast<const BundleExt&>(rhs);
1179  if (this->items != rhsc.items) return false;
1180  if (this->annotations != rhsc.annotations) return false;
1181  return true;
1182 }
1183 
1188  ::tree::cbor::MapWriter &map,
1189  const ::tree::base::PointerMap &ids
1190 ) const {
1191  (void)ids;
1192  map.append_string("@t", "BundleExt");
1193  auto submap = map.append_map("items");
1194  items.serialize(submap, ids);
1195  submap.close();
1196  submap = map.append_map("annotations");
1197  annotations.serialize(submap, ids);
1198  submap.close();
1199  serialize_annotations(map);
1200 }
1201 
1205 std::shared_ptr<BundleExt> BundleExt::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1206  (void)ids;
1207  auto type = map.at("@t").as_string();
1208  if (type != "BundleExt") {
1209  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1210  }
1211  auto node = std::make_shared<BundleExt>(
1212  Many<InstructionBase>(map.at("items").as_map(), ids),
1213  Any<AnnotationData>(map.at("annotations").as_map(), ids)
1214  );
1215  node->deserialize_annotations(map);
1216  return node;
1217 }
1218 
1223  : Structured(annotations)
1224 {}
1225 
1229 void ContinueStatement::find_reachable(::tree::base::PointerMap &map) const {
1230  (void)map;
1231  annotations.find_reachable(map);
1232 }
1233 
1237 void ContinueStatement::check_complete(const ::tree::base::PointerMap &map) const {
1238  (void)map;
1239  annotations.check_complete(map);
1240 }
1241 
1247 }
1248 
1252 void ContinueStatement::visit_internal(VisitorBase &visitor, void *retval) {
1253  visitor.raw_visit_continue_statement(*this, retval);
1254 }
1255 
1261  return dynamic_cast<ContinueStatement*>(this);
1262 }
1263 
1269  return dynamic_cast<const ContinueStatement*>(this);
1270 }
1271 
1276  return cqasm::tree::make<ContinueStatement>(*this);
1277 }
1278 
1283  auto node = cqasm::tree::make<ContinueStatement>(*this);
1284  node->annotations = this->annotations.clone();
1285  return node;
1286 }
1287 
1291 bool ContinueStatement::equals(const Node &rhs) const {
1292  if (rhs.type() != NodeType::ContinueStatement) return false;
1293  auto rhsc = dynamic_cast<const ContinueStatement&>(rhs);
1294  if (!this->annotations.equals(rhsc.annotations)) return false;
1295  return true;
1296 }
1297 
1301 bool ContinueStatement::operator==(const Node &rhs) const {
1302  if (rhs.type() != NodeType::ContinueStatement) return false;
1303  auto rhsc = dynamic_cast<const ContinueStatement&>(rhs);
1304  if (this->annotations != rhsc.annotations) return false;
1305  return true;
1306 }
1307 
1312  ::tree::cbor::MapWriter &map,
1313  const ::tree::base::PointerMap &ids
1314 ) const {
1315  (void)ids;
1316  map.append_string("@t", "ContinueStatement");
1317  auto submap = map.append_map("annotations");
1318  annotations.serialize(submap, ids);
1319  submap.close();
1320  serialize_annotations(map);
1321 }
1322 
1326 std::shared_ptr<ContinueStatement> ContinueStatement::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1327  (void)ids;
1328  auto type = map.at("@t").as_string();
1329  if (type != "ContinueStatement") {
1330  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1331  }
1332  auto node = std::make_shared<ContinueStatement>(
1333  Any<AnnotationData>(map.at("annotations").as_map(), ids)
1334  );
1335  node->deserialize_annotations(map);
1336  return node;
1337 }
1338 
1343  : Annotated(annotations), model(model), name(name), parameters(parameters)
1344 {}
1345 
1349 void ErrorModel::find_reachable(::tree::base::PointerMap &map) const {
1350  (void)map;
1351  parameters.find_reachable(map);
1352  annotations.find_reachable(map);
1353 }
1354 
1358 void ErrorModel::check_complete(const ::tree::base::PointerMap &map) const {
1359  (void)map;
1360  parameters.check_complete(map);
1361  annotations.check_complete(map);
1362 }
1363 
1368  return NodeType::ErrorModel;
1369 }
1370 
1374 void ErrorModel::visit_internal(VisitorBase &visitor, void *retval) {
1375  visitor.raw_visit_error_model(*this, retval);
1376 }
1377 
1383  return dynamic_cast<ErrorModel*>(this);
1384 }
1385 
1391  return dynamic_cast<const ErrorModel*>(this);
1392 }
1393 
1398  return cqasm::tree::make<ErrorModel>(*this);
1399 }
1400 
1405  auto node = cqasm::tree::make<ErrorModel>(*this);
1406  node->parameters = this->parameters.clone();
1407  node->annotations = this->annotations.clone();
1408  return node;
1409 }
1410 
1414 bool ErrorModel::equals(const Node &rhs) const {
1415  if (rhs.type() != NodeType::ErrorModel) return false;
1416  auto rhsc = dynamic_cast<const ErrorModel&>(rhs);
1417  if (this->model != rhsc.model) return false;
1418  if (this->name != rhsc.name) return false;
1419  if (!this->parameters.equals(rhsc.parameters)) return false;
1420  if (!this->annotations.equals(rhsc.annotations)) return false;
1421  return true;
1422 }
1423 
1427 bool ErrorModel::operator==(const Node &rhs) const {
1428  if (rhs.type() != NodeType::ErrorModel) return false;
1429  auto rhsc = dynamic_cast<const ErrorModel&>(rhs);
1430  if (this->model != rhsc.model) return false;
1431  if (this->name != rhsc.name) return false;
1432  if (this->parameters != rhsc.parameters) return false;
1433  if (this->annotations != rhsc.annotations) return false;
1434  return true;
1435 }
1436 
1441  ::tree::cbor::MapWriter &map,
1442  const ::tree::base::PointerMap &ids
1443 ) const {
1444  (void)ids;
1445  map.append_string("@t", "ErrorModel");
1446  auto submap = map.append_map("model");
1447  cqasm::v1::primitives::serialize<cqasm::v1::error_model::ErrorModelRef>(model, submap);
1448  submap.close();
1449  submap = map.append_map("name");
1450  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(name, submap);
1451  submap.close();
1452  submap = map.append_map("parameters");
1453  parameters.serialize(submap, ids);
1454  submap.close();
1455  submap = map.append_map("annotations");
1456  annotations.serialize(submap, ids);
1457  submap.close();
1458  serialize_annotations(map);
1459 }
1460 
1464 std::shared_ptr<ErrorModel> ErrorModel::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1465  (void)ids;
1466  auto type = map.at("@t").as_string();
1467  if (type != "ErrorModel") {
1468  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1469  }
1470  auto node = std::make_shared<ErrorModel>(
1471  cqasm::v1::primitives::deserialize<cqasm::v1::error_model::ErrorModelRef>(map.at("model").as_map()),
1472  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at("name").as_map()),
1473  Any<cqasm::v1::values::Node>(map.at("parameters").as_map(), ids),
1474  Any<AnnotationData>(map.at("annotations").as_map(), ids)
1475  );
1476  node->deserialize_annotations(map);
1477  return node;
1478 }
1479 
1484  : Structured(annotations), initialize(initialize), condition(condition), update(update), body(body)
1485 {}
1486 
1490 void ForLoop::find_reachable(::tree::base::PointerMap &map) const {
1491  (void)map;
1492  initialize.find_reachable(map);
1493  condition.find_reachable(map);
1494  update.find_reachable(map);
1495  body.find_reachable(map);
1496  annotations.find_reachable(map);
1497 }
1498 
1502 void ForLoop::check_complete(const ::tree::base::PointerMap &map) const {
1503  (void)map;
1504  initialize.check_complete(map);
1505  condition.check_complete(map);
1506  update.check_complete(map);
1507  body.check_complete(map);
1508  annotations.check_complete(map);
1509 }
1510 
1515  return NodeType::ForLoop;
1516 }
1517 
1521 void ForLoop::visit_internal(VisitorBase &visitor, void *retval) {
1522  visitor.raw_visit_for_loop(*this, retval);
1523 }
1524 
1530  return dynamic_cast<ForLoop*>(this);
1531 }
1532 
1538  return dynamic_cast<const ForLoop*>(this);
1539 }
1540 
1545  return cqasm::tree::make<ForLoop>(*this);
1546 }
1547 
1552  auto node = cqasm::tree::make<ForLoop>(*this);
1553  node->initialize = this->initialize.clone();
1554  node->condition = this->condition.clone();
1555  node->update = this->update.clone();
1556  node->body = this->body.clone();
1557  node->annotations = this->annotations.clone();
1558  return node;
1559 }
1560 
1564 bool ForLoop::equals(const Node &rhs) const {
1565  if (rhs.type() != NodeType::ForLoop) return false;
1566  auto rhsc = dynamic_cast<const ForLoop&>(rhs);
1567  if (!this->initialize.equals(rhsc.initialize)) return false;
1568  if (!this->condition.equals(rhsc.condition)) return false;
1569  if (!this->update.equals(rhsc.update)) return false;
1570  if (!this->body.equals(rhsc.body)) return false;
1571  if (!this->annotations.equals(rhsc.annotations)) return false;
1572  return true;
1573 }
1574 
1578 bool ForLoop::operator==(const Node &rhs) const {
1579  if (rhs.type() != NodeType::ForLoop) return false;
1580  auto rhsc = dynamic_cast<const ForLoop&>(rhs);
1581  if (this->initialize != rhsc.initialize) return false;
1582  if (this->condition != rhsc.condition) return false;
1583  if (this->update != rhsc.update) return false;
1584  if (this->body != rhsc.body) return false;
1585  if (this->annotations != rhsc.annotations) return false;
1586  return true;
1587 }
1588 
1593  ::tree::cbor::MapWriter &map,
1594  const ::tree::base::PointerMap &ids
1595 ) const {
1596  (void)ids;
1597  map.append_string("@t", "ForLoop");
1598  auto submap = map.append_map("initialize");
1599  initialize.serialize(submap, ids);
1600  submap.close();
1601  submap = map.append_map("condition");
1602  condition.serialize(submap, ids);
1603  submap.close();
1604  submap = map.append_map("update");
1605  update.serialize(submap, ids);
1606  submap.close();
1607  submap = map.append_map("body");
1608  body.serialize(submap, ids);
1609  submap.close();
1610  submap = map.append_map("annotations");
1611  annotations.serialize(submap, ids);
1612  submap.close();
1613  serialize_annotations(map);
1614 }
1615 
1619 std::shared_ptr<ForLoop> ForLoop::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1620  (void)ids;
1621  auto type = map.at("@t").as_string();
1622  if (type != "ForLoop") {
1623  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1624  }
1625  auto node = std::make_shared<ForLoop>(
1626  Maybe<SetInstruction>(map.at("initialize").as_map(), ids),
1627  One<cqasm::v1::values::Node>(map.at("condition").as_map(), ids),
1628  Maybe<SetInstruction>(map.at("update").as_map(), ids),
1629  One<Block>(map.at("body").as_map(), ids),
1630  Any<AnnotationData>(map.at("annotations").as_map(), ids)
1631  );
1632  node->deserialize_annotations(map);
1633  return node;
1634 }
1635 
1640  : Structured(annotations), lhs(lhs), frm(frm), to(to), body(body)
1641 {}
1642 
1646 void ForeachLoop::find_reachable(::tree::base::PointerMap &map) const {
1647  (void)map;
1648  lhs.find_reachable(map);
1649  body.find_reachable(map);
1650  annotations.find_reachable(map);
1651 }
1652 
1656 void ForeachLoop::check_complete(const ::tree::base::PointerMap &map) const {
1657  (void)map;
1658  lhs.check_complete(map);
1659  body.check_complete(map);
1660  annotations.check_complete(map);
1661 }
1662 
1667  return NodeType::ForeachLoop;
1668 }
1669 
1673 void ForeachLoop::visit_internal(VisitorBase &visitor, void *retval) {
1674  visitor.raw_visit_foreach_loop(*this, retval);
1675 }
1676 
1682  return dynamic_cast<ForeachLoop*>(this);
1683 }
1684 
1690  return dynamic_cast<const ForeachLoop*>(this);
1691 }
1692 
1697  return cqasm::tree::make<ForeachLoop>(*this);
1698 }
1699 
1704  auto node = cqasm::tree::make<ForeachLoop>(*this);
1705  node->lhs = this->lhs.clone();
1706  node->body = this->body.clone();
1707  node->annotations = this->annotations.clone();
1708  return node;
1709 }
1710 
1714 bool ForeachLoop::equals(const Node &rhs) const {
1715  if (rhs.type() != NodeType::ForeachLoop) return false;
1716  auto rhsc = dynamic_cast<const ForeachLoop&>(rhs);
1717  if (!this->lhs.equals(rhsc.lhs)) return false;
1718  if (this->frm != rhsc.frm) return false;
1719  if (this->to != rhsc.to) return false;
1720  if (!this->body.equals(rhsc.body)) return false;
1721  if (!this->annotations.equals(rhsc.annotations)) return false;
1722  return true;
1723 }
1724 
1728 bool ForeachLoop::operator==(const Node &rhs) const {
1729  if (rhs.type() != NodeType::ForeachLoop) return false;
1730  auto rhsc = dynamic_cast<const ForeachLoop&>(rhs);
1731  if (this->lhs != rhsc.lhs) return false;
1732  if (this->frm != rhsc.frm) return false;
1733  if (this->to != rhsc.to) return false;
1734  if (this->body != rhsc.body) return false;
1735  if (this->annotations != rhsc.annotations) return false;
1736  return true;
1737 }
1738 
1743  ::tree::cbor::MapWriter &map,
1744  const ::tree::base::PointerMap &ids
1745 ) const {
1746  (void)ids;
1747  map.append_string("@t", "ForeachLoop");
1748  auto submap = map.append_map("lhs");
1749  lhs.serialize(submap, ids);
1750  submap.close();
1751  submap = map.append_map("frm");
1752  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(frm, submap);
1753  submap.close();
1754  submap = map.append_map("to");
1755  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(to, submap);
1756  submap.close();
1757  submap = map.append_map("body");
1758  body.serialize(submap, ids);
1759  submap.close();
1760  submap = map.append_map("annotations");
1761  annotations.serialize(submap, ids);
1762  submap.close();
1763  serialize_annotations(map);
1764 }
1765 
1769 std::shared_ptr<ForeachLoop> ForeachLoop::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1770  (void)ids;
1771  auto type = map.at("@t").as_string();
1772  if (type != "ForeachLoop") {
1773  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1774  }
1775  auto node = std::make_shared<ForeachLoop>(
1776  One<cqasm::v1::values::Node>(map.at("lhs").as_map(), ids),
1777  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at("frm").as_map()),
1778  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at("to").as_map()),
1779  One<Block>(map.at("body").as_map(), ids),
1780  Any<AnnotationData>(map.at("annotations").as_map(), ids)
1781  );
1782  node->deserialize_annotations(map);
1783  return node;
1784 }
1785 
1790  : Annotated(annotations), condition(condition)
1791 {}
1792 
1798  return dynamic_cast<InstructionBase*>(this);
1799 }
1800 
1806  return dynamic_cast<const InstructionBase*>(this);
1807 }
1808 
1812 std::shared_ptr<InstructionBase> InstructionBase::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1813  auto type = map.at("@t").as_string();
1814  if (type == "Instruction") return Instruction::deserialize(map, ids);
1815  if (type == "SetInstruction") return SetInstruction::deserialize(map, ids);
1816  if (type == "GotoInstruction") return GotoInstruction::deserialize(map, ids);
1817  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1818 }
1819 
1824  : InstructionBase(condition, annotations), target(target)
1825 {}
1826 
1830 void GotoInstruction::find_reachable(::tree::base::PointerMap &map) const {
1831  (void)map;
1832  target.find_reachable(map);
1833  condition.find_reachable(map);
1834  annotations.find_reachable(map);
1835 }
1836 
1840 void GotoInstruction::check_complete(const ::tree::base::PointerMap &map) const {
1841  (void)map;
1842  target.check_complete(map);
1843  condition.check_complete(map);
1844  annotations.check_complete(map);
1845 }
1846 
1852 }
1853 
1857 void GotoInstruction::visit_internal(VisitorBase &visitor, void *retval) {
1858  visitor.raw_visit_goto_instruction(*this, retval);
1859 }
1860 
1866  return dynamic_cast<GotoInstruction*>(this);
1867 }
1868 
1874  return dynamic_cast<const GotoInstruction*>(this);
1875 }
1876 
1881  return cqasm::tree::make<GotoInstruction>(*this);
1882 }
1883 
1888  auto node = cqasm::tree::make<GotoInstruction>(*this);
1889  node->condition = this->condition.clone();
1890  node->annotations = this->annotations.clone();
1891  return node;
1892 }
1893 
1897 bool GotoInstruction::equals(const Node &rhs) const {
1898  if (rhs.type() != NodeType::GotoInstruction) return false;
1899  auto rhsc = dynamic_cast<const GotoInstruction&>(rhs);
1900  if (!this->target.equals(rhsc.target)) return false;
1901  if (!this->condition.equals(rhsc.condition)) return false;
1902  if (!this->annotations.equals(rhsc.annotations)) return false;
1903  return true;
1904 }
1905 
1909 bool GotoInstruction::operator==(const Node &rhs) const {
1910  if (rhs.type() != NodeType::GotoInstruction) return false;
1911  auto rhsc = dynamic_cast<const GotoInstruction&>(rhs);
1912  if (this->target != rhsc.target) return false;
1913  if (this->condition != rhsc.condition) return false;
1914  if (this->annotations != rhsc.annotations) return false;
1915  return true;
1916 }
1917 
1922  ::tree::cbor::MapWriter &map,
1923  const ::tree::base::PointerMap &ids
1924 ) const {
1925  (void)ids;
1926  map.append_string("@t", "GotoInstruction");
1927  auto submap = map.append_map("target");
1928  target.serialize(submap, ids);
1929  submap.close();
1930  submap = map.append_map("condition");
1931  condition.serialize(submap, ids);
1932  submap.close();
1933  submap = map.append_map("annotations");
1934  annotations.serialize(submap, ids);
1935  submap.close();
1936  serialize_annotations(map);
1937 }
1938 
1942 std::shared_ptr<GotoInstruction> GotoInstruction::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1943  (void)ids;
1944  auto type = map.at("@t").as_string();
1945  if (type != "GotoInstruction") {
1946  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1947  }
1948  auto node = std::make_shared<GotoInstruction>(
1949  Link<Subcircuit>(map.at("target").as_map(), ids),
1950  One<cqasm::v1::values::Node>(map.at("condition").as_map(), ids),
1951  Any<AnnotationData>(map.at("annotations").as_map(), ids)
1952  );
1953  auto link = map.at("target").as_map().at("@l");
1954  if (!link.is_null()) {
1955  ids.register_link(node->target, link.as_int());
1956  }
1957  node->deserialize_annotations(map);
1958  return node;
1959 }
1960 
1965  : Structured(annotations), branches(branches), otherwise(otherwise)
1966 {}
1967 
1971 void IfElse::find_reachable(::tree::base::PointerMap &map) const {
1972  (void)map;
1973  branches.find_reachable(map);
1974  otherwise.find_reachable(map);
1975  annotations.find_reachable(map);
1976 }
1977 
1981 void IfElse::check_complete(const ::tree::base::PointerMap &map) const {
1982  (void)map;
1983  branches.check_complete(map);
1984  otherwise.check_complete(map);
1985  annotations.check_complete(map);
1986 }
1987 
1992  return NodeType::IfElse;
1993 }
1994 
1998 void IfElse::visit_internal(VisitorBase &visitor, void *retval) {
1999  visitor.raw_visit_if_else(*this, retval);
2000 }
2001 
2007  return dynamic_cast<IfElse*>(this);
2008 }
2009 
2014 const IfElse *IfElse::as_if_else() const {
2015  return dynamic_cast<const IfElse*>(this);
2016 }
2017 
2022  return cqasm::tree::make<IfElse>(*this);
2023 }
2024 
2029  auto node = cqasm::tree::make<IfElse>(*this);
2030  node->branches = this->branches.clone();
2031  node->otherwise = this->otherwise.clone();
2032  node->annotations = this->annotations.clone();
2033  return node;
2034 }
2035 
2039 bool IfElse::equals(const Node &rhs) const {
2040  if (rhs.type() != NodeType::IfElse) return false;
2041  auto rhsc = dynamic_cast<const IfElse&>(rhs);
2042  if (!this->branches.equals(rhsc.branches)) return false;
2043  if (!this->otherwise.equals(rhsc.otherwise)) return false;
2044  if (!this->annotations.equals(rhsc.annotations)) return false;
2045  return true;
2046 }
2047 
2051 bool IfElse::operator==(const Node &rhs) const {
2052  if (rhs.type() != NodeType::IfElse) return false;
2053  auto rhsc = dynamic_cast<const IfElse&>(rhs);
2054  if (this->branches != rhsc.branches) return false;
2055  if (this->otherwise != rhsc.otherwise) return false;
2056  if (this->annotations != rhsc.annotations) return false;
2057  return true;
2058 }
2059 
2064  ::tree::cbor::MapWriter &map,
2065  const ::tree::base::PointerMap &ids
2066 ) const {
2067  (void)ids;
2068  map.append_string("@t", "IfElse");
2069  auto submap = map.append_map("branches");
2070  branches.serialize(submap, ids);
2071  submap.close();
2072  submap = map.append_map("otherwise");
2073  otherwise.serialize(submap, ids);
2074  submap.close();
2075  submap = map.append_map("annotations");
2076  annotations.serialize(submap, ids);
2077  submap.close();
2078  serialize_annotations(map);
2079 }
2080 
2084 std::shared_ptr<IfElse> IfElse::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
2085  (void)ids;
2086  auto type = map.at("@t").as_string();
2087  if (type != "IfElse") {
2088  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
2089  }
2090  auto node = std::make_shared<IfElse>(
2091  Many<IfElseBranch>(map.at("branches").as_map(), ids),
2092  Maybe<Block>(map.at("otherwise").as_map(), ids),
2093  Any<AnnotationData>(map.at("annotations").as_map(), ids)
2094  );
2095  node->deserialize_annotations(map);
2096  return node;
2097 }
2098 
2103  : condition(condition), body(body)
2104 {}
2105 
2109 void IfElseBranch::find_reachable(::tree::base::PointerMap &map) const {
2110  (void)map;
2111  condition.find_reachable(map);
2112  body.find_reachable(map);
2113 }
2114 
2118 void IfElseBranch::check_complete(const ::tree::base::PointerMap &map) const {
2119  (void)map;
2120  condition.check_complete(map);
2121  body.check_complete(map);
2122 }
2123 
2128  return NodeType::IfElseBranch;
2129 }
2130 
2134 void IfElseBranch::visit_internal(VisitorBase &visitor, void *retval) {
2135  visitor.raw_visit_if_else_branch(*this, retval);
2136 }
2137 
2143  return dynamic_cast<IfElseBranch*>(this);
2144 }
2145 
2151  return dynamic_cast<const IfElseBranch*>(this);
2152 }
2153 
2158  return cqasm::tree::make<IfElseBranch>(*this);
2159 }
2160 
2165  auto node = cqasm::tree::make<IfElseBranch>(*this);
2166  node->condition = this->condition.clone();
2167  node->body = this->body.clone();
2168  return node;
2169 }
2170 
2174 bool IfElseBranch::equals(const Node &rhs) const {
2175  if (rhs.type() != NodeType::IfElseBranch) return false;
2176  auto rhsc = dynamic_cast<const IfElseBranch&>(rhs);
2177  if (!this->condition.equals(rhsc.condition)) return false;
2178  if (!this->body.equals(rhsc.body)) return false;
2179  return true;
2180 }
2181 
2185 bool IfElseBranch::operator==(const Node &rhs) const {
2186  if (rhs.type() != NodeType::IfElseBranch) return false;
2187  auto rhsc = dynamic_cast<const IfElseBranch&>(rhs);
2188  if (this->condition != rhsc.condition) return false;
2189  if (this->body != rhsc.body) return false;
2190  return true;
2191 }
2192 
2197  ::tree::cbor::MapWriter &map,
2198  const ::tree::base::PointerMap &ids
2199 ) const {
2200  (void)ids;
2201  map.append_string("@t", "IfElseBranch");
2202  auto submap = map.append_map("condition");
2203  condition.serialize(submap, ids);
2204  submap.close();
2205  submap = map.append_map("body");
2206  body.serialize(submap, ids);
2207  submap.close();
2208  serialize_annotations(map);
2209 }
2210 
2214 std::shared_ptr<IfElseBranch> IfElseBranch::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
2215  (void)ids;
2216  auto type = map.at("@t").as_string();
2217  if (type != "IfElseBranch") {
2218  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
2219  }
2220  auto node = std::make_shared<IfElseBranch>(
2221  One<cqasm::v1::values::Node>(map.at("condition").as_map(), ids),
2222  One<Block>(map.at("body").as_map(), ids)
2223  );
2224  node->deserialize_annotations(map);
2225  return node;
2226 }
2227 
2232  : InstructionBase(condition, annotations), instruction(instruction), name(name), operands(operands)
2233 {}
2234 
2238 void Instruction::find_reachable(::tree::base::PointerMap &map) const {
2239  (void)map;
2240  condition.find_reachable(map);
2241  operands.find_reachable(map);
2242  annotations.find_reachable(map);
2243 }
2244 
2248 void Instruction::check_complete(const ::tree::base::PointerMap &map) const {
2249  (void)map;
2250  condition.check_complete(map);
2251  operands.check_complete(map);
2252  annotations.check_complete(map);
2253 }
2254 
2259  return NodeType::Instruction;
2260 }
2261 
2265 void Instruction::visit_internal(VisitorBase &visitor, void *retval) {
2266  visitor.raw_visit_instruction(*this, retval);
2267 }
2268 
2274  return dynamic_cast<Instruction*>(this);
2275 }
2276 
2282  return dynamic_cast<const Instruction*>(this);
2283 }
2284 
2289  return cqasm::tree::make<Instruction>(*this);
2290 }
2291 
2296  auto node = cqasm::tree::make<Instruction>(*this);
2297  node->condition = this->condition.clone();
2298  node->operands = this->operands.clone();
2299  node->annotations = this->annotations.clone();
2300  return node;
2301 }
2302 
2306 bool Instruction::equals(const Node &rhs) const {
2307  if (rhs.type() != NodeType::Instruction) return false;
2308  auto rhsc = dynamic_cast<const Instruction&>(rhs);
2309  if (this->instruction != rhsc.instruction) return false;
2310  if (this->name != rhsc.name) return false;
2311  if (!this->condition.equals(rhsc.condition)) return false;
2312  if (!this->operands.equals(rhsc.operands)) return false;
2313  if (!this->annotations.equals(rhsc.annotations)) return false;
2314  return true;
2315 }
2316 
2320 bool Instruction::operator==(const Node &rhs) const {
2321  if (rhs.type() != NodeType::Instruction) return false;
2322  auto rhsc = dynamic_cast<const Instruction&>(rhs);
2323  if (this->instruction != rhsc.instruction) return false;
2324  if (this->name != rhsc.name) return false;
2325  if (this->condition != rhsc.condition) return false;
2326  if (this->operands != rhsc.operands) return false;
2327  if (this->annotations != rhsc.annotations) return false;
2328  return true;
2329 }
2330 
2335  ::tree::cbor::MapWriter &map,
2336  const ::tree::base::PointerMap &ids
2337 ) const {
2338  (void)ids;
2339  map.append_string("@t", "Instruction");
2340  auto submap = map.append_map("instruction");
2341  cqasm::v1::primitives::serialize<cqasm::v1::instruction::InstructionRef>(instruction, submap);
2342  submap.close();
2343  submap = map.append_map("name");
2344  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(name, submap);
2345  submap.close();
2346  submap = map.append_map("condition");
2347  condition.serialize(submap, ids);
2348  submap.close();
2349  submap = map.append_map("operands");
2350  operands.serialize(submap, ids);
2351  submap.close();
2352  submap = map.append_map("annotations");
2353  annotations.serialize(submap, ids);
2354  submap.close();
2355  serialize_annotations(map);
2356 }
2357 
2361 std::shared_ptr<Instruction> Instruction::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
2362  (void)ids;
2363  auto type = map.at("@t").as_string();
2364  if (type != "Instruction") {
2365  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
2366  }
2367  auto node = std::make_shared<Instruction>(
2368  cqasm::v1::primitives::deserialize<cqasm::v1::instruction::InstructionRef>(map.at("instruction").as_map()),
2369  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at("name").as_map()),
2370  One<cqasm::v1::values::Node>(map.at("condition").as_map(), ids),
2371  Any<cqasm::v1::values::Node>(map.at("operands").as_map(), ids),
2372  Any<AnnotationData>(map.at("annotations").as_map(), ids)
2373  );
2374  node->deserialize_annotations(map);
2375  return node;
2376 }
2377 
2382  : Annotated(annotations), name(name), value(value)
2383 {}
2384 
2388 void Mapping::find_reachable(::tree::base::PointerMap &map) const {
2389  (void)map;
2390  value.find_reachable(map);
2391  annotations.find_reachable(map);
2392 }
2393 
2397 void Mapping::check_complete(const ::tree::base::PointerMap &map) const {
2398  (void)map;
2399  value.check_complete(map);
2400  annotations.check_complete(map);
2401 }
2402 
2407  return NodeType::Mapping;
2408 }
2409 
2413 void Mapping::visit_internal(VisitorBase &visitor, void *retval) {
2414  visitor.raw_visit_mapping(*this, retval);
2415 }
2416 
2422  return dynamic_cast<Mapping*>(this);
2423 }
2424 
2430  return dynamic_cast<const Mapping*>(this);
2431 }
2432 
2437  return cqasm::tree::make<Mapping>(*this);
2438 }
2439 
2444  auto node = cqasm::tree::make<Mapping>(*this);
2445  node->value = this->value.clone();
2446  node->annotations = this->annotations.clone();
2447  return node;
2448 }
2449 
2453 bool Mapping::equals(const Node &rhs) const {
2454  if (rhs.type() != NodeType::Mapping) return false;
2455  auto rhsc = dynamic_cast<const Mapping&>(rhs);
2456  if (this->name != rhsc.name) return false;
2457  if (!this->value.equals(rhsc.value)) return false;
2458  if (!this->annotations.equals(rhsc.annotations)) return false;
2459  return true;
2460 }
2461 
2465 bool Mapping::operator==(const Node &rhs) const {
2466  if (rhs.type() != NodeType::Mapping) return false;
2467  auto rhsc = dynamic_cast<const Mapping&>(rhs);
2468  if (this->name != rhsc.name) return false;
2469  if (this->value != rhsc.value) return false;
2470  if (this->annotations != rhsc.annotations) return false;
2471  return true;
2472 }
2473 
2478  ::tree::cbor::MapWriter &map,
2479  const ::tree::base::PointerMap &ids
2480 ) const {
2481  (void)ids;
2482  map.append_string("@t", "Mapping");
2483  auto submap = map.append_map("name");
2484  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(name, submap);
2485  submap.close();
2486  submap = map.append_map("value");
2487  value.serialize(submap, ids);
2488  submap.close();
2489  submap = map.append_map("annotations");
2490  annotations.serialize(submap, ids);
2491  submap.close();
2492  serialize_annotations(map);
2493 }
2494 
2498 std::shared_ptr<Mapping> Mapping::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
2499  (void)ids;
2500  auto type = map.at("@t").as_string();
2501  if (type != "Mapping") {
2502  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
2503  }
2504  auto node = std::make_shared<Mapping>(
2505  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at("name").as_map()),
2506  One<cqasm::v1::values::Node>(map.at("value").as_map(), ids),
2507  Any<AnnotationData>(map.at("annotations").as_map(), ids)
2508  );
2509  node->deserialize_annotations(map);
2510  return node;
2511 }
2512 
2516 Program::Program(const One<Version> &version, const cqasm::v1::primitives::Int &num_qubits, const Maybe<ErrorModel> &error_model, const Any<Subcircuit> &subcircuits, const Any<Mapping> &mappings, const Any<Variable> &variables, const cqasm::v1::primitives::Version &api_version)
2517  : version(version), num_qubits(num_qubits), error_model(error_model), subcircuits(subcircuits), mappings(mappings), variables(variables), api_version(api_version)
2518 {}
2519 
2523 void Program::find_reachable(::tree::base::PointerMap &map) const {
2524  (void)map;
2525  version.find_reachable(map);
2526  error_model.find_reachable(map);
2527  subcircuits.find_reachable(map);
2528  mappings.find_reachable(map);
2529  variables.find_reachable(map);
2530 }
2531 
2535 void Program::check_complete(const ::tree::base::PointerMap &map) const {
2536  (void)map;
2537  version.check_complete(map);
2538  error_model.check_complete(map);
2539  subcircuits.check_complete(map);
2540  mappings.check_complete(map);
2541  variables.check_complete(map);
2542 }
2543 
2548  return NodeType::Program;
2549 }
2550 
2554 void Program::visit_internal(VisitorBase &visitor, void *retval) {
2555  visitor.raw_visit_program(*this, retval);
2556 }
2557 
2563  return dynamic_cast<Program*>(this);
2564 }
2565 
2571  return dynamic_cast<const Program*>(this);
2572 }
2573 
2578  return cqasm::tree::make<Program>(*this);
2579 }
2580 
2585  auto node = cqasm::tree::make<Program>(*this);
2586  node->version = this->version.clone();
2587  node->error_model = this->error_model.clone();
2588  node->subcircuits = this->subcircuits.clone();
2589  node->mappings = this->mappings.clone();
2590  node->variables = this->variables.clone();
2591  return node;
2592 }
2593 
2597 bool Program::equals(const Node &rhs) const {
2598  if (rhs.type() != NodeType::Program) return false;
2599  auto rhsc = dynamic_cast<const Program&>(rhs);
2600  if (!this->version.equals(rhsc.version)) return false;
2601  if (this->num_qubits != rhsc.num_qubits) return false;
2602  if (!this->error_model.equals(rhsc.error_model)) return false;
2603  if (!this->subcircuits.equals(rhsc.subcircuits)) return false;
2604  if (!this->mappings.equals(rhsc.mappings)) return false;
2605  if (!this->variables.equals(rhsc.variables)) return false;
2606  if (this->api_version != rhsc.api_version) return false;
2607  return true;
2608 }
2609 
2613 bool Program::operator==(const Node &rhs) const {
2614  if (rhs.type() != NodeType::Program) return false;
2615  auto rhsc = dynamic_cast<const Program&>(rhs);
2616  if (this->version != rhsc.version) return false;
2617  if (this->num_qubits != rhsc.num_qubits) return false;
2618  if (this->error_model != rhsc.error_model) return false;
2619  if (this->subcircuits != rhsc.subcircuits) return false;
2620  if (this->mappings != rhsc.mappings) return false;
2621  if (this->variables != rhsc.variables) return false;
2622  if (this->api_version != rhsc.api_version) return false;
2623  return true;
2624 }
2625 
2630  ::tree::cbor::MapWriter &map,
2631  const ::tree::base::PointerMap &ids
2632 ) const {
2633  (void)ids;
2634  map.append_string("@t", "Program");
2635  auto submap = map.append_map("version");
2636  version.serialize(submap, ids);
2637  submap.close();
2638  submap = map.append_map("num_qubits");
2639  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(num_qubits, submap);
2640  submap.close();
2641  submap = map.append_map("error_model");
2642  error_model.serialize(submap, ids);
2643  submap.close();
2644  submap = map.append_map("subcircuits");
2645  subcircuits.serialize(submap, ids);
2646  submap.close();
2647  submap = map.append_map("mappings");
2648  mappings.serialize(submap, ids);
2649  submap.close();
2650  submap = map.append_map("variables");
2651  variables.serialize(submap, ids);
2652  submap.close();
2653  submap = map.append_map("api_version");
2654  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Version>(api_version, submap);
2655  submap.close();
2656  serialize_annotations(map);
2657 }
2658 
2662 std::shared_ptr<Program> Program::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
2663  (void)ids;
2664  auto type = map.at("@t").as_string();
2665  if (type != "Program") {
2666  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
2667  }
2668  auto node = std::make_shared<Program>(
2669  One<Version>(map.at("version").as_map(), ids),
2670  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at("num_qubits").as_map()),
2671  Maybe<ErrorModel>(map.at("error_model").as_map(), ids),
2672  Any<Subcircuit>(map.at("subcircuits").as_map(), ids),
2673  Any<Mapping>(map.at("mappings").as_map(), ids),
2674  Any<Variable>(map.at("variables").as_map(), ids),
2675  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Version>(map.at("api_version").as_map())
2676  );
2677  node->deserialize_annotations(map);
2678  return node;
2679 }
2680 
2685  : Structured(annotations), body(body), condition(condition)
2686 {}
2687 
2691 void RepeatUntilLoop::find_reachable(::tree::base::PointerMap &map) const {
2692  (void)map;
2693  body.find_reachable(map);
2694  condition.find_reachable(map);
2695  annotations.find_reachable(map);
2696 }
2697 
2701 void RepeatUntilLoop::check_complete(const ::tree::base::PointerMap &map) const {
2702  (void)map;
2703  body.check_complete(map);
2704  condition.check_complete(map);
2705  annotations.check_complete(map);
2706 }
2707 
2713 }
2714 
2718 void RepeatUntilLoop::visit_internal(VisitorBase &visitor, void *retval) {
2719  visitor.raw_visit_repeat_until_loop(*this, retval);
2720 }
2721 
2727  return dynamic_cast<RepeatUntilLoop*>(this);
2728 }
2729 
2735  return dynamic_cast<const RepeatUntilLoop*>(this);
2736 }
2737 
2742  return cqasm::tree::make<RepeatUntilLoop>(*this);
2743 }
2744 
2749  auto node = cqasm::tree::make<RepeatUntilLoop>(*this);
2750  node->body = this->body.clone();
2751  node->condition = this->condition.clone();
2752  node->annotations = this->annotations.clone();
2753  return node;
2754 }
2755 
2759 bool RepeatUntilLoop::equals(const Node &rhs) const {
2760  if (rhs.type() != NodeType::RepeatUntilLoop) return false;
2761  auto rhsc = dynamic_cast<const RepeatUntilLoop&>(rhs);
2762  if (!this->body.equals(rhsc.body)) return false;
2763  if (!this->condition.equals(rhsc.condition)) return false;
2764  if (!this->annotations.equals(rhsc.annotations)) return false;
2765  return true;
2766 }
2767 
2771 bool RepeatUntilLoop::operator==(const Node &rhs) const {
2772  if (rhs.type() != NodeType::RepeatUntilLoop) return false;
2773  auto rhsc = dynamic_cast<const RepeatUntilLoop&>(rhs);
2774  if (this->body != rhsc.body) return false;
2775  if (this->condition != rhsc.condition) return false;
2776  if (this->annotations != rhsc.annotations) return false;
2777  return true;
2778 }
2779 
2784  ::tree::cbor::MapWriter &map,
2785  const ::tree::base::PointerMap &ids
2786 ) const {
2787  (void)ids;
2788  map.append_string("@t", "RepeatUntilLoop");
2789  auto submap = map.append_map("body");
2790  body.serialize(submap, ids);
2791  submap.close();
2792  submap = map.append_map("condition");
2793  condition.serialize(submap, ids);
2794  submap.close();
2795  submap = map.append_map("annotations");
2796  annotations.serialize(submap, ids);
2797  submap.close();
2798  serialize_annotations(map);
2799 }
2800 
2804 std::shared_ptr<RepeatUntilLoop> RepeatUntilLoop::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
2805  (void)ids;
2806  auto type = map.at("@t").as_string();
2807  if (type != "RepeatUntilLoop") {
2808  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
2809  }
2810  auto node = std::make_shared<RepeatUntilLoop>(
2811  One<Block>(map.at("body").as_map(), ids),
2812  One<cqasm::v1::values::Node>(map.at("condition").as_map(), ids),
2813  Any<AnnotationData>(map.at("annotations").as_map(), ids)
2814  );
2815  node->deserialize_annotations(map);
2816  return node;
2817 }
2818 
2823  : InstructionBase(condition, annotations), lhs(lhs), rhs(rhs)
2824 {}
2825 
2829 void SetInstruction::find_reachable(::tree::base::PointerMap &map) const {
2830  (void)map;
2831  lhs.find_reachable(map);
2832  rhs.find_reachable(map);
2833  condition.find_reachable(map);
2834  annotations.find_reachable(map);
2835 }
2836 
2840 void SetInstruction::check_complete(const ::tree::base::PointerMap &map) const {
2841  (void)map;
2842  lhs.check_complete(map);
2843  rhs.check_complete(map);
2844  condition.check_complete(map);
2845  annotations.check_complete(map);
2846 }
2847 
2852  return NodeType::SetInstruction;
2853 }
2854 
2858 void SetInstruction::visit_internal(VisitorBase &visitor, void *retval) {
2859  visitor.raw_visit_set_instruction(*this, retval);
2860 }
2861 
2867  return dynamic_cast<SetInstruction*>(this);
2868 }
2869 
2875  return dynamic_cast<const SetInstruction*>(this);
2876 }
2877 
2882  return cqasm::tree::make<SetInstruction>(*this);
2883 }
2884 
2889  auto node = cqasm::tree::make<SetInstruction>(*this);
2890  node->lhs = this->lhs.clone();
2891  node->rhs = this->rhs.clone();
2892  node->condition = this->condition.clone();
2893  node->annotations = this->annotations.clone();
2894  return node;
2895 }
2896 
2900 bool SetInstruction::equals(const Node &rhs) const {
2901  if (rhs.type() != NodeType::SetInstruction) return false;
2902  auto rhsc = dynamic_cast<const SetInstruction&>(rhs);
2903  if (!this->lhs.equals(rhsc.lhs)) return false;
2904  if (!this->rhs.equals(rhsc.rhs)) return false;
2905  if (!this->condition.equals(rhsc.condition)) return false;
2906  if (!this->annotations.equals(rhsc.annotations)) return false;
2907  return true;
2908 }
2909 
2914  if (rhs.type() != NodeType::SetInstruction) return false;
2915  auto rhsc = dynamic_cast<const SetInstruction&>(rhs);
2916  if (this->lhs != rhsc.lhs) return false;
2917  if (this->rhs != rhsc.rhs) return false;
2918  if (this->condition != rhsc.condition) return false;
2919  if (this->annotations != rhsc.annotations) return false;
2920  return true;
2921 }
2922 
2927  ::tree::cbor::MapWriter &map,
2928  const ::tree::base::PointerMap &ids
2929 ) const {
2930  (void)ids;
2931  map.append_string("@t", "SetInstruction");
2932  auto submap = map.append_map("lhs");
2933  lhs.serialize(submap, ids);
2934  submap.close();
2935  submap = map.append_map("rhs");
2936  rhs.serialize(submap, ids);
2937  submap.close();
2938  submap = map.append_map("condition");
2939  condition.serialize(submap, ids);
2940  submap.close();
2941  submap = map.append_map("annotations");
2942  annotations.serialize(submap, ids);
2943  submap.close();
2944  serialize_annotations(map);
2945 }
2946 
2950 std::shared_ptr<SetInstruction> SetInstruction::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
2951  (void)ids;
2952  auto type = map.at("@t").as_string();
2953  if (type != "SetInstruction") {
2954  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
2955  }
2956  auto node = std::make_shared<SetInstruction>(
2957  One<cqasm::v1::values::Node>(map.at("lhs").as_map(), ids),
2958  One<cqasm::v1::values::Node>(map.at("rhs").as_map(), ids),
2959  One<cqasm::v1::values::Node>(map.at("condition").as_map(), ids),
2960  Any<AnnotationData>(map.at("annotations").as_map(), ids)
2961  );
2962  node->deserialize_annotations(map);
2963  return node;
2964 }
2965 
2970  : Annotated(annotations), name(name), iterations(iterations), bundles(bundles), body(body)
2971 {}
2972 
2976 void Subcircuit::find_reachable(::tree::base::PointerMap &map) const {
2977  (void)map;
2978  bundles.find_reachable(map);
2979  annotations.find_reachable(map);
2980  body.find_reachable(map);
2981 }
2982 
2986 void Subcircuit::check_complete(const ::tree::base::PointerMap &map) const {
2987  (void)map;
2988  bundles.check_complete(map);
2989  annotations.check_complete(map);
2990  body.check_complete(map);
2991 }
2992 
2997  return NodeType::Subcircuit;
2998 }
2999 
3003 void Subcircuit::visit_internal(VisitorBase &visitor, void *retval) {
3004  visitor.raw_visit_subcircuit(*this, retval);
3005 }
3006 
3012  return dynamic_cast<Subcircuit*>(this);
3013 }
3014 
3020  return dynamic_cast<const Subcircuit*>(this);
3021 }
3022 
3027  return cqasm::tree::make<Subcircuit>(*this);
3028 }
3029 
3034  auto node = cqasm::tree::make<Subcircuit>(*this);
3035  node->bundles = this->bundles.clone();
3036  node->annotations = this->annotations.clone();
3037  node->body = this->body.clone();
3038  return node;
3039 }
3040 
3044 bool Subcircuit::equals(const Node &rhs) const {
3045  if (rhs.type() != NodeType::Subcircuit) return false;
3046  auto rhsc = dynamic_cast<const Subcircuit&>(rhs);
3047  if (this->name != rhsc.name) return false;
3048  if (this->iterations != rhsc.iterations) return false;
3049  if (!this->bundles.equals(rhsc.bundles)) return false;
3050  if (!this->annotations.equals(rhsc.annotations)) return false;
3051  if (!this->body.equals(rhsc.body)) return false;
3052  return true;
3053 }
3054 
3058 bool Subcircuit::operator==(const Node &rhs) const {
3059  if (rhs.type() != NodeType::Subcircuit) return false;
3060  auto rhsc = dynamic_cast<const Subcircuit&>(rhs);
3061  if (this->name != rhsc.name) return false;
3062  if (this->iterations != rhsc.iterations) return false;
3063  if (this->bundles != rhsc.bundles) return false;
3064  if (this->annotations != rhsc.annotations) return false;
3065  if (this->body != rhsc.body) return false;
3066  return true;
3067 }
3068 
3073  ::tree::cbor::MapWriter &map,
3074  const ::tree::base::PointerMap &ids
3075 ) const {
3076  (void)ids;
3077  map.append_string("@t", "Subcircuit");
3078  auto submap = map.append_map("name");
3079  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(name, submap);
3080  submap.close();
3081  submap = map.append_map("iterations");
3082  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(iterations, submap);
3083  submap.close();
3084  submap = map.append_map("bundles");
3085  bundles.serialize(submap, ids);
3086  submap.close();
3087  submap = map.append_map("annotations");
3088  annotations.serialize(submap, ids);
3089  submap.close();
3090  submap = map.append_map("body");
3091  body.serialize(submap, ids);
3092  submap.close();
3093  serialize_annotations(map);
3094 }
3095 
3099 std::shared_ptr<Subcircuit> Subcircuit::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
3100  (void)ids;
3101  auto type = map.at("@t").as_string();
3102  if (type != "Subcircuit") {
3103  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
3104  }
3105  auto node = std::make_shared<Subcircuit>(
3106  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at("name").as_map()),
3107  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at("iterations").as_map()),
3108  Any<Bundle>(map.at("bundles").as_map(), ids),
3109  Any<AnnotationData>(map.at("annotations").as_map(), ids),
3110  Maybe<Block>(map.at("body").as_map(), ids)
3111  );
3112  node->deserialize_annotations(map);
3113  return node;
3114 }
3115 
3120  : Annotated(annotations), name(name), typ(typ)
3121 {}
3122 
3126 void Variable::find_reachable(::tree::base::PointerMap &map) const {
3127  (void)map;
3128  typ.find_reachable(map);
3129  annotations.find_reachable(map);
3130 }
3131 
3135 void Variable::check_complete(const ::tree::base::PointerMap &map) const {
3136  (void)map;
3137  typ.check_complete(map);
3138  annotations.check_complete(map);
3139 }
3140 
3145  return NodeType::Variable;
3146 }
3147 
3151 void Variable::visit_internal(VisitorBase &visitor, void *retval) {
3152  visitor.raw_visit_variable(*this, retval);
3153 }
3154 
3160  return dynamic_cast<Variable*>(this);
3161 }
3162 
3168  return dynamic_cast<const Variable*>(this);
3169 }
3170 
3175  return cqasm::tree::make<Variable>(*this);
3176 }
3177 
3182  auto node = cqasm::tree::make<Variable>(*this);
3183  node->typ = this->typ.clone();
3184  node->annotations = this->annotations.clone();
3185  return node;
3186 }
3187 
3191 bool Variable::equals(const Node &rhs) const {
3192  if (rhs.type() != NodeType::Variable) return false;
3193  auto rhsc = dynamic_cast<const Variable&>(rhs);
3194  if (this->name != rhsc.name) return false;
3195  if (!this->typ.equals(rhsc.typ)) return false;
3196  if (!this->annotations.equals(rhsc.annotations)) return false;
3197  return true;
3198 }
3199 
3203 bool Variable::operator==(const Node &rhs) const {
3204  if (rhs.type() != NodeType::Variable) return false;
3205  auto rhsc = dynamic_cast<const Variable&>(rhs);
3206  if (this->name != rhsc.name) return false;
3207  if (this->typ != rhsc.typ) return false;
3208  if (this->annotations != rhsc.annotations) return false;
3209  return true;
3210 }
3211 
3216  ::tree::cbor::MapWriter &map,
3217  const ::tree::base::PointerMap &ids
3218 ) const {
3219  (void)ids;
3220  map.append_string("@t", "Variable");
3221  auto submap = map.append_map("name");
3222  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(name, submap);
3223  submap.close();
3224  submap = map.append_map("typ");
3225  typ.serialize(submap, ids);
3226  submap.close();
3227  submap = map.append_map("annotations");
3228  annotations.serialize(submap, ids);
3229  submap.close();
3230  serialize_annotations(map);
3231 }
3232 
3236 std::shared_ptr<Variable> Variable::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
3237  (void)ids;
3238  auto type = map.at("@t").as_string();
3239  if (type != "Variable") {
3240  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
3241  }
3242  auto node = std::make_shared<Variable>(
3243  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at("name").as_map()),
3244  One<cqasm::v1::types::Node>(map.at("typ").as_map(), ids),
3245  Any<AnnotationData>(map.at("annotations").as_map(), ids)
3246  );
3247  node->deserialize_annotations(map);
3248  return node;
3249 }
3250 
3255  : items(items)
3256 {}
3257 
3261 void Version::find_reachable(::tree::base::PointerMap &map) const {
3262  (void)map;
3263 }
3264 
3268 void Version::check_complete(const ::tree::base::PointerMap &map) const {
3269  (void)map;
3270 }
3271 
3276  return NodeType::Version;
3277 }
3278 
3282 void Version::visit_internal(VisitorBase &visitor, void *retval) {
3283  visitor.raw_visit_version(*this, retval);
3284 }
3285 
3291  return dynamic_cast<Version*>(this);
3292 }
3293 
3299  return dynamic_cast<const Version*>(this);
3300 }
3301 
3306  return cqasm::tree::make<Version>(*this);
3307 }
3308 
3313  auto node = cqasm::tree::make<Version>(*this);
3314  return node;
3315 }
3316 
3320 bool Version::equals(const Node &rhs) const {
3321  if (rhs.type() != NodeType::Version) return false;
3322  auto rhsc = dynamic_cast<const Version&>(rhs);
3323  if (this->items != rhsc.items) return false;
3324  return true;
3325 }
3326 
3330 bool Version::operator==(const Node &rhs) const {
3331  if (rhs.type() != NodeType::Version) return false;
3332  auto rhsc = dynamic_cast<const Version&>(rhs);
3333  if (this->items != rhsc.items) return false;
3334  return true;
3335 }
3336 
3341  ::tree::cbor::MapWriter &map,
3342  const ::tree::base::PointerMap &ids
3343 ) const {
3344  (void)ids;
3345  map.append_string("@t", "Version");
3346  auto submap = map.append_map("items");
3347  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Version>(items, submap);
3348  submap.close();
3349  serialize_annotations(map);
3350 }
3351 
3355 std::shared_ptr<Version> Version::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
3356  (void)ids;
3357  auto type = map.at("@t").as_string();
3358  if (type != "Version") {
3359  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
3360  }
3361  auto node = std::make_shared<Version>(
3362  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Version>(map.at("items").as_map())
3363  );
3364  node->deserialize_annotations(map);
3365  return node;
3366 }
3367 
3371 WhileLoop::WhileLoop(const One<cqasm::v1::values::Node> &condition, const One<Block> &body, const Any<AnnotationData> &annotations)
3372  : Structured(annotations), condition(condition), body(body)
3373 {}
3374 
3378 void WhileLoop::find_reachable(::tree::base::PointerMap &map) const {
3379  (void)map;
3380  condition.find_reachable(map);
3381  body.find_reachable(map);
3382  annotations.find_reachable(map);
3383 }
3384 
3388 void WhileLoop::check_complete(const ::tree::base::PointerMap &map) const {
3389  (void)map;
3390  condition.check_complete(map);
3391  body.check_complete(map);
3392  annotations.check_complete(map);
3393 }
3394 
3399  return NodeType::WhileLoop;
3400 }
3401 
3405 void WhileLoop::visit_internal(VisitorBase &visitor, void *retval) {
3406  visitor.raw_visit_while_loop(*this, retval);
3407 }
3408 
3414  return dynamic_cast<WhileLoop*>(this);
3415 }
3416 
3422  return dynamic_cast<const WhileLoop*>(this);
3423 }
3424 
3429  return cqasm::tree::make<WhileLoop>(*this);
3430 }
3431 
3436  auto node = cqasm::tree::make<WhileLoop>(*this);
3437  node->condition = this->condition.clone();
3438  node->body = this->body.clone();
3439  node->annotations = this->annotations.clone();
3440  return node;
3441 }
3442 
3446 bool WhileLoop::equals(const Node &rhs) const {
3447  if (rhs.type() != NodeType::WhileLoop) return false;
3448  auto rhsc = dynamic_cast<const WhileLoop&>(rhs);
3449  if (!this->condition.equals(rhsc.condition)) return false;
3450  if (!this->body.equals(rhsc.body)) return false;
3451  if (!this->annotations.equals(rhsc.annotations)) return false;
3452  return true;
3453 }
3454 
3458 bool WhileLoop::operator==(const Node &rhs) const {
3459  if (rhs.type() != NodeType::WhileLoop) return false;
3460  auto rhsc = dynamic_cast<const WhileLoop&>(rhs);
3461  if (this->condition != rhsc.condition) return false;
3462  if (this->body != rhsc.body) return false;
3463  if (this->annotations != rhsc.annotations) return false;
3464  return true;
3465 }
3466 
3471  ::tree::cbor::MapWriter &map,
3472  const ::tree::base::PointerMap &ids
3473 ) const {
3474  (void)ids;
3475  map.append_string("@t", "WhileLoop");
3476  auto submap = map.append_map("condition");
3477  condition.serialize(submap, ids);
3478  submap.close();
3479  submap = map.append_map("body");
3480  body.serialize(submap, ids);
3481  submap.close();
3482  submap = map.append_map("annotations");
3483  annotations.serialize(submap, ids);
3484  submap.close();
3485  serialize_annotations(map);
3486 }
3487 
3491 std::shared_ptr<WhileLoop> WhileLoop::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
3492  (void)ids;
3493  auto type = map.at("@t").as_string();
3494  if (type != "WhileLoop") {
3495  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
3496  }
3497  auto node = std::make_shared<WhileLoop>(
3498  One<cqasm::v1::values::Node>(map.at("condition").as_map(), ids),
3499  One<Block>(map.at("body").as_map(), ids),
3500  Any<AnnotationData>(map.at("annotations").as_map(), ids)
3501  );
3502  node->deserialize_annotations(map);
3503  return node;
3504 }
3505 
3509 template <>
3510 void Visitor<void>::raw_visit_node(Node &node, void *retval) {
3511  (void)retval;
3512  this->visit_node(node);
3513 }
3514 
3518 template <>
3520  (void)retval;
3521  this->visit_annotated(node);
3522 }
3523 
3527 template <>
3529  (void)retval;
3530  this->visit_annotation_data(node);
3531 }
3532 
3536 template <>
3537 void Visitor<void>::raw_visit_block(Block &node, void *retval) {
3538  (void)retval;
3539  this->visit_block(node);
3540 }
3541 
3545 template <>
3547  (void)retval;
3548  this->visit_break_statement(node);
3549 }
3550 
3554 template <>
3555 void Visitor<void>::raw_visit_bundle(Bundle &node, void *retval) {
3556  (void)retval;
3557  this->visit_bundle(node);
3558 }
3559 
3563 template <>
3565  (void)retval;
3566  this->visit_bundle_ext(node);
3567 }
3568 
3572 template <>
3574  (void)retval;
3575  this->visit_continue_statement(node);
3576 }
3577 
3581 template <>
3583  (void)retval;
3584  this->visit_error_model(node);
3585 }
3586 
3590 template <>
3591 void Visitor<void>::raw_visit_for_loop(ForLoop &node, void *retval) {
3592  (void)retval;
3593  this->visit_for_loop(node);
3594 }
3595 
3599 template <>
3601  (void)retval;
3602  this->visit_foreach_loop(node);
3603 }
3604 
3608 template <>
3610  (void)retval;
3611  this->visit_goto_instruction(node);
3612 }
3613 
3617 template <>
3618 void Visitor<void>::raw_visit_if_else(IfElse &node, void *retval) {
3619  (void)retval;
3620  this->visit_if_else(node);
3621 }
3622 
3626 template <>
3628  (void)retval;
3629  this->visit_if_else_branch(node);
3630 }
3631 
3635 template <>
3637  (void)retval;
3638  this->visit_instruction(node);
3639 }
3640 
3644 template <>
3646  (void)retval;
3647  this->visit_instruction_base(node);
3648 }
3649 
3653 template <>
3654 void Visitor<void>::raw_visit_mapping(Mapping &node, void *retval) {
3655  (void)retval;
3656  this->visit_mapping(node);
3657 }
3658 
3662 template <>
3663 void Visitor<void>::raw_visit_program(Program &node, void *retval) {
3664  (void)retval;
3665  this->visit_program(node);
3666 }
3667 
3671 template <>
3673  (void)retval;
3674  this->visit_repeat_until_loop(node);
3675 }
3676 
3680 template <>
3682  (void)retval;
3683  this->visit_set_instruction(node);
3684 }
3685 
3689 template <>
3691  (void)retval;
3692  this->visit_statement(node);
3693 }
3694 
3698 template <>
3700  (void)retval;
3701  this->visit_structured(node);
3702 }
3703 
3707 template <>
3709  (void)retval;
3710  this->visit_subcircuit(node);
3711 }
3712 
3716 template <>
3717 void Visitor<void>::raw_visit_variable(Variable &node, void *retval) {
3718  (void)retval;
3719  this->visit_variable(node);
3720 }
3721 
3725 template <>
3726 void Visitor<void>::raw_visit_version(Version &node, void *retval) {
3727  (void)retval;
3728  this->visit_version(node);
3729 }
3730 
3734 template <>
3736  (void)retval;
3737  this->visit_while_loop(node);
3738 }
3739 
3744  visit_node(node);
3745  node.annotations.visit(*this);
3746 }
3747 
3752  visit_node(node);
3753 }
3754 
3759  visit_node(node);
3760  node.statements.visit(*this);
3761 }
3762 
3767  visit_structured(node);
3768 }
3769 
3774  visit_annotated(node);
3775  node.items.visit(*this);
3776 }
3777 
3782  visit_statement(node);
3783  node.items.visit(*this);
3784 }
3785 
3790  visit_structured(node);
3791 }
3792 
3797  visit_annotated(node);
3798 }
3799 
3804  visit_structured(node);
3805  node.initialize.visit(*this);
3806  node.update.visit(*this);
3807  node.body.visit(*this);
3808 }
3809 
3814  visit_structured(node);
3815  node.body.visit(*this);
3816 }
3817 
3822  visit_instruction_base(node);
3823 }
3824 
3829  visit_structured(node);
3830  node.branches.visit(*this);
3831  node.otherwise.visit(*this);
3832 }
3833 
3838  visit_node(node);
3839  node.body.visit(*this);
3840 }
3841 
3846  visit_instruction_base(node);
3847 }
3848 
3853  visit_annotated(node);
3854 }
3855 
3860  visit_annotated(node);
3861 }
3862 
3867  visit_node(node);
3868  node.version.visit(*this);
3869  node.error_model.visit(*this);
3870  node.subcircuits.visit(*this);
3871  node.mappings.visit(*this);
3872  node.variables.visit(*this);
3873 }
3874 
3879  visit_structured(node);
3880  node.body.visit(*this);
3881 }
3882 
3887  visit_instruction_base(node);
3888 }
3889 
3894  visit_annotated(node);
3895 }
3896 
3901  visit_statement(node);
3902 }
3903 
3908  visit_annotated(node);
3909  node.bundles.visit(*this);
3910  node.body.visit(*this);
3911 }
3912 
3917  visit_annotated(node);
3918 }
3919 
3924  visit_node(node);
3925 }
3926 
3931  visit_structured(node);
3932  node.body.visit(*this);
3933 }
3934 
3939  for (int i = 0; i < indent; i++) {
3940  out << " ";
3941  }
3942 }
3943 
3948  (void)node;
3949  write_indent();
3950  out << "!Node()" << std::endl;
3951 }
3952 
3957  write_indent();
3958  out << "Annotated";
3959  if (ids != nullptr) {
3960  out << "@" << ids->get_ref(node);
3961  }
3962  out << "(";
3963  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
3964  out << " # " << *loc;
3965  }
3966  out << std::endl;
3967  indent++;
3968  write_indent();
3969  out << "annotations: ";
3970  if (node.annotations.empty()) {
3971  out << "[]" << std::endl;
3972  } else {
3973  out << "[" << std::endl;
3974  indent++;
3975  for (auto &sptr : node.annotations) {
3976  if (!sptr.empty()) {
3977  sptr->visit(*this);
3978  } else {
3979  write_indent();
3980  out << "!NULL" << std::endl;
3981  }
3982  }
3983  indent--;
3984  write_indent();
3985  out << "]" << std::endl;
3986  }
3987  indent--;
3988  write_indent();
3989  out << ")" << std::endl;
3990 }
3991 
3996  write_indent();
3997  out << "AnnotationData";
3998  if (ids != nullptr) {
3999  out << "@" << ids->get_ref(node);
4000  }
4001  out << "(";
4002  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4003  out << " # " << *loc;
4004  }
4005  out << std::endl;
4006  indent++;
4007  write_indent();
4008  out << "interface: ";
4009  std::stringstream ss;
4010  size_t pos;
4011  ss << node.interface;
4012  pos = ss.str().find_last_not_of(" \n\r\t");
4013  if (pos != std::string::npos) {
4014  ss.str(ss.str().erase(pos+1));
4015  }
4016  if (ss.str().find('\n') == std::string::npos) {
4017  out << ss.str() << std::endl;
4018  } else {
4019  out << "cqasm::v1::primitives::Str<<" << std::endl;
4020  indent++;
4021  std::string s;
4022  while (!ss.eof()) {
4023  std::getline(ss, s);
4024  write_indent();
4025  out << s << std::endl;
4026  }
4027  indent--;
4028  write_indent();
4029  out << ">>" << std::endl;
4030  }
4031  write_indent();
4032  out << "operation: ";
4033  ss.str("");
4034  ss.clear();
4035  ss << node.operation;
4036  pos = ss.str().find_last_not_of(" \n\r\t");
4037  if (pos != std::string::npos) {
4038  ss.str(ss.str().erase(pos+1));
4039  }
4040  if (ss.str().find('\n') == std::string::npos) {
4041  out << ss.str() << std::endl;
4042  } else {
4043  out << "cqasm::v1::primitives::Str<<" << std::endl;
4044  indent++;
4045  std::string s;
4046  while (!ss.eof()) {
4047  std::getline(ss, s);
4048  write_indent();
4049  out << s << std::endl;
4050  }
4051  indent--;
4052  write_indent();
4053  out << ">>" << std::endl;
4054  }
4055  write_indent();
4056  out << "operands: ";
4057  if (node.operands.empty()) {
4058  out << "[]" << std::endl;
4059  } else {
4060  out << "[" << std::endl;
4061  indent++;
4062  for (auto &sptr : node.operands) {
4063  if (!sptr.empty()) {
4064  sptr->dump(out, indent);
4065  } else {
4066  write_indent();
4067  out << "!NULL" << std::endl;
4068  }
4069  }
4070  indent--;
4071  write_indent();
4072  out << "]" << std::endl;
4073  }
4074  indent--;
4075  write_indent();
4076  out << ")" << std::endl;
4077 }
4078 
4083  write_indent();
4084  out << "Block";
4085  if (ids != nullptr) {
4086  out << "@" << ids->get_ref(node);
4087  }
4088  out << "(";
4089  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4090  out << " # " << *loc;
4091  }
4092  out << std::endl;
4093  indent++;
4094  write_indent();
4095  out << "statements: ";
4096  if (node.statements.empty()) {
4097  out << "[]" << std::endl;
4098  } else {
4099  out << "[" << std::endl;
4100  indent++;
4101  for (auto &sptr : node.statements) {
4102  if (!sptr.empty()) {
4103  sptr->visit(*this);
4104  } else {
4105  write_indent();
4106  out << "!NULL" << std::endl;
4107  }
4108  }
4109  indent--;
4110  write_indent();
4111  out << "]" << std::endl;
4112  }
4113  indent--;
4114  write_indent();
4115  out << ")" << std::endl;
4116 }
4117 
4122  write_indent();
4123  out << "BreakStatement";
4124  if (ids != nullptr) {
4125  out << "@" << ids->get_ref(node);
4126  }
4127  out << "(";
4128  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4129  out << " # " << *loc;
4130  }
4131  out << std::endl;
4132  indent++;
4133  write_indent();
4134  out << "annotations: ";
4135  if (node.annotations.empty()) {
4136  out << "[]" << std::endl;
4137  } else {
4138  out << "[" << std::endl;
4139  indent++;
4140  for (auto &sptr : node.annotations) {
4141  if (!sptr.empty()) {
4142  sptr->visit(*this);
4143  } else {
4144  write_indent();
4145  out << "!NULL" << std::endl;
4146  }
4147  }
4148  indent--;
4149  write_indent();
4150  out << "]" << std::endl;
4151  }
4152  indent--;
4153  write_indent();
4154  out << ")" << std::endl;
4155 }
4156 
4161  write_indent();
4162  out << "Bundle";
4163  if (ids != nullptr) {
4164  out << "@" << ids->get_ref(node);
4165  }
4166  out << "(";
4167  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4168  out << " # " << *loc;
4169  }
4170  out << std::endl;
4171  indent++;
4172  write_indent();
4173  out << "items: ";
4174  if (node.items.empty()) {
4175  out << "!MISSING" << std::endl;
4176  } else {
4177  out << "[" << std::endl;
4178  indent++;
4179  for (auto &sptr : node.items) {
4180  if (!sptr.empty()) {
4181  sptr->visit(*this);
4182  } else {
4183  write_indent();
4184  out << "!NULL" << std::endl;
4185  }
4186  }
4187  indent--;
4188  write_indent();
4189  out << "]" << std::endl;
4190  }
4191  write_indent();
4192  out << "annotations: ";
4193  if (node.annotations.empty()) {
4194  out << "[]" << std::endl;
4195  } else {
4196  out << "[" << std::endl;
4197  indent++;
4198  for (auto &sptr : node.annotations) {
4199  if (!sptr.empty()) {
4200  sptr->visit(*this);
4201  } else {
4202  write_indent();
4203  out << "!NULL" << std::endl;
4204  }
4205  }
4206  indent--;
4207  write_indent();
4208  out << "]" << std::endl;
4209  }
4210  indent--;
4211  write_indent();
4212  out << ")" << std::endl;
4213 }
4214 
4219  write_indent();
4220  out << "BundleExt";
4221  if (ids != nullptr) {
4222  out << "@" << ids->get_ref(node);
4223  }
4224  out << "(";
4225  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4226  out << " # " << *loc;
4227  }
4228  out << std::endl;
4229  indent++;
4230  write_indent();
4231  out << "items: ";
4232  if (node.items.empty()) {
4233  out << "!MISSING" << std::endl;
4234  } else {
4235  out << "[" << std::endl;
4236  indent++;
4237  for (auto &sptr : node.items) {
4238  if (!sptr.empty()) {
4239  sptr->visit(*this);
4240  } else {
4241  write_indent();
4242  out << "!NULL" << std::endl;
4243  }
4244  }
4245  indent--;
4246  write_indent();
4247  out << "]" << std::endl;
4248  }
4249  write_indent();
4250  out << "annotations: ";
4251  if (node.annotations.empty()) {
4252  out << "[]" << std::endl;
4253  } else {
4254  out << "[" << std::endl;
4255  indent++;
4256  for (auto &sptr : node.annotations) {
4257  if (!sptr.empty()) {
4258  sptr->visit(*this);
4259  } else {
4260  write_indent();
4261  out << "!NULL" << std::endl;
4262  }
4263  }
4264  indent--;
4265  write_indent();
4266  out << "]" << std::endl;
4267  }
4268  indent--;
4269  write_indent();
4270  out << ")" << std::endl;
4271 }
4272 
4277  write_indent();
4278  out << "ContinueStatement";
4279  if (ids != nullptr) {
4280  out << "@" << ids->get_ref(node);
4281  }
4282  out << "(";
4283  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4284  out << " # " << *loc;
4285  }
4286  out << std::endl;
4287  indent++;
4288  write_indent();
4289  out << "annotations: ";
4290  if (node.annotations.empty()) {
4291  out << "[]" << std::endl;
4292  } else {
4293  out << "[" << std::endl;
4294  indent++;
4295  for (auto &sptr : node.annotations) {
4296  if (!sptr.empty()) {
4297  sptr->visit(*this);
4298  } else {
4299  write_indent();
4300  out << "!NULL" << std::endl;
4301  }
4302  }
4303  indent--;
4304  write_indent();
4305  out << "]" << std::endl;
4306  }
4307  indent--;
4308  write_indent();
4309  out << ")" << std::endl;
4310 }
4311 
4316  write_indent();
4317  out << "ErrorModel";
4318  if (ids != nullptr) {
4319  out << "@" << ids->get_ref(node);
4320  }
4321  out << "(";
4322  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4323  out << " # " << *loc;
4324  }
4325  out << std::endl;
4326  indent++;
4327  write_indent();
4328  out << "model: ";
4329  std::stringstream ss;
4330  size_t pos;
4331  ss << node.model;
4332  pos = ss.str().find_last_not_of(" \n\r\t");
4333  if (pos != std::string::npos) {
4334  ss.str(ss.str().erase(pos+1));
4335  }
4336  if (ss.str().find('\n') == std::string::npos) {
4337  out << ss.str() << std::endl;
4338  } else {
4339  out << "cqasm::v1::error_model::ErrorModelRef<<" << std::endl;
4340  indent++;
4341  std::string s;
4342  while (!ss.eof()) {
4343  std::getline(ss, s);
4344  write_indent();
4345  out << s << std::endl;
4346  }
4347  indent--;
4348  write_indent();
4349  out << ">>" << std::endl;
4350  }
4351  write_indent();
4352  out << "name: ";
4353  ss.str("");
4354  ss.clear();
4355  ss << node.name;
4356  pos = ss.str().find_last_not_of(" \n\r\t");
4357  if (pos != std::string::npos) {
4358  ss.str(ss.str().erase(pos+1));
4359  }
4360  if (ss.str().find('\n') == std::string::npos) {
4361  out << ss.str() << std::endl;
4362  } else {
4363  out << "cqasm::v1::primitives::Str<<" << std::endl;
4364  indent++;
4365  std::string s;
4366  while (!ss.eof()) {
4367  std::getline(ss, s);
4368  write_indent();
4369  out << s << std::endl;
4370  }
4371  indent--;
4372  write_indent();
4373  out << ">>" << std::endl;
4374  }
4375  write_indent();
4376  out << "parameters: ";
4377  if (node.parameters.empty()) {
4378  out << "[]" << std::endl;
4379  } else {
4380  out << "[" << std::endl;
4381  indent++;
4382  for (auto &sptr : node.parameters) {
4383  if (!sptr.empty()) {
4384  sptr->dump(out, indent);
4385  } else {
4386  write_indent();
4387  out << "!NULL" << std::endl;
4388  }
4389  }
4390  indent--;
4391  write_indent();
4392  out << "]" << std::endl;
4393  }
4394  write_indent();
4395  out << "annotations: ";
4396  if (node.annotations.empty()) {
4397  out << "[]" << std::endl;
4398  } else {
4399  out << "[" << std::endl;
4400  indent++;
4401  for (auto &sptr : node.annotations) {
4402  if (!sptr.empty()) {
4403  sptr->visit(*this);
4404  } else {
4405  write_indent();
4406  out << "!NULL" << std::endl;
4407  }
4408  }
4409  indent--;
4410  write_indent();
4411  out << "]" << std::endl;
4412  }
4413  indent--;
4414  write_indent();
4415  out << ")" << std::endl;
4416 }
4417 
4422  write_indent();
4423  out << "ForLoop";
4424  if (ids != nullptr) {
4425  out << "@" << ids->get_ref(node);
4426  }
4427  out << "(";
4428  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4429  out << " # " << *loc;
4430  }
4431  out << std::endl;
4432  indent++;
4433  write_indent();
4434  out << "initialize: ";
4435  if (node.initialize.empty()) {
4436  out << "-" << std::endl;
4437  } else {
4438  out << "<" << std::endl;
4439  indent++;
4440  node.initialize.visit(*this);
4441  indent--;
4442  write_indent();
4443  out << ">" << std::endl;
4444  }
4445  write_indent();
4446  out << "condition: ";
4447  if (node.condition.empty()) {
4448  out << "!MISSING" << std::endl;
4449  } else {
4450  out << "<" << std::endl;
4451  indent++;
4452  if (!node.condition.empty()) {
4453  node.condition->dump(out, indent);
4454  }
4455  indent--;
4456  write_indent();
4457  out << ">" << std::endl;
4458  }
4459  write_indent();
4460  out << "update: ";
4461  if (node.update.empty()) {
4462  out << "-" << std::endl;
4463  } else {
4464  out << "<" << std::endl;
4465  indent++;
4466  node.update.visit(*this);
4467  indent--;
4468  write_indent();
4469  out << ">" << std::endl;
4470  }
4471  write_indent();
4472  out << "body: ";
4473  if (node.body.empty()) {
4474  out << "!MISSING" << std::endl;
4475  } else {
4476  out << "<" << std::endl;
4477  indent++;
4478  node.body.visit(*this);
4479  indent--;
4480  write_indent();
4481  out << ">" << std::endl;
4482  }
4483  write_indent();
4484  out << "annotations: ";
4485  if (node.annotations.empty()) {
4486  out << "[]" << std::endl;
4487  } else {
4488  out << "[" << std::endl;
4489  indent++;
4490  for (auto &sptr : node.annotations) {
4491  if (!sptr.empty()) {
4492  sptr->visit(*this);
4493  } else {
4494  write_indent();
4495  out << "!NULL" << std::endl;
4496  }
4497  }
4498  indent--;
4499  write_indent();
4500  out << "]" << std::endl;
4501  }
4502  indent--;
4503  write_indent();
4504  out << ")" << std::endl;
4505 }
4506 
4511  write_indent();
4512  out << "ForeachLoop";
4513  if (ids != nullptr) {
4514  out << "@" << ids->get_ref(node);
4515  }
4516  out << "(";
4517  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4518  out << " # " << *loc;
4519  }
4520  out << std::endl;
4521  indent++;
4522  write_indent();
4523  out << "lhs: ";
4524  if (node.lhs.empty()) {
4525  out << "!MISSING" << std::endl;
4526  } else {
4527  out << "<" << std::endl;
4528  indent++;
4529  if (!node.lhs.empty()) {
4530  node.lhs->dump(out, indent);
4531  }
4532  indent--;
4533  write_indent();
4534  out << ">" << std::endl;
4535  }
4536  write_indent();
4537  out << "frm: ";
4538  std::stringstream ss;
4539  size_t pos;
4540  ss << node.frm;
4541  pos = ss.str().find_last_not_of(" \n\r\t");
4542  if (pos != std::string::npos) {
4543  ss.str(ss.str().erase(pos+1));
4544  }
4545  if (ss.str().find('\n') == std::string::npos) {
4546  out << ss.str() << std::endl;
4547  } else {
4548  out << "cqasm::v1::primitives::Int<<" << std::endl;
4549  indent++;
4550  std::string s;
4551  while (!ss.eof()) {
4552  std::getline(ss, s);
4553  write_indent();
4554  out << s << std::endl;
4555  }
4556  indent--;
4557  write_indent();
4558  out << ">>" << std::endl;
4559  }
4560  write_indent();
4561  out << "to: ";
4562  ss.str("");
4563  ss.clear();
4564  ss << node.to;
4565  pos = ss.str().find_last_not_of(" \n\r\t");
4566  if (pos != std::string::npos) {
4567  ss.str(ss.str().erase(pos+1));
4568  }
4569  if (ss.str().find('\n') == std::string::npos) {
4570  out << ss.str() << std::endl;
4571  } else {
4572  out << "cqasm::v1::primitives::Int<<" << std::endl;
4573  indent++;
4574  std::string s;
4575  while (!ss.eof()) {
4576  std::getline(ss, s);
4577  write_indent();
4578  out << s << std::endl;
4579  }
4580  indent--;
4581  write_indent();
4582  out << ">>" << std::endl;
4583  }
4584  write_indent();
4585  out << "body: ";
4586  if (node.body.empty()) {
4587  out << "!MISSING" << std::endl;
4588  } else {
4589  out << "<" << std::endl;
4590  indent++;
4591  node.body.visit(*this);
4592  indent--;
4593  write_indent();
4594  out << ">" << std::endl;
4595  }
4596  write_indent();
4597  out << "annotations: ";
4598  if (node.annotations.empty()) {
4599  out << "[]" << std::endl;
4600  } else {
4601  out << "[" << std::endl;
4602  indent++;
4603  for (auto &sptr : node.annotations) {
4604  if (!sptr.empty()) {
4605  sptr->visit(*this);
4606  } else {
4607  write_indent();
4608  out << "!NULL" << std::endl;
4609  }
4610  }
4611  indent--;
4612  write_indent();
4613  out << "]" << std::endl;
4614  }
4615  indent--;
4616  write_indent();
4617  out << ")" << std::endl;
4618 }
4619 
4624  write_indent();
4625  out << "GotoInstruction";
4626  if (ids != nullptr) {
4627  out << "@" << ids->get_ref(node);
4628  }
4629  out << "(";
4630  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4631  out << " # " << *loc;
4632  }
4633  out << std::endl;
4634  indent++;
4635  write_indent();
4636  out << "target --> ";
4637  if (node.target.empty()) {
4638  out << "!MISSING" << std::endl;
4639  } else if (ids != nullptr && ids->get(node.target) != (size_t)-1) {
4640  out << "Subcircuit@" << ids->get(node.target) << std::endl;
4641  } else {
4642  out << "<" << std::endl;
4643  indent++;
4644  if (!in_link) {
4645  in_link = true;
4646  node.target.visit(*this);
4647  in_link = false;
4648  } else {
4649  write_indent();
4650  out << "..." << std::endl;
4651  }
4652  indent--;
4653  write_indent();
4654  out << ">" << std::endl;
4655  }
4656  write_indent();
4657  out << "condition: ";
4658  if (node.condition.empty()) {
4659  out << "!MISSING" << std::endl;
4660  } else {
4661  out << "<" << std::endl;
4662  indent++;
4663  if (!node.condition.empty()) {
4664  node.condition->dump(out, indent);
4665  }
4666  indent--;
4667  write_indent();
4668  out << ">" << std::endl;
4669  }
4670  write_indent();
4671  out << "annotations: ";
4672  if (node.annotations.empty()) {
4673  out << "[]" << std::endl;
4674  } else {
4675  out << "[" << std::endl;
4676  indent++;
4677  for (auto &sptr : node.annotations) {
4678  if (!sptr.empty()) {
4679  sptr->visit(*this);
4680  } else {
4681  write_indent();
4682  out << "!NULL" << std::endl;
4683  }
4684  }
4685  indent--;
4686  write_indent();
4687  out << "]" << std::endl;
4688  }
4689  indent--;
4690  write_indent();
4691  out << ")" << std::endl;
4692 }
4693 
4698  write_indent();
4699  out << "IfElse";
4700  if (ids != nullptr) {
4701  out << "@" << ids->get_ref(node);
4702  }
4703  out << "(";
4704  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4705  out << " # " << *loc;
4706  }
4707  out << std::endl;
4708  indent++;
4709  write_indent();
4710  out << "branches: ";
4711  if (node.branches.empty()) {
4712  out << "!MISSING" << std::endl;
4713  } else {
4714  out << "[" << std::endl;
4715  indent++;
4716  for (auto &sptr : node.branches) {
4717  if (!sptr.empty()) {
4718  sptr->visit(*this);
4719  } else {
4720  write_indent();
4721  out << "!NULL" << std::endl;
4722  }
4723  }
4724  indent--;
4725  write_indent();
4726  out << "]" << std::endl;
4727  }
4728  write_indent();
4729  out << "otherwise: ";
4730  if (node.otherwise.empty()) {
4731  out << "-" << std::endl;
4732  } else {
4733  out << "<" << std::endl;
4734  indent++;
4735  node.otherwise.visit(*this);
4736  indent--;
4737  write_indent();
4738  out << ">" << std::endl;
4739  }
4740  write_indent();
4741  out << "annotations: ";
4742  if (node.annotations.empty()) {
4743  out << "[]" << std::endl;
4744  } else {
4745  out << "[" << std::endl;
4746  indent++;
4747  for (auto &sptr : node.annotations) {
4748  if (!sptr.empty()) {
4749  sptr->visit(*this);
4750  } else {
4751  write_indent();
4752  out << "!NULL" << std::endl;
4753  }
4754  }
4755  indent--;
4756  write_indent();
4757  out << "]" << std::endl;
4758  }
4759  indent--;
4760  write_indent();
4761  out << ")" << std::endl;
4762 }
4763 
4768  write_indent();
4769  out << "IfElseBranch";
4770  if (ids != nullptr) {
4771  out << "@" << ids->get_ref(node);
4772  }
4773  out << "(";
4774  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4775  out << " # " << *loc;
4776  }
4777  out << std::endl;
4778  indent++;
4779  write_indent();
4780  out << "condition: ";
4781  if (node.condition.empty()) {
4782  out << "!MISSING" << std::endl;
4783  } else {
4784  out << "<" << std::endl;
4785  indent++;
4786  if (!node.condition.empty()) {
4787  node.condition->dump(out, indent);
4788  }
4789  indent--;
4790  write_indent();
4791  out << ">" << std::endl;
4792  }
4793  write_indent();
4794  out << "body: ";
4795  if (node.body.empty()) {
4796  out << "!MISSING" << std::endl;
4797  } else {
4798  out << "<" << std::endl;
4799  indent++;
4800  node.body.visit(*this);
4801  indent--;
4802  write_indent();
4803  out << ">" << std::endl;
4804  }
4805  indent--;
4806  write_indent();
4807  out << ")" << std::endl;
4808 }
4809 
4814  write_indent();
4815  out << "Instruction";
4816  if (ids != nullptr) {
4817  out << "@" << ids->get_ref(node);
4818  }
4819  out << "(";
4820  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4821  out << " # " << *loc;
4822  }
4823  out << std::endl;
4824  indent++;
4825  write_indent();
4826  out << "instruction: ";
4827  std::stringstream ss;
4828  size_t pos;
4829  ss << node.instruction;
4830  pos = ss.str().find_last_not_of(" \n\r\t");
4831  if (pos != std::string::npos) {
4832  ss.str(ss.str().erase(pos+1));
4833  }
4834  if (ss.str().find('\n') == std::string::npos) {
4835  out << ss.str() << std::endl;
4836  } else {
4837  out << "cqasm::v1::instruction::InstructionRef<<" << std::endl;
4838  indent++;
4839  std::string s;
4840  while (!ss.eof()) {
4841  std::getline(ss, s);
4842  write_indent();
4843  out << s << std::endl;
4844  }
4845  indent--;
4846  write_indent();
4847  out << ">>" << std::endl;
4848  }
4849  write_indent();
4850  out << "name: ";
4851  ss.str("");
4852  ss.clear();
4853  ss << node.name;
4854  pos = ss.str().find_last_not_of(" \n\r\t");
4855  if (pos != std::string::npos) {
4856  ss.str(ss.str().erase(pos+1));
4857  }
4858  if (ss.str().find('\n') == std::string::npos) {
4859  out << ss.str() << std::endl;
4860  } else {
4861  out << "cqasm::v1::primitives::Str<<" << std::endl;
4862  indent++;
4863  std::string s;
4864  while (!ss.eof()) {
4865  std::getline(ss, s);
4866  write_indent();
4867  out << s << std::endl;
4868  }
4869  indent--;
4870  write_indent();
4871  out << ">>" << std::endl;
4872  }
4873  write_indent();
4874  out << "condition: ";
4875  if (node.condition.empty()) {
4876  out << "!MISSING" << std::endl;
4877  } else {
4878  out << "<" << std::endl;
4879  indent++;
4880  if (!node.condition.empty()) {
4881  node.condition->dump(out, indent);
4882  }
4883  indent--;
4884  write_indent();
4885  out << ">" << std::endl;
4886  }
4887  write_indent();
4888  out << "operands: ";
4889  if (node.operands.empty()) {
4890  out << "[]" << std::endl;
4891  } else {
4892  out << "[" << std::endl;
4893  indent++;
4894  for (auto &sptr : node.operands) {
4895  if (!sptr.empty()) {
4896  sptr->dump(out, indent);
4897  } else {
4898  write_indent();
4899  out << "!NULL" << std::endl;
4900  }
4901  }
4902  indent--;
4903  write_indent();
4904  out << "]" << std::endl;
4905  }
4906  write_indent();
4907  out << "annotations: ";
4908  if (node.annotations.empty()) {
4909  out << "[]" << std::endl;
4910  } else {
4911  out << "[" << std::endl;
4912  indent++;
4913  for (auto &sptr : node.annotations) {
4914  if (!sptr.empty()) {
4915  sptr->visit(*this);
4916  } else {
4917  write_indent();
4918  out << "!NULL" << std::endl;
4919  }
4920  }
4921  indent--;
4922  write_indent();
4923  out << "]" << std::endl;
4924  }
4925  indent--;
4926  write_indent();
4927  out << ")" << std::endl;
4928 }
4929 
4934  write_indent();
4935  out << "InstructionBase";
4936  if (ids != nullptr) {
4937  out << "@" << ids->get_ref(node);
4938  }
4939  out << "(";
4940  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4941  out << " # " << *loc;
4942  }
4943  out << std::endl;
4944  indent++;
4945  write_indent();
4946  out << "condition: ";
4947  if (node.condition.empty()) {
4948  out << "!MISSING" << std::endl;
4949  } else {
4950  out << "<" << std::endl;
4951  indent++;
4952  if (!node.condition.empty()) {
4953  node.condition->dump(out, indent);
4954  }
4955  indent--;
4956  write_indent();
4957  out << ">" << std::endl;
4958  }
4959  write_indent();
4960  out << "annotations: ";
4961  if (node.annotations.empty()) {
4962  out << "[]" << std::endl;
4963  } else {
4964  out << "[" << std::endl;
4965  indent++;
4966  for (auto &sptr : node.annotations) {
4967  if (!sptr.empty()) {
4968  sptr->visit(*this);
4969  } else {
4970  write_indent();
4971  out << "!NULL" << std::endl;
4972  }
4973  }
4974  indent--;
4975  write_indent();
4976  out << "]" << std::endl;
4977  }
4978  indent--;
4979  write_indent();
4980  out << ")" << std::endl;
4981 }
4982 
4987  write_indent();
4988  out << "Mapping";
4989  if (ids != nullptr) {
4990  out << "@" << ids->get_ref(node);
4991  }
4992  out << "(";
4993  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
4994  out << " # " << *loc;
4995  }
4996  out << std::endl;
4997  indent++;
4998  write_indent();
4999  out << "name: ";
5000  std::stringstream ss;
5001  size_t pos;
5002  ss << node.name;
5003  pos = ss.str().find_last_not_of(" \n\r\t");
5004  if (pos != std::string::npos) {
5005  ss.str(ss.str().erase(pos+1));
5006  }
5007  if (ss.str().find('\n') == std::string::npos) {
5008  out << ss.str() << std::endl;
5009  } else {
5010  out << "cqasm::v1::primitives::Str<<" << std::endl;
5011  indent++;
5012  std::string s;
5013  while (!ss.eof()) {
5014  std::getline(ss, s);
5015  write_indent();
5016  out << s << std::endl;
5017  }
5018  indent--;
5019  write_indent();
5020  out << ">>" << std::endl;
5021  }
5022  write_indent();
5023  out << "value: ";
5024  if (node.value.empty()) {
5025  out << "!MISSING" << std::endl;
5026  } else {
5027  out << "<" << std::endl;
5028  indent++;
5029  if (!node.value.empty()) {
5030  node.value->dump(out, indent);
5031  }
5032  indent--;
5033  write_indent();
5034  out << ">" << std::endl;
5035  }
5036  write_indent();
5037  out << "annotations: ";
5038  if (node.annotations.empty()) {
5039  out << "[]" << std::endl;
5040  } else {
5041  out << "[" << std::endl;
5042  indent++;
5043  for (auto &sptr : node.annotations) {
5044  if (!sptr.empty()) {
5045  sptr->visit(*this);
5046  } else {
5047  write_indent();
5048  out << "!NULL" << std::endl;
5049  }
5050  }
5051  indent--;
5052  write_indent();
5053  out << "]" << std::endl;
5054  }
5055  indent--;
5056  write_indent();
5057  out << ")" << std::endl;
5058 }
5059 
5064  write_indent();
5065  out << "Program";
5066  if (ids != nullptr) {
5067  out << "@" << ids->get_ref(node);
5068  }
5069  out << "(";
5070  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
5071  out << " # " << *loc;
5072  }
5073  out << std::endl;
5074  indent++;
5075  write_indent();
5076  out << "version: ";
5077  if (node.version.empty()) {
5078  out << "!MISSING" << std::endl;
5079  } else {
5080  out << "<" << std::endl;
5081  indent++;
5082  node.version.visit(*this);
5083  indent--;
5084  write_indent();
5085  out << ">" << std::endl;
5086  }
5087  write_indent();
5088  out << "num_qubits: ";
5089  std::stringstream ss;
5090  size_t pos;
5091  ss << node.num_qubits;
5092  pos = ss.str().find_last_not_of(" \n\r\t");
5093  if (pos != std::string::npos) {
5094  ss.str(ss.str().erase(pos+1));
5095  }
5096  if (ss.str().find('\n') == std::string::npos) {
5097  out << ss.str() << std::endl;
5098  } else {
5099  out << "cqasm::v1::primitives::Int<<" << std::endl;
5100  indent++;
5101  std::string s;
5102  while (!ss.eof()) {
5103  std::getline(ss, s);
5104  write_indent();
5105  out << s << std::endl;
5106  }
5107  indent--;
5108  write_indent();
5109  out << ">>" << std::endl;
5110  }
5111  write_indent();
5112  out << "error_model: ";
5113  if (node.error_model.empty()) {
5114  out << "-" << std::endl;
5115  } else {
5116  out << "<" << std::endl;
5117  indent++;
5118  node.error_model.visit(*this);
5119  indent--;
5120  write_indent();
5121  out << ">" << std::endl;
5122  }
5123  write_indent();
5124  out << "subcircuits: ";
5125  if (node.subcircuits.empty()) {
5126  out << "[]" << std::endl;
5127  } else {
5128  out << "[" << std::endl;
5129  indent++;
5130  for (auto &sptr : node.subcircuits) {
5131  if (!sptr.empty()) {
5132  sptr->visit(*this);
5133  } else {
5134  write_indent();
5135  out << "!NULL" << std::endl;
5136  }
5137  }
5138  indent--;
5139  write_indent();
5140  out << "]" << std::endl;
5141  }
5142  write_indent();
5143  out << "mappings: ";
5144  if (node.mappings.empty()) {
5145  out << "[]" << std::endl;
5146  } else {
5147  out << "[" << std::endl;
5148  indent++;
5149  for (auto &sptr : node.mappings) {
5150  if (!sptr.empty()) {
5151  sptr->visit(*this);
5152  } else {
5153  write_indent();
5154  out << "!NULL" << std::endl;
5155  }
5156  }
5157  indent--;
5158  write_indent();
5159  out << "]" << std::endl;
5160  }
5161  write_indent();
5162  out << "variables: ";
5163  if (node.variables.empty()) {
5164  out << "[]" << std::endl;
5165  } else {
5166  out << "[" << std::endl;
5167  indent++;
5168  for (auto &sptr : node.variables) {
5169  if (!sptr.empty()) {
5170  sptr->visit(*this);
5171  } else {
5172  write_indent();
5173  out << "!NULL" << std::endl;
5174  }
5175  }
5176  indent--;
5177  write_indent();
5178  out << "]" << std::endl;
5179  }
5180  write_indent();
5181  out << "api_version: ";
5182  ss.str("");
5183  ss.clear();
5184  ss << node.api_version;
5185  pos = ss.str().find_last_not_of(" \n\r\t");
5186  if (pos != std::string::npos) {
5187  ss.str(ss.str().erase(pos+1));
5188  }
5189  if (ss.str().find('\n') == std::string::npos) {
5190  out << ss.str() << std::endl;
5191  } else {
5192  out << "cqasm::v1::primitives::Version<<" << std::endl;
5193  indent++;
5194  std::string s;
5195  while (!ss.eof()) {
5196  std::getline(ss, s);
5197  write_indent();
5198  out << s << std::endl;
5199  }
5200  indent--;
5201  write_indent();
5202  out << ">>" << std::endl;
5203  }
5204  indent--;
5205  write_indent();
5206  out << ")" << std::endl;
5207 }
5208 
5213  write_indent();
5214  out << "RepeatUntilLoop";
5215  if (ids != nullptr) {
5216  out << "@" << ids->get_ref(node);
5217  }
5218  out << "(";
5219  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
5220  out << " # " << *loc;
5221  }
5222  out << std::endl;
5223  indent++;
5224  write_indent();
5225  out << "body: ";
5226  if (node.body.empty()) {
5227  out << "!MISSING" << std::endl;
5228  } else {
5229  out << "<" << std::endl;
5230  indent++;
5231  node.body.visit(*this);
5232  indent--;
5233  write_indent();
5234  out << ">" << std::endl;
5235  }
5236  write_indent();
5237  out << "condition: ";
5238  if (node.condition.empty()) {
5239  out << "!MISSING" << std::endl;
5240  } else {
5241  out << "<" << std::endl;
5242  indent++;
5243  if (!node.condition.empty()) {
5244  node.condition->dump(out, indent);
5245  }
5246  indent--;
5247  write_indent();
5248  out << ">" << std::endl;
5249  }
5250  write_indent();
5251  out << "annotations: ";
5252  if (node.annotations.empty()) {
5253  out << "[]" << std::endl;
5254  } else {
5255  out << "[" << std::endl;
5256  indent++;
5257  for (auto &sptr : node.annotations) {
5258  if (!sptr.empty()) {
5259  sptr->visit(*this);
5260  } else {
5261  write_indent();
5262  out << "!NULL" << std::endl;
5263  }
5264  }
5265  indent--;
5266  write_indent();
5267  out << "]" << std::endl;
5268  }
5269  indent--;
5270  write_indent();
5271  out << ")" << std::endl;
5272 }
5273 
5278  write_indent();
5279  out << "SetInstruction";
5280  if (ids != nullptr) {
5281  out << "@" << ids->get_ref(node);
5282  }
5283  out << "(";
5284  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
5285  out << " # " << *loc;
5286  }
5287  out << std::endl;
5288  indent++;
5289  write_indent();
5290  out << "lhs: ";
5291  if (node.lhs.empty()) {
5292  out << "!MISSING" << std::endl;
5293  } else {
5294  out << "<" << std::endl;
5295  indent++;
5296  if (!node.lhs.empty()) {
5297  node.lhs->dump(out, indent);
5298  }
5299  indent--;
5300  write_indent();
5301  out << ">" << std::endl;
5302  }
5303  write_indent();
5304  out << "rhs: ";
5305  if (node.rhs.empty()) {
5306  out << "!MISSING" << std::endl;
5307  } else {
5308  out << "<" << std::endl;
5309  indent++;
5310  if (!node.rhs.empty()) {
5311  node.rhs->dump(out, indent);
5312  }
5313  indent--;
5314  write_indent();
5315  out << ">" << std::endl;
5316  }
5317  write_indent();
5318  out << "condition: ";
5319  if (node.condition.empty()) {
5320  out << "!MISSING" << std::endl;
5321  } else {
5322  out << "<" << std::endl;
5323  indent++;
5324  if (!node.condition.empty()) {
5325  node.condition->dump(out, indent);
5326  }
5327  indent--;
5328  write_indent();
5329  out << ">" << std::endl;
5330  }
5331  write_indent();
5332  out << "annotations: ";
5333  if (node.annotations.empty()) {
5334  out << "[]" << std::endl;
5335  } else {
5336  out << "[" << std::endl;
5337  indent++;
5338  for (auto &sptr : node.annotations) {
5339  if (!sptr.empty()) {
5340  sptr->visit(*this);
5341  } else {
5342  write_indent();
5343  out << "!NULL" << std::endl;
5344  }
5345  }
5346  indent--;
5347  write_indent();
5348  out << "]" << std::endl;
5349  }
5350  indent--;
5351  write_indent();
5352  out << ")" << std::endl;
5353 }
5354 
5359  write_indent();
5360  out << "Statement";
5361  if (ids != nullptr) {
5362  out << "@" << ids->get_ref(node);
5363  }
5364  out << "(";
5365  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
5366  out << " # " << *loc;
5367  }
5368  out << std::endl;
5369  indent++;
5370  write_indent();
5371  out << "annotations: ";
5372  if (node.annotations.empty()) {
5373  out << "[]" << std::endl;
5374  } else {
5375  out << "[" << std::endl;
5376  indent++;
5377  for (auto &sptr : node.annotations) {
5378  if (!sptr.empty()) {
5379  sptr->visit(*this);
5380  } else {
5381  write_indent();
5382  out << "!NULL" << std::endl;
5383  }
5384  }
5385  indent--;
5386  write_indent();
5387  out << "]" << std::endl;
5388  }
5389  indent--;
5390  write_indent();
5391  out << ")" << std::endl;
5392 }
5393 
5398  write_indent();
5399  out << "Structured";
5400  if (ids != nullptr) {
5401  out << "@" << ids->get_ref(node);
5402  }
5403  out << "(";
5404  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
5405  out << " # " << *loc;
5406  }
5407  out << std::endl;
5408  indent++;
5409  write_indent();
5410  out << "annotations: ";
5411  if (node.annotations.empty()) {
5412  out << "[]" << std::endl;
5413  } else {
5414  out << "[" << std::endl;
5415  indent++;
5416  for (auto &sptr : node.annotations) {
5417  if (!sptr.empty()) {
5418  sptr->visit(*this);
5419  } else {
5420  write_indent();
5421  out << "!NULL" << std::endl;
5422  }
5423  }
5424  indent--;
5425  write_indent();
5426  out << "]" << std::endl;
5427  }
5428  indent--;
5429  write_indent();
5430  out << ")" << std::endl;
5431 }
5432 
5437  write_indent();
5438  out << "Subcircuit";
5439  if (ids != nullptr) {
5440  out << "@" << ids->get_ref(node);
5441  }
5442  out << "(";
5443  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
5444  out << " # " << *loc;
5445  }
5446  out << std::endl;
5447  indent++;
5448  write_indent();
5449  out << "name: ";
5450  std::stringstream ss;
5451  size_t pos;
5452  ss << node.name;
5453  pos = ss.str().find_last_not_of(" \n\r\t");
5454  if (pos != std::string::npos) {
5455  ss.str(ss.str().erase(pos+1));
5456  }
5457  if (ss.str().find('\n') == std::string::npos) {
5458  out << ss.str() << std::endl;
5459  } else {
5460  out << "cqasm::v1::primitives::Str<<" << std::endl;
5461  indent++;
5462  std::string s;
5463  while (!ss.eof()) {
5464  std::getline(ss, s);
5465  write_indent();
5466  out << s << std::endl;
5467  }
5468  indent--;
5469  write_indent();
5470  out << ">>" << std::endl;
5471  }
5472  write_indent();
5473  out << "iterations: ";
5474  ss.str("");
5475  ss.clear();
5476  ss << node.iterations;
5477  pos = ss.str().find_last_not_of(" \n\r\t");
5478  if (pos != std::string::npos) {
5479  ss.str(ss.str().erase(pos+1));
5480  }
5481  if (ss.str().find('\n') == std::string::npos) {
5482  out << ss.str() << std::endl;
5483  } else {
5484  out << "cqasm::v1::primitives::Int<<" << std::endl;
5485  indent++;
5486  std::string s;
5487  while (!ss.eof()) {
5488  std::getline(ss, s);
5489  write_indent();
5490  out << s << std::endl;
5491  }
5492  indent--;
5493  write_indent();
5494  out << ">>" << std::endl;
5495  }
5496  write_indent();
5497  out << "bundles: ";
5498  if (node.bundles.empty()) {
5499  out << "[]" << std::endl;
5500  } else {
5501  out << "[" << std::endl;
5502  indent++;
5503  for (auto &sptr : node.bundles) {
5504  if (!sptr.empty()) {
5505  sptr->visit(*this);
5506  } else {
5507  write_indent();
5508  out << "!NULL" << std::endl;
5509  }
5510  }
5511  indent--;
5512  write_indent();
5513  out << "]" << std::endl;
5514  }
5515  write_indent();
5516  out << "annotations: ";
5517  if (node.annotations.empty()) {
5518  out << "[]" << std::endl;
5519  } else {
5520  out << "[" << std::endl;
5521  indent++;
5522  for (auto &sptr : node.annotations) {
5523  if (!sptr.empty()) {
5524  sptr->visit(*this);
5525  } else {
5526  write_indent();
5527  out << "!NULL" << std::endl;
5528  }
5529  }
5530  indent--;
5531  write_indent();
5532  out << "]" << std::endl;
5533  }
5534  write_indent();
5535  out << "body: ";
5536  if (node.body.empty()) {
5537  out << "-" << std::endl;
5538  } else {
5539  out << "<" << std::endl;
5540  indent++;
5541  node.body.visit(*this);
5542  indent--;
5543  write_indent();
5544  out << ">" << std::endl;
5545  }
5546  indent--;
5547  write_indent();
5548  out << ")" << std::endl;
5549 }
5550 
5555  write_indent();
5556  out << "Variable";
5557  if (ids != nullptr) {
5558  out << "@" << ids->get_ref(node);
5559  }
5560  out << "(";
5561  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
5562  out << " # " << *loc;
5563  }
5564  out << std::endl;
5565  indent++;
5566  write_indent();
5567  out << "name: ";
5568  std::stringstream ss;
5569  size_t pos;
5570  ss << node.name;
5571  pos = ss.str().find_last_not_of(" \n\r\t");
5572  if (pos != std::string::npos) {
5573  ss.str(ss.str().erase(pos+1));
5574  }
5575  if (ss.str().find('\n') == std::string::npos) {
5576  out << ss.str() << std::endl;
5577  } else {
5578  out << "cqasm::v1::primitives::Str<<" << std::endl;
5579  indent++;
5580  std::string s;
5581  while (!ss.eof()) {
5582  std::getline(ss, s);
5583  write_indent();
5584  out << s << std::endl;
5585  }
5586  indent--;
5587  write_indent();
5588  out << ">>" << std::endl;
5589  }
5590  write_indent();
5591  out << "typ: ";
5592  if (node.typ.empty()) {
5593  out << "!MISSING" << std::endl;
5594  } else {
5595  out << "<" << std::endl;
5596  indent++;
5597  if (!node.typ.empty()) {
5598  node.typ->dump(out, indent);
5599  }
5600  indent--;
5601  write_indent();
5602  out << ">" << std::endl;
5603  }
5604  write_indent();
5605  out << "annotations: ";
5606  if (node.annotations.empty()) {
5607  out << "[]" << std::endl;
5608  } else {
5609  out << "[" << std::endl;
5610  indent++;
5611  for (auto &sptr : node.annotations) {
5612  if (!sptr.empty()) {
5613  sptr->visit(*this);
5614  } else {
5615  write_indent();
5616  out << "!NULL" << std::endl;
5617  }
5618  }
5619  indent--;
5620  write_indent();
5621  out << "]" << std::endl;
5622  }
5623  indent--;
5624  write_indent();
5625  out << ")" << std::endl;
5626 }
5627 
5632  write_indent();
5633  out << "Version";
5634  if (ids != nullptr) {
5635  out << "@" << ids->get_ref(node);
5636  }
5637  out << "(";
5638  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
5639  out << " # " << *loc;
5640  }
5641  out << std::endl;
5642  indent++;
5643  write_indent();
5644  out << "items: ";
5645  std::stringstream ss;
5646  size_t pos;
5647  ss << node.items;
5648  pos = ss.str().find_last_not_of(" \n\r\t");
5649  if (pos != std::string::npos) {
5650  ss.str(ss.str().erase(pos+1));
5651  }
5652  if (ss.str().find('\n') == std::string::npos) {
5653  out << ss.str() << std::endl;
5654  } else {
5655  out << "cqasm::v1::primitives::Version<<" << std::endl;
5656  indent++;
5657  std::string s;
5658  while (!ss.eof()) {
5659  std::getline(ss, s);
5660  write_indent();
5661  out << s << std::endl;
5662  }
5663  indent--;
5664  write_indent();
5665  out << ">>" << std::endl;
5666  }
5667  indent--;
5668  write_indent();
5669  out << ")" << std::endl;
5670 }
5671 
5676  write_indent();
5677  out << "WhileLoop";
5678  if (ids != nullptr) {
5679  out << "@" << ids->get_ref(node);
5680  }
5681  out << "(";
5682  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
5683  out << " # " << *loc;
5684  }
5685  out << std::endl;
5686  indent++;
5687  write_indent();
5688  out << "condition: ";
5689  if (node.condition.empty()) {
5690  out << "!MISSING" << std::endl;
5691  } else {
5692  out << "<" << std::endl;
5693  indent++;
5694  if (!node.condition.empty()) {
5695  node.condition->dump(out, indent);
5696  }
5697  indent--;
5698  write_indent();
5699  out << ">" << std::endl;
5700  }
5701  write_indent();
5702  out << "body: ";
5703  if (node.body.empty()) {
5704  out << "!MISSING" << std::endl;
5705  } else {
5706  out << "<" << std::endl;
5707  indent++;
5708  node.body.visit(*this);
5709  indent--;
5710  write_indent();
5711  out << ">" << std::endl;
5712  }
5713  write_indent();
5714  out << "annotations: ";
5715  if (node.annotations.empty()) {
5716  out << "[]" << std::endl;
5717  } else {
5718  out << "[" << std::endl;
5719  indent++;
5720  for (auto &sptr : node.annotations) {
5721  if (!sptr.empty()) {
5722  sptr->visit(*this);
5723  } else {
5724  write_indent();
5725  out << "!NULL" << std::endl;
5726  }
5727  }
5728  indent--;
5729  write_indent();
5730  out << "]" << std::endl;
5731  }
5732  indent--;
5733  write_indent();
5734  out << ")" << std::endl;
5735 }
5736 
5740 template <>
5741 void Node::visit(Visitor<void> &visitor) {
5742  this->visit_internal(visitor);
5743 }
5744 
5748 std::ostream &operator<<(std::ostream &os, const Node &object) {
5749  const_cast<Node&>(object).dump(os);
5750  return os;
5751 }
5752 
5753 } // namespace semantic
5754 } // namespace v1
5755 } // namespace cqasm
5756 
void visit_mapping(Mapping &node) override
Recursive traversal for Mapping nodes.
The file version identifier.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this BundleExt is complete/fully defined.
void visit_block(Block &node) override
Recursive traversal for Block nodes.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
Annotated(const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
NodeType type() const override
Returns the NodeType of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
static std::shared_ptr< ContinueStatement > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
static std::shared_ptr< Structured > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
Block(const Any< Statement > &statements=Any< Statement >())
Constructor.
void visit_if_else(IfElse &node) override
Recursive traversal for IfElse nodes.
void visit_statement(Statement &node) override
Recursive traversal for Statement nodes.
virtual Bundle * as_bundle()
Interprets this node to a node of type Bundle.
IfElse * as_if_else() override
Interprets this node to a node of type IfElse.
NodeType type() const override
Returns the NodeType of this node.
Visitor class that debug-dumps a tree to a stream.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
virtual IfElse * as_if_else()
Interprets this node to a node of type IfElse.
NodeType
Enumeration of all node types.
BundleExt * as_bundle_ext() override
Interprets this node to a node of type BundleExt.
static std::shared_ptr< Variable > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
cqasm::v1::primitives::Str name
The name of the subcircuit.
One< Node > copy() const override
Returns a shallow copy of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
RepeatUntilLoop(const One< Block > &body=One< Block >(), const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void visit_structured(Structured &node) override
Recursive traversal for Structured nodes.
void visit_foreach_loop(ForeachLoop &node) override
Recursive traversal for ForeachLoop nodes.
static std::shared_ptr< Annotated > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
One< Node > clone() const override
Returns a deep copy of this node.
virtual void raw_visit_bundle(Bundle &node, void *retval)=0
Internal visitor function for Bundle nodes.
static std::shared_ptr< ErrorModel > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void raw_visit_for_loop(ForLoop &node, void *retval) override
Internal visitor function for ForLoop nodes.
void raw_visit_annotation_data(AnnotationData &node, void *retval) override
Internal visitor function for AnnotationData nodes.
One< Node > clone() const override
Returns a deep copy of this node.
virtual Block * as_block()
Interprets this node to a node of type Block.
static std::shared_ptr< Instruction > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
Represents a node that carries annotation data.
A C-style for loop.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
ContinueStatement * as_continue_statement() override
Interprets this node to a node of type ContinueStatement.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void raw_visit_variable(Variable &node, void *retval) override
Internal visitor function for Variable nodes.
WhileLoop * as_while_loop() override
Interprets this node to a node of type WhileLoop.
NodeType type() const override
Returns the NodeType of this node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void raw_visit_break_statement(BreakStatement &node, void *retval) override
Internal visitor function for BreakStatement nodes.
One< Node > clone() const override
Returns a deep copy of this node.
T visit(Visitor< T > &visitor)
Visit this object.
tree::Maybe< ErrorModel > ErrorModelRef
Optional reference to an error model, used within the semantic tree.
Any< Variable > variables
This list of all user-defined variables at any point in the code.
One< Node > clone() const override
Returns a deep copy of this node.
static std::shared_ptr< IfElse > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
Statement(const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
RepeatUntilLoop * as_repeat_until_loop() override
Interprets this node to a node of type RepeatUntilLoop.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
NodeType type() const override
Returns the NodeType of this node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
tree::Maybe< Instruction > InstructionRef
Optional reference to an instruction, used within the semantic tree.
cqasm::v1::primitives::Str name
Name as it appears in the cQASM file.
virtual void raw_visit_foreach_loop(ForeachLoop &node, void *retval)=0
Internal visitor function for ForeachLoop nodes.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
NodeType type() const override
Returns the NodeType of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
AnnotationData(const cqasm::v1::primitives::Str &interface=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const cqasm::v1::primitives::Str &operation=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const Any< cqasm::v1::values::Node > &operands=cqasm::v1::primitives::initialize< Any< cqasm::v1::values::Node >>())
Constructor.
void visit_for_loop(ForLoop &node) override
Recursive traversal for ForLoop nodes.
Structured * as_structured() override
Interprets this node to a node of type Structured.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void visit_subcircuit(Subcircuit &node) override
Dumps a Subcircuit node.
One< Node > clone() const override
Returns a deep copy of this node.
cqasm::tree::Any< T > Any
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this WhileLoop is complete/fully defined.
cqasm::tree::One< T > One
void raw_visit_foreach_loop(ForeachLoop &node, void *retval) override
Internal visitor function for ForeachLoop nodes.
A list of parallel instructions.
One< cqasm::v1::values::Node > lhs
The assignment target.
NodeType type() const override
Returns the NodeType of this node.
virtual void raw_visit_subcircuit(Subcircuit &node, void *retval)=0
Internal visitor function for Subcircuit nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Subcircuit is complete/fully defined.
void visit_version(Version &node) override
Dumps a Version node.
void visit_block(Block &node) override
Dumps a Block node.
cqasm::v1::primitives::Str interface
The interface this annotation is intended for.
Contains annotation objects used within the trees by libqasm.
void raw_visit_set_instruction(SetInstruction &node, void *retval) override
Internal visitor function for SetInstruction nodes.
NodeType type() const override
Returns the NodeType of this node.
NodeType type() const override
Returns the NodeType of this node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Bundle is complete/fully defined.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
cqasm::v1::instruction::InstructionRef instruction
Instruction type as registered through the API.
cqasm::v1::primitives::Int to
The last value.
One< cqasm::v1::values::Node > condition
Condition (c- notation).
cqasm::v1::primitives::Str name
Name as it appears in the cQASM file.
Toplevel namespace with entry points for the new API.
ContinueStatement(const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this AnnotationData is complete/fully defined.
ErrorModel * as_error_model() override
Interprets this node to a node of type ErrorModel.
Any< cqasm::v1::values::Node > parameters
Error model parameters.
InstructionBase * as_instruction_base() override
Interprets this node to a node of type InstructionBase.
static std::shared_ptr< Statement > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual BreakStatement * as_break_statement()
Interprets this node to a node of type BreakStatement.
One< Block > body
The loop body.
Subcircuit(const cqasm::v1::primitives::Str &name=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const cqasm::v1::primitives::Int &iterations=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >(), const Any< Bundle > &bundles=Any< Bundle >(), const Any< AnnotationData > &annotations=Any< AnnotationData >(), const Maybe< Block > &body=Maybe< Block >())
Constructor.
void visit_while_loop(WhileLoop &node) override
Recursive traversal for WhileLoop nodes.
virtual InstructionBase * as_instruction_base()
Interprets this node to a node of type InstructionBase.
Any kind of instruction.
One< Node > clone() const override
Returns a deep copy of this node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
Any< cqasm::v1::values::Node > operands
Any operands attached to the annotation.
Program * as_program() override
Interprets this node to a node of type Program.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
BreakStatement(const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this BreakStatement is complete/fully defined.
SetInstruction(const One< cqasm::v1::values::Node > &lhs=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const One< cqasm::v1::values::Node > &rhs=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
virtual BundleExt * as_bundle_ext()
Interprets this node to a node of type BundleExt.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ForLoop is complete/fully defined.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this IfElseBranch is complete/fully defined.
void raw_visit_block(Block &node, void *retval) override
Internal visitor function for Block nodes.
void raw_visit_node(Node &node, void *retval) override
Internal visitor function for nodes of any type.
Many< InstructionBase > items
The list of parallel instructions.
A mapping (alias) for an expression.
virtual void raw_visit_block(Block &node, void *retval)=0
Internal visitor function for Block nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
static std::shared_ptr< ForeachLoop > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
static std::shared_ptr< Bundle > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_version(Version &node) override
Recursive traversal for Version nodes.
Any< Subcircuit > subcircuits
The list of subcircuit.
Source location annotation object, containing source file line numbers etc.
AnnotationData * as_annotation_data() override
Interprets this node to a node of type AnnotationData.
void visit_annotated(Annotated &node) override
Dumps a Annotated node.
A single condition + block for use in an if-else chain.
void visit_error_model(ErrorModel &node) override
Recursive traversal for ErrorModel nodes.
void visit_if_else_branch(IfElseBranch &node) override
Dumps a IfElseBranch node.
ForLoop * as_for_loop() override
Interprets this node to a node of type ForLoop.
bool equals(const Node &rhs) const override
Value-based equality operator.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
One< Version > version
File version.
void visit_program(Program &node) override
Dumps a Program node.
Internal class for implementing the visitor pattern.
NodeType type() const override
Returns the NodeType of this node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
One< Node > clone() const override
Returns a deep copy of this node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
static std::shared_ptr< BundleExt > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Program is complete/fully defined.
virtual void raw_visit_annotation_data(AnnotationData &node, void *retval)=0
Internal visitor function for AnnotationData nodes.
virtual void raw_visit_repeat_until_loop(RepeatUntilLoop &node, void *retval)=0
Internal visitor function for RepeatUntilLoop nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
bool equals(const Node &rhs) const override
Value-based equality operator.
virtual Instruction * as_instruction()
Interprets this node to a node of type Instruction.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
Variable(const cqasm::v1::primitives::Str &name=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const One< cqasm::v1::types::Node > &typ=cqasm::v1::primitives::initialize< One< cqasm::v1::types::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
virtual void raw_visit_continue_statement(ContinueStatement &node, void *retval)=0
Internal visitor function for ContinueStatement nodes.
virtual GotoInstruction * as_goto_instruction()
Interprets this node to a node of type GotoInstruction.
void raw_visit_error_model(ErrorModel &node, void *retval) override
Internal visitor function for ErrorModel nodes.
virtual void raw_visit_bundle_ext(BundleExt &node, void *retval)=0
Internal visitor function for BundleExt nodes.
void visit_goto_instruction(GotoInstruction &node) override
Dumps a GotoInstruction node.
One< Node > copy() const override
Returns a shallow copy of this node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
Version * as_version() override
Interprets this node to a node of type Version.
One< Node > clone() const override
Returns a deep copy of this node.
static std::shared_ptr< WhileLoop > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual Program * as_program()
Interprets this node to a node of type Program.
std::int64_t Int
Integer primitive used within the AST and semantic trees.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
virtual ForeachLoop * as_foreach_loop()
Interprets this node to a node of type ForeachLoop.
void visit_variable(Variable &node) override
Dumps a Variable node.
void visit_annotation_data(AnnotationData &node) override
Dumps a AnnotationData node.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
GotoInstruction * as_goto_instruction() override
Interprets this node to a node of type GotoInstruction.
static std::shared_ptr< IfElseBranch > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
bool equals(const Node &rhs) const override
Value-based equality operator.
InstructionBase(const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void visit_repeat_until_loop(RepeatUntilLoop &node) override
Recursive traversal for RepeatUntilLoop nodes.
One< Node > clone() const override
Returns a deep copy of this node.
cqasm::v1::error_model::ErrorModelRef model
Error model type as registered through the API.
Main class for all nodes.
virtual Mapping * as_mapping()
Interprets this node to a node of type Mapping.
NodeType type() const override
Returns the NodeType of this node.
One< Node > clone() const override
Returns a deep copy of this node.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
A version 1.2+ assignment instruction.
void raw_visit_goto_instruction(GotoInstruction &node, void *retval) override
Internal visitor function for GotoInstruction nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
Version number primitive used within the AST and semantic trees.
One< Node > copy() const override
Returns a shallow copy of this node.
One< Node > clone() const override
Returns a deep copy of this node.
ForLoop(const Maybe< SetInstruction > &initialize=Maybe< SetInstruction >(), const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Maybe< SetInstruction > &update=Maybe< SetInstruction >(), const One< Block > &body=One< Block >(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
ForeachLoop * as_foreach_loop() override
Interprets this node to a node of type ForeachLoop.
void write_indent()
Writes the current indentation level&#39;s worth of spaces.
void visit_mapping(Mapping &node) override
Dumps a Mapping node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
NodeType type() const override
Returns the NodeType of this node.
virtual ForLoop * as_for_loop()
Interprets this node to a node of type ForLoop.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ErrorModel is complete/fully defined.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
virtual Variable * as_variable()
Interprets this node to a node of type Variable.
One< Node > clone() const override
Returns a deep copy of this node.
void visit_repeat_until_loop(RepeatUntilLoop &node) override
Dumps a RepeatUntilLoop node.
cqasm::v1::primitives::Int frm
The first value.
One< Node > clone() const override
Returns a deep copy of this node.
static std::shared_ptr< InstructionBase > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
One< Node > copy() const override
Returns a shallow copy of this node.
virtual void raw_visit_error_model(ErrorModel &node, void *retval)=0
Internal visitor function for ErrorModel nodes.
A bundle of instructions, to be executed in parallel.
virtual SetInstruction * as_set_instruction()
Interprets this node to a node of type SetInstruction.
virtual IfElseBranch * as_if_else_branch()
Interprets this node to a node of type IfElseBranch.
void visit_for_loop(ForLoop &node) override
Dumps a ForLoop node.
void visit_continue_statement(ContinueStatement &node) override
Dumps a ContinueStatement node.
void visit_while_loop(WhileLoop &node) override
Dumps a WhileLoop node.
Maybe< Block > otherwise
The final else block, if any.
One< cqasm::v1::values::Node > lhs
Reference to the variable used for looping.
IfElseBranch * as_if_else_branch() override
Interprets this node to a node of type IfElseBranch.
One< Node > copy() const override
Returns a shallow copy of this node.
cqasm::v1::primitives::Int iterations
An optional integer expression representing the number of iterations for this subcircuit.
One< cqasm::v1::values::Node > condition
The condition for starting another iteration.
virtual Structured * as_structured()
Interprets this node to a node of type Structured.
static std::shared_ptr< Subcircuit > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this GotoInstruction is complete/fully defined.
One< Node > copy() const override
Returns a shallow copy of this node.
Instruction * as_instruction() override
Interprets this node to a node of type Instruction.
Main class for all nodes.
Any kind of statement.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
bool equals(const Node &rhs) const override
Value-based equality operator.
One< Node > copy() const override
Returns a shallow copy of this node.
NodeType type() const override
Returns the NodeType of this node.
void visit_bundle_ext(BundleExt &node) override
Dumps a BundleExt node.
cqasm::tree::Maybe< T > Maybe
void raw_visit_instruction_base(InstructionBase &node, void *retval) override
Internal visitor function for InstructionBase nodes.
Any version 1.2+ structured control-flow statement.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
Block * as_block() override
Interprets this node to a node of type Block.
BundleExt(const Many< InstructionBase > &items=Many< InstructionBase >(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void visit_statement(Statement &node) override
Dumps a Statement node.
One< cqasm::v1::values::Node > condition
The condition.
SetInstruction * as_set_instruction() override
Interprets this node to a node of type SetInstruction.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void raw_visit_subcircuit(Subcircuit &node, void *retval) override
Internal visitor function for Subcircuit nodes.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
NodeType type() const override
Returns the NodeType of this node.
virtual NodeType type() const =0
Returns the NodeType of this node.
Represents an annotation.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
T initialize()
Generates a default value for the given primitive type.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ForeachLoop is complete/fully defined.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void visit_bundle(Bundle &node) override
Dumps a Bundle node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void visit_annotation_data(AnnotationData &node) override
Recursive traversal for AnnotationData nodes.
void visit_structured(Structured &node) override
Dumps a Structured node.
bool equals(const Node &rhs) const override
Value-based equality operator.
void visit_instruction(Instruction &node) override
Dumps a Instruction node.
Header file for the semantic tree node classes.
GotoInstruction(const Link< Subcircuit > &target=Link< Subcircuit >(), const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
bool equals(const Node &rhs) const override
Value-based equality operator.
std::ostream & operator<<(std::ostream &os, const Node &object)
Stream << overload for tree nodes (writes debug dump).
static std::shared_ptr< RepeatUntilLoop > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_instruction_base(InstructionBase &node) override
Recursive traversal for InstructionBase nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void raw_visit_instruction(Instruction &node, void *retval) override
Internal visitor function for Instruction nodes.
Bundle(const Many< Instruction > &items=Many< Instruction >(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
NodeType type() const override
Returns the NodeType of this node.
IfElseBranch(const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const One< Block > &body=One< Block >())
Constructor.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this SetInstruction is complete/fully defined.
Many< IfElseBranch > branches
The if-else branches.
NodeType type() const override
Returns the NodeType of this node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
virtual void raw_visit_if_else_branch(IfElseBranch &node, void *retval)=0
Internal visitor function for IfElseBranch nodes.
virtual void raw_visit_mapping(Mapping &node, void *retval)=0
Internal visitor function for Mapping nodes.
Mapping(const cqasm::v1::primitives::Str &name=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const One< cqasm::v1::values::Node > &value=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
virtual void raw_visit_set_instruction(SetInstruction &node, void *retval)=0
Internal visitor function for SetInstruction nodes.
virtual Version * as_version()
Interprets this node to a node of type Version.
Namespace for the "new" cQASM 1.x API.
bool equals(const Node &rhs) const override
Value-based equality operator.
static std::shared_ptr< AnnotationData > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void raw_visit_structured(Structured &node, void *retval) override
Internal visitor function for Structured nodes.
One< cqasm::v1::values::Node > rhs
The value to assign.
void raw_visit_repeat_until_loop(RepeatUntilLoop &node, void *retval) override
Internal visitor function for RepeatUntilLoop nodes.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
cqasm::v1::primitives::Version items
The list of version components, ordered major to minor.
void raw_visit_while_loop(WhileLoop &node, void *retval) override
Internal visitor function for WhileLoop nodes.
virtual void raw_visit_goto_instruction(GotoInstruction &node, void *retval)=0
Internal visitor function for GotoInstruction nodes.
One< Node > clone() const override
Returns a deep copy of this node.
cqasm::tree::Link< T > Link
One< Node > copy() const override
Returns a shallow copy of this node.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
virtual WhileLoop * as_while_loop()
Interprets this node to a node of type WhileLoop.
void visit_instruction_base(InstructionBase &node) override
Dumps a InstructionBase node.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
Variable * as_variable() override
Interprets this node to a node of type Variable.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
ForeachLoop(const One< cqasm::v1::values::Node > &lhs=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const cqasm::v1::primitives::Int &frm=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >(), const cqasm::v1::primitives::Int &to=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >(), const One< Block > &body=One< Block >(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
One< Node > clone() const override
Returns a deep copy of this node.
One< Node > clone() const override
Returns a deep copy of this node.
cqasm::v1::primitives::Str name
The name of the variable.
The file version identifier.
Structured(const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
One< Node > clone() const override
Returns a deep copy of this node.
void raw_visit_statement(Statement &node, void *retval) override
Internal visitor function for Statement nodes.
virtual void raw_visit_break_statement(BreakStatement &node, void *retval)=0
Internal visitor function for BreakStatement nodes.
void visit_goto_instruction(GotoInstruction &node) override
Recursive traversal for GotoInstruction nodes.
Maybe< SetInstruction > initialize
The optional initializing assignment, run before the loop starts.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
One< Node > copy() const override
Returns a shallow copy of this node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
cqasm::v1::primitives::Str operation
The operation within the interface that this annotation is intended for.
One< Node > clone() const override
Returns a deep copy of this node.
virtual AnnotationData * as_annotation_data()
Interprets this node to a node of type AnnotationData.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
One< cqasm::v1::values::Node > value
The value it maps to.
void raw_visit_version(Version &node, void *retval) override
Internal visitor function for Version nodes.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
static std::shared_ptr< ForLoop > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
static std::shared_ptr< SetInstruction > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_node(Node &node) override
Dumps a Node.
Statement * as_statement() override
Interprets this node to a node of type Statement.
Subcircuit * as_subcircuit() override
Interprets this node to a node of type Subcircuit.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
One< cqasm::v1::types::Node > typ
The type of the variable.
A single condition + block for use in an if-else chain.
bool equals(const Node &rhs) const override
Value-based equality operator.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
std::string Str
String primitive used within the AST and semantic trees.
Many< Instruction > items
The list of parallel instructions.
WhileLoop(const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const One< Block > &body=One< Block >(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
One< Node > copy() const override
Returns a shallow copy of this node.
void raw_visit_program(Program &node, void *retval) override
Internal visitor function for Program nodes.
cqasm::v1::primitives::Int num_qubits
The required qubit register size.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Block is complete/fully defined.
One< Block > body
The loop body.
bool equals(const Node &rhs) const override
Value-based equality operator.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this IfElse is complete/fully defined.
Any< Bundle > bundles
The instruction bundles contained by this subcircuit.
IfElse(const Many< IfElseBranch > &branches=Many< IfElseBranch >(), const Maybe< Block > &otherwise=Maybe< Block >(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void raw_visit_if_else(IfElse &node, void *retval) override
Internal visitor function for IfElse nodes.
Mapping * as_mapping() override
Interprets this node to a node of type Mapping.
cqasm::v1::primitives::Version api_version
API version.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void raw_visit_bundle(Bundle &node, void *retval) override
Internal visitor function for Bundle nodes.
virtual Subcircuit * as_subcircuit()
Interprets this node to a node of type Subcircuit.
Maybe< Block > body
The statements contained by this subcircuit.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
static std::shared_ptr< BreakStatement > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_continue_statement(ContinueStatement &node) override
Recursive traversal for ContinueStatement nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
Instruction(const cqasm::v1::instruction::InstructionRef &instruction=cqasm::v1::primitives::initialize< cqasm::v1::instruction::InstructionRef >(), const cqasm::v1::primitives::Str &name=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Any< cqasm::v1::values::Node > &operands=cqasm::v1::primitives::initialize< Any< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
Maybe< SetInstruction > update
The updating assignment, done at the end of the loop body and upon continue.
void raw_visit_mapping(Mapping &node, void *retval) override
Internal visitor function for Mapping nodes.
NodeType type() const override
Returns the NodeType of this node.
void raw_visit_continue_statement(ContinueStatement &node, void *retval) override
Internal visitor function for ContinueStatement nodes.
static std::shared_ptr< Node > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void dump(std::ostream &out=std::cout, int indent=0)
Writes a debug dump of this node to the given stream.
NodeType type() const override
Returns the NodeType of this node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Variable is complete/fully defined.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
virtual void raw_visit_variable(Variable &node, void *retval)=0
Internal visitor function for Variable nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
Any< Mapping > mappings
The list of all user-defined mappings after parsing.
Any< AnnotationData > annotations
Zero or more annotations attached to this object.
virtual void raw_visit_while_loop(WhileLoop &node, void *retval)=0
Internal visitor function for WhileLoop nodes.
A complete program.
Any version 1.2+ structured control-flow statement.
virtual void raw_visit_for_loop(ForLoop &node, void *retval)=0
Internal visitor function for ForLoop nodes.
virtual void raw_visit_instruction(Instruction &node, void *retval)=0
Internal visitor function for Instruction nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
void dump_seq(std::ostream &out=std::cout, int indent=0)
Alternate debug dump that represents links and node uniqueness via sequence number tags...
NodeType type() const override
Returns the NodeType of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
A version 1.2+ goto instruction.
void raw_visit_annotated(Annotated &node, void *retval) override
Internal visitor function for Annotated nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
static std::shared_ptr< Program > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual bool equals(const Node &rhs) const =0
Value-based equality operator.
One< cqasm::v1::values::Node > condition
The condition for starting another iteration.
void visit_variable(Variable &node) override
Recursive traversal for Variable nodes.
NodeType type() const override
Returns the NodeType of this node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this RepeatUntilLoop is complete/fully defined.
NodeType type() const override
Returns the NodeType of this node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Version is complete/fully defined.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void visit_error_model(ErrorModel &node) override
Dumps a ErrorModel node.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
NodeType type() const override
Returns the NodeType of this node.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
Version(const cqasm::v1::primitives::Version &items=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Version >())
Constructor.
Any< cqasm::v1::values::Node > operands
Operands for the instruction.
Bundle * as_bundle() override
Interprets this node to a node of type Bundle.
static std::shared_ptr< Mapping > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual ErrorModel * as_error_model()
Interprets this node to a node of type ErrorModel.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
bool equals(const Node &rhs) const override
Value-based equality operator.
cqasm::tree::Many< T > Many
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ContinueStatement is complete/fully defined.
void visit_program(Program &node) override
Recursive traversal for Program nodes.
void visit_annotated(Annotated &node) override
Recursive traversal for Annotated nodes.
Link< Subcircuit > target
Link to the target subcircuit, used as a label.
Program(const One< Version > &version=One< Version >(), const cqasm::v1::primitives::Int &num_qubits=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >(), const Maybe< ErrorModel > &error_model=Maybe< ErrorModel >(), const Any< Subcircuit > &subcircuits=Any< Subcircuit >(), const Any< Mapping > &mappings=Any< Mapping >(), const Any< Variable > &variables=Any< Variable >(), const cqasm::v1::primitives::Version &api_version=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Version >())
Constructor.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
cqasm::v1::primitives::Str name
The name of the mapping.
One< Node > copy() const override
Returns a shallow copy of this node.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
virtual void raw_visit_if_else(IfElse &node, void *retval)=0
Internal visitor function for IfElse nodes.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void raw_visit_bundle_ext(BundleExt &node, void *retval) override
Internal visitor function for BundleExt nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
virtual Annotated * as_annotated()
Interprets this node to a node of type Annotated.
One< cqasm::v1::values::Node > condition
The condition for stopping iteration.
void visit_subcircuit(Subcircuit &node) override
Recursive traversal for Subcircuit nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
virtual Statement * as_statement()
Interprets this node to a node of type Statement.
void visit_if_else(IfElse &node) override
Dumps a IfElse node.
void visit_set_instruction(SetInstruction &node) override
Recursive traversal for SetInstruction nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
void raw_visit_if_else_branch(IfElseBranch &node, void *retval) override
Internal visitor function for IfElseBranch nodes.
Represents a node that carries annotation data.
virtual void raw_visit_version(Version &node, void *retval)=0
Internal visitor function for Version nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
Any< Statement > statements
The statements contained by the block.
One< Node > copy() const override
Returns a shallow copy of this node.
A bundle of instructions, to be executed in parallel.
BreakStatement * as_break_statement() override
Interprets this node to a node of type BreakStatement.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Instruction is complete/fully defined.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
Maybe< ErrorModel > error_model
Error model information.
static std::shared_ptr< GotoInstruction > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_if_else_branch(IfElseBranch &node) override
Recursive traversal for IfElseBranch nodes.
static std::shared_ptr< Block > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual RepeatUntilLoop * as_repeat_until_loop()
Interprets this node to a node of type RepeatUntilLoop.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
One< Node > clone() const override
Returns a deep copy of this node.
One< Node > clone() const override
Returns a deep copy of this node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
One< Node > clone() const override
Returns a deep copy of this node.
void visit_bundle_ext(BundleExt &node) override
Recursive traversal for BundleExt nodes.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void visit_instruction(Instruction &node) override
Recursive traversal for Instruction nodes.
Annotated * as_annotated() override
Interprets this node to a node of type Annotated.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void visit_bundle(Bundle &node) override
Recursive traversal for Bundle nodes.
virtual ContinueStatement * as_continue_statement()
Interprets this node to a node of type ContinueStatement.
void visit_break_statement(BreakStatement &node) override
Recursive traversal for BreakStatement nodes.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
bool equals(const Node &rhs) const override
Value-based equality operator.
ErrorModel(const cqasm::v1::error_model::ErrorModelRef &model=cqasm::v1::primitives::initialize< cqasm::v1::error_model::ErrorModelRef >(), const cqasm::v1::primitives::Str &name=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const Any< cqasm::v1::values::Node > &parameters=cqasm::v1::primitives::initialize< Any< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
static std::shared_ptr< Version > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_foreach_loop(ForeachLoop &node) override
Dumps a ForeachLoop node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Mapping is complete/fully defined.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
One< Node > copy() const override
Returns a shallow copy of this node.
virtual void raw_visit_program(Program &node, void *retval)=0
Internal visitor function for Program nodes.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void visit_break_statement(BreakStatement &node) override
Dumps a BreakStatement node.
void visit_set_instruction(SetInstruction &node) override
Dumps a SetInstruction node.