author | Edouard Tisserant |
Wed, 19 Feb 2014 22:27:11 +0100 | |
changeset 870 | 9c6c588fd708 |
parent 854 | 13d0b67de111 |
child 939 | 5074236fb3c4 |
permissions | -rw-r--r-- |
181 | 1 |
/* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
3 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
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 |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
6 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
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:
226
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:
226
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:
226
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:
226
diff
changeset
|
11 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
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:
226
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:
226
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:
226
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:
226
diff
changeset
|
16 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
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:
226
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:
226
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:
226
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 |
||
504
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
33 |
/* Search in a VAR* END_VAR declaration for the delcration of the specified variable instance. |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
34 |
* Will return: |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
35 |
* - the declaration itself (get_decl() ) |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
36 |
* - the type of declaration in which the variable was declared (get_vartype() ) |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
37 |
* |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
38 |
* The variable instance may NOT be a member of a structure of a memeber |
181 | 39 |
* of a structure of an element of an array of ... |
40 |
* |
|
504
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
41 |
* For example, considering the following 'variables': |
181 | 42 |
* window.points[1].coordinate.x |
43 |
* window.points[1].colour |
|
504
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
44 |
* offset[99] |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
45 |
* |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
46 |
* passing a reference to 'points', 'points[1]', 'points[1].colour', 'colour' |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
47 |
* ARE NOT ALLOWED! |
181 | 48 |
* |
49 |
* This class must only be passed the name of the variable that will appear |
|
50 |
* in the variable declaration. In the above examples, this would be |
|
504
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
51 |
* 'window.points[1].coordinate.x' |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
52 |
* 'window.points[1].coordinate' |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
53 |
* 'window.points[1]' |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
54 |
* 'window' |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
55 |
* 'window.points[1].colour' |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
56 |
* 'offset' |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
57 |
* 'offset[99]' |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
58 |
* |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
59 |
* |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
60 |
*/ |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
61 |
|
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
62 |
/* Note: |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
63 |
* Determining the declaration type of a specific variable instance (including |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
64 |
* function block instances) really means determining whether the variable was declared in a |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
65 |
* VAR_INPUT |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
66 |
* VAR_OUTPUT |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
67 |
* VAR_IN_OUT |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
68 |
* VAR |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
69 |
* VAR_TEMP |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
70 |
* VAR_EXTERNAL |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
71 |
* VAR_GLOBAL |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
72 |
* VAR <var_name> AT <location> -> Located variable! |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
73 |
* |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
74 |
*/ |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
75 |
|
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
76 |
/* Note: |
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
77 |
* The current_type_decl that this class returns may reference the |
181 | 78 |
* name of a type, or the type declaration itself! |
79 |
* For an example of the first, consider a variable declared as ... |
|
80 |
* x : AAA; |
|
81 |
* where the AAA type is previously declared as whatever. |
|
82 |
* For an example of the second, consider a variable declared as ... |
|
83 |
* x : array of int [10]; ----> is allowed |
|
84 |
* |
|
85 |
* If it is the first, we will return a reference to the name, if the second |
|
86 |
* we return a reference to the declaration!! |
|
87 |
*/ |
|
504
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
88 |
|
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
89 |
|
181 | 90 |
#include "absyntax_utils.hh" |
91 |
||
92 |
||
504
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
93 |
|
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
94 |
|
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
95 |
|
181 | 96 |
search_var_instance_decl_c::search_var_instance_decl_c(symbol_c *search_scope) { |
97 |
this->current_vartype = none_vt; |
|
98 |
this->search_scope = search_scope; |
|
99 |
this->search_name = NULL; |
|
100 |
this->current_type_decl = NULL; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
101 |
this->current_option = none_opt; |
181 | 102 |
} |
103 |
||
504
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
104 |
symbol_c *search_var_instance_decl_c::get_decl(symbol_c *variable) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
105 |
this->current_vartype = none_vt; |
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
106 |
this->current_option = none_opt; |
504
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
107 |
this->search_name = get_var_name_c::get_name(variable); |
812
6679b6b21214
Partial fix to VAR_EXTERN vs VAR_GLOBAL check. Now considers globals declared in resources too. TODO: recursively check FB declared in the program.
Mario de Sousa <msousa@fe.up.pt>
parents:
810
diff
changeset
|
108 |
if (NULL == search_scope) return NULL; // NOTE: This is not an ERROR! declaration_check_c, for e.g., relies on this returning NULL! |
181 | 109 |
return (symbol_c *)search_scope->accept(*this); |
110 |
} |
|
111 |
||
536
563b013ec670
Change constants into enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
531
diff
changeset
|
112 |
search_var_instance_decl_c::vt_t search_var_instance_decl_c::get_vartype(symbol_c *variable) { |
417
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
113 |
this->current_vartype = none_vt; |
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
114 |
this->current_option = none_opt; |
504
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
115 |
this->search_name = get_var_name_c::get_name(variable); |
812
6679b6b21214
Partial fix to VAR_EXTERN vs VAR_GLOBAL check. Now considers globals declared in resources too. TODO: recursively check FB declared in the program.
Mario de Sousa <msousa@fe.up.pt>
parents:
810
diff
changeset
|
116 |
if (NULL == search_scope) ERROR; |
417
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
117 |
search_scope->accept(*this); |
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
118 |
return this->current_vartype; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
119 |
} |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
120 |
|
536
563b013ec670
Change constants into enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
531
diff
changeset
|
121 |
search_var_instance_decl_c::opt_t search_var_instance_decl_c::get_option(symbol_c *variable) { |
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
122 |
this->current_vartype = none_vt; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
123 |
this->current_option = none_opt; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
124 |
this->search_name = get_var_name_c::get_name(variable); |
812
6679b6b21214
Partial fix to VAR_EXTERN vs VAR_GLOBAL check. Now considers globals declared in resources too. TODO: recursively check FB declared in the program.
Mario de Sousa <msousa@fe.up.pt>
parents:
810
diff
changeset
|
125 |
if (NULL == search_scope) ERROR; |
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
126 |
search_scope->accept(*this); |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
127 |
return this->current_option; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
128 |
} |
417
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
129 |
|
531
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
511
diff
changeset
|
130 |
|
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
511
diff
changeset
|
131 |
|
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
511
diff
changeset
|
132 |
|
181 | 133 |
/***************************/ |
134 |
/* B 0 - Programming Model */ |
|
135 |
/***************************/ |
|
136 |
void *search_var_instance_decl_c::visit(library_c *symbol) { |
|
137 |
/* we do not want to search multiple declaration scopes, |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
138 |
* so we do not visit all the functions, function blocks, etc... |
181 | 139 |
*/ |
140 |
return NULL; |
|
141 |
} |
|
142 |
||
143 |
||
144 |
||
145 |
/******************************************/ |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
146 |
/* B 1.4.3 - Declaration & Initialization */ |
181 | 147 |
/******************************************/ |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
148 |
|
181 | 149 |
/* edge -> The F_EDGE or R_EDGE directive */ |
150 |
// SYM_REF2(edge_declaration_c, edge, var1_list) |
|
151 |
// TODO |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
152 |
void *search_var_instance_decl_c::visit(constant_option_c *symbol) { |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
153 |
current_option = constant_opt; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
154 |
return NULL; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
155 |
} |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
156 |
|
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
157 |
void *search_var_instance_decl_c::visit(retain_option_c *symbol) { |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
158 |
current_option = retain_opt; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
159 |
return NULL; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
160 |
} |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
161 |
|
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
162 |
void *search_var_instance_decl_c::visit(non_retain_option_c *symbol) { |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
163 |
current_option = non_retain_opt; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
164 |
return NULL; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
165 |
} |
181 | 166 |
|
167 |
void *search_var_instance_decl_c::visit(input_declarations_c *symbol) { |
|
168 |
current_vartype = input_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
169 |
current_option = none_opt; /* not really required. Just to make the code more readable */ |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
170 |
if (NULL != symbol->option) |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
171 |
symbol->option->accept(*this); |
181 | 172 |
void *res = symbol->input_declaration_list->accept(*this); |
173 |
if (res == NULL) { |
|
174 |
current_vartype = none_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
175 |
current_option = none_opt; |
181 | 176 |
} |
177 |
return res; |
|
178 |
} |
|
179 |
||
180 |
/* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */ |
|
181 |
/* option -> may be NULL ! */ |
|
182 |
void *search_var_instance_decl_c::visit(output_declarations_c *symbol) { |
|
183 |
current_vartype = output_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
184 |
current_option = none_opt; /* not really required. Just to make the code more readable */ |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
185 |
if (NULL != symbol->option) |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
186 |
symbol->option->accept(*this); |
181 | 187 |
void *res = symbol->var_init_decl_list->accept(*this); |
188 |
if (res == NULL) { |
|
189 |
current_vartype = none_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
190 |
current_option = none_opt; |
181 | 191 |
} |
192 |
return res; |
|
193 |
} |
|
194 |
||
195 |
/* VAR_IN_OUT var_declaration_list END_VAR */ |
|
196 |
void *search_var_instance_decl_c::visit(input_output_declarations_c *symbol) { |
|
197 |
current_vartype = inoutput_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
198 |
current_option = none_opt; /* not really required. Just to make the code more readable */ |
181 | 199 |
void *res = symbol->var_declaration_list->accept(*this); |
200 |
if (res == NULL) { |
|
201 |
current_vartype = none_vt; |
|
202 |
} |
|
203 |
return res; |
|
204 |
} |
|
205 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
206 |
/* ENO : BOOL */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
207 |
void *search_var_instance_decl_c::visit(eno_param_declaration_c *symbol) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
208 |
if (compare_identifiers(symbol->name, search_name) == 0) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
209 |
return symbol->type; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
210 |
return NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
211 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
212 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
213 |
|
181 | 214 |
/* VAR [CONSTANT] var_init_decl_list END_VAR */ |
215 |
/* option -> may be NULL ! */ |
|
216 |
/* helper symbol for input_declarations */ |
|
217 |
void *search_var_instance_decl_c::visit(var_declarations_c *symbol) { |
|
218 |
current_vartype = private_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
219 |
current_option = none_opt; /* not really required. Just to make the code more readable */ |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
220 |
if (NULL != symbol->option) |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
221 |
symbol->option->accept(*this); |
181 | 222 |
void *res = symbol->var_init_decl_list->accept(*this); |
223 |
if (res == NULL) { |
|
224 |
current_vartype = none_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
225 |
current_option = none_opt; |
181 | 226 |
} |
227 |
return res; |
|
228 |
} |
|
229 |
||
230 |
/* VAR RETAIN var_init_decl_list END_VAR */ |
|
231 |
void *search_var_instance_decl_c::visit(retentive_var_declarations_c *symbol) { |
|
232 |
current_vartype = private_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
233 |
current_option = retain_opt; |
181 | 234 |
void *res = symbol->var_init_decl_list->accept(*this); |
235 |
if (res == NULL) { |
|
236 |
current_vartype = none_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
237 |
current_option = none_opt; |
181 | 238 |
} |
239 |
return res; |
|
240 |
} |
|
241 |
||
242 |
/* VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */ |
|
243 |
/* option -> may be NULL ! */ |
|
244 |
//SYM_REF2(located_var_declarations_c, option, located_var_decl_list) |
|
245 |
void *search_var_instance_decl_c::visit(located_var_declarations_c *symbol) { |
|
246 |
current_vartype = located_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
247 |
current_option = none_opt; /* not really required. Just to make the code more readable */ |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
248 |
if (NULL != symbol->option) |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
249 |
symbol->option->accept(*this); |
181 | 250 |
void *res = symbol->located_var_decl_list->accept(*this); |
251 |
if (res == NULL) { |
|
252 |
current_vartype = none_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
253 |
current_option = none_opt; |
181 | 254 |
} |
255 |
return res; |
|
256 |
} |
|
257 |
||
258 |
/*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ |
|
259 |
/* option -> may be NULL ! */ |
|
260 |
//SYM_REF2(external_var_declarations_c, option, external_declaration_list) |
|
261 |
void *search_var_instance_decl_c::visit(external_var_declarations_c *symbol) { |
|
262 |
current_vartype = external_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
263 |
current_option = none_opt; /* not really required. Just to make the code more readable */ |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
264 |
if (NULL != symbol->option) |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
265 |
symbol->option->accept(*this); |
181 | 266 |
void *res = symbol->external_declaration_list->accept(*this); |
267 |
if (res == NULL) { |
|
268 |
current_vartype = none_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
269 |
current_option = none_opt; |
181 | 270 |
} |
271 |
return res; |
|
272 |
} |
|
273 |
||
274 |
/*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ |
|
275 |
/* option -> may be NULL ! */ |
|
276 |
//SYM_REF2(global_var_declarations_c, option, global_var_decl_list) |
|
277 |
void *search_var_instance_decl_c::visit(global_var_declarations_c *symbol) { |
|
278 |
current_vartype = global_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
279 |
current_option = none_opt; /* not really required. Just to make the code more readable */ |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
280 |
if (NULL != symbol->option) |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
281 |
symbol->option->accept(*this); |
181 | 282 |
void *res = symbol->global_var_decl_list->accept(*this); |
283 |
if (res == NULL) { |
|
284 |
current_vartype = none_vt; |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
285 |
current_option = none_opt; |
181 | 286 |
} |
287 |
return res; |
|
288 |
} |
|
289 |
||
290 |
/* var1_list is one of the following... |
|
291 |
* simple_spec_init_c * |
|
292 |
* subrange_spec_init_c * |
|
293 |
* enumerated_spec_init_c * |
|
294 |
*/ |
|
295 |
// SYM_REF2(var1_init_decl_c, var1_list, spec_init) |
|
296 |
void *search_var_instance_decl_c::visit(var1_init_decl_c *symbol) { |
|
297 |
current_type_decl = symbol->spec_init; |
|
298 |
return symbol->var1_list->accept(*this); |
|
299 |
} |
|
300 |
||
301 |
/* var1_list ',' variable_name */ |
|
302 |
// SYM_LIST(var1_list_c) |
|
303 |
void *search_var_instance_decl_c::visit(var1_list_c *symbol) { |
|
304 |
list_c *list = symbol; |
|
305 |
for(int i = 0; i < list->n; i++) { |
|
306 |
if (compare_identifiers(list->elements[i], search_name) == 0) |
|
307 |
/* by now, current_type_decl should be != NULL */ |
|
308 |
return current_type_decl; |
|
309 |
} |
|
310 |
return NULL; |
|
311 |
} |
|
312 |
||
313 |
/* name_list ':' function_block_type_name ASSIGN structure_initialization */ |
|
314 |
/* structure_initialization -> may be NULL ! */ |
|
315 |
void *search_var_instance_decl_c::visit(fb_name_decl_c *symbol) { |
|
810
d9c48ad646f1
Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents:
793
diff
changeset
|
316 |
// TODO: The following line is wrong! It should be |
d9c48ad646f1
Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents:
793
diff
changeset
|
317 |
// current_type_decl = symbol->fb_spec_init; |
d9c48ad646f1
Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents:
793
diff
changeset
|
318 |
// However, this change will require a check of all callers, to see if they would handle this correctly. |
d9c48ad646f1
Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents:
793
diff
changeset
|
319 |
// For now, just keep what we have had historically, and seems to be working. |
d9c48ad646f1
Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents:
793
diff
changeset
|
320 |
current_type_decl = spec_init_sperator_c::get_spec(symbol->fb_spec_init); |
181 | 321 |
return symbol->fb_name_list->accept(*this); |
322 |
} |
|
323 |
||
324 |
/* name_list ',' fb_name */ |
|
325 |
void *search_var_instance_decl_c::visit(fb_name_list_c *symbol) { |
|
326 |
list_c *list = symbol; |
|
327 |
for(int i = 0; i < list->n; i++) { |
|
328 |
if (compare_identifiers(list->elements[i], search_name) == 0) |
|
504
f8d422b98315
Fix bug by expanding permissible data input of search_var_instance_decl_c
Mario de Sousa <msousa@fe.up.pt>
parents:
417
diff
changeset
|
329 |
/* by now, current_fb_declaration should be != NULL */ |
181 | 330 |
return current_type_decl; |
331 |
} |
|
332 |
return NULL; |
|
333 |
} |
|
334 |
||
335 |
/* var1_list ':' array_spec_init */ |
|
336 |
// SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
337 |
void *search_var_instance_decl_c::visit(array_var_init_decl_c *symbol) { |
|
338 |
current_type_decl = symbol->array_spec_init; |
|
339 |
return symbol->var1_list->accept(*this); |
|
340 |
} |
|
341 |
||
342 |
/* var1_list ':' initialized_structure */ |
|
343 |
// SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
344 |
void *search_var_instance_decl_c::visit(structured_var_init_decl_c *symbol) { |
|
345 |
current_type_decl = symbol->initialized_structure; |
|
346 |
return symbol->var1_list->accept(*this); |
|
347 |
} |
|
348 |
||
349 |
/* var1_list ':' array_specification */ |
|
350 |
// SYM_REF2(array_var_declaration_c, var1_list, array_specification) |
|
351 |
void *search_var_instance_decl_c::visit(array_var_declaration_c *symbol) { |
|
352 |
current_type_decl = symbol->array_specification; |
|
353 |
return symbol->var1_list->accept(*this); |
|
354 |
} |
|
355 |
||
356 |
/* var1_list ':' structure_type_name */ |
|
357 |
// SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) |
|
358 |
void *search_var_instance_decl_c::visit(structured_var_declaration_c *symbol) { |
|
359 |
current_type_decl = symbol->structure_type_name; |
|
360 |
return symbol->var1_list->accept(*this); |
|
361 |
} |
|
362 |
||
363 |
/* [variable_name] location ':' located_var_spec_init */ |
|
364 |
/* variable_name -> may be NULL ! */ |
|
365 |
// SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
366 |
// TODO!! |
|
367 |
||
368 |
/* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
369 |
// SYM_REF2(external_declaration_c, global_var_name, specification) |
|
370 |
void *search_var_instance_decl_c::visit(external_declaration_c *symbol) { |
|
371 |
if (compare_identifiers(symbol->global_var_name, search_name) == 0) |
|
372 |
return symbol->specification; |
|
373 |
return NULL; |
|
374 |
} |
|
375 |
||
376 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
377 |
/* type_specification ->may be NULL ! */ |
|
378 |
// SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
379 |
void *search_var_instance_decl_c::visit(global_var_decl_c *symbol) { |
|
380 |
if (symbol->type_specification != NULL) { |
|
381 |
current_type_decl = symbol->type_specification; |
|
382 |
return symbol->global_var_spec->accept(*this); |
|
383 |
} |
|
384 |
else |
|
385 |
return NULL; |
|
386 |
} |
|
387 |
||
388 |
/*| global_var_name location */ |
|
389 |
//SYM_REF2(global_var_spec_c, global_var_name, location) |
|
390 |
void *search_var_instance_decl_c::visit(global_var_spec_c *symbol) { |
|
391 |
if (symbol->global_var_name != NULL && compare_identifiers(symbol->global_var_name, search_name) == 0) |
|
392 |
return current_type_decl; |
|
393 |
else |
|
394 |
return symbol->location->accept(*this); |
|
395 |
} |
|
396 |
||
397 |
/*| global_var_list ',' global_var_name */ |
|
398 |
//SYM_LIST(global_var_list_c) |
|
399 |
void *search_var_instance_decl_c::visit(global_var_list_c *symbol) { |
|
400 |
list_c *list = symbol; |
|
401 |
for(int i = 0; i < list->n; i++) { |
|
402 |
if (compare_identifiers(list->elements[i], search_name) == 0) |
|
403 |
/* by now, current_type_decl should be != NULL */ |
|
404 |
return current_type_decl; |
|
405 |
} |
|
406 |
return NULL; |
|
407 |
} |
|
408 |
||
409 |
/* [variable_name] location ':' located_var_spec_init */ |
|
410 |
/* variable_name -> may be NULL ! */ |
|
411 |
//SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
412 |
void *search_var_instance_decl_c::visit(located_var_decl_c *symbol) { |
|
413 |
if (symbol->variable_name != NULL && compare_identifiers(symbol->variable_name, search_name) == 0) |
|
414 |
return symbol->located_var_spec_init; |
|
415 |
else { |
|
416 |
current_type_decl = symbol->located_var_spec_init; |
|
417 |
return symbol->location->accept(*this); |
|
418 |
} |
|
419 |
} |
|
420 |
||
421 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
422 |
/* type_specification ->may be NULL ! */ |
|
423 |
// SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
424 |
// TODO!! |
|
425 |
||
426 |
/* AT direct_variable */ |
|
427 |
// SYM_REF2(location_c, direct_variable, unused) |
|
428 |
void *search_var_instance_decl_c::visit(location_c *symbol) { |
|
429 |
if (compare_identifiers(symbol->direct_variable, search_name) == 0) |
|
430 |
return current_type_decl; |
|
431 |
else |
|
432 |
return NULL; |
|
433 |
} |
|
434 |
||
435 |
/*| global_var_list ',' global_var_name */ |
|
436 |
// SYM_LIST(global_var_list_c) |
|
437 |
// TODO!! |
|
438 |
||
439 |
/* var1_list ':' single_byte_string_spec */ |
|
440 |
// SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) |
|
441 |
void *search_var_instance_decl_c::visit(single_byte_string_var_declaration_c *symbol) { |
|
442 |
current_type_decl = symbol->single_byte_string_spec; |
|
443 |
return symbol->var1_list->accept(*this); |
|
444 |
} |
|
445 |
||
446 |
/* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ |
|
447 |
/* integer ->may be NULL ! */ |
|
448 |
/* single_byte_character_string ->may be NULL ! */ |
|
449 |
// SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) |
|
450 |
// TODO!! |
|
451 |
||
452 |
/* var1_list ':' double_byte_string_spec */ |
|
453 |
// SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) |
|
454 |
void *search_var_instance_decl_c::visit(double_byte_string_var_declaration_c *symbol) { |
|
455 |
current_type_decl = symbol->double_byte_string_spec; |
|
456 |
return symbol->var1_list->accept(*this); |
|
457 |
} |
|
458 |
||
459 |
/* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ |
|
460 |
/* integer ->may be NULL ! */ |
|
461 |
/* double_byte_character_string ->may be NULL ! */ |
|
462 |
// SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) |
|
463 |
// TODO!! |
|
464 |
||
465 |
/* variable_name incompl_location ':' var_spec */ |
|
466 |
// SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) |
|
467 |
// TODO!! |
|
468 |
||
469 |
/* AT incompl_location_token */ |
|
470 |
// SYM_TOKEN(incompl_location_c) |
|
471 |
// TODO!! |
|
472 |
||
473 |
||
474 |
/**************************************/ |
|
475 |
/* B.1.5 - Program organization units */ |
|
476 |
/**************************************/ |
|
477 |
/***********************/ |
|
478 |
/* B 1.5.1 - Functions */ |
|
479 |
/***********************/ |
|
480 |
// SYM_REF4(function_declaration_c, derived_function_name, type_name, var_declarations_list, function_body) |
|
481 |
void *search_var_instance_decl_c::visit(function_declaration_c *symbol) { |
|
482 |
/* functions have a variable named after themselves, to store |
|
483 |
* the variable that will be returned!! |
|
484 |
*/ |
|
485 |
if (compare_identifiers(symbol->derived_function_name, search_name) == 0) |
|
486 |
return symbol->type_name; |
|
487 |
||
488 |
/* no need to search through all the body, so we only |
|
489 |
* visit the variable declarations...! |
|
490 |
*/ |
|
491 |
return symbol->var_declarations_list->accept(*this); |
|
492 |
} |
|
493 |
||
494 |
/*****************************/ |
|
495 |
/* B 1.5.2 - Function Blocks */ |
|
496 |
/*****************************/ |
|
619
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
497 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
498 |
// SYM_REF3(function_block_declaration_c, fblock_name, var_declarations, fblock_body) |
181 | 499 |
void *search_var_instance_decl_c::visit(function_block_declaration_c *symbol) { |
619
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
500 |
/* visit the variable declarations...! */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
501 |
void *res = symbol->var_declarations->accept(*this); |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
502 |
if (NULL != res) |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
503 |
return res; |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
504 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
505 |
/* not yet found, so we look into the body, to see if it is an SFC step! */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
506 |
return symbol->fblock_body->accept(*this); |
181 | 507 |
} |
508 |
||
509 |
/**********************/ |
|
510 |
/* B 1.5.3 - Programs */ |
|
511 |
/**********************/ |
|
619
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
512 |
/* PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
513 |
// SYM_REF3(program_declaration_c, program_type_name, var_declarations, function_block_body) |
181 | 514 |
void *search_var_instance_decl_c::visit(program_declaration_c *symbol) { |
619
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
515 |
/* visit the variable declarations...! */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
516 |
void *res = symbol->var_declarations->accept(*this); |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
517 |
if (NULL != res) |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
518 |
return res; |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
519 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
520 |
/* not yet found, so we look into the body, to see if it is an SFC step! */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
521 |
return symbol->function_block_body->accept(*this); |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
522 |
} |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
523 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
524 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
525 |
/*********************************************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
526 |
/* B.1.6 Sequential function chart elements */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
527 |
/*********************************************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
528 |
/* | sequential_function_chart sfc_network */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
529 |
// SYM_LIST(sequential_function_chart_c) |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
530 |
/* search_var_instance_decl_c inherits from serach_visitor_c, so no need to implement the following method. */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
531 |
// void *search_var_instance_decl_c::visit(sequential_function_chart_c *symbol) {...} |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
532 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
533 |
/* initial_step {step | transition | action} */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
534 |
// SYM_LIST(sfc_network_c) |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
535 |
/* search_var_instance_decl_c inherits from serach_visitor_c, so no need to implement the following method. */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
536 |
// void *search_var_instance_decl_c::visit(sfc_network_c *symbol) {...} |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
537 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
538 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
539 |
/* INITIAL_STEP step_name ':' action_association_list END_STEP */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
540 |
// SYM_REF2(initial_step_c, step_name, action_association_list) |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
541 |
void *search_var_instance_decl_c::visit(initial_step_c *symbol) { |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
542 |
if (compare_identifiers(symbol->step_name, search_name) == 0) |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
543 |
return symbol; |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
544 |
return NULL; |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
545 |
} |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
546 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
547 |
/* STEP step_name ':' action_association_list END_STEP */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
548 |
// SYM_REF2(step_c, step_name, action_association_list) |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
549 |
void *search_var_instance_decl_c::visit(step_c *symbol) { |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
550 |
if (compare_identifiers(symbol->step_name, search_name) == 0) |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
551 |
return symbol; |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
552 |
return NULL; |
181 | 553 |
} |
554 |
||
555 |
||
556 |
/********************************/ |
|
557 |
/* B 1.7 Configuration elements */ |
|
558 |
/********************************/ |
|
559 |
||
560 |
/* |
|
561 |
CONFIGURATION configuration_name |
|
562 |
optional_global_var_declarations |
|
563 |
(resource_declaration_list | single_resource_declaration) |
|
564 |
optional_access_declarations |
|
565 |
optional_instance_specific_initializations |
|
566 |
END_CONFIGURATION |
|
567 |
*/ |
|
568 |
/* |
|
569 |
SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused) |
|
570 |
*/ |
|
571 |
void *search_var_instance_decl_c::visit(configuration_declaration_c *symbol) { |
|
572 |
/* no need to search through all the configuration, so we only |
|
573 |
* visit the global variable declarations...! |
|
574 |
*/ |
|
575 |
if (symbol->global_var_declarations != NULL) |
|
576 |
return symbol->global_var_declarations->accept(*this); |
|
577 |
else |
|
578 |
return NULL; |
|
579 |
} |
|
580 |
||
581 |
/* |
|
582 |
RESOURCE resource_name ON resource_type_name |
|
583 |
optional_global_var_declarations |
|
584 |
single_resource_declaration |
|
585 |
END_RESOURCE |
|
586 |
*/ |
|
587 |
// SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
588 |
void *search_var_instance_decl_c::visit(resource_declaration_c *symbol) { |
|
589 |
/* no need to search through all the resource, so we only |
|
590 |
* visit the global variable declarations...! |
|
591 |
*/ |
|
592 |
if (symbol->global_var_declarations != NULL) |
|
593 |
return symbol->global_var_declarations->accept(*this); |
|
594 |
else |
|
595 |
return NULL; |
|
596 |
} |
|
597 |
||
598 |
/* task_configuration_list program_configuration_list */ |
|
599 |
// SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
600 |
void *search_var_instance_decl_c::visit(single_resource_declaration_c *symbol) { |
|
601 |
/* no need to search through all the resource, |
|
602 |
* and there is no global variable declarations...! |
|
603 |
*/ |
|
604 |
return NULL; |
|
605 |
} |
|
606 |
||
619
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
607 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
608 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
609 |
/****************************************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
610 |
/* B.2 - Language IL (Instruction List) */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
611 |
/****************************************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
612 |
/***********************************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
613 |
/* B 2.1 Instructions and Operands */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
614 |
/***********************************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
615 |
/*| instruction_list il_instruction */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
616 |
// SYM_LIST(instruction_list_c) |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
617 |
void *search_var_instance_decl_c::visit(instruction_list_c *symbol) { |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
618 |
/* IL code does not contain any variable declarations! */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
619 |
return NULL; |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
620 |
} |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
621 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
622 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
623 |
/***************************************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
624 |
/* B.3 - Language ST (Structured Text) */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
625 |
/***************************************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
626 |
/********************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
627 |
/* B 3.2 Statements */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
628 |
/********************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
629 |
// SYM_LIST(statement_list_c) |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
630 |
void *search_var_instance_decl_c::visit(statement_list_c *symbol) { |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
631 |
/* ST code does not contain any variable declarations! */ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
632 |
return NULL; |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
633 |
} |