pub(crate) mod index;
pub(crate) mod index2;
mod indexer;
pub(crate) mod items;
mod scopes;
use crate as rune;
use crate::alloc::prelude::*;
use crate::ast::{self, Span, Spanned};
use crate::compile::meta;
use crate::compile::{ItemId, ItemMeta};
use crate::grammar::NodeAt;
use crate::runtime::Call;
use self::indexer::{ast_to_visibility, validate_call};
pub(crate) use self::indexer::{IndexItem, Indexer};
use self::items::Guard;
pub(crate) use self::items::Items;
use self::scopes::Layer;
pub(crate) use self::scopes::Scopes;
#[derive(Debug, TryClone)]
pub(crate) struct Entry {
pub(crate) item_meta: ItemMeta,
pub(crate) indexed: Indexed,
}
impl Entry {
pub(crate) fn item(&self) -> ItemId {
match &self.indexed {
Indexed::Import(Import { entry, .. }) => entry.target,
_ => self.item_meta.item,
}
}
}
#[derive(Debug, TryClone)]
pub(crate) enum Indexed {
Enum,
Struct(Struct),
Variant(Variant),
Function(Function),
ConstExpr(ConstExpr),
ConstBlock(ConstBlock),
ConstFn(ConstFn),
Import(Import),
Module,
}
#[derive(Debug, TryClone, Spanned)]
pub(crate) enum FunctionAst {
Bare(#[rune(span)] NodeAt),
Node(#[rune(span)] NodeAt, Option<ast::Ident>),
Empty(Box<ast::EmptyBlock>, #[rune(span)] Span),
Item(#[rune(span)] Box<ast::ItemFn>, ast::Ident),
}
#[derive(Debug, TryClone)]
pub(crate) struct Function {
pub(crate) ast: FunctionAst,
pub(crate) call: Call,
pub(crate) is_instance: bool,
pub(crate) is_test: bool,
pub(crate) is_bench: bool,
pub(crate) impl_item: Option<ItemId>,
pub(crate) args: Vec<Span>,
}
#[derive(Debug, TryClone, Clone, Copy)]
#[try_clone(copy)]
pub(crate) struct Import {
pub(crate) entry: meta::Import,
pub(crate) wildcard: bool,
}
#[derive(Debug, TryClone)]
pub(crate) struct Struct {
pub(crate) fields: meta::Fields,
}
#[derive(Debug, TryClone)]
pub(crate) struct Variant {
pub(crate) enum_id: ItemId,
pub(crate) index: usize,
pub(crate) fields: meta::Fields,
}
#[derive(Debug, TryClone)]
pub(crate) enum ConstExpr {
Ast(Box<ast::Expr>),
Node(NodeAt),
}
#[derive(Debug, TryClone)]
pub(crate) enum ConstBlock {
Ast(Box<ast::Block>),
Node(NodeAt),
}
#[derive(Debug, TryClone)]
pub(crate) enum ConstFn {
Node(NodeAt),
Ast(Box<ast::ItemFn>),
}