Remove dead is_xhp attribute
[hiphop-php.git] / hphp / hack / src / hackc / hhbc / hhas_class.rs
blob9a8f331e935463e7edc236d551192280503a4732
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.
6 use bitflags::bitflags;
8 use ffi::{Maybe, Pair, Quadruple, Slice, Str, Triple};
9 use hhas_attribute::HhasAttribute;
10 use hhas_coeffects::HhasCtxConstant;
11 use hhas_constant::HhasConstant;
12 use hhas_method::HhasMethod;
13 use hhas_pos::HhasSpan;
14 use hhas_property::HhasProperty;
15 use hhas_type::HhasTypeInfo;
16 use hhas_type_const::HhasTypeConstant;
17 use hhbc_ast::UseAsVisibility;
18 use hhbc_id::class::ClassType;
20 #[derive(Debug)]
21 #[repr(C)]
22 pub enum TraitReqKind {
23     MustExtend,
24     MustImplement,
27 #[derive(Debug)]
28 #[repr(C)]
29 pub struct HhasClass<'arena> {
30     pub attributes: Slice<'arena, HhasAttribute<'arena>>,
31     pub base: Maybe<ClassType<'arena>>,
32     pub implements: Slice<'arena, ClassType<'arena>>,
33     pub enum_includes: Slice<'arena, ClassType<'arena>>,
34     pub name: ClassType<'arena>,
35     pub span: HhasSpan,
36     pub uses: Slice<'arena, Str<'arena>>,
37     // Deprecated - kill please
38     pub use_aliases: Slice<
39         'arena,
40         Quadruple<
41             Maybe<ClassType<'arena>>,
42             ClassType<'arena>,
43             Maybe<ClassType<'arena>>,
44             Slice<'arena, UseAsVisibility>,
45         >,
46     >,
47     // Deprecated - kill please
48     pub use_precedences: Slice<
49         'arena,
50         Triple<ClassType<'arena>, ClassType<'arena>, Slice<'arena, ClassType<'arena>>>,
51     >,
52     pub enum_type: Maybe<HhasTypeInfo<'arena>>,
53     pub methods: Slice<'arena, HhasMethod<'arena>>,
54     pub properties: Slice<'arena, HhasProperty<'arena>>,
55     pub constants: Slice<'arena, HhasConstant<'arena>>,
56     pub type_constants: Slice<'arena, HhasTypeConstant<'arena>>,
57     pub ctx_constants: Slice<'arena, HhasCtxConstant<'arena>>, // TODO(SF, 2021-0811): HhasCtxConstant is part of Steve's HhasCoeffect work
58     pub requirements: Slice<'arena, Pair<ClassType<'arena>, TraitReqKind>>,
59     pub upper_bounds: Slice<'arena, Pair<Str<'arena>, Slice<'arena, HhasTypeInfo<'arena>>>>,
60     pub doc_comment: Maybe<Str<'arena>>,
61     pub flags: HhasClassFlags,
64 bitflags! {
65     #[repr(C)]
66     pub struct HhasClassFlags: u16 {
67         const IS_FINAL = 1 << 1;
68         const IS_SEALED = 1 << 2;
69         const IS_ABSTRACT = 1 << 3;
70         const IS_INTERFACE = 1 << 4;
71         const IS_TRAIT = 1 << 5;
72         const IS_CONST = 1 << 7;
73         const NO_DYNAMIC_PROPS = 1 << 8;
74         const NEEDS_NO_REIFIEDINIT = 1 << 9;
75     }
78 impl<'arena> HhasClass<'arena> {
79     pub fn is_final(&self) -> bool {
80         self.flags.contains(HhasClassFlags::IS_FINAL)
81     }
82     pub fn is_sealed(&self) -> bool {
83         self.flags.contains(HhasClassFlags::IS_SEALED)
84     }
85     pub fn is_abstract(&self) -> bool {
86         self.flags.contains(HhasClassFlags::IS_ABSTRACT)
87     }
88     pub fn is_interface(&self) -> bool {
89         self.flags.contains(HhasClassFlags::IS_INTERFACE)
90     }
91     pub fn is_trait(&self) -> bool {
92         self.flags.contains(HhasClassFlags::IS_TRAIT)
93     }
94     pub fn is_const(&self) -> bool {
95         self.flags.contains(HhasClassFlags::IS_CONST)
96     }
97     pub fn no_dynamic_props(&self) -> bool {
98         self.flags.contains(HhasClassFlags::NO_DYNAMIC_PROPS)
99     }
100     pub fn needs_no_reifiedinit(&self) -> bool {
101         self.flags.contains(HhasClassFlags::NEEDS_NO_REIFIEDINIT)
102     }
103     pub fn is_closure(&self) -> bool {
104         self.methods.as_ref().iter().any(|x| x.is_closure_body())
105     }