Skip to content

Commit 6f3544c

Browse files
committed
Finished basic support for C anonymous enums and naive auto conversion from them to integer types
1 parent 2288ae6 commit 6f3544c

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

Diff for: src/lower/datatype.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ pub fn lower_type(
9494
asg::TypeKind::AnonymousUnion() => {
9595
todo!("lower anonymous union")
9696
}
97-
asg::TypeKind::AnonymousEnum(_) => {
98-
todo!("lower anonymous enum")
99-
}
97+
asg::TypeKind::AnonymousEnum(anonymous_enum) => lower_type(
98+
ir_module,
99+
&ConcreteType(Cow::Borrowed(&anonymous_enum.backing_type)),
100+
asg,
101+
),
100102
asg::TypeKind::FixedArray(fixed_array) => {
101103
let size = fixed_array.size;
102104
let inner = lower_type(

Diff for: src/resolve/conform/from_anonymous_enum.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
use super::{ConformMode, Objective, ObjectiveResult};
22
use crate::{
3-
asg::{AnonymousEnum, Expr, Type, TypeKind},
3+
asg::{self, AnonymousEnum, Cast, CastFrom, Expr, Type, TypeKind, TypedExpr},
44
source_files::Source,
55
};
66

77
pub fn from_anonymous_enum<O: Objective>(
8-
_expr: &Expr,
8+
expr: &Expr,
99
_from_type: &Type,
1010
_mode: ConformMode,
1111
to_type: &Type,
1212
enumeration: &AnonymousEnum,
13-
_source: Source,
13+
source: Source,
1414
) -> ObjectiveResult<O> {
1515
match &to_type.kind {
16-
TypeKind::Integer(_to_bits, _to_sign) => {
16+
TypeKind::Integer(..) | TypeKind::CInteger(..) => {
1717
if !enumeration.allow_implicit_integer_conversions {
1818
return O::fail();
1919
}
2020

21-
todo!("convert from anonymous enum to fixed integer")
22-
}
23-
TypeKind::CInteger(_to_c_integer, _to_sign) => {
24-
if !enumeration.allow_implicit_integer_conversions {
25-
return O::fail();
26-
}
27-
28-
todo!("convert from anonymous enum to flexible integer")
21+
O::success(|| {
22+
TypedExpr::new(
23+
to_type.clone(),
24+
asg::ExprKind::IntegerCast(Box::new(CastFrom {
25+
cast: Cast {
26+
target_type: to_type.clone(),
27+
value: expr.clone(),
28+
},
29+
from_type: enumeration.backing_type.clone(),
30+
}))
31+
.at(source),
32+
)
33+
})
2934
}
3035
_ => O::fail(),
3136
}

0 commit comments

Comments
 (0)