diff options
author | Jonas Schievink <[email protected]> | 2020-06-24 15:50:23 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-06-24 15:54:21 +0100 |
commit | 2928600374a8356c2c2bffee080c47cb0f463fb9 (patch) | |
tree | a21d348fbfa2d06f1fba77622c5417383938e6fe /crates | |
parent | d6fd7809b016787e8a23f443b1b626840c4ea5c7 (diff) |
Reorder items
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/item_tree.rs | 152 |
1 files changed, 76 insertions, 76 deletions
diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index 31f3c4bd8..d7bc64e6c 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs | |||
@@ -23,6 +23,7 @@ use hir_expand::{ | |||
23 | use ra_arena::{Arena, Idx, RawId}; | 23 | use ra_arena::{Arena, Idx, RawId}; |
24 | use ra_syntax::{ast, match_ast}; | 24 | use ra_syntax::{ast, match_ast}; |
25 | use rustc_hash::FxHashMap; | 25 | use rustc_hash::FxHashMap; |
26 | use smallvec::SmallVec; | ||
26 | use test_utils::mark; | 27 | use test_utils::mark; |
27 | 28 | ||
28 | use crate::{ | 29 | use crate::{ |
@@ -33,26 +34,6 @@ use crate::{ | |||
33 | type_ref::{Mutability, TypeBound, TypeRef}, | 34 | type_ref::{Mutability, TypeBound, TypeRef}, |
34 | visibility::RawVisibility, | 35 | visibility::RawVisibility, |
35 | }; | 36 | }; |
36 | use smallvec::SmallVec; | ||
37 | |||
38 | #[derive(Default, Debug, Eq, PartialEq)] | ||
39 | struct ItemVisibilities { | ||
40 | arena: Arena<RawVisibility>, | ||
41 | } | ||
42 | |||
43 | impl ItemVisibilities { | ||
44 | fn alloc(&mut self, vis: RawVisibility) -> RawVisibilityId { | ||
45 | match &vis { | ||
46 | RawVisibility::Public => RawVisibilityId::PUB, | ||
47 | RawVisibility::Module(path) if path.segments.is_empty() => match &path.kind { | ||
48 | PathKind::Super(0) => RawVisibilityId::PRIV, | ||
49 | PathKind::Crate => RawVisibilityId::PUB_CRATE, | ||
50 | _ => RawVisibilityId(self.arena.alloc(vis).into_raw().into()), | ||
51 | }, | ||
52 | _ => RawVisibilityId(self.arena.alloc(vis).into_raw().into()), | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | 37 | ||
57 | #[derive(Copy, Clone, Eq, PartialEq)] | 38 | #[derive(Copy, Clone, Eq, PartialEq)] |
58 | pub struct RawVisibilityId(u32); | 39 | pub struct RawVisibilityId(u32); |
@@ -76,21 +57,6 @@ impl fmt::Debug for RawVisibilityId { | |||
76 | } | 57 | } |
77 | } | 58 | } |
78 | 59 | ||
79 | #[derive(Default, Debug, Eq, PartialEq)] | ||
80 | struct GenericParamsStorage { | ||
81 | arena: Arena<GenericParams>, | ||
82 | } | ||
83 | |||
84 | impl GenericParamsStorage { | ||
85 | fn alloc(&mut self, params: GenericParams) -> GenericParamsId { | ||
86 | if params.types.is_empty() && params.where_predicates.is_empty() { | ||
87 | return GenericParamsId::EMPTY; | ||
88 | } | ||
89 | |||
90 | GenericParamsId(self.arena.alloc(params).into_raw().into()) | ||
91 | } | ||
92 | } | ||
93 | |||
94 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | 60 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
95 | pub struct GenericParamsId(u32); | 61 | pub struct GenericParamsId(u32); |
96 | 62 | ||
@@ -98,47 +64,6 @@ impl GenericParamsId { | |||
98 | pub const EMPTY: Self = GenericParamsId(u32::max_value()); | 64 | pub const EMPTY: Self = GenericParamsId(u32::max_value()); |
99 | } | 65 | } |
100 | 66 | ||
101 | static VIS_PUB: RawVisibility = RawVisibility::Public; | ||
102 | static VIS_PRIV: RawVisibility = | ||
103 | RawVisibility::Module(ModPath { kind: PathKind::Super(0), segments: Vec::new() }); | ||
104 | static VIS_PUB_CRATE: RawVisibility = | ||
105 | RawVisibility::Module(ModPath { kind: PathKind::Crate, segments: Vec::new() }); | ||
106 | |||
107 | static EMPTY_GENERICS: GenericParams = | ||
108 | GenericParams { types: Arena::new(), where_predicates: Vec::new() }; | ||
109 | |||
110 | #[derive(Default, Debug, Eq, PartialEq)] | ||
111 | struct ItemTreeData { | ||
112 | imports: Arena<Import>, | ||
113 | extern_crates: Arena<ExternCrate>, | ||
114 | functions: Arena<Function>, | ||
115 | structs: Arena<Struct>, | ||
116 | fields: Arena<Field>, | ||
117 | unions: Arena<Union>, | ||
118 | enums: Arena<Enum>, | ||
119 | variants: Arena<Variant>, | ||
120 | consts: Arena<Const>, | ||
121 | statics: Arena<Static>, | ||
122 | traits: Arena<Trait>, | ||
123 | impls: Arena<Impl>, | ||
124 | type_aliases: Arena<TypeAlias>, | ||
125 | mods: Arena<Mod>, | ||
126 | macro_calls: Arena<MacroCall>, | ||
127 | exprs: Arena<Expr>, | ||
128 | |||
129 | vis: ItemVisibilities, | ||
130 | generics: GenericParamsStorage, | ||
131 | } | ||
132 | |||
133 | #[derive(Debug, Eq, PartialEq, Hash)] | ||
134 | enum AttrOwner { | ||
135 | /// Attributes on an item. | ||
136 | ModItem(ModItem), | ||
137 | /// Inner attributes of the source file. | ||
138 | TopLevel, | ||
139 | // FIXME: Store variant and field attrs, and stop reparsing them in `attrs_query`. | ||
140 | } | ||
141 | |||
142 | /// The item tree of a source file. | 67 | /// The item tree of a source file. |
143 | #[derive(Debug, Eq, PartialEq)] | 68 | #[derive(Debug, Eq, PartialEq)] |
144 | pub struct ItemTree { | 69 | pub struct ItemTree { |
@@ -290,6 +215,81 @@ impl ItemTree { | |||
290 | } | 215 | } |
291 | } | 216 | } |
292 | 217 | ||
218 | #[derive(Default, Debug, Eq, PartialEq)] | ||
219 | struct ItemVisibilities { | ||
220 | arena: Arena<RawVisibility>, | ||
221 | } | ||
222 | |||
223 | impl ItemVisibilities { | ||
224 | fn alloc(&mut self, vis: RawVisibility) -> RawVisibilityId { | ||
225 | match &vis { | ||
226 | RawVisibility::Public => RawVisibilityId::PUB, | ||
227 | RawVisibility::Module(path) if path.segments.is_empty() => match &path.kind { | ||
228 | PathKind::Super(0) => RawVisibilityId::PRIV, | ||
229 | PathKind::Crate => RawVisibilityId::PUB_CRATE, | ||
230 | _ => RawVisibilityId(self.arena.alloc(vis).into_raw().into()), | ||
231 | }, | ||
232 | _ => RawVisibilityId(self.arena.alloc(vis).into_raw().into()), | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | |||
237 | static VIS_PUB: RawVisibility = RawVisibility::Public; | ||
238 | static VIS_PRIV: RawVisibility = | ||
239 | RawVisibility::Module(ModPath { kind: PathKind::Super(0), segments: Vec::new() }); | ||
240 | static VIS_PUB_CRATE: RawVisibility = | ||
241 | RawVisibility::Module(ModPath { kind: PathKind::Crate, segments: Vec::new() }); | ||
242 | |||
243 | #[derive(Default, Debug, Eq, PartialEq)] | ||
244 | struct GenericParamsStorage { | ||
245 | arena: Arena<GenericParams>, | ||
246 | } | ||
247 | |||
248 | impl GenericParamsStorage { | ||
249 | fn alloc(&mut self, params: GenericParams) -> GenericParamsId { | ||
250 | if params.types.is_empty() && params.where_predicates.is_empty() { | ||
251 | return GenericParamsId::EMPTY; | ||
252 | } | ||
253 | |||
254 | GenericParamsId(self.arena.alloc(params).into_raw().into()) | ||
255 | } | ||
256 | } | ||
257 | |||
258 | static EMPTY_GENERICS: GenericParams = | ||
259 | GenericParams { types: Arena::new(), where_predicates: Vec::new() }; | ||
260 | |||
261 | #[derive(Default, Debug, Eq, PartialEq)] | ||
262 | struct ItemTreeData { | ||
263 | imports: Arena<Import>, | ||
264 | extern_crates: Arena<ExternCrate>, | ||
265 | functions: Arena<Function>, | ||
266 | structs: Arena<Struct>, | ||
267 | fields: Arena<Field>, | ||
268 | unions: Arena<Union>, | ||
269 | enums: Arena<Enum>, | ||
270 | variants: Arena<Variant>, | ||
271 | consts: Arena<Const>, | ||
272 | statics: Arena<Static>, | ||
273 | traits: Arena<Trait>, | ||
274 | impls: Arena<Impl>, | ||
275 | type_aliases: Arena<TypeAlias>, | ||
276 | mods: Arena<Mod>, | ||
277 | macro_calls: Arena<MacroCall>, | ||
278 | exprs: Arena<Expr>, | ||
279 | |||
280 | vis: ItemVisibilities, | ||
281 | generics: GenericParamsStorage, | ||
282 | } | ||
283 | |||
284 | #[derive(Debug, Eq, PartialEq, Hash)] | ||
285 | enum AttrOwner { | ||
286 | /// Attributes on an item. | ||
287 | ModItem(ModItem), | ||
288 | /// Inner attributes of the source file. | ||
289 | TopLevel, | ||
290 | // FIXME: Store variant and field attrs, and stop reparsing them in `attrs_query`. | ||
291 | } | ||
292 | |||
293 | /// Trait implemented by all nodes in the item tree. | 293 | /// Trait implemented by all nodes in the item tree. |
294 | pub trait ItemTreeNode: Clone { | 294 | pub trait ItemTreeNode: Clone { |
295 | type Source: AstNode + Into<ast::ModuleItem>; | 295 | type Source: AstNode + Into<ast::ModuleItem>; |