-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
118 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use cranelift_entity::{entity_impl, PrimaryMap}; | ||
use rustc_hash::FxHashSet; | ||
|
||
use super::{IdentId, ItemKind, PathId, Struct, TopLevelMod, UseAlias}; | ||
|
||
pub struct ScopeGraph { | ||
pub top_mod: TopLevelMod, | ||
pub scopes: PrimaryMap<LocalScopeId, LocalScope>, | ||
pub unresolved: FxHashSet<UnresolvedName>, | ||
} | ||
|
||
pub struct UnresolvedName { | ||
pub scope: LocalScopeId, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct LocalScope { | ||
kind: ScopeKind, | ||
edges: Vec<ScopeEdge>, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub enum ScopeKind { | ||
Item(ItemKind), | ||
Field(usize), | ||
Variant(Struct, usize), | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct ScopeEdge { | ||
dest: ScopeId, | ||
kind: EdgeKind, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub enum EdgeKind { | ||
Lex(LexEdge), | ||
Mod(ModEdge), | ||
GlobUse(GlobUseEdge), | ||
Use(UseEdge), | ||
Type(TypeEdge), | ||
Func(FuncEdge), | ||
Field(FieldEdge), | ||
Variant(VariantEdge), | ||
Super(SuperEdge), | ||
Ingot(IngotEdge), | ||
SelfTy(SelfTyEdge), | ||
Anon(AnonEdge), | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct LexEdge(); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct ModEdge(IdentId); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct GlobUseEdge { | ||
/// `UsePathSegment` are lowered to a normal `Path`. | ||
path: PathId, | ||
alias: UseAlias, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct UseEdge { | ||
/// `UsePathSegment` are lowered to a normal `Path`. | ||
path: PathId, | ||
alias: UseAlias, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct TypeEdge(IdentId); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct FuncEdge(IdentId); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct FieldEdge(IdentId); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct VariantEdge(IdentId); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct SuperEdge(); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct IngotEdge(); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct SelfEdge { | ||
path: PathId, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct SelfTyEdge { | ||
path: PathId, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct LocalEdge(IdentId); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct AnonEdge(); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct ScopeId { | ||
top_mod: TopLevelMod, | ||
local_id: LocalScopeId, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct LocalScopeId(u32); | ||
entity_impl!(LocalScopeId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters