Get structs in arrays working, but no luck with arrays in structs
This commit is contained in:
parent
f952651a66
commit
e4845c4084
@ -1024,7 +1024,11 @@ impl TypeKind {
|
|||||||
size_bits: self.size_of(),
|
size_bits: self.size_of(),
|
||||||
}),
|
}),
|
||||||
TypeKind::Array(type_kind, len) => {
|
TypeKind::Array(type_kind, len) => {
|
||||||
let elem_ty = type_kind.get_debug_type_hard(
|
let elem_ty = match **type_kind {
|
||||||
|
TypeKind::CustomType(_) => TypeKind::Ptr(Box::new(*type_kind.clone())),
|
||||||
|
_ => *type_kind.clone(),
|
||||||
|
};
|
||||||
|
let elem_ty = elem_ty.clone().get_debug_type_hard(
|
||||||
scope,
|
scope,
|
||||||
debug_info,
|
debug_info,
|
||||||
debug_types,
|
debug_types,
|
||||||
@ -1033,8 +1037,8 @@ impl TypeKind {
|
|||||||
tokens,
|
tokens,
|
||||||
);
|
);
|
||||||
DebugTypeData::Array(DebugArrayType {
|
DebugTypeData::Array(DebugArrayType {
|
||||||
size_bits: type_kind.size_of() * len,
|
size_bits: self.size_of(),
|
||||||
align_bits: type_kind.alignment(),
|
align_bits: self.alignment(),
|
||||||
element_type: elem_ty,
|
element_type: elem_ty,
|
||||||
length: *len,
|
length: *len,
|
||||||
})
|
})
|
||||||
@ -1047,13 +1051,17 @@ impl TypeKind {
|
|||||||
let mut fields = Vec::new();
|
let mut fields = Vec::new();
|
||||||
let mut size_bits = 0;
|
let mut size_bits = 0;
|
||||||
for field in &struct_type.0 {
|
for field in &struct_type.0 {
|
||||||
|
let ty = match &field.1 {
|
||||||
|
TypeKind::Array(elem_ty, len) => field.1.clone(),
|
||||||
|
_ => field.1.clone(),
|
||||||
|
};
|
||||||
fields.push(DebugFieldType {
|
fields.push(DebugFieldType {
|
||||||
name: field.0.clone(),
|
name: field.0.clone(),
|
||||||
location: field.2.into_debug(tokens).unwrap(),
|
location: field.2.into_debug(tokens).unwrap(),
|
||||||
size_bits: field.1.size_of(),
|
size_bits: ty.size_of(),
|
||||||
offset: size_bits,
|
offset: size_bits,
|
||||||
flags: DwarfFlags,
|
flags: DwarfFlags,
|
||||||
ty: field.1.get_debug_type_hard(
|
ty: ty.get_debug_type_hard(
|
||||||
scope,
|
scope,
|
||||||
debug_info,
|
debug_info,
|
||||||
debug_types,
|
debug_types,
|
||||||
|
@ -47,7 +47,7 @@ impl TypeKind {
|
|||||||
TypeKind::StringPtr => 32,
|
TypeKind::StringPtr => 32,
|
||||||
TypeKind::Array(type_kind, len) => type_kind.size_of() * len,
|
TypeKind::Array(type_kind, len) => type_kind.size_of() * len,
|
||||||
TypeKind::CustomType(_) => 32,
|
TypeKind::CustomType(_) => 32,
|
||||||
TypeKind::Ptr(inner) => 32,
|
TypeKind::Ptr(inner) => 64,
|
||||||
TypeKind::Vague(_) => panic!("Tried to sizeof a vague type!"),
|
TypeKind::Vague(_) => panic!("Tried to sizeof a vague type!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ impl TypeKind {
|
|||||||
TypeKind::StringPtr => 32,
|
TypeKind::StringPtr => 32,
|
||||||
TypeKind::Array(type_kind, _) => type_kind.alignment(),
|
TypeKind::Array(type_kind, _) => type_kind.alignment(),
|
||||||
TypeKind::CustomType(_) => 32,
|
TypeKind::CustomType(_) => 32,
|
||||||
TypeKind::Ptr(type_kind) => 32,
|
TypeKind::Ptr(type_kind) => 64,
|
||||||
TypeKind::Vague(_) => panic!("Tried to sizeof a vague type!"),
|
TypeKind::Vague(_) => panic!("Tried to sizeof a vague type!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,21 @@
|
|||||||
// Arithmetic, function calls and imports!
|
// Arithmetic, function calls and imports!
|
||||||
|
|
||||||
struct Test {
|
struct Test {
|
||||||
field : i32, second : [u32; 4]
|
field: i32,
|
||||||
|
second: [u32; 4]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test() -> [Test; 1] {
|
fn test() -> [Test; 1] {
|
||||||
let value = [Test {
|
let value = [Test {
|
||||||
field: 5,
|
field: 5,
|
||||||
second: [6, 3, 4, 8],
|
second: [6, 3, 4, 8],
|
||||||
}];
|
}];
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> u32 {
|
fn main() -> u32 {
|
||||||
let mut value = test();
|
let mut value = test();
|
||||||
|
|
||||||
let val1 = 0;
|
|
||||||
let val2 = 1;
|
|
||||||
|
|
||||||
// value[val1].second[val2 + 1] = 99;
|
return value[0].second[2];
|
||||||
|
|
||||||
let mut b = value[val1];
|
|
||||||
b.second[2] = 99;
|
|
||||||
|
|
||||||
return value[val1].second[2];
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user