libqasm
library for handling cQASM files
cqasm-v1-types-gen.cpp
Go to the documentation of this file.
1 
6 #include "cqasm-v1-semantic.hpp"
7 #include "cqasm-v1-types-gen.hpp"
8 
9 namespace cqasm {
10 namespace v1 {
11 namespace types {
12 
16 void Node::dump(std::ostream &out, int indent) {
17  auto dumper = Dumper(out, indent);
18  visit(dumper);
19 }
20 
25 void Node::dump_seq(std::ostream &out, int indent) {
26  ::tree::base::PointerMap ids;
27  ids.enable_exceptions = false;
28  ids.add_ref(*this);
29  find_reachable(ids);
30  auto dumper = Dumper(out, indent, &ids);
31  visit(dumper);
32 }
33 
39  return nullptr;
40 }
41 
46 const Axis *Node::as_axis() const {
47  return nullptr;
48 }
49 
55  return nullptr;
56 }
57 
62 const Bool *Node::as_bool() const {
63  return nullptr;
64 }
65 
71  return nullptr;
72 }
73 
78 const Complex *Node::as_complex() const {
79  return nullptr;
80 }
81 
87  return nullptr;
88 }
89 
95  return nullptr;
96 }
97 
103  return nullptr;
104 }
105 
110 const Int *Node::as_int() const {
111  return nullptr;
112 }
113 
119  return nullptr;
120 }
121 
126 const Json *Node::as_json() const {
127  return nullptr;
128 }
129 
135  return nullptr;
136 }
137 
142 const Qubit *Node::as_qubit() const {
143  return nullptr;
144 }
145 
151  return nullptr;
152 }
153 
158 const Real *Node::as_real() const {
159  return nullptr;
160 }
161 
167  return nullptr;
168 }
169 
175  return nullptr;
176 }
177 
183  return nullptr;
184 }
185 
190 const String *Node::as_string() const {
191  return nullptr;
192 }
193 
199  return nullptr;
200 }
201 
206 const TypeBase *Node::as_type_base() const {
207  return nullptr;
208 }
209 
213 std::shared_ptr<Node> Node::deserialize(
214  const ::tree::cbor::MapReader &map,
215  ::tree::base::IdentifierMap &ids
216 ) {
217  auto type = map.at("@t").as_string();
218  if (type == "Axis") return Axis::deserialize(map, ids);
219  if (type == "Bool") return Bool::deserialize(map, ids);
220  if (type == "Complex") return Complex::deserialize(map, ids);
221  if (type == "ComplexMatrix") return ComplexMatrix::deserialize(map, ids);
222  if (type == "Int") return Int::deserialize(map, ids);
223  if (type == "Json") return Json::deserialize(map, ids);
224  if (type == "Qubit") return Qubit::deserialize(map, ids);
225  if (type == "Real") return Real::deserialize(map, ids);
226  if (type == "RealMatrix") return RealMatrix::deserialize(map, ids);
227  if (type == "String") return String::deserialize(map, ids);
228  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
229 }
230 
235  : assignable(assignable)
236 {}
237 
243  return dynamic_cast<TypeBase*>(this);
244 }
245 
251  return dynamic_cast<const TypeBase*>(this);
252 }
253 
257 std::shared_ptr<TypeBase> TypeBase::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
258  auto type = map.at("@t").as_string();
259  if (type == "Qubit") return Qubit::deserialize(map, ids);
260  if (type == "Bool") return Bool::deserialize(map, ids);
261  if (type == "Axis") return Axis::deserialize(map, ids);
262  if (type == "Int") return Int::deserialize(map, ids);
263  if (type == "Real") return Real::deserialize(map, ids);
264  if (type == "Complex") return Complex::deserialize(map, ids);
265  if (type == "RealMatrix") return RealMatrix::deserialize(map, ids);
266  if (type == "ComplexMatrix") return ComplexMatrix::deserialize(map, ids);
267  if (type == "String") return String::deserialize(map, ids);
268  if (type == "Json") return Json::deserialize(map, ids);
269  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
270 }
271 
276  : TypeBase(assignable)
277 {}
278 
282 void Axis::find_reachable(::tree::base::PointerMap &map) const {
283  (void)map;
284 }
285 
289 void Axis::check_complete(const ::tree::base::PointerMap &map) const {
290  (void)map;
291 }
292 
297  return NodeType::Axis;
298 }
299 
303 void Axis::visit_internal(VisitorBase &visitor, void *retval) {
304  visitor.raw_visit_axis(*this, retval);
305 }
306 
312  return dynamic_cast<Axis*>(this);
313 }
314 
319 const Axis *Axis::as_axis() const {
320  return dynamic_cast<const Axis*>(this);
321 }
322 
327  return cqasm::tree::make<Axis>(*this);
328 }
329 
334  auto node = cqasm::tree::make<Axis>(*this);
335  return node;
336 }
337 
341 bool Axis::equals(const Node &rhs) const {
342  if (rhs.type() != NodeType::Axis) return false;
343  auto rhsc = dynamic_cast<const Axis&>(rhs);
344  if (this->assignable != rhsc.assignable) return false;
345  return true;
346 }
347 
351 bool Axis::operator==(const Node &rhs) const {
352  if (rhs.type() != NodeType::Axis) return false;
353  auto rhsc = dynamic_cast<const Axis&>(rhs);
354  if (this->assignable != rhsc.assignable) return false;
355  return true;
356 }
357 
362  ::tree::cbor::MapWriter &map,
363  const ::tree::base::PointerMap &ids
364 ) const {
365  (void)ids;
366  map.append_string("@t", "Axis");
367  auto submap = map.append_map("assignable");
368  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(assignable, submap);
369  submap.close();
370  serialize_annotations(map);
371 }
372 
376 std::shared_ptr<Axis> Axis::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
377  (void)ids;
378  auto type = map.at("@t").as_string();
379  if (type != "Axis") {
380  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
381  }
382  auto node = std::make_shared<Axis>(
383  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at("assignable").as_map())
384  );
385  node->deserialize_annotations(map);
386  return node;
387 }
388 
393  : TypeBase(assignable)
394 {}
395 
399 void Bool::find_reachable(::tree::base::PointerMap &map) const {
400  (void)map;
401 }
402 
406 void Bool::check_complete(const ::tree::base::PointerMap &map) const {
407  (void)map;
408 }
409 
414  return NodeType::Bool;
415 }
416 
420 void Bool::visit_internal(VisitorBase &visitor, void *retval) {
421  visitor.raw_visit_bool(*this, retval);
422 }
423 
429  return dynamic_cast<Bool*>(this);
430 }
431 
436 const Bool *Bool::as_bool() const {
437  return dynamic_cast<const Bool*>(this);
438 }
439 
444  return cqasm::tree::make<Bool>(*this);
445 }
446 
451  auto node = cqasm::tree::make<Bool>(*this);
452  return node;
453 }
454 
458 bool Bool::equals(const Node &rhs) const {
459  if (rhs.type() != NodeType::Bool) return false;
460  auto rhsc = dynamic_cast<const Bool&>(rhs);
461  if (this->assignable != rhsc.assignable) return false;
462  return true;
463 }
464 
468 bool Bool::operator==(const Node &rhs) const {
469  if (rhs.type() != NodeType::Bool) return false;
470  auto rhsc = dynamic_cast<const Bool&>(rhs);
471  if (this->assignable != rhsc.assignable) return false;
472  return true;
473 }
474 
479  ::tree::cbor::MapWriter &map,
480  const ::tree::base::PointerMap &ids
481 ) const {
482  (void)ids;
483  map.append_string("@t", "Bool");
484  auto submap = map.append_map("assignable");
485  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(assignable, submap);
486  submap.close();
487  serialize_annotations(map);
488 }
489 
493 std::shared_ptr<Bool> Bool::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
494  (void)ids;
495  auto type = map.at("@t").as_string();
496  if (type != "Bool") {
497  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
498  }
499  auto node = std::make_shared<Bool>(
500  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at("assignable").as_map())
501  );
502  node->deserialize_annotations(map);
503  return node;
504 }
505 
510  : TypeBase(assignable)
511 {}
512 
516 void Complex::find_reachable(::tree::base::PointerMap &map) const {
517  (void)map;
518 }
519 
523 void Complex::check_complete(const ::tree::base::PointerMap &map) const {
524  (void)map;
525 }
526 
531  return NodeType::Complex;
532 }
533 
537 void Complex::visit_internal(VisitorBase &visitor, void *retval) {
538  visitor.raw_visit_complex(*this, retval);
539 }
540 
546  return dynamic_cast<Complex*>(this);
547 }
548 
553 const Complex *Complex::as_complex() const {
554  return dynamic_cast<const Complex*>(this);
555 }
556 
561  return cqasm::tree::make<Complex>(*this);
562 }
563 
568  auto node = cqasm::tree::make<Complex>(*this);
569  return node;
570 }
571 
575 bool Complex::equals(const Node &rhs) const {
576  if (rhs.type() != NodeType::Complex) return false;
577  auto rhsc = dynamic_cast<const Complex&>(rhs);
578  if (this->assignable != rhsc.assignable) return false;
579  return true;
580 }
581 
585 bool Complex::operator==(const Node &rhs) const {
586  if (rhs.type() != NodeType::Complex) return false;
587  auto rhsc = dynamic_cast<const Complex&>(rhs);
588  if (this->assignable != rhsc.assignable) return false;
589  return true;
590 }
591 
596  ::tree::cbor::MapWriter &map,
597  const ::tree::base::PointerMap &ids
598 ) const {
599  (void)ids;
600  map.append_string("@t", "Complex");
601  auto submap = map.append_map("assignable");
602  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(assignable, submap);
603  submap.close();
604  serialize_annotations(map);
605 }
606 
610 std::shared_ptr<Complex> Complex::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
611  (void)ids;
612  auto type = map.at("@t").as_string();
613  if (type != "Complex") {
614  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
615  }
616  auto node = std::make_shared<Complex>(
617  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at("assignable").as_map())
618  );
619  node->deserialize_annotations(map);
620  return node;
621 }
622 
627  : TypeBase(assignable), num_rows(num_rows), num_cols(num_cols)
628 {}
629 
633 void ComplexMatrix::find_reachable(::tree::base::PointerMap &map) const {
634  (void)map;
635 }
636 
640 void ComplexMatrix::check_complete(const ::tree::base::PointerMap &map) const {
641  (void)map;
642 }
643 
649 }
650 
654 void ComplexMatrix::visit_internal(VisitorBase &visitor, void *retval) {
655  visitor.raw_visit_complex_matrix(*this, retval);
656 }
657 
663  return dynamic_cast<ComplexMatrix*>(this);
664 }
665 
671  return dynamic_cast<const ComplexMatrix*>(this);
672 }
673 
678  return cqasm::tree::make<ComplexMatrix>(*this);
679 }
680 
685  auto node = cqasm::tree::make<ComplexMatrix>(*this);
686  return node;
687 }
688 
692 bool ComplexMatrix::equals(const Node &rhs) const {
693  if (rhs.type() != NodeType::ComplexMatrix) return false;
694  auto rhsc = dynamic_cast<const ComplexMatrix&>(rhs);
695  if (this->num_rows != rhsc.num_rows) return false;
696  if (this->num_cols != rhsc.num_cols) return false;
697  if (this->assignable != rhsc.assignable) return false;
698  return true;
699 }
700 
704 bool ComplexMatrix::operator==(const Node &rhs) const {
705  if (rhs.type() != NodeType::ComplexMatrix) return false;
706  auto rhsc = dynamic_cast<const ComplexMatrix&>(rhs);
707  if (this->num_rows != rhsc.num_rows) return false;
708  if (this->num_cols != rhsc.num_cols) return false;
709  if (this->assignable != rhsc.assignable) return false;
710  return true;
711 }
712 
717  ::tree::cbor::MapWriter &map,
718  const ::tree::base::PointerMap &ids
719 ) const {
720  (void)ids;
721  map.append_string("@t", "ComplexMatrix");
722  auto submap = map.append_map("num_rows");
723  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(num_rows, submap);
724  submap.close();
725  submap = map.append_map("num_cols");
726  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(num_cols, submap);
727  submap.close();
728  submap = map.append_map("assignable");
729  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(assignable, submap);
730  submap.close();
731  serialize_annotations(map);
732 }
733 
737 std::shared_ptr<ComplexMatrix> ComplexMatrix::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
738  (void)ids;
739  auto type = map.at("@t").as_string();
740  if (type != "ComplexMatrix") {
741  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
742  }
743  auto node = std::make_shared<ComplexMatrix>(
744  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at("num_rows").as_map()),
745  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at("num_cols").as_map()),
746  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at("assignable").as_map())
747  );
748  node->deserialize_annotations(map);
749  return node;
750 }
751 
756  : TypeBase(assignable)
757 {}
758 
762 void Int::find_reachable(::tree::base::PointerMap &map) const {
763  (void)map;
764 }
765 
769 void Int::check_complete(const ::tree::base::PointerMap &map) const {
770  (void)map;
771 }
772 
777  return NodeType::Int;
778 }
779 
783 void Int::visit_internal(VisitorBase &visitor, void *retval) {
784  visitor.raw_visit_int(*this, retval);
785 }
786 
792  return dynamic_cast<Int*>(this);
793 }
794 
799 const Int *Int::as_int() const {
800  return dynamic_cast<const Int*>(this);
801 }
802 
807  return cqasm::tree::make<Int>(*this);
808 }
809 
814  auto node = cqasm::tree::make<Int>(*this);
815  return node;
816 }
817 
821 bool Int::equals(const Node &rhs) const {
822  if (rhs.type() != NodeType::Int) return false;
823  auto rhsc = dynamic_cast<const Int&>(rhs);
824  if (this->assignable != rhsc.assignable) return false;
825  return true;
826 }
827 
831 bool Int::operator==(const Node &rhs) const {
832  if (rhs.type() != NodeType::Int) return false;
833  auto rhsc = dynamic_cast<const Int&>(rhs);
834  if (this->assignable != rhsc.assignable) return false;
835  return true;
836 }
837 
842  ::tree::cbor::MapWriter &map,
843  const ::tree::base::PointerMap &ids
844 ) const {
845  (void)ids;
846  map.append_string("@t", "Int");
847  auto submap = map.append_map("assignable");
848  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(assignable, submap);
849  submap.close();
850  serialize_annotations(map);
851 }
852 
856 std::shared_ptr<Int> Int::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
857  (void)ids;
858  auto type = map.at("@t").as_string();
859  if (type != "Int") {
860  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
861  }
862  auto node = std::make_shared<Int>(
863  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at("assignable").as_map())
864  );
865  node->deserialize_annotations(map);
866  return node;
867 }
868 
873  : TypeBase(assignable)
874 {}
875 
879 void Json::find_reachable(::tree::base::PointerMap &map) const {
880  (void)map;
881 }
882 
886 void Json::check_complete(const ::tree::base::PointerMap &map) const {
887  (void)map;
888 }
889 
894  return NodeType::Json;
895 }
896 
900 void Json::visit_internal(VisitorBase &visitor, void *retval) {
901  visitor.raw_visit_json(*this, retval);
902 }
903 
909  return dynamic_cast<Json*>(this);
910 }
911 
916 const Json *Json::as_json() const {
917  return dynamic_cast<const Json*>(this);
918 }
919 
924  return cqasm::tree::make<Json>(*this);
925 }
926 
931  auto node = cqasm::tree::make<Json>(*this);
932  return node;
933 }
934 
938 bool Json::equals(const Node &rhs) const {
939  if (rhs.type() != NodeType::Json) return false;
940  auto rhsc = dynamic_cast<const Json&>(rhs);
941  if (this->assignable != rhsc.assignable) return false;
942  return true;
943 }
944 
948 bool Json::operator==(const Node &rhs) const {
949  if (rhs.type() != NodeType::Json) return false;
950  auto rhsc = dynamic_cast<const Json&>(rhs);
951  if (this->assignable != rhsc.assignable) return false;
952  return true;
953 }
954 
959  ::tree::cbor::MapWriter &map,
960  const ::tree::base::PointerMap &ids
961 ) const {
962  (void)ids;
963  map.append_string("@t", "Json");
964  auto submap = map.append_map("assignable");
965  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(assignable, submap);
966  submap.close();
967  serialize_annotations(map);
968 }
969 
973 std::shared_ptr<Json> Json::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
974  (void)ids;
975  auto type = map.at("@t").as_string();
976  if (type != "Json") {
977  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
978  }
979  auto node = std::make_shared<Json>(
980  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at("assignable").as_map())
981  );
982  node->deserialize_annotations(map);
983  return node;
984 }
985 
990  : TypeBase(assignable)
991 {}
992 
996 void Qubit::find_reachable(::tree::base::PointerMap &map) const {
997  (void)map;
998 }
999 
1003 void Qubit::check_complete(const ::tree::base::PointerMap &map) const {
1004  (void)map;
1005 }
1006 
1011  return NodeType::Qubit;
1012 }
1013 
1017 void Qubit::visit_internal(VisitorBase &visitor, void *retval) {
1018  visitor.raw_visit_qubit(*this, retval);
1019 }
1020 
1026  return dynamic_cast<Qubit*>(this);
1027 }
1028 
1033 const Qubit *Qubit::as_qubit() const {
1034  return dynamic_cast<const Qubit*>(this);
1035 }
1036 
1041  return cqasm::tree::make<Qubit>(*this);
1042 }
1043 
1048  auto node = cqasm::tree::make<Qubit>(*this);
1049  return node;
1050 }
1051 
1055 bool Qubit::equals(const Node &rhs) const {
1056  if (rhs.type() != NodeType::Qubit) return false;
1057  auto rhsc = dynamic_cast<const Qubit&>(rhs);
1058  if (this->assignable != rhsc.assignable) return false;
1059  return true;
1060 }
1061 
1065 bool Qubit::operator==(const Node &rhs) const {
1066  if (rhs.type() != NodeType::Qubit) return false;
1067  auto rhsc = dynamic_cast<const Qubit&>(rhs);
1068  if (this->assignable != rhsc.assignable) return false;
1069  return true;
1070 }
1071 
1076  ::tree::cbor::MapWriter &map,
1077  const ::tree::base::PointerMap &ids
1078 ) const {
1079  (void)ids;
1080  map.append_string("@t", "Qubit");
1081  auto submap = map.append_map("assignable");
1082  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(assignable, submap);
1083  submap.close();
1084  serialize_annotations(map);
1085 }
1086 
1090 std::shared_ptr<Qubit> Qubit::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1091  (void)ids;
1092  auto type = map.at("@t").as_string();
1093  if (type != "Qubit") {
1094  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1095  }
1096  auto node = std::make_shared<Qubit>(
1097  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at("assignable").as_map())
1098  );
1099  node->deserialize_annotations(map);
1100  return node;
1101 }
1102 
1107  : TypeBase(assignable)
1108 {}
1109 
1113 void Real::find_reachable(::tree::base::PointerMap &map) const {
1114  (void)map;
1115 }
1116 
1120 void Real::check_complete(const ::tree::base::PointerMap &map) const {
1121  (void)map;
1122 }
1123 
1128  return NodeType::Real;
1129 }
1130 
1134 void Real::visit_internal(VisitorBase &visitor, void *retval) {
1135  visitor.raw_visit_real(*this, retval);
1136 }
1137 
1143  return dynamic_cast<Real*>(this);
1144 }
1145 
1150 const Real *Real::as_real() const {
1151  return dynamic_cast<const Real*>(this);
1152 }
1153 
1158  return cqasm::tree::make<Real>(*this);
1159 }
1160 
1165  auto node = cqasm::tree::make<Real>(*this);
1166  return node;
1167 }
1168 
1172 bool Real::equals(const Node &rhs) const {
1173  if (rhs.type() != NodeType::Real) return false;
1174  auto rhsc = dynamic_cast<const Real&>(rhs);
1175  if (this->assignable != rhsc.assignable) return false;
1176  return true;
1177 }
1178 
1182 bool Real::operator==(const Node &rhs) const {
1183  if (rhs.type() != NodeType::Real) return false;
1184  auto rhsc = dynamic_cast<const Real&>(rhs);
1185  if (this->assignable != rhsc.assignable) return false;
1186  return true;
1187 }
1188 
1193  ::tree::cbor::MapWriter &map,
1194  const ::tree::base::PointerMap &ids
1195 ) const {
1196  (void)ids;
1197  map.append_string("@t", "Real");
1198  auto submap = map.append_map("assignable");
1199  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(assignable, submap);
1200  submap.close();
1201  serialize_annotations(map);
1202 }
1203 
1207 std::shared_ptr<Real> Real::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1208  (void)ids;
1209  auto type = map.at("@t").as_string();
1210  if (type != "Real") {
1211  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1212  }
1213  auto node = std::make_shared<Real>(
1214  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at("assignable").as_map())
1215  );
1216  node->deserialize_annotations(map);
1217  return node;
1218 }
1219 
1224  : TypeBase(assignable), num_rows(num_rows), num_cols(num_cols)
1225 {}
1226 
1230 void RealMatrix::find_reachable(::tree::base::PointerMap &map) const {
1231  (void)map;
1232 }
1233 
1237 void RealMatrix::check_complete(const ::tree::base::PointerMap &map) const {
1238  (void)map;
1239 }
1240 
1245  return NodeType::RealMatrix;
1246 }
1247 
1251 void RealMatrix::visit_internal(VisitorBase &visitor, void *retval) {
1252  visitor.raw_visit_real_matrix(*this, retval);
1253 }
1254 
1260  return dynamic_cast<RealMatrix*>(this);
1261 }
1262 
1268  return dynamic_cast<const RealMatrix*>(this);
1269 }
1270 
1275  return cqasm::tree::make<RealMatrix>(*this);
1276 }
1277 
1282  auto node = cqasm::tree::make<RealMatrix>(*this);
1283  return node;
1284 }
1285 
1289 bool RealMatrix::equals(const Node &rhs) const {
1290  if (rhs.type() != NodeType::RealMatrix) return false;
1291  auto rhsc = dynamic_cast<const RealMatrix&>(rhs);
1292  if (this->num_rows != rhsc.num_rows) return false;
1293  if (this->num_cols != rhsc.num_cols) return false;
1294  if (this->assignable != rhsc.assignable) return false;
1295  return true;
1296 }
1297 
1301 bool RealMatrix::operator==(const Node &rhs) const {
1302  if (rhs.type() != NodeType::RealMatrix) return false;
1303  auto rhsc = dynamic_cast<const RealMatrix&>(rhs);
1304  if (this->num_rows != rhsc.num_rows) return false;
1305  if (this->num_cols != rhsc.num_cols) return false;
1306  if (this->assignable != rhsc.assignable) return false;
1307  return true;
1308 }
1309 
1314  ::tree::cbor::MapWriter &map,
1315  const ::tree::base::PointerMap &ids
1316 ) const {
1317  (void)ids;
1318  map.append_string("@t", "RealMatrix");
1319  auto submap = map.append_map("num_rows");
1320  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(num_rows, submap);
1321  submap.close();
1322  submap = map.append_map("num_cols");
1323  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(num_cols, submap);
1324  submap.close();
1325  submap = map.append_map("assignable");
1326  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(assignable, submap);
1327  submap.close();
1328  serialize_annotations(map);
1329 }
1330 
1334 std::shared_ptr<RealMatrix> RealMatrix::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1335  (void)ids;
1336  auto type = map.at("@t").as_string();
1337  if (type != "RealMatrix") {
1338  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1339  }
1340  auto node = std::make_shared<RealMatrix>(
1341  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at("num_rows").as_map()),
1342  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at("num_cols").as_map()),
1343  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at("assignable").as_map())
1344  );
1345  node->deserialize_annotations(map);
1346  return node;
1347 }
1348 
1353  : TypeBase(assignable)
1354 {}
1355 
1359 void String::find_reachable(::tree::base::PointerMap &map) const {
1360  (void)map;
1361 }
1362 
1366 void String::check_complete(const ::tree::base::PointerMap &map) const {
1367  (void)map;
1368 }
1369 
1374  return NodeType::String;
1375 }
1376 
1380 void String::visit_internal(VisitorBase &visitor, void *retval) {
1381  visitor.raw_visit_string(*this, retval);
1382 }
1383 
1389  return dynamic_cast<String*>(this);
1390 }
1391 
1396 const String *String::as_string() const {
1397  return dynamic_cast<const String*>(this);
1398 }
1399 
1404  return cqasm::tree::make<String>(*this);
1405 }
1406 
1411  auto node = cqasm::tree::make<String>(*this);
1412  return node;
1413 }
1414 
1418 bool String::equals(const Node &rhs) const {
1419  if (rhs.type() != NodeType::String) return false;
1420  auto rhsc = dynamic_cast<const String&>(rhs);
1421  if (this->assignable != rhsc.assignable) return false;
1422  return true;
1423 }
1424 
1428 bool String::operator==(const Node &rhs) const {
1429  if (rhs.type() != NodeType::String) return false;
1430  auto rhsc = dynamic_cast<const String&>(rhs);
1431  if (this->assignable != rhsc.assignable) return false;
1432  return true;
1433 }
1434 
1439  ::tree::cbor::MapWriter &map,
1440  const ::tree::base::PointerMap &ids
1441 ) const {
1442  (void)ids;
1443  map.append_string("@t", "String");
1444  auto submap = map.append_map("assignable");
1445  cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(assignable, submap);
1446  submap.close();
1447  serialize_annotations(map);
1448 }
1449 
1453 std::shared_ptr<String> String::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1454  (void)ids;
1455  auto type = map.at("@t").as_string();
1456  if (type != "String") {
1457  throw std::runtime_error("Schema validation failed: unexpected node type " + type);
1458  }
1459  auto node = std::make_shared<String>(
1460  cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at("assignable").as_map())
1461  );
1462  node->deserialize_annotations(map);
1463  return node;
1464 }
1465 
1469 template <>
1470 void Visitor<void>::raw_visit_node(Node &node, void *retval) {
1471  (void)retval;
1472  this->visit_node(node);
1473 }
1474 
1478 template <>
1479 void Visitor<void>::raw_visit_axis(Axis &node, void *retval) {
1480  (void)retval;
1481  this->visit_axis(node);
1482 }
1483 
1487 template <>
1488 void Visitor<void>::raw_visit_bool(Bool &node, void *retval) {
1489  (void)retval;
1490  this->visit_bool(node);
1491 }
1492 
1496 template <>
1497 void Visitor<void>::raw_visit_complex(Complex &node, void *retval) {
1498  (void)retval;
1499  this->visit_complex(node);
1500 }
1501 
1505 template <>
1507  (void)retval;
1508  this->visit_complex_matrix(node);
1509 }
1510 
1514 template <>
1515 void Visitor<void>::raw_visit_int(Int &node, void *retval) {
1516  (void)retval;
1517  this->visit_int(node);
1518 }
1519 
1523 template <>
1524 void Visitor<void>::raw_visit_json(Json &node, void *retval) {
1525  (void)retval;
1526  this->visit_json(node);
1527 }
1528 
1532 template <>
1533 void Visitor<void>::raw_visit_qubit(Qubit &node, void *retval) {
1534  (void)retval;
1535  this->visit_qubit(node);
1536 }
1537 
1541 template <>
1542 void Visitor<void>::raw_visit_real(Real &node, void *retval) {
1543  (void)retval;
1544  this->visit_real(node);
1545 }
1546 
1550 template <>
1552  (void)retval;
1553  this->visit_real_matrix(node);
1554 }
1555 
1559 template <>
1560 void Visitor<void>::raw_visit_string(String &node, void *retval) {
1561  (void)retval;
1562  this->visit_string(node);
1563 }
1564 
1568 template <>
1570  (void)retval;
1571  this->visit_type_base(node);
1572 }
1573 
1578  visit_type_base(node);
1579 }
1580 
1585  visit_type_base(node);
1586 }
1587 
1592  visit_type_base(node);
1593 }
1594 
1599  visit_type_base(node);
1600 }
1601 
1606  visit_type_base(node);
1607 }
1608 
1613  visit_type_base(node);
1614 }
1615 
1620  visit_type_base(node);
1621 }
1622 
1627  visit_type_base(node);
1628 }
1629 
1634  visit_type_base(node);
1635 }
1636 
1641  visit_type_base(node);
1642 }
1643 
1648  visit_node(node);
1649 }
1650 
1655  for (int i = 0; i < indent; i++) {
1656  out << " ";
1657  }
1658 }
1659 
1664  (void)node;
1665  write_indent();
1666  out << "!Node()" << std::endl;
1667 }
1668 
1673  write_indent();
1674  out << "Axis";
1675  if (ids != nullptr) {
1676  out << "@" << ids->get_ref(node);
1677  }
1678  out << "(";
1679  out << std::endl;
1680  indent++;
1681  write_indent();
1682  out << "assignable: ";
1683  std::stringstream ss;
1684  size_t pos;
1685  ss << node.assignable;
1686  pos = ss.str().find_last_not_of(" \n\r\t");
1687  if (pos != std::string::npos) {
1688  ss.str(ss.str().erase(pos+1));
1689  }
1690  if (ss.str().find('\n') == std::string::npos) {
1691  out << ss.str() << std::endl;
1692  } else {
1693  out << "cqasm::v1::primitives::Bool<<" << std::endl;
1694  indent++;
1695  std::string s;
1696  while (!ss.eof()) {
1697  std::getline(ss, s);
1698  write_indent();
1699  out << s << std::endl;
1700  }
1701  indent--;
1702  write_indent();
1703  out << ">>" << std::endl;
1704  }
1705  indent--;
1706  write_indent();
1707  out << ")" << std::endl;
1708 }
1709 
1714  write_indent();
1715  out << "Bool";
1716  if (ids != nullptr) {
1717  out << "@" << ids->get_ref(node);
1718  }
1719  out << "(";
1720  out << std::endl;
1721  indent++;
1722  write_indent();
1723  out << "assignable: ";
1724  std::stringstream ss;
1725  size_t pos;
1726  ss << node.assignable;
1727  pos = ss.str().find_last_not_of(" \n\r\t");
1728  if (pos != std::string::npos) {
1729  ss.str(ss.str().erase(pos+1));
1730  }
1731  if (ss.str().find('\n') == std::string::npos) {
1732  out << ss.str() << std::endl;
1733  } else {
1734  out << "cqasm::v1::primitives::Bool<<" << std::endl;
1735  indent++;
1736  std::string s;
1737  while (!ss.eof()) {
1738  std::getline(ss, s);
1739  write_indent();
1740  out << s << std::endl;
1741  }
1742  indent--;
1743  write_indent();
1744  out << ">>" << std::endl;
1745  }
1746  indent--;
1747  write_indent();
1748  out << ")" << std::endl;
1749 }
1750 
1755  write_indent();
1756  out << "Complex";
1757  if (ids != nullptr) {
1758  out << "@" << ids->get_ref(node);
1759  }
1760  out << "(";
1761  out << std::endl;
1762  indent++;
1763  write_indent();
1764  out << "assignable: ";
1765  std::stringstream ss;
1766  size_t pos;
1767  ss << node.assignable;
1768  pos = ss.str().find_last_not_of(" \n\r\t");
1769  if (pos != std::string::npos) {
1770  ss.str(ss.str().erase(pos+1));
1771  }
1772  if (ss.str().find('\n') == std::string::npos) {
1773  out << ss.str() << std::endl;
1774  } else {
1775  out << "cqasm::v1::primitives::Bool<<" << std::endl;
1776  indent++;
1777  std::string s;
1778  while (!ss.eof()) {
1779  std::getline(ss, s);
1780  write_indent();
1781  out << s << std::endl;
1782  }
1783  indent--;
1784  write_indent();
1785  out << ">>" << std::endl;
1786  }
1787  indent--;
1788  write_indent();
1789  out << ")" << std::endl;
1790 }
1791 
1796  write_indent();
1797  out << "ComplexMatrix";
1798  if (ids != nullptr) {
1799  out << "@" << ids->get_ref(node);
1800  }
1801  out << "(";
1802  out << std::endl;
1803  indent++;
1804  write_indent();
1805  out << "num_rows: ";
1806  std::stringstream ss;
1807  size_t pos;
1808  ss << node.num_rows;
1809  pos = ss.str().find_last_not_of(" \n\r\t");
1810  if (pos != std::string::npos) {
1811  ss.str(ss.str().erase(pos+1));
1812  }
1813  if (ss.str().find('\n') == std::string::npos) {
1814  out << ss.str() << std::endl;
1815  } else {
1816  out << "cqasm::v1::primitives::Int<<" << std::endl;
1817  indent++;
1818  std::string s;
1819  while (!ss.eof()) {
1820  std::getline(ss, s);
1821  write_indent();
1822  out << s << std::endl;
1823  }
1824  indent--;
1825  write_indent();
1826  out << ">>" << std::endl;
1827  }
1828  write_indent();
1829  out << "num_cols: ";
1830  ss.str("");
1831  ss.clear();
1832  ss << node.num_cols;
1833  pos = ss.str().find_last_not_of(" \n\r\t");
1834  if (pos != std::string::npos) {
1835  ss.str(ss.str().erase(pos+1));
1836  }
1837  if (ss.str().find('\n') == std::string::npos) {
1838  out << ss.str() << std::endl;
1839  } else {
1840  out << "cqasm::v1::primitives::Int<<" << std::endl;
1841  indent++;
1842  std::string s;
1843  while (!ss.eof()) {
1844  std::getline(ss, s);
1845  write_indent();
1846  out << s << std::endl;
1847  }
1848  indent--;
1849  write_indent();
1850  out << ">>" << std::endl;
1851  }
1852  write_indent();
1853  out << "assignable: ";
1854  ss.str("");
1855  ss.clear();
1856  ss << node.assignable;
1857  pos = ss.str().find_last_not_of(" \n\r\t");
1858  if (pos != std::string::npos) {
1859  ss.str(ss.str().erase(pos+1));
1860  }
1861  if (ss.str().find('\n') == std::string::npos) {
1862  out << ss.str() << std::endl;
1863  } else {
1864  out << "cqasm::v1::primitives::Bool<<" << std::endl;
1865  indent++;
1866  std::string s;
1867  while (!ss.eof()) {
1868  std::getline(ss, s);
1869  write_indent();
1870  out << s << std::endl;
1871  }
1872  indent--;
1873  write_indent();
1874  out << ">>" << std::endl;
1875  }
1876  indent--;
1877  write_indent();
1878  out << ")" << std::endl;
1879 }
1880 
1884 void Dumper::visit_int(Int &node) {
1885  write_indent();
1886  out << "Int";
1887  if (ids != nullptr) {
1888  out << "@" << ids->get_ref(node);
1889  }
1890  out << "(";
1891  out << std::endl;
1892  indent++;
1893  write_indent();
1894  out << "assignable: ";
1895  std::stringstream ss;
1896  size_t pos;
1897  ss << node.assignable;
1898  pos = ss.str().find_last_not_of(" \n\r\t");
1899  if (pos != std::string::npos) {
1900  ss.str(ss.str().erase(pos+1));
1901  }
1902  if (ss.str().find('\n') == std::string::npos) {
1903  out << ss.str() << std::endl;
1904  } else {
1905  out << "cqasm::v1::primitives::Bool<<" << std::endl;
1906  indent++;
1907  std::string s;
1908  while (!ss.eof()) {
1909  std::getline(ss, s);
1910  write_indent();
1911  out << s << std::endl;
1912  }
1913  indent--;
1914  write_indent();
1915  out << ">>" << std::endl;
1916  }
1917  indent--;
1918  write_indent();
1919  out << ")" << std::endl;
1920 }
1921 
1926  write_indent();
1927  out << "Json";
1928  if (ids != nullptr) {
1929  out << "@" << ids->get_ref(node);
1930  }
1931  out << "(";
1932  out << std::endl;
1933  indent++;
1934  write_indent();
1935  out << "assignable: ";
1936  std::stringstream ss;
1937  size_t pos;
1938  ss << node.assignable;
1939  pos = ss.str().find_last_not_of(" \n\r\t");
1940  if (pos != std::string::npos) {
1941  ss.str(ss.str().erase(pos+1));
1942  }
1943  if (ss.str().find('\n') == std::string::npos) {
1944  out << ss.str() << std::endl;
1945  } else {
1946  out << "cqasm::v1::primitives::Bool<<" << std::endl;
1947  indent++;
1948  std::string s;
1949  while (!ss.eof()) {
1950  std::getline(ss, s);
1951  write_indent();
1952  out << s << std::endl;
1953  }
1954  indent--;
1955  write_indent();
1956  out << ">>" << std::endl;
1957  }
1958  indent--;
1959  write_indent();
1960  out << ")" << std::endl;
1961 }
1962 
1967  write_indent();
1968  out << "Qubit";
1969  if (ids != nullptr) {
1970  out << "@" << ids->get_ref(node);
1971  }
1972  out << "(";
1973  out << std::endl;
1974  indent++;
1975  write_indent();
1976  out << "assignable: ";
1977  std::stringstream ss;
1978  size_t pos;
1979  ss << node.assignable;
1980  pos = ss.str().find_last_not_of(" \n\r\t");
1981  if (pos != std::string::npos) {
1982  ss.str(ss.str().erase(pos+1));
1983  }
1984  if (ss.str().find('\n') == std::string::npos) {
1985  out << ss.str() << std::endl;
1986  } else {
1987  out << "cqasm::v1::primitives::Bool<<" << std::endl;
1988  indent++;
1989  std::string s;
1990  while (!ss.eof()) {
1991  std::getline(ss, s);
1992  write_indent();
1993  out << s << std::endl;
1994  }
1995  indent--;
1996  write_indent();
1997  out << ">>" << std::endl;
1998  }
1999  indent--;
2000  write_indent();
2001  out << ")" << std::endl;
2002 }
2003 
2008  write_indent();
2009  out << "Real";
2010  if (ids != nullptr) {
2011  out << "@" << ids->get_ref(node);
2012  }
2013  out << "(";
2014  out << std::endl;
2015  indent++;
2016  write_indent();
2017  out << "assignable: ";
2018  std::stringstream ss;
2019  size_t pos;
2020  ss << node.assignable;
2021  pos = ss.str().find_last_not_of(" \n\r\t");
2022  if (pos != std::string::npos) {
2023  ss.str(ss.str().erase(pos+1));
2024  }
2025  if (ss.str().find('\n') == std::string::npos) {
2026  out << ss.str() << std::endl;
2027  } else {
2028  out << "cqasm::v1::primitives::Bool<<" << std::endl;
2029  indent++;
2030  std::string s;
2031  while (!ss.eof()) {
2032  std::getline(ss, s);
2033  write_indent();
2034  out << s << std::endl;
2035  }
2036  indent--;
2037  write_indent();
2038  out << ">>" << std::endl;
2039  }
2040  indent--;
2041  write_indent();
2042  out << ")" << std::endl;
2043 }
2044 
2049  write_indent();
2050  out << "RealMatrix";
2051  if (ids != nullptr) {
2052  out << "@" << ids->get_ref(node);
2053  }
2054  out << "(";
2055  out << std::endl;
2056  indent++;
2057  write_indent();
2058  out << "num_rows: ";
2059  std::stringstream ss;
2060  size_t pos;
2061  ss << node.num_rows;
2062  pos = ss.str().find_last_not_of(" \n\r\t");
2063  if (pos != std::string::npos) {
2064  ss.str(ss.str().erase(pos+1));
2065  }
2066  if (ss.str().find('\n') == std::string::npos) {
2067  out << ss.str() << std::endl;
2068  } else {
2069  out << "cqasm::v1::primitives::Int<<" << std::endl;
2070  indent++;
2071  std::string s;
2072  while (!ss.eof()) {
2073  std::getline(ss, s);
2074  write_indent();
2075  out << s << std::endl;
2076  }
2077  indent--;
2078  write_indent();
2079  out << ">>" << std::endl;
2080  }
2081  write_indent();
2082  out << "num_cols: ";
2083  ss.str("");
2084  ss.clear();
2085  ss << node.num_cols;
2086  pos = ss.str().find_last_not_of(" \n\r\t");
2087  if (pos != std::string::npos) {
2088  ss.str(ss.str().erase(pos+1));
2089  }
2090  if (ss.str().find('\n') == std::string::npos) {
2091  out << ss.str() << std::endl;
2092  } else {
2093  out << "cqasm::v1::primitives::Int<<" << std::endl;
2094  indent++;
2095  std::string s;
2096  while (!ss.eof()) {
2097  std::getline(ss, s);
2098  write_indent();
2099  out << s << std::endl;
2100  }
2101  indent--;
2102  write_indent();
2103  out << ">>" << std::endl;
2104  }
2105  write_indent();
2106  out << "assignable: ";
2107  ss.str("");
2108  ss.clear();
2109  ss << node.assignable;
2110  pos = ss.str().find_last_not_of(" \n\r\t");
2111  if (pos != std::string::npos) {
2112  ss.str(ss.str().erase(pos+1));
2113  }
2114  if (ss.str().find('\n') == std::string::npos) {
2115  out << ss.str() << std::endl;
2116  } else {
2117  out << "cqasm::v1::primitives::Bool<<" << std::endl;
2118  indent++;
2119  std::string s;
2120  while (!ss.eof()) {
2121  std::getline(ss, s);
2122  write_indent();
2123  out << s << std::endl;
2124  }
2125  indent--;
2126  write_indent();
2127  out << ">>" << std::endl;
2128  }
2129  indent--;
2130  write_indent();
2131  out << ")" << std::endl;
2132 }
2133 
2138  write_indent();
2139  out << "String";
2140  if (ids != nullptr) {
2141  out << "@" << ids->get_ref(node);
2142  }
2143  out << "(";
2144  out << std::endl;
2145  indent++;
2146  write_indent();
2147  out << "assignable: ";
2148  std::stringstream ss;
2149  size_t pos;
2150  ss << node.assignable;
2151  pos = ss.str().find_last_not_of(" \n\r\t");
2152  if (pos != std::string::npos) {
2153  ss.str(ss.str().erase(pos+1));
2154  }
2155  if (ss.str().find('\n') == std::string::npos) {
2156  out << ss.str() << std::endl;
2157  } else {
2158  out << "cqasm::v1::primitives::Bool<<" << std::endl;
2159  indent++;
2160  std::string s;
2161  while (!ss.eof()) {
2162  std::getline(ss, s);
2163  write_indent();
2164  out << s << std::endl;
2165  }
2166  indent--;
2167  write_indent();
2168  out << ">>" << std::endl;
2169  }
2170  indent--;
2171  write_indent();
2172  out << ")" << std::endl;
2173 }
2174 
2179  write_indent();
2180  out << "TypeBase";
2181  if (ids != nullptr) {
2182  out << "@" << ids->get_ref(node);
2183  }
2184  out << "(";
2185  out << std::endl;
2186  indent++;
2187  write_indent();
2188  out << "assignable: ";
2189  std::stringstream ss;
2190  size_t pos;
2191  ss << node.assignable;
2192  pos = ss.str().find_last_not_of(" \n\r\t");
2193  if (pos != std::string::npos) {
2194  ss.str(ss.str().erase(pos+1));
2195  }
2196  if (ss.str().find('\n') == std::string::npos) {
2197  out << ss.str() << std::endl;
2198  } else {
2199  out << "cqasm::v1::primitives::Bool<<" << std::endl;
2200  indent++;
2201  std::string s;
2202  while (!ss.eof()) {
2203  std::getline(ss, s);
2204  write_indent();
2205  out << s << std::endl;
2206  }
2207  indent--;
2208  write_indent();
2209  out << ">>" << std::endl;
2210  }
2211  indent--;
2212  write_indent();
2213  out << ")" << std::endl;
2214 }
2215 
2219 template <>
2220 void Node::visit(Visitor<void> &visitor) {
2221  this->visit_internal(visitor);
2222 }
2223 
2227 std::ostream &operator<<(std::ostream &os, const Node &object) {
2228  const_cast<Node&>(object).dump(os);
2229  return os;
2230 }
2231 
2232 } // namespace types
2233 } // namespace v1
2234 } // namespace cqasm
2235 
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void visit_real(Real &node) override
Recursive traversal for Real nodes.
void raw_visit_json(Json &node, void *retval) override
Internal visitor function for Json nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
void visit_qubit(Qubit &node) override
Dumps a Qubit node.
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.
One< Node > copy() const override
Returns a shallow copy of this node.
Type of an integer (signed 64-bit).
String(const cqasm::v1::primitives::Bool &assignable=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Bool >())
Constructor.
NodeType type() const override
Returns the NodeType of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
Type of a real number (IEEE double).
void dump_seq(std::ostream &out=std::cout, int indent=0)
Alternate debug dump that represents links and node uniqueness via sequence number tags...
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
bool equals(const Node &rhs) const override
Value-based equality operator.
NodeType type() const override
Returns the NodeType of this node.
One< Node > copy() const override
Returns a shallow copy of this node.
static std::shared_ptr< Bool > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
NodeType type() const override
Returns the NodeType of this node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this String is complete/fully defined.
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.
NodeType type() const override
Returns the NodeType of this node.
Toplevel namespace with entry points for the new API.
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.
Type of an arbitrary string.
void visit_type_base(TypeBase &node) override
Recursive traversal for TypeBase nodes.
static std::shared_ptr< Axis > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_string(String &node) override
Recursive traversal for String nodes.
String * as_string() override
Interprets this node to a node of type String.
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.
NodeType type() const override
Returns the NodeType of this node.
virtual void raw_visit_string(String &node, void *retval)=0
Internal visitor function for String nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void raw_visit_node(Node &node, void *retval) override
Internal visitor function for nodes of any type.
virtual NodeType type() const =0
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.
static std::shared_ptr< TypeBase > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
Axis * as_axis() override
Interprets this node to a node of type Axis.
static std::shared_ptr< RealMatrix > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual Bool * as_bool()
Interprets this node to a node of type Bool.
void visit_real_matrix(RealMatrix &node) override
Dumps a RealMatrix node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Int 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_real_matrix(RealMatrix &node, void *retval)=0
Internal visitor function for RealMatrix nodes.
std::int64_t Int
Integer primitive used within the AST and semantic trees.
Header file for the various classes representing the types of values available in cQASM...
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
One< Node > clone() const override
Returns a deep copy of this node.
Main class for all nodes.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
Qubit(const cqasm::v1::primitives::Bool &assignable=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Bool >())
Constructor.
NodeType type() const override
Returns the NodeType of this node.
Defines the types for the cQASM semantic tree, based on the classes from cqasm::tree.
Json(const cqasm::v1::primitives::Bool &assignable=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Bool >())
Constructor.
void visit_bool(Bool &node) override
Dumps a Bool node.
cqasm::tree::One< T > One
virtual void raw_visit_int(Int &node, void *retval)=0
Internal visitor function for Int nodes.
Type of a boolean/bit.
virtual TypeBase * as_type_base()
Interprets this node to a node of type TypeBase.
Bool * as_bool() override
Interprets this node to a node of type Bool.
One< Node > clone() const override
Returns a deep copy of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
Int(const cqasm::v1::primitives::Bool &assignable=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Bool >())
Constructor.
Type of a complex matrix.
void raw_visit_bool(Bool &node, void *retval) override
Internal visitor function for Bool nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void visit_string(String &node) override
Dumps a String node.
void raw_visit_axis(Axis &node, void *retval) override
Internal visitor function for Axis nodes.
Qubit * as_qubit() override
Interprets this node to a node of type Qubit.
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.
virtual Real * as_real()
Interprets this node to a node of type Real.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Complex is complete/fully defined.
void raw_visit_real(Real &node, void *retval) override
Internal visitor function for Real nodes.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
virtual Qubit * as_qubit()
Interprets this node to a node of type Qubit.
Type of one or more qubit references.
RealMatrix * as_real_matrix() override
Interprets this node to a node of type RealMatrix.
virtual Axis * as_axis()
Interprets this node to a node of type Axis.
static std::shared_ptr< Qubit > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
bool Bool
Boolean primitive used within the semantic trees.
ComplexMatrix(const cqasm::v1::primitives::Int &num_rows=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >(), const cqasm::v1::primitives::Int &num_cols=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >(), const cqasm::v1::primitives::Bool &assignable=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Bool >())
Constructor.
cqasm::v1::primitives::Int num_rows
Number of rows.
Internal class for implementing the visitor pattern.
void visit_type_base(TypeBase &node) override
Dumps a TypeBase node.
Real(const cqasm::v1::primitives::Bool &assignable=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Bool >())
Constructor.
void visit_complex_matrix(ComplexMatrix &node) override
Dumps a ComplexMatrix node.
virtual ComplexMatrix * as_complex_matrix()
Interprets this node to a node of type ComplexMatrix.
void visit_bool(Bool &node) override
Recursive traversal for Bool nodes.
One< Node > clone() const override
Returns a deep copy of this node.
virtual void raw_visit_complex(Complex &node, void *retval)=0
Internal visitor function for Complex nodes.
void visit_qubit(Qubit &node) override
Recursive traversal for Qubit nodes.
static std::shared_ptr< ComplexMatrix > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void raw_visit_complex_matrix(ComplexMatrix &node, void *retval) override
Internal visitor function for ComplexMatrix nodes.
static std::shared_ptr< Real > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
cqasm::v1::primitives::Bool assignable
Whether a value of this type can be assigned (true), or can only be read (false). ...
void visit_int(Int &node) override
Dumps a Int node.
virtual Int * as_int()
Interprets this node to a node of type Int.
Namespace for the "new" cQASM 1.x API.
bool equals(const Node &rhs) const override
Value-based equality operator.
Type of an axis (x, y, or z).
Base for all types, with a member indicating whether values of this type are assignable (references) ...
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this RealMatrix is complete/fully defined.
void raw_visit_qubit(Qubit &node, void *retval) override
Internal visitor function for Qubit nodes.
cqasm::v1::primitives::Int num_cols
Number of columns.
NodeType
Enumeration of all node types.
Complex * as_complex() override
Interprets this node to a node of type Complex.
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.
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.
virtual String * as_string()
Interprets this node to a node of type String.
RealMatrix(const cqasm::v1::primitives::Int &num_rows=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >(), const cqasm::v1::primitives::Int &num_cols=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >(), const cqasm::v1::primitives::Bool &assignable=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Bool >())
Constructor.
static std::shared_ptr< Node > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual RealMatrix * as_real_matrix()
Interprets this node to a node of type RealMatrix.
static std::shared_ptr< Complex > 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.
void raw_visit_string(String &node, void *retval) override
Internal visitor function for String nodes.
Main class for all nodes.
void visit_int(Int &node) override
Recursive traversal for Int nodes.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void write_indent()
Writes the current indentation level&#39;s worth of spaces.
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.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
Type of a complex number (2x IEEE double).
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Axis is complete/fully defined.
bool equals(const Node &rhs) const override
Value-based equality operator.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Bool is complete/fully defined.
void raw_visit_real_matrix(RealMatrix &node, void *retval) override
Internal visitor function for RealMatrix nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
cqasm::v1::primitives::Int num_rows
Number of rows.
virtual void raw_visit_qubit(Qubit &node, void *retval)=0
Internal visitor function for Qubit nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
static std::shared_ptr< Json > 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_real(Real &node, void *retval)=0
Internal visitor function for Real nodes.
virtual void raw_visit_axis(Axis &node, void *retval)=0
Internal visitor function for Axis nodes.
virtual void raw_visit_bool(Bool &node, void *retval)=0
Internal visitor function for Bool nodes.
void raw_visit_complex(Complex &node, void *retval) override
Internal visitor function for Complex nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
NodeType type() const override
Returns the NodeType of this node.
static std::shared_ptr< String > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
Axis(const cqasm::v1::primitives::Bool &assignable=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Bool >())
Constructor.
static std::shared_ptr< Int > 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 Qubit is complete/fully defined.
Type of a JSON string.
One< Node > clone() const override
Returns a deep copy of this node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ComplexMatrix is complete/fully defined.
void visit_complex(Complex &node) override
Dumps a Complex node.
virtual void raw_visit_complex_matrix(ComplexMatrix &node, void *retval)=0
Internal visitor function for ComplexMatrix nodes.
void visit_json(Json &node) override
Recursive traversal for Json nodes.
NodeType type() const override
Returns the NodeType of this node.
std::ostream & operator<<(std::ostream &os, const Type &type)
Stream << overload for a single type.
void dump(std::ostream &out=std::cout, int indent=0)
Writes a debug dump of this node to the given stream.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
virtual Complex * as_complex()
Interprets this node to a node of type Complex.
void visit_axis(Axis &node) override
Recursive traversal for Axis nodes.
Bool(const cqasm::v1::primitives::Bool &assignable=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Bool >())
Constructor.
TypeBase * as_type_base() override
Interprets this node to a node of type TypeBase.
One< Node > clone() const override
Returns a deep copy of this node.
void visit_complex_matrix(ComplexMatrix &node) override
Recursive traversal for ComplexMatrix nodes.
bool equals(const Node &rhs) const override
Value-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.
virtual Json * as_json()
Interprets this node to a node of type Json.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Json is complete/fully defined.
virtual void raw_visit_json(Json &node, void *retval)=0
Internal visitor function for Json nodes.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void visit_node(Node &node) override
Dumps a Node.
bool equals(const Node &rhs) const override
Value-based equality operator.
Visitor class that debug-dumps a tree to a stream.
One< Node > clone() const override
Returns a deep copy of this node.
void visit_complex(Complex &node) override
Recursive traversal for Complex nodes.
void raw_visit_type_base(TypeBase &node, void *retval) override
Internal visitor function for TypeBase nodes.
One< Node > clone() const override
Returns a deep copy of this node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void visit_real(Real &node) override
Dumps a Real node.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
Real * as_real() override
Interprets this node to a node of type Real.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Real is complete/fully defined.
bool equals(const Node &rhs) const override
Value-based equality operator.
Complex(const cqasm::v1::primitives::Bool &assignable=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Bool >())
Constructor.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
NodeType type() const override
Returns the NodeType of this node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
Json * as_json() override
Interprets this node to a node of type Json.
One< Node > copy() const override
Returns a shallow copy of this node.
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_real_matrix(RealMatrix &node) override
Recursive traversal for RealMatrix nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
T visit(Visitor< T > &visitor)
Visit this object.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
One< Node > copy() const override
Returns a shallow copy of this node.
Int * as_int() override
Interprets this node to a node of type Int.
ComplexMatrix * as_complex_matrix() override
Interprets this node to a node of type ComplexMatrix.
void visit_axis(Axis &node) override
Dumps a Axis node.
void visit_json(Json &node) override
Dumps a Json node.
void raw_visit_int(Int &node, void *retval) override
Internal visitor function for Int nodes.
cqasm::v1::primitives::Int num_cols
Number of columns.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
TypeBase(const cqasm::v1::primitives::Bool &assignable=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Bool >())
Constructor.