Skip to content

Commit 15331ae

Browse files
committed
fix: Add parent class dependency when resolving methods
1 parent 632e9cf commit 15331ae

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/codegen.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl<'ink> CodeGen<'ink> {
343343
let location = (&unit.file).into();
344344

345345
self.debug.finalize();
346-
log::debug!("{}", self.module.to_string());
346+
log::trace!("{}", self.module.to_string());
347347

348348
#[cfg(feature = "verify")]
349349
{
@@ -382,7 +382,7 @@ impl<'ink> GeneratedModule<'ink> {
382382
.create_module_from_ir(buffer)
383383
.map_err(|it| Diagnostic::new(it.to_string_lossy()).with_error_code("E071"))?;
384384

385-
log::debug!("{}", module.to_string());
385+
log::trace!("{}", module.to_string());
386386

387387
Ok(GeneratedModule { module, location: path.into(), engine: RefCell::new(None) })
388388
}
@@ -391,7 +391,7 @@ impl<'ink> GeneratedModule<'ink> {
391391
self.module
392392
.link_in_module(other.module)
393393
.map_err(|it| Diagnostic::new(it.to_string_lossy()).with_error_code("E071"))?;
394-
log::debug!("Merged: {}", self.module.to_string());
394+
log::trace!("Merged: {}", self.module.to_string());
395395

396396
Ok(self)
397397
}
@@ -570,7 +570,7 @@ impl<'ink> GeneratedModule<'ink> {
570570
/// * `output` - The location to save the generated ir file
571571
pub fn persist_to_ir(&self, output: PathBuf) -> Result<PathBuf, Diagnostic> {
572572
log::debug!("Output location: {}", output.to_string_lossy());
573-
log::debug!("{}", self.persist_to_string());
573+
log::trace!("{}", self.persist_to_string());
574574

575575
self.module
576576
.print_to_file(&output)

src/codegen/generators/data_type_generator.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,28 @@ pub fn generate_data_types<'ink>(
8787
// and associate them in the llvm index
8888
for (name, user_type) in &types {
8989
if let DataTypeInformation::Struct { name: struct_name, .. } = user_type.get_type_information() {
90+
log::debug!("creating struct stub `{name}`");
9091
generator.types_index.associate_type(name, llvm.create_struct_stub(struct_name).into())?;
9192
}
9293
}
9394
// pou_types will always be struct
9495
for (name, user_type) in &pou_types {
9596
if let DataTypeInformation::Struct { name: struct_name, .. } = user_type.get_type_information() {
97+
log::debug!("creating POU stub `{name}`");
9698
generator.types_index.associate_pou_type(name, llvm.create_struct_stub(struct_name).into())?;
9799
}
98100
}
99101

100102
// now create all other types (enum's, arrays, etc.)
101103
for (name, user_type) in &types {
104+
log::debug!("creating type `{name}`");
102105
let gen_type = generator.create_type(name, user_type)?;
103106
generator.types_index.associate_type(name, gen_type)?
104107
//Get and associate debug type
105108
}
106109

107110
for (name, user_type) in &pou_types {
111+
log::debug!("creating type `{name}`");
108112
let gen_type = generator.create_type(name, user_type)?;
109113
generator.types_index.associate_pou_type(name, gen_type)?
110114
}
@@ -114,8 +118,9 @@ pub fn generate_data_types<'ink>(
114118
types_to_init.extend(types);
115119
types_to_init.extend(pou_types);
116120
// now since all types should be available in the llvm index, we can think about constructing and associating
117-
for (_, user_type) in &types_to_init {
121+
for (name, user_type) in &types_to_init {
118122
//Expand all types
123+
log::debug!("expanding type `{name}`");
119124
generator.expand_opaque_types(user_type)?;
120125
}
121126

@@ -206,7 +211,7 @@ impl<'ink> DataTypeGenerator<'ink, '_> {
206211

207212
parameter_types.extend(declared_params);
208213

209-
let fn_type = match dbg!(return_type) {
214+
let fn_type = match return_type {
210215
AnyTypeEnum::IntType(value) => value.fn_type(parameter_types.as_slice(), false),
211216
AnyTypeEnum::VoidType(value) => value.fn_type(parameter_types.as_slice(), false),
212217
_ => unimplemented!(),

src/resolver.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use plc_ast::{
1212
ast::{
1313
self, flatten_expression_list, Allocation, Assignment, AstFactory, AstId, AstNode, AstStatement,
1414
BinaryExpression, CompilationUnit, DataType, DataTypeDeclaration, DirectAccessType, Identifier,
15-
Interface, JumpStatement, Operator, Pou, ReferenceAccess, ReferenceExpr, TypeNature,
15+
Interface, JumpStatement, Operator, Pou, PouType, ReferenceAccess, ReferenceExpr, TypeNature,
1616
UserTypeDeclaration, Variable,
1717
},
1818
control_statements::{AstControlStatement, ReturnStatement},
@@ -1547,15 +1547,22 @@ impl<'i> TypeAnnotator<'i> {
15471547
};
15481548
if resolved_names.insert(Dependency::Datatype(datatype.get_name().to_string())) {
15491549
match datatype.get_type_information() {
1550-
DataTypeInformation::Struct { members, .. } => {
1550+
DataTypeInformation::Struct { members, source, .. } => {
15511551
for member in members {
15521552
resolved_names =
15531553
self.get_datatype_dependencies(member.get_type_name(), resolved_names);
15541554
}
1555+
1556+
if let StructSource::Pou(PouType::Method { parent, .. }) = source {
1557+
resolved_names = self.get_datatype_dependencies(parent, resolved_names);
1558+
}
1559+
15551560
resolved_names
15561561
}
15571562
DataTypeInformation::Array { inner_type_name, .. }
15581563
| DataTypeInformation::Pointer { inner_type_name, .. } => {
1564+
resolved_names
1565+
.insert(Dependency::Datatype(datatype.get_type_information().get_name().to_string()));
15591566
self.get_datatype_dependencies(inner_type_name, resolved_names)
15601567
}
15611568
_ => {

0 commit comments

Comments
 (0)