@@ -10,8 +10,7 @@ use serde::{Deserialize, Serialize};
10
10
11
11
use crate :: {
12
12
control_statements:: {
13
- AstControlStatement , CaseStatement , ConditionalBlock , ForLoopStatement , IfStatement , LoopStatement ,
14
- ReturnStatement ,
13
+ AstControlStatement , CaseStatement , ForLoopStatement , IfStatement , LoopStatement , ReturnStatement ,
15
14
} ,
16
15
literals:: { AstLiteral , StringValue } ,
17
16
pre_processor,
@@ -50,13 +49,14 @@ pub struct Pou {
50
49
51
50
#[ derive( Debug , PartialEq ) ]
52
51
pub struct Interface {
53
- pub name : String ,
52
+ pub id : AstId ,
53
+ pub identifier : Identifier ,
54
54
pub methods : Vec < Pou > ,
55
55
pub location : SourceLocation ,
56
- pub location_name : SourceLocation ,
56
+ pub extensions : Vec < Identifier > ,
57
57
}
58
58
59
- #[ derive( Debug , PartialEq , Clone ) ]
59
+ #[ derive( Debug , PartialEq , Eq , Clone , Hash ) ]
60
60
pub struct Identifier {
61
61
pub name : String ,
62
62
pub location : SourceLocation ,
@@ -312,6 +312,22 @@ pub enum AccessModifier {
312
312
Internal ,
313
313
}
314
314
315
+ #[ derive( Debug , PartialEq , Eq , Copy , Clone , Hash ) ]
316
+ pub enum DeclarationKind {
317
+ Abstract ,
318
+ Concrete ,
319
+ }
320
+
321
+ impl DeclarationKind {
322
+ pub fn is_abstract ( & self ) -> bool {
323
+ matches ! ( self , DeclarationKind :: Abstract )
324
+ }
325
+
326
+ pub fn is_concrete ( & self ) -> bool {
327
+ matches ! ( self , DeclarationKind :: Concrete )
328
+ }
329
+ }
330
+
315
331
#[ derive( Debug , PartialEq , Eq , Clone , Hash ) ]
316
332
pub enum PouType {
317
333
Program ,
@@ -325,6 +341,8 @@ pub enum PouType {
325
341
326
342
/// The fully qualified name of the property this GET or SET method represents
327
343
property : Option < String > ,
344
+
345
+ declaration_kind : DeclarationKind ,
328
346
} ,
329
347
Init ,
330
348
ProjectInit ,
@@ -1352,7 +1370,7 @@ impl Operator {
1352
1370
1353
1371
#[ cfg( test) ]
1354
1372
mod tests {
1355
- use crate :: ast:: { ArgumentProperty , PouType , VariableBlockType } ;
1373
+ use crate :: ast:: { ArgumentProperty , DeclarationKind , PouType , VariableBlockType } ;
1356
1374
1357
1375
#[ test]
1358
1376
fn display_pou ( ) {
@@ -1361,7 +1379,15 @@ mod tests {
1361
1379
assert_eq ! ( PouType :: FunctionBlock . to_string( ) , "FunctionBlock" ) ;
1362
1380
assert_eq ! ( PouType :: Action . to_string( ) , "Action" ) ;
1363
1381
assert_eq ! ( PouType :: Class . to_string( ) , "Class" ) ;
1364
- assert_eq ! ( PouType :: Method { parent: String :: new( ) , property: None } . to_string( ) , "Method" ) ;
1382
+ assert_eq ! (
1383
+ PouType :: Method {
1384
+ parent: String :: new( ) ,
1385
+ property: None ,
1386
+ declaration_kind: DeclarationKind :: Concrete
1387
+ }
1388
+ . to_string( ) ,
1389
+ "Method"
1390
+ ) ;
1365
1391
}
1366
1392
1367
1393
#[ test]
@@ -1440,107 +1466,28 @@ impl AstFactory {
1440
1466
}
1441
1467
1442
1468
/// creates a new if-statement
1443
- pub fn create_if_statement (
1444
- blocks : Vec < ConditionalBlock > ,
1445
- else_block : Vec < AstNode > ,
1446
- location : SourceLocation ,
1447
- end_location : SourceLocation ,
1448
- id : AstId ,
1449
- ) -> AstNode {
1450
- AstNode {
1451
- stmt : AstStatement :: ControlStatement ( AstControlStatement :: If ( IfStatement {
1452
- blocks,
1453
- else_block,
1454
- end_location,
1455
- } ) ) ,
1456
- location,
1457
- id,
1458
- }
1469
+ pub fn create_if_statement ( stmt : IfStatement , location : SourceLocation , id : AstId ) -> AstNode {
1470
+ AstNode { stmt : AstStatement :: ControlStatement ( AstControlStatement :: If ( stmt) ) , location, id }
1459
1471
}
1460
1472
1461
1473
/// creates a new for loop statement
1462
- #[ allow( clippy:: too_many_arguments) ]
1463
- pub fn create_for_loop (
1464
- counter : AstNode ,
1465
- start : AstNode ,
1466
- end : AstNode ,
1467
- by_step : Option < AstNode > ,
1468
- body : Vec < AstNode > ,
1469
- location : SourceLocation ,
1470
- end_location : SourceLocation ,
1471
- id : AstId ,
1472
- ) -> AstNode {
1473
- AstNode {
1474
- stmt : AstStatement :: ControlStatement ( AstControlStatement :: ForLoop ( ForLoopStatement {
1475
- counter : Box :: new ( counter) ,
1476
- start : Box :: new ( start) ,
1477
- end : Box :: new ( end) ,
1478
- by_step : by_step. map ( Box :: new) ,
1479
- body,
1480
- end_location,
1481
- } ) ) ,
1482
- location,
1483
- id,
1484
- }
1474
+ pub fn create_for_loop ( stmt : ForLoopStatement , location : SourceLocation , id : AstId ) -> AstNode {
1475
+ AstNode { stmt : AstStatement :: ControlStatement ( AstControlStatement :: ForLoop ( stmt) ) , location, id }
1485
1476
}
1486
1477
1487
1478
/// creates a new while statement
1488
- pub fn create_while_statement (
1489
- condition : AstNode ,
1490
- body : Vec < AstNode > ,
1491
- location : SourceLocation ,
1492
- end_location : SourceLocation ,
1493
- id : AstId ,
1494
- ) -> AstNode {
1495
- AstNode {
1496
- stmt : AstStatement :: ControlStatement ( AstControlStatement :: WhileLoop ( LoopStatement {
1497
- condition : Box :: new ( condition) ,
1498
- body,
1499
- end_location,
1500
- } ) ) ,
1501
- id,
1502
- location,
1503
- }
1479
+ pub fn create_while_statement ( stmt : LoopStatement , location : SourceLocation , id : AstId ) -> AstNode {
1480
+ AstNode { stmt : AstStatement :: ControlStatement ( AstControlStatement :: WhileLoop ( stmt) ) , id, location }
1504
1481
}
1505
1482
1506
1483
/// creates a new repeat-statement
1507
- pub fn create_repeat_statement (
1508
- condition : AstNode ,
1509
- body : Vec < AstNode > ,
1510
- location : SourceLocation ,
1511
- end_location : SourceLocation ,
1512
- id : AstId ,
1513
- ) -> AstNode {
1514
- AstNode {
1515
- stmt : AstStatement :: ControlStatement ( AstControlStatement :: RepeatLoop ( LoopStatement {
1516
- condition : Box :: new ( condition) ,
1517
- body,
1518
- end_location,
1519
- } ) ) ,
1520
- id,
1521
- location,
1522
- }
1484
+ pub fn create_repeat_statement ( stmt : LoopStatement , location : SourceLocation , id : AstId ) -> AstNode {
1485
+ AstNode { stmt : AstStatement :: ControlStatement ( AstControlStatement :: RepeatLoop ( stmt) ) , id, location }
1523
1486
}
1524
1487
1525
1488
/// creates a new case-statement
1526
- pub fn create_case_statement (
1527
- selector : AstNode ,
1528
- case_blocks : Vec < ConditionalBlock > ,
1529
- else_block : Vec < AstNode > ,
1530
- location : SourceLocation ,
1531
- end_location : SourceLocation ,
1532
- id : AstId ,
1533
- ) -> AstNode {
1534
- AstNode {
1535
- stmt : AstStatement :: ControlStatement ( AstControlStatement :: Case ( CaseStatement {
1536
- selector : Box :: new ( selector) ,
1537
- case_blocks,
1538
- else_block,
1539
- end_location,
1540
- } ) ) ,
1541
- id,
1542
- location,
1543
- }
1489
+ pub fn create_case_statement ( stmt : CaseStatement , location : SourceLocation , id : AstId ) -> AstNode {
1490
+ AstNode { stmt : AstStatement :: ControlStatement ( AstControlStatement :: Case ( stmt) ) , id, location }
1544
1491
}
1545
1492
1546
1493
/// creates an or-expression
0 commit comments