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.
8 use decl_provider::DeclProvider;
9 use hhbc_by_ref_ast_class_expr::ClassExpr;
10 use hhbc_by_ref_env::emitter::Emitter;
11 use hhbc_by_ref_hhas_body::HhasBodyEnv;
12 use oxidized::{ast, ast_defs, pos::Pos};
14 pub trait SpecialClassResolver {
15 fn resolve<'a>(&self, env: Option<&'a HhasBodyEnv>, id: &'a str) -> Cow<'a, str>;
18 impl<'arena, 'decl, D: DeclProvider<'decl>> SpecialClassResolver for Emitter<'arena, 'decl, D> {
19 fn resolve<'a>(&self, env: Option<&'a HhasBodyEnv>, id: &'a str) -> Cow<'a, str> {
20 let class_expr = match env {
21 None => ClassExpr::expr_to_class_expr_(
30 ast::Expr_::mk_id(ast_defs::Id(Pos::make_none(), id.into())),
33 Some(body_env) => ClassExpr::expr_to_class_expr_(
40 .map(|(k, s)| (k.clone(), s.as_str())),
41 body_env.parent_name.clone(),
45 ast::Expr_::mk_id(ast_defs::Id(Pos::make_none(), id.into())),
50 ClassExpr::Id(ast_defs::Id(_, name)) => Cow::Owned(name),
51 _ => Cow::Borrowed(id),