diff --git a/crates/oq3_semantics/src/asg.rs b/crates/oq3_semantics/src/asg.rs index 448e419..f3cbc02 100644 --- a/crates/oq3_semantics/src/asg.rs +++ b/crates/oq3_semantics/src/asg.rs @@ -47,7 +47,7 @@ impl Program { } } - pub fn stmts(&self) -> &Vec { + pub fn stmts(&self) -> &[Stmt] { &self.stmts } @@ -67,8 +67,8 @@ impl Program { self.version = Some(version); } - pub fn version(&self) -> &Option { - &self.version + pub fn version(&self) -> Option<&OpenQASMVersion> { + self.version.as_ref() } // FIXME: must exist idiomatic rust for managing these modes @@ -158,11 +158,11 @@ impl TExpr { } pub fn get_type(&self) -> &Type { - &(self.ty) + &self.ty } pub fn expression(&self) -> &Expr { - &(self.expression) + &self.expression } } @@ -270,7 +270,7 @@ impl AnnotatedStmt { &self.stmt } - pub fn annotations(&self) -> &Vec { + pub fn annotations(&self) -> &[Annotation] { &self.annotations } } @@ -346,6 +346,10 @@ impl HardwareQubit { } } + pub fn identifier(&self) -> &str { + &self.identifier + } + pub fn to_texpr(self) -> TExpr { TExpr::new(Expr::HardwareQubit(self), Type::HardwareQubit) } @@ -458,8 +462,8 @@ impl DeclareClassical { &self.name } - pub fn initializer(&self) -> &Option> { - &self.initializer + pub fn initializer(&self) -> Option<&TExpr> { + self.initializer.as_deref() } pub fn to_stmt(self) -> Stmt { @@ -536,11 +540,11 @@ impl GateDeclaration { &self.name } - pub fn params(&self) -> &Option> { - &self.params + pub fn params(&self) -> Option<&[SymbolIdResult]> { + self.params.as_deref() } - pub fn qubits(&self) -> &Vec { + pub fn qubits(&self) -> &[SymbolIdResult] { &self.qubits } @@ -586,8 +590,8 @@ impl Barrier { Barrier { qubits } } - pub fn qubits(&self) -> &Option> { - &self.qubits + pub fn qubits(&self) -> Option<&[TExpr]> { + self.qubits.as_deref() } } @@ -648,12 +652,12 @@ impl GateCall { &self.name } - pub fn qubits(&self) -> &Vec { + pub fn qubits(&self) -> &[TExpr] { &self.qubits } - pub fn params(&self) -> &Option> { - &self.params + pub fn params(&self) -> Option<&[TExpr]> { + self.params.as_deref() } pub fn modifiers(&self) -> &[GateModifier] { @@ -1110,8 +1114,8 @@ impl If { &self.then_branch } - pub fn else_branch(&self) -> &Option { - &self.else_branch + pub fn else_branch(&self) -> Option<&Block> { + self.else_branch.as_ref() } pub fn to_stmt(self) -> Stmt { diff --git a/crates/oq3_semantics/src/validate.rs b/crates/oq3_semantics/src/validate.rs index 2d23cda..b820b41 100644 --- a/crates/oq3_semantics/src/validate.rs +++ b/crates/oq3_semantics/src/validate.rs @@ -39,7 +39,7 @@ impl WalkSymbols for Program { } } -impl WalkSymbols for &Vec +impl WalkSymbols for &[V] where V: WalkSymbols, { @@ -59,7 +59,7 @@ where } } -impl WalkSymbols for Box +impl WalkSymbols for &Box where V: WalkSymbols, { @@ -68,7 +68,7 @@ where } } -impl WalkSymbols for TExpr { +impl WalkSymbols for &TExpr { fn walk_symbols(&self, context: &mut SymContext) { self.expression().walk_symbols(context); }