Skip to content

Commit

Permalink
inits/stdlib tests still broken
Browse files Browse the repository at this point in the history
  • Loading branch information
mhasel committed Jan 30, 2025
1 parent 6c7ef81 commit 86c3a0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion compiler/plc_driver/src/pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ impl<T: SourceContainer> BuildPipeline<T> {
let participants: Vec<Box<dyn PipelineParticipant>> = vec![];
let mut_participants: Vec<Box<dyn PipelineParticipantMut>> = vec![
Box::new(InitParticipant::new(&self.project.get_init_symbol_name(), self.context.provider())),
Box::new(AggregateTypeLowerer::new(self.context.provider())),
Box::new(InheritanceLowerer::new(self.context.provider())),
Box::new(AggregateTypeLowerer::new(self.context.provider()))
];

for participant in participants {
Expand Down Expand Up @@ -294,6 +294,8 @@ impl<T: SourceContainer> Pipeline for BuildPipeline<T> {
//TODO : this is post lowering, we might want to control this
if let Some(CompileParameters { output_ast: true, .. }) = self.compile_parameters {
println!("{:#?}", annotated_project.units);
println!("{:#?}", annotated_project.index);
println!("{:#?}", annotated_project.annotations);
return Ok(());
}

Expand Down
12 changes: 10 additions & 2 deletions src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ impl InitVisitor {
fn update_initializer(&mut self, variable: &mut plc_ast::ast::Variable) {
// flat references to stateful pou-local variables need to have a qualifier added, so they can be resolved in the init functions
let scope = self.ctxt.get_scope().as_ref().map(|it| it.as_str()).unwrap_or(GLOBAL_SCOPE);
// steal the original initializer
let initializer = std::mem::take(&mut variable.initializer);
let needs_qualifier = |flat_ref| {
let rhs = self.index.find_member(scope, flat_ref);
let lhs = self.index.find_member(scope, variable.get_name());
Expand Down Expand Up @@ -93,11 +95,13 @@ impl InitVisitor {
})
};

if let Some(initializer) = variable.initializer.as_ref() {

if let Some(initializer) = initializer {
let type_name =
variable.data_type_declaration.get_name().expect("Must have a type at this point");
let data_type = self.index.get_effective_type_or_void_by_name(type_name).get_type_information();
if !data_type.is_pointer() {
variable.initializer = Some(initializer);
return;
}

Expand Down Expand Up @@ -134,7 +138,11 @@ impl InitVisitor {
})
})
}),
_ => return,
_ => {
// nothing to do, add back the original initializer
variable.initializer = Some(initializer);
return
},
};

self.unresolved_initializers.insert_initializer(
Expand Down

0 comments on commit 86c3a0c

Please sign in to comment.