libqasm
library for handling cQASM files
cqasm-v1-values-gen.cpp
Go to the documentation of this file.
1 
6 #include "cqasm-v1-semantic.hpp"
7 #include "cqasm-annotations.hpp"
9 
10 namespace cqasm {
11 namespace v1 {
12 namespace values {
13 
17 void Node::dump(std::ostream &out, int indent) {
18  auto dumper = Dumper(out, indent);
19  visit(dumper);
20 }
21 
26 void Node::dump_seq(std::ostream &out, int indent) {
27  ::tree::base::PointerMap ids;
28  ids.enable_exceptions = false;
29  ids.add_ref(*this);
30  find_reachable(ids);
31  auto dumper = Dumper(out, indent, &ids);
32  visit(dumper);
33 }
34 
40  return nullptr;
41 }
42 
47 const BitRefs *Node::as_bit_refs() const {
48  return nullptr;
49 }
50 
56  return nullptr;
57 }
58 
64  return nullptr;
65 }
66 
72  return nullptr;
73 }
74 
80  return nullptr;
81 }
82 
88  return nullptr;
89 }
90 
96  return nullptr;
97 }
98 
104  return nullptr;
105 }
106 
112  return nullptr;
113 }
114 
120  return nullptr;
121 }
122 
127 const ConstInt *Node::as_const_int() const {
128  return nullptr;
129 }
130 
136  return nullptr;
137 }
138 
144  return nullptr;
145 }
146 
152  return nullptr;
153 }
154 
160  return nullptr;
161 }
162 
168  return nullptr;
169 }
170 
176  return nullptr;
177 }
178 
184  return nullptr;
185 }
186 
192  return nullptr;
193 }
194 
200  return nullptr;
201 }
202 
207 const Constant *Node::as_constant() const {
208  return nullptr;
209 }
210 
216  return nullptr;
217 }
218 
223 const Function *Node::as_function() const {
224  return nullptr;
225 }
226 
232  return nullptr;
233 }
234 
240  return nullptr;
241 }
242 
248  return nullptr;
249 }
250 
256  return nullptr;
257 }
258 
264  return nullptr;
265 }
266 
272  return nullptr;
273 }
274 
278 std::shared_ptr<Node> Node::deserialize(
279  const ::tree::cbor::MapReader &map,
280  ::tree::base::IdentifierMap &ids
281 ) {
282  auto type = map.at("@t").as_string();
283  if (type == "BitRefs") return BitRefs::deserialize(map, ids);
284  if (type == "ConstAxis") return ConstAxis::deserialize(map, ids);
285  if (type == "ConstBool") return ConstBool::deserialize(map, ids);
286  if (type == "ConstComplex") return ConstComplex::deserialize(map, ids);
287  if (type == "ConstComplexMatrix") return ConstComplexMatrix::deserialize(map, ids);
288  if (type == "ConstInt") return ConstInt::deserialize(map, ids);
289  if (type == "ConstJson") return ConstJson::deserialize(map, ids);
290  if (type == "ConstReal") return ConstReal::deserialize(map, ids);
291  if (type == "ConstRealMatrix") return ConstRealMatrix::deserialize(map, ids);
292  if (type == "ConstString") return ConstString::deserialize(map, ids);
293  if (type == "Function") return Function::deserialize(map, ids);
294  if (type == "QubitRefs") return QubitRefs::deserialize(map, ids);
295  if (type == "VariableRef") return VariableRef::deserialize(map, ids);
296  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
297 }
298 
304  return dynamic_cast<Reference*>(this);
305 }
306 
312  return dynamic_cast<const Reference*>(this);
313 }
314 
318 std::shared_ptr<Reference> Reference::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
319  auto type = map.at("@t").as_string();
320  if (type == "QubitRefs") return QubitRefs::deserialize(map, ids);
321  if (type == "BitRefs") return BitRefs::deserialize(map, ids);
322  if (type == "VariableRef") return VariableRef::deserialize(map, ids);
323  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
324 }
325 
330  : Reference(), index(index)
331 {}
332 
336 void BitRefs::find_reachable(::tree::base::PointerMap &map) const {
337  (void)map;
338  index.find_reachable(map);
339 }
340 
344 void BitRefs::check_complete(const ::tree::base::PointerMap &map) const {
345  (void)map;
346  index.check_complete(map);
347 }
348 
353  return NodeType::BitRefs;
354 }
355 
359 void BitRefs::visit_internal(VisitorBase &visitor, void *retval) {
360  visitor.raw_visit_bit_refs(*this, retval);
361 }
362 
368  return dynamic_cast<BitRefs*>(this);
369 }
370 
376  return dynamic_cast<const BitRefs*>(this);
377 }
378 
383  return cqasm::tree::make<BitRefs>(*this);
384 }
385 
390  auto node = cqasm::tree::make<BitRefs>(*this);
391  node->index = this->index.clone();
392  return node;
393 }
394 
398 bool BitRefs::equals(const Node &rhs) const {
399  if (rhs.type() != NodeType::BitRefs) return false;
400  auto rhsc = dynamic_cast<const BitRefs&>(rhs);
401  if (!this->index.equals(rhsc.index)) return false;
402  return true;
403 }
404 
408 bool BitRefs::operator==(const Node &rhs) const {
409  if (rhs.type() != NodeType::BitRefs) return false;
410  auto rhsc = dynamic_cast<const BitRefs&>(rhs);
411  if (this->index != rhsc.index) return false;
412  return true;
413 }
414 
419  ::tree::cbor::MapWriter &map,
420  const ::tree::base::PointerMap &ids
421 ) const {
422  (void)ids;
423  map.append_string("@t", "BitRefs");
424  auto submap = map.append_map("index");
425  index.serialize(submap, ids);
426  submap.close();
427  serialize_annotations(map);
428 }
429 
433 std::shared_ptr<BitRefs> BitRefs::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
434  (void)ids;
435  auto type = map.at("@t").as_string();
436  if (type != "BitRefs") {
437  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
438  }
439  auto node = std::make_shared<BitRefs>(
440  Many<ConstInt>(map.at("index").as_map(), ids)
441  );
442  node->deserialize_annotations(map);
443  return node;
444 }
445 
451  return dynamic_cast<Constant*>(this);
452 }
453 
459  return dynamic_cast<const Constant*>(this);
460 }
461 
465 std::shared_ptr<Constant> Constant::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
466  auto type = map.at("@t").as_string();
467  if (type == "ConstBool") return ConstBool::deserialize(map, ids);
468  if (type == "ConstAxis") return ConstAxis::deserialize(map, ids);
469  if (type == "ConstInt") return ConstInt::deserialize(map, ids);
470  if (type == "ConstReal") return ConstReal::deserialize(map, ids);
471  if (type == "ConstComplex") return ConstComplex::deserialize(map, ids);
472  if (type == "ConstRealMatrix") return ConstRealMatrix::deserialize(map, ids);
473  if (type == "ConstComplexMatrix") return ConstComplexMatrix::deserialize(map, ids);
474  if (type == "ConstString") return ConstString::deserialize(map, ids);
475  if (type == "ConstJson") return ConstJson::deserialize(map, ids);
476  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
477 }
478 
483  : Constant(), value(value)
484 {}
485 
489 void ConstAxis::find_reachable(::tree::base::PointerMap &map) const {
490  (void)map;
491 }
492 
496 void ConstAxis::check_complete(const ::tree::base::PointerMap &map) const {
497  (void)map;
498 }
499 
504  return NodeType::ConstAxis;
505 }
506 
510 void ConstAxis::visit_internal(VisitorBase &visitor, void *retval) {
511  visitor.raw_visit_const_axis(*this, retval);
512 }
513 
519  return dynamic_cast<ConstAxis*>(this);
520 }
521 
527  return dynamic_cast<const ConstAxis*>(this);
528 }
529 
534  return cqasm::tree::make<ConstAxis>(*this);
535 }
536 
541  auto node = cqasm::tree::make<ConstAxis>(*this);
542  return node;
543 }
544 
548 bool ConstAxis::equals(const Node &rhs) const {
549  if (rhs.type() != NodeType::ConstAxis) return false;
550  auto rhsc = dynamic_cast<const ConstAxis&>(rhs);
551  if (this->value != rhsc.value) return false;
552  return true;
553 }
554 
558 bool ConstAxis::operator==(const Node &rhs) const {
559  if (rhs.type() != NodeType::ConstAxis) return false;
560  auto rhsc = dynamic_cast<const ConstAxis&>(rhs);
561  if (this->value != rhsc.value) return false;
562  return true;
563 }
564 
569  ::tree::cbor::MapWriter &map,
570  const ::tree::base::PointerMap &ids
571 ) const {
572  (void)ids;
573  map.append_string("@t", "ConstAxis");
574  auto submap = map.append_map("value");
575  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Axis>(value, submap);
576  submap.close();
577  serialize_annotations(map);
578 }
579 
583 std::shared_ptr<ConstAxis> ConstAxis::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
584  (void)ids;
585  auto type = map.at("@t").as_string();
586  if (type != "ConstAxis") {
587  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
588  }
589  auto node = std::make_shared<ConstAxis>(
590  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Axis>(map.at("value").as_map())
591  );
592  node->deserialize_annotations(map);
593  return node;
594 }
595 
600  : Constant(), value(value)
601 {}
602 
606 void ConstBool::find_reachable(::tree::base::PointerMap &map) const {
607  (void)map;
608 }
609 
613 void ConstBool::check_complete(const ::tree::base::PointerMap &map) const {
614  (void)map;
615 }
616 
621  return NodeType::ConstBool;
622 }
623 
627 void ConstBool::visit_internal(VisitorBase &visitor, void *retval) {
628  visitor.raw_visit_const_bool(*this, retval);
629 }
630 
636  return dynamic_cast<ConstBool*>(this);
637 }
638 
644  return dynamic_cast<const ConstBool*>(this);
645 }
646 
651  return cqasm::tree::make<ConstBool>(*this);
652 }
653 
658  auto node = cqasm::tree::make<ConstBool>(*this);
659  return node;
660 }
661 
665 bool ConstBool::equals(const Node &rhs) const {
666  if (rhs.type() != NodeType::ConstBool) return false;
667  auto rhsc = dynamic_cast<const ConstBool&>(rhs);
668  if (this->value != rhsc.value) return false;
669  return true;
670 }
671 
675 bool ConstBool::operator==(const Node &rhs) const {
676  if (rhs.type() != NodeType::ConstBool) return false;
677  auto rhsc = dynamic_cast<const ConstBool&>(rhs);
678  if (this->value != rhsc.value) return false;
679  return true;
680 }
681 
686  ::tree::cbor::MapWriter &map,
687  const ::tree::base::PointerMap &ids
688 ) const {
689  (void)ids;
690  map.append_string("@t", "ConstBool");
691  auto submap = map.append_map("value");
692  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(value, submap);
693  submap.close();
694  serialize_annotations(map);
695 }
696 
700 std::shared_ptr<ConstBool> ConstBool::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
701  (void)ids;
702  auto type = map.at("@t").as_string();
703  if (type != "ConstBool") {
704  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
705  }
706  auto node = std::make_shared<ConstBool>(
707  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at("value").as_map())
708  );
709  node->deserialize_annotations(map);
710  return node;
711 }
712 
717  : Constant(), value(value)
718 {}
719 
723 void ConstComplex::find_reachable(::tree::base::PointerMap &map) const {
724  (void)map;
725 }
726 
730 void ConstComplex::check_complete(const ::tree::base::PointerMap &map) const {
731  (void)map;
732 }
733 
738  return NodeType::ConstComplex;
739 }
740 
744 void ConstComplex::visit_internal(VisitorBase &visitor, void *retval) {
745  visitor.raw_visit_const_complex(*this, retval);
746 }
747 
753  return dynamic_cast<ConstComplex*>(this);
754 }
755 
761  return dynamic_cast<const ConstComplex*>(this);
762 }
763 
768  return cqasm::tree::make<ConstComplex>(*this);
769 }
770 
775  auto node = cqasm::tree::make<ConstComplex>(*this);
776  return node;
777 }
778 
782 bool ConstComplex::equals(const Node &rhs) const {
783  if (rhs.type() != NodeType::ConstComplex) return false;
784  auto rhsc = dynamic_cast<const ConstComplex&>(rhs);
785  if (this->value != rhsc.value) return false;
786  return true;
787 }
788 
792 bool ConstComplex::operator==(const Node &rhs) const {
793  if (rhs.type() != NodeType::ConstComplex) return false;
794  auto rhsc = dynamic_cast<const ConstComplex&>(rhs);
795  if (this->value != rhsc.value) return false;
796  return true;
797 }
798 
803  ::tree::cbor::MapWriter &map,
804  const ::tree::base::PointerMap &ids
805 ) const {
806  (void)ids;
807  map.append_string("@t", "ConstComplex");
808  auto submap = map.append_map("value");
809  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Complex>(value, submap);
810  submap.close();
811  serialize_annotations(map);
812 }
813 
817 std::shared_ptr<ConstComplex> ConstComplex::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
818  (void)ids;
819  auto type = map.at("@t").as_string();
820  if (type != "ConstComplex") {
821  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
822  }
823  auto node = std::make_shared<ConstComplex>(
824  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Complex>(map.at("value").as_map())
825  );
826  node->deserialize_annotations(map);
827  return node;
828 }
829 
834  : Constant(), value(value)
835 {}
836 
840 void ConstComplexMatrix::find_reachable(::tree::base::PointerMap &map) const {
841  (void)map;
842 }
843 
847 void ConstComplexMatrix::check_complete(const ::tree::base::PointerMap &map) const {
848  (void)map;
849 }
850 
856 }
857 
861 void ConstComplexMatrix::visit_internal(VisitorBase &visitor, void *retval) {
862  visitor.raw_visit_const_complex_matrix(*this, retval);
863 }
864 
870  return dynamic_cast<ConstComplexMatrix*>(this);
871 }
872 
878  return dynamic_cast<const ConstComplexMatrix*>(this);
879 }
880 
885  return cqasm::tree::make<ConstComplexMatrix>(*this);
886 }
887 
892  auto node = cqasm::tree::make<ConstComplexMatrix>(*this);
893  return node;
894 }
895 
899 bool ConstComplexMatrix::equals(const Node &rhs) const {
900  if (rhs.type() != NodeType::ConstComplexMatrix) return false;
901  auto rhsc = dynamic_cast<const ConstComplexMatrix&>(rhs);
902  if (this->value != rhsc.value) return false;
903  return true;
904 }
905 
909 bool ConstComplexMatrix::operator==(const Node &rhs) const {
910  if (rhs.type() != NodeType::ConstComplexMatrix) return false;
911  auto rhsc = dynamic_cast<const ConstComplexMatrix&>(rhs);
912  if (this->value != rhsc.value) return false;
913  return true;
914 }
915 
920  ::tree::cbor::MapWriter &map,
921  const ::tree::base::PointerMap &ids
922 ) const {
923  (void)ids;
924  map.append_string("@t", "ConstComplexMatrix");
925  auto submap = map.append_map("value");
926  cqasm::v1::primitives::serialize<cqasm::v1::primitives::CMatrix>(value, submap);
927  submap.close();
928  serialize_annotations(map);
929 }
930 
934 std::shared_ptr<ConstComplexMatrix> ConstComplexMatrix::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
935  (void)ids;
936  auto type = map.at("@t").as_string();
937  if (type != "ConstComplexMatrix") {
938  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
939  }
940  auto node = std::make_shared<ConstComplexMatrix>(
941  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::CMatrix>(map.at("value").as_map())
942  );
943  node->deserialize_annotations(map);
944  return node;
945 }
946 
951  : Constant(), value(value)
952 {}
953 
957 void ConstInt::find_reachable(::tree::base::PointerMap &map) const {
958  (void)map;
959 }
960 
964 void ConstInt::check_complete(const ::tree::base::PointerMap &map) const {
965  (void)map;
966 }
967 
972  return NodeType::ConstInt;
973 }
974 
978 void ConstInt::visit_internal(VisitorBase &visitor, void *retval) {
979  visitor.raw_visit_const_int(*this, retval);
980 }
981 
987  return dynamic_cast<ConstInt*>(this);
988 }
989 
995  return dynamic_cast<const ConstInt*>(this);
996 }
997 
1002  return cqasm::tree::make<ConstInt>(*this);
1003 }
1004 
1009  auto node = cqasm::tree::make<ConstInt>(*this);
1010  return node;
1011 }
1012 
1016 bool ConstInt::equals(const Node &rhs) const {
1017  if (rhs.type() != NodeType::ConstInt) return false;
1018  auto rhsc = dynamic_cast<const ConstInt&>(rhs);
1019  if (this->value != rhsc.value) return false;
1020  return true;
1021 }
1022 
1026 bool ConstInt::operator==(const Node &rhs) const {
1027  if (rhs.type() != NodeType::ConstInt) return false;
1028  auto rhsc = dynamic_cast<const ConstInt&>(rhs);
1029  if (this->value != rhsc.value) return false;
1030  return true;
1031 }
1032 
1037  ::tree::cbor::MapWriter &map,
1038  const ::tree::base::PointerMap &ids
1039 ) const {
1040  (void)ids;
1041  map.append_string("@t", "ConstInt");
1042  auto submap = map.append_map("value");
1043  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(value, submap);
1044  submap.close();
1045  serialize_annotations(map);
1046 }
1047 
1051 std::shared_ptr<ConstInt> ConstInt::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1052  (void)ids;
1053  auto type = map.at("@t").as_string();
1054  if (type != "ConstInt") {
1055  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1056  }
1057  auto node = std::make_shared<ConstInt>(
1058  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at("value").as_map())
1059  );
1060  node->deserialize_annotations(map);
1061  return node;
1062 }
1063 
1068  : Constant(), value(value)
1069 {}
1070 
1074 void ConstJson::find_reachable(::tree::base::PointerMap &map) const {
1075  (void)map;
1076 }
1077 
1081 void ConstJson::check_complete(const ::tree::base::PointerMap &map) const {
1082  (void)map;
1083 }
1084 
1089  return NodeType::ConstJson;
1090 }
1091 
1095 void ConstJson::visit_internal(VisitorBase &visitor, void *retval) {
1096  visitor.raw_visit_const_json(*this, retval);
1097 }
1098 
1104  return dynamic_cast<ConstJson*>(this);
1105 }
1106 
1112  return dynamic_cast<const ConstJson*>(this);
1113 }
1114 
1119  return cqasm::tree::make<ConstJson>(*this);
1120 }
1121 
1126  auto node = cqasm::tree::make<ConstJson>(*this);
1127  return node;
1128 }
1129 
1133 bool ConstJson::equals(const Node &rhs) const {
1134  if (rhs.type() != NodeType::ConstJson) return false;
1135  auto rhsc = dynamic_cast<const ConstJson&>(rhs);
1136  if (this->value != rhsc.value) return false;
1137  return true;
1138 }
1139 
1143 bool ConstJson::operator==(const Node &rhs) const {
1144  if (rhs.type() != NodeType::ConstJson) return false;
1145  auto rhsc = dynamic_cast<const ConstJson&>(rhs);
1146  if (this->value != rhsc.value) return false;
1147  return true;
1148 }
1149 
1154  ::tree::cbor::MapWriter &map,
1155  const ::tree::base::PointerMap &ids
1156 ) const {
1157  (void)ids;
1158  map.append_string("@t", "ConstJson");
1159  auto submap = map.append_map("value");
1160  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(value, submap);
1161  submap.close();
1162  serialize_annotations(map);
1163 }
1164 
1168 std::shared_ptr<ConstJson> ConstJson::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1169  (void)ids;
1170  auto type = map.at("@t").as_string();
1171  if (type != "ConstJson") {
1172  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1173  }
1174  auto node = std::make_shared<ConstJson>(
1175  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at("value").as_map())
1176  );
1177  node->deserialize_annotations(map);
1178  return node;
1179 }
1180 
1185  : Constant(), value(value)
1186 {}
1187 
1191 void ConstReal::find_reachable(::tree::base::PointerMap &map) const {
1192  (void)map;
1193 }
1194 
1198 void ConstReal::check_complete(const ::tree::base::PointerMap &map) const {
1199  (void)map;
1200 }
1201 
1206  return NodeType::ConstReal;
1207 }
1208 
1212 void ConstReal::visit_internal(VisitorBase &visitor, void *retval) {
1213  visitor.raw_visit_const_real(*this, retval);
1214 }
1215 
1221  return dynamic_cast<ConstReal*>(this);
1222 }
1223 
1229  return dynamic_cast<const ConstReal*>(this);
1230 }
1231 
1236  return cqasm::tree::make<ConstReal>(*this);
1237 }
1238 
1243  auto node = cqasm::tree::make<ConstReal>(*this);
1244  return node;
1245 }
1246 
1250 bool ConstReal::equals(const Node &rhs) const {
1251  if (rhs.type() != NodeType::ConstReal) return false;
1252  auto rhsc = dynamic_cast<const ConstReal&>(rhs);
1253  if (this->value != rhsc.value) return false;
1254  return true;
1255 }
1256 
1260 bool ConstReal::operator==(const Node &rhs) const {
1261  if (rhs.type() != NodeType::ConstReal) return false;
1262  auto rhsc = dynamic_cast<const ConstReal&>(rhs);
1263  if (this->value != rhsc.value) return false;
1264  return true;
1265 }
1266 
1271  ::tree::cbor::MapWriter &map,
1272  const ::tree::base::PointerMap &ids
1273 ) const {
1274  (void)ids;
1275  map.append_string("@t", "ConstReal");
1276  auto submap = map.append_map("value");
1277  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Real>(value, submap);
1278  submap.close();
1279  serialize_annotations(map);
1280 }
1281 
1285 std::shared_ptr<ConstReal> ConstReal::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1286  (void)ids;
1287  auto type = map.at("@t").as_string();
1288  if (type != "ConstReal") {
1289  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1290  }
1291  auto node = std::make_shared<ConstReal>(
1292  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Real>(map.at("value").as_map())
1293  );
1294  node->deserialize_annotations(map);
1295  return node;
1296 }
1297 
1302  : Constant(), value(value)
1303 {}
1304 
1308 void ConstRealMatrix::find_reachable(::tree::base::PointerMap &map) const {
1309  (void)map;
1310 }
1311 
1315 void ConstRealMatrix::check_complete(const ::tree::base::PointerMap &map) const {
1316  (void)map;
1317 }
1318 
1324 }
1325 
1329 void ConstRealMatrix::visit_internal(VisitorBase &visitor, void *retval) {
1330  visitor.raw_visit_const_real_matrix(*this, retval);
1331 }
1332 
1338  return dynamic_cast<ConstRealMatrix*>(this);
1339 }
1340 
1346  return dynamic_cast<const ConstRealMatrix*>(this);
1347 }
1348 
1353  return cqasm::tree::make<ConstRealMatrix>(*this);
1354 }
1355 
1360  auto node = cqasm::tree::make<ConstRealMatrix>(*this);
1361  return node;
1362 }
1363 
1367 bool ConstRealMatrix::equals(const Node &rhs) const {
1368  if (rhs.type() != NodeType::ConstRealMatrix) return false;
1369  auto rhsc = dynamic_cast<const ConstRealMatrix&>(rhs);
1370  if (this->value != rhsc.value) return false;
1371  return true;
1372 }
1373 
1377 bool ConstRealMatrix::operator==(const Node &rhs) const {
1378  if (rhs.type() != NodeType::ConstRealMatrix) return false;
1379  auto rhsc = dynamic_cast<const ConstRealMatrix&>(rhs);
1380  if (this->value != rhsc.value) return false;
1381  return true;
1382 }
1383 
1388  ::tree::cbor::MapWriter &map,
1389  const ::tree::base::PointerMap &ids
1390 ) const {
1391  (void)ids;
1392  map.append_string("@t", "ConstRealMatrix");
1393  auto submap = map.append_map("value");
1394  cqasm::v1::primitives::serialize<cqasm::v1::primitives::RMatrix>(value, submap);
1395  submap.close();
1396  serialize_annotations(map);
1397 }
1398 
1402 std::shared_ptr<ConstRealMatrix> ConstRealMatrix::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1403  (void)ids;
1404  auto type = map.at("@t").as_string();
1405  if (type != "ConstRealMatrix") {
1406  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1407  }
1408  auto node = std::make_shared<ConstRealMatrix>(
1409  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::RMatrix>(map.at("value").as_map())
1410  );
1411  node->deserialize_annotations(map);
1412  return node;
1413 }
1414 
1419  : Constant(), value(value)
1420 {}
1421 
1425 void ConstString::find_reachable(::tree::base::PointerMap &map) const {
1426  (void)map;
1427 }
1428 
1432 void ConstString::check_complete(const ::tree::base::PointerMap &map) const {
1433  (void)map;
1434 }
1435 
1440  return NodeType::ConstString;
1441 }
1442 
1446 void ConstString::visit_internal(VisitorBase &visitor, void *retval) {
1447  visitor.raw_visit_const_string(*this, retval);
1448 }
1449 
1455  return dynamic_cast<ConstString*>(this);
1456 }
1457 
1463  return dynamic_cast<const ConstString*>(this);
1464 }
1465 
1470  return cqasm::tree::make<ConstString>(*this);
1471 }
1472 
1477  auto node = cqasm::tree::make<ConstString>(*this);
1478  return node;
1479 }
1480 
1484 bool ConstString::equals(const Node &rhs) const {
1485  if (rhs.type() != NodeType::ConstString) return false;
1486  auto rhsc = dynamic_cast<const ConstString&>(rhs);
1487  if (this->value != rhsc.value) return false;
1488  return true;
1489 }
1490 
1494 bool ConstString::operator==(const Node &rhs) const {
1495  if (rhs.type() != NodeType::ConstString) return false;
1496  auto rhsc = dynamic_cast<const ConstString&>(rhs);
1497  if (this->value != rhsc.value) return false;
1498  return true;
1499 }
1500 
1505  ::tree::cbor::MapWriter &map,
1506  const ::tree::base::PointerMap &ids
1507 ) const {
1508  (void)ids;
1509  map.append_string("@t", "ConstString");
1510  auto submap = map.append_map("value");
1511  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(value, submap);
1512  submap.close();
1513  serialize_annotations(map);
1514 }
1515 
1519 std::shared_ptr<ConstString> ConstString::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1520  (void)ids;
1521  auto type = map.at("@t").as_string();
1522  if (type != "ConstString") {
1523  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1524  }
1525  auto node = std::make_shared<ConstString>(
1526  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at("value").as_map())
1527  );
1528  node->deserialize_annotations(map);
1529  return node;
1530 }
1531 
1536  : name(name), operands(operands), return_type(return_type)
1537 {}
1538 
1542 void Function::find_reachable(::tree::base::PointerMap &map) const {
1543  (void)map;
1544  operands.find_reachable(map);
1545  return_type.find_reachable(map);
1546 }
1547 
1551 void Function::check_complete(const ::tree::base::PointerMap &map) const {
1552  (void)map;
1553  operands.check_complete(map);
1554  return_type.check_complete(map);
1555 }
1556 
1561  return NodeType::Function;
1562 }
1563 
1567 void Function::visit_internal(VisitorBase &visitor, void *retval) {
1568  visitor.raw_visit_function(*this, retval);
1569 }
1570 
1576  return dynamic_cast<Function*>(this);
1577 }
1578 
1584  return dynamic_cast<const Function*>(this);
1585 }
1586 
1591  return cqasm::tree::make<Function>(*this);
1592 }
1593 
1598  auto node = cqasm::tree::make<Function>(*this);
1599  node->operands = this->operands.clone();
1600  node->return_type = this->return_type.clone();
1601  return node;
1602 }
1603 
1607 bool Function::equals(const Node &rhs) const {
1608  if (rhs.type() != NodeType::Function) return false;
1609  auto rhsc = dynamic_cast<const Function&>(rhs);
1610  if (this->name != rhsc.name) return false;
1611  if (!this->operands.equals(rhsc.operands)) return false;
1612  if (!this->return_type.equals(rhsc.return_type)) return false;
1613  return true;
1614 }
1615 
1619 bool Function::operator==(const Node &rhs) const {
1620  if (rhs.type() != NodeType::Function) return false;
1621  auto rhsc = dynamic_cast<const Function&>(rhs);
1622  if (this->name != rhsc.name) return false;
1623  if (this->operands != rhsc.operands) return false;
1624  if (this->return_type != rhsc.return_type) return false;
1625  return true;
1626 }
1627 
1632  ::tree::cbor::MapWriter &map,
1633  const ::tree::base::PointerMap &ids
1634 ) const {
1635  (void)ids;
1636  map.append_string("@t", "Function");
1637  auto submap = map.append_map("name");
1638  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(name, submap);
1639  submap.close();
1640  submap = map.append_map("operands");
1641  operands.serialize(submap, ids);
1642  submap.close();
1643  submap = map.append_map("return_type");
1644  return_type.serialize(submap, ids);
1645  submap.close();
1646  serialize_annotations(map);
1647 }
1648 
1652 std::shared_ptr<Function> Function::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1653  (void)ids;
1654  auto type = map.at("@t").as_string();
1655  if (type != "Function") {
1656  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1657  }
1658  auto node = std::make_shared<Function>(
1659  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at("name").as_map()),
1660  Any<cqasm::v1::values::Node>(map.at("operands").as_map(), ids),
1661  One<cqasm::v1::types::Node>(map.at("return_type").as_map(), ids)
1662  );
1663  node->deserialize_annotations(map);
1664  return node;
1665 }
1666 
1671  : Reference(), index(index)
1672 {}
1673 
1677 void QubitRefs::find_reachable(::tree::base::PointerMap &map) const {
1678  (void)map;
1679  index.find_reachable(map);
1680 }
1681 
1685 void QubitRefs::check_complete(const ::tree::base::PointerMap &map) const {
1686  (void)map;
1687  index.check_complete(map);
1688 }
1689 
1694  return NodeType::QubitRefs;
1695 }
1696 
1700 void QubitRefs::visit_internal(VisitorBase &visitor, void *retval) {
1701  visitor.raw_visit_qubit_refs(*this, retval);
1702 }
1703 
1709  return dynamic_cast<QubitRefs*>(this);
1710 }
1711 
1717  return dynamic_cast<const QubitRefs*>(this);
1718 }
1719 
1724  return cqasm::tree::make<QubitRefs>(*this);
1725 }
1726 
1731  auto node = cqasm::tree::make<QubitRefs>(*this);
1732  node->index = this->index.clone();
1733  return node;
1734 }
1735 
1739 bool QubitRefs::equals(const Node &rhs) const {
1740  if (rhs.type() != NodeType::QubitRefs) return false;
1741  auto rhsc = dynamic_cast<const QubitRefs&>(rhs);
1742  if (!this->index.equals(rhsc.index)) return false;
1743  return true;
1744 }
1745 
1749 bool QubitRefs::operator==(const Node &rhs) const {
1750  if (rhs.type() != NodeType::QubitRefs) return false;
1751  auto rhsc = dynamic_cast<const QubitRefs&>(rhs);
1752  if (this->index != rhsc.index) return false;
1753  return true;
1754 }
1755 
1760  ::tree::cbor::MapWriter &map,
1761  const ::tree::base::PointerMap &ids
1762 ) const {
1763  (void)ids;
1764  map.append_string("@t", "QubitRefs");
1765  auto submap = map.append_map("index");
1766  index.serialize(submap, ids);
1767  submap.close();
1768  serialize_annotations(map);
1769 }
1770 
1774 std::shared_ptr<QubitRefs> QubitRefs::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1775  (void)ids;
1776  auto type = map.at("@t").as_string();
1777  if (type != "QubitRefs") {
1778  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1779  }
1780  auto node = std::make_shared<QubitRefs>(
1781  Many<ConstInt>(map.at("index").as_map(), ids)
1782  );
1783  node->deserialize_annotations(map);
1784  return node;
1785 }
1786 
1791  : Reference(), variable(variable)
1792 {}
1793 
1797 void VariableRef::find_reachable(::tree::base::PointerMap &map) const {
1798  (void)map;
1799  variable.find_reachable(map);
1800 }
1801 
1805 void VariableRef::check_complete(const ::tree::base::PointerMap &map) const {
1806  (void)map;
1807  variable.check_complete(map);
1808 }
1809 
1814  return NodeType::VariableRef;
1815 }
1816 
1820 void VariableRef::visit_internal(VisitorBase &visitor, void *retval) {
1821  visitor.raw_visit_variable_ref(*this, retval);
1822 }
1823 
1829  return dynamic_cast<VariableRef*>(this);
1830 }
1831 
1837  return dynamic_cast<const VariableRef*>(this);
1838 }
1839 
1844  return cqasm::tree::make<VariableRef>(*this);
1845 }
1846 
1851  auto node = cqasm::tree::make<VariableRef>(*this);
1852  return node;
1853 }
1854 
1858 bool VariableRef::equals(const Node &rhs) const {
1859  if (rhs.type() != NodeType::VariableRef) return false;
1860  auto rhsc = dynamic_cast<const VariableRef&>(rhs);
1861  if (!this->variable.equals(rhsc.variable)) return false;
1862  return true;
1863 }
1864 
1868 bool VariableRef::operator==(const Node &rhs) const {
1869  if (rhs.type() != NodeType::VariableRef) return false;
1870  auto rhsc = dynamic_cast<const VariableRef&>(rhs);
1871  if (this->variable != rhsc.variable) return false;
1872  return true;
1873 }
1874 
1879  ::tree::cbor::MapWriter &map,
1880  const ::tree::base::PointerMap &ids
1881 ) const {
1882  (void)ids;
1883  map.append_string("@t", "VariableRef");
1884  auto submap = map.append_map("variable");
1885  variable.serialize(submap, ids);
1886  submap.close();
1887  serialize_annotations(map);
1888 }
1889 
1893 std::shared_ptr<VariableRef> VariableRef::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1894  (void)ids;
1895  auto type = map.at("@t").as_string();
1896  if (type != "VariableRef") {
1897  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1898  }
1899  auto node = std::make_shared<VariableRef>(
1900  Link<cqasm::v1::semantic::Variable>(map.at("variable").as_map(), ids)
1901  );
1902  auto link = map.at("variable").as_map().at("@l");
1903  if (!link.is_null()) {
1904  ids.register_link(node->variable, link.as_int());
1905  }
1906  node->deserialize_annotations(map);
1907  return node;
1908 }
1909 
1913 template <>
1914 void Visitor<void>::raw_visit_node(Node &node, void *retval) {
1915  (void)retval;
1916  this->visit_node(node);
1917 }
1918 
1922 template <>
1923 void Visitor<void>::raw_visit_bit_refs(BitRefs &node, void *retval) {
1924  (void)retval;
1925  this->visit_bit_refs(node);
1926 }
1927 
1931 template <>
1933  (void)retval;
1934  this->visit_const_axis(node);
1935 }
1936 
1940 template <>
1942  (void)retval;
1943  this->visit_const_bool(node);
1944 }
1945 
1949 template <>
1951  (void)retval;
1952  this->visit_const_complex(node);
1953 }
1954 
1958 template <>
1960  (void)retval;
1961  this->visit_const_complex_matrix(node);
1962 }
1963 
1967 template <>
1969  (void)retval;
1970  this->visit_const_int(node);
1971 }
1972 
1976 template <>
1978  (void)retval;
1979  this->visit_const_json(node);
1980 }
1981 
1985 template <>
1987  (void)retval;
1988  this->visit_const_real(node);
1989 }
1990 
1994 template <>
1996  (void)retval;
1997  this->visit_const_real_matrix(node);
1998 }
1999 
2003 template <>
2005  (void)retval;
2006  this->visit_const_string(node);
2007 }
2008 
2012 template <>
2013 void Visitor<void>::raw_visit_constant(Constant &node, void *retval) {
2014  (void)retval;
2015  this->visit_constant(node);
2016 }
2017 
2021 template <>
2022 void Visitor<void>::raw_visit_function(Function &node, void *retval) {
2023  (void)retval;
2024  this->visit_function(node);
2025 }
2026 
2030 template <>
2032  (void)retval;
2033  this->visit_qubit_refs(node);
2034 }
2035 
2039 template <>
2041  (void)retval;
2042  this->visit_reference(node);
2043 }
2044 
2048 template <>
2050  (void)retval;
2051  this->visit_variable_ref(node);
2052 }
2053 
2058  visit_reference(node);
2059  node.index.visit(*this);
2060 }
2061 
2066  visit_constant(node);
2067 }
2068 
2073  visit_constant(node);
2074 }
2075 
2080  visit_constant(node);
2081 }
2082 
2087  visit_constant(node);
2088 }
2089 
2094  visit_constant(node);
2095 }
2096 
2101  visit_constant(node);
2102 }
2103 
2108  visit_constant(node);
2109 }
2110 
2115  visit_constant(node);
2116 }
2117 
2122  visit_constant(node);
2123 }
2124 
2129  visit_node(node);
2130 }
2131 
2136  visit_node(node);
2137 }
2138 
2143  visit_reference(node);
2144  node.index.visit(*this);
2145 }
2146 
2151  visit_node(node);
2152 }
2153 
2158  visit_reference(node);
2159 }
2160 
2165  for (int i = 0; i < indent; i++) {
2166  out << " ";
2167  }
2168 }
2169 
2174  (void)node;
2175  write_indent();
2176  out << "!Node()" << std::endl;
2177 }
2178 
2183  write_indent();
2184  out << "BitRefs";
2185  if (ids != nullptr) {
2186  out << "@" << ids->get_ref(node);
2187  }
2188  out << "(";
2189  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2190  out << " # " << *loc;
2191  }
2192  out << std::endl;
2193  indent++;
2194  write_indent();
2195  out << "index: ";
2196  if (node.index.empty()) {
2197  out << "!MISSING" << std::endl;
2198  } else {
2199  out << "[" << std::endl;
2200  indent++;
2201  for (auto &sptr : node.index) {
2202  if (!sptr.empty()) {
2203  sptr->visit(*this);
2204  } else {
2205  write_indent();
2206  out << "!NULL" << std::endl;
2207  }
2208  }
2209  indent--;
2210  write_indent();
2211  out << "]" << std::endl;
2212  }
2213  indent--;
2214  write_indent();
2215  out << ")" << std::endl;
2216 }
2217 
2222  write_indent();
2223  out << "ConstAxis";
2224  if (ids != nullptr) {
2225  out << "@" << ids->get_ref(node);
2226  }
2227  out << "(";
2228  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2229  out << " # " << *loc;
2230  }
2231  out << std::endl;
2232  indent++;
2233  write_indent();
2234  out << "value: ";
2235  std::stringstream ss;
2236  size_t pos;
2237  ss << node.value;
2238  pos = ss.str().find_last_not_of(" \n\r\t");
2239  if (pos != std::string::npos) {
2240  ss.str(ss.str().erase(pos+1));
2241  }
2242  if (ss.str().find('\n') == std::string::npos) {
2243  out << ss.str() << std::endl;
2244  } else {
2245  out << "cqasm::v1::primitives::Axis<<" << std::endl;
2246  indent++;
2247  std::string s;
2248  while (!ss.eof()) {
2249  std::getline(ss, s);
2250  write_indent();
2251  out << s << std::endl;
2252  }
2253  indent--;
2254  write_indent();
2255  out << ">>" << std::endl;
2256  }
2257  indent--;
2258  write_indent();
2259  out << ")" << std::endl;
2260 }
2261 
2266  write_indent();
2267  out << "ConstBool";
2268  if (ids != nullptr) {
2269  out << "@" << ids->get_ref(node);
2270  }
2271  out << "(";
2272  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2273  out << " # " << *loc;
2274  }
2275  out << std::endl;
2276  indent++;
2277  write_indent();
2278  out << "value: ";
2279  std::stringstream ss;
2280  size_t pos;
2281  ss << node.value;
2282  pos = ss.str().find_last_not_of(" \n\r\t");
2283  if (pos != std::string::npos) {
2284  ss.str(ss.str().erase(pos+1));
2285  }
2286  if (ss.str().find('\n') == std::string::npos) {
2287  out << ss.str() << std::endl;
2288  } else {
2289  out << "cqasm::v1::primitives::Bool<<" << std::endl;
2290  indent++;
2291  std::string s;
2292  while (!ss.eof()) {
2293  std::getline(ss, s);
2294  write_indent();
2295  out << s << std::endl;
2296  }
2297  indent--;
2298  write_indent();
2299  out << ">>" << std::endl;
2300  }
2301  indent--;
2302  write_indent();
2303  out << ")" << std::endl;
2304 }
2305 
2310  write_indent();
2311  out << "ConstComplex";
2312  if (ids != nullptr) {
2313  out << "@" << ids->get_ref(node);
2314  }
2315  out << "(";
2316  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2317  out << " # " << *loc;
2318  }
2319  out << std::endl;
2320  indent++;
2321  write_indent();
2322  out << "value: ";
2323  std::stringstream ss;
2324  size_t pos;
2325  ss << node.value;
2326  pos = ss.str().find_last_not_of(" \n\r\t");
2327  if (pos != std::string::npos) {
2328  ss.str(ss.str().erase(pos+1));
2329  }
2330  if (ss.str().find('\n') == std::string::npos) {
2331  out << ss.str() << std::endl;
2332  } else {
2333  out << "cqasm::v1::primitives::Complex<<" << std::endl;
2334  indent++;
2335  std::string s;
2336  while (!ss.eof()) {
2337  std::getline(ss, s);
2338  write_indent();
2339  out << s << std::endl;
2340  }
2341  indent--;
2342  write_indent();
2343  out << ">>" << std::endl;
2344  }
2345  indent--;
2346  write_indent();
2347  out << ")" << std::endl;
2348 }
2349 
2354  write_indent();
2355  out << "ConstComplexMatrix";
2356  if (ids != nullptr) {
2357  out << "@" << ids->get_ref(node);
2358  }
2359  out << "(";
2360  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2361  out << " # " << *loc;
2362  }
2363  out << std::endl;
2364  indent++;
2365  write_indent();
2366  out << "value: ";
2367  std::stringstream ss;
2368  size_t pos;
2369  ss << node.value;
2370  pos = ss.str().find_last_not_of(" \n\r\t");
2371  if (pos != std::string::npos) {
2372  ss.str(ss.str().erase(pos+1));
2373  }
2374  if (ss.str().find('\n') == std::string::npos) {
2375  out << ss.str() << std::endl;
2376  } else {
2377  out << "cqasm::v1::primitives::CMatrix<<" << std::endl;
2378  indent++;
2379  std::string s;
2380  while (!ss.eof()) {
2381  std::getline(ss, s);
2382  write_indent();
2383  out << s << std::endl;
2384  }
2385  indent--;
2386  write_indent();
2387  out << ">>" << std::endl;
2388  }
2389  indent--;
2390  write_indent();
2391  out << ")" << std::endl;
2392 }
2393 
2398  write_indent();
2399  out << "ConstInt";
2400  if (ids != nullptr) {
2401  out << "@" << ids->get_ref(node);
2402  }
2403  out << "(";
2404  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2405  out << " # " << *loc;
2406  }
2407  out << std::endl;
2408  indent++;
2409  write_indent();
2410  out << "value: ";
2411  std::stringstream ss;
2412  size_t pos;
2413  ss << node.value;
2414  pos = ss.str().find_last_not_of(" \n\r\t");
2415  if (pos != std::string::npos) {
2416  ss.str(ss.str().erase(pos+1));
2417  }
2418  if (ss.str().find('\n') == std::string::npos) {
2419  out << ss.str() << std::endl;
2420  } else {
2421  out << "cqasm::v1::primitives::Int<<" << std::endl;
2422  indent++;
2423  std::string s;
2424  while (!ss.eof()) {
2425  std::getline(ss, s);
2426  write_indent();
2427  out << s << std::endl;
2428  }
2429  indent--;
2430  write_indent();
2431  out << ">>" << std::endl;
2432  }
2433  indent--;
2434  write_indent();
2435  out << ")" << std::endl;
2436 }
2437 
2442  write_indent();
2443  out << "ConstJson";
2444  if (ids != nullptr) {
2445  out << "@" << ids->get_ref(node);
2446  }
2447  out << "(";
2448  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2449  out << " # " << *loc;
2450  }
2451  out << std::endl;
2452  indent++;
2453  write_indent();
2454  out << "value: ";
2455  std::stringstream ss;
2456  size_t pos;
2457  ss << node.value;
2458  pos = ss.str().find_last_not_of(" \n\r\t");
2459  if (pos != std::string::npos) {
2460  ss.str(ss.str().erase(pos+1));
2461  }
2462  if (ss.str().find('\n') == std::string::npos) {
2463  out << ss.str() << std::endl;
2464  } else {
2465  out << "cqasm::v1::primitives::Str<<" << std::endl;
2466  indent++;
2467  std::string s;
2468  while (!ss.eof()) {
2469  std::getline(ss, s);
2470  write_indent();
2471  out << s << std::endl;
2472  }
2473  indent--;
2474  write_indent();
2475  out << ">>" << std::endl;
2476  }
2477  indent--;
2478  write_indent();
2479  out << ")" << std::endl;
2480 }
2481 
2486  write_indent();
2487  out << "ConstReal";
2488  if (ids != nullptr) {
2489  out << "@" << ids->get_ref(node);
2490  }
2491  out << "(";
2492  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2493  out << " # " << *loc;
2494  }
2495  out << std::endl;
2496  indent++;
2497  write_indent();
2498  out << "value: ";
2499  std::stringstream ss;
2500  size_t pos;
2501  ss << node.value;
2502  pos = ss.str().find_last_not_of(" \n\r\t");
2503  if (pos != std::string::npos) {
2504  ss.str(ss.str().erase(pos+1));
2505  }
2506  if (ss.str().find('\n') == std::string::npos) {
2507  out << ss.str() << std::endl;
2508  } else {
2509  out << "cqasm::v1::primitives::Real<<" << std::endl;
2510  indent++;
2511  std::string s;
2512  while (!ss.eof()) {
2513  std::getline(ss, s);
2514  write_indent();
2515  out << s << std::endl;
2516  }
2517  indent--;
2518  write_indent();
2519  out << ">>" << std::endl;
2520  }
2521  indent--;
2522  write_indent();
2523  out << ")" << std::endl;
2524 }
2525 
2530  write_indent();
2531  out << "ConstRealMatrix";
2532  if (ids != nullptr) {
2533  out << "@" << ids->get_ref(node);
2534  }
2535  out << "(";
2536  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2537  out << " # " << *loc;
2538  }
2539  out << std::endl;
2540  indent++;
2541  write_indent();
2542  out << "value: ";
2543  std::stringstream ss;
2544  size_t pos;
2545  ss << node.value;
2546  pos = ss.str().find_last_not_of(" \n\r\t");
2547  if (pos != std::string::npos) {
2548  ss.str(ss.str().erase(pos+1));
2549  }
2550  if (ss.str().find('\n') == std::string::npos) {
2551  out << ss.str() << std::endl;
2552  } else {
2553  out << "cqasm::v1::primitives::RMatrix<<" << std::endl;
2554  indent++;
2555  std::string s;
2556  while (!ss.eof()) {
2557  std::getline(ss, s);
2558  write_indent();
2559  out << s << std::endl;
2560  }
2561  indent--;
2562  write_indent();
2563  out << ">>" << std::endl;
2564  }
2565  indent--;
2566  write_indent();
2567  out << ")" << std::endl;
2568 }
2569 
2574  write_indent();
2575  out << "ConstString";
2576  if (ids != nullptr) {
2577  out << "@" << ids->get_ref(node);
2578  }
2579  out << "(";
2580  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2581  out << " # " << *loc;
2582  }
2583  out << std::endl;
2584  indent++;
2585  write_indent();
2586  out << "value: ";
2587  std::stringstream ss;
2588  size_t pos;
2589  ss << node.value;
2590  pos = ss.str().find_last_not_of(" \n\r\t");
2591  if (pos != std::string::npos) {
2592  ss.str(ss.str().erase(pos+1));
2593  }
2594  if (ss.str().find('\n') == std::string::npos) {
2595  out << ss.str() << std::endl;
2596  } else {
2597  out << "cqasm::v1::primitives::Str<<" << std::endl;
2598  indent++;
2599  std::string s;
2600  while (!ss.eof()) {
2601  std::getline(ss, s);
2602  write_indent();
2603  out << s << std::endl;
2604  }
2605  indent--;
2606  write_indent();
2607  out << ">>" << std::endl;
2608  }
2609  indent--;
2610  write_indent();
2611  out << ")" << std::endl;
2612 }
2613 
2618  write_indent();
2619  out << "Constant";
2620  if (ids != nullptr) {
2621  out << "@" << ids->get_ref(node);
2622  }
2623  out << "(";
2624  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2625  out << " # " << *loc;
2626  }
2627  out << std::endl;
2628  out << ")" << std::endl;
2629 }
2630 
2635  write_indent();
2636  out << "Function";
2637  if (ids != nullptr) {
2638  out << "@" << ids->get_ref(node);
2639  }
2640  out << "(";
2641  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2642  out << " # " << *loc;
2643  }
2644  out << std::endl;
2645  indent++;
2646  write_indent();
2647  out << "name: ";
2648  std::stringstream ss;
2649  size_t pos;
2650  ss << node.name;
2651  pos = ss.str().find_last_not_of(" \n\r\t");
2652  if (pos != std::string::npos) {
2653  ss.str(ss.str().erase(pos+1));
2654  }
2655  if (ss.str().find('\n') == std::string::npos) {
2656  out << ss.str() << std::endl;
2657  } else {
2658  out << "cqasm::v1::primitives::Str<<" << std::endl;
2659  indent++;
2660  std::string s;
2661  while (!ss.eof()) {
2662  std::getline(ss, s);
2663  write_indent();
2664  out << s << std::endl;
2665  }
2666  indent--;
2667  write_indent();
2668  out << ">>" << std::endl;
2669  }
2670  write_indent();
2671  out << "operands: ";
2672  if (node.operands.empty()) {
2673  out << "[]" << std::endl;
2674  } else {
2675  out << "[" << std::endl;
2676  indent++;
2677  for (auto &sptr : node.operands) {
2678  if (!sptr.empty()) {
2679  sptr->dump(out, indent);
2680  } else {
2681  write_indent();
2682  out << "!NULL" << std::endl;
2683  }
2684  }
2685  indent--;
2686  write_indent();
2687  out << "]" << std::endl;
2688  }
2689  write_indent();
2690  out << "return_type: ";
2691  if (node.return_type.empty()) {
2692  out << "!MISSING" << std::endl;
2693  } else {
2694  out << "<" << std::endl;
2695  indent++;
2696  if (!node.return_type.empty()) {
2697  node.return_type->dump(out, indent);
2698  }
2699  indent--;
2700  write_indent();
2701  out << ">" << std::endl;
2702  }
2703  indent--;
2704  write_indent();
2705  out << ")" << std::endl;
2706 }
2707 
2712  write_indent();
2713  out << "QubitRefs";
2714  if (ids != nullptr) {
2715  out << "@" << ids->get_ref(node);
2716  }
2717  out << "(";
2718  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2719  out << " # " << *loc;
2720  }
2721  out << std::endl;
2722  indent++;
2723  write_indent();
2724  out << "index: ";
2725  if (node.index.empty()) {
2726  out << "!MISSING" << std::endl;
2727  } else {
2728  out << "[" << std::endl;
2729  indent++;
2730  for (auto &sptr : node.index) {
2731  if (!sptr.empty()) {
2732  sptr->visit(*this);
2733  } else {
2734  write_indent();
2735  out << "!NULL" << std::endl;
2736  }
2737  }
2738  indent--;
2739  write_indent();
2740  out << "]" << std::endl;
2741  }
2742  indent--;
2743  write_indent();
2744  out << ")" << std::endl;
2745 }
2746 
2751  write_indent();
2752  out << "Reference";
2753  if (ids != nullptr) {
2754  out << "@" << ids->get_ref(node);
2755  }
2756  out << "(";
2757  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2758  out << " # " << *loc;
2759  }
2760  out << std::endl;
2761  out << ")" << std::endl;
2762 }
2763 
2768  write_indent();
2769  out << "VariableRef";
2770  if (ids != nullptr) {
2771  out << "@" << ids->get_ref(node);
2772  }
2773  out << "(";
2774  if (auto loc = node.get_annotation_ptr<cqasm::annotations::SourceLocation>()) {
2775  out << " # " << *loc;
2776  }
2777  out << std::endl;
2778  indent++;
2779  write_indent();
2780  out << "variable --> ";
2781  if (node.variable.empty()) {
2782  out << "!MISSING" << std::endl;
2783  } else if (ids != nullptr && ids->get(node.variable) != (size_t)-1) {
2784  out << "Link<cqasm::v1::semantic::Variable>@" << ids->get(node.variable) << std::endl;
2785  } else {
2786  out << "<" << std::endl;
2787  indent++;
2788  if (!in_link) {
2789  in_link = true;
2790  if (!node.variable.empty()) {
2791  node.variable->dump(out, indent);
2792  }
2793  in_link = false;
2794  } else {
2795  write_indent();
2796  out << "..." << std::endl;
2797  }
2798  indent--;
2799  write_indent();
2800  out << ">" << std::endl;
2801  }
2802  indent--;
2803  write_indent();
2804  out << ")" << std::endl;
2805 }
2806 
2810 template <>
2811 void Node::visit(Visitor<void> &visitor) {
2812  this->visit_internal(visitor);
2813 }
2814 
2818 std::ostream &operator<<(std::ostream &os, const Node &object) {
2819  const_cast<Node&>(object).dump(os);
2820  return os;
2821 }
2822 
2823 } // namespace values
2824 } // namespace v1
2825 } // namespace cqasm
2826 
ConstString * as_const_string() override
Interprets this node to a node of type ConstString.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
Two-dimensional matrix of some kind of type.
cqasm::v1::primitives::RMatrix value
The contained value.
void write_indent()
Writes the current indentation level&#39;s worth of spaces.
void visit_const_complex_matrix(ConstComplexMatrix &node) override
Dumps a ConstComplexMatrix node.
Represents a reference to some storage location.
void visit_const_real(ConstReal &node) override
Recursive traversal for ConstReal nodes.
BitRefs(const Many< ConstInt > &index=Many< ConstInt >())
Constructor.
ConstBool * as_const_bool() override
Interprets this node to a node of type ConstBool.
std::complex< double > Complex
Complex number primitive used within the semantic trees.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
Internal class for implementing the visitor pattern.
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 raw_visit_function(Function &node, void *retval) override
Internal visitor function for Function nodes.
void raw_visit_const_real_matrix(ConstRealMatrix &node, void *retval) override
Internal visitor function for ConstRealMatrix nodes.
NodeType type() const override
Returns the NodeType of this node.
void visit_const_bool(ConstBool &node) override
Dumps a ConstBool node.
void raw_visit_const_bool(ConstBool &node, void *retval) override
Internal visitor function for ConstBool nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
static std::shared_ptr< ConstRealMatrix > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
ConstComplex(const cqasm::v1::primitives::Complex &value=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Complex >())
Constructor.
ConstString(const cqasm::v1::primitives::Str &value=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >())
Constructor.
void visit_const_json(ConstJson &node) override
Recursive traversal for ConstJson nodes.
ConstInt * as_const_int() override
Interprets this node to a node of type ConstInt.
NodeType type() const override
Returns the NodeType of this node.
This can be returned by user-defined functions as a placeholder value for something that needs to be ...
ConstInt(const cqasm::v1::primitives::Int &value=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >())
Constructor.
NodeType type() const override
Returns the NodeType of this node.
ConstAxis * as_const_axis() override
Interprets this node to a node of type ConstAxis.
void visit_constant(Constant &node) override
Dumps a Constant node.
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.
virtual Constant * as_constant()
Interprets this node to a node of type Constant.
ConstReal * as_const_real() override
Interprets this node to a node of type ConstReal.
bool equals(const Node &rhs) const override
Value-based equality operator.
std::ostream & operator<<(std::ostream &os, const Value &value)
Stream << overload for a single value.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
static std::shared_ptr< ConstJson > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
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.
void visit_const_bool(ConstBool &node) override
Recursive traversal for ConstBool nodes.
void visit_const_complex(ConstComplex &node) override
Dumps a ConstComplex node.
Represents a qubit, or a set of qubits for single-gate-multiple-qubit notation.
bool equals(const Node &rhs) const override
Value-based equality operator.
void raw_visit_const_real(ConstReal &node, void *retval) override
Internal visitor function for ConstReal nodes.
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.
Constant * as_constant() override
Interprets this node to a node of type Constant.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
ConstBool(const cqasm::v1::primitives::Bool &value=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Bool >())
Constructor.
void raw_visit_node(Node &node, void *retval) override
Internal visitor function for nodes of any type.
void dump_seq(std::ostream &out=std::cout, int indent=0)
Alternate debug dump that represents links and node uniqueness via sequence number tags...
Contains annotation objects used within the trees by libqasm.
void visit_variable_ref(VariableRef &node) override
Recursive traversal for VariableRef nodes.
Represents a variable reference.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
ConstComplexMatrix * as_const_complex_matrix() override
Interprets this node to a node of type ConstComplexMatrix.
virtual ConstComplex * as_const_complex()
Interprets this node to a node of type ConstComplex.
Toplevel namespace with entry points for the new API.
ConstComplexMatrix(const cqasm::v1::primitives::CMatrix &value=cqasm::v1::primitives::initialize< cqasm::v1::primitives::CMatrix >())
Constructor.
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.
static std::shared_ptr< Reference > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual void raw_visit_const_bool(ConstBool &node, void *retval)=0
Internal visitor function for ConstBool nodes.
virtual Function * as_function()
Interprets this node to a node of type Function.
Represents a value of type string.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void raw_visit_const_int(ConstInt &node, void *retval) override
Internal visitor function for ConstInt nodes.
virtual void raw_visit_const_string(ConstString &node, void *retval)=0
Internal visitor function for ConstString nodes.
ConstJson(const cqasm::v1::primitives::Str &value=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >())
Constructor.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
QubitRefs(const Many< ConstInt > &index=Many< ConstInt >())
Constructor.
virtual ConstAxis * as_const_axis()
Interprets this node to a node of type ConstAxis.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
virtual QubitRefs * as_qubit_refs()
Interprets this node to a node of type QubitRefs.
One< Node > clone() const override
Returns a deep copy of this node.
Source location annotation object, containing source file line numbers etc.
static std::shared_ptr< BitRefs > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual void raw_visit_const_axis(ConstAxis &node, void *retval)=0
Internal visitor function for ConstAxis nodes.
ConstRealMatrix * as_const_real_matrix() override
Interprets this node to a node of type ConstRealMatrix.
VariableRef(const Link< cqasm::v1::semantic::Variable > &variable=cqasm::v1::primitives::initialize< Link< cqasm::v1::semantic::Variable >>())
Constructor.
double Real
Real number primitive used within the AST and semantic trees.
static std::shared_ptr< ConstReal > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
ConstJson * as_const_json() override
Interprets this node to a node of type ConstJson.
NodeType type() const override
Returns the NodeType of this node.
Main class for all nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
T visit(Visitor< T > &visitor)
Visit this object.
void raw_visit_const_string(ConstString &node, void *retval) override
Internal visitor function for ConstString nodes.
cqasm::v1::primitives::Bool value
The contained value.
void visit_const_complex_matrix(ConstComplexMatrix &node) override
Recursive traversal for ConstComplexMatrix nodes.
static std::shared_ptr< ConstAxis > 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.
bool equals(const Node &rhs) const override
Value-based equality operator.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
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.
cqasm::v1::primitives::Int value
The contained value.
cqasm::v1::primitives::Real value
The contained value.
void dump(std::ostream &out=std::cout, int indent=0)
Writes a debug dump of this node to the given stream.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
std::int64_t Int
Integer primitive used within the AST and semantic trees.
void visit_const_real_matrix(ConstRealMatrix &node) override
Dumps a ConstRealMatrix node.
void raw_visit_const_json(ConstJson &node, void *retval) override
Internal visitor function for ConstJson nodes.
Main class for all nodes.
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.
Defines the types for the cQASM semantic tree, based on the classes from cqasm::tree.
virtual void raw_visit_const_real_matrix(ConstRealMatrix &node, void *retval)=0
Internal visitor function for ConstRealMatrix nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
Link< cqasm::v1::semantic::Variable > variable
The referenced variable.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ConstAxis is complete/fully defined.
Represents a value of type complex.
Many< ConstInt > index
The qubit index that this is a measurement bit for, starting at 0.
void visit_const_complex(ConstComplex &node) override
Recursive traversal for ConstComplex nodes.
Represents a value of type bool.
NodeType type() const override
Returns the NodeType of this node.
Many< ConstInt > index
Set of qubit indices referred to, starting at 0.
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 check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ConstJson is complete/fully defined.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
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_variable_ref(VariableRef &node, void *retval)=0
Internal visitor function for VariableRef nodes.
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.
cqasm::v1::primitives::Complex value
The contained value.
void visit_qubit_refs(QubitRefs &node) override
Recursive traversal for QubitRefs nodes.
static std::shared_ptr< Node > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_variable_ref(VariableRef &node) override
Dumps a VariableRef node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
cqasm::v1::primitives::CMatrix value
The contained value.
virtual void raw_visit_const_complex_matrix(ConstComplexMatrix &node, void *retval)=0
Internal visitor function for ConstComplexMatrix nodes.
Function(const cqasm::v1::primitives::Str &name=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const Any< cqasm::v1::values::Node > &operands=cqasm::v1::primitives::initialize< Any< cqasm::v1::values::Node >>(), const One< cqasm::v1::types::Node > &return_type=cqasm::v1::primitives::initialize< One< cqasm::v1::types::Node >>())
Constructor.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
NodeType type() const override
Returns the NodeType of this node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void raw_visit_const_axis(ConstAxis &node, void *retval) override
Internal visitor function for ConstAxis nodes.
virtual ConstComplexMatrix * as_const_complex_matrix()
Interprets this node to a node of type ConstComplexMatrix.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ConstReal is complete/fully defined.
void raw_visit_const_complex(ConstComplex &node, void *retval) override
Internal visitor function for ConstComplex nodes.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
static std::shared_ptr< Constant > 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.
VariableRef * as_variable_ref() override
Interprets this node to a node of type VariableRef.
bool Bool
Boolean primitive used within the semantic trees.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this BitRefs is complete/fully defined.
Visitor class that debug-dumps a tree to a stream.
virtual void raw_visit_function(Function &node, void *retval)=0
Internal visitor function for Function nodes.
virtual BitRefs * as_bit_refs()
Interprets this node to a node of type BitRefs.
virtual ConstBool * as_const_bool()
Interprets this node to a node of type ConstBool.
cqasm::tree::Any< T > Any
virtual void raw_visit_const_json(ConstJson &node, void *retval)=0
Internal visitor function for ConstJson nodes.
cqasm::tree::Link< T > Link
void visit_function(Function &node) override
Dumps a Function node.
NodeType type() const override
Returns the NodeType of this node.
BitRefs * as_bit_refs() override
Interprets this node to a node of type BitRefs.
void visit_const_int(ConstInt &node) override
Recursive traversal for ConstInt nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void visit_bit_refs(BitRefs &node) override
Recursive traversal for BitRefs nodes.
static std::shared_ptr< ConstInt > 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.
Namespace for the "new" cQASM 1.x API.
void visit_constant(Constant &node) override
Recursive traversal for Constant nodes.
One< Node > clone() const override
Returns a deep copy of this node.
static std::shared_ptr< QubitRefs > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
cqasm::v1::primitives::Str name
Name of the function as it appears or should appear in the cQASM file.
void visit_bit_refs(BitRefs &node) override
Dumps a BitRefs node.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void raw_visit_bit_refs(BitRefs &node, void *retval) override
Internal visitor function for BitRefs nodes.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
ConstComplex * as_const_complex() override
Interprets this node to a node of type ConstComplex.
Represents a value of type json.
Represents an axis value (x, y, or z).
void raw_visit_reference(Reference &node, void *retval) override
Internal visitor function for Reference nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
Represents a value of type real_matrix.
void visit_const_axis(ConstAxis &node) override
Recursive traversal for ConstAxis nodes.
One< Node > clone() const override
Returns a deep copy of this node.
virtual NodeType type() const =0
Returns the NodeType of this node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ConstComplexMatrix is complete/fully defined.
void visit_reference(Reference &node) override
Recursive traversal for Reference nodes.
cqasm::v1::primitives::Str value
The contained value.
virtual void raw_visit_qubit_refs(QubitRefs &node, void *retval)=0
Internal visitor function for QubitRefs nodes.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this QubitRefs is complete/fully defined.
ConstReal(const cqasm::v1::primitives::Real &value=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Real >())
Constructor.
One< Node > copy() const override
Returns a shallow copy of this node.
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 ConstRealMatrix is complete/fully defined.
std::string Str
String primitive used within the AST and semantic trees.
cqasm::v1::primitives::Axis value
The contained value.
One< Node > clone() const override
Returns a deep copy of this node.
static std::shared_ptr< ConstComplexMatrix > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual Reference * as_reference()
Interprets this node to a node of type Reference.
QubitRefs * as_qubit_refs() override
Interprets this node to a node of type QubitRefs.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void visit_qubit_refs(QubitRefs &node) override
Dumps a QubitRefs node.
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.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void visit_const_string(ConstString &node) override
Recursive traversal for ConstString nodes.
void visit_const_int(ConstInt &node) override
Dumps a ConstInt node.
void raw_visit_qubit_refs(QubitRefs &node, void *retval) override
Internal visitor function for QubitRefs nodes.
virtual ConstString * as_const_string()
Interprets this node to a node of type ConstString.
static std::shared_ptr< ConstString > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_const_json(ConstJson &node) override
Dumps a ConstJson node.
One< Node > clone() const override
Returns a deep copy of this node.
void visit_reference(Reference &node) override
Dumps a Reference node.
static std::shared_ptr< Function > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void visit_const_string(ConstString &node) override
Dumps a ConstString node.
One< Node > copy() const override
Returns a shallow copy of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
One< Node > clone() const override
Returns a deep copy of this node.
virtual ConstRealMatrix * as_const_real_matrix()
Interprets this node to a node of type ConstRealMatrix.
virtual void raw_visit_const_int(ConstInt &node, void *retval)=0
Internal visitor function for ConstInt nodes.
Represents a measurement bit, or a number of measurement bits for conditional gates with multiple con...
bool equals(const Node &rhs) const override
Value-based equality operator.
virtual void raw_visit_const_real(ConstReal &node, void *retval)=0
Internal visitor function for ConstReal nodes.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
Represents a constant value.
One< Node > clone() const override
Returns a deep copy of this node.
NodeType type() const override
Returns the NodeType of this node.
Any< cqasm::v1::values::Node > operands
Operands for the function.
One< Node > copy() const override
Returns a shallow copy of this node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ConstInt is complete/fully defined.
bool equals(const Node &rhs) const override
Value-based equality operator.
One< cqasm::v1::types::Node > return_type
Operands for the function.
NodeType type() const override
Returns the NodeType of this node.
NodeType type() const override
Returns the NodeType of this node.
virtual ConstJson * as_const_json()
Interprets this node to a node of type ConstJson.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
cqasm::tree::One< T > One
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Function is complete/fully defined.
static std::shared_ptr< ConstComplex > 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.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ConstBool is complete/fully defined.
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.
virtual void raw_visit_bit_refs(BitRefs &node, void *retval)=0
Internal visitor function for BitRefs nodes.
virtual ConstInt * as_const_int()
Interprets this node to a node of type ConstInt.
void visit_function(Function &node) override
Recursive traversal for Function nodes.
void visit_const_real_matrix(ConstRealMatrix &node) override
Recursive traversal for ConstRealMatrix nodes.
Header file for the various classes representing constants, references, and dynamic expressions in cQ...
Represents a value of type int.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this VariableRef is complete/fully defined.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
Represents a value of type real.
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.
One< Node > copy() const override
Returns a shallow copy of this node.
void visit_const_real(ConstReal &node) override
Dumps a ConstReal node.
Reference * as_reference() override
Interprets this node to a node of type Reference.
static std::shared_ptr< VariableRef > 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.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
cqasm::tree::Many< T > Many
virtual ConstReal * as_const_real()
Interprets this node to a node of type ConstReal.
void visit_const_axis(ConstAxis &node) override
Dumps a ConstAxis node.
ConstRealMatrix(const cqasm::v1::primitives::RMatrix &value=cqasm::v1::primitives::initialize< cqasm::v1::primitives::RMatrix >())
Constructor.
NodeType type() const override
Returns the NodeType of this node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void raw_visit_const_complex_matrix(ConstComplexMatrix &node, void *retval) override
Internal visitor function for ConstComplexMatrix nodes.
Represents a value of type complex_matrix.
Axis
Axis primitive used within the semantic trees.
One< Node > copy() const override
Returns a shallow copy of this node.
cqasm::v1::primitives::Str value
The contained value.
bool equals(const Node &rhs) const override
Value-based equality operator.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ConstComplex is complete/fully defined.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
NodeType
Enumeration of all node types.
Function * as_function() override
Interprets this node to a node of type Function.
One< Node > clone() const override
Returns a deep copy of this node.
static std::shared_ptr< ConstBool > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual VariableRef * as_variable_ref()
Interprets this node to a node of type VariableRef.
virtual void raw_visit_const_complex(ConstComplex &node, void *retval)=0
Internal visitor function for ConstComplex nodes.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ConstString 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 raw_visit_variable_ref(VariableRef &node, void *retval) override
Internal visitor function for VariableRef nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void raw_visit_constant(Constant &node, void *retval) override
Internal visitor function for Constant nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
One< Node > copy() const override
Returns a shallow copy of this node.
void visit_node(Node &node) override
Dumps a Node.
ConstAxis(const cqasm::v1::primitives::Axis &value=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Axis >())
Constructor.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.