libqasm
library for handling cQASM files
cqasm-v1-types-gen.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <iostream>
9 #include "cqasm-tree.hpp"
10 #include "cqasm-v1-primitives.hpp"
12 
13 namespace cqasm {
14 namespace v1 {
15 
58 namespace types {
59 
60 // Base classes used to construct the tree.
62 template <class T> using Maybe = cqasm::tree::Maybe<T>;
63 template <class T> using One = cqasm::tree::One<T>;
64 template <class T> using Any = cqasm::tree::Any<T>;
65 template <class T> using Many = cqasm::tree::Many<T>;
66 template <class T> using OptLink = cqasm::tree::OptLink<T>;
67 template <class T> using Link = cqasm::tree::Link<T>;
68 
69 // Forward declarations for all classes.
70 class Node;
71 class Axis;
72 class Bool;
73 class Complex;
74 class ComplexMatrix;
75 class Int;
76 class Json;
77 class Qubit;
78 class Real;
79 class RealMatrix;
80 class String;
81 class TypeBase;
82 class VisitorBase;
83 template <typename T = void>
84 class Visitor;
85 class RecursiveVisitor;
86 class Dumper;
87 
91 enum class NodeType {
92  Axis,
93  Bool,
94  Complex,
96  Int,
97  Json,
98  Qubit,
99  Real,
100  RealMatrix,
101  String
102 };
103 
107 class Node : public Base {
108 public:
109 
113  virtual NodeType type() const = 0;
114 
118  virtual One<Node> copy() const = 0;
119 
123  virtual One<Node> clone() const = 0;
124 
128  virtual bool equals(const Node& rhs) const = 0;
129 
133  virtual bool operator==(const Node& rhs) const = 0;
134 
138  inline bool operator!=(const Node& rhs) const {
139  return !(*this == rhs);
140  }
141 
142 protected:
143 
147  virtual void visit_internal(VisitorBase &visitor, void *retval=nullptr) = 0;
148 
149 public:
150 
154  template <typename T>
155  T visit(Visitor<T> &visitor);
156 
160  void dump(std::ostream &out=std::cout, int indent=0);
161 
166  void dump_seq(std::ostream &out=std::cout, int indent=0);
167 
172  virtual Axis *as_axis();
173 
178  virtual const Axis *as_axis() const;
179 
184  virtual Bool *as_bool();
185 
190  virtual const Bool *as_bool() const;
191 
196  virtual Complex *as_complex();
197 
202  virtual const Complex *as_complex() const;
203 
208  virtual ComplexMatrix *as_complex_matrix();
209 
214  virtual const ComplexMatrix *as_complex_matrix() const;
215 
220  virtual Int *as_int();
221 
226  virtual const Int *as_int() const;
227 
232  virtual Json *as_json();
233 
238  virtual const Json *as_json() const;
239 
244  virtual Qubit *as_qubit();
245 
250  virtual const Qubit *as_qubit() const;
251 
256  virtual Real *as_real();
257 
262  virtual const Real *as_real() const;
263 
268  virtual RealMatrix *as_real_matrix();
269 
274  virtual const RealMatrix *as_real_matrix() const;
275 
280  virtual String *as_string();
281 
286  virtual const String *as_string() const;
287 
292  virtual TypeBase *as_type_base();
293 
298  virtual const TypeBase *as_type_base() const;
299 
303  virtual void serialize(
304  ::tree::cbor::MapWriter &map,
305  const ::tree::base::PointerMap &ids
306  ) const = 0;
307 
311  static std::shared_ptr<Node> deserialize(
312  const ::tree::cbor::MapReader &map,
313  ::tree::base::IdentifierMap &ids
314  );
315 
316 };
317 
322 class TypeBase : public Node {
323 public:
324 
332 
336  TypeBase(const cqasm::v1::primitives::Bool &assignable = cqasm::v1::primitives::initialize<cqasm::v1::primitives::Bool>());
337 
342  TypeBase *as_type_base() override;
343 
348  const TypeBase *as_type_base() const override;
349 
353  static std::shared_ptr<TypeBase> deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
354 
355 };
356 
360 class Axis : public TypeBase {
361 public:
362 
366  Axis(const cqasm::v1::primitives::Bool &assignable = cqasm::v1::primitives::initialize<cqasm::v1::primitives::Bool>());
367 
371  void find_reachable(::tree::base::PointerMap &map) const override;
372 
376  void check_complete(const ::tree::base::PointerMap &map) const override;
377 
381  NodeType type() const override;
382 
383 protected:
384 
388  void visit_internal(VisitorBase &visitor, void *retval) override;
389 
390 public:
391 
396  Axis *as_axis() override;
397 
402  const Axis *as_axis() const override;
403 
407  One<Node> copy() const override;
408 
412  One<Node> clone() const override;
413 
417  bool equals(const Node &rhs) const override;
418 
422  bool operator==(const Node &rhs) const override;
423 
427  void serialize(
428  ::tree::cbor::MapWriter &map,
429  const ::tree::base::PointerMap &ids
430  ) const override;
431 
435  static std::shared_ptr<Axis> deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
436 
437 };
438 
442 class Bool : public TypeBase {
443 public:
444 
448  Bool(const cqasm::v1::primitives::Bool &assignable = cqasm::v1::primitives::initialize<cqasm::v1::primitives::Bool>());
449 
453  void find_reachable(::tree::base::PointerMap &map) const override;
454 
458  void check_complete(const ::tree::base::PointerMap &map) const override;
459 
463  NodeType type() const override;
464 
465 protected:
466 
470  void visit_internal(VisitorBase &visitor, void *retval) override;
471 
472 public:
473 
478  Bool *as_bool() override;
479 
484  const Bool *as_bool() const override;
485 
489  One<Node> copy() const override;
490 
494  One<Node> clone() const override;
495 
499  bool equals(const Node &rhs) const override;
500 
504  bool operator==(const Node &rhs) const override;
505 
509  void serialize(
510  ::tree::cbor::MapWriter &map,
511  const ::tree::base::PointerMap &ids
512  ) const override;
513 
517  static std::shared_ptr<Bool> deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
518 
519 };
520 
524 class Complex : public TypeBase {
525 public:
526 
530  Complex(const cqasm::v1::primitives::Bool &assignable = cqasm::v1::primitives::initialize<cqasm::v1::primitives::Bool>());
531 
535  void find_reachable(::tree::base::PointerMap &map) const override;
536 
540  void check_complete(const ::tree::base::PointerMap &map) const override;
541 
545  NodeType type() const override;
546 
547 protected:
548 
552  void visit_internal(VisitorBase &visitor, void *retval) override;
553 
554 public:
555 
560  Complex *as_complex() override;
561 
566  const Complex *as_complex() const override;
567 
571  One<Node> copy() const override;
572 
576  One<Node> clone() const override;
577 
581  bool equals(const Node &rhs) const override;
582 
586  bool operator==(const Node &rhs) const override;
587 
591  void serialize(
592  ::tree::cbor::MapWriter &map,
593  const ::tree::base::PointerMap &ids
594  ) const override;
595 
599  static std::shared_ptr<Complex> deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
600 
601 };
602 
606 class ComplexMatrix : public TypeBase {
607 public:
608 
614 
620 
624  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>());
625 
629  void find_reachable(::tree::base::PointerMap &map) const override;
630 
634  void check_complete(const ::tree::base::PointerMap &map) const override;
635 
639  NodeType type() const override;
640 
641 protected:
642 
646  void visit_internal(VisitorBase &visitor, void *retval) override;
647 
648 public:
649 
654  ComplexMatrix *as_complex_matrix() override;
655 
660  const ComplexMatrix *as_complex_matrix() const override;
661 
665  One<Node> copy() const override;
666 
670  One<Node> clone() const override;
671 
675  bool equals(const Node &rhs) const override;
676 
680  bool operator==(const Node &rhs) const override;
681 
685  void serialize(
686  ::tree::cbor::MapWriter &map,
687  const ::tree::base::PointerMap &ids
688  ) const override;
689 
693  static std::shared_ptr<ComplexMatrix> deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
694 
695 };
696 
700 class Int : public TypeBase {
701 public:
702 
706  Int(const cqasm::v1::primitives::Bool &assignable = cqasm::v1::primitives::initialize<cqasm::v1::primitives::Bool>());
707 
711  void find_reachable(::tree::base::PointerMap &map) const override;
712 
716  void check_complete(const ::tree::base::PointerMap &map) const override;
717 
721  NodeType type() const override;
722 
723 protected:
724 
728  void visit_internal(VisitorBase &visitor, void *retval) override;
729 
730 public:
731 
736  Int *as_int() override;
737 
742  const Int *as_int() const override;
743 
747  One<Node> copy() const override;
748 
752  One<Node> clone() const override;
753 
757  bool equals(const Node &rhs) const override;
758 
762  bool operator==(const Node &rhs) const override;
763 
767  void serialize(
768  ::tree::cbor::MapWriter &map,
769  const ::tree::base::PointerMap &ids
770  ) const override;
771 
775  static std::shared_ptr<Int> deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
776 
777 };
778 
782 class Json : public TypeBase {
783 public:
784 
788  Json(const cqasm::v1::primitives::Bool &assignable = cqasm::v1::primitives::initialize<cqasm::v1::primitives::Bool>());
789 
793  void find_reachable(::tree::base::PointerMap &map) const override;
794 
798  void check_complete(const ::tree::base::PointerMap &map) const override;
799 
803  NodeType type() const override;
804 
805 protected:
806 
810  void visit_internal(VisitorBase &visitor, void *retval) override;
811 
812 public:
813 
818  Json *as_json() override;
819 
824  const Json *as_json() const override;
825 
829  One<Node> copy() const override;
830 
834  One<Node> clone() const override;
835 
839  bool equals(const Node &rhs) const override;
840 
844  bool operator==(const Node &rhs) const override;
845 
849  void serialize(
850  ::tree::cbor::MapWriter &map,
851  const ::tree::base::PointerMap &ids
852  ) const override;
853 
857  static std::shared_ptr<Json> deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
858 
859 };
860 
864 class Qubit : public TypeBase {
865 public:
866 
870  Qubit(const cqasm::v1::primitives::Bool &assignable = cqasm::v1::primitives::initialize<cqasm::v1::primitives::Bool>());
871 
875  void find_reachable(::tree::base::PointerMap &map) const override;
876 
880  void check_complete(const ::tree::base::PointerMap &map) const override;
881 
885  NodeType type() const override;
886 
887 protected:
888 
892  void visit_internal(VisitorBase &visitor, void *retval) override;
893 
894 public:
895 
900  Qubit *as_qubit() override;
901 
906  const Qubit *as_qubit() const override;
907 
911  One<Node> copy() const override;
912 
916  One<Node> clone() const override;
917 
921  bool equals(const Node &rhs) const override;
922 
926  bool operator==(const Node &rhs) const override;
927 
931  void serialize(
932  ::tree::cbor::MapWriter &map,
933  const ::tree::base::PointerMap &ids
934  ) const override;
935 
939  static std::shared_ptr<Qubit> deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
940 
941 };
942 
946 class Real : public TypeBase {
947 public:
948 
952  Real(const cqasm::v1::primitives::Bool &assignable = cqasm::v1::primitives::initialize<cqasm::v1::primitives::Bool>());
953 
957  void find_reachable(::tree::base::PointerMap &map) const override;
958 
962  void check_complete(const ::tree::base::PointerMap &map) const override;
963 
967  NodeType type() const override;
968 
969 protected:
970 
974  void visit_internal(VisitorBase &visitor, void *retval) override;
975 
976 public:
977 
982  Real *as_real() override;
983 
988  const Real *as_real() const override;
989 
993  One<Node> copy() const override;
994 
998  One<Node> clone() const override;
999 
1003  bool equals(const Node &rhs) const override;
1004 
1008  bool operator==(const Node &rhs) const override;
1009 
1013  void serialize(
1014  ::tree::cbor::MapWriter &map,
1015  const ::tree::base::PointerMap &ids
1016  ) const override;
1017 
1021  static std::shared_ptr<Real> deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
1022 
1023 };
1024 
1028 class RealMatrix : public TypeBase {
1029 public:
1030 
1036 
1042 
1046  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>());
1047 
1051  void find_reachable(::tree::base::PointerMap &map) const override;
1052 
1056  void check_complete(const ::tree::base::PointerMap &map) const override;
1057 
1061  NodeType type() const override;
1062 
1063 protected:
1064 
1068  void visit_internal(VisitorBase &visitor, void *retval) override;
1069 
1070 public:
1071 
1076  RealMatrix *as_real_matrix() override;
1077 
1082  const RealMatrix *as_real_matrix() const override;
1083 
1087  One<Node> copy() const override;
1088 
1092  One<Node> clone() const override;
1093 
1097  bool equals(const Node &rhs) const override;
1098 
1102  bool operator==(const Node &rhs) const override;
1103 
1107  void serialize(
1108  ::tree::cbor::MapWriter &map,
1109  const ::tree::base::PointerMap &ids
1110  ) const override;
1111 
1115  static std::shared_ptr<RealMatrix> deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
1116 
1117 };
1118 
1122 class String : public TypeBase {
1123 public:
1124 
1128  String(const cqasm::v1::primitives::Bool &assignable = cqasm::v1::primitives::initialize<cqasm::v1::primitives::Bool>());
1129 
1133  void find_reachable(::tree::base::PointerMap &map) const override;
1134 
1138  void check_complete(const ::tree::base::PointerMap &map) const override;
1139 
1143  NodeType type() const override;
1144 
1145 protected:
1146 
1150  void visit_internal(VisitorBase &visitor, void *retval) override;
1151 
1152 public:
1153 
1158  String *as_string() override;
1159 
1164  const String *as_string() const override;
1165 
1169  One<Node> copy() const override;
1170 
1174  One<Node> clone() const override;
1175 
1179  bool equals(const Node &rhs) const override;
1180 
1184  bool operator==(const Node &rhs) const override;
1185 
1189  void serialize(
1190  ::tree::cbor::MapWriter &map,
1191  const ::tree::base::PointerMap &ids
1192  ) const override;
1193 
1197  static std::shared_ptr<String> deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
1198 
1199 };
1200 
1205 public:
1206 
1210  virtual ~VisitorBase() = default;
1211 
1212 protected:
1213 
1214  friend class Node;
1215  friend class Axis;
1216  friend class Bool;
1217  friend class Complex;
1218  friend class ComplexMatrix;
1219  friend class Int;
1220  friend class Json;
1221  friend class Qubit;
1222  friend class Real;
1223  friend class RealMatrix;
1224  friend class String;
1225  friend class TypeBase;
1226 
1230  virtual void raw_visit_node(Node &node, void *retval) = 0;
1231 
1235  virtual void raw_visit_axis(Axis &node, void *retval) = 0;
1236 
1240  virtual void raw_visit_bool(Bool &node, void *retval) = 0;
1241 
1245  virtual void raw_visit_complex(Complex &node, void *retval) = 0;
1246 
1250  virtual void raw_visit_complex_matrix(ComplexMatrix &node, void *retval) = 0;
1251 
1255  virtual void raw_visit_int(Int &node, void *retval) = 0;
1256 
1260  virtual void raw_visit_json(Json &node, void *retval) = 0;
1261 
1265  virtual void raw_visit_qubit(Qubit &node, void *retval) = 0;
1266 
1270  virtual void raw_visit_real(Real &node, void *retval) = 0;
1271 
1275  virtual void raw_visit_real_matrix(RealMatrix &node, void *retval) = 0;
1276 
1280  virtual void raw_visit_string(String &node, void *retval) = 0;
1281 
1285  virtual void raw_visit_type_base(TypeBase &node, void *retval) = 0;
1286 
1287 };
1288 
1299 template <typename T>
1300 class Visitor : public VisitorBase {
1301 protected:
1302 
1306  void raw_visit_node(Node &node, void *retval) override;
1307 
1311  void raw_visit_axis(Axis &node, void *retval) override;
1312 
1316  void raw_visit_bool(Bool &node, void *retval) override;
1317 
1321  void raw_visit_complex(Complex &node, void *retval) override;
1322 
1326  void raw_visit_complex_matrix(ComplexMatrix &node, void *retval) override;
1327 
1331  void raw_visit_int(Int &node, void *retval) override;
1332 
1336  void raw_visit_json(Json &node, void *retval) override;
1337 
1341  void raw_visit_qubit(Qubit &node, void *retval) override;
1342 
1346  void raw_visit_real(Real &node, void *retval) override;
1347 
1351  void raw_visit_real_matrix(RealMatrix &node, void *retval) override;
1352 
1356  void raw_visit_string(String &node, void *retval) override;
1357 
1361  void raw_visit_type_base(TypeBase &node, void *retval) override;
1362 
1363 public:
1364 
1368  virtual T visit_node(Node &node) = 0;
1369 
1373  virtual T visit_axis(Axis &node) {
1374  return visit_type_base(node);
1375  }
1376 
1380  virtual T visit_bool(Bool &node) {
1381  return visit_type_base(node);
1382  }
1383 
1387  virtual T visit_complex(Complex &node) {
1388  return visit_type_base(node);
1389  }
1390 
1395  return visit_type_base(node);
1396  }
1397 
1401  virtual T visit_int(Int &node) {
1402  return visit_type_base(node);
1403  }
1404 
1408  virtual T visit_json(Json &node) {
1409  return visit_type_base(node);
1410  }
1411 
1415  virtual T visit_qubit(Qubit &node) {
1416  return visit_type_base(node);
1417  }
1418 
1422  virtual T visit_real(Real &node) {
1423  return visit_type_base(node);
1424  }
1425 
1429  virtual T visit_real_matrix(RealMatrix &node) {
1430  return visit_type_base(node);
1431  }
1432 
1436  virtual T visit_string(String &node) {
1437  return visit_type_base(node);
1438  }
1439 
1443  virtual T visit_type_base(TypeBase &node) {
1444  return visit_node(node);
1445  }
1446 
1447 };
1448 
1452  template <typename T>
1453  void Visitor<T>::raw_visit_node(Node &node, void *retval) {
1454  if (retval == nullptr) {
1455  this->visit_node(node);
1456  } else {
1457  *((T*)retval) = this->visit_node(node);
1458  };
1459  }
1460 
1464  template <>
1465  void Visitor<void>::raw_visit_node(Node &node, void *retval);
1466 
1470  template <typename T>
1471  void Visitor<T>::raw_visit_axis(Axis &node, void *retval) {
1472  if (retval == nullptr) {
1473  this->visit_axis(node);
1474  } else {
1475  *((T*)retval) = this->visit_axis(node);
1476  };
1477  }
1478 
1482  template <>
1483  void Visitor<void>::raw_visit_axis(Axis &node, void *retval);
1484 
1488  template <typename T>
1489  void Visitor<T>::raw_visit_bool(Bool &node, void *retval) {
1490  if (retval == nullptr) {
1491  this->visit_bool(node);
1492  } else {
1493  *((T*)retval) = this->visit_bool(node);
1494  };
1495  }
1496 
1500  template <>
1501  void Visitor<void>::raw_visit_bool(Bool &node, void *retval);
1502 
1506  template <typename T>
1507  void Visitor<T>::raw_visit_complex(Complex &node, void *retval) {
1508  if (retval == nullptr) {
1509  this->visit_complex(node);
1510  } else {
1511  *((T*)retval) = this->visit_complex(node);
1512  };
1513  }
1514 
1518  template <>
1519  void Visitor<void>::raw_visit_complex(Complex &node, void *retval);
1520 
1524  template <typename T>
1526  if (retval == nullptr) {
1527  this->visit_complex_matrix(node);
1528  } else {
1529  *((T*)retval) = this->visit_complex_matrix(node);
1530  };
1531  }
1532 
1536  template <>
1537  void Visitor<void>::raw_visit_complex_matrix(ComplexMatrix &node, void *retval);
1538 
1542  template <typename T>
1543  void Visitor<T>::raw_visit_int(Int &node, void *retval) {
1544  if (retval == nullptr) {
1545  this->visit_int(node);
1546  } else {
1547  *((T*)retval) = this->visit_int(node);
1548  };
1549  }
1550 
1554  template <>
1555  void Visitor<void>::raw_visit_int(Int &node, void *retval);
1556 
1560  template <typename T>
1561  void Visitor<T>::raw_visit_json(Json &node, void *retval) {
1562  if (retval == nullptr) {
1563  this->visit_json(node);
1564  } else {
1565  *((T*)retval) = this->visit_json(node);
1566  };
1567  }
1568 
1572  template <>
1573  void Visitor<void>::raw_visit_json(Json &node, void *retval);
1574 
1578  template <typename T>
1579  void Visitor<T>::raw_visit_qubit(Qubit &node, void *retval) {
1580  if (retval == nullptr) {
1581  this->visit_qubit(node);
1582  } else {
1583  *((T*)retval) = this->visit_qubit(node);
1584  };
1585  }
1586 
1590  template <>
1591  void Visitor<void>::raw_visit_qubit(Qubit &node, void *retval);
1592 
1596  template <typename T>
1597  void Visitor<T>::raw_visit_real(Real &node, void *retval) {
1598  if (retval == nullptr) {
1599  this->visit_real(node);
1600  } else {
1601  *((T*)retval) = this->visit_real(node);
1602  };
1603  }
1604 
1608  template <>
1609  void Visitor<void>::raw_visit_real(Real &node, void *retval);
1610 
1614  template <typename T>
1615  void Visitor<T>::raw_visit_real_matrix(RealMatrix &node, void *retval) {
1616  if (retval == nullptr) {
1617  this->visit_real_matrix(node);
1618  } else {
1619  *((T*)retval) = this->visit_real_matrix(node);
1620  };
1621  }
1622 
1626  template <>
1627  void Visitor<void>::raw_visit_real_matrix(RealMatrix &node, void *retval);
1628 
1632  template <typename T>
1633  void Visitor<T>::raw_visit_string(String &node, void *retval) {
1634  if (retval == nullptr) {
1635  this->visit_string(node);
1636  } else {
1637  *((T*)retval) = this->visit_string(node);
1638  };
1639  }
1640 
1644  template <>
1645  void Visitor<void>::raw_visit_string(String &node, void *retval);
1646 
1650  template <typename T>
1651  void Visitor<T>::raw_visit_type_base(TypeBase &node, void *retval) {
1652  if (retval == nullptr) {
1653  this->visit_type_base(node);
1654  } else {
1655  *((T*)retval) = this->visit_type_base(node);
1656  };
1657  }
1658 
1662  template <>
1663  void Visitor<void>::raw_visit_type_base(TypeBase &node, void *retval);
1664 
1672 class RecursiveVisitor : public Visitor<void> {
1673 public:
1674 
1678  void visit_axis(Axis &node) override;
1679 
1683  void visit_bool(Bool &node) override;
1684 
1688  void visit_complex(Complex &node) override;
1689 
1693  void visit_complex_matrix(ComplexMatrix &node) override;
1694 
1698  void visit_int(Int &node) override;
1699 
1703  void visit_json(Json &node) override;
1704 
1708  void visit_qubit(Qubit &node) override;
1709 
1713  void visit_real(Real &node) override;
1714 
1718  void visit_real_matrix(RealMatrix &node) override;
1719 
1723  void visit_string(String &node) override;
1724 
1728  void visit_type_base(TypeBase &node) override;
1729 
1730 };
1731 
1735 class Dumper : public RecursiveVisitor {
1736 protected:
1737 
1741  std::ostream &out;
1742 
1746  int indent = 0;
1747 
1751  ::tree::base::PointerMap *ids;
1755  bool in_link = false;
1756 
1760  void write_indent();
1761 
1762 public:
1763 
1767  Dumper(std::ostream &out, int indent=0, ::tree::base::PointerMap *ids = nullptr) : out(out), indent(indent), ids(ids) {};
1768 
1772  void visit_node(Node &node) override;
1776  void visit_axis(Axis &node) override;
1777 
1781  void visit_bool(Bool &node) override;
1782 
1786  void visit_complex(Complex &node) override;
1787 
1791  void visit_complex_matrix(ComplexMatrix &node) override;
1792 
1796  void visit_int(Int &node) override;
1797 
1801  void visit_json(Json &node) override;
1802 
1806  void visit_qubit(Qubit &node) override;
1807 
1811  void visit_real(Real &node) override;
1812 
1816  void visit_real_matrix(RealMatrix &node) override;
1817 
1821  void visit_string(String &node) override;
1822 
1826  void visit_type_base(TypeBase &node) override;
1827 
1828 };
1829 
1833 template <typename T>
1835  T retval;
1836  this->visit_internal(visitor, &retval);
1837  return retval;
1838 }
1839 
1843 template <>
1844 void Node::visit(Visitor<void> &visitor);
1845 
1849 std::ostream &operator<<(std::ostream &os, const Node &object);
1850 
1851 } // namespace types
1852 } // namespace v1
1853 } // namespace cqasm
1854 
void raw_visit_json(Json &node, void *retval) override
Internal visitor function for Json nodes.
cqasm::tree::Maybe< T > Maybe
::tree::base::Base Base
Definition: cqasm-tree.hpp:20
Type of an integer (signed 64-bit).
::tree::base::Maybe< T > Maybe
Definition: cqasm-tree.hpp:23
Type of a real number (IEEE double).
::tree::base::Link< T > Link
Definition: cqasm-tree.hpp:35
cqasm::tree::Many< T > Many
cqasm::tree::OptLink< T > OptLink
::tree::base::OptLink< T > OptLink
Definition: cqasm-tree.hpp:38
virtual T visit_qubit(Qubit &node)
Visitor function for Qubit nodes.
error_model::ErrorModelRef deserialize(const ::tree::cbor::MapReader &map)
Deserializes the given primitive object from CBOR.
Toplevel namespace with entry points for the new API.
cqasm::tree::Base Base
Type of an arbitrary string.
void raw_visit_node(Node &node, void *retval) override
Internal visitor function for nodes of any type.
std::int64_t Int
Integer primitive used within the AST and semantic trees.
Main class for all nodes.
bool operator!=(const Node &rhs) const
Pointer-based inequality operator.
cqasm::tree::One< T > One
Type of a boolean/bit.
void serialize(const error_model::ErrorModelRef &obj, ::tree::cbor::MapWriter &map)
Type of a complex matrix.
void raw_visit_bool(Bool &node, void *retval) override
Internal visitor function for Bool nodes.
void raw_visit_axis(Axis &node, void *retval) override
Internal visitor function for Axis nodes.
Base class for the visitor pattern for the tree.
virtual T visit_json(Json &node)
Visitor function for Json nodes.
void raw_visit_real(Real &node, void *retval) override
Internal visitor function for Real nodes.
Type of one or more qubit references.
bool Bool
Boolean primitive used within the semantic trees.
cqasm::v1::primitives::Int num_rows
Number of rows.
cqasm::tree::Any< T > Any
Internal class for implementing the visitor pattern.
Defines primitive types for use in trees generated by tree-gen.
virtual T visit_bool(Bool &node)
Visitor function for Bool nodes.
virtual T visit_real_matrix(RealMatrix &node)
Visitor function for RealMatrix nodes.
void raw_visit_complex_matrix(ComplexMatrix &node, void *retval) override
Internal visitor function for ComplexMatrix nodes.
cqasm::v1::primitives::Bool assignable
Whether a value of this type can be assigned (true), or can only be read (false). ...
virtual T visit_axis(Axis &node)
Visitor function for Axis nodes.
Namespace for the "new" cQASM 1.x API.
Type of an axis (x, y, or z).
Wrapper for pulling parts of tree-gen&#39;s support library into libqasm.
Base for all types, with a member indicating whether values of this type are assignable (references) ...
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.
Forward reference for tree::semantic::Variable, so the values tree can use it (resolves circular depe...
void raw_visit_string(String &node, void *retval) override
Internal visitor function for String nodes.
Main class for all nodes.
::tree::base::Any< T > Any
Definition: cqasm-tree.hpp:29
Type of a complex number (2x IEEE double).
void raw_visit_real_matrix(RealMatrix &node, void *retval) override
Internal visitor function for RealMatrix nodes.
Visitor base class defaulting to DFS pre-order traversal.
cqasm::v1::primitives::Int num_rows
Number of rows.
::tree::base::Many< T > Many
Definition: cqasm-tree.hpp:32
std::ostream & out
Output stream to dump to.
virtual T visit_complex_matrix(ComplexMatrix &node)
Visitor function for ComplexMatrix nodes.
void raw_visit_complex(Complex &node, void *retval) override
Internal visitor function for Complex nodes.
virtual T visit_int(Int &node)
Visitor function for Int nodes.
Type of a JSON string.
virtual T visit_string(String &node)
Visitor function for String nodes.
std::ostream & operator<<(std::ostream &os, const Type &type)
Stream << overload for a single type.
Dumper(std::ostream &out, int indent=0, ::tree::base::PointerMap *ids=nullptr)
Construct a dumping visitor.
virtual T visit_real(Real &node)
Visitor function for Real nodes.
virtual T visit_type_base(TypeBase &node)
Fallback function for TypeBase nodes.
cqasm::tree::Link< T > Link
Visitor class that debug-dumps a tree to a stream.
void raw_visit_type_base(TypeBase &node, void *retval) override
Internal visitor function for TypeBase nodes.
::tree::base::One< T > One
Definition: cqasm-tree.hpp:26
T visit(Visitor< T > &visitor)
Visit this object.
::tree::base::PointerMap * ids
When non-null, the print node IDs from here instead of link contents.
void raw_visit_int(Int &node, void *retval) override
Internal visitor function for Int nodes.
cqasm::v1::primitives::Int num_cols
Number of columns.
virtual T visit_complex(Complex &node)
Visitor function for Complex nodes.