Skip to content

Commit 0fb9c82

Browse files
authored
[Parser] Let parameter parser reuse the same concrete constant parameters across files (#206)
1 parent 1bc5f2f commit 0fb9c82

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/quartz/parser/qasm_parser.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ std::string strip(const std::string &input) {
6666
return std::string(st, ed.base());
6767
}
6868

69+
ParamParser::ParamParser(Context *ctx)
70+
: ctx_(ctx), symbolic_pi_(false), first_file_(true) {
71+
// Initiate the constant parameter map from the context.
72+
const auto &param_values =
73+
ctx_->get_param_info()->get_all_input_param_values();
74+
const auto &param_class = ctx_->get_param_info()->parameter_class_;
75+
for (int i = 0; i < (int)param_class.size(); i++) {
76+
if (param_class[i] == ParamClass::concrete_const) {
77+
number_params_[param_values[i]] = i;
78+
}
79+
}
80+
}
81+
6982
int ParamParser::parse_number(bool negative, ParamType p, bool is_arithmetic,
7083
bool is_halved) {
7184
// Handles negative constants.

src/quartz/parser/qasm_parser.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ std::string strip(const std::string &input);
4040
*/
4141
class ParamParser {
4242
public:
43-
ParamParser(Context *ctx)
44-
: ctx_(ctx), symbolic_pi_(false), first_file_(true) {}
43+
ParamParser(Context *ctx);
4544

4645
/**
4746
* Adds an angle array declaration to the registry of symbolic parameters.

0 commit comments

Comments
 (0)