Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return &[T] rather than Vec<T> and similar in getters #75

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions crates/oq3_semantics/src/asg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Program {
}
}

pub fn stmts(&self) -> &Vec<Stmt> {
pub fn stmts(&self) -> &[Stmt] {
&self.stmts
}

Expand All @@ -67,8 +67,8 @@ impl Program {
self.version = Some(version);
}

pub fn version(&self) -> &Option<OpenQASMVersion> {
&self.version
pub fn version(&self) -> Option<&OpenQASMVersion> {
self.version.as_ref()
}

// FIXME: must exist idiomatic rust for managing these modes
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -270,7 +270,7 @@ impl AnnotatedStmt {
&self.stmt
}

pub fn annotations(&self) -> &Vec<Annotation> {
pub fn annotations(&self) -> &[Annotation] {
&self.annotations
}
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -458,8 +462,8 @@ impl DeclareClassical {
&self.name
}

pub fn initializer(&self) -> &Option<Box<TExpr>> {
&self.initializer
pub fn initializer(&self) -> Option<&TExpr> {
self.initializer.as_deref()
}

pub fn to_stmt(self) -> Stmt {
Expand Down Expand Up @@ -536,11 +540,11 @@ impl GateDeclaration {
&self.name
}

pub fn params(&self) -> &Option<Vec<SymbolIdResult>> {
&self.params
pub fn params(&self) -> Option<&[SymbolIdResult]> {
self.params.as_deref()
}

pub fn qubits(&self) -> &Vec<SymbolIdResult> {
pub fn qubits(&self) -> &[SymbolIdResult] {
&self.qubits
}

Expand Down Expand Up @@ -586,8 +590,8 @@ impl Barrier {
Barrier { qubits }
}

pub fn qubits(&self) -> &Option<Vec<TExpr>> {
&self.qubits
pub fn qubits(&self) -> Option<&[TExpr]> {
self.qubits.as_deref()
}
}

Expand Down Expand Up @@ -648,12 +652,12 @@ impl GateCall {
&self.name
}

pub fn qubits(&self) -> &Vec<TExpr> {
pub fn qubits(&self) -> &[TExpr] {
&self.qubits
}

pub fn params(&self) -> &Option<Vec<TExpr>> {
&self.params
pub fn params(&self) -> Option<&[TExpr]> {
self.params.as_deref()
}

pub fn modifiers(&self) -> &[GateModifier] {
Expand Down Expand Up @@ -1110,8 +1114,8 @@ impl If {
&self.then_branch
}

pub fn else_branch(&self) -> &Option<Block> {
&self.else_branch
pub fn else_branch(&self) -> Option<&Block> {
self.else_branch.as_ref()
}

pub fn to_stmt(self) -> Stmt {
Expand Down
6 changes: 3 additions & 3 deletions crates/oq3_semantics/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<T: SymTrait> WalkSymbols<T> for Program {
}
}

impl<V, T: SymTrait> WalkSymbols<T> for &Vec<V>
impl<V, T: SymTrait> WalkSymbols<T> for &[V]
where
V: WalkSymbols<T>,
{
Expand All @@ -59,7 +59,7 @@ where
}
}

impl<V, T: SymTrait> WalkSymbols<T> for Box<V>
impl<V, T: SymTrait> WalkSymbols<T> for &Box<V>
where
V: WalkSymbols<T>,
{
Expand All @@ -68,7 +68,7 @@ where
}
}

impl<T: SymTrait> WalkSymbols<T> for TExpr {
impl<T: SymTrait> WalkSymbols<T> for &TExpr {
fn walk_symbols(&self, context: &mut SymContext<T>) {
self.expression().walk_symbols(context);
}
Expand Down
Loading