@@ -11,7 +11,7 @@ use std::{
1111 sync:: { Arc , Mutex , RwLock } ,
1212} ;
1313
14- use ast:: provider:: IdProvider ;
14+ use ast:: { provider:: IdProvider , visitor :: AstVisitor } ;
1515use plc:: {
1616 codegen:: GeneratedModule ,
1717 lowering:: {
@@ -21,7 +21,7 @@ use plc::{
2121 ConfigFormat , OnlineChange , Target ,
2222} ;
2323use plc_diagnostics:: diagnostics:: Diagnostic ;
24- use plc_lowering:: inheritance:: InheritanceLowerer ;
24+ use plc_lowering:: { inheritance:: InheritanceLowerer , initializer :: Initializer } ;
2525use project:: { object:: Object , project:: LibraryInformation } ;
2626use source_code:: SourceContainer ;
2727
@@ -224,8 +224,33 @@ impl InitParticipant {
224224}
225225
226226impl PipelineParticipantMut for InitParticipant {
227+ /*
228+
229+ /// Adds additional, internally generated units to provide functions to be called by a runtime
230+ /// in order to initialize pointers before first cycle.
231+ ///
232+ /// This method will consume the provided indexed project, modify the AST and re-index each unit
233+ pub fn extend_with_init_units(
234+ self,
235+ symbol_name: &'static str,
236+ id_provider: IdProvider,
237+ ) -> IndexedProject {
238+ let units = self.project.units;
239+ let lowered =
240+ InitVisitor::visit(units, self.index, self.unresolvables, id_provider.clone(), symbol_name);
241+ ParsedProject { units: lowered }.index(id_provider.clone())
242+ }
243+ */
227244 fn pre_annotate ( & mut self , indexed_project : IndexedProject ) -> IndexedProject {
228- indexed_project. extend_with_init_units ( self . symbol_name , self . id_provider . clone ( ) )
245+ // 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 ( ) , & index) ;
249+ initializer. apply_initialization ( unit) ;
250+ }
251+ // indexed_project.extend_with_init_units(self.symbol_name, self.id_provider.clone())
252+ // Append new units and constructor to the ast and re-index
253+ project. index ( self . id_provider . clone ( ) )
229254 }
230255}
231256
0 commit comments