Skip to main content

Printer

Struct Printer 

Source
pub struct Printer<'a> {
    pub ctx: &'a dyn Ctx,
    pub vt: &'a VarTable,
    pub ret_bool: bool,
    pub ret_char: bool,
    pub ret_byte: bool,
    pub ret_short: bool,
    /* private fields */
}

Fields§

§ctx: &'a dyn Ctx

Front-end services: naming, nesting, type queries, nested bodies.

§vt: &'a VarTable§ret_bool: bool

True when the enclosing method returns boolean.

§ret_char: bool

True when the enclosing method returns char: int constants in the returned expression render as char literals (bytecode chars are ints; return cond ? 63 : 105; in a char method is a lossy conversion — source was ? '?' : 'i', jdk XML Parser x23).

§ret_byte: bool

Narrowing-return markers: int-valued expressions in the return need (byte)/(short) casts (jdk11 MemberName: byte normalVirtual = cond ? 5 : 9;).

§ret_short: bool

Implementations§

Source§

impl<'a> Printer<'a>

Source

pub fn new(ctx: &'a dyn Ctx, vt: &'a VarTable) -> Self

Source

pub fn with_ret_bool(self, b: bool) -> Self

Source

pub fn with_ret_sam(self, t: Option<TypeRef>) -> Self

Source

pub fn with_ret_char(self, b: bool) -> Self

Source

pub fn with_ret_narrow(self, byte: bool, short: bool) -> Self

Source

pub fn with_indent(self, indent: usize) -> Self

Printer starting at a fixed indentation level (method bodies at 1).

Source

pub fn into_string(self, body: &Stmt) -> String

Source

pub fn expr_bool(&mut self, e: &Expr, out: &mut String)

Source

pub fn expr_narrow(&mut self, e: &Expr, ty: &JavaType, out: &mut String)

Render an int-typed expression in a byte/short target: constants and ternary branches get the narrowing cast (javac’s conditional expression only narrows when the target type is known — a return or local-decl of byte/short with int constants needs explicit casts: byte normalVirtual = !if() ? (byte) 5 : (byte) 9;).

Source

pub fn expr_char(&mut self, e: &Expr, out: &mut String)

Render an expression in a char-typed target: int constants become char literals, ternary branches recurse (the lossy-conversion fix for char name2type(..) { return c ? 63 : 105; }).

Source

pub fn expr(&mut self, e: &Expr, outer_prec: u8, out: &mut String)

Source

pub fn shorten(&self, internal: &str) -> String

Source

pub fn type_name(&self, ty: &TypeRef) -> String

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Printer<'a>

§

impl<'a> !Send for Printer<'a>

§

impl<'a> !Sync for Printer<'a>

§

impl<'a> !UnwindSafe for Printer<'a>

§

impl<'a> Freeze for Printer<'a>

§

impl<'a> Unpin for Printer<'a>

§

impl<'a> UnsafeUnpin for Printer<'a>

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.