16 auto dumper =
Dumper(out, indent);
25 ::tree::base::PointerMap ids;
26 ids.enable_exceptions =
false;
29 auto dumper =
Dumper(out, indent, &ids);
437 const ::tree::cbor::MapReader &map,
438 ::tree::base::IdentifierMap &ids
440 auto type = map.at(
"@t").as_string();
462 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
469 : annotations(annotations)
485 return dynamic_cast<const Annotated*
>(
this);
491 std::shared_ptr<Annotated>
Annotated::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
492 auto type = map.at(
"@t").as_string();
509 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
516 : interface(interface), operation(operation), operands(operands)
569 return cqasm::tree::make<AnnotationData>(*this);
576 auto node = cqasm::tree::make<AnnotationData>(*this);
577 node->operands = this->
operands.clone();
587 if (this->
interface != rhsc.interface)
return false;
588 if (this->
operation != rhsc.operation)
return false;
589 if (!this->
operands.equals(rhsc.operands))
return false;
599 if (this->
interface != rhsc.interface)
return false;
600 if (this->
operation != rhsc.operation)
return false;
601 if (this->
operands != rhsc.operands)
return false;
609 ::tree::cbor::MapWriter &map,
610 const ::tree::base::PointerMap &ids
613 map.append_string(
"@t",
"AnnotationData");
614 auto submap = map.append_map(
"interface");
615 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(
interface, submap);
617 submap = map.append_map(
"operation");
618 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(
operation, submap);
620 submap = map.append_map(
"operands");
623 serialize_annotations(map);
631 auto type = map.at(
"@t").as_string();
632 if (
type !=
"AnnotationData") {
633 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
635 auto node = std::make_shared<AnnotationData>(
636 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at(
"interface").as_map()),
637 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at(
"operation").as_map()),
640 node->deserialize_annotations(map);
648 : statements(statements)
686 return dynamic_cast<Block*
>(
this);
694 return dynamic_cast<const Block*
>(
this);
701 return cqasm::tree::make<Block>(*this);
708 auto node = cqasm::tree::make<Block>(*this);
718 auto rhsc =
dynamic_cast<const Block&
>(rhs);
719 if (!this->
statements.equals(rhsc.statements))
return false;
728 auto rhsc =
dynamic_cast<const Block&
>(rhs);
729 if (this->
statements != rhsc.statements)
return false;
737 ::tree::cbor::MapWriter &map,
738 const ::tree::base::PointerMap &ids
741 map.append_string(
"@t",
"Block");
742 auto submap = map.append_map(
"statements");
745 serialize_annotations(map);
751 std::shared_ptr<Block>
Block::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
753 auto type = map.at(
"@t").as_string();
754 if (
type !=
"Block") {
755 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
757 auto node = std::make_shared<Block>(
760 node->deserialize_annotations(map);
784 return dynamic_cast<const Statement*
>(
this);
790 std::shared_ptr<Statement>
Statement::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
791 auto type = map.at(
"@t").as_string();
800 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
830 auto type = map.at(
"@t").as_string();
838 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
898 return cqasm::tree::make<BreakStatement>(*this);
905 auto node = cqasm::tree::make<BreakStatement>(*this);
916 if (!this->
annotations.equals(rhsc.annotations))
return false;
926 if (this->
annotations != rhsc.annotations)
return false;
934 ::tree::cbor::MapWriter &map,
935 const ::tree::base::PointerMap &ids
938 map.append_string(
"@t",
"BreakStatement");
939 auto submap = map.append_map(
"annotations");
942 serialize_annotations(map);
950 auto type = map.at(
"@t").as_string();
951 if (
type !=
"BreakStatement") {
952 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
954 auto node = std::make_shared<BreakStatement>(
957 node->deserialize_annotations(map);
973 items.find_reachable(map);
982 items.check_complete(map);
1005 return dynamic_cast<Bundle*
>(
this);
1013 return dynamic_cast<const Bundle*
>(
this);
1020 return cqasm::tree::make<Bundle>(*this);
1027 auto node = cqasm::tree::make<Bundle>(*this);
1028 node->items = this->
items.clone();
1038 auto rhsc =
dynamic_cast<const Bundle&
>(rhs);
1039 if (!this->
items.equals(rhsc.items))
return false;
1040 if (!this->
annotations.equals(rhsc.annotations))
return false;
1049 auto rhsc =
dynamic_cast<const Bundle&
>(rhs);
1050 if (this->
items != rhsc.items)
return false;
1051 if (this->
annotations != rhsc.annotations)
return false;
1059 ::tree::cbor::MapWriter &map,
1060 const ::tree::base::PointerMap &ids
1063 map.append_string(
"@t",
"Bundle");
1064 auto submap = map.append_map(
"items");
1065 items.serialize(submap, ids);
1067 submap = map.append_map(
"annotations");
1070 serialize_annotations(map);
1076 std::shared_ptr<Bundle>
Bundle::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1078 auto type = map.at(
"@t").as_string();
1079 if (
type !=
"Bundle") {
1080 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
1082 auto node = std::make_shared<Bundle>(
1086 node->deserialize_annotations(map);
1102 items.find_reachable(map);
1111 items.check_complete(map);
1142 return dynamic_cast<const BundleExt*
>(
this);
1149 return cqasm::tree::make<BundleExt>(*this);
1156 auto node = cqasm::tree::make<BundleExt>(*this);
1157 node->items = this->
items.clone();
1167 auto rhsc =
dynamic_cast<const BundleExt&
>(rhs);
1168 if (!this->
items.equals(rhsc.items))
return false;
1169 if (!this->
annotations.equals(rhsc.annotations))
return false;
1178 auto rhsc =
dynamic_cast<const BundleExt&
>(rhs);
1179 if (this->
items != rhsc.items)
return false;
1180 if (this->
annotations != rhsc.annotations)
return false;
1188 ::tree::cbor::MapWriter &map,
1189 const ::tree::base::PointerMap &ids
1192 map.append_string(
"@t",
"BundleExt");
1193 auto submap = map.append_map(
"items");
1194 items.serialize(submap, ids);
1196 submap = map.append_map(
"annotations");
1199 serialize_annotations(map);
1207 auto type = map.at(
"@t").as_string();
1208 if (
type !=
"BundleExt") {
1209 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
1211 auto node = std::make_shared<BundleExt>(
1215 node->deserialize_annotations(map);
1276 return cqasm::tree::make<ContinueStatement>(*this);
1283 auto node = cqasm::tree::make<ContinueStatement>(*this);
1294 if (!this->
annotations.equals(rhsc.annotations))
return false;
1304 if (this->
annotations != rhsc.annotations)
return false;
1312 ::tree::cbor::MapWriter &map,
1313 const ::tree::base::PointerMap &ids
1316 map.append_string(
"@t",
"ContinueStatement");
1317 auto submap = map.append_map(
"annotations");
1320 serialize_annotations(map);
1328 auto type = map.at(
"@t").as_string();
1329 if (
type !=
"ContinueStatement") {
1330 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
1332 auto node = std::make_shared<ContinueStatement>(
1335 node->deserialize_annotations(map);
1343 :
Annotated(annotations), model(model), name(name), parameters(parameters)
1391 return dynamic_cast<const ErrorModel*
>(
this);
1398 return cqasm::tree::make<ErrorModel>(*this);
1405 auto node = cqasm::tree::make<ErrorModel>(*this);
1416 auto rhsc =
dynamic_cast<const ErrorModel&
>(rhs);
1417 if (this->
model != rhsc.model)
return false;
1418 if (this->
name != rhsc.name)
return false;
1419 if (!this->
parameters.equals(rhsc.parameters))
return false;
1420 if (!this->
annotations.equals(rhsc.annotations))
return false;
1429 auto rhsc =
dynamic_cast<const ErrorModel&
>(rhs);
1430 if (this->
model != rhsc.model)
return false;
1431 if (this->
name != rhsc.name)
return false;
1432 if (this->
parameters != rhsc.parameters)
return false;
1433 if (this->
annotations != rhsc.annotations)
return false;
1441 ::tree::cbor::MapWriter &map,
1442 const ::tree::base::PointerMap &ids
1445 map.append_string(
"@t",
"ErrorModel");
1446 auto submap = map.append_map(
"model");
1447 cqasm::v1::primitives::serialize<cqasm::v1::error_model::ErrorModelRef>(
model, submap);
1449 submap = map.append_map(
"name");
1450 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(
name, submap);
1452 submap = map.append_map(
"parameters");
1455 submap = map.append_map(
"annotations");
1458 serialize_annotations(map);
1466 auto type = map.at(
"@t").as_string();
1467 if (
type !=
"ErrorModel") {
1468 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
1470 auto node = std::make_shared<ErrorModel>(
1471 cqasm::v1::primitives::deserialize<cqasm::v1::error_model::ErrorModelRef>(map.at(
"model").as_map()),
1472 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at(
"name").as_map()),
1476 node->deserialize_annotations(map);
1484 :
Structured(annotations), initialize(initialize), condition(condition), update(update), body(body)
1494 update.find_reachable(map);
1495 body.find_reachable(map);
1506 update.check_complete(map);
1507 body.check_complete(map);
1530 return dynamic_cast<ForLoop*
>(
this);
1538 return dynamic_cast<const ForLoop*
>(
this);
1545 return cqasm::tree::make<ForLoop>(*this);
1552 auto node = cqasm::tree::make<ForLoop>(*this);
1554 node->condition = this->
condition.clone();
1555 node->update = this->
update.clone();
1556 node->body = this->
body.clone();
1566 auto rhsc =
dynamic_cast<const ForLoop&
>(rhs);
1567 if (!this->
initialize.equals(rhsc.initialize))
return false;
1568 if (!this->
condition.equals(rhsc.condition))
return false;
1569 if (!this->
update.equals(rhsc.update))
return false;
1570 if (!this->
body.equals(rhsc.body))
return false;
1571 if (!this->
annotations.equals(rhsc.annotations))
return false;
1580 auto rhsc =
dynamic_cast<const ForLoop&
>(rhs);
1581 if (this->
initialize != rhsc.initialize)
return false;
1582 if (this->
condition != rhsc.condition)
return false;
1583 if (this->
update != rhsc.update)
return false;
1584 if (this->
body != rhsc.body)
return false;
1585 if (this->
annotations != rhsc.annotations)
return false;
1593 ::tree::cbor::MapWriter &map,
1594 const ::tree::base::PointerMap &ids
1597 map.append_string(
"@t",
"ForLoop");
1598 auto submap = map.append_map(
"initialize");
1601 submap = map.append_map(
"condition");
1604 submap = map.append_map(
"update");
1605 update.serialize(submap, ids);
1607 submap = map.append_map(
"body");
1608 body.serialize(submap, ids);
1610 submap = map.append_map(
"annotations");
1613 serialize_annotations(map);
1619 std::shared_ptr<ForLoop>
ForLoop::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
1621 auto type = map.at(
"@t").as_string();
1622 if (
type !=
"ForLoop") {
1623 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
1625 auto node = std::make_shared<ForLoop>(
1632 node->deserialize_annotations(map);
1640 :
Structured(annotations), lhs(lhs), frm(frm), to(to), body(body)
1648 lhs.find_reachable(map);
1649 body.find_reachable(map);
1658 lhs.check_complete(map);
1659 body.check_complete(map);
1697 return cqasm::tree::make<ForeachLoop>(*this);
1704 auto node = cqasm::tree::make<ForeachLoop>(*this);
1705 node->lhs = this->
lhs.clone();
1706 node->body = this->
body.clone();
1716 auto rhsc =
dynamic_cast<const ForeachLoop&
>(rhs);
1717 if (!this->
lhs.equals(rhsc.lhs))
return false;
1718 if (this->
frm != rhsc.frm)
return false;
1719 if (this->
to != rhsc.to)
return false;
1720 if (!this->
body.equals(rhsc.body))
return false;
1721 if (!this->
annotations.equals(rhsc.annotations))
return false;
1730 auto rhsc =
dynamic_cast<const ForeachLoop&
>(rhs);
1731 if (this->
lhs != rhsc.lhs)
return false;
1732 if (this->
frm != rhsc.frm)
return false;
1733 if (this->
to != rhsc.to)
return false;
1734 if (this->
body != rhsc.body)
return false;
1735 if (this->
annotations != rhsc.annotations)
return false;
1743 ::tree::cbor::MapWriter &map,
1744 const ::tree::base::PointerMap &ids
1747 map.append_string(
"@t",
"ForeachLoop");
1748 auto submap = map.append_map(
"lhs");
1749 lhs.serialize(submap, ids);
1751 submap = map.append_map(
"frm");
1752 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(
frm, submap);
1754 submap = map.append_map(
"to");
1755 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(
to, submap);
1757 submap = map.append_map(
"body");
1758 body.serialize(submap, ids);
1760 submap = map.append_map(
"annotations");
1763 serialize_annotations(map);
1771 auto type = map.at(
"@t").as_string();
1772 if (
type !=
"ForeachLoop") {
1773 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
1775 auto node = std::make_shared<ForeachLoop>(
1777 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at(
"frm").as_map()),
1778 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at(
"to").as_map()),
1782 node->deserialize_annotations(map);
1790 :
Annotated(annotations), condition(condition)
1813 auto type = map.at(
"@t").as_string();
1817 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
1832 target.find_reachable(map);
1842 target.check_complete(map);
1881 return cqasm::tree::make<GotoInstruction>(*this);
1888 auto node = cqasm::tree::make<GotoInstruction>(*this);
1889 node->condition = this->
condition.clone();
1900 if (!this->
target.equals(rhsc.target))
return false;
1901 if (!this->
condition.equals(rhsc.condition))
return false;
1902 if (!this->
annotations.equals(rhsc.annotations))
return false;
1912 if (this->
target != rhsc.target)
return false;
1913 if (this->
condition != rhsc.condition)
return false;
1914 if (this->
annotations != rhsc.annotations)
return false;
1922 ::tree::cbor::MapWriter &map,
1923 const ::tree::base::PointerMap &ids
1926 map.append_string(
"@t",
"GotoInstruction");
1927 auto submap = map.append_map(
"target");
1928 target.serialize(submap, ids);
1930 submap = map.append_map(
"condition");
1933 submap = map.append_map(
"annotations");
1936 serialize_annotations(map);
1944 auto type = map.at(
"@t").as_string();
1945 if (
type !=
"GotoInstruction") {
1946 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
1948 auto node = std::make_shared<GotoInstruction>(
1953 auto link = map.at(
"target").as_map().at(
"@l");
1954 if (!link.is_null()) {
1955 ids.register_link(node->target, link.as_int());
1957 node->deserialize_annotations(map);
1965 :
Structured(annotations), branches(branches), otherwise(otherwise)
2007 return dynamic_cast<IfElse*
>(
this);
2015 return dynamic_cast<const IfElse*
>(
this);
2022 return cqasm::tree::make<IfElse>(*this);
2029 auto node = cqasm::tree::make<IfElse>(*this);
2030 node->branches = this->
branches.clone();
2031 node->otherwise = this->
otherwise.clone();
2041 auto rhsc =
dynamic_cast<const IfElse&
>(rhs);
2042 if (!this->
branches.equals(rhsc.branches))
return false;
2043 if (!this->
otherwise.equals(rhsc.otherwise))
return false;
2044 if (!this->
annotations.equals(rhsc.annotations))
return false;
2053 auto rhsc =
dynamic_cast<const IfElse&
>(rhs);
2054 if (this->
branches != rhsc.branches)
return false;
2055 if (this->
otherwise != rhsc.otherwise)
return false;
2056 if (this->
annotations != rhsc.annotations)
return false;
2064 ::tree::cbor::MapWriter &map,
2065 const ::tree::base::PointerMap &ids
2068 map.append_string(
"@t",
"IfElse");
2069 auto submap = map.append_map(
"branches");
2072 submap = map.append_map(
"otherwise");
2075 submap = map.append_map(
"annotations");
2078 serialize_annotations(map);
2084 std::shared_ptr<IfElse>
IfElse::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
2086 auto type = map.at(
"@t").as_string();
2087 if (
type !=
"IfElse") {
2088 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
2090 auto node = std::make_shared<IfElse>(
2095 node->deserialize_annotations(map);
2103 : condition(condition), body(body)
2112 body.find_reachable(map);
2121 body.check_complete(map);
2158 return cqasm::tree::make<IfElseBranch>(*this);
2165 auto node = cqasm::tree::make<IfElseBranch>(*this);
2166 node->condition = this->
condition.clone();
2167 node->body = this->
body.clone();
2177 if (!this->
condition.equals(rhsc.condition))
return false;
2178 if (!this->
body.equals(rhsc.body))
return false;
2188 if (this->
condition != rhsc.condition)
return false;
2189 if (this->
body != rhsc.body)
return false;
2197 ::tree::cbor::MapWriter &map,
2198 const ::tree::base::PointerMap &ids
2201 map.append_string(
"@t",
"IfElseBranch");
2202 auto submap = map.append_map(
"condition");
2205 submap = map.append_map(
"body");
2206 body.serialize(submap, ids);
2208 serialize_annotations(map);
2216 auto type = map.at(
"@t").as_string();
2217 if (
type !=
"IfElseBranch") {
2218 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
2220 auto node = std::make_shared<IfElseBranch>(
2224 node->deserialize_annotations(map);
2232 :
InstructionBase(condition, annotations), instruction(instruction), name(name), operands(operands)
2289 return cqasm::tree::make<Instruction>(*this);
2296 auto node = cqasm::tree::make<Instruction>(*this);
2297 node->condition = this->
condition.clone();
2298 node->operands = this->
operands.clone();
2308 auto rhsc =
dynamic_cast<const Instruction&
>(rhs);
2309 if (this->
instruction != rhsc.instruction)
return false;
2310 if (this->
name != rhsc.name)
return false;
2311 if (!this->
condition.equals(rhsc.condition))
return false;
2312 if (!this->
operands.equals(rhsc.operands))
return false;
2313 if (!this->
annotations.equals(rhsc.annotations))
return false;
2322 auto rhsc =
dynamic_cast<const Instruction&
>(rhs);
2323 if (this->
instruction != rhsc.instruction)
return false;
2324 if (this->
name != rhsc.name)
return false;
2325 if (this->
condition != rhsc.condition)
return false;
2326 if (this->
operands != rhsc.operands)
return false;
2327 if (this->
annotations != rhsc.annotations)
return false;
2335 ::tree::cbor::MapWriter &map,
2336 const ::tree::base::PointerMap &ids
2339 map.append_string(
"@t",
"Instruction");
2340 auto submap = map.append_map(
"instruction");
2341 cqasm::v1::primitives::serialize<cqasm::v1::instruction::InstructionRef>(
instruction, submap);
2343 submap = map.append_map(
"name");
2344 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(
name, submap);
2346 submap = map.append_map(
"condition");
2349 submap = map.append_map(
"operands");
2352 submap = map.append_map(
"annotations");
2355 serialize_annotations(map);
2363 auto type = map.at(
"@t").as_string();
2364 if (
type !=
"Instruction") {
2365 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
2367 auto node = std::make_shared<Instruction>(
2368 cqasm::v1::primitives::deserialize<cqasm::v1::instruction::InstructionRef>(map.at(
"instruction").as_map()),
2369 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at(
"name").as_map()),
2374 node->deserialize_annotations(map);
2382 :
Annotated(annotations), name(name), value(value)
2390 value.find_reachable(map);
2399 value.check_complete(map);
2422 return dynamic_cast<Mapping*
>(
this);
2430 return dynamic_cast<const Mapping*
>(
this);
2437 return cqasm::tree::make<Mapping>(*this);
2444 auto node = cqasm::tree::make<Mapping>(*this);
2445 node->value = this->
value.clone();
2455 auto rhsc =
dynamic_cast<const Mapping&
>(rhs);
2456 if (this->
name != rhsc.name)
return false;
2457 if (!this->
value.equals(rhsc.value))
return false;
2458 if (!this->
annotations.equals(rhsc.annotations))
return false;
2467 auto rhsc =
dynamic_cast<const Mapping&
>(rhs);
2468 if (this->
name != rhsc.name)
return false;
2469 if (this->
value != rhsc.value)
return false;
2470 if (this->
annotations != rhsc.annotations)
return false;
2478 ::tree::cbor::MapWriter &map,
2479 const ::tree::base::PointerMap &ids
2482 map.append_string(
"@t",
"Mapping");
2483 auto submap = map.append_map(
"name");
2484 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(
name, submap);
2486 submap = map.append_map(
"value");
2487 value.serialize(submap, ids);
2489 submap = map.append_map(
"annotations");
2492 serialize_annotations(map);
2498 std::shared_ptr<Mapping>
Mapping::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
2500 auto type = map.at(
"@t").as_string();
2501 if (
type !=
"Mapping") {
2502 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
2504 auto node = std::make_shared<Mapping>(
2505 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at(
"name").as_map()),
2509 node->deserialize_annotations(map);
2517 : version(version), num_qubits(num_qubits), error_model(error_model), subcircuits(subcircuits), mappings(mappings), variables(variables), api_version(api_version)
2563 return dynamic_cast<Program*
>(
this);
2571 return dynamic_cast<const Program*
>(
this);
2578 return cqasm::tree::make<Program>(*this);
2585 auto node = cqasm::tree::make<Program>(*this);
2586 node->version = this->
version.clone();
2589 node->mappings = this->
mappings.clone();
2590 node->variables = this->
variables.clone();
2599 auto rhsc =
dynamic_cast<const Program&
>(rhs);
2600 if (!this->
version.equals(rhsc.version))
return false;
2601 if (this->
num_qubits != rhsc.num_qubits)
return false;
2602 if (!this->
error_model.equals(rhsc.error_model))
return false;
2603 if (!this->
subcircuits.equals(rhsc.subcircuits))
return false;
2604 if (!this->
mappings.equals(rhsc.mappings))
return false;
2605 if (!this->
variables.equals(rhsc.variables))
return false;
2606 if (this->
api_version != rhsc.api_version)
return false;
2615 auto rhsc =
dynamic_cast<const Program&
>(rhs);
2616 if (this->
version != rhsc.version)
return false;
2617 if (this->
num_qubits != rhsc.num_qubits)
return false;
2618 if (this->
error_model != rhsc.error_model)
return false;
2619 if (this->
subcircuits != rhsc.subcircuits)
return false;
2620 if (this->
mappings != rhsc.mappings)
return false;
2621 if (this->
variables != rhsc.variables)
return false;
2622 if (this->
api_version != rhsc.api_version)
return false;
2630 ::tree::cbor::MapWriter &map,
2631 const ::tree::base::PointerMap &ids
2634 map.append_string(
"@t",
"Program");
2635 auto submap = map.append_map(
"version");
2636 version.serialize(submap, ids);
2638 submap = map.append_map(
"num_qubits");
2639 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(
num_qubits, submap);
2641 submap = map.append_map(
"error_model");
2644 submap = map.append_map(
"subcircuits");
2647 submap = map.append_map(
"mappings");
2650 submap = map.append_map(
"variables");
2653 submap = map.append_map(
"api_version");
2654 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Version>(
api_version, submap);
2656 serialize_annotations(map);
2662 std::shared_ptr<Program>
Program::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
2664 auto type = map.at(
"@t").as_string();
2665 if (
type !=
"Program") {
2666 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
2668 auto node = std::make_shared<Program>(
2670 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at(
"num_qubits").as_map()),
2675 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Version>(map.at(
"api_version").as_map())
2677 node->deserialize_annotations(map);
2685 :
Structured(annotations), body(body), condition(condition)
2693 body.find_reachable(map);
2703 body.check_complete(map);
2742 return cqasm::tree::make<RepeatUntilLoop>(*this);
2749 auto node = cqasm::tree::make<RepeatUntilLoop>(*this);
2750 node->body = this->
body.clone();
2751 node->condition = this->
condition.clone();
2762 if (!this->
body.equals(rhsc.body))
return false;
2763 if (!this->
condition.equals(rhsc.condition))
return false;
2764 if (!this->
annotations.equals(rhsc.annotations))
return false;
2774 if (this->
body != rhsc.body)
return false;
2775 if (this->
condition != rhsc.condition)
return false;
2776 if (this->
annotations != rhsc.annotations)
return false;
2784 ::tree::cbor::MapWriter &map,
2785 const ::tree::base::PointerMap &ids
2788 map.append_string(
"@t",
"RepeatUntilLoop");
2789 auto submap = map.append_map(
"body");
2790 body.serialize(submap, ids);
2792 submap = map.append_map(
"condition");
2795 submap = map.append_map(
"annotations");
2798 serialize_annotations(map);
2806 auto type = map.at(
"@t").as_string();
2807 if (
type !=
"RepeatUntilLoop") {
2808 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
2810 auto node = std::make_shared<RepeatUntilLoop>(
2815 node->deserialize_annotations(map);
2831 lhs.find_reachable(map);
2832 rhs.find_reachable(map);
2842 lhs.check_complete(map);
2843 rhs.check_complete(map);
2882 return cqasm::tree::make<SetInstruction>(*this);
2889 auto node = cqasm::tree::make<SetInstruction>(*this);
2890 node->lhs = this->
lhs.clone();
2891 node->rhs = this->
rhs.clone();
2892 node->condition = this->
condition.clone();
2903 if (!this->
lhs.equals(rhsc.lhs))
return false;
2904 if (!this->rhs.
equals(rhsc.rhs))
return false;
2905 if (!this->
condition.equals(rhsc.condition))
return false;
2906 if (!this->
annotations.equals(rhsc.annotations))
return false;
2916 if (this->
lhs != rhsc.lhs)
return false;
2917 if (this->rhs != rhsc.rhs)
return false;
2918 if (this->
condition != rhsc.condition)
return false;
2919 if (this->
annotations != rhsc.annotations)
return false;
2927 ::tree::cbor::MapWriter &map,
2928 const ::tree::base::PointerMap &ids
2931 map.append_string(
"@t",
"SetInstruction");
2932 auto submap = map.append_map(
"lhs");
2933 lhs.serialize(submap, ids);
2935 submap = map.append_map(
"rhs");
2936 rhs.serialize(submap, ids);
2938 submap = map.append_map(
"condition");
2941 submap = map.append_map(
"annotations");
2944 serialize_annotations(map);
2952 auto type = map.at(
"@t").as_string();
2953 if (
type !=
"SetInstruction") {
2954 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
2956 auto node = std::make_shared<SetInstruction>(
2962 node->deserialize_annotations(map);
2970 :
Annotated(annotations), name(name), iterations(iterations), bundles(bundles), body(body)
2980 body.find_reachable(map);
2990 body.check_complete(map);
3020 return dynamic_cast<const Subcircuit*
>(
this);
3027 return cqasm::tree::make<Subcircuit>(*this);
3034 auto node = cqasm::tree::make<Subcircuit>(*this);
3035 node->bundles = this->
bundles.clone();
3037 node->body = this->
body.clone();
3046 auto rhsc =
dynamic_cast<const Subcircuit&
>(rhs);
3047 if (this->
name != rhsc.name)
return false;
3048 if (this->
iterations != rhsc.iterations)
return false;
3049 if (!this->
bundles.equals(rhsc.bundles))
return false;
3050 if (!this->
annotations.equals(rhsc.annotations))
return false;
3051 if (!this->
body.equals(rhsc.body))
return false;
3060 auto rhsc =
dynamic_cast<const Subcircuit&
>(rhs);
3061 if (this->
name != rhsc.name)
return false;
3062 if (this->
iterations != rhsc.iterations)
return false;
3063 if (this->
bundles != rhsc.bundles)
return false;
3064 if (this->
annotations != rhsc.annotations)
return false;
3065 if (this->
body != rhsc.body)
return false;
3073 ::tree::cbor::MapWriter &map,
3074 const ::tree::base::PointerMap &ids
3077 map.append_string(
"@t",
"Subcircuit");
3078 auto submap = map.append_map(
"name");
3079 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(
name, submap);
3081 submap = map.append_map(
"iterations");
3082 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Int>(
iterations, submap);
3084 submap = map.append_map(
"bundles");
3085 bundles.serialize(submap, ids);
3087 submap = map.append_map(
"annotations");
3090 submap = map.append_map(
"body");
3091 body.serialize(submap, ids);
3093 serialize_annotations(map);
3101 auto type = map.at(
"@t").as_string();
3102 if (
type !=
"Subcircuit") {
3103 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
3105 auto node = std::make_shared<Subcircuit>(
3106 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at(
"name").as_map()),
3107 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Int>(map.at(
"iterations").as_map()),
3112 node->deserialize_annotations(map);
3120 :
Annotated(annotations), name(name), typ(typ)
3128 typ.find_reachable(map);
3137 typ.check_complete(map);
3160 return dynamic_cast<Variable*
>(
this);
3168 return dynamic_cast<const Variable*
>(
this);
3175 return cqasm::tree::make<Variable>(*this);
3182 auto node = cqasm::tree::make<Variable>(*this);
3183 node->typ = this->
typ.clone();
3193 auto rhsc =
dynamic_cast<const Variable&
>(rhs);
3194 if (this->
name != rhsc.name)
return false;
3195 if (!this->
typ.equals(rhsc.typ))
return false;
3196 if (!this->
annotations.equals(rhsc.annotations))
return false;
3205 auto rhsc =
dynamic_cast<const Variable&
>(rhs);
3206 if (this->
name != rhsc.name)
return false;
3207 if (this->
typ != rhsc.typ)
return false;
3208 if (this->
annotations != rhsc.annotations)
return false;
3216 ::tree::cbor::MapWriter &map,
3217 const ::tree::base::PointerMap &ids
3220 map.append_string(
"@t",
"Variable");
3221 auto submap = map.append_map(
"name");
3222 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Str>(
name, submap);
3224 submap = map.append_map(
"typ");
3225 typ.serialize(submap, ids);
3227 submap = map.append_map(
"annotations");
3230 serialize_annotations(map);
3238 auto type = map.at(
"@t").as_string();
3239 if (
type !=
"Variable") {
3240 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
3242 auto node = std::make_shared<Variable>(
3243 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Str>(map.at(
"name").as_map()),
3247 node->deserialize_annotations(map);
3291 return dynamic_cast<Version*
>(
this);
3299 return dynamic_cast<const Version*
>(
this);
3306 return cqasm::tree::make<Version>(*this);
3313 auto node = cqasm::tree::make<Version>(*this);
3322 auto rhsc =
dynamic_cast<const Version&
>(rhs);
3323 if (this->
items != rhsc.items)
return false;
3332 auto rhsc =
dynamic_cast<const Version&
>(rhs);
3333 if (this->
items != rhsc.items)
return false;
3341 ::tree::cbor::MapWriter &map,
3342 const ::tree::base::PointerMap &ids
3345 map.append_string(
"@t",
"Version");
3346 auto submap = map.append_map(
"items");
3347 cqasm::v1::primitives::serialize<cqasm::v1::primitives::Version>(
items, submap);
3349 serialize_annotations(map);
3355 std::shared_ptr<Version>
Version::deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids) {
3357 auto type = map.at(
"@t").as_string();
3358 if (
type !=
"Version") {
3359 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
3361 auto node = std::make_shared<Version>(
3362 cqasm::v1::primitives::deserialize<cqasm::v1::primitives::Version>(map.at(
"items").as_map())
3364 node->deserialize_annotations(map);
3372 :
Structured(annotations), condition(condition), body(body)
3381 body.find_reachable(map);
3391 body.check_complete(map);
3422 return dynamic_cast<const WhileLoop*
>(
this);
3429 return cqasm::tree::make<WhileLoop>(*this);
3436 auto node = cqasm::tree::make<WhileLoop>(*this);
3437 node->condition = this->
condition.clone();
3438 node->body = this->
body.clone();
3448 auto rhsc =
dynamic_cast<const WhileLoop&
>(rhs);
3449 if (!this->
condition.equals(rhsc.condition))
return false;
3450 if (!this->
body.equals(rhsc.body))
return false;
3451 if (!this->
annotations.equals(rhsc.annotations))
return false;
3460 auto rhsc =
dynamic_cast<const WhileLoop&
>(rhs);
3461 if (this->
condition != rhsc.condition)
return false;
3462 if (this->
body != rhsc.body)
return false;
3463 if (this->
annotations != rhsc.annotations)
return false;
3471 ::tree::cbor::MapWriter &map,
3472 const ::tree::base::PointerMap &ids
3475 map.append_string(
"@t",
"WhileLoop");
3476 auto submap = map.append_map(
"condition");
3479 submap = map.append_map(
"body");
3480 body.serialize(submap, ids);
3482 submap = map.append_map(
"annotations");
3485 serialize_annotations(map);
3493 auto type = map.at(
"@t").as_string();
3494 if (
type !=
"WhileLoop") {
3495 throw std::runtime_error(
"Schema validation failed: unexpected node type " +
type);
3497 auto node = std::make_shared<WhileLoop>(
3502 node->deserialize_annotations(map);
3512 this->visit_node(node);
3521 this->visit_annotated(node);
3530 this->visit_annotation_data(node);
3539 this->visit_block(node);
3548 this->visit_break_statement(node);
3557 this->visit_bundle(node);
3566 this->visit_bundle_ext(node);
3575 this->visit_continue_statement(node);
3584 this->visit_error_model(node);
3593 this->visit_for_loop(node);
3602 this->visit_foreach_loop(node);
3611 this->visit_goto_instruction(node);
3620 this->visit_if_else(node);
3629 this->visit_if_else_branch(node);
3638 this->visit_instruction(node);
3647 this->visit_instruction_base(node);
3656 this->visit_mapping(node);
3665 this->visit_program(node);
3674 this->visit_repeat_until_loop(node);
3683 this->visit_set_instruction(node);
3692 this->visit_statement(node);
3701 this->visit_structured(node);
3710 this->visit_subcircuit(node);
3719 this->visit_variable(node);
3728 this->visit_version(node);
3737 this->visit_while_loop(node);
3767 visit_structured(node);
3774 visit_annotated(node);
3775 node.
items.visit(*
this);
3782 visit_statement(node);
3783 node.
items.visit(*
this);
3790 visit_structured(node);
3797 visit_annotated(node);
3804 visit_structured(node);
3806 node.
update.visit(*
this);
3807 node.
body.visit(*
this);
3814 visit_structured(node);
3815 node.
body.visit(*
this);
3822 visit_instruction_base(node);
3829 visit_structured(node);
3839 node.
body.visit(*
this);
3846 visit_instruction_base(node);
3853 visit_annotated(node);
3860 visit_annotated(node);
3879 visit_structured(node);
3880 node.
body.visit(*
this);
3887 visit_instruction_base(node);
3894 visit_annotated(node);
3901 visit_statement(node);
3908 visit_annotated(node);
3910 node.
body.visit(*
this);
3917 visit_annotated(node);
3931 visit_structured(node);
3932 node.
body.visit(*
this);
3939 for (
int i = 0; i < indent; i++) {
3950 out <<
"!Node()" << std::endl;
3959 if (ids !=
nullptr) {
3960 out <<
"@" << ids->get_ref(node);
3964 out <<
" # " << *loc;
3969 out <<
"annotations: ";
3971 out <<
"[]" << std::endl;
3973 out <<
"[" << std::endl;
3976 if (!sptr.empty()) {
3980 out <<
"!NULL" << std::endl;
3985 out <<
"]" << std::endl;
3989 out <<
")" << std::endl;
3997 out <<
"AnnotationData";
3998 if (ids !=
nullptr) {
3999 out <<
"@" << ids->get_ref(node);
4003 out <<
" # " << *loc;
4008 out <<
"interface: ";
4009 std::stringstream ss;
4012 pos = ss.str().find_last_not_of(
" \n\r\t");
4013 if (pos != std::string::npos) {
4014 ss.str(ss.str().erase(pos+1));
4016 if (ss.str().find(
'\n') == std::string::npos) {
4017 out << ss.str() << std::endl;
4019 out <<
"cqasm::v1::primitives::Str<<" << std::endl;
4023 std::getline(ss, s);
4025 out << s << std::endl;
4029 out <<
">>" << std::endl;
4032 out <<
"operation: ";
4036 pos = ss.str().find_last_not_of(
" \n\r\t");
4037 if (pos != std::string::npos) {
4038 ss.str(ss.str().erase(pos+1));
4040 if (ss.str().find(
'\n') == std::string::npos) {
4041 out << ss.str() << std::endl;
4043 out <<
"cqasm::v1::primitives::Str<<" << std::endl;
4047 std::getline(ss, s);
4049 out << s << std::endl;
4053 out <<
">>" << std::endl;
4056 out <<
"operands: ";
4058 out <<
"[]" << std::endl;
4060 out <<
"[" << std::endl;
4063 if (!sptr.empty()) {
4064 sptr->dump(out, indent);
4067 out <<
"!NULL" << std::endl;
4072 out <<
"]" << std::endl;
4076 out <<
")" << std::endl;
4085 if (ids !=
nullptr) {
4086 out <<
"@" << ids->get_ref(node);
4090 out <<
" # " << *loc;
4095 out <<
"statements: ";
4097 out <<
"[]" << std::endl;
4099 out <<
"[" << std::endl;
4102 if (!sptr.empty()) {
4106 out <<
"!NULL" << std::endl;
4111 out <<
"]" << std::endl;
4115 out <<
")" << std::endl;
4123 out <<
"BreakStatement";
4124 if (ids !=
nullptr) {
4125 out <<
"@" << ids->get_ref(node);
4129 out <<
" # " << *loc;
4134 out <<
"annotations: ";
4136 out <<
"[]" << std::endl;
4138 out <<
"[" << std::endl;
4141 if (!sptr.empty()) {
4145 out <<
"!NULL" << std::endl;
4150 out <<
"]" << std::endl;
4154 out <<
")" << std::endl;
4163 if (ids !=
nullptr) {
4164 out <<
"@" << ids->get_ref(node);
4168 out <<
" # " << *loc;
4174 if (node.
items.empty()) {
4175 out <<
"!MISSING" << std::endl;
4177 out <<
"[" << std::endl;
4179 for (
auto &sptr : node.
items) {
4180 if (!sptr.empty()) {
4184 out <<
"!NULL" << std::endl;
4189 out <<
"]" << std::endl;
4192 out <<
"annotations: ";
4194 out <<
"[]" << std::endl;
4196 out <<
"[" << std::endl;
4199 if (!sptr.empty()) {
4203 out <<
"!NULL" << std::endl;
4208 out <<
"]" << std::endl;
4212 out <<
")" << std::endl;
4221 if (ids !=
nullptr) {
4222 out <<
"@" << ids->get_ref(node);
4226 out <<
" # " << *loc;
4232 if (node.
items.empty()) {
4233 out <<
"!MISSING" << std::endl;
4235 out <<
"[" << std::endl;
4237 for (
auto &sptr : node.
items) {
4238 if (!sptr.empty()) {
4242 out <<
"!NULL" << std::endl;
4247 out <<
"]" << std::endl;
4250 out <<
"annotations: ";
4252 out <<
"[]" << std::endl;
4254 out <<
"[" << std::endl;
4257 if (!sptr.empty()) {
4261 out <<
"!NULL" << std::endl;
4266 out <<
"]" << std::endl;
4270 out <<
")" << std::endl;
4278 out <<
"ContinueStatement";
4279 if (ids !=
nullptr) {
4280 out <<
"@" << ids->get_ref(node);
4284 out <<
" # " << *loc;
4289 out <<
"annotations: ";
4291 out <<
"[]" << std::endl;
4293 out <<
"[" << std::endl;
4296 if (!sptr.empty()) {
4300 out <<
"!NULL" << std::endl;
4305 out <<
"]" << std::endl;
4309 out <<
")" << std::endl;
4317 out <<
"ErrorModel";
4318 if (ids !=
nullptr) {
4319 out <<
"@" << ids->get_ref(node);
4323 out <<
" # " << *loc;
4329 std::stringstream ss;
4332 pos = ss.str().find_last_not_of(
" \n\r\t");
4333 if (pos != std::string::npos) {
4334 ss.str(ss.str().erase(pos+1));
4336 if (ss.str().find(
'\n') == std::string::npos) {
4337 out << ss.str() << std::endl;
4339 out <<
"cqasm::v1::error_model::ErrorModelRef<<" << std::endl;
4343 std::getline(ss, s);
4345 out << s << std::endl;
4349 out <<
">>" << std::endl;
4356 pos = ss.str().find_last_not_of(
" \n\r\t");
4357 if (pos != std::string::npos) {
4358 ss.str(ss.str().erase(pos+1));
4360 if (ss.str().find(
'\n') == std::string::npos) {
4361 out << ss.str() << std::endl;
4363 out <<
"cqasm::v1::primitives::Str<<" << std::endl;
4367 std::getline(ss, s);
4369 out << s << std::endl;
4373 out <<
">>" << std::endl;
4376 out <<
"parameters: ";
4378 out <<
"[]" << std::endl;
4380 out <<
"[" << std::endl;
4383 if (!sptr.empty()) {
4384 sptr->dump(out, indent);
4387 out <<
"!NULL" << std::endl;
4392 out <<
"]" << std::endl;
4395 out <<
"annotations: ";
4397 out <<
"[]" << std::endl;
4399 out <<
"[" << std::endl;
4402 if (!sptr.empty()) {
4406 out <<
"!NULL" << std::endl;
4411 out <<
"]" << std::endl;
4415 out <<
")" << std::endl;
4424 if (ids !=
nullptr) {
4425 out <<
"@" << ids->get_ref(node);
4429 out <<
" # " << *loc;
4434 out <<
"initialize: ";
4436 out <<
"-" << std::endl;
4438 out <<
"<" << std::endl;
4443 out <<
">" << std::endl;
4446 out <<
"condition: ";
4448 out <<
"!MISSING" << std::endl;
4450 out <<
"<" << std::endl;
4457 out <<
">" << std::endl;
4461 if (node.
update.empty()) {
4462 out <<
"-" << std::endl;
4464 out <<
"<" << std::endl;
4466 node.
update.visit(*
this);
4469 out <<
">" << std::endl;
4473 if (node.
body.empty()) {
4474 out <<
"!MISSING" << std::endl;
4476 out <<
"<" << std::endl;
4478 node.
body.visit(*
this);
4481 out <<
">" << std::endl;
4484 out <<
"annotations: ";
4486 out <<
"[]" << std::endl;
4488 out <<
"[" << std::endl;
4491 if (!sptr.empty()) {
4495 out <<
"!NULL" << std::endl;
4500 out <<
"]" << std::endl;
4504 out <<
")" << std::endl;
4512 out <<
"ForeachLoop";
4513 if (ids !=
nullptr) {
4514 out <<
"@" << ids->get_ref(node);
4518 out <<
" # " << *loc;
4524 if (node.
lhs.empty()) {
4525 out <<
"!MISSING" << std::endl;
4527 out <<
"<" << std::endl;
4529 if (!node.
lhs.empty()) {
4530 node.
lhs->dump(out, indent);
4534 out <<
">" << std::endl;
4538 std::stringstream ss;
4541 pos = ss.str().find_last_not_of(
" \n\r\t");
4542 if (pos != std::string::npos) {
4543 ss.str(ss.str().erase(pos+1));
4545 if (ss.str().find(
'\n') == std::string::npos) {
4546 out << ss.str() << std::endl;
4548 out <<
"cqasm::v1::primitives::Int<<" << std::endl;
4552 std::getline(ss, s);
4554 out << s << std::endl;
4558 out <<
">>" << std::endl;
4565 pos = ss.str().find_last_not_of(
" \n\r\t");
4566 if (pos != std::string::npos) {
4567 ss.str(ss.str().erase(pos+1));
4569 if (ss.str().find(
'\n') == std::string::npos) {
4570 out << ss.str() << std::endl;
4572 out <<
"cqasm::v1::primitives::Int<<" << std::endl;
4576 std::getline(ss, s);
4578 out << s << std::endl;
4582 out <<
">>" << std::endl;
4586 if (node.
body.empty()) {
4587 out <<
"!MISSING" << std::endl;
4589 out <<
"<" << std::endl;
4591 node.
body.visit(*
this);
4594 out <<
">" << std::endl;
4597 out <<
"annotations: ";
4599 out <<
"[]" << std::endl;
4601 out <<
"[" << std::endl;
4604 if (!sptr.empty()) {
4608 out <<
"!NULL" << std::endl;
4613 out <<
"]" << std::endl;
4617 out <<
")" << std::endl;
4625 out <<
"GotoInstruction";
4626 if (ids !=
nullptr) {
4627 out <<
"@" << ids->get_ref(node);
4631 out <<
" # " << *loc;
4636 out <<
"target --> ";
4637 if (node.
target.empty()) {
4638 out <<
"!MISSING" << std::endl;
4639 }
else if (ids !=
nullptr && ids->get(node.
target) != (size_t)-1) {
4640 out <<
"Subcircuit@" << ids->get(node.
target) << std::endl;
4642 out <<
"<" << std::endl;
4646 node.
target.visit(*
this);
4650 out <<
"..." << std::endl;
4654 out <<
">" << std::endl;
4657 out <<
"condition: ";
4659 out <<
"!MISSING" << std::endl;
4661 out <<
"<" << std::endl;
4668 out <<
">" << std::endl;
4671 out <<
"annotations: ";
4673 out <<
"[]" << std::endl;
4675 out <<
"[" << std::endl;
4678 if (!sptr.empty()) {
4682 out <<
"!NULL" << std::endl;
4687 out <<
"]" << std::endl;
4691 out <<
")" << std::endl;
4700 if (ids !=
nullptr) {
4701 out <<
"@" << ids->get_ref(node);
4705 out <<
" # " << *loc;
4710 out <<
"branches: ";
4712 out <<
"!MISSING" << std::endl;
4714 out <<
"[" << std::endl;
4717 if (!sptr.empty()) {
4721 out <<
"!NULL" << std::endl;
4726 out <<
"]" << std::endl;
4729 out <<
"otherwise: ";
4731 out <<
"-" << std::endl;
4733 out <<
"<" << std::endl;
4738 out <<
">" << std::endl;
4741 out <<
"annotations: ";
4743 out <<
"[]" << std::endl;
4745 out <<
"[" << std::endl;
4748 if (!sptr.empty()) {
4752 out <<
"!NULL" << std::endl;
4757 out <<
"]" << std::endl;
4761 out <<
")" << std::endl;
4769 out <<
"IfElseBranch";
4770 if (ids !=
nullptr) {
4771 out <<
"@" << ids->get_ref(node);
4775 out <<
" # " << *loc;
4780 out <<
"condition: ";
4782 out <<
"!MISSING" << std::endl;
4784 out <<
"<" << std::endl;
4791 out <<
">" << std::endl;
4795 if (node.
body.empty()) {
4796 out <<
"!MISSING" << std::endl;
4798 out <<
"<" << std::endl;
4800 node.
body.visit(*
this);
4803 out <<
">" << std::endl;
4807 out <<
")" << std::endl;
4815 out <<
"Instruction";
4816 if (ids !=
nullptr) {
4817 out <<
"@" << ids->get_ref(node);
4821 out <<
" # " << *loc;
4826 out <<
"instruction: ";
4827 std::stringstream ss;
4830 pos = ss.str().find_last_not_of(
" \n\r\t");
4831 if (pos != std::string::npos) {
4832 ss.str(ss.str().erase(pos+1));
4834 if (ss.str().find(
'\n') == std::string::npos) {
4835 out << ss.str() << std::endl;
4837 out <<
"cqasm::v1::instruction::InstructionRef<<" << std::endl;
4841 std::getline(ss, s);
4843 out << s << std::endl;
4847 out <<
">>" << std::endl;
4854 pos = ss.str().find_last_not_of(
" \n\r\t");
4855 if (pos != std::string::npos) {
4856 ss.str(ss.str().erase(pos+1));
4858 if (ss.str().find(
'\n') == std::string::npos) {
4859 out << ss.str() << std::endl;
4861 out <<
"cqasm::v1::primitives::Str<<" << std::endl;
4865 std::getline(ss, s);
4867 out << s << std::endl;
4871 out <<
">>" << std::endl;
4874 out <<
"condition: ";
4876 out <<
"!MISSING" << std::endl;
4878 out <<
"<" << std::endl;
4885 out <<
">" << std::endl;
4888 out <<
"operands: ";
4890 out <<
"[]" << std::endl;
4892 out <<
"[" << std::endl;
4895 if (!sptr.empty()) {
4896 sptr->dump(out, indent);
4899 out <<
"!NULL" << std::endl;
4904 out <<
"]" << std::endl;
4907 out <<
"annotations: ";
4909 out <<
"[]" << std::endl;
4911 out <<
"[" << std::endl;
4914 if (!sptr.empty()) {
4918 out <<
"!NULL" << std::endl;
4923 out <<
"]" << std::endl;
4927 out <<
")" << std::endl;
4935 out <<
"InstructionBase";
4936 if (ids !=
nullptr) {
4937 out <<
"@" << ids->get_ref(node);
4941 out <<
" # " << *loc;
4946 out <<
"condition: ";
4948 out <<
"!MISSING" << std::endl;
4950 out <<
"<" << std::endl;
4957 out <<
">" << std::endl;
4960 out <<
"annotations: ";
4962 out <<
"[]" << std::endl;
4964 out <<
"[" << std::endl;
4967 if (!sptr.empty()) {
4971 out <<
"!NULL" << std::endl;
4976 out <<
"]" << std::endl;
4980 out <<
")" << std::endl;
4989 if (ids !=
nullptr) {
4990 out <<
"@" << ids->get_ref(node);
4994 out <<
" # " << *loc;
5000 std::stringstream ss;
5003 pos = ss.str().find_last_not_of(
" \n\r\t");
5004 if (pos != std::string::npos) {
5005 ss.str(ss.str().erase(pos+1));
5007 if (ss.str().find(
'\n') == std::string::npos) {
5008 out << ss.str() << std::endl;
5010 out <<
"cqasm::v1::primitives::Str<<" << std::endl;
5014 std::getline(ss, s);
5016 out << s << std::endl;
5020 out <<
">>" << std::endl;
5024 if (node.
value.empty()) {
5025 out <<
"!MISSING" << std::endl;
5027 out <<
"<" << std::endl;
5029 if (!node.
value.empty()) {
5030 node.
value->dump(out, indent);
5034 out <<
">" << std::endl;
5037 out <<
"annotations: ";
5039 out <<
"[]" << std::endl;
5041 out <<
"[" << std::endl;
5044 if (!sptr.empty()) {
5048 out <<
"!NULL" << std::endl;
5053 out <<
"]" << std::endl;
5057 out <<
")" << std::endl;
5066 if (ids !=
nullptr) {
5067 out <<
"@" << ids->get_ref(node);
5071 out <<
" # " << *loc;
5078 out <<
"!MISSING" << std::endl;
5080 out <<
"<" << std::endl;
5085 out <<
">" << std::endl;
5088 out <<
"num_qubits: ";
5089 std::stringstream ss;
5092 pos = ss.str().find_last_not_of(
" \n\r\t");
5093 if (pos != std::string::npos) {
5094 ss.str(ss.str().erase(pos+1));
5096 if (ss.str().find(
'\n') == std::string::npos) {
5097 out << ss.str() << std::endl;
5099 out <<
"cqasm::v1::primitives::Int<<" << std::endl;
5103 std::getline(ss, s);
5105 out << s << std::endl;
5109 out <<
">>" << std::endl;
5112 out <<
"error_model: ";
5114 out <<
"-" << std::endl;
5116 out <<
"<" << std::endl;
5121 out <<
">" << std::endl;
5124 out <<
"subcircuits: ";
5126 out <<
"[]" << std::endl;
5128 out <<
"[" << std::endl;
5131 if (!sptr.empty()) {
5135 out <<
"!NULL" << std::endl;
5140 out <<
"]" << std::endl;
5143 out <<
"mappings: ";
5145 out <<
"[]" << std::endl;
5147 out <<
"[" << std::endl;
5150 if (!sptr.empty()) {
5154 out <<
"!NULL" << std::endl;
5159 out <<
"]" << std::endl;
5162 out <<
"variables: ";
5164 out <<
"[]" << std::endl;
5166 out <<
"[" << std::endl;
5169 if (!sptr.empty()) {
5173 out <<
"!NULL" << std::endl;
5178 out <<
"]" << std::endl;
5181 out <<
"api_version: ";
5185 pos = ss.str().find_last_not_of(
" \n\r\t");
5186 if (pos != std::string::npos) {
5187 ss.str(ss.str().erase(pos+1));
5189 if (ss.str().find(
'\n') == std::string::npos) {
5190 out << ss.str() << std::endl;
5192 out <<
"cqasm::v1::primitives::Version<<" << std::endl;
5196 std::getline(ss, s);
5198 out << s << std::endl;
5202 out <<
">>" << std::endl;
5206 out <<
")" << std::endl;
5214 out <<
"RepeatUntilLoop";
5215 if (ids !=
nullptr) {
5216 out <<
"@" << ids->get_ref(node);
5220 out <<
" # " << *loc;
5226 if (node.
body.empty()) {
5227 out <<
"!MISSING" << std::endl;
5229 out <<
"<" << std::endl;
5231 node.
body.visit(*
this);
5234 out <<
">" << std::endl;
5237 out <<
"condition: ";
5239 out <<
"!MISSING" << std::endl;
5241 out <<
"<" << std::endl;
5248 out <<
">" << std::endl;
5251 out <<
"annotations: ";
5253 out <<
"[]" << std::endl;
5255 out <<
"[" << std::endl;
5258 if (!sptr.empty()) {
5262 out <<
"!NULL" << std::endl;
5267 out <<
"]" << std::endl;
5271 out <<
")" << std::endl;
5279 out <<
"SetInstruction";
5280 if (ids !=
nullptr) {
5281 out <<
"@" << ids->get_ref(node);
5285 out <<
" # " << *loc;
5291 if (node.
lhs.empty()) {
5292 out <<
"!MISSING" << std::endl;
5294 out <<
"<" << std::endl;
5296 if (!node.
lhs.empty()) {
5297 node.
lhs->dump(out, indent);
5301 out <<
">" << std::endl;
5305 if (node.
rhs.empty()) {
5306 out <<
"!MISSING" << std::endl;
5308 out <<
"<" << std::endl;
5310 if (!node.
rhs.empty()) {
5311 node.
rhs->dump(out, indent);
5315 out <<
">" << std::endl;
5318 out <<
"condition: ";
5320 out <<
"!MISSING" << std::endl;
5322 out <<
"<" << std::endl;
5329 out <<
">" << std::endl;
5332 out <<
"annotations: ";
5334 out <<
"[]" << std::endl;
5336 out <<
"[" << std::endl;
5339 if (!sptr.empty()) {
5343 out <<
"!NULL" << std::endl;
5348 out <<
"]" << std::endl;
5352 out <<
")" << std::endl;
5361 if (ids !=
nullptr) {
5362 out <<
"@" << ids->get_ref(node);
5366 out <<
" # " << *loc;
5371 out <<
"annotations: ";
5373 out <<
"[]" << std::endl;
5375 out <<
"[" << std::endl;
5378 if (!sptr.empty()) {
5382 out <<
"!NULL" << std::endl;
5387 out <<
"]" << std::endl;
5391 out <<
")" << std::endl;
5399 out <<
"Structured";
5400 if (ids !=
nullptr) {
5401 out <<
"@" << ids->get_ref(node);
5405 out <<
" # " << *loc;
5410 out <<
"annotations: ";
5412 out <<
"[]" << std::endl;
5414 out <<
"[" << std::endl;
5417 if (!sptr.empty()) {
5421 out <<
"!NULL" << std::endl;
5426 out <<
"]" << std::endl;
5430 out <<
")" << std::endl;
5438 out <<
"Subcircuit";
5439 if (ids !=
nullptr) {
5440 out <<
"@" << ids->get_ref(node);
5444 out <<
" # " << *loc;
5450 std::stringstream ss;
5453 pos = ss.str().find_last_not_of(
" \n\r\t");
5454 if (pos != std::string::npos) {
5455 ss.str(ss.str().erase(pos+1));
5457 if (ss.str().find(
'\n') == std::string::npos) {
5458 out << ss.str() << std::endl;
5460 out <<
"cqasm::v1::primitives::Str<<" << std::endl;
5464 std::getline(ss, s);
5466 out << s << std::endl;
5470 out <<
">>" << std::endl;
5473 out <<
"iterations: ";
5477 pos = ss.str().find_last_not_of(
" \n\r\t");
5478 if (pos != std::string::npos) {
5479 ss.str(ss.str().erase(pos+1));
5481 if (ss.str().find(
'\n') == std::string::npos) {
5482 out << ss.str() << std::endl;
5484 out <<
"cqasm::v1::primitives::Int<<" << std::endl;
5488 std::getline(ss, s);
5490 out << s << std::endl;
5494 out <<
">>" << std::endl;
5499 out <<
"[]" << std::endl;
5501 out <<
"[" << std::endl;
5503 for (
auto &sptr : node.
bundles) {
5504 if (!sptr.empty()) {
5508 out <<
"!NULL" << std::endl;
5513 out <<
"]" << std::endl;
5516 out <<
"annotations: ";
5518 out <<
"[]" << std::endl;
5520 out <<
"[" << std::endl;
5523 if (!sptr.empty()) {
5527 out <<
"!NULL" << std::endl;
5532 out <<
"]" << std::endl;
5536 if (node.
body.empty()) {
5537 out <<
"-" << std::endl;
5539 out <<
"<" << std::endl;
5541 node.
body.visit(*
this);
5544 out <<
">" << std::endl;
5548 out <<
")" << std::endl;
5557 if (ids !=
nullptr) {
5558 out <<
"@" << ids->get_ref(node);
5562 out <<
" # " << *loc;
5568 std::stringstream ss;
5571 pos = ss.str().find_last_not_of(
" \n\r\t");
5572 if (pos != std::string::npos) {
5573 ss.str(ss.str().erase(pos+1));
5575 if (ss.str().find(
'\n') == std::string::npos) {
5576 out << ss.str() << std::endl;
5578 out <<
"cqasm::v1::primitives::Str<<" << std::endl;
5582 std::getline(ss, s);
5584 out << s << std::endl;
5588 out <<
">>" << std::endl;
5592 if (node.
typ.empty()) {
5593 out <<
"!MISSING" << std::endl;
5595 out <<
"<" << std::endl;
5597 if (!node.
typ.empty()) {
5598 node.
typ->dump(out, indent);
5602 out <<
">" << std::endl;
5605 out <<
"annotations: ";
5607 out <<
"[]" << std::endl;
5609 out <<
"[" << std::endl;
5612 if (!sptr.empty()) {
5616 out <<
"!NULL" << std::endl;
5621 out <<
"]" << std::endl;
5625 out <<
")" << std::endl;
5634 if (ids !=
nullptr) {
5635 out <<
"@" << ids->get_ref(node);
5639 out <<
" # " << *loc;
5645 std::stringstream ss;
5648 pos = ss.str().find_last_not_of(
" \n\r\t");
5649 if (pos != std::string::npos) {
5650 ss.str(ss.str().erase(pos+1));
5652 if (ss.str().find(
'\n') == std::string::npos) {
5653 out << ss.str() << std::endl;
5655 out <<
"cqasm::v1::primitives::Version<<" << std::endl;
5659 std::getline(ss, s);
5661 out << s << std::endl;
5665 out <<
">>" << std::endl;
5669 out <<
")" << std::endl;
5678 if (ids !=
nullptr) {
5679 out <<
"@" << ids->get_ref(node);
5683 out <<
" # " << *loc;
5688 out <<
"condition: ";
5690 out <<
"!MISSING" << std::endl;
5692 out <<
"<" << std::endl;
5699 out <<
">" << std::endl;
5703 if (node.
body.empty()) {
5704 out <<
"!MISSING" << std::endl;
5706 out <<
"<" << std::endl;
5708 node.
body.visit(*
this);
5711 out <<
">" << std::endl;
5714 out <<
"annotations: ";
5716 out <<
"[]" << std::endl;
5718 out <<
"[" << std::endl;
5721 if (!sptr.empty()) {
5725 out <<
"!NULL" << std::endl;
5730 out <<
"]" << std::endl;
5734 out <<
")" << std::endl;
5749 const_cast<Node&
>(object).
dump(os);
void visit_mapping(Mapping &node) override
Recursive traversal for Mapping nodes.
The file version identifier.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this BundleExt is complete/fully defined.
void visit_block(Block &node) override
Recursive traversal for Block nodes.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
Annotated(const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
NodeType type() const override
Returns the NodeType of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
static std::shared_ptr< ContinueStatement > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
static std::shared_ptr< Structured > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
Block(const Any< Statement > &statements=Any< Statement >())
Constructor.
void visit_if_else(IfElse &node) override
Recursive traversal for IfElse nodes.
void visit_statement(Statement &node) override
Recursive traversal for Statement nodes.
virtual Bundle * as_bundle()
Interprets this node to a node of type Bundle.
IfElse * as_if_else() override
Interprets this node to a node of type IfElse.
NodeType type() const override
Returns the NodeType of this node.
Visitor class that debug-dumps a tree to a stream.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
virtual IfElse * as_if_else()
Interprets this node to a node of type IfElse.
NodeType
Enumeration of all node types.
BundleExt * as_bundle_ext() override
Interprets this node to a node of type BundleExt.
static std::shared_ptr< Variable > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
cqasm::v1::primitives::Str name
The name of the subcircuit.
One< Node > copy() const override
Returns a shallow copy of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
RepeatUntilLoop(const One< Block > &body=One< Block >(), const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void visit_structured(Structured &node) override
Recursive traversal for Structured nodes.
void visit_foreach_loop(ForeachLoop &node) override
Recursive traversal for ForeachLoop nodes.
static std::shared_ptr< Annotated > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
One< Node > clone() const override
Returns a deep copy of this node.
virtual void raw_visit_bundle(Bundle &node, void *retval)=0
Internal visitor function for Bundle nodes.
static std::shared_ptr< ErrorModel > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void raw_visit_for_loop(ForLoop &node, void *retval) override
Internal visitor function for ForLoop nodes.
void raw_visit_annotation_data(AnnotationData &node, void *retval) override
Internal visitor function for AnnotationData nodes.
One< Node > clone() const override
Returns a deep copy of this node.
virtual Block * as_block()
Interprets this node to a node of type Block.
static std::shared_ptr< Instruction > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
Represents a node that carries annotation data.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
ContinueStatement * as_continue_statement() override
Interprets this node to a node of type ContinueStatement.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void raw_visit_variable(Variable &node, void *retval) override
Internal visitor function for Variable nodes.
WhileLoop * as_while_loop() override
Interprets this node to a node of type WhileLoop.
NodeType type() const override
Returns the NodeType of this node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void raw_visit_break_statement(BreakStatement &node, void *retval) override
Internal visitor function for BreakStatement nodes.
One< Node > clone() const override
Returns a deep copy of this node.
T visit(Visitor< T > &visitor)
Visit this object.
tree::Maybe< ErrorModel > ErrorModelRef
Optional reference to an error model, used within the semantic tree.
Any< Variable > variables
This list of all user-defined variables at any point in the code.
One< Node > clone() const override
Returns a deep copy of this node.
static std::shared_ptr< IfElse > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
Statement(const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
RepeatUntilLoop * as_repeat_until_loop() override
Interprets this node to a node of type RepeatUntilLoop.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
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.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
tree::Maybe< Instruction > InstructionRef
Optional reference to an instruction, used within the semantic tree.
cqasm::v1::primitives::Str name
Name as it appears in the cQASM file.
virtual void raw_visit_foreach_loop(ForeachLoop &node, void *retval)=0
Internal visitor function for ForeachLoop nodes.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
NodeType type() const override
Returns the NodeType of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
AnnotationData(const cqasm::v1::primitives::Str &interface=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const cqasm::v1::primitives::Str &operation=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const Any< cqasm::v1::values::Node > &operands=cqasm::v1::primitives::initialize< Any< cqasm::v1::values::Node >>())
Constructor.
void visit_for_loop(ForLoop &node) override
Recursive traversal for ForLoop nodes.
Structured * as_structured() override
Interprets this node to a node of type Structured.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void visit_subcircuit(Subcircuit &node) override
Dumps a Subcircuit node.
One< Node > clone() const override
Returns a deep copy of this node.
cqasm::tree::Any< T > Any
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this WhileLoop is complete/fully defined.
cqasm::tree::One< T > One
void raw_visit_foreach_loop(ForeachLoop &node, void *retval) override
Internal visitor function for ForeachLoop nodes.
A list of parallel instructions.
One< cqasm::v1::values::Node > lhs
The assignment target.
NodeType type() const override
Returns the NodeType of this node.
virtual void raw_visit_subcircuit(Subcircuit &node, void *retval)=0
Internal visitor function for Subcircuit nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Subcircuit is complete/fully defined.
void visit_version(Version &node) override
Dumps a Version node.
void visit_block(Block &node) override
Dumps a Block node.
cqasm::v1::primitives::Str interface
The interface this annotation is intended for.
Contains annotation objects used within the trees by libqasm.
void raw_visit_set_instruction(SetInstruction &node, void *retval) override
Internal visitor function for SetInstruction nodes.
NodeType type() const override
Returns the NodeType of this node.
NodeType type() const override
Returns the NodeType of this node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Bundle is complete/fully defined.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
cqasm::v1::instruction::InstructionRef instruction
Instruction type as registered through the API.
cqasm::v1::primitives::Int to
The last value.
One< cqasm::v1::values::Node > condition
Condition (c- notation).
cqasm::v1::primitives::Str name
Name as it appears in the cQASM file.
Toplevel namespace with entry points for the new API.
ContinueStatement(const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this AnnotationData is complete/fully defined.
ErrorModel * as_error_model() override
Interprets this node to a node of type ErrorModel.
Any< cqasm::v1::values::Node > parameters
Error model parameters.
InstructionBase * as_instruction_base() override
Interprets this node to a node of type InstructionBase.
static std::shared_ptr< Statement > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual BreakStatement * as_break_statement()
Interprets this node to a node of type BreakStatement.
One< Block > body
The loop body.
Subcircuit(const cqasm::v1::primitives::Str &name=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const cqasm::v1::primitives::Int &iterations=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >(), const Any< Bundle > &bundles=Any< Bundle >(), const Any< AnnotationData > &annotations=Any< AnnotationData >(), const Maybe< Block > &body=Maybe< Block >())
Constructor.
void visit_while_loop(WhileLoop &node) override
Recursive traversal for WhileLoop nodes.
virtual InstructionBase * as_instruction_base()
Interprets this node to a node of type InstructionBase.
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.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
Any< cqasm::v1::values::Node > operands
Any operands attached to the annotation.
Program * as_program() override
Interprets this node to a node of type Program.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
BreakStatement(const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this BreakStatement is complete/fully defined.
SetInstruction(const One< cqasm::v1::values::Node > &lhs=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const One< cqasm::v1::values::Node > &rhs=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
virtual BundleExt * as_bundle_ext()
Interprets this node to a node of type BundleExt.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ForLoop is complete/fully defined.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this IfElseBranch is complete/fully defined.
void raw_visit_block(Block &node, void *retval) override
Internal visitor function for Block nodes.
void raw_visit_node(Node &node, void *retval) override
Internal visitor function for nodes of any type.
Many< InstructionBase > items
The list of parallel instructions.
A mapping (alias) for an expression.
virtual void raw_visit_block(Block &node, void *retval)=0
Internal visitor function for Block nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
static std::shared_ptr< ForeachLoop > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
static std::shared_ptr< Bundle > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_version(Version &node) override
Recursive traversal for Version nodes.
Any< Subcircuit > subcircuits
The list of subcircuit.
Source location annotation object, containing source file line numbers etc.
AnnotationData * as_annotation_data() override
Interprets this node to a node of type AnnotationData.
void visit_annotated(Annotated &node) override
Dumps a Annotated node.
A single condition + block for use in an if-else chain.
void visit_error_model(ErrorModel &node) override
Recursive traversal for ErrorModel nodes.
void visit_if_else_branch(IfElseBranch &node) override
Dumps a IfElseBranch node.
ForLoop * as_for_loop() override
Interprets this node to a node of type ForLoop.
bool equals(const Node &rhs) const override
Value-based equality operator.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
One< Version > version
File version.
void visit_program(Program &node) override
Dumps a Program node.
Internal class for implementing the visitor pattern.
NodeType type() const override
Returns the NodeType of this node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
One< Node > clone() const override
Returns a deep copy of this node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
static std::shared_ptr< BundleExt > 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 Program is complete/fully defined.
virtual void raw_visit_annotation_data(AnnotationData &node, void *retval)=0
Internal visitor function for AnnotationData nodes.
virtual void raw_visit_repeat_until_loop(RepeatUntilLoop &node, void *retval)=0
Internal visitor function for RepeatUntilLoop nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
bool equals(const Node &rhs) const override
Value-based equality operator.
virtual Instruction * as_instruction()
Interprets this node to a node of type Instruction.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
Variable(const cqasm::v1::primitives::Str &name=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const One< cqasm::v1::types::Node > &typ=cqasm::v1::primitives::initialize< One< cqasm::v1::types::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
virtual void raw_visit_continue_statement(ContinueStatement &node, void *retval)=0
Internal visitor function for ContinueStatement nodes.
virtual GotoInstruction * as_goto_instruction()
Interprets this node to a node of type GotoInstruction.
void raw_visit_error_model(ErrorModel &node, void *retval) override
Internal visitor function for ErrorModel nodes.
virtual void raw_visit_bundle_ext(BundleExt &node, void *retval)=0
Internal visitor function for BundleExt nodes.
void visit_goto_instruction(GotoInstruction &node) override
Dumps a GotoInstruction node.
One< Node > copy() const override
Returns a shallow copy of this node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
Version * as_version() override
Interprets this node to a node of type Version.
One< Node > clone() const override
Returns a deep copy of this node.
static std::shared_ptr< WhileLoop > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual Program * as_program()
Interprets this node to a node of type Program.
std::int64_t Int
Integer primitive used within the AST and semantic trees.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
virtual ForeachLoop * as_foreach_loop()
Interprets this node to a node of type ForeachLoop.
void visit_variable(Variable &node) override
Dumps a Variable node.
void visit_annotation_data(AnnotationData &node) override
Dumps a AnnotationData node.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
GotoInstruction * as_goto_instruction() override
Interprets this node to a node of type GotoInstruction.
One< Block > body
The body.
static std::shared_ptr< IfElseBranch > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
bool equals(const Node &rhs) const override
Value-based equality operator.
InstructionBase(const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void visit_repeat_until_loop(RepeatUntilLoop &node) override
Recursive traversal for RepeatUntilLoop nodes.
One< Node > clone() const override
Returns a deep copy of this node.
cqasm::v1::error_model::ErrorModelRef model
Error model type as registered through the API.
Main class for all nodes.
virtual Mapping * as_mapping()
Interprets this node to a node of type Mapping.
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.
A version 1.2+ assignment instruction.
void raw_visit_goto_instruction(GotoInstruction &node, void *retval) override
Internal visitor function for GotoInstruction nodes.
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.
Version number primitive used within the AST and semantic trees.
One< Node > copy() const override
Returns a shallow copy of this node.
One< Node > clone() const override
Returns a deep copy of this node.
ForLoop(const Maybe< SetInstruction > &initialize=Maybe< SetInstruction >(), const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Maybe< SetInstruction > &update=Maybe< SetInstruction >(), const One< Block > &body=One< Block >(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
ForeachLoop * as_foreach_loop() override
Interprets this node to a node of type ForeachLoop.
void write_indent()
Writes the current indentation level's worth of spaces.
void visit_mapping(Mapping &node) override
Dumps a Mapping node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
NodeType type() const override
Returns the NodeType of this node.
virtual ForLoop * as_for_loop()
Interprets this node to a node of type ForLoop.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ErrorModel is complete/fully defined.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
virtual Variable * as_variable()
Interprets this node to a node of type Variable.
One< Node > clone() const override
Returns a deep copy of this node.
void visit_repeat_until_loop(RepeatUntilLoop &node) override
Dumps a RepeatUntilLoop node.
cqasm::v1::primitives::Int frm
The first value.
One< Node > clone() const override
Returns a deep copy of this node.
static std::shared_ptr< InstructionBase > 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_error_model(ErrorModel &node, void *retval)=0
Internal visitor function for ErrorModel nodes.
A bundle of instructions, to be executed in parallel.
virtual SetInstruction * as_set_instruction()
Interprets this node to a node of type SetInstruction.
virtual IfElseBranch * as_if_else_branch()
Interprets this node to a node of type IfElseBranch.
void visit_for_loop(ForLoop &node) override
Dumps a ForLoop node.
void visit_continue_statement(ContinueStatement &node) override
Dumps a ContinueStatement node.
void visit_while_loop(WhileLoop &node) override
Dumps a WhileLoop node.
Maybe< Block > otherwise
The final else block, if any.
One< cqasm::v1::values::Node > lhs
Reference to the variable used for looping.
IfElseBranch * as_if_else_branch() override
Interprets this node to a node of type IfElseBranch.
One< Node > copy() const override
Returns a shallow copy of this node.
cqasm::v1::primitives::Int iterations
An optional integer expression representing the number of iterations for this subcircuit.
One< cqasm::v1::values::Node > condition
The condition for starting another iteration.
virtual Structured * as_structured()
Interprets this node to a node of type Structured.
static std::shared_ptr< Subcircuit > 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 GotoInstruction is complete/fully defined.
One< Node > copy() const override
Returns a shallow copy of this node.
Instruction * as_instruction() override
Interprets this node to a node of type Instruction.
Main class for all nodes.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
bool equals(const Node &rhs) const override
Value-based equality operator.
One< Node > copy() const override
Returns a shallow copy of this node.
NodeType type() const override
Returns the NodeType of this node.
void visit_bundle_ext(BundleExt &node) override
Dumps a BundleExt node.
cqasm::tree::Maybe< T > Maybe
void raw_visit_instruction_base(InstructionBase &node, void *retval) override
Internal visitor function for InstructionBase nodes.
Any version 1.2+ structured control-flow statement.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
Block * as_block() override
Interprets this node to a node of type Block.
BundleExt(const Many< InstructionBase > &items=Many< InstructionBase >(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void visit_statement(Statement &node) override
Dumps a Statement node.
One< cqasm::v1::values::Node > condition
The condition.
SetInstruction * as_set_instruction() override
Interprets this node to a node of type SetInstruction.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void raw_visit_subcircuit(Subcircuit &node, void *retval) override
Internal visitor function for Subcircuit 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 NodeType type() const =0
Returns the NodeType of this node.
Represents an annotation.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
T initialize()
Generates a default value for the given primitive type.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ForeachLoop is complete/fully defined.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void visit_bundle(Bundle &node) override
Dumps a Bundle node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void visit_annotation_data(AnnotationData &node) override
Recursive traversal for AnnotationData nodes.
void visit_structured(Structured &node) override
Dumps a Structured node.
bool equals(const Node &rhs) const override
Value-based equality operator.
void visit_instruction(Instruction &node) override
Dumps a Instruction node.
Header file for the semantic tree node classes.
GotoInstruction(const Link< Subcircuit > &target=Link< Subcircuit >(), const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
bool equals(const Node &rhs) const override
Value-based equality operator.
std::ostream & operator<<(std::ostream &os, const Node &object)
Stream << overload for tree nodes (writes debug dump).
static std::shared_ptr< RepeatUntilLoop > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_instruction_base(InstructionBase &node) override
Recursive traversal for InstructionBase nodes.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void raw_visit_instruction(Instruction &node, void *retval) override
Internal visitor function for Instruction nodes.
Bundle(const Many< Instruction > &items=Many< Instruction >(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
NodeType type() const override
Returns the NodeType of this node.
IfElseBranch(const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const One< Block > &body=One< Block >())
Constructor.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this SetInstruction is complete/fully defined.
Many< IfElseBranch > branches
The if-else branches.
NodeType type() const override
Returns the NodeType of this node.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
virtual void raw_visit_if_else_branch(IfElseBranch &node, void *retval)=0
Internal visitor function for IfElseBranch nodes.
virtual void raw_visit_mapping(Mapping &node, void *retval)=0
Internal visitor function for Mapping nodes.
Mapping(const cqasm::v1::primitives::Str &name=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const One< cqasm::v1::values::Node > &value=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
virtual void raw_visit_set_instruction(SetInstruction &node, void *retval)=0
Internal visitor function for SetInstruction nodes.
virtual Version * as_version()
Interprets this node to a node of type Version.
Namespace for the "new" cQASM 1.x API.
bool equals(const Node &rhs) const override
Value-based equality operator.
static std::shared_ptr< AnnotationData > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void raw_visit_structured(Structured &node, void *retval) override
Internal visitor function for Structured nodes.
One< cqasm::v1::values::Node > rhs
The value to assign.
void raw_visit_repeat_until_loop(RepeatUntilLoop &node, void *retval) override
Internal visitor function for RepeatUntilLoop nodes.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
cqasm::v1::primitives::Version items
The list of version components, ordered major to minor.
void raw_visit_while_loop(WhileLoop &node, void *retval) override
Internal visitor function for WhileLoop nodes.
virtual void raw_visit_goto_instruction(GotoInstruction &node, void *retval)=0
Internal visitor function for GotoInstruction nodes.
One< Node > clone() const override
Returns a deep copy of this node.
cqasm::tree::Link< T > Link
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_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
virtual WhileLoop * as_while_loop()
Interprets this node to a node of type WhileLoop.
void visit_instruction_base(InstructionBase &node) override
Dumps a InstructionBase node.
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.
Variable * as_variable() override
Interprets this node to a node of type Variable.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
ForeachLoop(const One< cqasm::v1::values::Node > &lhs=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const cqasm::v1::primitives::Int &frm=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >(), const cqasm::v1::primitives::Int &to=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >(), const One< Block > &body=One< Block >(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
One< Node > clone() const override
Returns a deep copy of this node.
One< Node > clone() const override
Returns a deep copy of this node.
cqasm::v1::primitives::Str name
The name of the variable.
The file version identifier.
Structured(const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
One< Node > clone() const override
Returns a deep copy of this node.
void raw_visit_statement(Statement &node, void *retval) override
Internal visitor function for Statement nodes.
virtual void raw_visit_break_statement(BreakStatement &node, void *retval)=0
Internal visitor function for BreakStatement nodes.
void visit_goto_instruction(GotoInstruction &node) override
Recursive traversal for GotoInstruction nodes.
Maybe< SetInstruction > initialize
The optional initializing assignment, run before the loop starts.
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.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
cqasm::v1::primitives::Str operation
The operation within the interface that this annotation is intended for.
One< Node > clone() const override
Returns a deep copy of this node.
virtual AnnotationData * as_annotation_data()
Interprets this node to a node of type AnnotationData.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
One< cqasm::v1::values::Node > value
The value it maps to.
void raw_visit_version(Version &node, void *retval) override
Internal visitor function for Version nodes.
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.
static std::shared_ptr< ForLoop > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
static std::shared_ptr< SetInstruction > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_node(Node &node) override
Dumps a Node.
Statement * as_statement() override
Interprets this node to a node of type Statement.
Subcircuit * as_subcircuit() override
Interprets this node to a node of type Subcircuit.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
One< cqasm::v1::types::Node > typ
The type of the variable.
A single condition + block for use in an if-else chain.
bool equals(const Node &rhs) const override
Value-based equality operator.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
std::string Str
String primitive used within the AST and semantic trees.
Many< Instruction > items
The list of parallel instructions.
WhileLoop(const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const One< Block > &body=One< Block >(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
One< Node > copy() const override
Returns a shallow copy of this node.
void raw_visit_program(Program &node, void *retval) override
Internal visitor function for Program nodes.
cqasm::v1::primitives::Int num_qubits
The required qubit register size.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Block is complete/fully defined.
One< Block > body
The loop body.
bool equals(const Node &rhs) const override
Value-based equality operator.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this IfElse is complete/fully defined.
Any< Bundle > bundles
The instruction bundles contained by this subcircuit.
IfElse(const Many< IfElseBranch > &branches=Many< IfElseBranch >(), const Maybe< Block > &otherwise=Maybe< Block >(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
void raw_visit_if_else(IfElse &node, void *retval) override
Internal visitor function for IfElse nodes.
Mapping * as_mapping() override
Interprets this node to a node of type Mapping.
cqasm::v1::primitives::Version api_version
API version.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void raw_visit_bundle(Bundle &node, void *retval) override
Internal visitor function for Bundle nodes.
virtual Subcircuit * as_subcircuit()
Interprets this node to a node of type Subcircuit.
Maybe< Block > body
The statements contained by this subcircuit.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
static std::shared_ptr< BreakStatement > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_continue_statement(ContinueStatement &node) override
Recursive traversal for ContinueStatement nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
Instruction(const cqasm::v1::instruction::InstructionRef &instruction=cqasm::v1::primitives::initialize< cqasm::v1::instruction::InstructionRef >(), const cqasm::v1::primitives::Str &name=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const One< cqasm::v1::values::Node > &condition=cqasm::v1::primitives::initialize< One< cqasm::v1::values::Node >>(), const Any< cqasm::v1::values::Node > &operands=cqasm::v1::primitives::initialize< Any< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
Maybe< SetInstruction > update
The updating assignment, done at the end of the loop body and upon continue.
void raw_visit_mapping(Mapping &node, void *retval) override
Internal visitor function for Mapping nodes.
NodeType type() const override
Returns the NodeType of this node.
void raw_visit_continue_statement(ContinueStatement &node, void *retval) override
Internal visitor function for ContinueStatement nodes.
static std::shared_ptr< Node > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void dump(std::ostream &out=std::cout, int indent=0)
Writes a debug dump of this node to the given stream.
NodeType type() const override
Returns the NodeType of this node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Variable 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_variable(Variable &node, void *retval)=0
Internal visitor function for Variable nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
void 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.
Any< Mapping > mappings
The list of all user-defined mappings after parsing.
Any< AnnotationData > annotations
Zero or more annotations attached to this object.
virtual void raw_visit_while_loop(WhileLoop &node, void *retval)=0
Internal visitor function for WhileLoop nodes.
Any version 1.2+ structured control-flow statement.
virtual void raw_visit_for_loop(ForLoop &node, void *retval)=0
Internal visitor function for ForLoop nodes.
virtual void raw_visit_instruction(Instruction &node, void *retval)=0
Internal visitor function for Instruction nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
void dump_seq(std::ostream &out=std::cout, int indent=0)
Alternate debug dump that represents links and node uniqueness via sequence number tags...
NodeType type() const override
Returns the NodeType of this node.
bool equals(const Node &rhs) const override
Value-based equality operator.
A version 1.2+ goto instruction.
void raw_visit_annotated(Annotated &node, void *retval) override
Internal visitor function for Annotated nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
static std::shared_ptr< Program > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual bool equals(const Node &rhs) const =0
Value-based equality operator.
One< cqasm::v1::values::Node > condition
The condition for starting another iteration.
void visit_variable(Variable &node) override
Recursive traversal for Variable nodes.
NodeType type() const override
Returns the NodeType of this node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this RepeatUntilLoop is complete/fully defined.
NodeType type() const override
Returns the NodeType of this node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Version is complete/fully defined.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void visit_error_model(ErrorModel &node) override
Dumps a ErrorModel node.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
Represents an annotation.
One< Block > body
The loop body.
NodeType type() const override
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.
Version(const cqasm::v1::primitives::Version &items=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Version >())
Constructor.
Any< cqasm::v1::values::Node > operands
Operands for the instruction.
Bundle * as_bundle() override
Interprets this node to a node of type Bundle.
static std::shared_ptr< Mapping > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual ErrorModel * as_error_model()
Interprets this node to a node of type ErrorModel.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
bool equals(const Node &rhs) const override
Value-based equality operator.
cqasm::tree::Many< T > Many
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this ContinueStatement is complete/fully defined.
void visit_program(Program &node) override
Recursive traversal for Program nodes.
void visit_annotated(Annotated &node) override
Recursive traversal for Annotated nodes.
Link< Subcircuit > target
Link to the target subcircuit, used as a label.
Program(const One< Version > &version=One< Version >(), const cqasm::v1::primitives::Int &num_qubits=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Int >(), const Maybe< ErrorModel > &error_model=Maybe< ErrorModel >(), const Any< Subcircuit > &subcircuits=Any< Subcircuit >(), const Any< Mapping > &mappings=Any< Mapping >(), const Any< Variable > &variables=Any< Variable >(), const cqasm::v1::primitives::Version &api_version=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Version >())
Constructor.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
cqasm::v1::primitives::Str name
The name of the mapping.
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.
virtual void raw_visit_if_else(IfElse &node, void *retval)=0
Internal visitor function for IfElse nodes.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void raw_visit_bundle_ext(BundleExt &node, void *retval) override
Internal visitor function for BundleExt nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
virtual Annotated * as_annotated()
Interprets this node to a node of type Annotated.
One< cqasm::v1::values::Node > condition
The condition for stopping iteration.
void visit_subcircuit(Subcircuit &node) override
Recursive traversal for Subcircuit nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
virtual Statement * as_statement()
Interprets this node to a node of type Statement.
void visit_if_else(IfElse &node) override
Dumps a IfElse node.
void visit_set_instruction(SetInstruction &node) override
Recursive traversal for SetInstruction nodes.
One< Node > copy() const override
Returns a shallow copy of this node.
void raw_visit_if_else_branch(IfElseBranch &node, void *retval) override
Internal visitor function for IfElseBranch nodes.
Represents a node that carries annotation data.
virtual void raw_visit_version(Version &node, void *retval)=0
Internal visitor function for Version nodes.
bool equals(const Node &rhs) const override
Value-based equality operator.
Any< Statement > statements
The statements contained by the block.
One< Node > copy() const override
Returns a shallow copy of this node.
A bundle of instructions, to be executed in parallel.
BreakStatement * as_break_statement() override
Interprets this node to a node of type BreakStatement.
void visit_internal(VisitorBase &visitor, void *retval) override
Helper method for visiting nodes.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Instruction is complete/fully defined.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
Maybe< ErrorModel > error_model
Error model information.
static std::shared_ptr< GotoInstruction > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_if_else_branch(IfElseBranch &node) override
Recursive traversal for IfElseBranch nodes.
static std::shared_ptr< Block > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
virtual RepeatUntilLoop * as_repeat_until_loop()
Interprets this node to a node of type RepeatUntilLoop.
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.
One< Block > body
The loop body.
One< Node > clone() const override
Returns a deep copy of this node.
bool operator==(const Node &rhs) const override
Pointer-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.
void visit_bundle_ext(BundleExt &node) override
Recursive traversal for BundleExt nodes.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void visit_instruction(Instruction &node) override
Recursive traversal for Instruction nodes.
Annotated * as_annotated() override
Interprets this node to a node of type Annotated.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
void visit_bundle(Bundle &node) override
Recursive traversal for Bundle nodes.
virtual ContinueStatement * as_continue_statement()
Interprets this node to a node of type ContinueStatement.
void visit_break_statement(BreakStatement &node) override
Recursive traversal for BreakStatement nodes.
void serialize(::tree::cbor::MapWriter &map, const ::tree::base::PointerMap &ids) const override
Serializes this node to the given map.
bool equals(const Node &rhs) const override
Value-based equality operator.
ErrorModel(const cqasm::v1::error_model::ErrorModelRef &model=cqasm::v1::primitives::initialize< cqasm::v1::error_model::ErrorModelRef >(), const cqasm::v1::primitives::Str &name=cqasm::v1::primitives::initialize< cqasm::v1::primitives::Str >(), const Any< cqasm::v1::values::Node > ¶meters=cqasm::v1::primitives::initialize< Any< cqasm::v1::values::Node >>(), const Any< AnnotationData > &annotations=Any< AnnotationData >())
Constructor.
static std::shared_ptr< Version > deserialize(const ::tree::cbor::MapReader &map, ::tree::base::IdentifierMap &ids)
Deserializes the given node.
void visit_foreach_loop(ForeachLoop &node) override
Dumps a ForeachLoop node.
void check_complete(const ::tree::base::PointerMap &map) const override
Returns whether this Mapping is complete/fully defined.
void find_reachable(::tree::base::PointerMap &map) const override
Registers all reachable nodes with the given PointerMap.
One< Node > copy() const override
Returns a shallow copy of this node.
virtual void raw_visit_program(Program &node, void *retval)=0
Internal visitor function for Program nodes.
bool operator==(const Node &rhs) const override
Pointer-based equality operator.
void visit_break_statement(BreakStatement &node) override
Dumps a BreakStatement node.
void visit_set_instruction(SetInstruction &node) override
Dumps a SetInstruction node.