From 0d24e5b384f3f1f597e6c044f3b1a8ab1da54b01 Mon Sep 17 00:00:00 2001 From: fruffy Date: Mon, 27 Mar 2023 09:21:48 -0400 Subject: [PATCH 1/2] Replace boost::optional. --- backends/bmv2/common/helpers.h | 18 ++-- .../control-plane/bfruntime_arch_handler.h | 9 +- backends/dpdk/control-plane/bfruntime_ext.cpp | 16 ++-- backends/dpdk/control-plane/bfruntime_ext.h | 6 +- backends/dpdk/dpdkArch.cpp | 10 +-- backends/dpdk/dpdkProgram.cpp | 22 ++--- backends/dpdk/dpdkProgram.h | 4 +- backends/graphs/controls.cpp | 8 +- backends/graphs/controls.h | 2 +- backends/graphs/graphs.cpp | 4 +- backends/graphs/graphs.h | 4 +- backends/graphs/parsers.h | 2 +- .../common/compiler/compiler_target.cpp | 18 ++-- .../p4tools/common/compiler/compiler_target.h | 17 ++-- backends/p4tools/common/core/solver.h | 7 +- backends/p4tools/common/core/target.cpp | 5 +- backends/p4tools/common/core/target.h | 8 +- backends/p4tools/common/core/z3_solver.cpp | 10 +-- backends/p4tools/common/core/z3_solver.h | 12 ++- backends/p4tools/common/lib/util.cpp | 14 ++-- backends/p4tools/common/lib/util.h | 11 ++- backends/p4tools/common/options.cpp | 18 ++-- backends/p4tools/common/options.h | 10 +-- .../p4tools/modules/testgen/core/externs.cpp | 5 +- .../modules/testgen/core/program_info.cpp | 2 +- .../modules/testgen/core/program_info.h | 8 +- .../core/small_step/abstract_stepper.cpp | 9 +- .../core/small_step/abstract_stepper.h | 5 +- .../testgen/core/small_step/cmd_stepper.cpp | 8 +- .../testgen/core/small_step/cmd_stepper.h | 7 +- .../core/small_step/extern_stepper.cpp | 5 +- .../testgen/core/small_step/small_step.cpp | 11 ++- .../testgen/core/small_step/small_step.h | 7 +- .../testgen/core/small_step/table_stepper.cpp | 10 +-- .../testgen/core/small_step/table_stepper.h | 5 +- .../core/symbolic_executor/depth_first.cpp | 3 +- .../core/symbolic_executor/depth_first.h | 3 +- .../symbolic_executor/greedy_stmt_cov.cpp | 3 +- .../core/symbolic_executor/greedy_stmt_cov.h | 2 - .../core/symbolic_executor/max_stmt_cov.cpp | 7 +- .../core/symbolic_executor/max_stmt_cov.h | 3 +- .../symbolic_executor/random_backtrack.cpp | 3 +- .../core/symbolic_executor/random_backtrack.h | 3 +- .../symbolic_executor/selected_branches.h | 3 +- .../symbolic_executor/symbolic_executor.cpp | 9 +- .../symbolic_executor/symbolic_executor.h | 3 +- .../p4tools/modules/testgen/core/target.h | 7 +- .../p4tools/modules/testgen/lib/concolic.cpp | 5 +- .../modules/testgen/lib/continuation.cpp | 2 +- .../modules/testgen/lib/continuation.h | 22 ++--- .../modules/testgen/lib/execution_state.cpp | 24 +++--- .../modules/testgen/lib/execution_state.h | 11 ++- .../modules/testgen/lib/namespace_context.h | 5 +- .../modules/testgen/lib/test_backend.cpp | 2 +- .../p4tools/modules/testgen/lib/test_spec.cpp | 8 +- .../p4tools/modules/testgen/lib/test_spec.h | 8 +- backends/p4tools/modules/testgen/lib/tf.cpp | 4 +- backends/p4tools/modules/testgen/lib/tf.h | 6 +- .../bmv2/backend/metadata/metadata.cpp | 6 +- .../targets/bmv2/backend/metadata/metadata.h | 4 +- .../bmv2/backend/protobuf/protobuf.cpp | 22 ++--- .../targets/bmv2/backend/protobuf/protobuf.h | 12 +-- .../testgen/targets/bmv2/backend/ptf/ptf.cpp | 6 +- .../testgen/targets/bmv2/backend/ptf/ptf.h | 4 +- .../testgen/targets/bmv2/backend/stf/stf.cpp | 6 +- .../testgen/targets/bmv2/backend/stf/stf.h | 4 +- .../testgen/targets/bmv2/cmd_stepper.cpp | 7 +- .../testgen/targets/bmv2/cmd_stepper.h | 7 +- .../testgen/targets/bmv2/expr_stepper.cpp | 7 +- .../targets/bmv2/p4_asserts_parser.cpp | 2 +- .../testgen/targets/bmv2/program_info.cpp | 3 +- .../testgen/targets/bmv2/table_stepper.cpp | 7 +- .../modules/testgen/targets/bmv2/target.cpp | 2 +- .../modules/testgen/targets/bmv2/target.h | 4 +- .../testgen/targets/bmv2/test_backend.cpp | 7 +- .../testgen/targets/bmv2/test_backend.h | 5 +- .../testgen/targets/ebpf/backend/stf/stf.cpp | 6 +- .../testgen/targets/ebpf/backend/stf/stf.h | 4 +- .../testgen/targets/ebpf/cmd_stepper.cpp | 7 +- .../testgen/targets/ebpf/cmd_stepper.h | 7 +- .../testgen/targets/ebpf/program_info.cpp | 3 +- .../testgen/targets/ebpf/table_stepper.cpp | 7 +- .../modules/testgen/targets/ebpf/target.cpp | 2 +- .../modules/testgen/targets/ebpf/target.h | 5 +- .../testgen/targets/ebpf/test_backend.cpp | 19 ++--- .../testgen/targets/ebpf/test_backend.h | 18 +--- .../modules/testgen/test/gtest_utils.cpp | 18 ++-- .../modules/testgen/test/gtest_utils.h | 21 +++-- .../testgen/test/small-step/binary.cpp | 3 +- .../modules/testgen/test/small-step/unary.cpp | 3 +- .../modules/testgen/test/small-step/util.cpp | 4 +- .../modules/testgen/test/small-step/util.h | 6 +- .../modules/testgen/test/small-step/value.cpp | 3 +- .../transformations/saturation_arithm.cpp | 3 +- .../modules/testgen/test/z3-solver/accessor.h | 2 +- .../testgen/test/z3-solver/asrt_model.cpp | 2 +- .../testgen/test/z3-solver/expressions.cpp | 3 +- backends/p4tools/modules/testgen/testgen.cpp | 3 +- control-plane/bfruntime.cpp | 54 ++++++------ control-plane/bfruntime.h | 48 ++++++----- control-plane/bytestrings.cpp | 8 +- control-plane/bytestrings.h | 9 +- control-plane/p4RuntimeArchHandler.cpp | 20 ++--- control-plane/p4RuntimeArchHandler.h | 52 ++++++------ control-plane/p4RuntimeArchStandard.cpp | 13 ++- control-plane/p4RuntimeArchStandard.h | 75 +++++++++-------- control-plane/p4RuntimeSerializer.cpp | 82 +++++++++---------- control-plane/p4RuntimeSymbolTable.cpp | 22 ++--- control-plane/p4RuntimeSymbolTable.h | 14 ++-- frontends/common/applyOptionsPragmas.cpp | 12 +-- frontends/common/applyOptionsPragmas.h | 9 +- frontends/common/parseInput.cpp | 3 +- frontends/common/parseInput.h | 2 +- frontends/p4/externInstance.cpp | 26 +++--- frontends/p4/externInstance.h | 22 ++--- frontends/p4/typeChecking/typeConstraints.h | 2 +- ir/json_generator.h | 5 +- ir/json_loader.h | 7 +- test/gtest/complex_bitwise.cpp | 4 +- test/gtest/diagnostics.cpp | 8 +- test/gtest/helpers.cpp | 14 ++-- test/gtest/helpers.h | 6 +- test/gtest/p4runtime.cpp | 32 ++++---- 123 files changed, 593 insertions(+), 683 deletions(-) diff --git a/backends/bmv2/common/helpers.h b/backends/bmv2/common/helpers.h index 0c08ecd1f90..5699d74e2e1 100644 --- a/backends/bmv2/common/helpers.h +++ b/backends/bmv2/common/helpers.h @@ -126,12 +126,12 @@ struct RegisterTraits { // the index of the type parameter for the data stored in the register, in // the type parameter list of the extern type declaration static size_t dataTypeParamIdx() { return 0; } - static boost::optional indexTypeParamIdx() { return boost::none; } + static std::optional indexTypeParamIdx() { return std::nullopt; } }; template <> struct RegisterTraits : public RegisterTraits { - static boost::optional indexTypeParamIdx() { return 1; } + static std::optional indexTypeParamIdx() { return 1; } }; template <> @@ -142,7 +142,7 @@ struct RegisterTraits { static size_t dataTypeParamIdx() { return 0; } // the index of the type parameter for the register index, in the type // parameter list of the extern type declaration. - static boost::optional indexTypeParamIdx() { return 1; } + static std::optional indexTypeParamIdx() { return 1; } }; template @@ -181,7 +181,7 @@ struct CounterlikeTraits> { static const cstring typeName() { return P4V1::V1Model::instance.counter.name; } static const cstring directTypeName() { return P4V1::V1Model::instance.directCounter.name; } static const cstring sizeParamName() { return "size"; } - static boost::optional indexTypeParamIdx() { return boost::none; } + static std::optional indexTypeParamIdx() { return std::nullopt; } }; template <> @@ -193,7 +193,7 @@ struct CounterlikeTraits> { static const cstring typeName() { return P4V1::V1Model::instance.counter.name; } static const cstring directTypeName() { return P4V1::V1Model::instance.directCounter.name; } static const cstring sizeParamName() { return "size"; } - static boost::optional indexTypeParamIdx() { return 0; } + static std::optional indexTypeParamIdx() { return 0; } }; /// @ref CounterlikeTraits<> specialization for @ref CounterExtern for PSA @@ -206,7 +206,7 @@ struct CounterlikeTraits> { static const cstring sizeParamName() { return "n_counters"; } // the index of the type parameter for the counter index, in the type // parameter list of the extern type declaration. - static boost::optional indexTypeParamIdx() { return 1; } + static std::optional indexTypeParamIdx() { return 1; } }; /// @ref CounterlikeTraits<> specialization for @ref MeterExtern for v1model @@ -219,7 +219,7 @@ struct CounterlikeTraits> { static const cstring typeName() { return P4V1::V1Model::instance.meter.name; } static const cstring directTypeName() { return P4V1::V1Model::instance.directMeter.name; } static const cstring sizeParamName() { return "size"; } - static boost::optional indexTypeParamIdx() { return boost::none; } + static std::optional indexTypeParamIdx() { return std::nullopt; } }; template <> @@ -231,7 +231,7 @@ struct CounterlikeTraits> { static const cstring typeName() { return P4V1::V1Model::instance.meter.name; } static const cstring directTypeName() { return P4V1::V1Model::instance.directMeter.name; } static const cstring sizeParamName() { return "size"; } - static boost::optional indexTypeParamIdx() { return 0; } + static std::optional indexTypeParamIdx() { return 0; } }; /// @ref CounterlikeTraits<> specialization for @ref MeterExtern for PSA @@ -244,7 +244,7 @@ struct CounterlikeTraits> { static const cstring sizeParamName() { return "n_meters"; } // the index of the type parameter for the meter index, in the type // parameter list of the extern type declaration. - static boost::optional indexTypeParamIdx() { return 0; } + static std::optional indexTypeParamIdx() { return 0; } }; } // namespace Helpers diff --git a/backends/dpdk/control-plane/bfruntime_arch_handler.h b/backends/dpdk/control-plane/bfruntime_arch_handler.h index 80a73bda8a2..9ecc3e2b748 100644 --- a/backends/dpdk/control-plane/bfruntime_arch_handler.h +++ b/backends/dpdk/control-plane/bfruntime_arch_handler.h @@ -16,12 +16,11 @@ limitations under the License. #define DPDK_CONTROL_PLANE_BFRUNTIME_ARCH_HANDLER_H_ #include +#include #include #include #include -#include - #include "control-plane/bfruntime.h" #include "control-plane/p4RuntimeArchHandler.h" #include "control-plane/p4RuntimeArchStandard.h" @@ -163,7 +162,7 @@ class BFRuntimeArchHandler : public P4RuntimeArchHandlerCommon { externInstance->mutable_info()->PackFrom(message); } - boost::optional getActionSelector(const IR::ExternBlock *instance) { + std::optional getActionSelector(const IR::ExternBlock *instance) { auto actionSelDecl = instance->node->to(); // to be deleted, used to support deprecated ActionSelector constructor. auto size = instance->getParameterValue("size"); @@ -295,8 +294,8 @@ class BFRuntimeArchHandler : public P4RuntimeArchHandlerCommon { } /// @return serialization information for the Digest extern instacne @decl - boost::optional getDigest(const IR::Declaration_Instance *decl, - p4configv1::P4TypeInfo *p4RtTypeInfo) { + std::optional getDigest(const IR::Declaration_Instance *decl, + p4configv1::P4TypeInfo *p4RtTypeInfo) { BUG_CHECK(decl->type->is(), "%1%: expected Type_Specialized", decl->type); auto type = decl->type->to(); diff --git a/backends/dpdk/control-plane/bfruntime_ext.cpp b/backends/dpdk/control-plane/bfruntime_ext.cpp index 15adbc9c5eb..2716e3882b6 100644 --- a/backends/dpdk/control-plane/bfruntime_ext.cpp +++ b/backends/dpdk/control-plane/bfruntime_ext.cpp @@ -30,14 +30,14 @@ struct BFRuntimeSchemaGenerator::ActionSelector { std::vector tableIds; Util::JsonArray *annotations; - static boost::optional fromDPDK( + static std::optional fromDPDK( const p4configv1::P4Info &p4info, const p4configv1::ExternInstance &externInstance) { const auto &pre = externInstance.preamble(); ::dpdk::ActionSelector actionSelector; if (!externInstance.info().UnpackTo(&actionSelector)) { ::error(ErrorType::ERR_NOT_FOUND, "Extern instance %1% does not pack an ActionSelector object", pre.name()); - return boost::none; + return std::nullopt; } auto selectorId = makeBFRuntimeId(pre.id(), ::dpdk::P4Ids::ACTION_SELECTOR); auto selectorGetMemId = @@ -163,7 +163,7 @@ bool BFRuntimeSchemaGenerator::addActionProfIds(const p4configv1::Table &table, auto actProfId = static_cast(0); if (implementationId > 0) { auto hasSelector = actProfHasSelector(implementationId); - if (hasSelector == boost::none) { + if (hasSelector == std::nullopt) { ::error(ErrorType::ERR_INVALID, "Invalid implementation id in p4info: %1%", implementationId); return false; @@ -187,20 +187,20 @@ bool BFRuntimeSchemaGenerator::addActionProfIds(const p4configv1::Table &table, void BFRuntimeSchemaGenerator::addActionProfs(Util::JsonArray *tablesJson) const { for (const auto &actionProf : p4info.action_profiles()) { auto actionProfInstance = ActionProf::from(p4info, actionProf); - if (actionProfInstance == boost::none) continue; + if (actionProfInstance == std::nullopt) continue; addActionProfCommon(tablesJson, *actionProfInstance); } } -boost::optional BFRuntimeSchemaGenerator::actProfHasSelector(P4Id actProfId) const { +std::optional BFRuntimeSchemaGenerator::actProfHasSelector(P4Id actProfId) const { if (isOfType(actProfId, p4configv1::P4Ids::ACTION_PROFILE)) { auto *actionProf = Standard::findActionProf(p4info, actProfId); - if (actionProf == nullptr) return boost::none; + if (actionProf == nullptr) return std::nullopt; return actionProf->with_selector(); } else if (isOfType(actProfId, ::dpdk::P4Ids::ACTION_SELECTOR)) { return true; } - return boost::none; + return std::nullopt; } const Util::JsonObject *BFRuntimeSchemaGenerator::genSchema() const { @@ -249,7 +249,7 @@ void BFRuntimeSchemaGenerator::addDPDKExterns(Util::JsonArray *tablesJson, if (externTypeId == ::dpdk::P4Ids::ACTION_SELECTOR) { for (const auto &externInstance : externType.instances()) { auto actionSelector = ActionSelector::fromDPDK(p4info, externInstance); - if (actionSelector != boost::none) { + if (actionSelector != std::nullopt) { addActionSelectorCommon(tablesJson, *actionSelector); addActionSelectorGetMemberCommon(tablesJson, *actionSelector); } diff --git a/backends/dpdk/control-plane/bfruntime_ext.h b/backends/dpdk/control-plane/bfruntime_ext.h index 3b2d1e9c887..96aef12ac3e 100644 --- a/backends/dpdk/control-plane/bfruntime_ext.h +++ b/backends/dpdk/control-plane/bfruntime_ext.h @@ -72,16 +72,16 @@ class BFRuntimeSchemaGenerator : public BFRuntimeGenerator { void addMatchActionData(const p4configv1::Table &table, Util::JsonObject *tableJson, Util::JsonArray *dataJson, P4Id maxActionParamId) const; - boost::optional actProfHasSelector(P4Id actProfId) const override; + std::optional actProfHasSelector(P4Id actProfId) const override; - static boost::optional fromDPDKActionProfile( + static std::optional fromDPDKActionProfile( const p4configv1::P4Info &p4info, const p4configv1::ExternInstance &externInstance) { const auto &pre = externInstance.preamble(); p4configv1::ActionProfile actionProfile; if (!externInstance.info().UnpackTo(&actionProfile)) { ::error(ErrorType::ERR_NOT_FOUND, "Extern instance %1% does not pack an ActionProfile object", pre.name()); - return boost::none; + return std::nullopt; } auto tableIds = collectTableIds(p4info, actionProfile.table_ids().begin(), actionProfile.table_ids().end()); diff --git a/backends/dpdk/dpdkArch.cpp b/backends/dpdk/dpdkArch.cpp index 9bf631d0c87..91efd60cd9e 100644 --- a/backends/dpdk/dpdkArch.cpp +++ b/backends/dpdk/dpdkArch.cpp @@ -1719,16 +1719,16 @@ const IR::Node *CopyMatchKeysToSingleStruct::doStatement(const IR::Statement *st namespace Helpers { -boost::optional getExternInstanceFromProperty( +std::optional getExternInstanceFromProperty( const IR::P4Table *table, const cstring &propertyName, P4::ReferenceMap *refMap, P4::TypeMap *typeMap, bool *isConstructedInPlace, cstring &externName) { auto property = table->properties->getProperty(propertyName); - if (property == nullptr) return boost::none; + if (property == nullptr) return std::nullopt; if (!property->value->is()) { ::error(ErrorType::ERR_EXPECTED, "Expected %1% property value for table %2% to be an expression: %3%", propertyName, table->controlPlaneName(), property); - return boost::none; + return std::nullopt; } auto expr = property->value->to()->expression; @@ -1740,7 +1740,7 @@ boost::optional getExternInstanceFromProperty( "Table '%1%' has an anonymous table property '%2%' with no name annotation, " "which is not supported by P4Runtime", table->controlPlaneName(), propertyName); - return boost::none; + return std::nullopt; } auto name = property->controlPlaneName(); auto externInstance = P4::ExternInstance::resolve(expr, refMap, typeMap, name); @@ -1749,7 +1749,7 @@ boost::optional getExternInstanceFromProperty( "Expected %1% property value for table %2% to resolve to an " "extern instance: %3%", propertyName, table->controlPlaneName(), property); - return boost::none; + return std::nullopt; } return externInstance; } diff --git a/backends/dpdk/dpdkProgram.cpp b/backends/dpdk/dpdkProgram.cpp index c25259dd9da..f038d400272 100644 --- a/backends/dpdk/dpdkProgram.cpp +++ b/backends/dpdk/dpdkProgram.cpp @@ -545,43 +545,43 @@ bool ConvertToDpdkControl::checkTableValid(const IR::P4Table *a) { return true; } -boost::optional ConvertToDpdkControl::getMemExprFromProperty( +std::optional ConvertToDpdkControl::getMemExprFromProperty( const IR::P4Table *table, cstring propertyName) { auto property = table->properties->getProperty(propertyName); - if (property == nullptr) return boost::none; + if (property == nullptr) return std::nullopt; if (!property->value->is()) { ::error(ErrorType::ERR_EXPECTED, "Expected %1% property value for table %2% to be an expression: %3%", propertyName, table->controlPlaneName(), property); - return boost::none; + return std::nullopt; } auto expr = property->value->to()->expression; if (!expr->is()) { ::error(ErrorType::ERR_EXPECTED, "Exprected %1% property value for table %2% to be a member", propertyName, table->controlPlaneName()); - return boost::none; + return std::nullopt; } return expr->to(); } -boost::optional ConvertToDpdkControl::getNumberFromProperty(const IR::P4Table *table, - cstring propertyName) { +std::optional ConvertToDpdkControl::getNumberFromProperty(const IR::P4Table *table, + cstring propertyName) { auto property = table->properties->getProperty(propertyName); - if (property == nullptr) return boost::none; + if (property == nullptr) return std::nullopt; if (!property->value->is()) { ::error(ErrorType::ERR_EXPECTED, "Expected %1% property value for table %2% to be an expression: %3%", propertyName, table->controlPlaneName(), property); - return boost::none; + return std::nullopt; } auto expr = property->value->to()->expression; if (!expr->is()) { ::error(ErrorType::ERR_EXPECTED, "Exprected %1% property value for table %2% to be a constant", propertyName, table->controlPlaneName()); - return boost::none; + return std::nullopt; } return expr->to()->asInt(); @@ -597,8 +597,8 @@ bool ConvertToDpdkControl::preorder(const IR::P4Table *t) { auto n_groups_max = getNumberFromProperty(t, "n_groups_max"); auto n_members_per_group_max = getNumberFromProperty(t, "n_members_per_group_max"); - if (group_id == boost::none || member_id == boost::none || n_groups_max == boost::none || - n_members_per_group_max == boost::none) + if (group_id == std::nullopt || member_id == std::nullopt || n_groups_max == std::nullopt || + n_members_per_group_max == std::nullopt) return false; auto selector = new IR::DpdkSelector(t->name, (*group_id)->clone(), (*member_id)->clone(), diff --git a/backends/dpdk/dpdkProgram.h b/backends/dpdk/dpdkProgram.h index f429f22dc3d..36b85efd5d3 100644 --- a/backends/dpdk/dpdkProgram.h +++ b/backends/dpdk/dpdkProgram.h @@ -122,8 +122,8 @@ class ConvertToDpdkControl : public Inspector { void add_table(const IR::DpdkLearner *s) { learners.push_back(s); } void add_action(const IR::DpdkAction *a) { actions.push_back(a); } - boost::optional getMemExprFromProperty(const IR::P4Table *, cstring); - boost::optional getNumberFromProperty(const IR::P4Table *, cstring); + std::optional getMemExprFromProperty(const IR::P4Table *, cstring); + std::optional getNumberFromProperty(const IR::P4Table *, cstring); }; class CollectActionUses : public Inspector { diff --git a/backends/graphs/controls.cpp b/backends/graphs/controls.cpp index d4aeb1b8896..4539b727b62 100644 --- a/backends/graphs/controls.cpp +++ b/backends/graphs/controls.cpp @@ -82,7 +82,7 @@ bool ControlGraphs::preorder(const IR::PackageBlock *block) { Graph *g_ = new Graph(); g = g_; - instanceName = boost::none; + instanceName = std::nullopt; boost::get_property(*g_, boost::graph_name) = name; BUG_CHECK(controlStack.isEmpty(), "Invalid control stack state"); g = controlStack.pushBack(*g_, ""); @@ -111,9 +111,9 @@ bool ControlGraphs::preorder(const IR::ControlBlock *block) { bool ControlGraphs::preorder(const IR::P4Control *cont) { bool doPop = false; - // instanceName == boost::none <=> top level - if (instanceName != boost::none) { - g = controlStack.pushBack(*g, instanceName.get()); + // instanceName == std::nullopt <=> top level + if (instanceName != std::nullopt) { + g = controlStack.pushBack(*g, instanceName.value()); doPop = true; } return_parents.clear(); diff --git a/backends/graphs/controls.h b/backends/graphs/controls.h index 3b3a8c519bd..07750e7ee53 100644 --- a/backends/graphs/controls.h +++ b/backends/graphs/controls.h @@ -63,7 +63,7 @@ class ControlGraphs : public Graphs { // new subgraph and push it to the stack; this new graph becomes the // "current graph" to which we add vertices (e.g. tables). ControlStack controlStack{}; - boost::optional instanceName{}; + std::optional instanceName{}; }; } // namespace graphs diff --git a/backends/graphs/graphs.cpp b/backends/graphs/graphs.cpp index 3c805df4f80..06c3be4879e 100644 --- a/backends/graphs/graphs.cpp +++ b/backends/graphs/graphs.cpp @@ -58,8 +58,8 @@ void Graphs::limitStringSize(std::stringstream &sstream, std::stringstream &help helper_sstream.clear(); } -boost::optional Graphs::merge_other_statements_into_vertex() { - if (statementsStack.empty()) return boost::none; +std::optional Graphs::merge_other_statements_into_vertex() { + if (statementsStack.empty()) return std::nullopt; std::stringstream sstream; std::stringstream helper_sstream; // to limit line width diff --git a/backends/graphs/graphs.h b/backends/graphs/graphs.h index 440c9f7f7d1..d08bb888c99 100644 --- a/backends/graphs/graphs.h +++ b/backends/graphs/graphs.h @@ -26,13 +26,13 @@ limitations under the License. #endif #include +#include #include // std::pair #include #include #include #include -#include #include "frontends/p4/parserCallGraph.h" #include "ir/ir.h" @@ -135,7 +135,7 @@ class Graphs : public Inspector { // merge misc control statements (action calls, extern method calls, // assignments) into a single vertex to reduce graph complexity - boost::optional merge_other_statements_into_vertex(); + std::optional merge_other_statements_into_vertex(); vertex_t add_vertex(const cstring &name, VertexType type); vertex_t add_and_connect_vertex(const cstring &name, VertexType type); diff --git a/backends/graphs/parsers.h b/backends/graphs/parsers.h index efb8499d3d4..2f593ef8575 100644 --- a/backends/graphs/parsers.h +++ b/backends/graphs/parsers.h @@ -56,7 +56,7 @@ class ParserGraphs : public Graphs { private: P4::ReferenceMap *refMap; const cstring graphsDir; - boost::optional instanceName{}; + std::optional instanceName{}; }; } // namespace graphs diff --git a/backends/p4tools/common/compiler/compiler_target.cpp b/backends/p4tools/common/compiler/compiler_target.cpp index 4f12d818300..0ec597a02f6 100644 --- a/backends/p4tools/common/compiler/compiler_target.cpp +++ b/backends/p4tools/common/compiler/compiler_target.cpp @@ -3,8 +3,6 @@ #include #include -#include - #include "backends/p4tools/common/compiler/configuration.h" #include "backends/p4tools/common/compiler/context.h" #include "backends/p4tools/common/compiler/convert_hs_index.h" @@ -26,40 +24,40 @@ std::vector *CompilerTarget::initCompiler(int argc, char **argv) { return get().initCompiler_impl(argc, argv); } -boost::optional CompilerTarget::runCompiler() { +std::optional CompilerTarget::runCompiler() { const auto *program = P4Tools::CompilerTarget::runParser(); if (program == nullptr) { - return boost::none; + return std::nullopt; } return runCompiler(program); } -boost::optional CompilerTarget::runCompiler(const std::string &source) { +std::optional CompilerTarget::runCompiler(const std::string &source) { const auto *program = P4::parseP4String(source, P4CContext::get().options().langVersion); if (program == nullptr) { - return boost::none; + return std::nullopt; } return runCompiler(program); } -boost::optional CompilerTarget::runCompiler(const IR::P4Program *program) { +std::optional CompilerTarget::runCompiler(const IR::P4Program *program) { return get().runCompiler_impl(program); } -boost::optional CompilerTarget::runCompiler_impl( +std::optional CompilerTarget::runCompiler_impl( const IR::P4Program *program) const { const auto &self = get(); program = self.runFrontend(program); if (program == nullptr) { - return boost::none; + return std::nullopt; } program = self.runMidEnd(program); if (program == nullptr) { - return boost::none; + return std::nullopt; } // Rewrite all occurrences of ArrayIndex to be members instead. diff --git a/backends/p4tools/common/compiler/compiler_target.h b/backends/p4tools/common/compiler/compiler_target.h index a55c3307e35..5a291e62563 100644 --- a/backends/p4tools/common/compiler/compiler_target.h +++ b/backends/p4tools/common/compiler/compiler_target.h @@ -1,11 +1,10 @@ #ifndef BACKENDS_P4TOOLS_COMMON_COMPILER_COMPILER_TARGET_H_ #define BACKENDS_P4TOOLS_COMMON_COMPILER_COMPILER_TARGET_H_ +#include #include #include -#include - #include "backends/p4tools/common/compiler/midend.h" #include "backends/p4tools/common/core/target.h" #include "frontends/common/options.h" @@ -28,26 +27,26 @@ class CompilerTarget : public Target { /// Runs the P4 compiler to produce an IR. /// - /// @returns boost::none if an error occurs during compilation. - static boost::optional runCompiler(); + /// @returns std::nullopt if an error occurs during compilation. + static std::optional runCompiler(); /// Runs the P4 compiler to produce an IR for the given source code. /// - /// @returns boost::none if an error occurs during compilation. - static boost::optional runCompiler(const std::string &source); + /// @returns std::nullopt if an error occurs during compilation. + static std::optional runCompiler(const std::string &source); private: /// Runs the front and mid ends on the given parsed program. /// - /// @returns boost::none if an error occurs during compilation. - static boost::optional runCompiler(const IR::P4Program *); + /// @returns std::nullopt if an error occurs during compilation. + static std::optional runCompiler(const IR::P4Program *); protected: /// @see @makeContext. virtual ICompileContext *makeContext_impl() const; /// @see runCompiler. - virtual boost::optional runCompiler_impl(const IR::P4Program *) const; + virtual std::optional runCompiler_impl(const IR::P4Program *) const; /// This implementation just forwards the given arguments to the compiler. /// diff --git a/backends/p4tools/common/core/solver.h b/backends/p4tools/common/core/solver.h index ab57ba581ed..42df527f4a5 100644 --- a/backends/p4tools/common/core/solver.h +++ b/backends/p4tools/common/core/solver.h @@ -1,10 +1,9 @@ #ifndef BACKENDS_P4TOOLS_COMMON_CORE_SOLVER_H_ #define BACKENDS_P4TOOLS_COMMON_CORE_SOLVER_H_ +#include #include -#include - #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/model.h" #include "lib/cstring.h" @@ -29,8 +28,8 @@ class AbstractSolver { /// /// @return true if the given assertions are consistent. /// @return false if the given assertions are inconsistent. - /// @return boost::none if the solver times out, or is otherwise unable to provide an answer. - virtual boost::optional checkSat(const std::vector &asserts) = 0; + /// @return std::nullopt if the solver times out, or is otherwise unable to provide an answer. + virtual std::optional checkSat(const std::vector &asserts) = 0; /// Obtains the first solution found by the solver in the last call to @checkSat. /// diff --git a/backends/p4tools/common/core/target.cpp b/backends/p4tools/common/core/target.cpp index 78a4f712287..3c6db6c789c 100644 --- a/backends/p4tools/common/core/target.cpp +++ b/backends/p4tools/common/core/target.cpp @@ -4,11 +4,10 @@ #include #include #include +#include #include #include -#include - namespace P4Tools { Target::Spec::Spec(std::string deviceName, std::string archName) @@ -30,7 +29,7 @@ bool Target::Spec::operator<(const Spec &other) const { * Target implementation * ============================================================================================= */ -boost::optional Target::curTarget = boost::none; +std::optional Target::curTarget = std::nullopt; std::map> Target::registry = {}; std::map Target::defaultArchByDevice = {}; std::map Target::defaultDeviceByArch = {}; diff --git a/backends/p4tools/common/core/target.h b/backends/p4tools/common/core/target.h index 63b8e90d568..8f9cabc7d71 100644 --- a/backends/p4tools/common/core/target.h +++ b/backends/p4tools/common/core/target.h @@ -2,11 +2,9 @@ #define BACKENDS_P4TOOLS_COMMON_CORE_TARGET_H_ #include +#include #include -#include -#include - #include "lib/exceptions.h" namespace P4Tools { @@ -71,7 +69,7 @@ class Target { // Implemented here because of limitations of templates. template static const TargetImpl &get(const std::string &toolName) { - if (curTarget == boost::none) { + if (curTarget == std::nullopt) { FATAL_ERROR( "Target not initialized. Please provide a target using the --target option."); } @@ -89,7 +87,7 @@ class Target { private: /// The active target, if any. - static boost::optional curTarget; + static std::optional curTarget; /// Maps supported target specs to Target implementations for each supported tool. static std::map> registry; diff --git a/backends/p4tools/common/core/z3_solver.cpp b/backends/p4tools/common/core/z3_solver.cpp index 0dd68b35e9d..0c4d54a1d2f 100644 --- a/backends/p4tools/common/core/z3_solver.cpp +++ b/backends/p4tools/common/core/z3_solver.cpp @@ -260,7 +260,7 @@ void Z3Solver::timeout(unsigned tm) { timeout_ = tm; } -boost::optional Z3Solver::checkSat(const std::vector &asserts) { +std::optional Z3Solver::checkSat(const std::vector &asserts) { if (isIncremental) { // Find common prefix with the previous invocation's list of assertions auto from = asserts.begin(); @@ -295,7 +295,7 @@ boost::optional Z3Solver::checkSat(const std::vector & default: // unknown Z3_LOG("result:%s", "unknown"); - return boost::none; + return std::nullopt; } } @@ -418,16 +418,16 @@ const z3::context &Z3Solver::getZ3Ctx() const { return z3context; } bool Z3Solver::isInIncrementalMode() const { return isIncremental; } -Z3Solver::Z3Solver(bool isIncremental, boost::optional inOpt) +Z3Solver::Z3Solver(bool isIncremental, std::optional inOpt) : z3solver(z3context), isIncremental(isIncremental), z3Assertions(z3context) { // Add a top-level set to declaration vars that we can insert variables. // TODO: Think about whether this is necessary or it is not better to remove it. declaredVarsById.emplace_back(); - if (inOpt == boost::none) { + if (inOpt == std::nullopt) { return; } - JSONLoader loader(inOpt.value()); + JSONLoader loader(*inOpt.value()); JSONLoader solverCheckpoints(loader, "checkpoints"); BUG_CHECK(solverCheckpoints.json->is(), diff --git a/backends/p4tools/common/core/z3_solver.h b/backends/p4tools/common/core/z3_solver.h index f446f089b2c..9005c9096b7 100644 --- a/backends/p4tools/common/core/z3_solver.h +++ b/backends/p4tools/common/core/z3_solver.h @@ -6,12 +6,10 @@ #include #include +#include #include #include -#include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/model.h" @@ -38,7 +36,7 @@ class Z3Solver : public AbstractSolver { virtual ~Z3Solver() = default; explicit Z3Solver(bool isIncremental = true, - boost::optional inOpt = boost::none); + std::optional inOpt = std::nullopt); void comment(cstring comment) override; @@ -46,7 +44,7 @@ class Z3Solver : public AbstractSolver { void timeout(unsigned tm) override; - boost::optional checkSat(const std::vector &asserts) override; + std::optional checkSat(const std::vector &asserts) override; const Model *getModel() const override; @@ -128,10 +126,10 @@ class Z3Solver : public AbstractSolver { z3::expr_vector z3Assertions; /// Stores the RNG seed, as last set by @ref seed. - boost::optional seed_; + std::optional seed_; /// Stores the timeout, as last set by @ref timeout. - boost::optional timeout_; + std::optional timeout_; }; } // namespace P4Tools diff --git a/backends/p4tools/common/lib/util.cpp b/backends/p4tools/common/lib/util.cpp index cba9015246c..17e17fd4cb1 100644 --- a/backends/p4tools/common/lib/util.cpp +++ b/backends/p4tools/common/lib/util.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -18,7 +19,6 @@ #include #include #include -#include #include #include "backends/p4tools/common/lib/formulae.h" @@ -34,7 +34,7 @@ namespace P4Tools { * Seeds, timestamps, randomness. * ========================================================================================= */ -boost::optional Utils::currentSeed = boost::none; +std::optional Utils::currentSeed = std::nullopt; boost::random::mt19937 Utils::rng(0); @@ -56,14 +56,14 @@ std::string Utils::getTimeStamp() { } void Utils::setRandomSeed(int seed) { - if (currentSeed) { - BUG("Seed already initialized with %1%.", currentSeed.get()); + if (currentSeed.has_value()) { + BUG("Seed already initialized with %1%.", currentSeed.value()); } currentSeed = seed; rng.seed(seed); } -boost::optional Utils::getCurrentSeed() { return currentSeed; } +std::optional Utils::getCurrentSeed() { return currentSeed; } uint64_t Utils::getRandInt(uint64_t max) { if (!currentSeed) { @@ -101,8 +101,8 @@ const IR::Constant *Utils::getRandConstantForType(const IR::Type_Bits *type) { const cstring Utils::Valid = "*valid"; const StateVariable &Utils::getZombieTableVar(const IR::Type *type, const IR::P4Table *table, - cstring name, boost::optional idx1_opt, - boost::optional idx2_opt) { + cstring name, std::optional idx1_opt, + std::optional idx2_opt) { // Mash the table name, the given name, and the optional indices together. // XXX To be nice, we should probably build a PathExpression, but that's annoying to do, and we // XXX can probably get away with this. diff --git a/backends/p4tools/common/lib/util.h b/backends/p4tools/common/lib/util.h index 86409929085..d5b59b53d88 100644 --- a/backends/p4tools/common/lib/util.h +++ b/backends/p4tools/common/lib/util.h @@ -2,13 +2,12 @@ #define BACKENDS_P4TOOLS_COMMON_LIB_UTIL_H_ #include +#include #include #include #include #include -#include -#include #include #include "backends/p4tools/common/lib/formulae.h" @@ -51,7 +50,7 @@ class Utils { static boost::random::mt19937 rng; /// Stores the state of the PRNG. - static boost::optional currentSeed; + static std::optional currentSeed; public: /// Return the current timestamp with millisecond accuracy. @@ -64,7 +63,7 @@ class Utils { static void setRandomSeed(int seed); /// @returns currentSeed. - static boost::optional getCurrentSeed(); + static std::optional getCurrentSeed(); /// @returns a random integer in the range [0, @param max]. Always return 0 if no seed is set. static uint64_t getRandInt(uint64_t max); @@ -111,8 +110,8 @@ class Utils { /// idx2 are given, respectively. static const StateVariable &getZombieTableVar(const IR::Type *type, const IR::P4Table *table, cstring name, - boost::optional idx1_opt = boost::none, - boost::optional idx2_opt = boost::none); + std::optional idx1_opt = std::nullopt, + std::optional idx2_opt = std::nullopt); /// @returns the state variable for the validity of the given header instance. The resulting /// variable will be boolean-typed. diff --git a/backends/p4tools/common/options.cpp b/backends/p4tools/common/options.cpp index 2ebff5de1ac..dd253af0772 100644 --- a/backends/p4tools/common/options.cpp +++ b/backends/p4tools/common/options.cpp @@ -28,7 +28,7 @@ std::tuple AbstractP4cToolOptions::convertArgs( return {argc, argv}; } -boost::optional AbstractP4cToolOptions::process( +std::optional AbstractP4cToolOptions::process( const std::vector &args) { // Compiler expects path to executable as first element in argument list. compilerArgs.push_back(args.at(0)); @@ -47,7 +47,7 @@ boost::optional AbstractP4cToolOptions::process( // Delegate to the hook. auto *remainingArgs = process(argc, argv); if ((remainingArgs == nullptr) || ::errorCount() > 0) { - return boost::none; + return std::nullopt; } // Establish the real compilation context. @@ -59,7 +59,7 @@ boost::optional AbstractP4cToolOptions::process( auto *unprocessedCompilerArgs = P4Tools::CompilerTarget::initCompiler(argc, argv); if ((unprocessedCompilerArgs == nullptr) || ::errorCount() > 0) { - return boost::none; + return std::nullopt; } BUG_CHECK(unprocessedCompilerArgs->empty(), "Compiler did not process all of its arguments: %s", cstring::join(unprocessedCompilerArgs->begin(), unprocessedCompilerArgs->end(), " ")); @@ -70,16 +70,16 @@ boost::optional AbstractP4cToolOptions::process( ::error("Only one input file can be specified. Duplicate args:\n%1%", cstring::join(remainingArgs->begin(), remainingArgs->end(), "\n ")); usage(); - return boost::none; + return std::nullopt; } if (remainingArgs->empty()) { ::error("No input files specified"); usage(); - return boost::none; + return std::nullopt; } P4CContext::get().options().file = remainingArgs->at(0); - return boost::make_optional(::errorCount() == 0, compilerContext); + return compilerContext; } std::vector *AbstractP4cToolOptions::process(int argc, char *const argv[]) { @@ -102,7 +102,7 @@ struct InheritedCompilerOptionSpec { /// An optional handler for the option. If provided, this is executed before the option is /// forwarded to the compiler. Any argument to the option is provided to the handler. The /// handler should return true on successful processing, and false otherwise. - boost::optional> handler; + std::optional> handler; }; AbstractP4cToolOptions::AbstractP4cToolOptions(cstring message) : Options(message) { @@ -143,7 +143,7 @@ AbstractP4cToolOptions::AbstractP4cToolOptions(cstring message) : Options(messag {"--std", "{p4-14|p4-16}", "Specifies source language version.", {}}, {"-T", "loglevel", "Adjusts logging level per file.", {}}, {"--target", "target", "Specifies the device targeted by the program.", - boost::optional>{[](const char *arg) { + std::optional>{[](const char *arg) { if (!P4Tools::Target::setDevice(arg)) { ::error("Unsupported target device: %s", arg); return false; @@ -151,7 +151,7 @@ AbstractP4cToolOptions::AbstractP4cToolOptions(cstring message) : Options(messag return true; }}}, {"--arch", "arch", "Specifies the architecture targeted by the program.", - boost::optional>{[](const char *arg) { + std::optional>{[](const char *arg) { if (!P4Tools::Target::setArch(arg)) { ::error("Unsupported architecture: %s", arg); return false; diff --git a/backends/p4tools/common/options.h b/backends/p4tools/common/options.h index 11713f727ba..d6188755dec 100644 --- a/backends/p4tools/common/options.h +++ b/backends/p4tools/common/options.h @@ -3,12 +3,10 @@ // Boost #include +#include #include #include -#include -#include - #include "lib/compile_context.h" #include "lib/cstring.h" #include "lib/options.h" @@ -28,12 +26,12 @@ class AbstractP4cToolOptions : protected Util::Options { int minPktSize = 0; /// A seed for the PRNG. - boost::optional seed = boost::none; + std::optional seed = std::nullopt; /// Processes options. /// - /// @returns a compilation context on success, boost::none on error. - boost::optional process(const std::vector &args); + /// @returns a compilation context on success, std::nullopt on error. + std::optional process(const std::vector &args); protected: /// Command-line arguments to be sent to the compiler. Populated by @process. diff --git a/backends/p4tools/modules/testgen/core/externs.cpp b/backends/p4tools/modules/testgen/core/externs.cpp index 7de4718823d..59191243896 100644 --- a/backends/p4tools/modules/testgen/core/externs.cpp +++ b/backends/p4tools/modules/testgen/core/externs.cpp @@ -1,12 +1,11 @@ #include "backends/p4tools/modules/testgen/core/externs.h" #include +#include #include #include #include -#include - #include "ir/ir.h" #include "lib/exceptions.h" #include "lib/null.h" @@ -45,7 +44,7 @@ bool ExternMethodImpls::exec(const IR::MethodCallExpression *call, const IR::Exp } // Find matching methods: if any arguments are named, then the parameter name must match. - boost::optional matchingImpl; + std::optional matchingImpl; for (const auto &pair : submap.at(args->size())) { const auto ¶mNames = pair.first; const auto &methodImpl = pair.second; diff --git a/backends/p4tools/modules/testgen/core/program_info.cpp b/backends/p4tools/modules/testgen/core/program_info.cpp index d5f787f0617..303fb89db79 100644 --- a/backends/p4tools/modules/testgen/core/program_info.cpp +++ b/backends/p4tools/modules/testgen/core/program_info.cpp @@ -70,7 +70,7 @@ const std::vector *ProgramInfo::getPipelineSequence() con return &pipelineSequence; } -boost::optional ProgramInfo::getTargetConstraints() const { +std::optional ProgramInfo::getTargetConstraints() const { return targetConstraints; } diff --git a/backends/p4tools/modules/testgen/core/program_info.h b/backends/p4tools/modules/testgen/core/program_info.h index e87189e4fb3..8a4aec5767d 100644 --- a/backends/p4tools/modules/testgen/core/program_info.h +++ b/backends/p4tools/modules/testgen/core/program_info.h @@ -2,11 +2,9 @@ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_PROGRAM_INFO_H_ #include +#include #include -#include -#include - #include "backends/p4tools/common/compiler/reachability.h" #include "backends/p4tools/common/lib/formulae.h" #include "ir/declaration.h" @@ -41,7 +39,7 @@ class ProgramInfo : public ICastable { std::vector pipelineSequence; - boost::optional targetConstraints = boost::none; + std::optional targetConstraints = std::nullopt; public: ProgramInfo(const ProgramInfo &) = default; @@ -65,7 +63,7 @@ class ProgramInfo : public ICastable { /// @returns the constraints of this target. /// These constraints can influence the execution of the interpreter - boost::optional getTargetConstraints() const; + std::optional getTargetConstraints() const; /// @returns the metadata member corresponding to the ingress port virtual const IR::Member *getTargetInputPortVar() const = 0; diff --git a/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.cpp b/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.cpp index 37f5c96c8e8..db6daa362c4 100644 --- a/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.cpp +++ b/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.cpp @@ -1,11 +1,10 @@ #include "backends/p4tools/modules/testgen/core/small_step/abstract_stepper.h" #include +#include #include #include -#include -#include #include #include "backends/p4tools/common/compiler/convert_hs_index.h" @@ -329,8 +328,8 @@ bool AbstractStepper::stepStackPushPopFront(const IR::Expression *stackRef, return false; } -const Value *AbstractStepper::evaluateExpression( - const IR::Expression *expr, boost::optional cond) const { +const Value *AbstractStepper::evaluateExpression(const IR::Expression *expr, + std::optional cond) const { BUG_CHECK(solver.isInIncrementalMode(), "Currently, expression valuation only supports an incremental solver."); auto constraints = state.getPathConstraint(); @@ -344,7 +343,7 @@ const Value *AbstractStepper::evaluateExpression( // If the solver can find a solution under the given condition, get the model and return the // value. const Value *result = nullptr; - if (solverResult != boost::none && *solverResult) { + if (solverResult != std::nullopt && *solverResult) { auto model = *solver.getModel(); model.complete(expr); result = model.evaluate(expr); diff --git a/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.h b/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.h index 12bf0988889..d65b2df64d0 100644 --- a/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.h +++ b/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.h @@ -2,10 +2,9 @@ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_ABSTRACT_STEPPER_H_ #include +#include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "ir/ir.h" @@ -159,7 +158,7 @@ class AbstractStepper : public Inspector { /// If the solver can find a solution, it @returns the assigned value to the expression. /// If not, this function @returns nullptr. const Value *evaluateExpression(const IR::Expression *expr, - boost::optional cond) const; + std::optional cond) const; /// Reset the given reference to an uninitialized value. If the reference has a /// Type_StructLike, unroll the reference and reset each member. diff --git a/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.cpp b/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.cpp index fd19372afe1..e7bf9c29868 100644 --- a/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.cpp +++ b/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.cpp @@ -2,12 +2,12 @@ #include #include +#include #include #include #include #include -#include #include #include @@ -360,7 +360,7 @@ bool CmdStepper::preorder(const IR::P4Program * /*program*/) { // Don't invoke logStep for the top-level program, as that would be overly verbose. // Get the initial constraints of the target. These constraints influence branch selection. - boost::optional cond = programInfo.getTargetConstraints(); + std::optional cond = programInfo.getTargetConstraints(); // Have the target break apart the main declaration instance. auto *nextState = new ExecutionState(state); @@ -374,7 +374,7 @@ bool CmdStepper::preorder(const IR::P4Program * /*program*/) { const auto *fixedSizeEqu = new IR::Equ(ExecutionState::getInputPacketSizeVar(), IR::getConstant(ExecutionState::getPacketSizeVarType(), pktSize)); - if (cond == boost::none) { + if (cond == std::nullopt) { cond = fixedSizeEqu; } else { cond = new IR::LAnd(*cond, fixedSizeEqu); @@ -623,7 +623,7 @@ bool CmdStepper::preorder(const IR::SwitchStatement *switchStatement) { } BUG_CHECK(!cmds.empty(), "Switch statements should have at least one case (default)."); nextState->replaceTopBody(&cmds); - result->emplace_back(boost::none, state, nextState, coveredStmts); + result->emplace_back(std::nullopt, state, nextState, coveredStmts); return false; } diff --git a/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.h b/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.h index 0e358f326eb..f30147269f4 100644 --- a/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.h +++ b/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.h @@ -2,10 +2,9 @@ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_CMD_STEPPER_H_ #include +#include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "ir/ir.h" @@ -47,8 +46,8 @@ class CmdStepper : public AbstractStepper { /// @see startParser. Implementations can assume that the parser has been registered, and the /// cursor position has been initialized. - virtual boost::optional startParser_impl( - const IR::P4Parser *parser, ExecutionState *nextState) const = 0; + virtual std::optional startParser_impl(const IR::P4Parser *parser, + ExecutionState *nextState) const = 0; /// Initializes variables and adds constraints for the program initialization, which is target /// specific. diff --git a/backends/p4tools/modules/testgen/core/small_step/extern_stepper.cpp b/backends/p4tools/modules/testgen/core/small_step/extern_stepper.cpp index fbd4986dfd7..1750c5032ac 100644 --- a/backends/p4tools/modules/testgen/core/small_step/extern_stepper.cpp +++ b/backends/p4tools/modules/testgen/core/small_step/extern_stepper.cpp @@ -1,12 +1,11 @@ #include #include #include +#include #include #include #include -#include - #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/symbolic_env.h" #include "backends/p4tools/common/lib/trace_events.h" @@ -807,7 +806,7 @@ void ExprStepper::evalExternMethodCall(const IR::MethodCallExpression *call, IR::getConstant(lengthVar->type, 8)); nextState->add(new TraceEvent::Expression(divVar, "Return packet length")); nextState->replaceTopBody(Continuation::Return(divVar)); - result->emplace_back(boost::none, state, nextState); + result->emplace_back(std::nullopt, state, nextState); }}, /* ====================================================================================== * packet_out.emit diff --git a/backends/p4tools/modules/testgen/core/small_step/small_step.cpp b/backends/p4tools/modules/testgen/core/small_step/small_step.cpp index 416d662a906..37ddbd165a7 100644 --- a/backends/p4tools/modules/testgen/core/small_step/small_step.cpp +++ b/backends/p4tools/modules/testgen/core/small_step/small_step.cpp @@ -1,13 +1,12 @@ #include "backends/p4tools/modules/testgen/core/small_step/small_step.h" #include +#include #include #include #include #include -#include -#include #include #include @@ -37,7 +36,7 @@ namespace P4Tools::P4Testgen { SmallStepEvaluator::Branch::Branch(gsl::not_null nextState) : constraint(IR::getBoolLiteral(true)), nextState(std::move(nextState)) {} -SmallStepEvaluator::Branch::Branch(boost::optional c, +SmallStepEvaluator::Branch::Branch(std::optional c, const ExecutionState &prevState, gsl::not_null nextState) : constraint(IR::getBoolLiteral(true)), nextState(nextState) { @@ -53,7 +52,7 @@ SmallStepEvaluator::Branch::Branch(boost::optional c, } } -SmallStepEvaluator::Branch::Branch(boost::optional c, +SmallStepEvaluator::Branch::Branch(std::optional c, const ExecutionState &prevState, gsl::not_null nextState, const P4::Coverage::CoverageSet &potentialStatements) @@ -205,7 +204,7 @@ SmallStepEvaluator::Result SmallStepEvaluator::step(ExecutionState &state) { // Evaluate the guard condition by directly using the solver. const auto *cond = guard.cond; - boost::optional solverResult = boost::none; + std::optional solverResult = std::nullopt; // If the guard condition is tainted, treat it equivalent to an invalid state. if (!state.hasTaint(cond)) { @@ -223,7 +222,7 @@ SmallStepEvaluator::Result SmallStepEvaluator::step(ExecutionState &state) { // If we can not solve the guard (either we time out or the solver can not solve // the problem) we increment the count of violatedGuardConditions and stop // executing this branch. - if (solverResult == boost::none || !solverResult.get()) { + if (solverResult == std::nullopt || !solverResult.value()) { std::stringstream condStream; guard.cond->dbprint(condStream); ::warning( diff --git a/backends/p4tools/modules/testgen/core/small_step/small_step.h b/backends/p4tools/modules/testgen/core/small_step/small_step.h index 67275fa3279..8db7d832acd 100644 --- a/backends/p4tools/modules/testgen/core/small_step/small_step.h +++ b/backends/p4tools/modules/testgen/core/small_step/small_step.h @@ -2,10 +2,9 @@ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_SMALL_STEP_H_ #include +#include #include -#include - #include "backends/p4tools/common/compiler/reachability.h" #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" @@ -34,12 +33,12 @@ class SmallStepEvaluator { /// Branch constrained by a condition. prevState is the state in which the condition /// is later evaluated. - Branch(boost::optional c, const ExecutionState &prevState, + Branch(std::optional c, const ExecutionState &prevState, gsl::not_null nextState); /// Branch constrained by a condition. prevState is the state in which the condition /// is later evaluated. - Branch(boost::optional c, const ExecutionState &prevState, + Branch(std::optional c, const ExecutionState &prevState, gsl::not_null nextState, const P4::Coverage::CoverageSet &potentialStatements); }; diff --git a/backends/p4tools/modules/testgen/core/small_step/table_stepper.cpp b/backends/p4tools/modules/testgen/core/small_step/table_stepper.cpp index 915e38e1676..3b48d3bba9a 100644 --- a/backends/p4tools/modules/testgen/core/small_step/table_stepper.cpp +++ b/backends/p4tools/modules/testgen/core/small_step/table_stepper.cpp @@ -2,13 +2,13 @@ #include #include +#include #include #include #include #include #include -#include #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/symbolic_env.h" @@ -386,7 +386,7 @@ void TableStepper::setTableDefaultEntries( tableStream << "| Overriding default action: " << actionName; nextState->add(new TraceEvent::Generic(tableStream.str())); nextState->replaceTopBody(&replacements); - stepper->result->emplace_back(boost::none, stepper->state, nextState, coveredStmts); + stepper->result->emplace_back(std::nullopt, stepper->state, nextState, coveredStmts); } } @@ -485,7 +485,7 @@ void TableStepper::evalTableControlEntries( void TableStepper::evalTaintedTable() { // If the table is not immutable, we just do not add any entry and execute the default action. if (!properties.tableIsImmutable) { - addDefaultAction(boost::none); + addDefaultAction(std::nullopt); return; } std::vector replacements; @@ -628,7 +628,7 @@ std::vector TableStepper::buildTableActionList() return tableActionList; } -void TableStepper::addDefaultAction(boost::optional tableMissCondition) { +void TableStepper::addDefaultAction(std::optional tableMissCondition) { const auto *defaultAction = table->getDefaultAction(); CHECK_NULL(defaultAction); BUG_CHECK(defaultAction->is(), @@ -668,7 +668,7 @@ void TableStepper::evalTargetTable( const std::vector &tableActionList) { // If the table is not constant, the default action can always be executed. // This is because we can simply not enter any table entry. - boost::optional tableMissCondition = boost::none; + std::optional tableMissCondition = std::nullopt; // If the table is not immutable, we synthesize control plane entries and follow the paths. if (properties.tableIsImmutable) { // If the entries properties is constant it means the entries are fixed. diff --git a/backends/p4tools/modules/testgen/core/small_step/table_stepper.h b/backends/p4tools/modules/testgen/core/small_step/table_stepper.h index 1e18be4a671..2cbecaef771 100644 --- a/backends/p4tools/modules/testgen/core/small_step/table_stepper.h +++ b/backends/p4tools/modules/testgen/core/small_step/table_stepper.h @@ -3,10 +3,9 @@ #include #include +#include #include -#include - #include "backends/p4tools/common/lib/formulae.h" #include "ir/ir.h" #include "lib/cstring.h" @@ -119,7 +118,7 @@ class TableStepper { /// Add the default action path to the expression stepper. If only hits if @param /// tableMissCondition is true. - void addDefaultAction(boost::optional tableMissCondition); + void addDefaultAction(std::optional tableMissCondition); /// Helper function that collects the list of actions contained in the table. std::vector buildTableActionList(); diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.cpp b/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.cpp index 8e1c5bb4c95..ae7e5a5922c 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.cpp +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.cpp @@ -1,9 +1,8 @@ #include "backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.h" +#include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/util.h" diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.h b/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.h index 9c5eed4d524..ad0ca35a9d4 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.h +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.h @@ -3,11 +3,10 @@ #include #include +#include #include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/modules/testgen/core/program_info.h" diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_stmt_cov.cpp b/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_stmt_cov.cpp index 85d03d39960..3a78034dab6 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_stmt_cov.cpp +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_stmt_cov.cpp @@ -1,9 +1,8 @@ #include "backends/p4tools/modules/testgen/core/symbolic_executor/greedy_stmt_cov.h" +#include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/util.h" diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_stmt_cov.h b/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_stmt_cov.h index 69d118200be..c5f3f2d85ff 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_stmt_cov.h +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_stmt_cov.h @@ -7,8 +7,6 @@ #include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/modules/testgen/core/program_info.h" diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/max_stmt_cov.cpp b/backends/p4tools/modules/testgen/core/symbolic_executor/max_stmt_cov.cpp index 113ba53301a..13050d2f554 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/max_stmt_cov.cpp +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/max_stmt_cov.cpp @@ -2,11 +2,10 @@ #include #include +#include #include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/util.h" @@ -223,10 +222,10 @@ ExecutionState *RandomMaxStmtCoverage::chooseBranch(std::vector &branche if (guaranteeViability) { // Check the consistency of the path constraints asserted so far. auto solverResult = solver.checkSat(branch.nextState->getPathConstraint()); - if (solverResult == boost::none) { + if (solverResult == std::nullopt) { ::warning("Solver timed out"); } - if (solverResult == boost::none || !solverResult.get()) { + if (solverResult == std::nullopt || !solverResult.value()) { // Solver timed out or path constraints were not satisfiable. Need to choose a // different branch. Roll back our branch selection and try again. continue; diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/max_stmt_cov.h b/backends/p4tools/modules/testgen/core/symbolic_executor/max_stmt_cov.h index 749878e2240..7b57b3e3665 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/max_stmt_cov.h +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/max_stmt_cov.h @@ -4,12 +4,11 @@ #include #include #include +#include #include #include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/modules/testgen/core/program_info.h" diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.cpp b/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.cpp index b5335f41a74..f5a267ef14b 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.cpp +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.cpp @@ -1,9 +1,8 @@ #include "backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.h" +#include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/util.h" diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.h b/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.h index 8ba766e08af..4c9838c208c 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.h +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.h @@ -3,11 +3,10 @@ #include #include +#include #include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/modules/testgen/core/program_info.h" diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/selected_branches.h b/backends/p4tools/modules/testgen/core/symbolic_executor/selected_branches.h index fe70f54bb82..18947c9d12e 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/selected_branches.h +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/selected_branches.h @@ -3,11 +3,10 @@ #include #include +#include #include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/modules/testgen/core/program_info.h" diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.cpp b/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.cpp index a5e3e2be48a..8b77f6aa73a 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.cpp +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.cpp @@ -3,12 +3,12 @@ #include #include #include +#include #include #include #include #include -#include #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" @@ -73,11 +73,10 @@ bool SymbolicExecutor::evaluateBranch(const SymbolicExecutor::Branch &branch, // Check the consistency of the path constraints asserted so far. auto solverResult = solver.checkSat(branch.nextState->getPathConstraint()); - if (solverResult == boost::none) { + if (solverResult == std::nullopt) { ::warning("Solver timed out"); } - - return solverResult != boost::none && solverResult.get(); + return solverResult.value_or(false); } SymbolicExecutor::Branch SymbolicExecutor::popRandomBranch( @@ -97,7 +96,7 @@ SymbolicExecutor::SymbolicExecutor(AbstractSolver &solver, const ProgramInfo &pr evaluator(solver, programInfo) { // If there is no seed provided, do not randomize the solver. auto seed = Utils::getCurrentSeed(); - if (seed != boost::none) { + if (seed != std::nullopt) { this->solver.seed(*seed); } executionState = new ExecutionState(programInfo.program); diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h b/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h index 6385ee22c8c..fa9787b8e08 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h @@ -4,10 +4,9 @@ #include #include #include +#include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "midend/coverage.h" diff --git a/backends/p4tools/modules/testgen/core/target.h b/backends/p4tools/modules/testgen/core/target.h index a11fb338422..f22ab2adee8 100644 --- a/backends/p4tools/modules/testgen/core/target.h +++ b/backends/p4tools/modules/testgen/core/target.h @@ -2,11 +2,10 @@ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_TARGET_H_ #include +#include #include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/core/target.h" #include "ir/ir.h" @@ -38,7 +37,7 @@ class TestgenTarget : public Target { /// Returns the test back end associated with this P4Testgen target. static TestBackEnd *getTestBackend(const ProgramInfo &programInfo, SymbolicExecutor &symbex, const std::filesystem::path &testPath, - boost::optional seed) { + std::optional seed) { return get().getTestBackend_impl(programInfo, symbex, testPath, seed); } @@ -79,7 +78,7 @@ class TestgenTarget : public Target { virtual TestBackEnd *getTestBackend_impl(const ProgramInfo &programInfo, SymbolicExecutor &symbex, const std::filesystem::path &testPath, - boost::optional seed) const = 0; + std::optional seed) const = 0; /// @see getCmdStepper. virtual CmdStepper *getCmdStepper_impl(ExecutionState &state, AbstractSolver &solver, diff --git a/backends/p4tools/modules/testgen/lib/concolic.cpp b/backends/p4tools/modules/testgen/lib/concolic.cpp index 3068d97f740..638acf77418 100644 --- a/backends/p4tools/modules/testgen/lib/concolic.cpp +++ b/backends/p4tools/modules/testgen/lib/concolic.cpp @@ -1,10 +1,9 @@ #include "backends/p4tools/modules/testgen/lib/concolic.h" +#include #include #include -#include - #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/model.h" #include "ir/id.h" @@ -56,7 +55,7 @@ bool ConcolicMethodImpls::exec(cstring qualifiedMethodName, const IR::ConcolicVa } // Find matching methods: if any arguments are named, then the parameter name must match. - boost::optional matchingImpl; + std::optional matchingImpl; for (const auto &pair : submap.at(args->size())) { const auto ¶mNames = pair.first; const auto &methodImpl = pair.second; diff --git a/backends/p4tools/modules/testgen/lib/continuation.cpp b/backends/p4tools/modules/testgen/lib/continuation.cpp index 60636055a4f..e5542e425b1 100644 --- a/backends/p4tools/modules/testgen/lib/continuation.cpp +++ b/backends/p4tools/modules/testgen/lib/continuation.cpp @@ -93,7 +93,7 @@ class VariableSubstitution : public Transform { : var(var), expr(expr) {} }; -Continuation::Body Continuation::apply(boost::optional value_opt) const { +Continuation::Body Continuation::apply(std::optional value_opt) const { BUG_CHECK(!(value_opt && !parameterOpt), "Supplied a value to a continuation with no parameters."); BUG_CHECK(!(!value_opt && parameterOpt), diff --git a/backends/p4tools/modules/testgen/lib/continuation.h b/backends/p4tools/modules/testgen/lib/continuation.h index 869d88d11dc..b0ae31b33a6 100644 --- a/backends/p4tools/modules/testgen/lib/continuation.h +++ b/backends/p4tools/modules/testgen/lib/continuation.h @@ -6,11 +6,11 @@ #include #include #include +#include #include +#include #include -#include -#include #include #include "backends/p4tools/common/lib/trace_events.h" @@ -75,12 +75,12 @@ class Continuation { /// of IR::Expression; other IR nodes may be treated as expressions in the metalanguage, even /// though they are not P4 expressions. struct Return { - boost::optional expr; + std::optional expr; /// Delegates to IR equality. bool operator==(const Return &other) const; - Return() : expr(boost::none) {} + Return() : expr(std::nullopt) {} explicit Return(const IR::Node *expr); }; @@ -182,16 +182,16 @@ class Continuation { /// Represents the continuation's parameter. // // Invariant: this parameter is uniquely named. - boost::optional parameterOpt; + std::optional parameterOpt; Body body; /// @returns a body that is equivalent to applying this continuation to the given value (or - /// unit, if no value is provided). A BUG occurs if parameterOpt is boost::none but value_opt + /// unit, if no value is provided). A BUG occurs if parameterOpt is std::nullopt but value_opt /// is not, or vice versa. /// /// Expressions in the metalanguage include P4 non-expressions. Because of this, the value (if /// provided) does not necessarily need to be an instance of IR::Expression. - Body apply(boost::optional value_opt) const; + Body apply(std::optional value_opt) const; /// @returns a parameter for use in building continuations. The parameter will be fresh in the /// given @ctx. @@ -199,13 +199,13 @@ class Continuation { const NamespaceContext *ctx); /// Creates a parameterless continuation. - explicit Continuation(Body body) : Continuation(boost::none, body) {} + explicit Continuation(Body body) : Continuation(std::nullopt, std::move(body)) {} /// Creates a continuation. The continuation will have the given parameter, if one is provided; /// otherwise, the continuation will have no parameters. - Continuation(boost::optional parameterOpt, Body body) - : parameterOpt(parameterOpt ? boost::make_optional((*parameterOpt)->param) : boost::none), - body(body) {} + Continuation(std::optional parameterOpt, Body body) + : parameterOpt(parameterOpt ? std::make_optional((*parameterOpt)->param) : std::nullopt), + body(std::move(body)) {} }; } // namespace P4Testgen diff --git a/backends/p4tools/modules/testgen/lib/execution_state.cpp b/backends/p4tools/modules/testgen/lib/execution_state.cpp index 67c4140bb6e..197c301636d 100644 --- a/backends/p4tools/modules/testgen/lib/execution_state.cpp +++ b/backends/p4tools/modules/testgen/lib/execution_state.cpp @@ -96,9 +96,9 @@ ExecutionState::ExecutionState(Continuation::Body body) bool ExecutionState::isTerminal() const { return body.empty() && stack.empty(); } -boost::optional ExecutionState::getNextCmd() const { +std::optional ExecutionState::getNextCmd() const { if (body.empty()) { - return boost::none; + return std::nullopt; } return body.next(); } @@ -260,32 +260,32 @@ void ExecutionState::pushContinuation(gsl::not_null frame) { } void ExecutionState::pushCurrentContinuation(StackFrame::ExceptionHandlers handlers) { - pushCurrentContinuation(boost::none, handlers); + pushCurrentContinuation(std::nullopt, std::move(handlers)); } -void ExecutionState::pushCurrentContinuation(boost::optional parameterType_opt, +void ExecutionState::pushCurrentContinuation(std::optional parameterType_opt, StackFrame::ExceptionHandlers handlers) { - // If we were given a void parameter type, treat that the same as boost::none. + // If we were given a void parameter type, treat that the same as std::nullopt. if (parameterType_opt && IR::Type::Void::get()->equiv(**parameterType_opt)) { - parameterType_opt = boost::none; + parameterType_opt = std::nullopt; } // Create the optional parameter. - boost::optional parameter_opt = boost::none; + std::optional parameterOpt = std::nullopt; if (parameterType_opt) { const auto *parameter = Continuation::genParameter(*parameterType_opt, "_", getNamespaceContext()); - parameter_opt = boost::make_optional(parameter); + parameterOpt = parameter; } // Actually push the current continuation. - Continuation k(parameter_opt, body); - const auto *frame = new StackFrame(k, handlers, namespaces); + Continuation k(parameterOpt, body); + const auto *frame = new StackFrame(k, std::move(handlers), namespaces); pushContinuation(frame); body.clear(); } -void ExecutionState::popContinuation(boost::optional argument_opt) { +void ExecutionState::popContinuation(std::optional argument_opt) { BUG_CHECK(!stack.empty(), "Popped an empty continuation stack"); auto frame = stack.top(); stack.pop(); @@ -300,7 +300,7 @@ void ExecutionState::handleException(Continuation::Exception e) { auto frame = stack.top(); if (frame->exceptionHandlers.count(e) > 0) { auto k = frame->exceptionHandlers.at(e); - auto newBody = k.apply(boost::none); + auto newBody = k.apply(std::nullopt); replaceBody(newBody); setNamespaceContext(frame->namespaces); return; diff --git a/backends/p4tools/modules/testgen/lib/execution_state.h b/backends/p4tools/modules/testgen/lib/execution_state.h index 7d1ad37bfba..11396a4541b 100644 --- a/backends/p4tools/modules/testgen/lib/execution_state.h +++ b/backends/p4tools/modules/testgen/lib/execution_state.h @@ -5,13 +5,12 @@ #include #include #include +#include #include #include #include #include -#include -#include #include #include "backends/p4tools/common/compiler/reachability.h" @@ -171,8 +170,8 @@ class ExecutionState { void pushBranchDecision(uint64_t); /// @returns the next command to be evaluated, if any. - /// @returns boost::none if the current body is empty. - boost::optional getNextCmd() const; + /// @returns std::nullopt if the current body is empty. + std::optional getNextCmd() const; /// @returns the symbolic value of the given state variable. const IR::Expression *get(const StateVariable &var) const; @@ -333,7 +332,7 @@ class ExecutionState { /// new frame will use the given set of exception handlers. If @parameterType_opt is given, /// then the continuation in the new frame will have a function parameter, with the given type, /// that is ignored by the body. - void pushCurrentContinuation(boost::optional parameterType_opt = boost::none, + void pushCurrentContinuation(std::optional parameterType_opt = std::nullopt, StackFrame::ExceptionHandlers = {}); /// Pops the topmost frame in the stack of continuations. From the popped frame, the @@ -342,7 +341,7 @@ class ExecutionState { /// /// Expressions in the metalanguage include P4 non-expressions. Because of this, the argument /// (if provided) does not necessarily need to be an instance of IR::Expression. - void popContinuation(boost::optional argument_opt = boost::none); + void popContinuation(std::optional argument_opt = std::nullopt); /// Invokes first handler for e found on the stack void handleException(Continuation::Exception e); diff --git a/backends/p4tools/modules/testgen/lib/namespace_context.h b/backends/p4tools/modules/testgen/lib/namespace_context.h index 79be6eae762..18c0cc202ac 100644 --- a/backends/p4tools/modules/testgen/lib/namespace_context.h +++ b/backends/p4tools/modules/testgen/lib/namespace_context.h @@ -1,10 +1,9 @@ #ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_NAMESPACE_CONTEXT_H_ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_NAMESPACE_CONTEXT_H_ +#include #include -#include - #include "ir/declaration.h" #include "ir/ir.h" #include "lib/cstring.h" @@ -20,7 +19,7 @@ class NamespaceContext { const NamespaceContext *outer; /// All names that appear in this context and all outer contexts. Populated lazily. - mutable boost::optional> usedNames; + mutable std::optional> usedNames; NamespaceContext(const IR::INamespace *ns, const NamespaceContext *outer) : curNamespace(ns), outer(outer) {} diff --git a/backends/p4tools/modules/testgen/lib/test_backend.cpp b/backends/p4tools/modules/testgen/lib/test_backend.cpp index 15eda5b3f99..a7d8c1fb366 100644 --- a/backends/p4tools/modules/testgen/lib/test_backend.cpp +++ b/backends/p4tools/modules/testgen/lib/test_backend.cpp @@ -2,11 +2,11 @@ #include #include +#include #include #include #include -#include #include #include diff --git a/backends/p4tools/modules/testgen/lib/test_spec.cpp b/backends/p4tools/modules/testgen/lib/test_spec.cpp index 4c9cbf13f33..b18db83f73a 100644 --- a/backends/p4tools/modules/testgen/lib/test_spec.cpp +++ b/backends/p4tools/modules/testgen/lib/test_spec.cpp @@ -1,10 +1,10 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include +#include #include #include -#include #include #include "backends/p4tools/common/lib/formulae.h" @@ -262,17 +262,17 @@ const TableConfig *TableConfig::evaluate(const Model &model) const { * Test Specification Object * ========================================================================================= */ -TestSpec::TestSpec(Packet ingressPacket, boost::optional egressPacket, +TestSpec::TestSpec(Packet ingressPacket, std::optional egressPacket, std::vector> traces) : ingressPacket(std::move(ingressPacket)), egressPacket(std::move(egressPacket)), traces(std::move(traces)) {} -boost::optional TestSpec::getEgressPacket() const { +std::optional TestSpec::getEgressPacket() const { if (egressPacket) { return &(*egressPacket); } - return boost::none; + return std::nullopt; } const Packet *TestSpec::getIngressPacket() const { return &ingressPacket; } diff --git a/backends/p4tools/modules/testgen/lib/test_spec.h b/backends/p4tools/modules/testgen/lib/test_spec.h index 9f557c58135..e44b9dcd7f0 100644 --- a/backends/p4tools/modules/testgen/lib/test_spec.h +++ b/backends/p4tools/modules/testgen/lib/test_spec.h @@ -2,9 +2,9 @@ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_TEST_SPEC_H_ #include +#include #include -#include #include #include "backends/p4tools/common/lib/model.h" @@ -299,7 +299,7 @@ class TestSpec { /// The expected output packet of this test. Only single output packets are supported. /// Additional output packets need to be encoded as test objects. - const boost::optional egressPacket; + const std::optional egressPacket; /// The traces that have been collected while the interpreter stepped through the program. const std::vector> traces; @@ -309,7 +309,7 @@ class TestSpec { std::map> testObjects; public: - TestSpec(Packet ingressPacket, boost::optional egressPacket, + TestSpec(Packet ingressPacket, std::optional egressPacket, std::vector> traces); /// Add a test object to the test specification with @param category as the object category @@ -341,7 +341,7 @@ class TestSpec { const std::map *getTables() const; /// @returns the expected output packet for this test. - boost::optional getEgressPacket() const; + std::optional getEgressPacket() const; /// @returns the list of traces that has been executed const std::vector> *getTraces() const; diff --git a/backends/p4tools/modules/testgen/lib/tf.cpp b/backends/p4tools/modules/testgen/lib/tf.cpp index e009405566b..730738896c3 100644 --- a/backends/p4tools/modules/testgen/lib/tf.cpp +++ b/backends/p4tools/modules/testgen/lib/tf.cpp @@ -1,13 +1,13 @@ #include "backends/p4tools/modules/testgen/lib/tf.h" -#include +#include #include "backends/p4tools/common/lib/util.h" #include "lib/timer.h" namespace P4Tools::P4Testgen { -TF::TF(cstring testName, boost::optional seed = boost::none) +TF::TF(cstring testName, std::optional seed = std::nullopt) : testName(testName), seed(seed) {} void TF::printPerformanceReport(bool write) const { diff --git a/backends/p4tools/modules/testgen/lib/tf.h b/backends/p4tools/modules/testgen/lib/tf.h index fdcaeb7fbcb..df063387d7f 100644 --- a/backends/p4tools/modules/testgen/lib/tf.h +++ b/backends/p4tools/modules/testgen/lib/tf.h @@ -2,8 +2,8 @@ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_TF_H_ #include +#include -#include #include #include "backends/p4tools/common/lib/format_int.h" @@ -21,10 +21,10 @@ class TF { const cstring testName; /// The seed used by the testgen. - boost::optional seed; + std::optional seed; /// Creates a generic test framework. - explicit TF(cstring, boost::optional); + explicit TF(cstring, std::optional); /// Converts the traces of this test into a string representation and Inja object. static inja::json getTrace(const TestSpec *testSpec) { diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/metadata/metadata.cpp b/backends/p4tools/modules/testgen/targets/bmv2/backend/metadata/metadata.cpp index 975ee28a787..d74f6a1be3b 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/metadata/metadata.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/metadata/metadata.cpp @@ -2,13 +2,13 @@ #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -33,7 +33,7 @@ namespace P4Tools::P4Testgen::Bmv2 { -Metadata::Metadata(cstring testName, boost::optional seed = boost::none) +Metadata::Metadata(cstring testName, std::optional seed = std::nullopt) : TF(testName, seed) {} std::vector> Metadata::getIgnoreMasks(const IR::Constant *mask) { @@ -73,7 +73,7 @@ inja::json Metadata::getSend(const TestSpec *testSpec) { inja::json Metadata::getVerify(const TestSpec *testSpec) { inja::json verifyData = inja::json::object(); - if (testSpec->getEgressPacket() != boost::none) { + if (testSpec->getEgressPacket() != std::nullopt) { const auto &packet = **testSpec->getEgressPacket(); verifyData["eg_port"] = packet.getPort(); const auto *payload = packet.getEvaluatedPayload(); diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/metadata/metadata.h b/backends/p4tools/modules/testgen/targets/bmv2/backend/metadata/metadata.h index 8c5b57d8387..a6cbe66e00e 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/metadata/metadata.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/metadata/metadata.h @@ -4,11 +4,11 @@ #include #include #include +#include #include #include #include -#include #include #include "ir/ir.h" @@ -35,7 +35,7 @@ class Metadata : public TF { Metadata &operator=(Metadata &&) = delete; - Metadata(cstring testName, boost::optional seed); + Metadata(cstring testName, std::optional seed); /// Produce a Metadata test. void outputTest(const TestSpec *spec, cstring selectedBranches, size_t testIdx, diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.cpp index ec192d3f3e5..7de1a4026cf 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.cpp @@ -2,13 +2,13 @@ #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -41,34 +41,34 @@ std::string formatHexExprWithSep(const IR::Expression *expr) { return insertHexSeparators(formatHexExpr(expr, false, true, false)); } -Protobuf::Protobuf(cstring testName, boost::optional seed = boost::none) +Protobuf::Protobuf(cstring testName, std::optional seed = std::nullopt) : TF(testName, seed) {} -boost::optional Protobuf::getIdAnnotation(const IR::IAnnotated *node) { +std::optional Protobuf::getIdAnnotation(const IR::IAnnotated *node) { const auto *idAnnotation = node->getAnnotation("id"); if (idAnnotation == nullptr) { - return boost::none; + return std::nullopt; } const auto *idConstant = idAnnotation->expr[0]->to(); CHECK_NULL(idConstant); if (!idConstant->fitsUint()) { ::error(ErrorType::ERR_INVALID, "%1%: @id should be an unsigned integer", node); - return boost::none; + return std::nullopt; } return static_cast(idConstant->value); } -boost::optional Protobuf::externalId( - const P4::ControlPlaneAPI::P4RuntimeSymbolType &type, const IR::IDeclaration *declaration) { +std::optional Protobuf::externalId(const P4::ControlPlaneAPI::P4RuntimeSymbolType &type, + const IR::IDeclaration *declaration) { CHECK_NULL(declaration); if (!declaration->is()) { - return boost::none; // Assign an id later; see below. + return std::nullopt; // Assign an id later; see below. } // If the user specified an @id annotation, use that. auto idOrNone = getIdAnnotation(declaration->to()); if (!idOrNone) { - return boost::none; // the user didn't assign an id + return std::nullopt; // the user didn't assign an id } auto id = *idOrNone; @@ -78,7 +78,7 @@ boost::optional Protobuf::externalId( const auto prefixMask = static_cast(0xff) << 24; if ((id & prefixMask) != 0 && (id & prefixMask) != typePrefix) { ::error(ErrorType::ERR_INVALID, "%1%: @id has the wrong 8-bit prefix", declaration); - return boost::none; + return std::nullopt; } id |= typePrefix; @@ -243,7 +243,7 @@ inja::json Protobuf::getSend(const TestSpec *testSpec) { inja::json Protobuf::getVerify(const TestSpec *testSpec) { inja::json verifyData = inja::json::object(); - if (testSpec->getEgressPacket() != boost::none) { + if (testSpec->getEgressPacket() != std::nullopt) { const auto &packet = **testSpec->getEgressPacket(); verifyData["eg_port"] = packet.getPort(); const auto *payload = packet.getEvaluatedPayload(); diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.h b/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.h index 7aa467c492d..05bf39835dc 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/protobuf/protobuf.h @@ -4,11 +4,11 @@ #include #include #include +#include #include #include #include -#include #include #include "control-plane/p4RuntimeArchStandard.h" @@ -43,7 +43,7 @@ class Protobuf : public TF { Protobuf &operator=(Protobuf &&) = delete; - Protobuf(cstring testName, boost::optional seed); + Protobuf(cstring testName, std::optional seed); /// Produce a Protobuf test. void outputTest(const TestSpec *spec, cstring selectedBranches, size_t testIdx, @@ -83,14 +83,14 @@ class Protobuf : public TF { const std::vector &args); /// @return the id allocated to the object through the @id annotation if any, or - /// boost::none. - static boost::optional getIdAnnotation(const IR::IAnnotated *node); + /// std::nullopt. + static std::optional getIdAnnotation(const IR::IAnnotated *node); /// @return the value of any P4 '@id' annotation @declaration may have, and /// ensure that the value is correct with respect to the P4Runtime /// specification. The name 'externalId' is in analogy with externalName(). - static boost::optional externalId( - const P4::ControlPlaneAPI::P4RuntimeSymbolType &type, const IR::IDeclaration *declaration); + static std::optional externalId(const P4::ControlPlaneAPI::P4RuntimeSymbolType &type, + const IR::IDeclaration *declaration); }; } // namespace Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.cpp index cd7fe9c5df7..579b284b3c1 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.cpp @@ -2,12 +2,12 @@ #include #include +#include #include #include #include #include -#include #include #include #include @@ -28,7 +28,7 @@ namespace P4Tools::P4Testgen::Bmv2 { -PTF::PTF(cstring testName, boost::optional seed = boost::none) : TF(testName, seed) {} +PTF::PTF(cstring testName, std::optional seed = std::nullopt) : TF(testName, seed) {} inja::json::array_t PTF::getClone(const std::map &cloneInfos) { auto cloneJson = inja::json::array_t(); @@ -188,7 +188,7 @@ inja::json PTF::getSend(const TestSpec *testSpec) { inja::json PTF::getVerify(const TestSpec *testSpec) { inja::json verifyData = inja::json::object(); - if (testSpec->getEgressPacket() != boost::none) { + if (testSpec->getEgressPacket() != std::nullopt) { const auto &packet = **testSpec->getEgressPacket(); verifyData["eg_port"] = packet.getPort(); const auto *payload = packet.getEvaluatedPayload(); diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.h b/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.h index 2166aa4f5c3..aecfe25cd94 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/ptf/ptf.h @@ -4,11 +4,11 @@ #include #include #include +#include #include #include #include -#include #include /// Inja @@ -39,7 +39,7 @@ class PTF : public TF { PTF &operator=(PTF &&) = delete; - PTF(cstring testName, boost::optional seed); + PTF(cstring testName, std::optional seed); /// Produce a PTF test. void outputTest(const TestSpec *spec, cstring selectedBranches, size_t testIdx, diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.cpp index d4a2f17fb69..c2d8b5ccd4b 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -11,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -33,7 +33,7 @@ namespace P4Tools::P4Testgen::Bmv2 { -STF::STF(cstring testName, boost::optional seed = boost::none) : TF(testName, seed) {} +STF::STF(cstring testName, std::optional seed = std::nullopt) : TF(testName, seed) {} inja::json STF::getControlPlane(const TestSpec *testSpec) { inja::json controlPlaneJson = inja::json::object(); @@ -172,7 +172,7 @@ inja::json STF::getSend(const TestSpec *testSpec) { inja::json STF::getVerify(const TestSpec *testSpec) { inja::json verifyData = inja::json::object(); - if (testSpec->getEgressPacket() != boost::none) { + if (testSpec->getEgressPacket() != std::nullopt) { const auto &packet = **testSpec->getEgressPacket(); verifyData["eg_port"] = packet.getPort(); const auto *payload = packet.getEvaluatedPayload(); diff --git a/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.h b/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.h index 205aee9166e..a9eb08c9e5a 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.h @@ -4,10 +4,10 @@ #include #include #include +#include #include #include -#include #include #include "lib/cstring.h" @@ -33,7 +33,7 @@ class STF : public TF { STF &operator=(STF &&) = delete; - STF(cstring testName, boost::optional seed); + STF(cstring testName, std::optional seed); /// Produce an STF test. void outputTest(const TestSpec *spec, cstring selectedBranches, size_t testIdx, diff --git a/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.cpp b/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.cpp index 4fae667a3d3..003a8d88320 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.cpp @@ -4,10 +4,9 @@ #include #include +#include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "ir/id.h" @@ -101,7 +100,7 @@ void BMv2_V1ModelCmdStepper::initializeTargetEnvironment(ExecutionState *nextSta nextState->set(packetSizeVar, packetSizeConst); } -boost::optional BMv2_V1ModelCmdStepper::startParser_impl( +std::optional BMv2_V1ModelCmdStepper::startParser_impl( const IR::P4Parser *parser, ExecutionState *nextState) const { // We need to explicitly map the parser error const auto *errVar = @@ -114,7 +113,7 @@ boost::optional BMv2_V1ModelCmdStepper::startParser_impl( const auto &portVar = programInfo.getTargetInputPortVar(); return new IR::Lss(portVar, new IR::Constant(portVar->type, 8)); } - return boost::none; + return std::nullopt; } std::map BMv2_V1ModelCmdStepper::getExceptionHandlers( diff --git a/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.h b/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.h index fe2f6504c56..0700b72e944 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.h @@ -2,10 +2,9 @@ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_CMD_STEPPER_H_ #include +#include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "ir/ir.h" @@ -30,8 +29,8 @@ class BMv2_V1ModelCmdStepper : public CmdStepper { void initializeTargetEnvironment(ExecutionState *nextState) const override; - boost::optional startParser_impl(const IR::P4Parser *parser, - ExecutionState *state) const override; + std::optional startParser_impl(const IR::P4Parser *parser, + ExecutionState *state) const override; std::map getExceptionHandlers( const IR::P4Parser *parser, Continuation::Body normalContinuation, diff --git a/backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.cpp b/backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.cpp index 7e7d7cb9d72..559cd9296ee 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.cpp @@ -3,14 +3,13 @@ #include #include #include +#include #include #include #include #include #include -#include -#include #include #include "backends/p4tools/common/core/solver.h" @@ -855,7 +854,7 @@ void BMv2_V1ModelExprStepper::evalExternMethodCall(const IR::MethodCallExpressio auto cloneType = args->at(0)->expression->checkedTo()->asUint64(); const auto *sessionIdExpr = args->at(1)->expression; auto recirculateIndex = args->at(2)->expression->checkedTo()->asUint64(); - boost::optional cond = boost::none; + std::optional cond = std::nullopt; if (cloneType == BMv2Constants::CLONE_TYPE_I2E) { // Pick a clone port var. For now, pick a random value from 0-511. @@ -1142,7 +1141,7 @@ void BMv2_V1ModelExprStepper::evalExternMethodCall(const IR::MethodCallExpressio auto cloneType = args->at(0)->expression->checkedTo()->asUint64(); const auto *sessionIdExpr = args->at(1)->expression; uint64_t sessionId = 0; - boost::optional cond = boost::none; + std::optional cond = std::nullopt; if (cloneType == BMv2Constants::CLONE_TYPE_I2E) { // Pick a clone port var. For now, pick a random value from 0-511. diff --git a/backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.cpp b/backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.cpp index dc34e774888..23640658075 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.cpp @@ -5,11 +5,11 @@ #include #include #include +#include #include #include #include -#include #include "backends/p4tools/common/core/z3_solver.h" #include "backends/p4tools/common/lib/formulae.h" diff --git a/backends/p4tools/modules/testgen/targets/bmv2/program_info.cpp b/backends/p4tools/modules/testgen/targets/bmv2/program_info.cpp index b7a695f1749..c9e3570b654 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/program_info.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/program_info.cpp @@ -2,11 +2,10 @@ #include #include +#include #include #include -#include - #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/util.h" #include "ir/id.h" diff --git a/backends/p4tools/modules/testgen/targets/bmv2/table_stepper.cpp b/backends/p4tools/modules/testgen/targets/bmv2/table_stepper.cpp index 29907b1c596..8ca897b65af 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/table_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/table_stepper.cpp @@ -2,13 +2,12 @@ #include #include +#include #include #include #include #include -#include -#include #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/trace_events.h" @@ -407,13 +406,13 @@ void BMv2_V1ModelTableStepper::evalTargetTable( "Choosing default action", properties.tableName, testBackend); } - addDefaultAction(boost::none); + addDefaultAction(std::nullopt); return; } // If the table is not constant, the default action can always be executed. // This is because we can simply not enter any table entry. - boost::optional tableMissCondition = boost::none; + std::optional tableMissCondition = std::nullopt; // If the table is not immutable, we synthesize control plane entries and follow the paths. if (properties.tableIsImmutable) { diff --git a/backends/p4tools/modules/testgen/targets/bmv2/target.cpp b/backends/p4tools/modules/testgen/targets/bmv2/target.cpp index 508b71225be..f1ead183283 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/target.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/target.cpp @@ -77,7 +77,7 @@ const BMv2_V1ModelProgramInfo *BMv2_V1ModelTestgenTarget::initProgram_impl( Bmv2TestBackend *BMv2_V1ModelTestgenTarget::getTestBackend_impl( const ProgramInfo &programInfo, SymbolicExecutor &symbex, const std::filesystem::path &testPath, - boost::optional seed) const { + std::optional seed) const { return new Bmv2TestBackend(programInfo, symbex, testPath, seed); } diff --git a/backends/p4tools/modules/testgen/targets/bmv2/target.h b/backends/p4tools/modules/testgen/targets/bmv2/target.h index 8c0cd433fbf..7e560ffec57 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/target.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/target.h @@ -3,7 +3,7 @@ #include -#include +#include #include "backends/p4tools/common/core/solver.h" #include "ir/ir.h" @@ -37,7 +37,7 @@ class BMv2_V1ModelTestgenTarget : public TestgenTarget { Bmv2TestBackend *getTestBackend_impl(const ProgramInfo &programInfo, SymbolicExecutor &symbex, const std::filesystem::path &testPath, - boost::optional seed) const override; + std::optional seed) const override; BMv2_V1ModelCmdStepper *getCmdStepper_impl(ExecutionState &state, AbstractSolver &solver, const ProgramInfo &programInfo) const override; diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test_backend.cpp index ae3d8a81029..7ffe9deb123 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend.cpp @@ -1,12 +1,11 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend.h" #include +#include #include #include #include -#include - #include "backends/p4tools/common/lib/model.h" #include "backends/p4tools/common/lib/trace_events.h" #include "backends/p4tools/common/lib/util.h" @@ -37,7 +36,7 @@ const std::set Bmv2TestBackend::SUPPORTED_BACKENDS = {"PTF", "STF", Bmv2TestBackend::Bmv2TestBackend(const ProgramInfo &programInfo, SymbolicExecutor &symbex, const std::filesystem::path &testPath, - boost::optional seed) + std::optional seed) : TestBackEnd(programInfo, symbex) { cstring testBackendString = TestgenOptions::get().testBackend; if (testBackendString.isNullOrEmpty()) { @@ -90,7 +89,7 @@ const TestSpec *Bmv2TestBackend::createTestSpec(const ExecutionState *executionS const auto *ingressPayloadMask = IR::getConstant(IR::getBitType(1), 1); const auto ingressPacket = Packet(testInfo.inputPort, ingressPayload, ingressPayloadMask); - boost::optional egressPacket = boost::none; + std::optional egressPacket = std::nullopt; if (!testInfo.packetIsDropped) { egressPacket = Packet(testInfo.outputPort, testInfo.outputPacket, testInfo.packetTaintMask); } diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend.h b/backends/p4tools/modules/testgen/targets/bmv2/test_backend.h index ea4f3af4d37..c650d0fd9c7 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend.h @@ -2,11 +2,10 @@ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_H_ #include +#include #include #include -#include - #include "backends/p4tools/common/lib/model.h" #include "backends/p4tools/common/lib/trace_events.h" #include "gsl/gsl-lite.hpp" @@ -35,7 +34,7 @@ class Bmv2TestBackend : public TestBackEnd { public: explicit Bmv2TestBackend(const ProgramInfo &programInfo, SymbolicExecutor &symbex, - const std::filesystem::path &testPath, boost::optional seed); + const std::filesystem::path &testPath, std::optional seed); TestBackEnd::TestInfo produceTestInfo( const ExecutionState *executionState, const Model *completedModel, diff --git a/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.cpp b/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.cpp index 0174cf4a4a6..6833faeb20c 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.cpp @@ -2,6 +2,7 @@ #include #include +#include #include // NOLINT #include #include @@ -13,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -33,7 +33,7 @@ namespace P4Tools::P4Testgen::EBPF { -STF::STF(cstring testName, boost::optional seed = boost::none) : TF(testName, seed) { +STF::STF(cstring testName, std::optional seed = std::nullopt) : TF(testName, seed) { std::filesystem::path testFile(testName + ".stf"); cstring testNameOnly(testFile.stem().c_str()); } @@ -168,7 +168,7 @@ inja::json STF::getSend(const TestSpec *testSpec) { inja::json STF::getVerify(const TestSpec *testSpec) { inja::json verifyData = inja::json::object(); - if (testSpec->getEgressPacket() != boost::none) { + if (testSpec->getEgressPacket() != std::nullopt) { const auto &packet = **testSpec->getEgressPacket(); verifyData["eg_port"] = packet.getPort(); const auto *payload = packet.getEvaluatedPayload(); diff --git a/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h b/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h index a400253a2ff..49493167fcf 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h @@ -4,10 +4,10 @@ #include #include #include +#include #include #include -#include #include #include "lib/cstring.h" @@ -33,7 +33,7 @@ class STF : public TF { STF &operator=(STF &&) = delete; - STF(cstring testName, boost::optional seed); + STF(cstring testName, std::optional seed); /// Produce an STF test. void outputTest(const TestSpec *spec, cstring selectedBranches, size_t testIdx, diff --git a/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.cpp b/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.cpp index 25abb0d5ecc..ce5512b1f31 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.cpp @@ -3,10 +3,9 @@ #include #include #include +#include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/util.h" @@ -62,9 +61,9 @@ void EBPFCmdStepper::initializeTargetEnvironment(ExecutionState *nextState) cons nextState->setParserErrorLabel(errVar); } -boost::optional EBPFCmdStepper::startParser_impl( +std::optional EBPFCmdStepper::startParser_impl( const IR::P4Parser * /*parser*/, ExecutionState * /*nextState*/) const { - return boost::none; + return std::nullopt; } std::map EBPFCmdStepper::getExceptionHandlers( diff --git a/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.h b/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.h index 267a841badd..e12a2a71ea9 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.h @@ -2,10 +2,9 @@ #define TESTGEN_TARGETS_EBPF_CMD_STEPPER_H_ #include +#include #include -#include - #include "backends/p4tools/common/core/solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "ir/ir.h" @@ -30,8 +29,8 @@ class EBPFCmdStepper : public CmdStepper { void initializeTargetEnvironment(ExecutionState *nextState) const override; - boost::optional startParser_impl(const IR::P4Parser *parser, - ExecutionState *state) const override; + std::optional startParser_impl(const IR::P4Parser *parser, + ExecutionState *state) const override; std::map getExceptionHandlers( const IR::P4Parser *parser, Continuation::Body normalContinuation, diff --git a/backends/p4tools/modules/testgen/targets/ebpf/program_info.cpp b/backends/p4tools/modules/testgen/targets/ebpf/program_info.cpp index 85dc1fa3f1e..bef7043f881 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/program_info.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/program_info.cpp @@ -1,11 +1,10 @@ #include "backends/p4tools/modules/testgen/targets/ebpf/program_info.h" #include +#include #include #include -#include - #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/util.h" #include "ir/id.h" diff --git a/backends/p4tools/modules/testgen/targets/ebpf/table_stepper.cpp b/backends/p4tools/modules/testgen/targets/ebpf/table_stepper.cpp index 756a6ff2f75..daaba185aa1 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/table_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/table_stepper.cpp @@ -1,11 +1,10 @@ #include "backends/p4tools/modules/testgen/targets/ebpf/table_stepper.h" #include +#include #include #include -#include -#include #include "lib/error.h" @@ -46,13 +45,13 @@ void EBPFTableStepper::evalTargetTable( const auto *keys = table->getKey(); // If we have no keys, there is nothing to match. if (keys == nullptr) { - addDefaultAction(boost::none); + addDefaultAction(std::nullopt); return; } // If the table is not constant, the default action can always be executed. // This is because we can simply not enter any table entry. - boost::optional tableMissCondition = boost::none; + std::optional tableMissCondition = std::nullopt; // If the table is not immutable, we synthesize control plane entries and follow the paths. if (properties.tableIsImmutable) { diff --git a/backends/p4tools/modules/testgen/targets/ebpf/target.cpp b/backends/p4tools/modules/testgen/targets/ebpf/target.cpp index 0eea7c73880..47e0e7b6c98 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/target.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/target.cpp @@ -75,7 +75,7 @@ const EBPFProgramInfo *EBPFTestgenTarget::initProgram_impl( EBPFTestBackend *EBPFTestgenTarget::getTestBackend_impl(const ProgramInfo &programInfo, SymbolicExecutor &symbex, const std::filesystem::path &testPath, - boost::optional seed) const { + std::optional seed) const { return new EBPFTestBackend(programInfo, symbex, testPath, seed); } diff --git a/backends/p4tools/modules/testgen/targets/ebpf/target.h b/backends/p4tools/modules/testgen/targets/ebpf/target.h index 07cab90ed3d..64d47f1b8cf 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/target.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/target.h @@ -2,8 +2,7 @@ #define TESTGEN_TARGETS_EBPF_TARGET_H_ #include - -#include +#include #include "backends/p4tools/common/core/solver.h" #include "ir/ir.h" @@ -37,7 +36,7 @@ class EBPFTestgenTarget : public TestgenTarget { EBPFTestBackend *getTestBackend_impl(const ProgramInfo &programInfo, SymbolicExecutor &symbex, const std::filesystem::path &testPath, - boost::optional seed) const override; + std::optional seed) const override; EBPFCmdStepper *getCmdStepper_impl(ExecutionState &state, AbstractSolver &solver, const ProgramInfo &programInfo) const override; diff --git a/backends/p4tools/modules/testgen/targets/ebpf/test_backend.cpp b/backends/p4tools/modules/testgen/targets/ebpf/test_backend.cpp index 21b0a119c63..d858e23757e 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/test_backend.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/test_backend.cpp @@ -1,12 +1,11 @@ #include "backends/p4tools/modules/testgen/targets/ebpf/test_backend.h" #include +#include #include #include #include -#include - #include "backends/p4tools/common/lib/model.h" #include "backends/p4tools/common/lib/trace_events.h" #include "gsl/gsl-lite.hpp" @@ -23,11 +22,7 @@ #include "backends/p4tools/modules/testgen/options.h" #include "backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h" -namespace P4Tools { - -namespace P4Testgen { - -namespace EBPF { +namespace P4Tools::P4Testgen::EBPF { const big_int EBPFTestBackend::ZERO_PKT_VAL = 0x2000000; const big_int EBPFTestBackend::ZERO_PKT_MAX = 0xffffffff; @@ -35,7 +30,7 @@ const std::vector EBPFTestBackend::SUPPORTED_BACKENDS = {"STF"}; EBPFTestBackend::EBPFTestBackend(const ProgramInfo &programInfo, SymbolicExecutor &symbex, const std::filesystem::path &testPath, - boost::optional seed) + std::optional seed) : TestBackEnd(programInfo, symbex) { cstring testBackendString = TestgenOptions::get().testBackend; if (testBackendString == "STF") { @@ -90,7 +85,7 @@ const TestSpec *EBPFTestBackend::createTestSpec(const ExecutionState *executionS const auto *ingressPayloadMask = IR::getConstant(IR::getBitType(1), 1); const auto ingressPacket = Packet(testInfo.inputPort, ingressPayload, ingressPayloadMask); - boost::optional egressPacket = boost::none; + std::optional egressPacket = std::nullopt; if (!testInfo.packetIsDropped) { egressPacket = Packet(testInfo.outputPort, testInfo.outputPacket, testInfo.packetTaintMask); } @@ -108,8 +103,4 @@ const TestSpec *EBPFTestBackend::createTestSpec(const ExecutionState *executionS return testSpec; } -} // namespace EBPF - -} // namespace P4Testgen - -} // namespace P4Tools +} // namespace P4Tools::P4Testgen::EBPF diff --git a/backends/p4tools/modules/testgen/targets/ebpf/test_backend.h b/backends/p4tools/modules/testgen/targets/ebpf/test_backend.h index c2639735b72..457048822c9 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/test_backend.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/test_backend.h @@ -2,12 +2,10 @@ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_EBPF_TEST_BACKEND_H_ #include +#include #include #include -#include -#include - #include "backends/p4tools/common/lib/model.h" #include "backends/p4tools/common/lib/trace_events.h" #include "gsl/gsl-lite.hpp" @@ -20,11 +18,7 @@ #include "backends/p4tools/modules/testgen/lib/test_backend.h" #include "backends/p4tools/modules/testgen/lib/test_spec.h" -namespace P4Tools { - -namespace P4Testgen { - -namespace EBPF { +namespace P4Tools::P4Testgen::EBPF { class EBPFTestBackend : public TestBackEnd { private: @@ -40,7 +34,7 @@ class EBPFTestBackend : public TestBackEnd { public: explicit EBPFTestBackend(const ProgramInfo &programInfo, SymbolicExecutor &symbex, - const std::filesystem::path &testPath, boost::optional seed); + const std::filesystem::path &testPath, std::optional seed); TestBackEnd::TestInfo produceTestInfo( const ExecutionState *executionState, const Model *completedModel, @@ -51,10 +45,6 @@ class EBPFTestBackend : public TestBackEnd { const Model *completedModel, const TestInfo &testInfo) override; }; -} // namespace EBPF - -} // namespace P4Testgen - -} // namespace P4Tools +} // namespace P4Tools::P4Testgen::EBPF #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_EBPF_TEST_BACKEND_H_ */ diff --git a/backends/p4tools/modules/testgen/test/gtest_utils.cpp b/backends/p4tools/modules/testgen/test/gtest_utils.cpp index 37db11aac41..37e26e64d17 100644 --- a/backends/p4tools/modules/testgen/test/gtest_utils.cpp +++ b/backends/p4tools/modules/testgen/test/gtest_utils.cpp @@ -1,6 +1,6 @@ #include "backends/p4tools/modules/testgen/test/gtest_utils.h" -#include +#include #include "backends/p4tools/common/compiler/compiler_target.h" #include "backends/p4tools/common/core/target.h" @@ -13,7 +13,7 @@ namespace Test { -boost::optional P4ToolsTestCase::create( +std::optional P4ToolsTestCase::create( std::string deviceName, std::string archName, CompilerOptions::FrontendVersion langVersion, const std::string &source) { // Initialize the target. @@ -27,20 +27,20 @@ boost::optional P4ToolsTestCase::create( auto program = P4Tools::CompilerTarget::runCompiler(source); if (!program) { - return boost::none; + return std::nullopt; } return P4ToolsTestCase{*program}; } -boost::optional P4ToolsTestCase::create_14(std::string deviceName, - std::string archName, - const std::string &source) { +std::optional P4ToolsTestCase::create_14(std::string deviceName, + std::string archName, + const std::string &source) { return create(deviceName, archName, CompilerOptions::FrontendVersion::P4_14, source); } -boost::optional P4ToolsTestCase::create_16(std::string deviceName, - std::string archName, - const std::string &source) { +std::optional P4ToolsTestCase::create_16(std::string deviceName, + std::string archName, + const std::string &source) { return create(deviceName, archName, CompilerOptions::FrontendVersion::P4_16, source); } diff --git a/backends/p4tools/modules/testgen/test/gtest_utils.h b/backends/p4tools/modules/testgen/test/gtest_utils.h index feb92d098c3..21bf10769de 100644 --- a/backends/p4tools/modules/testgen/test/gtest_utils.h +++ b/backends/p4tools/modules/testgen/test/gtest_utils.h @@ -1,10 +1,9 @@ #ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_TEST_GTEST_UTILS_H_ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_TEST_GTEST_UTILS_H_ +#include #include -#include - #include "frontends/common/options.h" #include "frontends/common/parser_options.h" #include "ir/ir.h" @@ -16,19 +15,19 @@ namespace Test { class P4ToolsTestCase { public: /// Factory method for producing a test case from a P4 program source. - static boost::optional create( - std::string deviceName, std::string archName, CompilerOptions::FrontendVersion langVersion, - const std::string &source); + static std::optional create(std::string deviceName, std::string archName, + CompilerOptions::FrontendVersion langVersion, + const std::string &source); /// Factory method for producing a test case from a P4_14 program source. - static boost::optional create_14(std::string deviceName, - std::string archName, - const std::string &source); + static std::optional create_14(std::string deviceName, + std::string archName, + const std::string &source); /// Factory method for producing a test case from a P4_16 program source. - static boost::optional create_16(std::string deviceName, - std::string archName, - const std::string &source); + static std::optional create_16(std::string deviceName, + std::string archName, + const std::string &source); /// The output of the compiler's mid end. const IR::P4Program *program; diff --git a/backends/p4tools/modules/testgen/test/small-step/binary.cpp b/backends/p4tools/modules/testgen/test/small-step/binary.cpp index 9218adb55da..0f8df553a9f 100644 --- a/backends/p4tools/modules/testgen/test/small-step/binary.cpp +++ b/backends/p4tools/modules/testgen/test/small-step/binary.cpp @@ -1,6 +1,5 @@ #include - -#include +#include #include "gtest/gtest-message.h" #include "gtest/gtest-test-part.h" diff --git a/backends/p4tools/modules/testgen/test/small-step/unary.cpp b/backends/p4tools/modules/testgen/test/small-step/unary.cpp index 54dce025c20..29d48c1ab1a 100644 --- a/backends/p4tools/modules/testgen/test/small-step/unary.cpp +++ b/backends/p4tools/modules/testgen/test/small-step/unary.cpp @@ -1,6 +1,5 @@ #include - -#include +#include #include "gtest/gtest-message.h" #include "gtest/gtest-test-part.h" diff --git a/backends/p4tools/modules/testgen/test/small-step/util.cpp b/backends/p4tools/modules/testgen/test/small-step/util.cpp index 3034e95bb28..fe79fd552c3 100644 --- a/backends/p4tools/modules/testgen/test/small-step/util.cpp +++ b/backends/p4tools/modules/testgen/test/small-step/util.cpp @@ -13,8 +13,8 @@ namespace Test { namespace SmallStepUtil { /// Creates a test case with the @hdrFields for stepping on an @expr. -boost::optional createSmallStepExprTest(const std::string &hdrFields, - const std::string &expr) { +std::optional createSmallStepExprTest(const std::string &hdrFields, + const std::string &expr) { auto source = P4_SOURCE(P4Headers::V1MODEL, R"( header H { %HEADER_FIELDS% diff --git a/backends/p4tools/modules/testgen/test/small-step/util.h b/backends/p4tools/modules/testgen/test/small-step/util.h index 4b4ec38c923..38fdb23c16f 100644 --- a/backends/p4tools/modules/testgen/test/small-step/util.h +++ b/backends/p4tools/modules/testgen/test/small-step/util.h @@ -2,11 +2,11 @@ #define BACKENDS_P4TOOLS_MODULES_TESTGEN_TEST_SMALL_STEP_UTIL_H_ #include +#include #include #include #include -#include #include #include "backends/p4tools/common/core/z3_solver.h" @@ -51,8 +51,8 @@ namespace SmallStepUtil { /// Creates a test case with the given header fields for /// stepping on a given expression. -boost::optional createSmallStepExprTest(const std::string &, - const std::string &); +std::optional createSmallStepExprTest(const std::string &, + const std::string &); /// Extract the expression from the P4Program. template diff --git a/backends/p4tools/modules/testgen/test/small-step/value.cpp b/backends/p4tools/modules/testgen/test/small-step/value.cpp index e1783ac3471..f21dc3f8275 100644 --- a/backends/p4tools/modules/testgen/test/small-step/value.cpp +++ b/backends/p4tools/modules/testgen/test/small-step/value.cpp @@ -1,6 +1,5 @@ #include - -#include +#include #include "gtest/gtest-message.h" #include "gtest/gtest-test-part.h" diff --git a/backends/p4tools/modules/testgen/test/transformations/saturation_arithm.cpp b/backends/p4tools/modules/testgen/test/transformations/saturation_arithm.cpp index 9f1ad731924..254fe188447 100644 --- a/backends/p4tools/modules/testgen/test/transformations/saturation_arithm.cpp +++ b/backends/p4tools/modules/testgen/test/transformations/saturation_arithm.cpp @@ -1,9 +1,8 @@ +#include #include #include #include -#include - #include "backends/p4tools/common/core/z3_solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/model.h" diff --git a/backends/p4tools/modules/testgen/test/z3-solver/accessor.h b/backends/p4tools/modules/testgen/test/z3-solver/accessor.h index fa1a2531135..bad47dfb448 100644 --- a/backends/p4tools/modules/testgen/test/z3-solver/accessor.h +++ b/backends/p4tools/modules/testgen/test/z3-solver/accessor.h @@ -15,7 +15,7 @@ class Z3SolverAccessor { explicit Z3SolverAccessor(gsl::not_null solver) : solver(solver) {} /// Gets all assertions. Used by GTests only. - z3::expr_vector getAssertions(boost::optional assertionType = boost::none) { + z3::expr_vector getAssertions(std::optional assertionType = std::nullopt) { if (!assertionType) { return solver->isIncremental ? solver->z3solver.assertions() : solver->z3Assertions; } else if (assertionType.value()) { diff --git a/backends/p4tools/modules/testgen/test/z3-solver/asrt_model.cpp b/backends/p4tools/modules/testgen/test/z3-solver/asrt_model.cpp index 22e4f005f43..ee4c9263a9f 100644 --- a/backends/p4tools/modules/testgen/test/z3-solver/asrt_model.cpp +++ b/backends/p4tools/modules/testgen/test/z3-solver/asrt_model.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -6,7 +7,6 @@ #include #include #include -#include #include "backends/p4tools/common/core/z3_solver.h" #include "backends/p4tools/common/lib/formulae.h" diff --git a/backends/p4tools/modules/testgen/test/z3-solver/expressions.cpp b/backends/p4tools/modules/testgen/test/z3-solver/expressions.cpp index deda585bc72..45177323078 100644 --- a/backends/p4tools/modules/testgen/test/z3-solver/expressions.cpp +++ b/backends/p4tools/modules/testgen/test/z3-solver/expressions.cpp @@ -1,9 +1,8 @@ +#include #include #include #include -#include - #include "backends/p4tools/common/core/z3_solver.h" #include "backends/p4tools/common/lib/formulae.h" #include "backends/p4tools/common/lib/model.h" diff --git a/backends/p4tools/modules/testgen/testgen.cpp b/backends/p4tools/modules/testgen/testgen.cpp index 9cf2939aea1..ef21dd6fbeb 100644 --- a/backends/p4tools/modules/testgen/testgen.cpp +++ b/backends/p4tools/modules/testgen/testgen.cpp @@ -4,12 +4,11 @@ #include #include #include +#include #include #include #include -#include -#include #include "backends/p4tools/common/core/z3_solver.h" #include "backends/p4tools/common/lib/util.h" diff --git a/control-plane/bfruntime.cpp b/control-plane/bfruntime.cpp index 4d6903adbff..e209a2b13b2 100644 --- a/control-plane/bfruntime.cpp +++ b/control-plane/bfruntime.cpp @@ -144,7 +144,7 @@ TypeSpecParser TypeSpecParser::make(const p4configv1::P4Info &p4info, } // Counter -boost::optional BFRuntimeGenerator::Counter::from( +std::optional BFRuntimeGenerator::Counter::from( const p4configv1::Counter &counterInstance) { const auto &pre = counterInstance.preamble(); auto id = makeBFRuntimeId(pre.id(), p4configv1::P4Ids::COUNTER); @@ -155,7 +155,7 @@ boost::optional BFRuntimeGenerator::Counter::from( return Counter{pre.name(), id, counterInstance.size(), unit, transformAnnotations(pre)}; } -boost::optional BFRuntimeGenerator::Counter::fromDirect( +std::optional BFRuntimeGenerator::Counter::fromDirect( const p4configv1::DirectCounter &counterInstance) { const auto &pre = counterInstance.preamble(); auto id = makeBFRuntimeId(pre.id(), p4configv1::P4Ids::DIRECT_COUNTER); @@ -164,7 +164,7 @@ boost::optional BFRuntimeGenerator::Counter::fromDi } // Meter -boost::optional BFRuntimeGenerator::Meter::from( +std::optional BFRuntimeGenerator::Meter::from( const p4configv1::Meter &meterInstance) { const auto &pre = meterInstance.preamble(); auto id = makeBFRuntimeId(pre.id(), p4configv1::P4Ids::METER); @@ -172,7 +172,7 @@ boost::optional BFRuntimeGenerator::Meter::from( return Meter{pre.name(), id, meterInstance.size(), unit, transformAnnotations(pre)}; } -boost::optional BFRuntimeGenerator::Meter::fromDirect( +std::optional BFRuntimeGenerator::Meter::fromDirect( const p4configv1::DirectMeter &meterInstance) { const auto &pre = meterInstance.preamble(); auto id = makeBFRuntimeId(pre.id(), p4configv1::P4Ids::DIRECT_METER); @@ -181,7 +181,7 @@ boost::optional BFRuntimeGenerator::Meter::fromDirect } // Register -boost::optional BFRuntimeGenerator::Register::from( +std::optional BFRuntimeGenerator::Register::from( const p4configv1::Register ®Instance) { const auto &pre = regInstance.preamble(); auto id = makeBFRuntimeId(pre.id(), p4configv1::P4Ids::REGISTER); @@ -194,7 +194,7 @@ P4Id BFRuntimeGenerator::ActionProf::makeActProfId(P4Id implementationId) { return makeBFRuntimeId(implementationId, p4configv1::P4Ids::ACTION_PROFILE); } -boost::optional BFRuntimeGenerator::ActionProf::from( +std::optional BFRuntimeGenerator::ActionProf::from( const p4configv1::P4Info &p4info, const p4configv1::ActionProfile &actionProfile) { const auto &pre = actionProfile.preamble(); auto profileId = makeBFRuntimeId(pre.id(), p4configv1::P4Ids::ACTION_PROFILE); @@ -205,38 +205,38 @@ boost::optional BFRuntimeGenerator::ActionProf:: } // Digest -boost::optional BFRuntimeGenerator::Digest::from( +std::optional BFRuntimeGenerator::Digest::from( const p4configv1::Digest &digest) { const auto &pre = digest.preamble(); auto id = makeBFRuntimeId(pre.id(), p4configv1::P4Ids::DIGEST); return Digest{pre.name(), id, digest.type_spec(), transformAnnotations(pre)}; } -boost::optional BFRuntimeGenerator::getDirectCounter( +std::optional BFRuntimeGenerator::getDirectCounter( P4Id counterId) const { if (isOfType(counterId, p4configv1::P4Ids::DIRECT_COUNTER)) { auto *counter = Standard::findDirectCounter(p4info, counterId); - if (counter == nullptr) return boost::none; + if (counter == nullptr) return std::nullopt; return Counter::fromDirect(*counter); } - return boost::none; + return std::nullopt; } -boost::optional BFRuntimeGenerator::getDirectMeter(P4Id meterId) const { +std::optional BFRuntimeGenerator::getDirectMeter(P4Id meterId) const { if (isOfType(meterId, p4configv1::P4Ids::DIRECT_METER)) { auto *meter = Standard::findDirectMeter(p4info, meterId); - if (meter == nullptr) return boost::none; + if (meter == nullptr) return std::nullopt; return Meter::fromDirect(*meter); } - return boost::none; + return std::nullopt; } // TBD -// boost::optional +// std::optional // BFRuntimeGenerator::getRegister(P4Id registerId) const { -// if (!isOfType(registerId, p4configv1::P4Ids::DIRECT_REGISTER)) return boost::none; +// if (!isOfType(registerId, p4configv1::P4Ids::DIRECT_REGISTER)) return std::nullopt; // auto* externInstance = findExternInstance(p4info, registerId); -// if (externInstance == nullptr) return boost::none; +// if (externInstance == nullptr) return std::nullopt; // return Register::from(*externInstance); // } @@ -523,13 +523,13 @@ void BFRuntimeGenerator::addActionProfCommon( tablesJson->append(tableJson); } -boost::optional BFRuntimeGenerator::actProfHasSelector(P4Id actProfId) const { +std::optional BFRuntimeGenerator::actProfHasSelector(P4Id actProfId) const { if (isOfType(actProfId, p4configv1::P4Ids::ACTION_PROFILE)) { auto *actionProf = Standard::findActionProf(p4info, actProfId); - if (actionProf == nullptr) return boost::none; + if (actionProf == nullptr) return std::nullopt; return actionProf->with_selector(); } - return boost::none; + return std::nullopt; } Util::JsonArray *BFRuntimeGenerator::makeActionSpecs(const p4configv1::Table &table, @@ -604,7 +604,7 @@ void BFRuntimeGenerator::addLearnFilterCommon(Util::JsonArray *learnFiltersJson, void BFRuntimeGenerator::addLearnFilters(Util::JsonArray *learnFiltersJson) const { for (const auto &digest : p4info.digests()) { auto digestInstance = Digest::from(digest); - if (digestInstance == boost::none) continue; + if (digestInstance == std::nullopt) continue; addLearnFilterCommon(learnFiltersJson, *digestInstance); } } @@ -658,7 +658,7 @@ void BFRuntimeGenerator::addMatchTables(Util::JsonArray *tablesJson) const { bool needsPriority = false; auto *keyJson = new Util::JsonArray(); for (const auto &mf : table.match_fields()) { - boost::optional matchType = boost::none; + std::optional matchType = std::nullopt; switch (mf.match_case()) { case p4configv1::MatchField::kMatchType: matchType = transformMatchType(mf.match_type()); @@ -670,7 +670,7 @@ void BFRuntimeGenerator::addMatchTables(Util::JsonArray *tablesJson) const { BUG("Invalid oneof case for the match type of table '%1%'", pre.name()); break; } - if (matchType == boost::none) { + if (matchType == std::nullopt) { ::error(ErrorType::ERR_UNSUPPORTED, "Unsupported match type for BF-RT: %1%", int(mf.match_type())); continue; @@ -721,7 +721,7 @@ void BFRuntimeGenerator::addMatchTables(Util::JsonArray *tablesJson) const { // DRV-3112 - Make key fields not mandatory, this allows user to use a // driver initialized default value (0). addKeyField(keyJson, mf.id(), keyName, false /* mandatory */, *matchType, - makeTypeBytes(mf.bitwidth(), boost::none), annotations); + makeTypeBytes(mf.bitwidth(), std::nullopt), annotations); } if (needsPriority) { // DRV-3112 - Make key fields not mandatory, this allows user to use a @@ -804,7 +804,7 @@ void BFRuntimeGenerator::addMatchTables(Util::JsonArray *tablesJson) const { void BFRuntimeGenerator::addActionProfs(Util::JsonArray *tablesJson) const { for (const auto &actionProf : p4info.action_profiles()) { auto actionProfInstance = ActionProf::from(p4info, actionProf); - if (actionProfInstance == boost::none) continue; + if (actionProfInstance == std::nullopt) continue; addActionProfCommon(tablesJson, *actionProfInstance); } } @@ -812,7 +812,7 @@ void BFRuntimeGenerator::addActionProfs(Util::JsonArray *tablesJson) const { void BFRuntimeGenerator::addCounters(Util::JsonArray *tablesJson) const { for (const auto &counter : p4info.counters()) { auto counterInstance = Counter::from(counter); - if (counterInstance == boost::none) continue; + if (counterInstance == std::nullopt) continue; addCounterCommon(tablesJson, *counterInstance); } } @@ -820,7 +820,7 @@ void BFRuntimeGenerator::addCounters(Util::JsonArray *tablesJson) const { void BFRuntimeGenerator::addMeters(Util::JsonArray *tablesJson) const { for (const auto &meter : p4info.meters()) { auto meterInstance = Meter::from(meter); - if (meterInstance == boost::none) continue; + if (meterInstance == std::nullopt) continue; addMeterCommon(tablesJson, *meterInstance); } } @@ -828,7 +828,7 @@ void BFRuntimeGenerator::addMeters(Util::JsonArray *tablesJson) const { void BFRuntimeGenerator::addRegisters(Util::JsonArray *tablesJson) const { for (const auto ® : p4info.registers()) { auto regInstance = Register::from(reg); - if (regInstance == boost::none) continue; + if (regInstance == std::nullopt) continue; addRegisterCommon(tablesJson, *regInstance); } } diff --git a/control-plane/bfruntime.h b/control-plane/bfruntime.h index 7e3143ddd21..3597a772981 100644 --- a/control-plane/bfruntime.h +++ b/control-plane/bfruntime.h @@ -20,13 +20,12 @@ limitations under the License. #include #include #include +#include #include #include #include #include -#include - #include "control-plane/p4RuntimeSerializer.h" #include "lib/big_int_util.h" #include "lib/exceptions.h" @@ -148,30 +147,30 @@ static inline Util::JsonObject *makeType(cstring type, T defaultValue) { return typeObj; } -static inline Util::JsonObject *makeTypeBool(boost::optional defaultValue = boost::none) { +static inline Util::JsonObject *makeTypeBool(std::optional defaultValue = std::nullopt) { auto *typeObj = new Util::JsonObject(); typeObj->emplace("type", "bool"); - if (defaultValue != boost::none) typeObj->emplace("default_value", *defaultValue); + if (defaultValue != std::nullopt) typeObj->emplace("default_value", *defaultValue); return typeObj; } static inline Util::JsonObject *makeTypeBytes(int width, - boost::optional defaultValue = boost::none) { + std::optional defaultValue = std::nullopt) { auto *typeObj = new Util::JsonObject(); typeObj->emplace("type", "bytes"); typeObj->emplace("width", width); - if (defaultValue != boost::none) typeObj->emplace("default_value", *defaultValue); + if (defaultValue != std::nullopt) typeObj->emplace("default_value", *defaultValue); return typeObj; } static inline Util::JsonObject *makeTypeEnum(const std::vector &choices, - boost::optional defaultValue = boost::none) { + std::optional defaultValue = std::nullopt) { auto *typeObj = new Util::JsonObject(); typeObj->emplace("type", "string"); auto *choicesArray = new Util::JsonArray(); for (auto choice : choices) choicesArray->append(choice); typeObj->emplace("choices", choicesArray); - if (defaultValue != boost::none) typeObj->emplace("default_value", *defaultValue); + if (defaultValue != std::nullopt) typeObj->emplace("default_value", *defaultValue); return typeObj; } @@ -193,11 +192,11 @@ static inline void addOneOf(Util::JsonArray *dataJson, Util::JsonArray *choicesJ dataJson->append(oneOfJson); } -static inline boost::optional transformMatchType( +static inline std::optional transformMatchType( p4configv1::MatchField_MatchType matchType) { switch (matchType) { case p4configv1::MatchField_MatchType_UNSPECIFIED: - return boost::none; + return std::nullopt; case p4configv1::MatchField_MatchType_EXACT: return cstring("Exact"); case p4configv1::MatchField_MatchType_LPM: @@ -209,17 +208,17 @@ static inline boost::optional transformMatchType( case p4configv1::MatchField_MatchType_OPTIONAL: return cstring("Optional"); default: - return boost::none; + return std::nullopt; } } -static inline boost::optional transformOtherMatchType(std::string matchType) { +static inline std::optional transformOtherMatchType(std::string matchType) { if (matchType == "atcam_partition_index") return cstring("ATCAM"); else if (matchType == "dleft_hash") return cstring("DLEFT_HASH"); else - return boost::none; + return std::nullopt; } template @@ -330,9 +329,8 @@ class BFRuntimeGenerator { Unit unit; Util::JsonArray *annotations; - static boost::optional from(const p4configv1::Counter &counterInstance); - static boost::optional fromDirect( - const p4configv1::DirectCounter &counterInstance); + static std::optional from(const p4configv1::Counter &counterInstance); + static std::optional fromDirect(const p4configv1::DirectCounter &counterInstance); }; /// Common meter representation between PSA and other architectures @@ -345,8 +343,8 @@ class BFRuntimeGenerator { Unit unit; Util::JsonArray *annotations; - static boost::optional from(const p4configv1::Meter &meterInstance); - static boost::optional fromDirect(const p4configv1::DirectMeter &meterInstance); + static std::optional from(const p4configv1::Meter &meterInstance); + static std::optional fromDirect(const p4configv1::DirectMeter &meterInstance); }; /// Common action profile / selector representation between PSA and other @@ -358,8 +356,8 @@ class BFRuntimeGenerator { std::vector tableIds; Util::JsonArray *annotations; static P4Id makeActProfId(P4Id implementationId); - static boost::optional from(const p4configv1::P4Info &p4info, - const p4configv1::ActionProfile &actionProfile); + static std::optional from(const p4configv1::P4Info &p4info, + const p4configv1::ActionProfile &actionProfile); }; /// Common digest representation between PSA and other architectures @@ -369,7 +367,7 @@ class BFRuntimeGenerator { p4configv1::P4DataTypeSpec typeSpec; Util::JsonArray *annotations; - static boost::optional from(const p4configv1::Digest &digest); + static std::optional from(const p4configv1::Digest &digest); }; /// Common register representation between PSA and other architectures @@ -381,7 +379,7 @@ class BFRuntimeGenerator { p4configv1::P4DataTypeSpec typeSpec; Util::JsonArray *annotations; - static boost::optional from(const p4configv1::Register ®Instance); + static std::optional from(const p4configv1::Register ®Instance); }; void addMatchTables(Util::JsonArray *tablesJson) const; @@ -403,7 +401,7 @@ class BFRuntimeGenerator { Util::JsonArray *attributesJson, P4Id maxActionParamId = 0) const; - virtual boost::optional actProfHasSelector(P4Id actProfId) const; + virtual std::optional actProfHasSelector(P4Id actProfId) const; /// Generates the JSON array for table action specs. When the function /// returns normally and @maxActionParamId is not NULL, @maxActionParamId is /// set to the maximum assigned id for an action parameter across all @@ -411,8 +409,8 @@ class BFRuntimeGenerator { /// fields) need to receive a distinct id in the same space. Util::JsonArray *makeActionSpecs(const p4configv1::Table &table, P4Id *maxActionParamId = nullptr) const; - virtual boost::optional getDirectCounter(P4Id counterId) const; - virtual boost::optional getDirectMeter(P4Id meterId) const; + virtual std::optional getDirectCounter(P4Id counterId) const; + virtual std::optional getDirectMeter(P4Id meterId) const; /// Transforms a P4Info @typeSpec to a list of JSON objects matching the /// BF-RT format. @instanceType and @instanceName are used for logging error diff --git a/control-plane/bytestrings.cpp b/control-plane/bytestrings.cpp index 2c5cd9f94aa..3cb4273e91a 100644 --- a/control-plane/bytestrings.cpp +++ b/control-plane/bytestrings.cpp @@ -26,11 +26,11 @@ namespace ControlPlaneAPI { /// Convert a bignum to the P4Runtime bytes representation. The value must fit /// within the provided @width expressed in bits. Padding will be added as /// necessary (as the most significant bits). -boost::optional stringReprConstant(big_int value, int width) { +std::optional stringReprConstant(big_int value, int width) { // TODO(antonin): support negative values if (value < 0) { ::error(ErrorType::ERR_UNSUPPORTED, "%1%: Negative values not supported yet", value); - return boost::none; + return std::nullopt; } BUG_CHECK(width > 0, "Unexpected width 0"); size_t bitsRequired = floor_log2(value) + 1; @@ -55,13 +55,13 @@ boost::optional stringReprConstant(big_int value, int width) { /// Convert a Constant to the P4Runtime bytes representation by calling /// stringReprConstant. -boost::optional stringRepr(const IR::Constant *constant, int width) { +std::optional stringRepr(const IR::Constant *constant, int width) { return stringReprConstant(constant->value, width); } /// Convert a BoolLiteral to the P4Runtime bytes representation by calling /// stringReprConstant. -boost::optional stringRepr(const IR::BoolLiteral *constant, int width) { +std::optional stringRepr(const IR::BoolLiteral *constant, int width) { auto v = static_cast(constant->value ? 1 : 0); return stringReprConstant(v, width); } diff --git a/control-plane/bytestrings.h b/control-plane/bytestrings.h index 160d923c2c8..2938b37b82d 100644 --- a/control-plane/bytestrings.h +++ b/control-plane/bytestrings.h @@ -17,10 +17,9 @@ limitations under the License. #ifndef CONTROL_PLANE_BYTESTRINGS_H_ #define CONTROL_PLANE_BYTESTRINGS_H_ +#include #include -#include - #include "lib/big_int_util.h" namespace IR { @@ -34,11 +33,11 @@ namespace P4 { namespace ControlPlaneAPI { -boost::optional stringRepr(const IR::Constant *constant, int width); +std::optional stringRepr(const IR::Constant *constant, int width); -boost::optional stringRepr(const IR::BoolLiteral *constant, int width); +std::optional stringRepr(const IR::BoolLiteral *constant, int width); -boost::optional stringReprConstant(big_int value, int width); +std::optional stringReprConstant(big_int value, int width); } // namespace ControlPlaneAPI diff --git a/control-plane/p4RuntimeArchHandler.cpp b/control-plane/p4RuntimeArchHandler.cpp index 4fcee27da41..7b7104da194 100644 --- a/control-plane/p4RuntimeArchHandler.cpp +++ b/control-plane/p4RuntimeArchHandler.cpp @@ -14,10 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ +#include #include // for std::ostringstream -#include - #include "frontends/common/resolveReferences/referenceMap.h" // TODO(antonin): this include should go away when we cleanup getTableSize // implementation. @@ -39,18 +38,17 @@ namespace ControlPlaneAPI { namespace Helpers { -boost::optional getExternInstanceFromProperty(const IR::P4Table *table, - const cstring &propertyName, - ReferenceMap *refMap, - TypeMap *typeMap, - bool *isConstructedInPlace) { +std::optional getExternInstanceFromProperty(const IR::P4Table *table, + const cstring &propertyName, + ReferenceMap *refMap, TypeMap *typeMap, + bool *isConstructedInPlace) { auto property = table->properties->getProperty(propertyName); - if (property == nullptr) return boost::none; + if (property == nullptr) return std::nullopt; if (!property->value->is()) { ::error(ErrorType::ERR_EXPECTED, "Expected %1% property value for table %2% to be an expression: %3%", propertyName, table->controlPlaneName(), property); - return boost::none; + return std::nullopt; } auto expr = property->value->to()->expression; @@ -61,7 +59,7 @@ boost::optional getExternInstanceFromProperty(const IR::P4Table "Table '%1%' has an anonymous table property '%2%' with no name annotation, " "which is not supported by P4Runtime", table->controlPlaneName(), propertyName); - return boost::none; + return std::nullopt; } auto name = property->controlPlaneName(); auto externInstance = ExternInstance::resolve(expr, refMap, typeMap, name); @@ -70,7 +68,7 @@ boost::optional getExternInstanceFromProperty(const IR::P4Table "Expected %1% property value for table %2% to resolve to an " "extern instance: %3%", propertyName, table->controlPlaneName(), property); - return boost::none; + return std::nullopt; } return externInstance; diff --git a/control-plane/p4RuntimeArchHandler.h b/control-plane/p4RuntimeArchHandler.h index 985f5e39a62..2dc1b65b347 100644 --- a/control-plane/p4RuntimeArchHandler.h +++ b/control-plane/p4RuntimeArchHandler.h @@ -17,10 +17,9 @@ limitations under the License. #ifndef CONTROL_PLANE_P4RUNTIMEARCHHANDLER_H_ #define CONTROL_PLANE_P4RUNTIMEARCHHANDLER_H_ +#include #include -#include - #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" #include "p4/config/v1/p4info.pb.h" @@ -99,7 +98,7 @@ class P4RuntimeSymbolTableIface { virtual void add(P4RuntimeSymbolType type, const IR::IDeclaration *declaration) = 0; /// Add a @type symbol with @name and possibly an explicit P4 '@id'. virtual void add(P4RuntimeSymbolType type, cstring name, - boost::optional id = boost::none) = 0; + std::optional id = std::nullopt) = 0; /// @return the P4Runtime id for the symbol of @type corresponding to /// @declaration. virtual p4rt_id_t getId(P4RuntimeSymbolType type, @@ -189,12 +188,11 @@ struct P4RuntimeArchHandlerBuilderIface { namespace Helpers { /// @return an extern instance defined or referenced by the value of @table's -/// @propertyName property, or boost::none if no extern was referenced. -boost::optional getExternInstanceFromProperty(const IR::P4Table *table, - const cstring &propertyName, - ReferenceMap *refMap, - TypeMap *typeMap, - bool *isConstructedInPlace = nullptr); +/// @propertyName property, or std::nullopt if no extern was referenced. +std::optional getExternInstanceFromProperty(const IR::P4Table *table, + const cstring &propertyName, + ReferenceMap *refMap, TypeMap *typeMap, + bool *isConstructedInPlace = nullptr); /// @return true if the extern instance assigned to property @propertyName for /// the @table was constructed in-place or outside of teh @table declaration. @@ -355,16 +353,16 @@ struct Counterlike { /// The size parameter to the instance. const int64_t size; /// If not none, the instance is a direct resource associated with @table. - const boost::optional table; + const std::optional table; /// If the type of the index is a user-defined type, this is the name of the type. Otherwise it /// is nullptr. const cstring index_type_name; /// @return the information required to serialize an explicit @instance of /// @Kind, which is defined inside a control block. - static boost::optional> from(const IR::ExternBlock *instance, - const ReferenceMap *refMap, P4::TypeMap *typeMap, - ::p4::config::v1::P4TypeInfo *p4RtTypeInfo) { + static std::optional> from(const IR::ExternBlock *instance, + const ReferenceMap *refMap, P4::TypeMap *typeMap, + ::p4::config::v1::P4TypeInfo *p4RtTypeInfo) { CHECK_NULL(instance); auto declaration = instance->node->to(); @@ -376,7 +374,7 @@ struct Counterlike { ::error(ErrorType::ERR_INVALID, "%1% '%2%' has a unit type which is not an enum constant: %3%", CounterlikeTraits::name(), declaration, unit); - return boost::none; + return std::nullopt; } auto size = instance->getParameterValue(CounterlikeTraits::sizeParamName()); @@ -389,13 +387,13 @@ struct Counterlike { } else { ::error(ErrorType::ERR_INVALID, "%1% '%2%' has a non-constant size: %3%", CounterlikeTraits::name(), declaration, size); - return boost::none; + return std::nullopt; } cstring index_type_name = nullptr; auto indexTypeParamIdx = CounterlikeTraits::indexTypeParamIdx(); // In v1model, the index is a bit<32>, in PSA it is determined by a type parameter. - if (indexTypeParamIdx != boost::none) { + if (indexTypeParamIdx != std::nullopt) { // retrieve type parameter for the index. BUG_CHECK(declaration->type->is(), "%1%: expected Type_Specialized", declaration->type); @@ -414,22 +412,22 @@ struct Counterlike { declaration->to(), unit->to()->name, int(val), - boost::none, + std::nullopt, index_type_name}; } /// @return the information required to serialize an @instance of @Kind which /// is either defined in or referenced by a property value of @table. (This /// implies that @instance is a direct resource of @table.) - static boost::optional> fromDirect(const ExternInstance &instance, - const IR::P4Table *table) { + static std::optional> fromDirect(const ExternInstance &instance, + const IR::P4Table *table) { CHECK_NULL(table); - BUG_CHECK(instance.name != boost::none, "Caller should've ensured we have a name"); + BUG_CHECK(instance.name != std::nullopt, "Caller should've ensured we have a name"); if (instance.type->name != CounterlikeTraits::directTypeName()) { ::error(ErrorType::ERR_EXPECTED, "Expected a direct %1%: %2%", CounterlikeTraits::name(), instance.expression); - return boost::none; + return std::nullopt; } auto unitArgument = instance.substitution.lookupByName("type")->expression; @@ -437,13 +435,13 @@ struct Counterlike { ::error(ErrorType::ERR_EXPECTED, "Direct %1% instance %2% should take a constructor argument", CounterlikeTraits::name(), instance.expression); - return boost::none; + return std::nullopt; } if (!unitArgument->is()) { ::error(ErrorType::ERR_UNEXPECTED, "Direct %1% instance %2% has an unexpected constructor argument", CounterlikeTraits::name(), instance.expression); - return boost::none; + return std::nullopt; } auto unit = unitArgument->to()->member.name; @@ -457,13 +455,13 @@ struct Counterlike { }; /// @return the direct counter associated with @table, if it has one, or -/// boost::none otherwise. +/// std::nullopt otherwise. template -boost::optional> getDirectCounterlike(const IR::P4Table *table, - ReferenceMap *refMap, TypeMap *typeMap) { +std::optional> getDirectCounterlike(const IR::P4Table *table, + ReferenceMap *refMap, TypeMap *typeMap) { auto propertyName = CounterlikeTraits::directPropertyName(); auto instance = getExternInstanceFromProperty(table, propertyName, refMap, typeMap); - if (!instance) return boost::none; + if (!instance) return std::nullopt; return Counterlike::fromDirect(*instance, table); } diff --git a/control-plane/p4RuntimeArchStandard.cpp b/control-plane/p4RuntimeArchStandard.cpp index b291046c50a..67146168530 100644 --- a/control-plane/p4RuntimeArchStandard.cpp +++ b/control-plane/p4RuntimeArchStandard.cpp @@ -16,11 +16,10 @@ limitations under the License. #include "p4RuntimeArchStandard.h" +#include #include #include -#include - #include "frontends/common/resolveReferences/referenceMap.h" #include "frontends/p4/fromv1.0/v1model.h" #include "frontends/p4/typeMap.h" @@ -75,12 +74,12 @@ class P4RuntimeArchHandlerV1Model final : public P4RuntimeArchHandlerCommon getDigestCall(const P4::ExternFunction *function, - ReferenceMap *refMap, P4::TypeMap *typeMap, - p4configv1::P4TypeInfo *p4RtTypeInfo) { + /// @call, or std::nullopt if @call is not a digest() call or is invalid. + static std::optional getDigestCall(const P4::ExternFunction *function, + ReferenceMap *refMap, P4::TypeMap *typeMap, + p4configv1::P4TypeInfo *p4RtTypeInfo) { if (function->method->name != P4V1::V1Model::instance.digest_receiver.name) - return boost::none; + return std::nullopt; auto call = function->expr; BUG_CHECK(call->typeArguments->size() == 1, "%1%: Expected one type argument", call); diff --git a/control-plane/p4RuntimeArchStandard.h b/control-plane/p4RuntimeArchStandard.h index e264199caf7..e9610799665 100644 --- a/control-plane/p4RuntimeArchStandard.h +++ b/control-plane/p4RuntimeArchStandard.h @@ -89,7 +89,7 @@ struct CounterlikeTraits> { return CounterSpec::BOTH; return CounterSpec::UNSPECIFIED; } - static boost::optional indexTypeParamIdx() { return boost::none; } + static std::optional indexTypeParamIdx() { return std::nullopt; } }; template <> @@ -111,7 +111,7 @@ struct CounterlikeTraits> { return CounterSpec::BOTH; return CounterSpec::UNSPECIFIED; } - static boost::optional indexTypeParamIdx() { return 0; } + static std::optional indexTypeParamIdx() { return 0; } }; /// @ref CounterlikeTraits<> specialization for @ref CounterExtern for PSA @@ -134,7 +134,7 @@ struct CounterlikeTraits> { } // the index of the type parameter for the counter index, in the type // parameter list of the extern type declaration. - static boost::optional indexTypeParamIdx() { return 1; } + static std::optional indexTypeParamIdx() { return 1; } }; /// @ref CounterlikeTraits<> specialization for @ref CounterExtern for PNA @@ -157,7 +157,7 @@ struct CounterlikeTraits> { } // the index of the type parameter for the counter index, in the type // parameter list of the extern type declaration. - static boost::optional indexTypeParamIdx() { return 1; } + static std::optional indexTypeParamIdx() { return 1; } }; /// @ref CounterlikeTraits<> specialization for @ref MeterExtern for v1model @@ -178,7 +178,7 @@ struct CounterlikeTraits> { return MeterSpec::BYTES; return MeterSpec::UNSPECIFIED; } - static boost::optional indexTypeParamIdx() { return boost::none; } + static std::optional indexTypeParamIdx() { return std::nullopt; } }; template <> @@ -198,7 +198,7 @@ struct CounterlikeTraits> { return MeterSpec::BYTES; return MeterSpec::UNSPECIFIED; } - static boost::optional indexTypeParamIdx() { return 0; } + static std::optional indexTypeParamIdx() { return 0; } }; /// @ref CounterlikeTraits<> specialization for @ref MeterExtern for PSA @@ -219,7 +219,7 @@ struct CounterlikeTraits> { } // the index of the type parameter for the meter index, in the type // parameter list of the extern type declaration. - static boost::optional indexTypeParamIdx() { return 0; } + static std::optional indexTypeParamIdx() { return 0; } }; /// @ref CounterlikeTraits<> specialization for @ref MeterExtern for PNA @@ -240,7 +240,7 @@ struct CounterlikeTraits> { } // the index of the type parameter for the meter index, in the type // parameter list of the extern type declaration. - static boost::optional indexTypeParamIdx() { return 0; } + static std::optional indexTypeParamIdx() { return 0; } }; } // namespace Helpers @@ -383,7 +383,7 @@ struct RegisterTraits { // the index of the type parameter for the data stored in the register, in // the type parameter list of the extern type declaration static size_t dataTypeParamIdx() { return 0; } - static boost::optional indexTypeParamIdx() { return boost::none; } + static std::optional indexTypeParamIdx() { return std::nullopt; } }; template <> @@ -394,7 +394,7 @@ struct RegisterTraits { // the index of the type parameter for the data stored in the register, in // the type parameter list of the extern type declaration static size_t dataTypeParamIdx() { return 0; } - static boost::optional indexTypeParamIdx() { return 1; } + static std::optional indexTypeParamIdx() { return 1; } }; template <> @@ -405,7 +405,7 @@ struct RegisterTraits { static size_t dataTypeParamIdx() { return 0; } // the index of the type parameter for the register index, in the type // parameter list of the extern type declaration. - static boost::optional indexTypeParamIdx() { return 1; } + static std::optional indexTypeParamIdx() { return 1; } }; template <> @@ -416,7 +416,7 @@ struct RegisterTraits { static size_t dataTypeParamIdx() { return 0; } // the index of the type parameter for the register index, in the type // parameter list of the extern type declaration. - static boost::optional indexTypeParamIdx() { return 1; } + static std::optional indexTypeParamIdx() { return 1; } }; //// The information about a digest call which is needed to serialize it. @@ -440,11 +440,11 @@ struct Register { const cstring index_type_name; /// @return the information required to serialize an @instance of register - /// or boost::none in case of error. + /// or std::nullopt in case of error. template - static boost::optional from(const IR::ExternBlock *instance, - const ReferenceMap *refMap, P4::TypeMap *typeMap, - p4configv1::P4TypeInfo *p4RtTypeInfo) { + static std::optional from(const IR::ExternBlock *instance, const ReferenceMap *refMap, + P4::TypeMap *typeMap, + p4configv1::P4TypeInfo *p4RtTypeInfo) { CHECK_NULL(instance); auto declaration = instance->node->to(); @@ -452,13 +452,13 @@ struct Register { if (!size->is()) { ::error(ErrorType::ERR_UNSUPPORTED, "Register '%1%' has a non-constant size: %2%", declaration, size); - return boost::none; + return std::nullopt; } if (!size->to()->fitsInt()) { ::error(ErrorType::ERR_UNSUPPORTED, "Register '%1%' has a size that doesn't fit in an integer: %2%", declaration, size); - return boost::none; + return std::nullopt; } // retrieve type parameter for the register instance and convert it to P4DataTypeSpec @@ -475,7 +475,7 @@ struct Register { cstring index_type_name = nullptr; auto indexTypeParamIdx = RegisterTraits::indexTypeParamIdx(); // In v1model, the index is a bit<32>, in PSA it is determined by a type parameter. - if (indexTypeParamIdx != boost::none) { + if (indexTypeParamIdx != std::nullopt) { // retrieve type parameter for the index. BUG_CHECK(declaration->type->is(), "%1%: expected Type_Specialized", declaration->type); @@ -709,35 +709,34 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { (void)p4info; } - static boost::optional getActionProfile(cstring name, - const IR::Type_Extern *type, - int64_t size, - const IR::IAnnotated *annotations) { + static std::optional getActionProfile(cstring name, const IR::Type_Extern *type, + int64_t size, + const IR::IAnnotated *annotations) { ActionProfileType actionProfileType; if (type->name == ActionSelectorTraits::typeName()) { actionProfileType = ActionProfileType::INDIRECT_WITH_SELECTOR; } else if (type->name == ActionProfileTraits::typeName()) { actionProfileType = ActionProfileType::INDIRECT; } else { - return boost::none; + return std::nullopt; } return ActionProfile{name, actionProfileType, size, annotations}; } /// @return the action profile referenced in @table's implementation property, - /// if it has one, or boost::none otherwise. - static boost::optional getActionProfile(const IR::P4Table *table, - ReferenceMap *refMap, TypeMap *typeMap) { + /// if it has one, or std::nullopt otherwise. + static std::optional getActionProfile(const IR::P4Table *table, + ReferenceMap *refMap, TypeMap *typeMap) { auto propertyName = ActionProfileTraits::propertyName(); auto instance = getExternInstanceFromProperty(table, propertyName, refMap, typeMap); - if (!instance) return boost::none; + if (!instance) return std::nullopt; auto size = instance->substitution.lookupByName(ActionProfileTraits::sizeParamName()) ->expression; if (!size->template is()) { ::error(ErrorType::ERR_INVALID, "Action profile '%1%' has non-constant size '%2%'", *instance->name, size); - return boost::none; + return std::nullopt; } return getActionProfile(*instance->name, instance->type, size->template to()->asInt(), @@ -745,13 +744,13 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { } /// @return the action profile declared with @decl - static boost::optional getActionProfile(const IR::ExternBlock *instance) { + static std::optional getActionProfile(const IR::ExternBlock *instance) { auto decl = instance->node->to(); auto size = instance->getParameterValue(ActionProfileTraits::sizeParamName()); if (!size->template is()) { ::error(ErrorType::ERR_INVALID, "Action profile '%1%' has non-constant size '%2%'", decl->controlPlaneName(), size); - return boost::none; + return std::nullopt; } return getActionProfile(decl->controlPlaneName(), instance->type, size->template to()->asInt(), @@ -899,15 +898,15 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { return nullptr; } - static boost::optional getTableImplementationName(const IR::P4Table *table, - ReferenceMap *refMap) { + static std::optional getTableImplementationName(const IR::P4Table *table, + ReferenceMap *refMap) { const IR::Property *impl = getTableImplementationProperty(table); - if (impl == nullptr) return boost::none; + if (impl == nullptr) return std::nullopt; if (!impl->value->is()) { ::error(ErrorType::ERR_EXPECTED, "Expected implementation property value for table %1% to be an expression: %2%", table->controlPlaneName(), impl); - return boost::none; + return std::nullopt; } auto expr = impl->value->to()->expression; if (expr->is()) return impl->controlPlaneName(); @@ -915,7 +914,7 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { auto decl = refMap->getDeclaration(expr->to()->path, true); return decl->controlPlaneName(); } - return boost::none; + return std::nullopt; } ReferenceMap *refMap; @@ -976,8 +975,8 @@ class P4RuntimeArchHandlerPSAPNA : public P4RuntimeArchHandlerCommon { } /// @return serialization information for the Digest extern instacne @decl - boost::optional getDigest(const IR::Declaration_Instance *decl, - p4configv1::P4TypeInfo *p4RtTypeInfo) { + std::optional getDigest(const IR::Declaration_Instance *decl, + p4configv1::P4TypeInfo *p4RtTypeInfo) { BUG_CHECK(decl->type->is(), "%1%: expected Type_Specialized", decl->type); auto type = decl->type->to(); diff --git a/control-plane/p4RuntimeSerializer.cpp b/control-plane/p4RuntimeSerializer.cpp index ffec6452012..b51ec0ea939 100644 --- a/control-plane/p4RuntimeSerializer.cpp +++ b/control-plane/p4RuntimeSerializer.cpp @@ -23,6 +23,7 @@ limitations under the License. #include #include #include +#include #include #include #include @@ -35,7 +36,6 @@ limitations under the License. #pragma GCC diagnostic pop #include -#include #include #include "frontends/common/options.h" @@ -83,17 +83,17 @@ using Helpers::setPreamble; /// @return the value of @item's explicit name annotation, if it has one. We use /// this rather than e.g. controlPlaneName() when we want to prevent any /// fallback. -static boost::optional explicitNameAnnotation(const IR::IAnnotated *item) { +static std::optional explicitNameAnnotation(const IR::IAnnotated *item) { auto *anno = item->getAnnotation(IR::Annotation::nameAnnotation); - if (!anno) return boost::none; + if (!anno) return std::nullopt; if (anno->expr.size() != 1) { ::error(ErrorType::ERR_INVALID, "A %1% annotation must have one argument", anno); - return boost::none; + return std::nullopt; } auto *str = anno->expr[0]->to(); if (!str) { ::error(ErrorType::ERR_INVALID, "An %1% annotation's argument must be a string", anno); - return boost::none; + return std::nullopt; } return str->value; } @@ -251,17 +251,17 @@ class FieldIdAllocator { std::map idMapping; }; -/// @return @table's default action, if it has one, or boost::none otherwise. -static boost::optional getDefaultAction(const IR::P4Table *table, - ReferenceMap *refMap, TypeMap *typeMap) { +/// @return @table's default action, if it has one, or std::nullopt otherwise. +static std::optional getDefaultAction(const IR::P4Table *table, ReferenceMap *refMap, + TypeMap *typeMap) { // not using getDefaultAction() here as I actually need the property IR node // to check if the default action is constant. auto defaultActionProperty = table->properties->getProperty(IR::TableProperties::defaultActionPropertyName); - if (defaultActionProperty == nullptr) return boost::none; + if (defaultActionProperty == nullptr) return std::nullopt; if (!defaultActionProperty->value->is()) { ::error(ErrorType::ERR_EXPECTED, "Expected an action: %1%", defaultActionProperty); - return boost::none; + return std::nullopt; } auto expr = defaultActionProperty->value->to()->expression; @@ -279,7 +279,7 @@ static boost::optional getDefaultAction(const IR::P4Table *table, ::error(ErrorType::ERR_UNEXPECTED, "Unexpected expression in default action for table %1%: %2%", table->controlPlaneName(), expr); - return boost::none; + return std::nullopt; } return DefaultAction{actionName, defaultActionProperty->isConstant}; @@ -326,10 +326,10 @@ static cstring getMatchTypeName(const IR::PathExpression *matchPathExpr, /// maps the match type name to the corresponding P4Info MatchType enum /// member. If the match type should not be exposed to the control plane and -/// should be ignored, boost::none is returned. If the match type does not +/// should be ignored, std::nullopt is returned. If the match type does not /// correspond to any standard match type known to P4Info, default enum member /// UNSPECIFIED is returned. -static boost::optional getMatchType(cstring matchTypeName) { +static std::optional getMatchType(cstring matchTypeName) { if (matchTypeName == P4CoreLibrary::instance.exactMatch.name) { return MatchField::MatchTypes::EXACT; } else if (matchTypeName == P4CoreLibrary::instance.lpmMatch.name) { @@ -342,7 +342,7 @@ static boost::optional getMatchType(cstring matchTypeName return MatchField::MatchTypes::OPTIONAL; } else if (matchTypeName == P4V1::V1Model::instance.selectorMatchType.name) { // Nothing to do here, we cannot even perform some sanity-checking. - return boost::none; + return std::nullopt; } else { return MatchField::MatchTypes::UNSPECIFIED; } @@ -380,7 +380,7 @@ static std::vector getMatchFields(const IR::P4Table *table, Referenc for (auto keyElement : key->keyElements) { auto matchTypeName = getMatchTypeName(keyElement->matchType, refMap); auto matchType = getMatchType(matchTypeName); - if (matchType == boost::none) continue; + if (matchType == std::nullopt) continue; auto id = idAllocator.getId(keyElement); @@ -797,7 +797,7 @@ class P4RuntimeAnalyzer { CHECK_NULL(matchPathExpr); auto matchTypeName = getMatchTypeName(matchPathExpr, refMap); auto matchType = getMatchType(matchTypeName); - if (matchType == boost::none) { + if (matchType == std::nullopt) { ::error(ErrorType::ERR_UNSUPPORTED, "unsupported match type %1% for Value Set '@match' annotation", matchAnnotation); @@ -1122,9 +1122,9 @@ class P4RuntimeEntriesConverter { /// Convert a key expression to the P4Runtime bytes representation if the /// expression is simple (integer literal or boolean literal) or returns - /// boost::none otherwise. - boost::optional convertSimpleKeyExpression(const IR::Expression *k, int keyWidth, - TypeMap *typeMap) const { + /// std::nullopt otherwise. + std::optional convertSimpleKeyExpression(const IR::Expression *k, int keyWidth, + TypeMap *typeMap) const { if (k->is()) { return stringRepr(k->to(), keyWidth); } else if (k->is()) { @@ -1133,7 +1133,7 @@ class P4RuntimeEntriesConverter { auto mem = k->to(); auto se = mem->type->to(); auto ei = EnumInstance::resolve(mem, typeMap); - if (!ei) return boost::none; + if (!ei) return std::nullopt; if (auto sei = ei->to()) { auto type = sei->value->to(); auto w = se->type->width_bits(); @@ -1141,20 +1141,20 @@ class P4RuntimeEntriesConverter { return stringRepr(type, w); } ::error(ErrorType::ERR_INVALID, "%1% invalid Member key expression", k); - return boost::none; + return std::nullopt; } else if (k->is()) { return convertSimpleKeyExpression(k->to()->expr, keyWidth, typeMap); } else { ::error(ErrorType::ERR_INVALID, "%1% invalid key expression", k); - return boost::none; + return std::nullopt; } } /// Convert a key expression to the big_int integer value if the /// expression is simple (integer literal or boolean literal) or returns - /// boost::none otherwise. - boost::optional simpleKeyExpressionValue(const IR::Expression *k, - TypeMap *typeMap) const { + /// std::nullopt otherwise. + std::optional simpleKeyExpressionValue(const IR::Expression *k, + TypeMap *typeMap) const { if (k->is()) { return k->to()->value; } else if (k->is()) { @@ -1162,17 +1162,17 @@ class P4RuntimeEntriesConverter { } else if (k->is()) { // handle SerEnum members auto mem = k->to(); auto ei = EnumInstance::resolve(mem, typeMap); - if (!ei) return boost::none; + if (!ei) return std::nullopt; if (auto sei = ei->to()) { return simpleKeyExpressionValue(sei->value, typeMap); } ::error(ErrorType::ERR_INVALID, "%1% invalid Member key expression", k); - return boost::none; + return std::nullopt; } else if (k->is()) { return simpleKeyExpressionValue(k->to()->expr, typeMap); } else { ::error(ErrorType::ERR_INVALID, "%1% invalid key expression", k); - return boost::none; + return std::nullopt; } } @@ -1182,7 +1182,7 @@ class P4RuntimeEntriesConverter { protoMatch->set_field_id(fieldId); auto protoExact = protoMatch->mutable_exact(); auto value = convertSimpleKeyExpression(k, keyWidth, typeMap); - if (value == boost::none) return; + if (value == std::nullopt) return; protoExact->set_value(*value); } @@ -1191,11 +1191,11 @@ class P4RuntimeEntriesConverter { if (k->is()) // don't care, skip in P4Runtime message return; int prefixLen; - boost::optional valueStr; + std::optional valueStr; if (k->is()) { auto km = k->to(); auto value = simpleKeyExpressionValue(km->left, typeMap); - if (value == boost::none) return; + if (value == std::nullopt) return; auto trailing_zeros = [keyWidth](const big_int &n) -> int { return (n == 0) ? keyWidth : boost::multiprecision::lsb(n); }; @@ -1221,7 +1221,7 @@ class P4RuntimeEntriesConverter { prefixLen = keyWidth; valueStr = convertSimpleKeyExpression(k, keyWidth, typeMap); } - if (valueStr == boost::none) return; + if (valueStr == std::nullopt) return; auto protoMatch = protoEntry->add_match(); protoMatch->set_field_id(fieldId); auto protoLpm = protoMatch->mutable_lpm(); @@ -1233,13 +1233,13 @@ class P4RuntimeEntriesConverter { int keyWidth, TypeMap *typeMap) const { if (k->is()) // don't care, skip in P4Runtime message return; - boost::optional valueStr; - boost::optional maskStr; + std::optional valueStr; + std::optional maskStr; if (k->is()) { auto km = k->to(); auto value = simpleKeyExpressionValue(km->left, typeMap); auto mask = simpleKeyExpressionValue(km->right, typeMap); - if (value == boost::none || mask == boost::none) return; + if (value == std::nullopt || mask == std::nullopt) return; if ((*value & *mask) != *value) { ::warning(ErrorType::WARN_MISMATCH, "P4Runtime requires that Ternary matches have masked-off bits set to 0, " @@ -1255,7 +1255,7 @@ class P4RuntimeEntriesConverter { valueStr = convertSimpleKeyExpression(k, keyWidth, typeMap); maskStr = stringReprConstant(Util::mask(keyWidth), keyWidth); } - if (valueStr == boost::none || maskStr == boost::none) return; + if (valueStr == std::nullopt || maskStr == std::nullopt) return; auto protoMatch = protoEntry->add_match(); protoMatch->set_field_id(fieldId); auto protoTernary = protoMatch->mutable_ternary(); @@ -1267,13 +1267,13 @@ class P4RuntimeEntriesConverter { TypeMap *typeMap) const { if (k->is()) // don't care, skip in P4Runtime message return; - boost::optional startStr; - boost::optional endStr; + std::optional startStr; + std::optional endStr; if (k->is()) { auto kr = k->to(); auto start = simpleKeyExpressionValue(kr->left, typeMap); auto end = simpleKeyExpressionValue(kr->right, typeMap); - if (start == boost::none || end == boost::none) return; + if (start == std::nullopt || end == std::nullopt) return; // Error on invalid range values big_int maxValue = (big_int(1) << keyWidth) - 1; // NOTE: If end value is > max allowed for keyWidth, value gets @@ -1291,7 +1291,7 @@ class P4RuntimeEntriesConverter { startStr = convertSimpleKeyExpression(k, keyWidth, typeMap); endStr = startStr; } - if (startStr == boost::none || endStr == boost::none) return; + if (startStr == std::nullopt || endStr == std::nullopt) return; auto protoMatch = protoEntry->add_match(); protoMatch->set_field_id(fieldId); auto protoRange = protoMatch->mutable_range(); @@ -1307,7 +1307,7 @@ class P4RuntimeEntriesConverter { protoMatch->set_field_id(fieldId); auto protoOptional = protoMatch->mutable_optional(); auto value = convertSimpleKeyExpression(k, keyWidth, typeMap); - if (value == boost::none) return; + if (value == std::nullopt) return; protoOptional->set_value(*value); } diff --git a/control-plane/p4RuntimeSymbolTable.cpp b/control-plane/p4RuntimeSymbolTable.cpp index 8e693bf254b..d7ee645692b 100644 --- a/control-plane/p4RuntimeSymbolTable.cpp +++ b/control-plane/p4RuntimeSymbolTable.cpp @@ -35,16 +35,16 @@ bool isControllerHeader(const IR::Type_Header *type) { bool isHidden(const IR::Node *node) { return node->getAnnotation("hidden") != nullptr; } -boost::optional getIdAnnotation(const IR::IAnnotated *node) { +std::optional getIdAnnotation(const IR::IAnnotated *node) { const auto *idAnnotation = node->getAnnotation("id"); if (idAnnotation == nullptr) { - return boost::none; + return std::nullopt; } const auto *idConstant = idAnnotation->expr[0]->to(); CHECK_NULL(idConstant); if (!idConstant->fitsUint()) { ::error(ErrorType::ERR_INVALID, "%1%: @id should be an unsigned integer", node); - return boost::none; + return std::nullopt; } return static_cast(idConstant->value); } @@ -52,17 +52,17 @@ boost::optional getIdAnnotation(const IR::IAnnotated *node) { /// @return the value of any P4 '@id' annotation @declaration may have, and /// ensure that the value is correct with respect to the P4Runtime /// specification. The name 'externalId' is in analogy with externalName(). -static boost::optional externalId(const P4RuntimeSymbolType &type, - const IR::IDeclaration *declaration) { +static std::optional externalId(const P4RuntimeSymbolType &type, + const IR::IDeclaration *declaration) { CHECK_NULL(declaration); if (!declaration->is()) { - return boost::none; // Assign an id later; see below. + return std::nullopt; // Assign an id later; see below. } // If the user specified an @id annotation, use that. auto idOrNone = getIdAnnotation(declaration->to()); if (!idOrNone) { - return boost::none; // the user didn't assign an id + return std::nullopt; // the user didn't assign an id } auto id = *idOrNone; @@ -72,7 +72,7 @@ static boost::optional externalId(const P4RuntimeSymbolType &type, const auto prefixMask = static_cast(0xff) << 24; if ((id & prefixMask) != 0 && (id & prefixMask) != typePrefix) { ::error(ErrorType::ERR_INVALID, "%1%: @id has the wrong 8-bit prefix", declaration); - return boost::none; + return std::nullopt; } id |= typePrefix; @@ -175,7 +175,7 @@ void P4::ControlPlaneAPI::P4RuntimeSymbolTable::add(P4RuntimeSymbolType type, } void P4::ControlPlaneAPI::P4RuntimeSymbolTable::add(P4RuntimeSymbolType type, cstring name, - boost::optional id) { + std::optional id) { auto &symbolTable = symbolTables[type]; if (symbolTable.find(name) != symbolTable.end()) { return; // This is a duplicate, but that's OK. @@ -210,7 +210,7 @@ cstring P4::ControlPlaneAPI::P4RuntimeSymbolTable::getAlias(cstring name) const } P4::ControlPlaneAPI::p4rt_id_t P4::ControlPlaneAPI::P4RuntimeSymbolTable::tryToAssignId( - boost::optional id) { + std::optional id) { if (!id) { // The user didn't assign an id, so return the special value // INVALID_ID to indicate that computeIds() should assign one later. @@ -255,7 +255,7 @@ void P4::ControlPlaneAPI::P4RuntimeSymbolTable::computeIdsForSymbols(P4RuntimeSy // to resolve hash collisions, the id that we select depends on the // order in which the names are hashed. This is why we sort the // names above. - boost::optional id = probeForId( + std::optional id = probeForId( nameId, [=](uint32_t nameId) { return (resourceType << 24) | (nameId & 0xffffff); }); if (!id) { diff --git a/control-plane/p4RuntimeSymbolTable.h b/control-plane/p4RuntimeSymbolTable.h index 4de045a2a26..e690b75f34b 100644 --- a/control-plane/p4RuntimeSymbolTable.h +++ b/control-plane/p4RuntimeSymbolTable.h @@ -49,8 +49,8 @@ bool isControllerHeader(const IR::Type_Header *type); bool isHidden(const IR::Node *node); /// @return the id allocated to the object through the @id annotation if any, or -/// boost::none. -boost::optional getIdAnnotation(const IR::IAnnotated *node); +/// std::nullopt. +std::optional getIdAnnotation(const IR::IAnnotated *node); /** * Stores a set of P4 symbol suffixes. Symbols consist of path components @@ -131,7 +131,7 @@ class P4RuntimeSymbolTable : public P4RuntimeSymbolTableIface { /// Add a @type symbol with @name and possibly an explicit P4 '@id'. void add(P4RuntimeSymbolType type, cstring name, - boost::optional id = boost::none) override; + std::optional id = std::nullopt) override; /// @return the P4Runtime id for the symbol of @type corresponding to /// @declaration. @@ -153,7 +153,7 @@ class P4RuntimeSymbolTable : public P4RuntimeSymbolTableIface { /// @return an initial (possibly invalid) id for a resource, and if the id /// is not invalid, record the assignment. An initial @id typically comes /// from the P4 '@id' annotation. - p4rt_id_t tryToAssignId(boost::optional id); + p4rt_id_t tryToAssignId(std::optional id); /** * Assign an id to each resource of @type (ACTION, TABLE, etc..) which does @@ -174,13 +174,13 @@ class P4RuntimeSymbolTable : public P4RuntimeSymbolTableIface { * indicating a resource type, and those bits need to remain correct. */ template - boost::optional probeForId(const uint32_t sourceValue, ConstructIdFunc constructId) { + std::optional probeForId(const uint32_t sourceValue, ConstructIdFunc constructId) { uint32_t value = sourceValue; while (assignedIds.find(constructId(value)) != assignedIds.end()) { ++value; if (value == sourceValue) { - return boost::none; // We wrapped around; there's no unassigned - // id left. + return std::nullopt; // We wrapped around; there's no unassigned + // id left. } } diff --git a/frontends/common/applyOptionsPragmas.cpp b/frontends/common/applyOptionsPragmas.cpp index e85422b5967..dc67166067b 100644 --- a/frontends/common/applyOptionsPragmas.cpp +++ b/frontends/common/applyOptionsPragmas.cpp @@ -47,14 +47,14 @@ void ApplyOptionsPragmas::end_apply() { compilerOptionsInstance.process(options.size(), const_cast(options.data())); } -boost::optional P4COptionPragmaParser::tryToParse( +std::optional P4COptionPragmaParser::tryToParse( const IR::Annotation *annotation) { auto pragmaName = annotation->name.name; if (pragmaName == "diagnostic") return parseDiagnostic(annotation); - return boost::none; + return std::nullopt; } -boost::optional P4COptionPragmaParser::parseDiagnostic( +std::optional P4COptionPragmaParser::parseDiagnostic( const IR::Annotation *annotation) { CommandLineOptions newOptions; @@ -73,7 +73,7 @@ boost::optional P4COptionPragmaParser:: if (pragmaArgs->size() != 2) { ::warning(ErrorType::WARN_MISSING, "@diagnostic takes two arguments: %1%", annotation); - return boost::none; + return std::nullopt; } auto *diagnosticName = pragmaArgs->at(0)->to(); @@ -81,7 +81,7 @@ boost::optional P4COptionPragmaParser:: if (!diagnosticName || !diagnosticAction) { ::warning(ErrorType::WARN_MISSING, "@diagnostic arguments must be strings: %1%", annotation); - return boost::none; + return std::nullopt; } cstring diagnosticOption; @@ -96,7 +96,7 @@ boost::optional P4COptionPragmaParser:: "@diagnostic's second argument must be 'disable', " "'warn', or 'error': %1%", annotation); - return boost::none; + return std::nullopt; } diagnosticOption += diagnosticName->value; diff --git a/frontends/common/applyOptionsPragmas.h b/frontends/common/applyOptionsPragmas.h index 667c8896f6f..e2c4c55f4db 100644 --- a/frontends/common/applyOptionsPragmas.h +++ b/frontends/common/applyOptionsPragmas.h @@ -17,10 +17,9 @@ limitations under the License. #ifndef FRONTENDS_COMMON_APPLYOPTIONSPRAGMAS_H_ #define FRONTENDS_COMMON_APPLYOPTIONSPRAGMAS_H_ +#include #include -#include - #include "ir/ir.h" #include "ir/visitor.h" #include "lib/cstring.h" @@ -33,7 +32,7 @@ class IOptionPragmaParser { public: using CommandLineOptions = std::vector; - virtual boost::optional tryToParse(const IR::Annotation *annotation) = 0; + virtual std::optional tryToParse(const IR::Annotation *annotation) = 0; }; /** @@ -78,10 +77,10 @@ class ApplyOptionsPragmas : public Inspector { */ class P4COptionPragmaParser : public IOptionPragmaParser { public: - boost::optional tryToParse(const IR::Annotation *annotation) override; + std::optional tryToParse(const IR::Annotation *annotation) override; private: - boost::optional parseDiagnostic(const IR::Annotation *annotation); + std::optional parseDiagnostic(const IR::Annotation *annotation); }; } // namespace P4 diff --git a/frontends/common/parseInput.cpp b/frontends/common/parseInput.cpp index 0e5db38506e..fcbd6c4d345 100644 --- a/frontends/common/parseInput.cpp +++ b/frontends/common/parseInput.cpp @@ -18,10 +18,9 @@ limitations under the License. #include #include +#include #include -#include - #include "frontends/p4/fromv1.0/converters.h" #include "frontends/p4/frontend.h" #include "frontends/parsers/parserDriver.h" diff --git a/frontends/common/parseInput.h b/frontends/common/parseInput.h index a0470bf0838..bea1440ae91 100644 --- a/frontends/common/parseInput.h +++ b/frontends/common/parseInput.h @@ -33,7 +33,7 @@ namespace P4 { template static const IR::P4Program *parseV1Program(Input &stream, const char *sourceFile, unsigned sourceLine, - boost::optional debugHook = boost::none) { + std::optional debugHook = std::nullopt) { // We load the model before parsing the input file, so that the SourceInfo // in the model comes first. C converter; diff --git a/frontends/p4/externInstance.cpp b/frontends/p4/externInstance.cpp index 3ca0acc61dc..235ca3a71ea 100644 --- a/frontends/p4/externInstance.cpp +++ b/frontends/p4/externInstance.cpp @@ -23,10 +23,10 @@ limitations under the License. namespace P4 { -boost::optional ExternInstance::resolve(const IR::Expression *expr, - ReferenceMap *refMap, TypeMap *typeMap, - const boost::optional &defaultName - /* = boost::none */) { +std::optional ExternInstance::resolve(const IR::Expression *expr, + ReferenceMap *refMap, TypeMap *typeMap, + const std::optional &defaultName + /* = std::nullopt */) { CHECK_NULL(expr); CHECK_NULL(refMap); CHECK_NULL(typeMap); @@ -36,28 +36,28 @@ boost::optional ExternInstance::resolve(const IR::Expression *ex } else if (expr->is()) { return resolve(expr->to(), refMap, typeMap, defaultName); } else { - return boost::none; + return std::nullopt; } } -boost::optional ExternInstance::resolve(const IR::PathExpression *path, - ReferenceMap *refMap, TypeMap *typeMap) { +std::optional ExternInstance::resolve(const IR::PathExpression *path, + ReferenceMap *refMap, TypeMap *typeMap) { CHECK_NULL(path); CHECK_NULL(refMap); CHECK_NULL(typeMap); auto decl = refMap->getDeclaration(path->path, true); - if (!decl->is()) return boost::none; + if (!decl->is()) return std::nullopt; auto instance = decl->to(); auto type = typeMap->getType(instance); if (!type) { BUG("Couldn't determine the type of expression: %1%", path); - return boost::none; + return std::nullopt; } auto instantiation = Instantiation::resolve(instance, refMap, typeMap); - if (!instantiation->is()) return boost::none; + if (!instantiation->is()) return std::nullopt; auto externInstantiation = instantiation->to(); return ExternInstance{instance->controlPlaneName(), path, @@ -66,15 +66,15 @@ boost::optional ExternInstance::resolve(const IR::PathExpression instance->to()}; } -boost::optional ExternInstance::resolve( +std::optional ExternInstance::resolve( const IR::ConstructorCallExpression *constructorCallExpr, ReferenceMap *refMap, - TypeMap *typeMap, const boost::optional &name /* = boost::none */) { + TypeMap *typeMap, const std::optional &name /* = std::nullopt */) { CHECK_NULL(constructorCallExpr); CHECK_NULL(refMap); CHECK_NULL(typeMap); auto constructorCall = P4::ConstructorCall::resolve(constructorCallExpr, refMap, typeMap); - if (!constructorCall->is()) return boost::none; + if (!constructorCall->is()) return std::nullopt; auto type = constructorCall->to()->type; return ExternInstance{name, diff --git a/frontends/p4/externInstance.h b/frontends/p4/externInstance.h index a62ebfc6609..a36596beda4 100644 --- a/frontends/p4/externInstance.h +++ b/frontends/p4/externInstance.h @@ -17,7 +17,7 @@ limitations under the License. #ifndef _FRONTENDS_P4_EXTERNINSTANCE_H_ #define _FRONTENDS_P4_EXTERNINSTANCE_H_ -#include +#include #include "frontends/p4/parameterSubstitution.h" #include "lib/cstring.h" @@ -49,7 +49,7 @@ class TypeMap; * expression which constructs an anonymous instance. */ struct ExternInstance final { - const boost::optional name; // The instance's name, if any. + const std::optional name; // The instance's name, if any. const IR::Expression *expression; // The original expression passed to resolve(). const IR::Type_Extern *type; // The type of the instance. const IR::Vector *typeArguments; // The instance's type arguments; @@ -59,7 +59,7 @@ struct ExternInstance final { /** * @return the extern instance that @expr resolves to, if any, or - * boost::none otherwise. + * std::nullopt otherwise. * * @expr may either refer to a named extern instance (i.e., it may be a * PathExpression), or it may construct an anonymous instance directly @@ -67,27 +67,27 @@ struct ExternInstance final { * instance will not have a name; @defaultName may optionally be used to * specify a default name to return. */ - static boost::optional resolve( + static std::optional resolve( const IR::Expression *expr, ReferenceMap *refMap, TypeMap *typeMap, - const boost::optional &defaultName = boost::none); + const std::optional &defaultName = std::nullopt); /** * @return the extern instance that @path resolves to, if any, or - * boost::none otherwise. + * std::nullopt otherwise. */ - static boost::optional resolve(const IR::PathExpression *path, - ReferenceMap *refMap, TypeMap *typeMap); + static std::optional resolve(const IR::PathExpression *path, + ReferenceMap *refMap, TypeMap *typeMap); /** * @return the extern instance that @constructorCallExpr resolves to, if any, or - * boost::none otherwise. + * std::nullopt otherwise. * * Anonymous instances do not have a name, but the caller may provide one * via @name if it has external information about what the name should be. */ - static boost::optional resolve( + static std::optional resolve( const IR::ConstructorCallExpression *constructorCallExpr, ReferenceMap *refMap, - TypeMap *typeMap, const boost::optional &name = boost::none); + TypeMap *typeMap, const std::optional &name = std::nullopt); }; } // namespace P4 diff --git a/frontends/p4/typeChecking/typeConstraints.h b/frontends/p4/typeChecking/typeConstraints.h index da2f53887ee..0eebdaa0d9c 100644 --- a/frontends/p4/typeChecking/typeConstraints.h +++ b/frontends/p4/typeChecking/typeConstraints.h @@ -17,10 +17,10 @@ limitations under the License. #ifndef _TYPECHECKING_TYPECONSTRAINTS_H_ #define _TYPECHECKING_TYPECONSTRAINTS_H_ +#include #include #include -#include #include "ir/ir.h" #include "lib/castable.h" diff --git a/ir/json_generator.h b/ir/json_generator.h index 6dc68823459..a0df39269eb 100644 --- a/ir/json_generator.h +++ b/ir/json_generator.h @@ -18,11 +18,10 @@ limitations under the License. #define _IR_JSON_GENERATOR_H_ #include +#include #include #include -#include - #include "ir/node.h" #include "lib/bitvec.h" #include "lib/cstring.h" @@ -107,7 +106,7 @@ class JSONGenerator { } template - void generate(const boost::optional &v) { + void generate(const std::optional &v) { if (!v) { out << "{ \"valid\" : false }"; return; diff --git a/ir/json_loader.h b/ir/json_loader.h index a3a15661470..766f64ca019 100644 --- a/ir/json_loader.h +++ b/ir/json_loader.h @@ -20,12 +20,11 @@ limitations under the License. #include #include +#include #include #include #include -#include - #include "ir.h" #include "json_parser.h" #include "lib/bitvec.h" @@ -202,12 +201,12 @@ class JSONLoader { } template - void unpack_json(boost::optional &v) { + void unpack_json(std::optional &v) { const JsonObject *obj = json->to(); bool isValid = false; load(::get(obj, "valid"), isValid); if (!isValid) { - v = boost::none; + v = std::nullopt; return; } T value; diff --git a/test/gtest/complex_bitwise.cpp b/test/gtest/complex_bitwise.cpp index a95e6960ba8..4a55309bef1 100644 --- a/test/gtest/complex_bitwise.cpp +++ b/test/gtest/complex_bitwise.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include "gtest/gtest.h" #include "ir/ir.h" @@ -21,7 +21,7 @@ namespace Test { namespace { -boost::optional +std::optional createSimplifyBitwiseTestCase(const std::string &ingressSource) { std::string source = P4_SOURCE(P4Headers::V1MODEL, R"( header H diff --git a/test/gtest/diagnostics.cpp b/test/gtest/diagnostics.cpp index 7e5791dfbe0..505a2005968 100644 --- a/test/gtest/diagnostics.cpp +++ b/test/gtest/diagnostics.cpp @@ -17,7 +17,7 @@ limitations under the License. #include #include -#include +#include #include "gtest/gtest.h" @@ -29,7 +29,7 @@ namespace Test { namespace { -boost::optional +std::optional createP4_16DiagnosticsTestCase(const std::string& pragmaSource) { auto source = P4_SOURCE(P4Headers::V1MODEL, R"( %PRAGMA_SOURCE% @@ -50,7 +50,7 @@ createP4_16DiagnosticsTestCase(const std::string& pragmaSource) { return FrontendTestCase::create(source); } -boost::optional +std::optional createP4_14DiagnosticsTestCase(const std::string& pragmaSource) { auto source = P4_SOURCE(R"( %PRAGMA_SOURCE% @@ -165,7 +165,7 @@ TEST_F(Diagnostics, CompilerOptions) { using CommandLineOptions = P4::IOptionPragmaParser::CommandLineOptions; auto parseWithCompilerOptions = [](const CommandLineOptions& args) - -> boost::optional { + -> std::optional { auto& options = GTestContext::get().options(); options.process(args.size(), const_cast(args.data())); return createP4_16DiagnosticsTestCase(P4_SOURCE(R"()")); diff --git a/test/gtest/helpers.cpp b/test/gtest/helpers.cpp index 2719cecd08b..24a753ca50d 100644 --- a/test/gtest/helpers.cpp +++ b/test/gtest/helpers.cpp @@ -146,7 +146,7 @@ P4CTestEnvironment::P4CTestEnvironment() { namespace Test { -/* static */ boost::optional +/* static */ std::optional FrontendTestCase::create(const std::string& source, CompilerOptions::FrontendVersion langVersion /* = CompilerOptions::FrontendVersion::P4_16 */, @@ -155,12 +155,12 @@ FrontendTestCase::create(const std::string& source, auto* program = P4::parseP4String(source, langVersion); if (program == nullptr) { std::cerr << "Couldn't parse test case source" << std::endl; - return boost::none; + return std::nullopt; } if (::diagnosticCount() > 0) { std::cerr << "Encountered " << ::diagnosticCount() << " errors while parsing test case" << std::endl; - return boost::none; + return std::nullopt; } P4::P4COptionPragmaParser optionsPragmaParser; @@ -168,7 +168,7 @@ FrontendTestCase::create(const std::string& source, if (::errorCount() > 0) { std::cerr << "Encountered " << ::errorCount() << " errors while collecting options pragmas" << std::endl; - return boost::none; + return std::nullopt; } CompilerOptions options; @@ -176,18 +176,18 @@ FrontendTestCase::create(const std::string& source, program = P4::FrontEnd(parseAnnotations).run(options, program, true); if (program == nullptr) { std::cerr << "Frontend failed" << std::endl; - return boost::none; + return std::nullopt; } if (::errorCount() > 0) { std::cerr << "Encountered " << ::errorCount() << " errors while executing frontend" << std::endl; - return boost::none; + return std::nullopt; } if (::errorCount() > 0) { std::cerr << "Encountered " << ::errorCount() << " errors while parsing back-end annotations" << std::endl; - return boost::none; + return std::nullopt; } return FrontendTestCase{program}; diff --git a/test/gtest/helpers.h b/test/gtest/helpers.h index 963b1f52b99..2b95ac35e44 100644 --- a/test/gtest/helpers.h +++ b/test/gtest/helpers.h @@ -19,7 +19,7 @@ limitations under the License. #include -#include +#include #include "frontends/common/options.h" #include "frontends/p4/parseAnnotations.h" @@ -116,12 +116,12 @@ struct FrontendTestCase { CompilerOptions::FrontendVersion::P4_16; /// Create a test case that only requires the frontend to run. - static boost::optional + static std::optional create(const std::string& source, CompilerOptions::FrontendVersion langVersion = defaultVersion, P4::ParseAnnotations parseAnnotations = P4::ParseAnnotations()); - static boost::optional + static std::optional create(const std::string& source, P4::ParseAnnotations parseAnnotations) { return create(source, defaultVersion, parseAnnotations); } diff --git a/test/gtest/p4runtime.cpp b/test/gtest/p4runtime.cpp index 28c72ce6dbd..e0b5caac837 100644 --- a/test/gtest/p4runtime.cpp +++ b/test/gtest/p4runtime.cpp @@ -23,7 +23,7 @@ limitations under the License. #include #include -#include +#include #include "control-plane/p4/config/v1/p4info.pb.h" #include "control-plane/p4/config/v1/p4types.pb.h" @@ -63,18 +63,18 @@ class ParseAnnotations : public P4::ParseAnnotations { }) { } }; -boost::optional +std::optional createP4RuntimeTestCase( const std::string& source, CompilerOptions::FrontendVersion langVersion = FrontendTestCase::defaultVersion, const cstring arch = defaultArch, P4::ParseAnnotations parseAnnotations = P4::ParseAnnotations()) { auto frontendTestCase = FrontendTestCase::create(source, langVersion, parseAnnotations); - if (!frontendTestCase) return boost::none; + if (!frontendTestCase) return std::nullopt; return P4::generateP4Runtime(frontendTestCase->program, arch); } -boost::optional +std::optional createP4RuntimeTestCase( const std::string& source, P4::ParseAnnotations parseAnnotations) { @@ -1099,18 +1099,18 @@ TEST_F(P4Runtime, StaticTableEntries) { int priority = 1000; auto check_entry = [&](const p4v1::Update& update, const std::string& exact_v, - const boost::optional& ternary_v, - const boost::optional& ternary_mask, + const std::optional& ternary_v, + const std::optional& ternary_mask, const std::string& param_v) { EXPECT_EQ(p4v1::Update::INSERT, update.type()); const auto& protoEntry = update.entity().table_entry(); EXPECT_EQ(table->preamble().id(), protoEntry.table_id()); - ASSERT_EQ((ternary_v == boost::none) ? 1 : 2, protoEntry.match().size()); + ASSERT_EQ((ternary_v == std::nullopt) ? 1 : 2, protoEntry.match().size()); const auto& mfA = protoEntry.match().Get(0); EXPECT_EQ(hfAId, mfA.field_id()); EXPECT_EQ(exact_v, mfA.exact().value()); - if (ternary_v != boost::none) { + if (ternary_v != std::nullopt) { const auto& mfB = protoEntry.match().Get(1); EXPECT_EQ(hfBId, mfB.field_id()); EXPECT_EQ(*ternary_v, mfB.ternary().value()); @@ -1136,7 +1136,7 @@ TEST_F(P4Runtime, StaticTableEntries) { std::string("\x00\x02", 2)); check_entry(updates.Get(2), "\x03", std::string("\x10\x00", 2), std::string("\xf0\x00", 2), std::string("\x00\x03", 2)); - check_entry(updates.Get(3), "\x04", boost::none, boost::none, // don't care match + check_entry(updates.Get(3), "\x04", std::nullopt, std::nullopt, // don't care match std::string("\x00\x04", 2)); } @@ -1329,8 +1329,8 @@ TEST_F(P4Runtime, ValueSet) { unsigned int id, cstring name, const std::vector annotations, int bitwidth, - boost::optional matchType, - boost::optional otherMatchType) { + std::optional matchType, + std::optional otherMatchType) { EXPECT_EQ(mf.id(), id); EXPECT_EQ(mf.name(), name); ASSERT_EQ(static_cast(mf.annotations_size()), annotations.size()); @@ -1341,9 +1341,9 @@ TEST_F(P4Runtime, ValueSet) { if (otherMatchType) { EXPECT_EQ(mf.other_match_type(), *otherMatchType); } }; checkMatchField(vset->match(0), 1, "f1", {"@my_anno(\"body\")"}, 8, - MatchField::TERNARY, boost::none); - checkMatchField(vset->match(1), 2, "f2", {}, 8, MatchField::EXACT, boost::none); - checkMatchField(vset->match(2), 3, "f3", {}, 8, boost::none, cstring("custom")); + MatchField::TERNARY, std::nullopt); + checkMatchField(vset->match(1), 2, "f2", {}, 8, MatchField::EXACT, std::nullopt); + checkMatchField(vset->match(2), 3, "f3", {}, 8, std::nullopt, cstring("custom")); } TEST_F(P4Runtime, Register) { @@ -1470,11 +1470,11 @@ TEST_F(P4Runtime, Documentation) { class P4RuntimePkgInfo : public P4CTest { protected: - static boost::optional createTestCase(const char* annotations); + static std::optional createTestCase(const char* annotations); }; /* static */ -boost::optional P4RuntimePkgInfo::createTestCase(const char* annotations) { +std::optional P4RuntimePkgInfo::createTestCase(const char* annotations) { auto source = P4_SOURCE(P4Headers::V1MODEL, R"( struct Headers { } struct Metadata { } From 95d01a0a8b04947ad4c4739c2bdafe9ed0f8830f Mon Sep 17 00:00:00 2001 From: fruffy Date: Mon, 27 Mar 2023 10:07:27 -0400 Subject: [PATCH 2/2] Specify a standard for Bazel? --- .bazelrc | 1 + bazel/example/.bazelrc | 1 + 2 files changed, 2 insertions(+) create mode 100644 .bazelrc create mode 100644 bazel/example/.bazelrc diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000000..6532c3cafd9 --- /dev/null +++ b/.bazelrc @@ -0,0 +1 @@ +build --action_env=BAZEL_CXXOPTS="-std=c++17" diff --git a/bazel/example/.bazelrc b/bazel/example/.bazelrc new file mode 100644 index 00000000000..6532c3cafd9 --- /dev/null +++ b/bazel/example/.bazelrc @@ -0,0 +1 @@ +build --action_env=BAZEL_CXXOPTS="-std=c++17"