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