Skip to main content

Lowerer

Struct Lowerer 

Source
pub struct Lowerer<'m, K> { /* private fields */ }
Expand description

Lowers syntax trees with one mapping: the configured path, for a budget, a compilation unit other than 0, or host-provided field labels.

§Examples

use hir_lang::UnitId;
use lower_lang::{Arch, Budget, Lowerer, MappingBuilder, Pick};
use syntax_lang::Node;

let mut b = MappingBuilder::new();
b.node(K(0), Arch::Module { name: Pick::Absent, items: Pick::Nodes });
let mapping = b.build()?;
let tree = Node::new(K(0), vec![]);
let mut names = intern_lang::Interner::new();
let out = Lowerer::new(&mapping)
    .with_unit(UnitId::new(3))
    .with_budget(Budget::default())
    .lower(&tree, "", &mut names)
    .expect("within budget");
assert_eq!(out.hir.unit(), UnitId::new(3));

Implementations§

Source§

impl<'m, K> Lowerer<'m, K>
where K: Copy + Ord + TokenKind,

Source

pub fn new(mapping: &'m Mapping<K>) -> Self

A lowerer for mapping, with the default budget, unit 0, and no field labels.

§Examples

See Lowerer.

Source

pub fn with_budget(self, budget: Budget) -> Self

Sets the budget.

§Examples

See Lowerer.

Source

pub fn with_unit(self, unit: UnitId) -> Self

Sets the compilation unit the HIR is built for.

§Examples

See Lowerer.

Source

pub fn with_labeler(self, labeler: &'m dyn Labeler<K>) -> Self

Uses labeler for Pick::Label fields.

§Examples
use lower_lang::{Labeler, Lowerer, MappingBuilder};
use syntax_lang::Node;

struct NoFields;
impl Labeler<K> for NoFields {
    fn label(&self, _: &Node<K>, _: usize) -> Option<u16> { None }
}
let mapping = MappingBuilder::<K>::new().build()?;
let _lowerer = Lowerer::new(&mapping).with_labeler(&NoFields);
Source

pub fn lower( &self, tree: &Node<K>, source: &str, names: &mut Interner, ) -> Result<Lowered, LowerError>

Lowers tree (parsed from source) into a validated HIR unit, with names interned in names.

§Errors

Only for exhausted resources: LowerError::NodeBudget, LowerError::SymbolSpaceExhausted, or LowerError::Hir when hir-lang’s arenas overflow. Problems in the code are never errors: they are in Lowered::problems.

§Examples

See Lowerer.

Auto Trait Implementations§

§

impl<'m, K> !RefUnwindSafe for Lowerer<'m, K>

§

impl<'m, K> !Send for Lowerer<'m, K>

§

impl<'m, K> !Sync for Lowerer<'m, K>

§

impl<'m, K> !UnwindSafe for Lowerer<'m, K>

§

impl<'m, K> Freeze for Lowerer<'m, K>
where &'m Mapping<K>: Freeze, Option<&'m dyn Labeler<K>>: Freeze,

§

impl<'m, K> Unpin for Lowerer<'m, K>
where &'m Mapping<K>: Unpin, Option<&'m dyn Labeler<K>>: Unpin,

§

impl<'m, K> UnsafeUnpin for Lowerer<'m, K>
where &'m Mapping<K>: UnsafeUnpin, Option<&'m dyn Labeler<K>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.