1pub(crate) mod index;
2pub(crate) mod index2;
3mod indexer;
4pub(crate) mod items;
5mod scopes;
6
7use crate as rune;
8use crate::alloc::prelude::*;
9use crate::ast::{self, Span, Spanned};
10use crate::compile::meta;
11use crate::compile::{ItemId, ItemMeta};
12use crate::grammar::NodeAt;
13use crate::runtime::Call;
14
15use self::indexer::{ast_to_visibility, validate_call};
16pub(crate) use self::indexer::{IndexItem, Indexer};
17use self::items::Guard;
18pub(crate) use self::items::Items;
19use self::scopes::Layer;
20pub(crate) use self::scopes::Scopes;
21
22#[derive(Debug, TryClone)]
23pub(crate) struct Entry {
24 pub(crate) item_meta: ItemMeta,
26 pub(crate) indexed: Indexed,
28}
29
30impl Entry {
31 pub(crate) fn item(&self) -> ItemId {
33 match &self.indexed {
34 Indexed::Import(Import { entry, .. }) => entry.target,
35 _ => self.item_meta.item,
36 }
37 }
38}
39
40#[derive(Debug, TryClone)]
42pub(crate) enum Indexed {
43 Enum,
45 Struct(Struct),
47 Variant(Variant),
49 Function(Function),
51 ConstExpr(ConstExpr),
53 ConstBlock(ConstBlock),
55 ConstFn(ConstFn),
57 Import(Import),
59 Module,
61}
62
63#[derive(Debug, TryClone, Spanned)]
65pub(crate) enum FunctionAst {
66 Bare(#[rune(span)] NodeAt),
68 Node(#[rune(span)] NodeAt, Option<ast::Ident>),
70 Empty(Box<ast::EmptyBlock>, #[rune(span)] Span),
72 Item(#[rune(span)] Box<ast::ItemFn>, ast::Ident),
74}
75
76#[derive(Debug, TryClone)]
77pub(crate) struct Function {
78 pub(crate) ast: FunctionAst,
80 pub(crate) call: Call,
82 pub(crate) is_instance: bool,
84 pub(crate) is_test: bool,
86 pub(crate) is_bench: bool,
88 pub(crate) impl_item: Option<ItemId>,
90 pub(crate) args: Vec<Span>,
92}
93
94#[derive(Debug, TryClone, Clone, Copy)]
95#[try_clone(copy)]
96pub(crate) struct Import {
97 pub(crate) entry: meta::Import,
99 pub(crate) wildcard: bool,
103}
104
105#[derive(Debug, TryClone)]
106pub(crate) struct Struct {
107 pub(crate) fields: meta::Fields,
109}
110
111#[derive(Debug, TryClone)]
112pub(crate) struct Variant {
113 pub(crate) enum_id: ItemId,
115 pub(crate) fields: meta::Fields,
117}
118
119#[derive(Debug, TryClone)]
120pub(crate) enum ConstExpr {
121 Ast(Box<ast::Expr>),
123 Node(NodeAt),
125}
126
127#[derive(Debug, TryClone)]
128pub(crate) enum ConstBlock {
129 Ast(Box<ast::Block>),
131 Node(NodeAt),
133}
134
135#[derive(Debug, TryClone)]
136pub(crate) enum ConstFn {
137 Node(NodeAt),
139 Ast(Box<ast::ItemFn>),
141}