83 template <
typename T =
void>
128 virtual bool equals(
const Node& rhs)
const = 0;
133 virtual bool operator==(
const Node& rhs)
const = 0;
139 return !(*
this == rhs);
147 virtual void visit_internal(
VisitorBase &visitor,
void *retval=
nullptr) = 0;
154 template <
typename T>
160 void dump(std::ostream &out=std::cout,
int indent=0);
166 void dump_seq(std::ostream &out=std::cout,
int indent=0);
172 virtual Axis *as_axis();
178 virtual const Axis *as_axis()
const;
184 virtual Bool *as_bool();
190 virtual const Bool *as_bool()
const;
202 virtual const Complex *as_complex()
const;
220 virtual Int *as_int();
226 virtual const Int *as_int()
const;
232 virtual Json *as_json();
238 virtual const Json *as_json()
const;
244 virtual Qubit *as_qubit();
250 virtual const Qubit *as_qubit()
const;
256 virtual Real *as_real();
262 virtual const Real *as_real()
const;
274 virtual const RealMatrix *as_real_matrix()
const;
280 virtual String *as_string();
286 virtual const String *as_string()
const;
298 virtual const TypeBase *as_type_base()
const;
304 ::tree::cbor::MapWriter &map,
305 const ::tree::base::PointerMap &ids
312 const ::tree::cbor::MapReader &map,
313 ::tree::base::IdentifierMap &ids
348 const TypeBase *as_type_base()
const override;
353 static std::shared_ptr<TypeBase>
deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
371 void find_reachable(::tree::base::PointerMap &map)
const override;
376 void check_complete(const ::tree::base::PointerMap &map)
const override;
388 void visit_internal(
VisitorBase &visitor,
void *retval)
override;
396 Axis *as_axis()
override;
402 const Axis *as_axis()
const override;
417 bool equals(
const Node &rhs)
const override;
422 bool operator==(
const Node &rhs)
const override;
428 ::tree::cbor::MapWriter &map,
429 const ::tree::base::PointerMap &ids
435 static std::shared_ptr<Axis>
deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
453 void find_reachable(::tree::base::PointerMap &map)
const override;
458 void check_complete(const ::tree::base::PointerMap &map)
const override;
470 void visit_internal(
VisitorBase &visitor,
void *retval)
override;
478 Bool *as_bool()
override;
484 const Bool *as_bool()
const override;
499 bool equals(
const Node &rhs)
const override;
504 bool operator==(
const Node &rhs)
const override;
510 ::tree::cbor::MapWriter &map,
511 const ::tree::base::PointerMap &ids
517 static std::shared_ptr<Bool>
deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
535 void find_reachable(::tree::base::PointerMap &map)
const override;
540 void check_complete(const ::tree::base::PointerMap &map)
const override;
552 void visit_internal(
VisitorBase &visitor,
void *retval)
override;
560 Complex *as_complex()
override;
566 const Complex *as_complex()
const override;
581 bool equals(
const Node &rhs)
const override;
586 bool operator==(
const Node &rhs)
const override;
592 ::tree::cbor::MapWriter &map,
593 const ::tree::base::PointerMap &ids
599 static std::shared_ptr<Complex>
deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
629 void find_reachable(::tree::base::PointerMap &map)
const override;
634 void check_complete(const ::tree::base::PointerMap &map)
const override;
646 void visit_internal(
VisitorBase &visitor,
void *retval)
override;
675 bool equals(
const Node &rhs)
const override;
680 bool operator==(
const Node &rhs)
const override;
686 ::tree::cbor::MapWriter &map,
687 const ::tree::base::PointerMap &ids
693 static std::shared_ptr<ComplexMatrix>
deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
711 void find_reachable(::tree::base::PointerMap &map)
const override;
716 void check_complete(const ::tree::base::PointerMap &map)
const override;
728 void visit_internal(
VisitorBase &visitor,
void *retval)
override;
736 Int *as_int()
override;
742 const Int *as_int()
const override;
757 bool equals(
const Node &rhs)
const override;
762 bool operator==(
const Node &rhs)
const override;
768 ::tree::cbor::MapWriter &map,
769 const ::tree::base::PointerMap &ids
775 static std::shared_ptr<Int>
deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
793 void find_reachable(::tree::base::PointerMap &map)
const override;
798 void check_complete(const ::tree::base::PointerMap &map)
const override;
810 void visit_internal(
VisitorBase &visitor,
void *retval)
override;
818 Json *as_json()
override;
824 const Json *as_json()
const override;
839 bool equals(
const Node &rhs)
const override;
844 bool operator==(
const Node &rhs)
const override;
850 ::tree::cbor::MapWriter &map,
851 const ::tree::base::PointerMap &ids
857 static std::shared_ptr<Json>
deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
875 void find_reachable(::tree::base::PointerMap &map)
const override;
880 void check_complete(const ::tree::base::PointerMap &map)
const override;
892 void visit_internal(
VisitorBase &visitor,
void *retval)
override;
900 Qubit *as_qubit()
override;
906 const Qubit *as_qubit()
const override;
921 bool equals(
const Node &rhs)
const override;
926 bool operator==(
const Node &rhs)
const override;
932 ::tree::cbor::MapWriter &map,
933 const ::tree::base::PointerMap &ids
939 static std::shared_ptr<Qubit>
deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
957 void find_reachable(::tree::base::PointerMap &map)
const override;
962 void check_complete(const ::tree::base::PointerMap &map)
const override;
974 void visit_internal(
VisitorBase &visitor,
void *retval)
override;
982 Real *as_real()
override;
988 const Real *as_real()
const override;
1003 bool equals(
const Node &rhs)
const override;
1008 bool operator==(
const Node &rhs)
const override;
1014 ::tree::cbor::MapWriter &map,
1015 const ::tree::base::PointerMap &ids
1021 static std::shared_ptr<Real>
deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
1051 void find_reachable(::tree::base::PointerMap &map)
const override;
1056 void check_complete(const ::tree::base::PointerMap &map)
const override;
1068 void visit_internal(
VisitorBase &visitor,
void *retval)
override;
1082 const RealMatrix *as_real_matrix()
const override;
1097 bool equals(
const Node &rhs)
const override;
1102 bool operator==(
const Node &rhs)
const override;
1108 ::tree::cbor::MapWriter &map,
1109 const ::tree::base::PointerMap &ids
1115 static std::shared_ptr<RealMatrix>
deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
1133 void find_reachable(::tree::base::PointerMap &map)
const override;
1138 void check_complete(const ::tree::base::PointerMap &map)
const override;
1150 void visit_internal(
VisitorBase &visitor,
void *retval)
override;
1158 String *as_string()
override;
1164 const String *as_string()
const override;
1179 bool equals(
const Node &rhs)
const override;
1184 bool operator==(
const Node &rhs)
const override;
1190 ::tree::cbor::MapWriter &map,
1191 const ::tree::base::PointerMap &ids
1197 static std::shared_ptr<String>
deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids);
1224 friend class String;
1230 virtual void raw_visit_node(
Node &node,
void *retval) = 0;
1235 virtual void raw_visit_axis(
Axis &node,
void *retval) = 0;
1240 virtual void raw_visit_bool(
Bool &node,
void *retval) = 0;
1245 virtual void raw_visit_complex(
Complex &node,
void *retval) = 0;
1250 virtual void raw_visit_complex_matrix(
ComplexMatrix &node,
void *retval) = 0;
1255 virtual void raw_visit_int(
Int &node,
void *retval) = 0;
1260 virtual void raw_visit_json(
Json &node,
void *retval) = 0;
1265 virtual void raw_visit_qubit(
Qubit &node,
void *retval) = 0;
1270 virtual void raw_visit_real(
Real &node,
void *retval) = 0;
1275 virtual void raw_visit_real_matrix(
RealMatrix &node,
void *retval) = 0;
1280 virtual void raw_visit_string(String &node,
void *retval) = 0;
1285 virtual void raw_visit_type_base(
TypeBase &node,
void *retval) = 0;
1299 template <
typename T>
1306 void raw_visit_node(
Node &node,
void *retval)
override;
1311 void raw_visit_axis(
Axis &node,
void *retval)
override;
1316 void raw_visit_bool(
Bool &node,
void *retval)
override;
1321 void raw_visit_complex(
Complex &node,
void *retval)
override;
1326 void raw_visit_complex_matrix(
ComplexMatrix &node,
void *retval)
override;
1331 void raw_visit_int(
Int &node,
void *retval)
override;
1336 void raw_visit_json(
Json &node,
void *retval)
override;
1341 void raw_visit_qubit(
Qubit &node,
void *retval)
override;
1346 void raw_visit_real(
Real &node,
void *retval)
override;
1351 void raw_visit_real_matrix(
RealMatrix &node,
void *retval)
override;
1356 void raw_visit_string(String &node,
void *retval)
override;
1361 void raw_visit_type_base(
TypeBase &node,
void *retval)
override;
1368 virtual T visit_node(
Node &node) = 0;
1374 return visit_type_base(node);
1381 return visit_type_base(node);
1388 return visit_type_base(node);
1395 return visit_type_base(node);
1402 return visit_type_base(node);
1409 return visit_type_base(node);
1416 return visit_type_base(node);
1423 return visit_type_base(node);
1430 return visit_type_base(node);
1437 return visit_type_base(node);
1444 return visit_node(node);
1452 template <
typename T>
1454 if (retval ==
nullptr) {
1455 this->visit_node(node);
1457 *((T*)retval) = this->visit_node(node);
1470 template <
typename T>
1472 if (retval ==
nullptr) {
1473 this->visit_axis(node);
1475 *((T*)retval) = this->visit_axis(node);
1488 template <
typename T>
1490 if (retval ==
nullptr) {
1491 this->visit_bool(node);
1493 *((T*)retval) = this->visit_bool(node);
1506 template <
typename T>
1508 if (retval ==
nullptr) {
1509 this->visit_complex(node);
1511 *((T*)retval) = this->visit_complex(node);
1524 template <
typename T>
1526 if (retval ==
nullptr) {
1527 this->visit_complex_matrix(node);
1529 *((T*)retval) = this->visit_complex_matrix(node);
1542 template <
typename T>
1544 if (retval ==
nullptr) {
1545 this->visit_int(node);
1547 *((T*)retval) = this->visit_int(node);
1560 template <
typename T>
1562 if (retval ==
nullptr) {
1563 this->visit_json(node);
1565 *((T*)retval) = this->visit_json(node);
1578 template <
typename T>
1580 if (retval ==
nullptr) {
1581 this->visit_qubit(node);
1583 *((T*)retval) = this->visit_qubit(node);
1596 template <
typename T>
1598 if (retval ==
nullptr) {
1599 this->visit_real(node);
1601 *((T*)retval) = this->visit_real(node);
1614 template <
typename T>
1616 if (retval ==
nullptr) {
1617 this->visit_real_matrix(node);
1619 *((T*)retval) = this->visit_real_matrix(node);
1632 template <
typename T>
1634 if (retval ==
nullptr) {
1635 this->visit_string(node);
1637 *((T*)retval) = this->visit_string(node);
1650 template <
typename T>
1652 if (retval ==
nullptr) {
1653 this->visit_type_base(node);
1655 *((T*)retval) = this->visit_type_base(node);
1678 void visit_axis(
Axis &node)
override;
1683 void visit_bool(
Bool &node)
override;
1688 void visit_complex(
Complex &node)
override;
1698 void visit_int(
Int &node)
override;
1703 void visit_json(
Json &node)
override;
1708 void visit_qubit(
Qubit &node)
override;
1713 void visit_real(
Real &node)
override;
1718 void visit_real_matrix(
RealMatrix &node)
override;
1723 void visit_string(String &node)
override;
1728 void visit_type_base(
TypeBase &node)
override;
1751 ::tree::base::PointerMap *
ids;
1755 bool in_link =
false;
1760 void write_indent();
1767 Dumper(std::ostream &out,
int indent=0, ::tree::base::PointerMap *ids =
nullptr) : out(out), indent(indent), ids(ids) {};
1772 void visit_node(
Node &node)
override;
1776 void visit_axis(
Axis &node)
override;
1781 void visit_bool(
Bool &node)
override;
1786 void visit_complex(
Complex &node)
override;
1796 void visit_int(
Int &node)
override;
1801 void visit_json(
Json &node)
override;
1806 void visit_qubit(
Qubit &node)
override;
1811 void visit_real(
Real &node)
override;
1816 void visit_real_matrix(
RealMatrix &node)
override;
1821 void visit_string(String &node)
override;
1826 void visit_type_base(
TypeBase &node)
override;
1833 template <
typename T>
1836 this->visit_internal(visitor, &retval);
void raw_visit_json(Json &node, void *retval) override
Internal visitor function for Json nodes.
cqasm::tree::Maybe< T > Maybe
Type of an integer (signed 64-bit).
::tree::base::Maybe< T > Maybe
Type of a real number (IEEE double).
::tree::base::Link< T > Link
cqasm::tree::Many< T > Many
cqasm::tree::OptLink< T > OptLink
::tree::base::OptLink< T > OptLink
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.
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
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'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
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
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.
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
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.