Skip to content

Commit

Permalink
[NEW] Adding from_designator + notes for usage (#224)
Browse files Browse the repository at this point in the history
* Adding from_designator + notes for usage

* Adding from_designator + notes for usage
  • Loading branch information
abhamra authored Jun 11, 2024
1 parent 614ee04 commit badf590
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/oq3_semantics/src/syntax_to_semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ fn from_stmt(stmt: synast::Stmt, context: &mut Context) -> Option<asg::Stmt> {
return Some(asg::DeclareHardwareQubit::new(ast_hardware_qubit(&hw_qubit)).to_stmt());
};
let qubit_type = q_decl.qubit_type().unwrap();
let width = match qubit_type.designator().and_then(|x| x.expr()) {
let width = match from_designator(qubit_type.designator()) {
Some(synast::Expr::Literal(ref literal)) => {
match literal.kind() {
synast::LiteralKind::IntNumber(int_num) => {
Expand Down Expand Up @@ -969,7 +969,7 @@ fn from_scalar_type(
// not complex
scalar_type.designator()
};
let width = match designator.and_then(|desg| desg.expr()) {
let width = match from_designator(designator) {
// We only support literal integer designators at the moment.
Some(synast::Expr::Literal(ref literal)) => {
match literal.kind() {
Expand Down Expand Up @@ -1243,6 +1243,13 @@ fn bind_typed_parameter_list(
})
}

fn from_designator(arg: Option<synast::Designator>) -> Option<synast::Expr> {
arg.and_then(|desg| desg.expr())
// NOTE: Other uses of this pattern above have certain error checking,
// but because it was not standardized, it is not included
// in this helper function
}

// This works, but using it is pretty clumsy.
// fn with_scope<F>(context: &mut Context, scope: ScopeType, func: F) where
// F: FnOnce(&mut Context)
Expand Down

0 comments on commit badf590

Please sign in to comment.