author | Edouard Tisserant |
Wed, 24 Nov 2021 08:58:58 +0100 | |
changeset 1095 | 36bbd0b64816 |
parent 1041 | 56ebe2a31b5b |
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 |
||
939
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
854
diff
changeset
|
112 |
symbol_c *search_var_instance_decl_c::get_basetype_decl(symbol_c *variable) { |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
854
diff
changeset
|
113 |
return search_base_type_c::get_basetype_decl(get_decl(variable)); |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
854
diff
changeset
|
114 |
} |
5074236fb3c4
fill_candidate_datatypes_c now uses search_varinstance_decl_c instead of search_varfb_instance_type_c (moving towards deprecation of search_varfb_instance_type_c)
mjsousa
parents:
854
diff
changeset
|
115 |
|
536
563b013ec670
Change constants into enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
531
diff
changeset
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
return this->current_vartype; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
123 |
} |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
124 |
|
536
563b013ec670
Change constants into enums.
Mario de Sousa <msousa@fe.up.pt>
parents:
531
diff
changeset
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
search_scope->accept(*this); |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
131 |
return this->current_option; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
132 |
} |
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
|
133 |
|
531
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
511
diff
changeset
|
134 |
|
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
511
diff
changeset
|
135 |
|
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
511
diff
changeset
|
136 |
|
181 | 137 |
/***************************/ |
138 |
/* B 0 - Programming Model */ |
|
139 |
/***************************/ |
|
140 |
void *search_var_instance_decl_c::visit(library_c *symbol) { |
|
141 |
/* 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
|
142 |
* so we do not visit all the functions, function blocks, etc... |
181 | 143 |
*/ |
144 |
return NULL; |
|
145 |
} |
|
146 |
||
147 |
||
148 |
||
149 |
/******************************************/ |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
150 |
/* B 1.4.3 - Declaration & Initialization */ |
181 | 151 |
/******************************************/ |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
152 |
|
181 | 153 |
/* edge -> The F_EDGE or R_EDGE directive */ |
154 |
// SYM_REF2(edge_declaration_c, edge, var1_list) |
|
155 |
// TODO |
|
507
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
156 |
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
|
157 |
current_option = constant_opt; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
158 |
return NULL; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
159 |
} |
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 |
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
|
162 |
current_option = retain_opt; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
163 |
return NULL; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
164 |
} |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
165 |
|
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
166 |
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
|
167 |
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
|
168 |
return NULL; |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
169 |
} |
181 | 170 |
|
171 |
void *search_var_instance_decl_c::visit(input_declarations_c *symbol) { |
|
172 |
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
|
173 |
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
|
174 |
if (NULL != symbol->option) |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
175 |
symbol->option->accept(*this); |
181 | 176 |
void *res = symbol->input_declaration_list->accept(*this); |
177 |
if (res == NULL) { |
|
178 |
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
|
179 |
current_option = none_opt; |
181 | 180 |
} |
181 |
return res; |
|
182 |
} |
|
183 |
||
184 |
/* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */ |
|
185 |
/* option -> may be NULL ! */ |
|
186 |
void *search_var_instance_decl_c::visit(output_declarations_c *symbol) { |
|
187 |
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
|
188 |
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
|
189 |
if (NULL != symbol->option) |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
190 |
symbol->option->accept(*this); |
181 | 191 |
void *res = symbol->var_init_decl_list->accept(*this); |
192 |
if (res == NULL) { |
|
193 |
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
|
194 |
current_option = none_opt; |
181 | 195 |
} |
196 |
return res; |
|
197 |
} |
|
198 |
||
199 |
/* VAR_IN_OUT var_declaration_list END_VAR */ |
|
200 |
void *search_var_instance_decl_c::visit(input_output_declarations_c *symbol) { |
|
201 |
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
|
202 |
current_option = none_opt; /* not really required. Just to make the code more readable */ |
181 | 203 |
void *res = symbol->var_declaration_list->accept(*this); |
204 |
if (res == NULL) { |
|
205 |
current_vartype = none_vt; |
|
206 |
} |
|
207 |
return res; |
|
208 |
} |
|
209 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
210 |
/* ENO : BOOL */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
211 |
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
|
212 |
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
|
213 |
return symbol->type; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
214 |
return NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
215 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
216 |
|
1011
76175defb87b
Add option to not add the EN and ENO parameters to every function and FB (generated C code becomes smaller, and uses less memory for function invocations)
mjsousa
parents:
939
diff
changeset
|
217 |
/* EN : BOOL */ |
76175defb87b
Add option to not add the EN and ENO parameters to every function and FB (generated C code becomes smaller, and uses less memory for function invocations)
mjsousa
parents:
939
diff
changeset
|
218 |
void *search_var_instance_decl_c::visit(en_param_declaration_c *symbol) { |
76175defb87b
Add option to not add the EN and ENO parameters to every function and FB (generated C code becomes smaller, and uses less memory for function invocations)
mjsousa
parents:
939
diff
changeset
|
219 |
if (compare_identifiers(symbol->name, search_name) == 0) |
76175defb87b
Add option to not add the EN and ENO parameters to every function and FB (generated C code becomes smaller, and uses less memory for function invocations)
mjsousa
parents:
939
diff
changeset
|
220 |
return symbol->type_decl; |
76175defb87b
Add option to not add the EN and ENO parameters to every function and FB (generated C code becomes smaller, and uses less memory for function invocations)
mjsousa
parents:
939
diff
changeset
|
221 |
return NULL; |
76175defb87b
Add option to not add the EN and ENO parameters to every function and FB (generated C code becomes smaller, and uses less memory for function invocations)
mjsousa
parents:
939
diff
changeset
|
222 |
} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
223 |
|
181 | 224 |
/* VAR [CONSTANT] var_init_decl_list END_VAR */ |
225 |
/* option -> may be NULL ! */ |
|
226 |
/* helper symbol for input_declarations */ |
|
227 |
void *search_var_instance_decl_c::visit(var_declarations_c *symbol) { |
|
228 |
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
|
229 |
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
|
230 |
if (NULL != symbol->option) |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
231 |
symbol->option->accept(*this); |
181 | 232 |
void *res = symbol->var_init_decl_list->accept(*this); |
233 |
if (res == NULL) { |
|
234 |
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
|
235 |
current_option = none_opt; |
181 | 236 |
} |
237 |
return res; |
|
238 |
} |
|
239 |
||
240 |
/* VAR RETAIN var_init_decl_list END_VAR */ |
|
241 |
void *search_var_instance_decl_c::visit(retentive_var_declarations_c *symbol) { |
|
242 |
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
|
243 |
current_option = retain_opt; |
181 | 244 |
void *res = symbol->var_init_decl_list->accept(*this); |
245 |
if (res == NULL) { |
|
246 |
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
|
247 |
current_option = none_opt; |
181 | 248 |
} |
249 |
return res; |
|
250 |
} |
|
251 |
||
252 |
/* VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */ |
|
253 |
/* option -> may be NULL ! */ |
|
254 |
//SYM_REF2(located_var_declarations_c, option, located_var_decl_list) |
|
255 |
void *search_var_instance_decl_c::visit(located_var_declarations_c *symbol) { |
|
256 |
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
|
257 |
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
|
258 |
if (NULL != symbol->option) |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
259 |
symbol->option->accept(*this); |
181 | 260 |
void *res = symbol->located_var_decl_list->accept(*this); |
261 |
if (res == NULL) { |
|
262 |
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
|
263 |
current_option = none_opt; |
181 | 264 |
} |
265 |
return res; |
|
266 |
} |
|
267 |
||
268 |
/*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ |
|
269 |
/* option -> may be NULL ! */ |
|
270 |
//SYM_REF2(external_var_declarations_c, option, external_declaration_list) |
|
271 |
void *search_var_instance_decl_c::visit(external_var_declarations_c *symbol) { |
|
272 |
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
|
273 |
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
|
274 |
if (NULL != symbol->option) |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
275 |
symbol->option->accept(*this); |
181 | 276 |
void *res = symbol->external_declaration_list->accept(*this); |
277 |
if (res == NULL) { |
|
278 |
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
|
279 |
current_option = none_opt; |
181 | 280 |
} |
281 |
return res; |
|
282 |
} |
|
283 |
||
284 |
/*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ |
|
285 |
/* option -> may be NULL ! */ |
|
286 |
//SYM_REF2(global_var_declarations_c, option, global_var_decl_list) |
|
287 |
void *search_var_instance_decl_c::visit(global_var_declarations_c *symbol) { |
|
288 |
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
|
289 |
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
|
290 |
if (NULL != symbol->option) |
30b31d8f6d0f
Determine the modifiers (CONST, REATAIN) used when declaring a variable.
manuele.conti@sirius-es.it
parents:
504
diff
changeset
|
291 |
symbol->option->accept(*this); |
181 | 292 |
void *res = symbol->global_var_decl_list->accept(*this); |
293 |
if (res == NULL) { |
|
294 |
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
|
295 |
current_option = none_opt; |
181 | 296 |
} |
297 |
return res; |
|
298 |
} |
|
299 |
||
300 |
/* var1_list is one of the following... |
|
301 |
* simple_spec_init_c * |
|
302 |
* subrange_spec_init_c * |
|
303 |
* enumerated_spec_init_c * |
|
304 |
*/ |
|
305 |
// SYM_REF2(var1_init_decl_c, var1_list, spec_init) |
|
306 |
void *search_var_instance_decl_c::visit(var1_init_decl_c *symbol) { |
|
307 |
current_type_decl = symbol->spec_init; |
|
308 |
return symbol->var1_list->accept(*this); |
|
309 |
} |
|
310 |
||
311 |
/* var1_list ',' variable_name */ |
|
312 |
// SYM_LIST(var1_list_c) |
|
313 |
void *search_var_instance_decl_c::visit(var1_list_c *symbol) { |
|
314 |
list_c *list = symbol; |
|
315 |
for(int i = 0; i < list->n; i++) { |
|
1041
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
1011
diff
changeset
|
316 |
if (compare_identifiers(list->get_element(i), search_name) == 0) |
181 | 317 |
/* by now, current_type_decl should be != NULL */ |
318 |
return current_type_decl; |
|
319 |
} |
|
320 |
return NULL; |
|
321 |
} |
|
322 |
||
323 |
/* name_list ':' function_block_type_name ASSIGN structure_initialization */ |
|
324 |
/* structure_initialization -> may be NULL ! */ |
|
325 |
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
|
326 |
// 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
|
327 |
// 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
|
328 |
// 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
|
329 |
// 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
|
330 |
current_type_decl = spec_init_sperator_c::get_spec(symbol->fb_spec_init); |
181 | 331 |
return symbol->fb_name_list->accept(*this); |
332 |
} |
|
333 |
||
334 |
/* name_list ',' fb_name */ |
|
335 |
void *search_var_instance_decl_c::visit(fb_name_list_c *symbol) { |
|
336 |
list_c *list = symbol; |
|
337 |
for(int i = 0; i < list->n; i++) { |
|
1041
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
1011
diff
changeset
|
338 |
if (compare_identifiers(list->get_element(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
|
339 |
/* by now, current_fb_declaration should be != NULL */ |
181 | 340 |
return current_type_decl; |
341 |
} |
|
342 |
return NULL; |
|
343 |
} |
|
344 |
||
345 |
/* var1_list ':' array_spec_init */ |
|
346 |
// SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
347 |
void *search_var_instance_decl_c::visit(array_var_init_decl_c *symbol) { |
|
348 |
current_type_decl = symbol->array_spec_init; |
|
349 |
return symbol->var1_list->accept(*this); |
|
350 |
} |
|
351 |
||
352 |
/* var1_list ':' initialized_structure */ |
|
353 |
// SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
354 |
void *search_var_instance_decl_c::visit(structured_var_init_decl_c *symbol) { |
|
355 |
current_type_decl = symbol->initialized_structure; |
|
356 |
return symbol->var1_list->accept(*this); |
|
357 |
} |
|
358 |
||
359 |
/* var1_list ':' array_specification */ |
|
360 |
// SYM_REF2(array_var_declaration_c, var1_list, array_specification) |
|
361 |
void *search_var_instance_decl_c::visit(array_var_declaration_c *symbol) { |
|
362 |
current_type_decl = symbol->array_specification; |
|
363 |
return symbol->var1_list->accept(*this); |
|
364 |
} |
|
365 |
||
366 |
/* var1_list ':' structure_type_name */ |
|
367 |
// SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) |
|
368 |
void *search_var_instance_decl_c::visit(structured_var_declaration_c *symbol) { |
|
369 |
current_type_decl = symbol->structure_type_name; |
|
370 |
return symbol->var1_list->accept(*this); |
|
371 |
} |
|
372 |
||
373 |
/* [variable_name] location ':' located_var_spec_init */ |
|
374 |
/* variable_name -> may be NULL ! */ |
|
375 |
// SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
376 |
// TODO!! |
|
377 |
||
378 |
/* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
379 |
// SYM_REF2(external_declaration_c, global_var_name, specification) |
|
380 |
void *search_var_instance_decl_c::visit(external_declaration_c *symbol) { |
|
381 |
if (compare_identifiers(symbol->global_var_name, search_name) == 0) |
|
382 |
return symbol->specification; |
|
383 |
return NULL; |
|
384 |
} |
|
385 |
||
386 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
387 |
/* type_specification ->may be NULL ! */ |
|
388 |
// SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
389 |
void *search_var_instance_decl_c::visit(global_var_decl_c *symbol) { |
|
390 |
if (symbol->type_specification != NULL) { |
|
391 |
current_type_decl = symbol->type_specification; |
|
392 |
return symbol->global_var_spec->accept(*this); |
|
393 |
} |
|
394 |
else |
|
395 |
return NULL; |
|
396 |
} |
|
397 |
||
398 |
/*| global_var_name location */ |
|
399 |
//SYM_REF2(global_var_spec_c, global_var_name, location) |
|
400 |
void *search_var_instance_decl_c::visit(global_var_spec_c *symbol) { |
|
401 |
if (symbol->global_var_name != NULL && compare_identifiers(symbol->global_var_name, search_name) == 0) |
|
402 |
return current_type_decl; |
|
403 |
else |
|
404 |
return symbol->location->accept(*this); |
|
405 |
} |
|
406 |
||
407 |
/*| global_var_list ',' global_var_name */ |
|
408 |
//SYM_LIST(global_var_list_c) |
|
409 |
void *search_var_instance_decl_c::visit(global_var_list_c *symbol) { |
|
410 |
list_c *list = symbol; |
|
411 |
for(int i = 0; i < list->n; i++) { |
|
1041
56ebe2a31b5b
Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
1011
diff
changeset
|
412 |
if (compare_identifiers(list->get_element(i), search_name) == 0) |
181 | 413 |
/* by now, current_type_decl should be != NULL */ |
414 |
return current_type_decl; |
|
415 |
} |
|
416 |
return NULL; |
|
417 |
} |
|
418 |
||
419 |
/* [variable_name] location ':' located_var_spec_init */ |
|
420 |
/* variable_name -> may be NULL ! */ |
|
421 |
//SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
422 |
void *search_var_instance_decl_c::visit(located_var_decl_c *symbol) { |
|
423 |
if (symbol->variable_name != NULL && compare_identifiers(symbol->variable_name, search_name) == 0) |
|
424 |
return symbol->located_var_spec_init; |
|
425 |
else { |
|
426 |
current_type_decl = symbol->located_var_spec_init; |
|
427 |
return symbol->location->accept(*this); |
|
428 |
} |
|
429 |
} |
|
430 |
||
431 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
432 |
/* type_specification ->may be NULL ! */ |
|
433 |
// SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
434 |
// TODO!! |
|
435 |
||
436 |
/* AT direct_variable */ |
|
437 |
// SYM_REF2(location_c, direct_variable, unused) |
|
438 |
void *search_var_instance_decl_c::visit(location_c *symbol) { |
|
439 |
if (compare_identifiers(symbol->direct_variable, search_name) == 0) |
|
440 |
return current_type_decl; |
|
441 |
else |
|
442 |
return NULL; |
|
443 |
} |
|
444 |
||
445 |
/*| global_var_list ',' global_var_name */ |
|
446 |
// SYM_LIST(global_var_list_c) |
|
447 |
// TODO!! |
|
448 |
||
449 |
/* var1_list ':' single_byte_string_spec */ |
|
450 |
// SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) |
|
451 |
void *search_var_instance_decl_c::visit(single_byte_string_var_declaration_c *symbol) { |
|
452 |
current_type_decl = symbol->single_byte_string_spec; |
|
453 |
return symbol->var1_list->accept(*this); |
|
454 |
} |
|
455 |
||
456 |
/* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ |
|
457 |
/* integer ->may be NULL ! */ |
|
458 |
/* single_byte_character_string ->may be NULL ! */ |
|
459 |
// SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) |
|
460 |
// TODO!! |
|
461 |
||
462 |
/* var1_list ':' double_byte_string_spec */ |
|
463 |
// SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) |
|
464 |
void *search_var_instance_decl_c::visit(double_byte_string_var_declaration_c *symbol) { |
|
465 |
current_type_decl = symbol->double_byte_string_spec; |
|
466 |
return symbol->var1_list->accept(*this); |
|
467 |
} |
|
468 |
||
469 |
/* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ |
|
470 |
/* integer ->may be NULL ! */ |
|
471 |
/* double_byte_character_string ->may be NULL ! */ |
|
472 |
// SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) |
|
473 |
// TODO!! |
|
474 |
||
475 |
/* variable_name incompl_location ':' var_spec */ |
|
476 |
// SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) |
|
477 |
// TODO!! |
|
478 |
||
479 |
/* AT incompl_location_token */ |
|
480 |
// SYM_TOKEN(incompl_location_c) |
|
481 |
// TODO!! |
|
482 |
||
483 |
||
484 |
/**************************************/ |
|
485 |
/* B.1.5 - Program organization units */ |
|
486 |
/**************************************/ |
|
487 |
/***********************/ |
|
488 |
/* B 1.5.1 - Functions */ |
|
489 |
/***********************/ |
|
490 |
// SYM_REF4(function_declaration_c, derived_function_name, type_name, var_declarations_list, function_body) |
|
491 |
void *search_var_instance_decl_c::visit(function_declaration_c *symbol) { |
|
492 |
/* functions have a variable named after themselves, to store |
|
493 |
* the variable that will be returned!! |
|
494 |
*/ |
|
495 |
if (compare_identifiers(symbol->derived_function_name, search_name) == 0) |
|
496 |
return symbol->type_name; |
|
497 |
||
498 |
/* no need to search through all the body, so we only |
|
499 |
* visit the variable declarations...! |
|
500 |
*/ |
|
501 |
return symbol->var_declarations_list->accept(*this); |
|
502 |
} |
|
503 |
||
504 |
/*****************************/ |
|
505 |
/* B 1.5.2 - Function Blocks */ |
|
506 |
/*****************************/ |
|
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
|
507 |
/* 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
|
508 |
// SYM_REF3(function_block_declaration_c, fblock_name, var_declarations, fblock_body) |
181 | 509 |
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
|
510 |
/* 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
|
511 |
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
|
512 |
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
|
513 |
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
|
514 |
|
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 |
/* 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
|
516 |
return symbol->fblock_body->accept(*this); |
181 | 517 |
} |
518 |
||
519 |
/**********************/ |
|
520 |
/* B 1.5.3 - Programs */ |
|
521 |
/**********************/ |
|
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
|
522 |
/* 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
|
523 |
// SYM_REF3(program_declaration_c, program_type_name, var_declarations, function_block_body) |
181 | 524 |
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
|
525 |
/* 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
|
526 |
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
|
527 |
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
|
528 |
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
|
529 |
|
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 |
/* 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
|
531 |
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
|
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 |
|
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 |
|
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 |
/*********************************************/ |
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 |
/* 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
|
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 |
/* | 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
|
539 |
// 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
|
540 |
/* 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
|
541 |
// 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
|
542 |
|
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 |
/* 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
|
544 |
// 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
|
545 |
/* 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
|
546 |
// 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
|
547 |
|
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 |
|
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 |
/* 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
|
550 |
// 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
|
551 |
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
|
552 |
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
|
553 |
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
|
554 |
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
|
555 |
} |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
556 |
|
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
557 |
/* 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
|
558 |
// 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
|
559 |
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
|
560 |
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
|
561 |
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
|
562 |
return NULL; |
181 | 563 |
} |
564 |
||
565 |
||
566 |
/********************************/ |
|
567 |
/* B 1.7 Configuration elements */ |
|
568 |
/********************************/ |
|
569 |
||
570 |
/* |
|
571 |
CONFIGURATION configuration_name |
|
572 |
optional_global_var_declarations |
|
573 |
(resource_declaration_list | single_resource_declaration) |
|
574 |
optional_access_declarations |
|
575 |
optional_instance_specific_initializations |
|
576 |
END_CONFIGURATION |
|
577 |
*/ |
|
578 |
/* |
|
579 |
SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused) |
|
580 |
*/ |
|
581 |
void *search_var_instance_decl_c::visit(configuration_declaration_c *symbol) { |
|
582 |
/* no need to search through all the configuration, so we only |
|
583 |
* visit the global variable declarations...! |
|
584 |
*/ |
|
585 |
if (symbol->global_var_declarations != NULL) |
|
586 |
return symbol->global_var_declarations->accept(*this); |
|
587 |
else |
|
588 |
return NULL; |
|
589 |
} |
|
590 |
||
591 |
/* |
|
592 |
RESOURCE resource_name ON resource_type_name |
|
593 |
optional_global_var_declarations |
|
594 |
single_resource_declaration |
|
595 |
END_RESOURCE |
|
596 |
*/ |
|
597 |
// SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
598 |
void *search_var_instance_decl_c::visit(resource_declaration_c *symbol) { |
|
599 |
/* no need to search through all the resource, so we only |
|
600 |
* visit the global variable declarations...! |
|
601 |
*/ |
|
602 |
if (symbol->global_var_declarations != NULL) |
|
603 |
return symbol->global_var_declarations->accept(*this); |
|
604 |
else |
|
605 |
return NULL; |
|
606 |
} |
|
607 |
||
608 |
/* task_configuration_list program_configuration_list */ |
|
609 |
// SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
610 |
void *search_var_instance_decl_c::visit(single_resource_declaration_c *symbol) { |
|
611 |
/* no need to search through all the resource, |
|
612 |
* and there is no global variable declarations...! |
|
613 |
*/ |
|
614 |
return NULL; |
|
615 |
} |
|
616 |
||
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
|
617 |
|
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 |
|
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 |
/****************************************/ |
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 |
/* 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
|
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 |
/* 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
|
624 |
/***********************************/ |
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 |
/*| 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
|
626 |
// 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
|
627 |
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
|
628 |
/* 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
|
629 |
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
|
630 |
} |
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 |
|
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 |
|
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 |
/***************************************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
634 |
/* 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
|
635 |
/***************************************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
636 |
/********************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
637 |
/* 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
|
638 |
/********************/ |
f8c9ac5c529a
Support for data types of STEP.T and STEP.X in SFCs
Mario de Sousa <msousa@fe.up.pt>
parents:
536
diff
changeset
|
639 |
// 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
|
640 |
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
|
641 |
/* 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
|
642 |
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
|
643 |
} |