-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnested_control_test.bcsctrl
More file actions
116 lines (108 loc) · 3.84 KB
/
Copy pathnested_control_test.bcsctrl
File metadata and controls
116 lines (108 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// A test file for nested control structures code generation
control NestedControlTestController {
enum ProcessState {
INIT,
PROCESSING,
FINALIZING,
COMPLETE
}
functionblock NestedControlsFB {
inputs {
var iState: ProcessState;
var iCount: INT;
var iThreshold: REAL;
var iValues: REAL[10];
}
outputs {
var oResult: REAL;
var oStatus: STRING;
var oProcessedItems: INT;
}
locals {
var i: INT;
var tempSum: REAL = 0.0;
var itemsProcessed: INT = 0;
var skipCount: INT = 0;
}
logic {
// Reset variables
tempSum = 0.0;
itemsProcessed = 0;
skipCount = 0;
// Complex nested control structures
if (iState == ProcessState.INIT || iState == ProcessState.PROCESSING) {
// Process the array using nested loops and conditions
for (var i : INT = 0 to 9 by 1) {
// Skip processing if value is below threshold
if (iValues[i] < iThreshold) {
skipCount = skipCount + 1;
continue;
}
// Different processing based on state
switch (iState) {
case ProcessState.INIT {
// Initialization processing
tempSum = tempSum + iValues[i] * 0.8;
}
case ProcessState.PROCESSING {
// Normal processing - with nested if
if (iValues[i] > iThreshold * 2.0) {
tempSum = tempSum + iValues[i] * 1.5;
} else {
tempSum = tempSum + iValues[i];
}
}
default {
// Should not happen, but handle anyway
tempSum = tempSum + iValues[i] * 0.5;
}
}
itemsProcessed = itemsProcessed + 1;
}
} else if (iState == ProcessState.FINALIZING) {
// Final processing
tempSum = 0.0;
i = 0;
while (i < iCount && i < 10) {
tempSum = tempSum + iValues[i] * 1.2;
i = i + 1;
}
itemsProcessed = i;
} else {
// Complete state
tempSum = -1.0;
itemsProcessed = 0;
}
// Set outputs
oResult = tempSum;
oProcessedItems = itemsProcessed;
// Set status message based on processed items
if (itemsProcessed == 0) {
oStatus = "No items processed";
} else if (skipCount > 0) {
oStatus = "Processed with skips";
} else {
oStatus = "All items processed";
}
}
}
unit TestNestedControls {
var state: ProcessState = ProcessState.PROCESSING;
var count: INT = 5;
var threshold: REAL = 10.0;
var values: REAL[10] = [5.0, 15.0, 25.0, 7.5, 30.0, 0.0, 0.0, 0.0, 0.0, 0.0];
var result: REAL;
var status: STRING;
var processedItems: INT;
use NestedControlsFB(
iState: state,
iCount: count,
iThreshold: threshold,
iValues: values
) -> {
oResult: result,
oStatus: status,
oProcessedItems: processedItems
};
}
}