diff options
Diffstat (limited to 'crates/hir_def/src/item_tree.rs')
-rw-r--r-- | crates/hir_def/src/item_tree.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 7bb22c4c4..90df3d929 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs | |||
@@ -134,6 +134,7 @@ impl ItemTree { | |||
134 | imports, | 134 | imports, |
135 | extern_crates, | 135 | extern_crates, |
136 | functions, | 136 | functions, |
137 | params, | ||
137 | structs, | 138 | structs, |
138 | fields, | 139 | fields, |
139 | unions, | 140 | unions, |
@@ -157,6 +158,7 @@ impl ItemTree { | |||
157 | imports.shrink_to_fit(); | 158 | imports.shrink_to_fit(); |
158 | extern_crates.shrink_to_fit(); | 159 | extern_crates.shrink_to_fit(); |
159 | functions.shrink_to_fit(); | 160 | functions.shrink_to_fit(); |
161 | params.shrink_to_fit(); | ||
160 | structs.shrink_to_fit(); | 162 | structs.shrink_to_fit(); |
161 | fields.shrink_to_fit(); | 163 | fields.shrink_to_fit(); |
162 | unions.shrink_to_fit(); | 164 | unions.shrink_to_fit(); |
@@ -303,6 +305,7 @@ struct ItemTreeData { | |||
303 | imports: Arena<Import>, | 305 | imports: Arena<Import>, |
304 | extern_crates: Arena<ExternCrate>, | 306 | extern_crates: Arena<ExternCrate>, |
305 | functions: Arena<Function>, | 307 | functions: Arena<Function>, |
308 | params: Arena<Param>, | ||
306 | structs: Arena<Struct>, | 309 | structs: Arena<Struct>, |
307 | fields: Arena<Field>, | 310 | fields: Arena<Field>, |
308 | unions: Arena<Union>, | 311 | unions: Arena<Union>, |
@@ -334,6 +337,7 @@ pub enum AttrOwner { | |||
334 | 337 | ||
335 | Variant(Idx<Variant>), | 338 | Variant(Idx<Variant>), |
336 | Field(Idx<Field>), | 339 | Field(Idx<Field>), |
340 | Param(Idx<Param>), | ||
337 | } | 341 | } |
338 | 342 | ||
339 | macro_rules! from_attrs { | 343 | macro_rules! from_attrs { |
@@ -348,7 +352,7 @@ macro_rules! from_attrs { | |||
348 | }; | 352 | }; |
349 | } | 353 | } |
350 | 354 | ||
351 | from_attrs!(ModItem(ModItem), Variant(Idx<Variant>), Field(Idx<Field>)); | 355 | from_attrs!(ModItem(ModItem), Variant(Idx<Variant>), Field(Idx<Field>), Param(Idx<Param>)); |
352 | 356 | ||
353 | /// Trait implemented by all item nodes in the item tree. | 357 | /// Trait implemented by all item nodes in the item tree. |
354 | pub trait ItemTreeNode: Clone { | 358 | pub trait ItemTreeNode: Clone { |
@@ -484,7 +488,7 @@ macro_rules! impl_index { | |||
484 | }; | 488 | }; |
485 | } | 489 | } |
486 | 490 | ||
487 | impl_index!(fields: Field, variants: Variant); | 491 | impl_index!(fields: Field, variants: Variant, params: Param); |
488 | 492 | ||
489 | impl Index<RawVisibilityId> for ItemTree { | 493 | impl Index<RawVisibilityId> for ItemTree { |
490 | type Output = RawVisibility; | 494 | type Output = RawVisibility; |
@@ -560,12 +564,17 @@ pub struct Function { | |||
560 | /// Whether the function is located in an `extern` block (*not* whether it is an | 564 | /// Whether the function is located in an `extern` block (*not* whether it is an |
561 | /// `extern "abi" fn`). | 565 | /// `extern "abi" fn`). |
562 | pub is_in_extern_block: bool, | 566 | pub is_in_extern_block: bool, |
563 | pub params: Box<[Idx<TypeRef>]>, | 567 | pub params: IdRange<Param>, |
564 | pub is_varargs: bool, | ||
565 | pub ret_type: Idx<TypeRef>, | 568 | pub ret_type: Idx<TypeRef>, |
566 | pub ast_id: FileAstId<ast::Fn>, | 569 | pub ast_id: FileAstId<ast::Fn>, |
567 | } | 570 | } |
568 | 571 | ||
572 | #[derive(Debug, Clone, Eq, PartialEq)] | ||
573 | pub enum Param { | ||
574 | Normal(Idx<TypeRef>), | ||
575 | Varargs, | ||
576 | } | ||
577 | |||
569 | #[derive(Debug, Clone, PartialEq, Eq)] | 578 | #[derive(Debug, Clone, PartialEq, Eq)] |
570 | pub struct FunctionQualifier { | 579 | pub struct FunctionQualifier { |
571 | pub is_default: bool, | 580 | pub is_default: bool, |
@@ -796,6 +805,7 @@ pub struct Variant { | |||
796 | pub fields: Fields, | 805 | pub fields: Fields, |
797 | } | 806 | } |
798 | 807 | ||
808 | /// A range of densely allocated ItemTree IDs. | ||
799 | pub struct IdRange<T> { | 809 | pub struct IdRange<T> { |
800 | range: Range<u32>, | 810 | range: Range<u32>, |
801 | _p: PhantomData<T>, | 811 | _p: PhantomData<T>, |
@@ -814,6 +824,12 @@ impl<T> Iterator for IdRange<T> { | |||
814 | } | 824 | } |
815 | } | 825 | } |
816 | 826 | ||
827 | impl<T> DoubleEndedIterator for IdRange<T> { | ||
828 | fn next_back(&mut self) -> Option<Self::Item> { | ||
829 | self.range.next_back().map(|raw| Idx::from_raw(raw.into())) | ||
830 | } | ||
831 | } | ||
832 | |||
817 | impl<T> fmt::Debug for IdRange<T> { | 833 | impl<T> fmt::Debug for IdRange<T> { |
818 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 834 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
819 | f.debug_tuple(&format!("IdRange::<{}>", type_name::<T>())).field(&self.range).finish() | 835 | f.debug_tuple(&format!("IdRange::<{}>", type_name::<T>())).field(&self.range).finish() |