From 2928600374a8356c2c2bffee080c47cb0f463fb9 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 24 Jun 2020 16:50:23 +0200 Subject: Reorder items --- crates/ra_hir_def/src/item_tree.rs | 152 ++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 76 deletions(-) (limited to 'crates') 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::{ use ra_arena::{Arena, Idx, RawId}; use ra_syntax::{ast, match_ast}; use rustc_hash::FxHashMap; +use smallvec::SmallVec; use test_utils::mark; use crate::{ @@ -33,26 +34,6 @@ use crate::{ type_ref::{Mutability, TypeBound, TypeRef}, visibility::RawVisibility, }; -use smallvec::SmallVec; - -#[derive(Default, Debug, Eq, PartialEq)] -struct ItemVisibilities { - arena: Arena, -} - -impl ItemVisibilities { - fn alloc(&mut self, vis: RawVisibility) -> RawVisibilityId { - match &vis { - RawVisibility::Public => RawVisibilityId::PUB, - RawVisibility::Module(path) if path.segments.is_empty() => match &path.kind { - PathKind::Super(0) => RawVisibilityId::PRIV, - PathKind::Crate => RawVisibilityId::PUB_CRATE, - _ => RawVisibilityId(self.arena.alloc(vis).into_raw().into()), - }, - _ => RawVisibilityId(self.arena.alloc(vis).into_raw().into()), - } - } -} #[derive(Copy, Clone, Eq, PartialEq)] pub struct RawVisibilityId(u32); @@ -76,21 +57,6 @@ impl fmt::Debug for RawVisibilityId { } } -#[derive(Default, Debug, Eq, PartialEq)] -struct GenericParamsStorage { - arena: Arena, -} - -impl GenericParamsStorage { - fn alloc(&mut self, params: GenericParams) -> GenericParamsId { - if params.types.is_empty() && params.where_predicates.is_empty() { - return GenericParamsId::EMPTY; - } - - GenericParamsId(self.arena.alloc(params).into_raw().into()) - } -} - #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub struct GenericParamsId(u32); @@ -98,47 +64,6 @@ impl GenericParamsId { pub const EMPTY: Self = GenericParamsId(u32::max_value()); } -static VIS_PUB: RawVisibility = RawVisibility::Public; -static VIS_PRIV: RawVisibility = - RawVisibility::Module(ModPath { kind: PathKind::Super(0), segments: Vec::new() }); -static VIS_PUB_CRATE: RawVisibility = - RawVisibility::Module(ModPath { kind: PathKind::Crate, segments: Vec::new() }); - -static EMPTY_GENERICS: GenericParams = - GenericParams { types: Arena::new(), where_predicates: Vec::new() }; - -#[derive(Default, Debug, Eq, PartialEq)] -struct ItemTreeData { - imports: Arena, - extern_crates: Arena, - functions: Arena, - structs: Arena, - fields: Arena, - unions: Arena, - enums: Arena, - variants: Arena, - consts: Arena, - statics: Arena, - traits: Arena, - impls: Arena, - type_aliases: Arena, - mods: Arena, - macro_calls: Arena, - exprs: Arena, - - vis: ItemVisibilities, - generics: GenericParamsStorage, -} - -#[derive(Debug, Eq, PartialEq, Hash)] -enum AttrOwner { - /// Attributes on an item. - ModItem(ModItem), - /// Inner attributes of the source file. - TopLevel, - // FIXME: Store variant and field attrs, and stop reparsing them in `attrs_query`. -} - /// The item tree of a source file. #[derive(Debug, Eq, PartialEq)] pub struct ItemTree { @@ -290,6 +215,81 @@ impl ItemTree { } } +#[derive(Default, Debug, Eq, PartialEq)] +struct ItemVisibilities { + arena: Arena, +} + +impl ItemVisibilities { + fn alloc(&mut self, vis: RawVisibility) -> RawVisibilityId { + match &vis { + RawVisibility::Public => RawVisibilityId::PUB, + RawVisibility::Module(path) if path.segments.is_empty() => match &path.kind { + PathKind::Super(0) => RawVisibilityId::PRIV, + PathKind::Crate => RawVisibilityId::PUB_CRATE, + _ => RawVisibilityId(self.arena.alloc(vis).into_raw().into()), + }, + _ => RawVisibilityId(self.arena.alloc(vis).into_raw().into()), + } + } +} + +static VIS_PUB: RawVisibility = RawVisibility::Public; +static VIS_PRIV: RawVisibility = + RawVisibility::Module(ModPath { kind: PathKind::Super(0), segments: Vec::new() }); +static VIS_PUB_CRATE: RawVisibility = + RawVisibility::Module(ModPath { kind: PathKind::Crate, segments: Vec::new() }); + +#[derive(Default, Debug, Eq, PartialEq)] +struct GenericParamsStorage { + arena: Arena, +} + +impl GenericParamsStorage { + fn alloc(&mut self, params: GenericParams) -> GenericParamsId { + if params.types.is_empty() && params.where_predicates.is_empty() { + return GenericParamsId::EMPTY; + } + + GenericParamsId(self.arena.alloc(params).into_raw().into()) + } +} + +static EMPTY_GENERICS: GenericParams = + GenericParams { types: Arena::new(), where_predicates: Vec::new() }; + +#[derive(Default, Debug, Eq, PartialEq)] +struct ItemTreeData { + imports: Arena, + extern_crates: Arena, + functions: Arena, + structs: Arena, + fields: Arena, + unions: Arena, + enums: Arena, + variants: Arena, + consts: Arena, + statics: Arena, + traits: Arena, + impls: Arena, + type_aliases: Arena, + mods: Arena, + macro_calls: Arena, + exprs: Arena, + + vis: ItemVisibilities, + generics: GenericParamsStorage, +} + +#[derive(Debug, Eq, PartialEq, Hash)] +enum AttrOwner { + /// Attributes on an item. + ModItem(ModItem), + /// Inner attributes of the source file. + TopLevel, + // FIXME: Store variant and field attrs, and stop reparsing them in `attrs_query`. +} + /// Trait implemented by all nodes in the item tree. pub trait ItemTreeNode: Clone { type Source: AstNode + Into; -- cgit v1.2.3