author | Manuele Conti <conti.ma@alice.it> |
Thu, 03 Jan 2013 23:39:25 +0100 | |
changeset 790 | a722594dcd64 |
parent 382 | ac6dfec701c9 |
child 825 | 6658fc039264 |
permissions | -rwxr-xr-x |
181 | 1 |
/* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
181 | 3 |
* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
4 |
* Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
265
diff
changeset
|
5 |
* Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant |
181 | 6 |
* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
7 |
* This program is free software: you can redistribute it and/or modify |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
8 |
* it under the terms of the GNU General Public License as published by |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
9 |
* the Free Software Foundation, either version 3 of the License, or |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
10 |
* (at your option) any later version. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
11 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
12 |
* This program is distributed in the hope that it will be useful, |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
15 |
* GNU General Public License for more details. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
16 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
19 |
* |
181 | 20 |
* |
21 |
* This code is made available on the understanding that it will not be |
|
22 |
* used in safety-critical situations without a full and competent review. |
|
23 |
*/ |
|
24 |
||
25 |
/* |
|
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
26 |
* An IEC 61131-3 compiler. |
181 | 27 |
* |
28 |
* Based on the |
|
29 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
30 |
* |
|
31 |
*/ |
|
32 |
||
33 |
||
34 |
/* Decomposes a variable instance name into its constituents, |
|
35 |
* example: |
|
36 |
* window.points[1].coordinate.x |
|
37 |
* |
|
38 |
* will succesfully return |
|
39 |
* - window |
|
40 |
* - points |
|
41 |
* - coordinate |
|
42 |
* - x |
|
43 |
* on succesive calls to decompose_var_instance_name_c::next_part() |
|
44 |
*/ |
|
45 |
||
46 |
||
47 |
||
48 |
#include "decompose_var_instance_name.hh" |
|
49 |
||
50 |
decompose_var_instance_name_c::decompose_var_instance_name_c(symbol_c *variable_instance_name) { |
|
51 |
variable_name = variable_instance_name; |
|
52 |
next_variable_name = NULL; |
|
53 |
current_recursive_variable_name = NULL; |
|
54 |
previously_returned_variable_name = NULL; |
|
55 |
} |
|
56 |
||
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
202
diff
changeset
|
57 |
symbol_c *decompose_var_instance_name_c::next_part(bool increment) { |
181 | 58 |
/* We must always start from the top! |
59 |
* See note in the structured_variable_c visitor |
|
60 |
* to understand why... |
|
61 |
*/ |
|
62 |
symbol_c *res = (symbol_c *)variable_name->accept(*this); |
|
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
202
diff
changeset
|
63 |
if (increment) |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
202
diff
changeset
|
64 |
next_variable_name = current_recursive_variable_name; |
181 | 65 |
|
66 |
if (previously_returned_variable_name == res) |
|
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
202
diff
changeset
|
67 |
return NULL; |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
202
diff
changeset
|
68 |
if (increment) |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
202
diff
changeset
|
69 |
previously_returned_variable_name = res; |
181 | 70 |
return res; |
71 |
} |
|
72 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
73 |
/*************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
74 |
/* B.1 - Common elements */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
75 |
/*************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
76 |
/*******************************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
77 |
/* B 1.1 - Letters, digits and identifiers */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
78 |
/*******************************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
79 |
/* sometimes (e.g. FB calls) the name of the variable is stored directly in an identifier_c object */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
80 |
void *decompose_var_instance_name_c::visit(identifier_c *symbol) {return (void *)symbol;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
81 |
|
181 | 82 |
/*********************/ |
83 |
/* B 1.4 - Variables */ |
|
84 |
/*********************/ |
|
85 |
void *decompose_var_instance_name_c::visit(symbolic_variable_c *symbol) {return (void *)(symbol->var_name);} |
|
86 |
||
87 |
/********************************************/ |
|
88 |
/* B.1.4.1 Directly Represented Variables */ |
|
89 |
/********************************************/ |
|
90 |
void *decompose_var_instance_name_c::visit(direct_variable_c *symbol) {return (void *)symbol;} |
|
91 |
||
92 |
/*************************************/ |
|
93 |
/* B.1.4.2 Multi-element Variables */ |
|
94 |
/*************************************/ |
|
95 |
/* subscripted_variable '[' subscript_list ']' */ |
|
96 |
// SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
97 |
void *decompose_var_instance_name_c::visit(array_variable_c *symbol) { |
|
98 |
/* NOTE: the subscripted_variable may itself be a structure!, |
|
99 |
* so we must recursevily visit! |
|
100 |
*/ |
|
101 |
return symbol->subscripted_variable->accept(*this); |
|
102 |
} |
|
103 |
||
104 |
/* record_variable '.' field_selector */ |
|
105 |
/* WARNING: input and/or output variables of function blocks |
|
106 |
* may be accessed as fields of a tructured variable! |
|
107 |
* Code handling a structured_variable_c must take |
|
108 |
* this into account! |
|
109 |
*/ |
|
110 |
//SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
111 |
void *decompose_var_instance_name_c::visit(structured_variable_c *symbol) { |
|
112 |
/* NOTE: The following code will not work, as structured_variable_c |
|
113 |
* are grouped on the left, and not on the right! |
|
114 |
* |
|
115 |
* example: window.origin.x |
|
116 |
* will result in |
|
117 |
* s1 = structured_variable_c("window, "origin"); |
|
118 |
* s2 = structured_variable_c(s1, "x"); |
|
119 |
* AND NOT |
|
120 |
* s1 = structured_variable_c("origin", "x"); |
|
121 |
* s2 = structured_variable_c("window", s1); |
|
122 |
* |
|
123 |
* as the following code assumes!! |
|
124 |
* |
|
125 |
current_variable_name = symbol->field_selector; |
|
126 |
return symbol->record_variable->accept(*this); |
|
127 |
*/ |
|
128 |
||
129 |
/* The correct code, is therefore more complex... */ |
|
130 |
if (next_variable_name == symbol) { |
|
382
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
131 |
return (void *)symbol->field_selector->accept(*this); |
181 | 132 |
} |
133 |
||
134 |
current_recursive_variable_name = symbol; |
|
135 |
return symbol->record_variable->accept(*this); |
|
136 |
} |
|
137 |
||
382
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
138 |
/********************************/ |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
139 |
/* B 2.2 - Operators */ |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
140 |
/********************************/ |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
141 |
void *decompose_var_instance_name_c::visit(LD_operator_c *symbol) {return (void *)&LD_operator_name;} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
142 |
void *decompose_var_instance_name_c::visit(S_operator_c *symbol) {return (void *)&S_operator_name;} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
143 |
void *decompose_var_instance_name_c::visit(R_operator_c *symbol) {return (void *)&R_operator_name;} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
144 |
void *decompose_var_instance_name_c::visit(S1_operator_c *symbol) {return (void *)&S1_operator_name;} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
145 |
void *decompose_var_instance_name_c::visit(R1_operator_c *symbol) {return (void *)&R1_operator_name;} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
146 |
void *decompose_var_instance_name_c::visit(CLK_operator_c *symbol) {return (void *)&CLK_operator_name;} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
147 |
void *decompose_var_instance_name_c::visit(CU_operator_c *symbol) {return (void *)&CU_operator_name;} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
148 |
void *decompose_var_instance_name_c::visit(CD_operator_c *symbol) {return (void *)&CD_operator_name;} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
149 |
void *decompose_var_instance_name_c::visit(PV_operator_c *symbol) {return (void *)&PV_operator_name;} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
150 |
void *decompose_var_instance_name_c::visit(IN_operator_c *symbol) {return (void *)&IN_operator_name;} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
151 |
void *decompose_var_instance_name_c::visit(PT_operator_c *symbol) {return (void *)&PT_operator_name;} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
152 |
|
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
153 |
identifier_c decompose_var_instance_name_c::LD_operator_name("LD"); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
154 |
identifier_c decompose_var_instance_name_c::S_operator_name("S"); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
155 |
identifier_c decompose_var_instance_name_c::R_operator_name("R"); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
156 |
identifier_c decompose_var_instance_name_c::S1_operator_name("S1"); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
157 |
identifier_c decompose_var_instance_name_c::R1_operator_name("R1"); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
158 |
identifier_c decompose_var_instance_name_c::CLK_operator_name("CLK"); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
159 |
identifier_c decompose_var_instance_name_c::CU_operator_name("CU"); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
160 |
identifier_c decompose_var_instance_name_c::CD_operator_name("CD"); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
161 |
identifier_c decompose_var_instance_name_c::PV_operator_name("PV"); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
162 |
identifier_c decompose_var_instance_name_c::IN_operator_name("IN"); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
279
diff
changeset
|
163 |
identifier_c decompose_var_instance_name_c::PT_operator_name("PT"); |
181 | 164 |
|
165 |