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.
11 use crate::func::SrcLoc;
12 use crate::string_intern::StringInterner;
19 use crate::FunctionName;
20 use crate::HackConstant;
21 use crate::IncludePath;
26 pub struct SymbolRefs<'a> {
27 pub classes: Vec<ClassName<'a>>,
28 pub constants: Vec<ConstName<'a>>,
29 pub functions: Vec<FunctionName<'a>>,
30 pub includes: Vec<IncludePath<'a>>,
33 /// Fields used when a unit had compile-time errors that should be reported
34 /// when the unit is loaded.
42 /// Unit represents a single parsed file.
45 /// The list of classes defined in this Unit. This also includes enums which
46 /// are transformed into classes internally.
49 /// class MyClass { ... }
51 pub classes: Vec<Class<'a>>,
53 /// The list of top-level constants.
56 /// const MAGIC_VALUE: int = 42;
58 pub constants: Vec<HackConstant>,
60 /// Per-file attributes.
63 /// <<file:__EnableUnstableFeatures('readonly')>>
65 pub file_attributes: Vec<Attribute<'a>>,
67 /// The list of top-level functions defined in this Unit. This include both
68 /// user-defined functions and "special" compiler-defined functions (like
69 /// static initializers).
72 /// function my_fn(int $a, int $b) { ... }
74 pub functions: Vec<Function<'a>>,
76 /// If the Unit failed to parse or compile this defines the error that
77 /// should be reported and the rest of the Unit will be empty.
79 // NB: It could be argued that Unit should be an enum with Fatal/Success
80 // being two separate variants.
81 pub fatal: Option<Fatal>,
83 pub modules: Vec<Module<'a>>,
84 pub module_use: Option<Str<'a>>,
86 /// The unit string interning table.
87 pub strings: Arc<StringInterner>,
89 /// The list of all external symbols referenced by this Unit.
91 // NB: We really should be able to generate this from the IR itself instead
92 // of relying on a separate table.
93 pub symbol_refs: SymbolRefs<'a>,
95 /// The list of top-level typedefs or aliases defined in this Unit.
100 pub typedefs: Vec<Typedef<'a>>,