Skip to content

Commit a0c1033

Browse files
authored
Merge branch 'master' into abroooo/fix_dbg_alignment
2 parents 5fc589a + f5ab238 commit a0c1033

30 files changed

+2644
-531
lines changed

compiler/plc_ast/src/ast.rs

Lines changed: 43 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use serde::{Deserialize, Serialize};
1010

1111
use crate::{
1212
control_statements::{
13-
AstControlStatement, CaseStatement, ConditionalBlock, ForLoopStatement, IfStatement, LoopStatement,
14-
ReturnStatement,
13+
AstControlStatement, CaseStatement, ForLoopStatement, IfStatement, LoopStatement, ReturnStatement,
1514
},
1615
literals::{AstLiteral, StringValue},
1716
pre_processor,
@@ -50,13 +49,14 @@ pub struct Pou {
5049

5150
#[derive(Debug, PartialEq)]
5251
pub struct Interface {
53-
pub name: String,
52+
pub id: AstId,
53+
pub identifier: Identifier,
5454
pub methods: Vec<Pou>,
5555
pub location: SourceLocation,
56-
pub location_name: SourceLocation,
56+
pub extensions: Vec<Identifier>,
5757
}
5858

59-
#[derive(Debug, PartialEq, Clone)]
59+
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
6060
pub struct Identifier {
6161
pub name: String,
6262
pub location: SourceLocation,
@@ -312,6 +312,22 @@ pub enum AccessModifier {
312312
Internal,
313313
}
314314

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+
315331
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
316332
pub enum PouType {
317333
Program,
@@ -325,6 +341,8 @@ pub enum PouType {
325341

326342
/// The fully qualified name of the property this GET or SET method represents
327343
property: Option<String>,
344+
345+
declaration_kind: DeclarationKind,
328346
},
329347
Init,
330348
ProjectInit,
@@ -1352,7 +1370,7 @@ impl Operator {
13521370

13531371
#[cfg(test)]
13541372
mod tests {
1355-
use crate::ast::{ArgumentProperty, PouType, VariableBlockType};
1373+
use crate::ast::{ArgumentProperty, DeclarationKind, PouType, VariableBlockType};
13561374

13571375
#[test]
13581376
fn display_pou() {
@@ -1361,7 +1379,15 @@ mod tests {
13611379
assert_eq!(PouType::FunctionBlock.to_string(), "FunctionBlock");
13621380
assert_eq!(PouType::Action.to_string(), "Action");
13631381
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+
);
13651391
}
13661392

13671393
#[test]
@@ -1440,107 +1466,28 @@ impl AstFactory {
14401466
}
14411467

14421468
/// 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 }
14591471
}
14601472

14611473
/// 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 }
14851476
}
14861477

14871478
/// 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 }
15041481
}
15051482

15061483
/// 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 }
15231486
}
15241487

15251488
/// 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 }
15441491
}
15451492

15461493
/// creates an or-expression

compiler/plc_lowering/src/inheritance.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ mod units_tests {
20952095

20962096
let (_, project) = parse_and_annotate("test", vec![src]).unwrap();
20972097
let unit = &project.units[0].get_unit().units[3];
2098-
assert_debug_snapshot!(unit, @r###"
2098+
assert_debug_snapshot!(unit, @r#"
20992099
POU {
21002100
name: "child.foo",
21012101
variable_blocks: [
@@ -2142,11 +2142,12 @@ mod units_tests {
21422142
pou_type: Method {
21432143
parent: "child",
21442144
property: None,
2145+
declaration_kind: Concrete,
21452146
},
21462147
return_type: None,
21472148
interfaces: [],
21482149
}
2149-
"###);
2150+
"#);
21502151
}
21512152

21522153
#[test]
@@ -2168,14 +2169,15 @@ mod units_tests {
21682169

21692170
let (_, project) = parse_and_annotate("test", vec![src]).unwrap();
21702171
let unit = &project.units[0].get_unit().implementations[1];
2171-
assert_debug_snapshot!(unit, @r###"
2172+
assert_debug_snapshot!(unit, @r#"
21722173
Implementation {
21732174
name: "bar.set0",
21742175
type_name: "bar.set0",
21752176
linkage: Internal,
21762177
pou_type: Method {
21772178
parent: "bar",
21782179
property: None,
2180+
declaration_kind: Concrete,
21792181
},
21802182
statements: [
21812183
Assignment {
@@ -2255,7 +2257,7 @@ mod units_tests {
22552257
Protected,
22562258
),
22572259
}
2258-
"###);
2260+
"#);
22592261
}
22602262
}
22612263

0 commit comments

Comments
 (0)