Remove positive is_typechecker guards
[hiphop-php.git] / hphp / hack / src / hhbc / emitter / generator.rs
blob4b696fac1208d060ef88b349688adf5ef45a87a1
1 // Copyright (c) Facebook, Inc. and its affiliates.
2 //
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the "hack" directory of this source tree.
5 use ast_body::AstBody;
6 use oxidized::{
7     aast_visitor::{visit, AstParams, Node, Visitor},
8     ast,
9 };
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> {
19             self
20         }
22         fn visit_stmt_(&mut self, c: &mut (), stmt_: &ast::Stmt_) -> Result<(), ()> {
23             match stmt_ {
24                 ast::Stmt_::YieldBreak => Ok((self.0).0 = true),
25                 _ => stmt_.recurse(c, self),
26             }
27         }
29         fn visit_expr_(&mut self, c: &mut (), expr_: &ast::Expr_) -> Result<(), ()> {
30             match expr_ {
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),
34                 }),
35                 _ => expr_.recurse(c, self),
36             }
37         }
39         fn visit_class_(&mut self, _: &mut (), _: &ast::Class_) -> Result<(), ()> {
40             Ok(())
41         }
42         fn visit_fun_(&mut self, _: &mut (), _: &ast::Fun_) -> Result<(), ()> {
43             Ok(())
44         }
45     }
46     let mut state = S((false, false));
47     visit(&mut state, &mut (), body).unwrap();
48     state.0