Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellen Arteca committed Dec 10, 2024
1 parent cd2baf5 commit d063e4c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
46 changes: 40 additions & 6 deletions tool/src/kotlin/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,55 @@ impl<'tcx> KotlinFormatter<'tcx> {
"Array<String>"
}

pub fn fmt_primitive_as_ffi(&self, prim: PrimitiveType, support_unsigned: bool) -> &'static str {
pub fn fmt_primitive_as_ffi(
&self,
prim: PrimitiveType,
support_unsigned: bool,
) -> &'static str {
match prim {
PrimitiveType::Bool => "Boolean",
PrimitiveType::Char => "Int",
PrimitiveType::Int(IntType::I8) => "Byte",
PrimitiveType::Int(IntType::I16) => "Short",
PrimitiveType::Int(IntType::I32) => "Int",
PrimitiveType::Int(IntType::I64) => "Long",
PrimitiveType::Int(IntType::U8) => if support_unsigned {"UByte"} else {"Byte"},
PrimitiveType::Int(IntType::U16) => if support_unsigned {"UShort"} else {"Short"},
PrimitiveType::Int(IntType::U32) => if support_unsigned {"UInt"} else {"Int"},
PrimitiveType::Int(IntType::U64) => if support_unsigned {"ULong"} else {"Long"},
PrimitiveType::Int(IntType::U8) => {
if support_unsigned {
"UByte"
} else {
"Byte"
}
}
PrimitiveType::Int(IntType::U16) => {
if support_unsigned {
"UShort"
} else {
"Short"
}
}
PrimitiveType::Int(IntType::U32) => {
if support_unsigned {
"UInt"
} else {
"Int"
}
}
PrimitiveType::Int(IntType::U64) => {
if support_unsigned {
"ULong"
} else {
"Long"
}
}
PrimitiveType::Byte => "Byte",
PrimitiveType::IntSize(IntSizeType::Isize) => "Long",
PrimitiveType::IntSize(IntSizeType::Usize) => if support_unsigned {"ULong"} else {"Long"},
PrimitiveType::IntSize(IntSizeType::Usize) => {
if support_unsigned {
"ULong"
} else {
"Long"
}
}
PrimitiveType::Float(FloatType::F32) => "Float",
PrimitiveType::Float(FloatType::F64) => "Double",
PrimitiveType::Int128(_) => panic!("i128 not supported in Kotlin"),
Expand Down
5 changes: 4 additions & 1 deletion tool/src/kotlin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,10 @@ returnVal.option() ?: return null
support_unsigned: bool,
) -> Cow<'cx, str> {
match *ty {
Type::Primitive(prim) => self.formatter.fmt_primitive_as_ffi(prim, support_unsigned).into(),
Type::Primitive(prim) => self
.formatter
.fmt_primitive_as_ffi(prim, support_unsigned)
.into(),
Type::Opaque(ref op) => {
let optional = if op.is_optional() { "?" } else { "" };
format!("Pointer{optional}").into()
Expand Down

0 comments on commit d063e4c

Please sign in to comment.