use std::collections::{HashMap, HashSet};
use crate::ir::expr::Expr;
use crate::ir::expr::TypeRef;
use crate::ir::stmt::Stmt;
use crate::types::{ClassAccessFlags, MethodDescriptor};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NestedKind {
Member,
Anonymous,
Local,
Lambda,
}
#[derive(Debug, Clone)]
pub struct NestedClass {
pub name: String,
pub simple: String,
pub kind: NestedKind,
pub access: ClassAccessFlags,
pub sig_header: Option<String>,
}
#[derive(Debug, Default, Clone)]
pub struct Family {
pub root: String,
pub nested: HashMap<String, NestedClass>,
pub anonymous: HashSet<String>,
pub locals: HashSet<String>,
pub lambdas: HashSet<String>,
}
pub struct MethodBody {
pub body: Stmt,
pub vt: crate::var::VarTable,
pub desc: MethodDescriptor,
}
pub trait Ctx {
fn class_name(&self) -> &str;
fn source_level(&self) -> u16 {
52
}
fn obscured_member_escape(&self, _owner: &str, _member: &str) -> bool {
false
}
fn obscured_simple(&self, _internal: &str) -> Option<String> {
None
}
fn pool_id(&self) -> u64 {
0
}
fn find_outer(&self, internal: &str) -> Option<String>;
fn family(&self, root: &str) -> Family;
fn nested_is_static(&self, internal: &str) -> bool;
fn class_has_this0(&self, internal: &str) -> bool;
fn is_subtype_of(&self, sub: &crate::types::JavaType, sup: &str) -> bool;
fn class_supers_args(
&self,
internal: &str,
args: &[crate::types::GenericType],
) -> Vec<(String, Vec<crate::types::GenericType>)>;
fn is_generic_call(&self, e: &Expr) -> bool;
fn generic_call_formals(
&self,
e: &Expr,
) -> Option<(Vec<crate::types::GenericType>, Vec<String>)>;
fn polymorphic_ret_cast(
&self,
cls: &str,
name: &str,
desc: &MethodDescriptor,
) -> Option<crate::types::JavaType>;
fn ctor_formals_by_arity(
&self,
internal: &str,
arity: usize,
) -> Option<Vec<crate::types::GenericType>>;
fn local_class_internal(&self, simple: &str) -> Option<String> {
let _ = simple;
None
}
fn class_type_params(&self, internal: &str) -> Vec<crate::types::TypeParam> {
let _ = internal;
Vec::new()
}
fn generic_call_mt_typevars(&self, e: &Expr) -> Vec<String> {
let _ = e;
Vec::new()
}
fn super_name(&self, internal: &str) -> Option<String> {
let _ = internal;
None
}
fn field_flags(&self, internal: &str, name: &str) -> Option<crate::types::FieldAccessFlags> {
let _ = (internal, name);
None
}
fn method_flags(
&self,
internal: &str,
name: &str,
desc: &str,
) -> Option<crate::types::MethodAccessFlags> {
let _ = (internal, name, desc);
None
}
fn declares_field(&self, internal: &str, name: &str) -> bool {
self.field_flags(internal, name).is_some()
}
fn declares_field_display(&self, internal: &str, display: &str) -> bool {
let _ = (internal, display);
false
}
fn declares_method_named(&self, internal: &str, name: &str) -> bool {
let _ = (internal, name);
false
}
fn is_fw_shadow(&self, internal: &str) -> bool {
let _ = internal;
false
}
fn is_interface(&self, internal: &str) -> bool;
fn is_sealed(&self, internal: &str) -> bool;
fn has_class(&self, internal: &str) -> bool;
fn class_bases(&self, internal: &str) -> Option<(Vec<String>, Option<String>)>;
fn outer_param_via_super(&self, internal: &str) -> bool;
fn nested_method(
&self,
l: &crate::ir::expr::LambdaExpr,
outer_vt: &crate::var::VarTable,
) -> Option<MethodBody>;
fn ctor_param_types(
&self,
internal: &str,
skip: usize,
n: usize,
args: &[Expr],
) -> Option<Vec<crate::types::JavaType>> {
let _ = (internal, skip, n, args);
None
}
fn sam_ret_cast(&self, g: &crate::types::GenericType, sam_name: &str) -> Option<TypeRef> {
let _ = (g, sam_name);
None
}
fn class_declares_generics(&self, internal: &str) -> bool {
!self.class_type_params(internal).is_empty()
}
}
pub struct NullCtx {
pub class_name: String,
pub level: u16,
}
impl Default for NullCtx {
fn default() -> Self {
NullCtx {
class_name: String::new(),
level: 52,
}
}
}
impl Ctx for NullCtx {
fn class_name(&self) -> &str {
&self.class_name
}
fn source_level(&self) -> u16 {
self.level
}
fn find_outer(&self, _internal: &str) -> Option<String> {
None
}
fn family(&self, root: &str) -> Family {
Family {
root: root.to_string(),
..Default::default()
}
}
fn nested_is_static(&self, _internal: &str) -> bool {
true
}
fn class_has_this0(&self, _internal: &str) -> bool {
false
}
fn is_subtype_of(&self, _sub: &crate::types::JavaType, _sup: &str) -> bool {
false
}
fn class_supers_args(
&self,
_internal: &str,
_args: &[crate::types::GenericType],
) -> Vec<(String, Vec<crate::types::GenericType>)> {
Vec::new()
}
fn is_generic_call(&self, _e: &Expr) -> bool {
false
}
fn generic_call_formals(
&self,
_e: &Expr,
) -> Option<(Vec<crate::types::GenericType>, Vec<String>)> {
None
}
fn polymorphic_ret_cast(
&self,
_cls: &str,
_name: &str,
_desc: &MethodDescriptor,
) -> Option<crate::types::JavaType> {
None
}
fn ctor_formals_by_arity(
&self,
_internal: &str,
_arity: usize,
) -> Option<Vec<crate::types::GenericType>> {
None
}
fn is_interface(&self, _internal: &str) -> bool {
false
}
fn is_sealed(&self, _internal: &str) -> bool {
false
}
fn has_class(&self, _internal: &str) -> bool {
false
}
fn class_bases(&self, _internal: &str) -> Option<(Vec<String>, Option<String>)> {
None
}
fn outer_param_via_super(&self, _internal: &str) -> bool {
false
}
fn nested_method(
&self,
_l: &crate::ir::expr::LambdaExpr,
_outer_vt: &crate::var::VarTable,
) -> Option<MethodBody> {
None
}
}
pub fn ctx_method_body(
body: crate::ir::stmt::Stmt,
vt: crate::var::VarTable,
desc: MethodDescriptor,
) -> MethodBody {
MethodBody { body, vt, desc }
}