Skip to content

Commit 69e0783

Browse files
committed
add global constructor and fb_init logic
1 parent 9ab8718 commit 69e0783

File tree

6 files changed

+186
-69
lines changed

6 files changed

+186
-69
lines changed

compiler/plc_ast/src/ast.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,10 @@ impl VariableBlockType {
508508
pub fn is_local(&self) -> bool {
509509
matches!(self, VariableBlockType::Local)
510510
}
511+
512+
pub fn is_global(&self) -> bool {
513+
matches!(self, VariableBlockType::Global)
514+
}
511515
}
512516

513517
impl Display for VariableBlockType {
@@ -682,9 +686,9 @@ impl DataTypeDeclaration {
682686
}
683687
}
684688

685-
pub fn get_referenced_type(&self) -> Option<String> {
689+
pub fn get_referenced_type(&self) -> Option<&str> {
686690
let DataTypeDeclaration::Reference { referenced_type, .. } = self else { return None };
687-
Some(referenced_type.to_owned())
691+
Some(referenced_type.as_str())
688692
}
689693

690694
pub fn get_inner_pointer_ty(&self) -> Option<DataTypeDeclaration> {

compiler/plc_driver/src/pipelines.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use plc::{
2424
index::{indexer, FxIndexSet, Index},
2525
linker::LinkerType,
2626
lowering::{
27-
calls::AggregateTypeLowerer, init_visitor::InitVisitor, polymorphism::PolymorphicCallLowerer,
28-
property::PropertyLowerer, vtable::VirtualTableGenerator,
27+
calls::AggregateTypeLowerer, polymorphism::PolymorphicCallLowerer, property::PropertyLowerer,
28+
vtable::VirtualTableGenerator,
2929
},
3030
output::FormatOption,
3131
parser::parse_file,

compiler/plc_driver/src/pipelines/participant.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,11 @@ impl PipelineParticipantMut for InitParticipant {
243243
*/
244244
fn pre_annotate(&mut self, indexed_project: IndexedProject) -> IndexedProject {
245245
// Create a new init lowerer
246-
let IndexedProject { mut project, index, .. } = indexed_project;
247-
for unit in project.units.iter_mut() {
248-
let mut initializer = Initializer::new(self.id_provider.clone());
249-
initializer.apply_initialization(unit, &index);
250-
}
251-
// indexed_project.extend_with_init_units(self.symbol_name, self.id_provider.clone())
246+
let IndexedProject { project: ParsedProject { units }, index, .. } = indexed_project;
247+
let mut initializer = Initializer::new(self.id_provider.clone());
248+
let units = initializer.apply_initialization(units, index);
252249
// Append new units and constructor to the ast and re-index
250+
let project = ParsedProject { units };
253251
project.index(self.id_provider.clone())
254252
}
255253
}

0 commit comments

Comments
 (0)