1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright contributors to the openqasm-parser project
// SPDX-License-Identifier: Apache-2.0

//! Various traits that are implemented by ast nodes.
//!
//! The implementations are usually trivial, and live in generated.rs
//!
//! NOTE!!! This is not support for the rust traits!
//! This cannot be removed for OQ3.

use either::Either;

use crate::ast::{self, support, AstChildren, AstNode};

pub trait HasName: AstNode {
    fn name(&self) -> Option<ast::Name> {
        support::child(self.syntax())
    }
}

pub trait HasLoopBody: AstNode {
    fn loop_body(&self) -> Option<ast::BlockExpr> {
        support::child(self.syntax())
    }
}

pub trait HasArgList: AstNode {
    fn arg_list(&self) -> Option<ast::ArgList> {
        support::child(self.syntax())
    }
}

pub trait HasModuleItem: AstNode {
    fn items(&self) -> AstChildren<ast::Item> {
        println!("fn items in traits.rs");
        support::children(self.syntax())
    }

    fn statements(&self) -> AstChildren<ast::Stmt> {
        support::children(self.syntax())
    }
}

impl<A: HasName, B: HasName> HasName for Either<A, B> {}