@@ -42,9 +42,13 @@ pub struct Pou {
42
42
pub generics : Vec < GenericBinding > ,
43
43
pub linkage : LinkageType ,
44
44
pub super_class : Option < Identifier > ,
45
+ pub is_const : bool ,
46
+
45
47
/// A list of interfaces this POU implements
46
48
pub interfaces : Vec < Identifier > ,
47
- pub is_const : bool ,
49
+
50
+ /// A list of properties this POU contains
51
+ pub properties : Vec < PropertyBlock > ,
48
52
}
49
53
50
54
#[ derive( Debug , PartialEq ) ]
@@ -62,17 +66,15 @@ pub struct Identifier {
62
66
pub location : SourceLocation ,
63
67
}
64
68
69
+ /// The property container as a whole, which contains [`PropertyImplementation`]s
65
70
#[ derive( Debug , PartialEq , Clone ) ]
66
- pub struct Property {
67
- pub name : String ,
68
- pub name_location : SourceLocation ,
69
- pub parent_kind : PouType ,
70
- pub parent_name : String ,
71
- pub parent_name_location : SourceLocation ,
72
- pub datatype : DataTypeDeclaration ,
71
+ pub struct PropertyBlock {
72
+ pub name : Identifier ,
73
+ pub return_type : DataTypeDeclaration ,
73
74
pub implementations : Vec < PropertyImplementation > ,
74
75
}
75
76
77
+ /// The declaration and implementation of a properties accessor (GET or SET)
76
78
#[ derive( Debug , PartialEq , Clone ) ]
77
79
pub struct PropertyImplementation {
78
80
pub kind : PropertyKind ,
@@ -88,6 +90,18 @@ pub enum PropertyKind {
88
90
Set ,
89
91
}
90
92
93
+ impl From < & PropertyBlock > for Variable {
94
+ fn from ( value : & PropertyBlock ) -> Self {
95
+ Variable {
96
+ name : value. name . name . clone ( ) ,
97
+ data_type_declaration : value. return_type . clone ( ) ,
98
+ initializer : None ,
99
+ address : None ,
100
+ location : value. name . location . clone ( ) ,
101
+ }
102
+ }
103
+ }
104
+
91
105
impl std:: fmt:: Display for PropertyKind {
92
106
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
93
107
match self {
@@ -339,9 +353,6 @@ pub enum PouType {
339
353
/// The parent of this method, i.e. a function block, class or an interface
340
354
parent : String ,
341
355
342
- /// The fully qualified name of the property this GET or SET method represents
343
- property : Option < String > ,
344
-
345
356
declaration_kind : DeclarationKind ,
346
357
} ,
347
358
Init ,
@@ -412,7 +423,6 @@ pub struct CompilationUnit {
412
423
pub interfaces : Vec < Interface > ,
413
424
pub user_types : Vec < UserTypeDeclaration > ,
414
425
pub file : FileMarker ,
415
- pub properties : Vec < Property > ,
416
426
}
417
427
418
428
impl CompilationUnit {
@@ -425,7 +435,6 @@ impl CompilationUnit {
425
435
interfaces : Vec :: new ( ) ,
426
436
user_types : Vec :: new ( ) ,
427
437
file : FileMarker :: File ( file_name) ,
428
- properties : Vec :: new ( ) ,
429
438
}
430
439
}
431
440
@@ -457,9 +466,6 @@ pub enum VariableBlockType {
457
466
Global ,
458
467
InOut ,
459
468
External ,
460
-
461
- /// A compiler internal variable block representing all properties defined within a stateful POU
462
- Property ,
463
469
}
464
470
465
471
impl Display for VariableBlockType {
@@ -472,7 +478,6 @@ impl Display for VariableBlockType {
472
478
VariableBlockType :: Global => write ! ( f, "Global" ) ,
473
479
VariableBlockType :: InOut => write ! ( f, "InOut" ) ,
474
480
VariableBlockType :: External => write ! ( f, "External" ) ,
475
- VariableBlockType :: Property => write ! ( f, "Property" ) ,
476
481
}
477
482
}
478
483
}
@@ -504,19 +509,6 @@ impl VariableBlock {
504
509
self . variables = variables;
505
510
self
506
511
}
507
-
508
- /// Creates a new (internal) variable block with a block type of [`Property`]
509
- pub fn property ( variables : Vec < Variable > ) -> VariableBlock {
510
- VariableBlock {
511
- access : AccessModifier :: Internal ,
512
- constant : false ,
513
- retain : false ,
514
- variables,
515
- variable_block_type : VariableBlockType :: Property ,
516
- linkage : LinkageType :: Internal ,
517
- location : SourceLocation :: internal ( ) ,
518
- }
519
- }
520
512
}
521
513
522
514
impl Default for VariableBlock {
@@ -1147,6 +1139,13 @@ impl AstNode {
1147
1139
matches ! ( self . stmt, AstStatement :: ReferenceExpr ( ..) )
1148
1140
}
1149
1141
1142
+ pub fn is_member_access ( & self ) -> bool {
1143
+ matches ! (
1144
+ self . stmt,
1145
+ AstStatement :: ReferenceExpr ( ReferenceExpr { access: ReferenceAccess :: Member ( ..) , .. } , ..)
1146
+ )
1147
+ }
1148
+
1150
1149
pub fn is_call ( & self ) -> bool {
1151
1150
matches ! ( self . stmt, AstStatement :: CallStatement ( ..) )
1152
1151
}
@@ -1380,12 +1379,8 @@ mod tests {
1380
1379
assert_eq ! ( PouType :: Action . to_string( ) , "Action" ) ;
1381
1380
assert_eq ! ( PouType :: Class . to_string( ) , "Class" ) ;
1382
1381
assert_eq ! (
1383
- PouType :: Method {
1384
- parent: String :: new( ) ,
1385
- property: None ,
1386
- declaration_kind: DeclarationKind :: Concrete
1387
- }
1388
- . to_string( ) ,
1382
+ PouType :: Method { parent: String :: new( ) , declaration_kind: DeclarationKind :: Concrete }
1383
+ . to_string( ) ,
1389
1384
"Method"
1390
1385
) ;
1391
1386
}
0 commit comments