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.
6 use crate::decl_defs::ty::{
7 ClassConstKind, ClassConstRef, DeclTy, EnumType, FunElt, Tparam, Typeconst, TypedefType,
8 UserAttribute, WhereConstraint, XhpAttribute, XhpEnumValue,
10 use crate::reason::Reason;
12 ClassConstName, MethodName, ModuleName, Positioned, PropName, Symbol, TypeConstName, TypeName,
14 use std::collections::BTreeMap;
16 pub use crate::decl_defs::ty::ConstDecl;
17 pub use oxidized::ast_defs::Visibility;
18 pub use oxidized_by_ref::{method_flags::MethodFlags, prop_flags::PropFlags};
20 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
21 pub struct ShallowClassConst<R: Reason> {
22 pub is_abstract: ClassConstKind,
23 pub name: Positioned<ClassConstName, R::Pos>,
25 /// This field is used for two different meanings in two different places:
27 /// enum class A:arraykey { int X = "a"; }
29 /// In an enum class, X.ty = \HH\MemberOf<A,int>.
31 /// enum B:int as arraykey { X = "a"; Y = 1; Z = B::X; }
33 /// In a legacy enum, X.ty = string, Y.ty = int, and Z.ty = TAny, and ty is
34 /// just a simple syntactic attempt to retrieve the type from the initializer.
37 /// This is a list of all scope-resolution operators "A::B" that are mentioned
38 /// in the const initializer, for members of regular-enums and enum-class-enums
39 /// to detect circularity of initializers. We don't yet have a similar mechanism
40 /// for top-level const initializers.
41 pub refs: Vec<ClassConstRef>,
44 walkable!(ShallowClassConst<R> => [ty]);
46 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
47 pub struct ShallowTypeconst<R: Reason> {
48 pub name: Positioned<TypeConstName, R::Pos>,
49 pub kind: Typeconst<R>,
50 pub enforceable: (R::Pos, bool),
51 pub reifiable: Option<R::Pos>,
55 walkable!(ShallowTypeconst<R> => [kind]);
57 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
58 pub struct ShallowProp<R: Reason> {
59 pub name: Positioned<PropName, R::Pos>,
60 pub xhp_attr: Option<XhpAttribute>,
61 pub ty: Option<DeclTy<R>>,
62 pub visibility: Visibility,
66 walkable!(ShallowProp<R> => [ty]);
68 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
69 pub struct ShallowMethod<R: Reason> {
70 // note(sf, 2022-01-27):
72 // - `Shallow_decl_defs.shallow_method`
73 // - `oxidized_by_ref::shallow_decl_defs::ShallowMethod<'_>`
74 pub name: Positioned<MethodName, R::Pos>,
76 pub visibility: Visibility,
77 pub deprecated: Option<intern::string::BytesId>, // e.g. "The method foo is deprecated: ..."
78 pub flags: MethodFlags,
79 pub attributes: Vec<UserAttribute<R::Pos>>,
82 walkable!(ShallowMethod<R> => [ty]);
84 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
85 pub struct ShallowClass<R: Reason> {
86 // note(sf, 2022-01-27):
88 // - `Shallow_decl_defs.shallow_class`
89 // - `oxidized_by_ref::shallow_decl_defs::ShallowClass<'_>`
90 pub mode: oxidized::file_info::Mode,
92 pub is_abstract: bool,
94 pub has_xhp_keyword: bool,
95 pub kind: oxidized::ast_defs::ClassishKind,
96 pub module: Option<Positioned<ModuleName, R::Pos>>,
97 pub name: Positioned<TypeName, R::Pos>,
98 pub tparams: Vec<Tparam<R, DeclTy<R>>>,
99 pub where_constraints: Vec<WhereConstraint<DeclTy<R>>>,
100 pub extends: Vec<DeclTy<R>>,
101 pub uses: Vec<DeclTy<R>>,
102 pub xhp_attr_uses: Vec<DeclTy<R>>,
103 pub xhp_enum_values: BTreeMap<Symbol, Vec<XhpEnumValue>>,
104 pub req_extends: Vec<DeclTy<R>>,
105 pub req_implements: Vec<DeclTy<R>>,
106 pub implements: Vec<DeclTy<R>>,
107 pub support_dynamic_type: bool,
108 pub consts: Vec<ShallowClassConst<R>>,
109 pub typeconsts: Vec<ShallowTypeconst<R>>,
110 pub props: Vec<ShallowProp<R>>,
111 pub static_props: Vec<ShallowProp<R>>,
112 pub constructor: Option<ShallowMethod<R>>,
113 pub static_methods: Vec<ShallowMethod<R>>,
114 pub methods: Vec<ShallowMethod<R>>,
115 pub user_attributes: Vec<UserAttribute<R::Pos>>,
116 pub enum_type: Option<EnumType<R>>,
119 walkable!(ShallowClass<R> => [
120 tparams, where_constraints, extends, uses, xhp_attr_uses, req_extends,
121 req_implements, implements, consts, typeconsts, props, static_props,
122 constructor, static_methods, methods, enum_type
125 pub type FunDecl<R> = FunElt<R>;
127 pub type ClassDecl<R> = ShallowClass<R>;
129 pub type TypedefDecl<R> = TypedefType<R>;
131 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
132 pub enum Decl<R: Reason> {
133 Class(TypeName, ClassDecl<R>),
134 Fun(Symbol, FunDecl<R>),
135 Typedef(TypeName, TypedefDecl<R>),
136 Const(Symbol, ConstDecl<R>),
139 walkable!(Decl<R> => {
140 Decl::Class(_, x) => [x],
141 Decl::Fun(_, x) => [x],
142 Decl::Typedef(_, x) => [x],
143 Decl::Const(_, x) => [x],