17 auto dumper =
Dumper(out, indent);
26 ::tree::base::PointerMap ids;
27 ids.enable_exceptions =
false;
30 auto dumper =
Dumper(out, indent, &ids);
214 const ::tree::cbor::MapReader &map,
215 ::tree::base::IdentifierMap &ids
217 auto type = map.at(
"@t").as_string();
228 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
235 : assignable(assignable)
243 return dynamic_cast<TypeBase*
>(
this);
251 return dynamic_cast<const TypeBase*
>(
this);
257 std::shared_ptr<TypeBase>
TypeBase::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
258 auto type = map.at(
"@t").as_string();
269 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
312 return dynamic_cast<Axis*
>(
this);
320 return dynamic_cast<const Axis*
>(
this);
327 return cqasm::tree::make<Axis>(*this);
334 auto node = cqasm::tree::make<Axis>(*this);
343 auto rhsc =
dynamic_cast<const Axis&
>(rhs);
344 if (this->
assignable != rhsc.assignable)
return false;
353 auto rhsc =
dynamic_cast<const Axis&
>(rhs);
354 if (this->
assignable != rhsc.assignable)
return false;
362 ::tree::cbor::MapWriter &map,
363 const ::tree::base::PointerMap &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);
370 serialize_annotations(map);
376 std::shared_ptr<Axis>
Axis::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &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);
382 auto node = std::make_shared<Axis>(
383 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at(
"assignable").as_map())
385 node->deserialize_annotations(map);
429 return dynamic_cast<Bool*
>(
this);
437 return dynamic_cast<const Bool*
>(
this);
444 return cqasm::tree::make<Bool>(*this);
451 auto node = cqasm::tree::make<Bool>(*this);
460 auto rhsc =
dynamic_cast<const Bool&
>(rhs);
461 if (this->
assignable != rhsc.assignable)
return false;
470 auto rhsc =
dynamic_cast<const Bool&
>(rhs);
471 if (this->
assignable != rhsc.assignable)
return false;
479 ::tree::cbor::MapWriter &map,
480 const ::tree::base::PointerMap &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);
487 serialize_annotations(map);
493 std::shared_ptr<Bool>
Bool::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &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);
499 auto node = std::make_shared<Bool>(
500 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at(
"assignable").as_map())
502 node->deserialize_annotations(map);
546 return dynamic_cast<Complex*
>(
this);
554 return dynamic_cast<const Complex*
>(
this);
561 return cqasm::tree::make<Complex>(*this);
568 auto node = cqasm::tree::make<Complex>(*this);
577 auto rhsc =
dynamic_cast<const Complex&
>(rhs);
578 if (this->
assignable != rhsc.assignable)
return false;
587 auto rhsc =
dynamic_cast<const Complex&
>(rhs);
588 if (this->
assignable != rhsc.assignable)
return false;
596 ::tree::cbor::MapWriter &map,
597 const ::tree::base::PointerMap &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);
604 serialize_annotations(map);
610 std::shared_ptr<Complex>
Complex::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &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);
616 auto node = std::make_shared<Complex>(
617 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at(
"assignable").as_map())
619 node->deserialize_annotations(map);
627 :
TypeBase(assignable), num_rows(num_rows), num_cols(num_cols)
678 return cqasm::tree::make<ComplexMatrix>(*this);
685 auto node = cqasm::tree::make<ComplexMatrix>(*this);
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;
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;
717 ::tree::cbor::MapWriter &map,
718 const ::tree::base::PointerMap &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);
725 submap = map.append_map(
"num_cols");
726 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(
num_cols, submap);
728 submap = map.append_map(
"assignable");
729 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(
assignable, submap);
731 serialize_annotations(map);
739 auto type = map.at(
"@t").as_string();
740 if (
type !=
"ComplexMatrix") {
741 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
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())
748 node->deserialize_annotations(map);
792 return dynamic_cast<Int*
>(
this);
800 return dynamic_cast<const Int*
>(
this);
807 return cqasm::tree::make<Int>(*this);
814 auto node = cqasm::tree::make<Int>(*this);
823 auto rhsc =
dynamic_cast<const Int&
>(rhs);
824 if (this->
assignable != rhsc.assignable)
return false;
833 auto rhsc =
dynamic_cast<const Int&
>(rhs);
834 if (this->
assignable != rhsc.assignable)
return false;
842 ::tree::cbor::MapWriter &map,
843 const ::tree::base::PointerMap &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);
850 serialize_annotations(map);
856 std::shared_ptr<Int>
Int::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
858 auto type = map.at(
"@t").as_string();
860 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
862 auto node = std::make_shared<Int>(
863 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at(
"assignable").as_map())
865 node->deserialize_annotations(map);
909 return dynamic_cast<Json*
>(
this);
917 return dynamic_cast<const Json*
>(
this);
924 return cqasm::tree::make<Json>(*this);
931 auto node = cqasm::tree::make<Json>(*this);
940 auto rhsc =
dynamic_cast<const Json&
>(rhs);
941 if (this->
assignable != rhsc.assignable)
return false;
950 auto rhsc =
dynamic_cast<const Json&
>(rhs);
951 if (this->
assignable != rhsc.assignable)
return false;
959 ::tree::cbor::MapWriter &map,
960 const ::tree::base::PointerMap &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);
967 serialize_annotations(map);
973 std::shared_ptr<Json>
Json::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &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);
979 auto node = std::make_shared<Json>(
980 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at(
"assignable").as_map())
982 node->deserialize_annotations(map);
1026 return dynamic_cast<Qubit*
>(
this);
1034 return dynamic_cast<const Qubit*
>(
this);
1041 return cqasm::tree::make<Qubit>(*this);
1048 auto node = cqasm::tree::make<Qubit>(*this);
1057 auto rhsc =
dynamic_cast<const Qubit&
>(rhs);
1058 if (this->
assignable != rhsc.assignable)
return false;
1067 auto rhsc =
dynamic_cast<const Qubit&
>(rhs);
1068 if (this->
assignable != rhsc.assignable)
return false;
1076 ::tree::cbor::MapWriter &map,
1077 const ::tree::base::PointerMap &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);
1084 serialize_annotations(map);
1090 std::shared_ptr<Qubit>
Qubit::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &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);
1096 auto node = std::make_shared<Qubit>(
1097 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at(
"assignable").as_map())
1099 node->deserialize_annotations(map);
1143 return dynamic_cast<Real*
>(
this);
1151 return dynamic_cast<const Real*
>(
this);
1158 return cqasm::tree::make<Real>(*this);
1165 auto node = cqasm::tree::make<Real>(*this);
1174 auto rhsc =
dynamic_cast<const Real&
>(rhs);
1175 if (this->
assignable != rhsc.assignable)
return false;
1184 auto rhsc =
dynamic_cast<const Real&
>(rhs);
1185 if (this->
assignable != rhsc.assignable)
return false;
1193 ::tree::cbor::MapWriter &map,
1194 const ::tree::base::PointerMap &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);
1201 serialize_annotations(map);
1207 std::shared_ptr<Real>
Real::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &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);
1213 auto node = std::make_shared<Real>(
1214 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at(
"assignable").as_map())
1216 node->deserialize_annotations(map);
1224 :
TypeBase(assignable), num_rows(num_rows), num_cols(num_cols)
1268 return dynamic_cast<const RealMatrix*
>(
this);
1275 return cqasm::tree::make<RealMatrix>(*this);
1282 auto node = cqasm::tree::make<RealMatrix>(*this);
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;
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;
1314 ::tree::cbor::MapWriter &map,
1315 const ::tree::base::PointerMap &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);
1322 submap = map.append_map(
"num_cols");
1323 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(
num_cols, submap);
1325 submap = map.append_map(
"assignable");
1326 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Bool>(
assignable, submap);
1328 serialize_annotations(map);
1336 auto type = map.at(
"@t").as_string();
1337 if (
type !=
"RealMatrix") {
1338 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
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())
1345 node->deserialize_annotations(map);
1389 return dynamic_cast<String*
>(
this);
1397 return dynamic_cast<const String*
>(
this);
1404 return cqasm::tree::make<String>(*this);
1411 auto node = cqasm::tree::make<String>(*this);
1420 auto rhsc =
dynamic_cast<const String&
>(rhs);
1421 if (this->
assignable != rhsc.assignable)
return false;
1430 auto rhsc =
dynamic_cast<const String&
>(rhs);
1431 if (this->
assignable != rhsc.assignable)
return false;
1439 ::tree::cbor::MapWriter &map,
1440 const ::tree::base::PointerMap &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);
1447 serialize_annotations(map);
1453 std::shared_ptr<String>
String::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &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);
1459 auto node = std::make_shared<String>(
1460 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Bool>(map.at(
"assignable").as_map())
1462 node->deserialize_annotations(map);
1472 this->visit_node(node);
1481 this->visit_axis(node);
1490 this->visit_bool(node);
1499 this->visit_complex(node);
1508 this->visit_complex_matrix(node);
1517 this->visit_int(node);
1526 this->visit_json(node);
1535 this->visit_qubit(node);
1544 this->visit_real(node);
1553 this->visit_real_matrix(node);
1562 this->visit_string(node);
1571 this->visit_type_base(node);
1578 visit_type_base(node);
1585 visit_type_base(node);
1592 visit_type_base(node);
1599 visit_type_base(node);
1606 visit_type_base(node);
1613 visit_type_base(node);
1620 visit_type_base(node);
1627 visit_type_base(node);
1634 visit_type_base(node);
1641 visit_type_base(node);
1655 for (
int i = 0; i < indent; i++) {
1666 out <<
"!Node()" << std::endl;
1675 if (ids !=
nullptr) {
1676 out <<
"@" << ids->get_ref(node);
1682 out <<
"assignable: ";
1683 std::stringstream ss;
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));
1690 if (ss.str().find(
'\n') == std::string::npos) {
1691 out << ss.str() << std::endl;
1693 out <<
"cqasm::v1::primitives::Bool<<" << std::endl;
1697 std::getline(ss, s);
1699 out << s << std::endl;
1703 out <<
">>" << std::endl;
1707 out <<
")" << std::endl;
1716 if (ids !=
nullptr) {
1717 out <<
"@" << ids->get_ref(node);
1723 out <<
"assignable: ";
1724 std::stringstream ss;
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));
1731 if (ss.str().find(
'\n') == std::string::npos) {
1732 out << ss.str() << std::endl;
1734 out <<
"cqasm::v1::primitives::Bool<<" << std::endl;
1738 std::getline(ss, s);
1740 out << s << std::endl;
1744 out <<
">>" << std::endl;
1748 out <<
")" << std::endl;
1757 if (ids !=
nullptr) {
1758 out <<
"@" << ids->get_ref(node);
1764 out <<
"assignable: ";
1765 std::stringstream ss;
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));
1772 if (ss.str().find(
'\n') == std::string::npos) {
1773 out << ss.str() << std::endl;
1775 out <<
"cqasm::v1::primitives::Bool<<" << std::endl;
1779 std::getline(ss, s);
1781 out << s << std::endl;
1785 out <<
">>" << std::endl;
1789 out <<
")" << std::endl;
1797 out <<
"ComplexMatrix";
1798 if (ids !=
nullptr) {
1799 out <<
"@" << ids->get_ref(node);
1805 out <<
"num_rows: ";
1806 std::stringstream ss;
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));
1813 if (ss.str().find(
'\n') == std::string::npos) {
1814 out << ss.str() << std::endl;
1816 out <<
"cqasm::v1::primitives::Int<<" << std::endl;
1820 std::getline(ss, s);
1822 out << s << std::endl;
1826 out <<
">>" << std::endl;
1829 out <<
"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));
1837 if (ss.str().find(
'\n') == std::string::npos) {
1838 out << ss.str() << std::endl;
1840 out <<
"cqasm::v1::primitives::Int<<" << std::endl;
1844 std::getline(ss, s);
1846 out << s << std::endl;
1850 out <<
">>" << std::endl;
1853 out <<
"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));
1861 if (ss.str().find(
'\n') == std::string::npos) {
1862 out << ss.str() << std::endl;
1864 out <<
"cqasm::v1::primitives::Bool<<" << std::endl;
1868 std::getline(ss, s);
1870 out << s << std::endl;
1874 out <<
">>" << std::endl;
1878 out <<
")" << std::endl;
1887 if (ids !=
nullptr) {
1888 out <<
"@" << ids->get_ref(node);
1894 out <<
"assignable: ";
1895 std::stringstream ss;
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));
1902 if (ss.str().find(
'\n') == std::string::npos) {
1903 out << ss.str() << std::endl;
1905 out <<
"cqasm::v1::primitives::Bool<<" << std::endl;
1909 std::getline(ss, s);
1911 out << s << std::endl;
1915 out <<
">>" << std::endl;
1919 out <<
")" << std::endl;
1928 if (ids !=
nullptr) {
1929 out <<
"@" << ids->get_ref(node);
1935 out <<
"assignable: ";
1936 std::stringstream ss;
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));
1943 if (ss.str().find(
'\n') == std::string::npos) {
1944 out << ss.str() << std::endl;
1946 out <<
"cqasm::v1::primitives::Bool<<" << std::endl;
1950 std::getline(ss, s);
1952 out << s << std::endl;
1956 out <<
">>" << std::endl;
1960 out <<
")" << std::endl;
1969 if (ids !=
nullptr) {
1970 out <<
"@" << ids->get_ref(node);
1976 out <<
"assignable: ";
1977 std::stringstream ss;
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));
1984 if (ss.str().find(
'\n') == std::string::npos) {
1985 out << ss.str() << std::endl;
1987 out <<
"cqasm::v1::primitives::Bool<<" << std::endl;
1991 std::getline(ss, s);
1993 out << s << std::endl;
1997 out <<
">>" << std::endl;
2001 out <<
")" << std::endl;
2010 if (ids !=
nullptr) {
2011 out <<
"@" << ids->get_ref(node);
2017 out <<
"assignable: ";
2018 std::stringstream ss;
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));
2025 if (ss.str().find(
'\n') == std::string::npos) {
2026 out << ss.str() << std::endl;
2028 out <<
"cqasm::v1::primitives::Bool<<" << std::endl;
2032 std::getline(ss, s);
2034 out << s << std::endl;
2038 out <<
">>" << std::endl;
2042 out <<
")" << std::endl;
2050 out <<
"RealMatrix";
2051 if (ids !=
nullptr) {
2052 out <<
"@" << ids->get_ref(node);
2058 out <<
"num_rows: ";
2059 std::stringstream ss;
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));
2066 if (ss.str().find(
'\n') == std::string::npos) {
2067 out << ss.str() << std::endl;
2069 out <<
"cqasm::v1::primitives::Int<<" << std::endl;
2073 std::getline(ss, s);
2075 out << s << std::endl;
2079 out <<
">>" << std::endl;
2082 out <<
"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));
2090 if (ss.str().find(
'\n') == std::string::npos) {
2091 out << ss.str() << std::endl;
2093 out <<
"cqasm::v1::primitives::Int<<" << std::endl;
2097 std::getline(ss, s);
2099 out << s << std::endl;
2103 out <<
">>" << std::endl;
2106 out <<
"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));
2114 if (ss.str().find(
'\n') == std::string::npos) {
2115 out << ss.str() << std::endl;
2117 out <<
"cqasm::v1::primitives::Bool<<" << std::endl;
2121 std::getline(ss, s);
2123 out << s << std::endl;
2127 out <<
">>" << std::endl;
2131 out <<
")" << std::endl;
2140 if (ids !=
nullptr) {
2141 out <<
"@" << ids->get_ref(node);
2147 out <<
"assignable: ";
2148 std::stringstream ss;
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));
2155 if (ss.str().find(
'\n') == std::string::npos) {
2156 out << ss.str() << std::endl;
2158 out <<
"cqasm::v1::primitives::Bool<<" << std::endl;
2162 std::getline(ss, s);
2164 out << s << std::endl;
2168 out <<
">>" << std::endl;
2172 out <<
")" << std::endl;
2181 if (ids !=
nullptr) {
2182 out <<
"@" << ids->get_ref(node);
2188 out <<
"assignable: ";
2189 std::stringstream ss;
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));
2196 if (ss.str().find(
'\n') == std::string::npos) {
2197 out << ss.str() << std::endl;
2199 out <<
"cqasm::v1::primitives::Bool<<" << std::endl;
2203 std::getline(ss, s);
2205 out << s << std::endl;
2209 out <<
">>" << std::endl;
2213 out <<
")" << std::endl;
2228 const_cast<Node&
>(object).
dump(os);
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.
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'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.
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.