File tree 6 files changed +117
-1
lines changed
compiler/plc_xml/src/xml_parser
6 files changed +117
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ impl<'xml> Block<'xml> {
16
16
. collect ( ) ;
17
17
18
18
AstFactory :: create_call_to (
19
- self . type_name . to_string ( ) ,
19
+ self . instance_name . as_ref ( ) . unwrap_or ( & self . type_name ) . to_string ( ) ,
20
20
parameters,
21
21
session. next_id ( ) ,
22
22
session. next_id ( ) ,
Original file line number Diff line number Diff line change @@ -565,10 +565,12 @@ impl AnnotationMapImpl {
565
565
566
566
/// annotates the given statement (using it's `get_id()`) with the given type-name
567
567
pub fn annotate ( & mut self , s : & AstNode , annotation : StatementAnnotation ) {
568
+ log:: trace!( "Annotation: {annotation:?} @ {s:?}" ) ;
568
569
self . type_map . insert ( s. get_id ( ) , annotation) ;
569
570
}
570
571
571
572
pub fn annotate_type_hint ( & mut self , s : & AstNode , annotation : StatementAnnotation ) {
573
+ log:: trace!( "Annotation (type-hint): {annotation:?} @ {s:?}" ) ;
572
574
self . type_hint_map . insert ( s. get_id ( ) , annotation) ;
573
575
}
574
576
Original file line number Diff line number Diff line change @@ -163,6 +163,7 @@ fn connection_sink_source() {
163
163
// THEN the result will have double the value of the initial value
164
164
assert_eq ! ( res, 4 ) ;
165
165
}
166
+
166
167
#[ test]
167
168
fn jump_to_label_with_true ( ) {
168
169
let cfc_file = get_test_file ( "cfc/jump_true.cfc" ) ;
Original file line number Diff line number Diff line change @@ -76,3 +76,29 @@ fn action_variables_annotated() {
76
76
} ;
77
77
assert_debug_snapshot ! ( annotations. get( left) ) ;
78
78
}
79
+
80
+ #[ test]
81
+ fn function_block_calls_are_annotated_correctly ( ) {
82
+ let main = get_test_file ( "cfc/function_block_call_main.cfc" ) ;
83
+ let fb = get_test_file ( "cfc/function_block_call_fb.cfc" ) ;
84
+
85
+ let main = main. load_source ( None ) . unwrap ( ) ;
86
+ let fb = fb. load_source ( None ) . unwrap ( ) ;
87
+
88
+ let annotated_project = parse_and_annotate ( "plc" , vec ! [ main, fb] ) . unwrap ( ) ;
89
+ let annotations = & annotated_project. annotations ;
90
+ let ( unit, ..) = & annotated_project. units [ 0 ] ;
91
+
92
+ let call_annotation = annotations. get ( & unit. implementations [ 0 ] . statements [ 0 ] ) . unwrap ( ) . clone ( ) ;
93
+ assert_debug_snapshot ! ( call_annotation, @r###"
94
+ Variable {
95
+ resulting_type: "myFb",
96
+ qualified_name: "main.fb0",
97
+ constant: false,
98
+ argument_type: ByVal(
99
+ Local,
100
+ ),
101
+ is_auto_deref: false,
102
+ }
103
+ "### ) ;
104
+ }
Original file line number Diff line number Diff line change
1
+ < ? xml version = " 1.0" encoding = " UTF-8" ? >
2
+ < pou xmlns = " http://www.plcopen.org/xml/tc6_0201" name = " myFb" pouType = " functionBlock" >
3
+ < interface >
4
+ < localVars / >
5
+ < addData >
6
+ < data name = " www.bachmann.at/plc/plcopenxml" handleUnknown = " implementation" >
7
+ < textDeclaration >
8
+ < content >
9
+ FUNCTION_BLOCK myFb
10
+ VAR_INPUT
11
+ in1 : DINT ;
12
+ in2 : DINT ;
13
+ END_VAR
14
+
15
+ VAR_OUTPUT
16
+ out1 : DINT ;
17
+ out2 : DINT ;
18
+ out3 : DINT ;
19
+ END_VAR
20
+
21
+ VAR
22
+
23
+ END_VAR
24
+ < / content >
25
+ < / textDeclaration >
26
+ < / data >
27
+ < / addData >
28
+ < / interface >
29
+ < body >
30
+ < FBD / >
31
+ < / body >
32
+ < / pou >
Original file line number Diff line number Diff line change
1
+ < ? xml version = " 1.0" encoding = " UTF-8" ? >
2
+ < pou xmlns = " http://www.plcopen.org/xml/tc6_0201" name = " main" pouType = " program" >
3
+ < interface >
4
+ < localVars / >
5
+ < addData >
6
+ < data name = " www.bachmann.at/plc/plcopenxml" handleUnknown = " implementation" >
7
+ < textDeclaration >
8
+ < content >
9
+ PROGRAM main
10
+ VAR
11
+ fb0 : myFb ;
12
+ END_VAR
13
+ < / content >
14
+ < / textDeclaration >
15
+ < / data >
16
+ < / addData >
17
+ < / interface >
18
+ < body >
19
+ < FBD >
20
+ < block localId = " 4" width = " 137" height = " 80" typeName = " myFb" instanceName = " fb0" executionOrderId = " 0" >
21
+ < position x = " 200" y = " 110" / >
22
+ < inputVariables >
23
+ < variable formalParameter = " in1" negated = " false" >
24
+ < connectionPointIn >
25
+ < relPosition x = " 0" y = " 30" / >
26
+ < / connectionPointIn >
27
+ < / variable >
28
+ < variable formalParameter = " in2" negated = " false" >
29
+ < connectionPointIn >
30
+ < relPosition x = " 0" y = " 50" / >
31
+ < / connectionPointIn >
32
+ < / variable >
33
+ < / inputVariables >
34
+ < inOutVariables / >
35
+ < outputVariables >
36
+ < variable formalParameter = " out1" negated = " false" >
37
+ < connectionPointOut >
38
+ < relPosition x = " 137" y = " 30" / >
39
+ < / connectionPointOut >
40
+ < / variable >
41
+ < variable formalParameter = " out2" negated = " false" >
42
+ < connectionPointOut >
43
+ < relPosition x = " 137" y = " 50" / >
44
+ < / connectionPointOut >
45
+ < / variable >
46
+ < variable formalParameter = " out3" negated = " false" >
47
+ < connectionPointOut >
48
+ < relPosition x = " 137" y = " 70" / >
49
+ < / connectionPointOut >
50
+ < / variable >
51
+ < / outputVariables >
52
+ < / block >
53
+ < / FBD >
54
+ < / body >
55
+ < / pou >
You can’t perform that action at this time.
0 commit comments