1 // Copyright (c) Facebook, Inc. and its affiliates.
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the "hack" directory of this source tree.
7 aast_visitor::{visit, AstParams, Node, Visitor},
11 #[allow(clippy::needless_lifetimes)]
12 pub fn is_function_generator<'a>(body: &AstBody<'a>) -> (bool, bool) {
13 struct S((bool, bool));
15 impl<'ast> Visitor<'ast> for S {
16 type P = AstParams<(), ()>;
18 fn object(&mut self) -> &mut dyn Visitor<'ast, P = Self::P> {
22 fn visit_stmt_(&mut self, c: &mut (), stmt_: &ast::Stmt_) -> Result<(), ()> {
24 ast::Stmt_::YieldBreak => Ok((self.0).0 = true),
25 _ => stmt_.recurse(c, self),
29 fn visit_expr_(&mut self, c: &mut (), expr_: &ast::Expr_) -> Result<(), ()> {
31 ast::Expr_::Yield(afield) => Ok(match afield.as_ref() {
32 ast::Afield::AFvalue(_) => (self.0).0 = true,
33 ast::Afield::AFkvalue(_, _) => self.0 = (true, true),
35 _ => expr_.recurse(c, self),
39 fn visit_class_(&mut self, _: &mut (), _: &ast::Class_) -> Result<(), ()> {
42 fn visit_fun_(&mut self, _: &mut (), _: &ast::Fun_) -> Result<(), ()> {
46 let mut state = S((false, false));
47 visit(&mut state, &mut (), body).unwrap();