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 CtxFront-end services: naming, nesting, type queries, nested bodies.
vt: &'a VarTable§ret_bool: bool§ret_char: boolTrue 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: boolNarrowing-return markers: int-valued expressions in the return
need (byte)/(short) casts (jdk11 MemberName:
byte normalVirtual = cond ? 5 : 9;).
ret_short: boolImplementations§
Source§impl<'a> Printer<'a>
impl<'a> Printer<'a>
pub fn new(ctx: &'a dyn Ctx, vt: &'a VarTable) -> Self
pub fn with_ret_bool(self, b: bool) -> Self
pub fn with_ret_sam(self, t: Option<TypeRef>) -> Self
pub fn with_ret_char(self, b: bool) -> Self
pub fn with_ret_narrow(self, byte: bool, short: bool) -> Self
Sourcepub fn with_output(self, out: String) -> Self
pub fn with_output(self, out: String) -> Self
Printer rendering into a caller-provided buffer: the method text (signature, braces) and the printed body land in ONE string — ddc used to render the body separately and copy it line-by-line into the class buffer (a full extra pass over every method).
Sourcepub fn with_indent(self, indent: usize) -> Self
pub fn with_indent(self, indent: usize) -> Self
Printer starting at a fixed indentation level (method bodies at 1).
pub fn into_string(self, body: &Stmt) -> String
pub fn expr_bool(&mut self, e: &Expr, out: &mut String)
Sourcepub fn expr_narrow(&mut self, e: &Expr, ty: &JavaType, out: &mut String)
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;).
Sourcepub fn expr_char(&mut self, e: &Expr, out: &mut String)
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; }).