Struct rustlr::generic_absyn::LBox
source · pub struct LBox<T: ?Sized> {
pub exp: Box<T>,
pub line: u32,
pub column: u32,
pub uid: u32,
}
Expand description
Custom smart pointer that encapsulates line and column numbers along with a regular Box. Implements Deref and DerefMut so the encapsulated expression can be accessed as in a standard Box. This is intended to to be used in the formation of abstract syntax trees so that the lexical information is available for each construct after the parsing stage. Also included in each LBox created by the runtime parser (ZCParser) is a 32 bit (u32) unique identifier uid that uniquely identifies each LBox. An expression and a subexpression can both begin at the same line and column numbers and the unique id would be required to distinguish them. This device is useful for hashing information, such as inferred types, based on the location of an expression in the source.
Fields§
§exp: Box<T>
§line: u32
§column: u32
§uid: u32
Implementations§
source§impl<T> LBox<T>
impl<T> LBox<T>
sourcepub fn new(e: T, ln: usize, col: usize) -> LBox<T>
pub fn new(e: T, ln: usize, col: usize) -> LBox<T>
creates a new LBox with line ln, column col and uid set to zero; this function is deprecated by LBox::make.
sourcepub fn make(e: T, ln: usize, col: usize, u: u32) -> LBox<T>
pub fn make(e: T, ln: usize, col: usize, u: u32) -> LBox<T>
creates a new LBox enclosing e, with line ln, column col and uid u
sourcepub fn transfer<U>(&self, e: U) -> LBox<U>
pub fn transfer<U>(&self, e: U) -> LBox<U>
should be used to create a new LBoxed expression that inherits lexical information from existing LBox
sourcepub fn line(&self) -> usize
pub fn line(&self) -> usize
Since version 0.2.4, Rustlr now stores the line and column information internally as u32 values instead of usize, and the LBox::line and LBox::column functions are provided for interface
pub fn column(&self) -> usize
pub fn uid(&self) -> u32
source§impl<'t> LBox<dyn Any + 't>
impl<'t> LBox<dyn Any + 't>
sourcepub fn downcast<U: 't>(self) -> Option<LBox<U>>
pub fn downcast<U: 't>(self) -> Option<LBox<U>>
emulates Box::downcast function, when LBox<dyn Any>
is used as
the abstract syntax type. Note that unlike Box::downcast, an Option
is returned here instead of a result.
sourcepub fn upcast<T: 't>(lb: LBox<T>) -> Self
pub fn upcast<T: 't>(lb: LBox<T>) -> Self
do not try to create a LBox<dyn Any>
structure with something like
let lb:LBox<dyn Any> = LBox::new(String::from("abc"),0,0);
This does not work as LBox is simply borrowing the underlying mechanics of Box instead of re-creating them. Do instead:
let lb:LBox<dyn Any> = LBox::upcast(LBox::new(String::from("abc"),0,0));
upcast always returns a LBox<dyn Any>
.
Trait Implementations§
source§impl Default for LBox<dyn Any>
impl Default for LBox<dyn Any>
this is provided so LBox<dyn Any>
can be used for the abstract syntax type.
the default is a Lbox containing a static string.