Skip to content

Commit

Permalink
Addressed some of the comments from Pablo's code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
rturrado committed Jan 30, 2024
1 parent c8f1f75 commit e0d2d2d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
10 changes: 5 additions & 5 deletions include/v1x/cqasm-functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ template <typename ReturnType, typename ParamType, auto F>
struct uf_cp : public f_cp<ReturnType, ParamType, F> {
values::Value operator()(const values::Values &vs) const {
values::check_const(vs);
auto arg = dynamic_cast<ParamType&>(*vs[0]).value;
auto arg = vs[0].as<ParamType>()->value;
return tree::make<ReturnType>(F(arg));
}
};
Expand All @@ -67,8 +67,8 @@ template <typename ReturnType, typename ParamType, auto F>
struct bf_cp : public f_cp<ReturnType, ParamType, F> {
values::Value operator()(const values::Values &vs) const {
values::check_const(vs);
auto a = dynamic_cast<ParamType&>(*vs[0]).value;
auto b = dynamic_cast<ParamType&>(*vs[1]).value;
auto a = vs[0].as<ParamType>()->value;
auto b = vs[1].as<ParamType>()->value;
return tree::make<ReturnType>(F(a, b));
}
};
Expand All @@ -81,8 +81,8 @@ struct tf_cp : public f_cp<ParamType, ParamType, F> {
values::Value operator()(const values::Values &vs) const {
values::check_const(vs);
auto condition = vs[0]->as_const_bool()->value;
auto if_true = dynamic_cast<ParamType&>(*vs[1]).value;
auto if_false = dynamic_cast<ParamType&>(*vs[2]).value;
auto if_true = vs[1].as<ParamType>()->value;
auto if_false = vs[2].as<ParamType>()->value;
return tree::make<ParamType>(F(condition, if_true, if_false));
}
};
Expand Down
10 changes: 5 additions & 5 deletions include/v3x/cqasm-functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ template <typename ReturnType, typename ParamType, auto F>
struct uf_cp : public f_cp<ReturnType, ParamType, F> {
values::Value operator()(const values::Values &vs) const {
values::check_const(vs);
auto arg = dynamic_cast<ParamType&>(*vs[0]).value;
auto arg = vs[0].as<ParamType>()->value;
return tree::make<ReturnType>(F(arg));
}
};
Expand All @@ -53,8 +53,8 @@ template <typename ReturnType, typename ParamType, auto F>
struct bf_cp : public f_cp<ReturnType, ParamType, F> {
values::Value operator()(const values::Values &vs) const {
values::check_const(vs);
auto a = dynamic_cast<ParamType&>(*vs[0]).value;
auto b = dynamic_cast<ParamType&>(*vs[1]).value;
auto a = vs[0].as<ParamType>()->value;
auto b = vs[1].as<ParamType>()->value;
return tree::make<ReturnType>(F(a, b));
}
};
Expand All @@ -67,8 +67,8 @@ struct tf_cp : public f_cp<ParamType, ParamType, F> {
values::Value operator()(const values::Values &vs) const {
values::check_const(vs);
auto condition = vs[0]->as_const_bool()->value;
auto if_true = dynamic_cast<ParamType&>(*vs[1]).value;
auto if_false = dynamic_cast<ParamType&>(*vs[2]).value;
auto if_true = vs[1].as<ParamType>()->value;
auto if_false = vs[2].as<ParamType>()->value;
return tree::make<ParamType>(F(condition, if_true, if_false));
}
};
Expand Down
2 changes: 1 addition & 1 deletion test/v3x/cpp/AnalyzeTreeGenAstVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST(visit_function_call, analyzer_call_function_returns_a_non_empty_value) {
auto arguments = cqasm::tree::make<ast::ExpressionList>(cqasm::tree::Any<ast::Expression>{});
auto function_call = ast::FunctionCall{ name, arguments };
auto ret = std::any_cast<values::Value>(visitor.visit_function_call(function_call));
EXPECT_EQ(ret->as_const_real()->value, function_return_value->as_const_real()->value);
EXPECT_TRUE(ret.equals(function_return_value));
}

TEST(visit_function_call, analyzer_call_function_returns_an_empty_value) {
Expand Down
8 changes: 1 addition & 7 deletions test/v3x/cpp/matcher_values.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "matcher_values.hpp"
#include "v3x/cqasm-semantic-gen.hpp"

#include <algorithm> // equal
#include <gmock/gmock.h>
#include <ostream>

Expand All @@ -13,12 +12,7 @@ ValuesEqMatcher::ValuesEqMatcher(const Values &expectedValue)
{}

bool ValuesEqMatcher::MatchAndExplain(const Values &args, std::ostream* /* os */) const {
const auto &expected_vec = expectedValue_.get_vec();
const auto &actual_vec = args.get_vec();
return std::equal(expected_vec.begin(), expected_vec.end(), actual_vec.begin(), actual_vec.end(),
[](const auto expected, const auto actual) {
return !expected.empty() && !actual.empty() && expected.equals(actual);
});
return args.equals(expectedValue_);
}

void ValuesEqMatcher::DescribeTo(std::ostream *os) const {
Expand Down

0 comments on commit e0d2d2d

Please sign in to comment.