@@ -204,6 +204,24 @@ pub ClassDefinition: ast::ClassDefinition = {
204
204
match part {
205
205
ast::CompositionPart::ElementList(list) => {
206
206
for element in list.elements {
207
+ match element {
208
+ ast::Element::ImportClause(import) => {
209
+ def.imports.push(import);
210
+ }
211
+ ast::Element::ExtendsClause(extends) => {
212
+ def.extends.push(extends.type_specifier);
213
+ }
214
+ ast::Element::ClassDefinition(class) => {
215
+ def.classes.insert(class.name.clone(), class);
216
+ }
217
+ ast::Element::ComponentClause(components) => {
218
+ for mut comp in components {
219
+ comp.visibility = list.visibility.clone();
220
+ def.components.insert(comp.name.clone(), comp);
221
+ }
222
+ }
223
+ ast::Element::Empty => {}
224
+ }
207
225
}
208
226
},
209
227
ast::CompositionPart::AlgorithmSection(sec) => {
@@ -423,30 +441,33 @@ pub ElementFlags : ast::ElementFlags = {
423
441
}
424
442
425
443
pub Element : ast::Element = {
426
- <elem: ComponentClause > => ast::Element::ComponentClause(elem),
444
+ <elem: ElementComponentClause > => ast::Element::ComponentClause(elem),
427
445
<elem: ClassDefinition> => ast::Element::ClassDefinition(elem),
428
446
<elem: ExtendsClause> => ast::Element::ExtendsClause(elem),
429
447
}
430
448
431
- pub ElementComponentClause : ast::ComponentClause = {
432
- <left: @L> <flags: ElementFlags> <clause: ComponentClause> <right: @R> => {
433
- let mut res = clause;
434
- res.flags = flags;
435
- res.node_data.span = (left, right);
436
- res
449
+ pub ElementComponentClause : Vec<ast::ComponentDeclaration> = {
450
+ <left: @L> <flags: ElementFlags> <mut components: ComponentClause> <right: @R> => {
451
+ for comp in &mut components {
452
+ comp.flags.replaceable |= flags.replaceable;
453
+ comp.flags.redeclare |= flags.redeclare;
454
+ comp.flags.is_final |= flags.is_final;
455
+ comp.flags.inner |= flags.inner;
456
+ comp.flags.outer |= flags.outer;
457
+ }
458
+ components
437
459
},
438
460
}
439
461
440
462
pub ElementClassDefinition : ast::ClassDefinition = {
441
- <left: @L> <flags: ElementFlags> <def: ClassDefinition> <right: @R> => {
442
- let mut res = def;
443
- res.flags.redeclare = flags.redeclare;
444
- res.flags.is_final = flags.is_final;
445
- res.flags.inner = flags.inner;
446
- res.flags.outer = flags.outer;
447
- res.flags.replaceable = flags.replaceable;
448
- res.node_data.span = (left, right);
449
- res
463
+ <left: @L> <flags: ElementFlags> <mut def: ClassDefinition> <right: @R> => {
464
+ def.flags.redeclare |= flags.redeclare;
465
+ def.flags.is_final |= flags.is_final;
466
+ def.flags.inner |= flags.inner;
467
+ def.flags.outer |= flags.outer;
468
+ def.flags.replaceable |= flags.replaceable;
469
+ def.node_data.span = (left, right);
470
+ def
450
471
},
451
472
}
452
473
@@ -532,22 +553,21 @@ pub ExtendsClause: ast::ExtendsClause = {
532
553
533
554
//✅ component-clause :
534
555
//✅ type-prefix type-specifier [ array-subscripts ] component-list
535
- pub ComponentClause: ast::ComponentClause = {
536
- <left: @L> < type_prefix: TypePrefix>
556
+ pub ComponentClause: Vec< ast::ComponentDeclaration> = {
557
+ <type_prefix: TypePrefix>
537
558
<type_specifier: TypeSpecifier>
538
559
<array_subscripts: ArraySubscripts?>
539
- <components: ComponentList> <right: @R> => {
540
- let id = context.new_id();
541
- ast::ComponentClause {
542
- node_data: NodeData::new(id, left, right),
543
- type_specifier,
544
- flags: ast::ElementFlags::default(),
545
- connection: type_prefix.connection,
546
- variability: type_prefix.variability,
547
- causality: type_prefix.causality,
548
- array_subscripts: array_subscripts.unwrap_or(Vec::new()),
549
- components,
560
+ <mut components: ComponentList> => {
561
+ for comp in &mut components {
562
+ comp.type_specifier = type_specifier.clone();
563
+ comp.causality = type_prefix.causality.clone();
564
+ comp.variability = type_prefix.variability.clone();
565
+ comp.connection = type_prefix.connection.clone();
566
+ if let Some(ref subs) = array_subscripts {
567
+ comp.array_subscripts = subs.clone();
568
+ }
550
569
}
570
+ components
551
571
}
552
572
}
553
573
@@ -602,6 +622,7 @@ pub ComponentDeclaration: ast::ComponentDeclaration = {
602
622
modification: declaration.modification,
603
623
condition_attribute,
604
624
description,
625
+ ..Default::default()
605
626
}
606
627
}
607
628
}
@@ -707,21 +728,16 @@ pub Argument: ast::Argument = {
707
728
708
729
//✅ component-clause1 :
709
730
//✅ type-prefix type-specifier component-declaration1
710
- pub ComponentClause1: ast::ComponentClause = {
711
- <left: @L> < type_prefix: TypePrefix>
731
+ pub ComponentClause1: ast::ComponentDeclaration = {
732
+ <type_prefix: TypePrefix>
712
733
<type_specifier: TypeSpecifier>
713
- <component_declaration1: ComponentDeclaration1> <right: @R> => {
714
- let id = context.new_id();
715
- ast::ComponentClause {
716
- node_data: NodeData::new(id, left, right),
717
- type_specifier,
718
- flags: ast::ElementFlags::default(),
719
- connection: type_prefix.connection,
720
- variability: type_prefix.variability,
721
- causality: type_prefix.causality,
722
- array_subscripts: Vec::new(),
723
- components: vec![component_declaration1],
724
- }
734
+ <component_declaration1: ComponentDeclaration1> => {
735
+ let mut comp = component_declaration1;
736
+ comp.type_specifier = type_specifier;
737
+ comp.causality = type_prefix.causality;
738
+ comp.variability = type_prefix.variability;
739
+ comp.connection = type_prefix.connection;
740
+ comp
725
741
}
726
742
}
727
743
@@ -738,6 +754,7 @@ pub ComponentDeclaration1: ast::ComponentDeclaration = {
738
754
modification: declaration.modification,
739
755
condition_attribute: None,
740
756
description,
757
+ ..Default::default()
741
758
}
742
759
}
743
760
}
0 commit comments