Update how types are formatted
This commit is contained in:
parent
ce645519ce
commit
f55040ad00
@ -74,12 +74,12 @@ impl Display for FunctionDefinition {
|
|||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{}fn {}({}) -> {} ",
|
"{}fn {}({}) -> {:#} ",
|
||||||
if self.is_pub { "pub " } else { "" },
|
if self.is_pub { "pub " } else { "" },
|
||||||
self.name,
|
self.name,
|
||||||
self.parameters
|
self.parameters
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(n, t)| format!("{}: {}", n, t))
|
.map(|(n, t)| format!("{}: {:#}", n, t))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(", "),
|
.join(", "),
|
||||||
self.return_type
|
self.return_type
|
||||||
@ -166,7 +166,7 @@ impl Display for ExprKind {
|
|||||||
ExprKind::Block(block) => Display::fmt(block, f),
|
ExprKind::Block(block) => Display::fmt(block, f),
|
||||||
ExprKind::Indexed(expression, elem_ty, idx_expr) => {
|
ExprKind::Indexed(expression, elem_ty, idx_expr) => {
|
||||||
Display::fmt(&expression, f)?;
|
Display::fmt(&expression, f)?;
|
||||||
write!(f, "<{}>", elem_ty)?;
|
write!(f, "<{:#}>", elem_ty)?;
|
||||||
write_index(f, idx_expr)
|
write_index(f, idx_expr)
|
||||||
}
|
}
|
||||||
ExprKind::Array(expressions) => {
|
ExprKind::Array(expressions) => {
|
||||||
@ -228,7 +228,7 @@ impl Display for IfExpression {
|
|||||||
|
|
||||||
impl Display for FunctionCall {
|
impl Display for FunctionCall {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "{}<{}>(", self.name, self.return_type)?;
|
write!(f, "{}<{:#}>(", self.name, self.return_type)?;
|
||||||
for (i, param) in self.parameters.iter().enumerate() {
|
for (i, param) in self.parameters.iter().enumerate() {
|
||||||
Display::fmt(param, f)?;
|
Display::fmt(param, f)?;
|
||||||
if i < (self.parameters.len() - 1) {
|
if i < (self.parameters.len() - 1) {
|
||||||
@ -241,7 +241,7 @@ impl Display for FunctionCall {
|
|||||||
|
|
||||||
impl Display for NamedVariableRef {
|
impl Display for NamedVariableRef {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "v(\"{}\", {})", &self.1, &self.0)
|
write!(f, "v(\"{}\", {:#})", &self.1, &self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,3 +312,62 @@ fn write_access(f: &mut std::fmt::Formatter<'_>, name: &String) -> std::fmt::Res
|
|||||||
f.write_char('.')?;
|
f.write_char('.')?;
|
||||||
Display::fmt(name, f)
|
Display::fmt(name, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for TypeKind {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
TypeKind::Bool => write!(f, "bool"),
|
||||||
|
TypeKind::I8 => write!(f, "i8"),
|
||||||
|
TypeKind::I16 => write!(f, "i16"),
|
||||||
|
TypeKind::I32 => write!(f, "i32"),
|
||||||
|
TypeKind::I64 => write!(f, "i64"),
|
||||||
|
TypeKind::I128 => write!(f, "i128"),
|
||||||
|
TypeKind::U8 => write!(f, "u8"),
|
||||||
|
TypeKind::U16 => write!(f, "u16"),
|
||||||
|
TypeKind::U32 => write!(f, "u32"),
|
||||||
|
TypeKind::U64 => write!(f, "u64"),
|
||||||
|
TypeKind::U128 => write!(f, "u128"),
|
||||||
|
TypeKind::Void => write!(f, "void"),
|
||||||
|
TypeKind::StringPtr => write!(f, "string"),
|
||||||
|
TypeKind::Array(type_kind, len) => {
|
||||||
|
f.write_char('[')?;
|
||||||
|
Display::fmt(type_kind, f)?;
|
||||||
|
write!(f, "; ")?;
|
||||||
|
Display::fmt(len, f)?;
|
||||||
|
f.write_char(']')
|
||||||
|
}
|
||||||
|
TypeKind::CustomType(name) => write!(f, "{}", name),
|
||||||
|
TypeKind::Borrow(type_kind, false) => {
|
||||||
|
write!(f, "&")?;
|
||||||
|
Display::fmt(type_kind, f)
|
||||||
|
}
|
||||||
|
TypeKind::Borrow(type_kind, true) => {
|
||||||
|
write!(f, "&mut ")?;
|
||||||
|
Display::fmt(type_kind, f)
|
||||||
|
}
|
||||||
|
TypeKind::Ptr(type_kind) => {
|
||||||
|
write!(f, "*")?;
|
||||||
|
Display::fmt(type_kind, f)
|
||||||
|
}
|
||||||
|
TypeKind::Vague(vague_type) => Display::fmt(vague_type, f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for VagueType {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
if f.alternate() {
|
||||||
|
match self {
|
||||||
|
VagueType::Unknown => write!(f, "Unknown"),
|
||||||
|
VagueType::Number => write!(f, "Number"),
|
||||||
|
VagueType::TypeRef(id) => write!(f, "TypeRef({0})", id),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match self {
|
||||||
|
VagueType::Unknown => write!(f, "{{unknown}}"),
|
||||||
|
VagueType::Number => write!(f, "Number"),
|
||||||
|
VagueType::TypeRef(_) => write!(f, "{{unknown}}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -77,53 +77,32 @@ impl TokenRange {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub enum TypeKind {
|
pub enum TypeKind {
|
||||||
#[error("bool")]
|
|
||||||
Bool,
|
Bool,
|
||||||
#[error("i8")]
|
|
||||||
I8,
|
I8,
|
||||||
#[error("i16")]
|
|
||||||
I16,
|
I16,
|
||||||
#[error("i32")]
|
|
||||||
I32,
|
I32,
|
||||||
#[error("i64")]
|
|
||||||
I64,
|
I64,
|
||||||
#[error("i128")]
|
|
||||||
I128,
|
I128,
|
||||||
#[error("u8")]
|
|
||||||
U8,
|
U8,
|
||||||
#[error("u16")]
|
|
||||||
U16,
|
U16,
|
||||||
#[error("u32")]
|
|
||||||
U32,
|
U32,
|
||||||
#[error("u64")]
|
|
||||||
U64,
|
U64,
|
||||||
#[error("u128")]
|
|
||||||
U128,
|
U128,
|
||||||
#[error("void")]
|
|
||||||
Void,
|
Void,
|
||||||
#[error("string")]
|
|
||||||
StringPtr,
|
StringPtr,
|
||||||
#[error("[{0}; {1}]")]
|
|
||||||
Array(Box<TypeKind>, u64),
|
Array(Box<TypeKind>, u64),
|
||||||
#[error("{0}")]
|
|
||||||
CustomType(String),
|
CustomType(String),
|
||||||
#[error("Borrow({0}, {1})")]
|
|
||||||
Borrow(Box<TypeKind>, bool),
|
Borrow(Box<TypeKind>, bool),
|
||||||
#[error("Ptr({0})")]
|
|
||||||
Ptr(Box<TypeKind>),
|
Ptr(Box<TypeKind>),
|
||||||
#[error(transparent)]
|
Vague(VagueType),
|
||||||
Vague(#[from] VagueType),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub enum VagueType {
|
pub enum VagueType {
|
||||||
#[error("Unknown")]
|
|
||||||
Unknown,
|
Unknown,
|
||||||
#[error("Number")]
|
|
||||||
Number,
|
Number,
|
||||||
#[error("TypeRef({0})")]
|
|
||||||
TypeRef(usize),
|
TypeRef(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@ fn changer(param: &mut u32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> u32 {
|
fn main() -> u32 {
|
||||||
let value = 6;
|
let mut value = 6;
|
||||||
|
|
||||||
let mut a = &value;
|
changer(&mut value);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user