author | Edouard Tisserant |
Mon, 04 Apr 2011 17:19:35 +0200 | |
changeset 272 | 579db02bebd9 |
parent 265 | 4d222f46f8cc |
child 279 | c0453b7f99df |
permissions | -rwxr-xr-x |
181 | 1 |
/* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
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:
237
diff
changeset
|
3 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
4 |
* Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
5 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
6 |
* 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:
237
diff
changeset
|
7 |
* 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:
237
diff
changeset
|
8 |
* 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:
237
diff
changeset
|
9 |
* (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:
237
diff
changeset
|
10 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
11 |
* 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:
237
diff
changeset
|
12 |
* 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:
237
diff
changeset
|
13 |
* 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:
237
diff
changeset
|
14 |
* 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:
237
diff
changeset
|
15 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
16 |
* 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:
237
diff
changeset
|
17 |
* 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:
237
diff
changeset
|
18 |
* |
181 | 19 |
* |
20 |
* This code is made available on the understanding that it will not be |
|
21 |
* used in safety-critical situations without a full and competent review. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
237
diff
changeset
|
25 |
* An IEC 61131-3 compiler. |
181 | 26 |
* |
27 |
* Based on the |
|
28 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
29 |
* |
|
30 |
*/ |
|
31 |
||
32 |
||
33 |
/* |
|
34 |
* Function parameter iterator. |
|
35 |
* Iterate through the in/out parameters of a function declaration. |
|
36 |
* Function blocks are also suported. |
|
37 |
* |
|
38 |
* This is part of the 4th stage that generates |
|
39 |
* a c++ source program equivalent to the IL and ST |
|
40 |
* code. |
|
41 |
*/ |
|
42 |
||
43 |
/* Given a function_declaration_c, iterate through each |
|
44 |
* function in/out/inout parameter, returning the name |
|
45 |
* of each parameter...function_param_iterator_c |
|
46 |
*/ |
|
47 |
||
48 |
||
49 |
||
50 |
#include "function_param_iterator.hh" |
|
51 |
#include "spec_init_separator.hh" |
|
52 |
#include <strings.h> |
|
53 |
||
54 |
||
55 |
//#define DEBUG |
|
56 |
#ifdef DEBUG |
|
57 |
#define TRACE(classname) printf("\n____%s____\n",classname); |
|
58 |
#else |
|
59 |
#define TRACE(classname) |
|
60 |
#endif |
|
61 |
||
62 |
||
63 |
#define ERROR error_exit(__FILE__,__LINE__) |
|
64 |
/* function defined in main.cc */ |
|
65 |
extern void error_exit(const char *file_name, int line_no); |
|
66 |
||
67 |
||
68 |
||
69 |
void* function_param_iterator_c::handle_param_list(list_c *list) { |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
70 |
switch (current_operation) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
71 |
case iterate_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
72 |
if (next_param <= param_count + list->n) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
73 |
return list->elements[next_param - param_count - 1]; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
74 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
75 |
/* the desired param is not on this list... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
76 |
param_count += list->n; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
77 |
break; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
78 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
79 |
case search_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
80 |
for(int i = 0; i < list->n; i++) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
81 |
identifier_c *variable_name = dynamic_cast<identifier_c *>(list->elements[i]); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
82 |
if (variable_name == NULL) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
83 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
84 |
if (strcasecmp(search_param_name->value, variable_name->value) == 0) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
85 |
/* FOUND! This is the same parameter!! */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
86 |
return (void *)variable_name; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
87 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
88 |
break; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
89 |
} /* switch */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
90 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
91 |
/* Not found! */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
92 |
return NULL; |
181 | 93 |
} |
94 |
||
95 |
void* function_param_iterator_c::handle_single_param(symbol_c *var_name) { |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
96 |
switch (current_operation) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
97 |
case iterate_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
98 |
param_count++; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
99 |
if (next_param == param_count) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
100 |
return var_name; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
101 |
break; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
102 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
103 |
case search_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
104 |
identifier_c *variable_name = dynamic_cast<identifier_c *>(var_name); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
105 |
if (variable_name == NULL) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
106 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
107 |
if (strcasecmp(search_param_name->value, variable_name->value) == 0) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
108 |
/* FOUND! This is the same parameter!! */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
109 |
return (void *)variable_name; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
110 |
break; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
111 |
} /* switch */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
112 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
113 |
/* Not found! */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
114 |
return NULL; |
181 | 115 |
} |
116 |
||
117 |
void* function_param_iterator_c::iterate_list(list_c *list) { |
|
118 |
void *res; |
|
119 |
for (int i = 0; i < list->n; i++) { |
|
120 |
res = list->elements[i]->accept(*this); |
|
121 |
if (res != NULL) |
|
122 |
return res; |
|
123 |
} |
|
124 |
return NULL; |
|
125 |
} |
|
126 |
||
127 |
/* start off at the first parameter once again... */ |
|
128 |
void function_param_iterator_c::reset(void) { |
|
129 |
next_param = param_count = 0; |
|
130 |
current_param_name = NULL; |
|
131 |
current_param_type = current_param_default_value = NULL; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
132 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
133 |
|
181 | 134 |
|
135 |
/* initialise the iterator object. |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
136 |
* We must be given a reference to one of the following |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
137 |
* - function_declaration_c |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
138 |
* - function_block_declaration_c |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
139 |
* - program_declaration_c |
181 | 140 |
* that will be analysed... |
141 |
*/ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
142 |
function_param_iterator_c::function_param_iterator_c(symbol_c *pou_decl) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
143 |
/* do some consistency checks... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
144 |
function_declaration_c * f_decl = dynamic_cast<function_declaration_c *>(pou_decl); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
145 |
function_block_declaration_c *fb_decl = dynamic_cast<function_block_declaration_c *>(pou_decl); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
146 |
program_declaration_c * p_decl = dynamic_cast<program_declaration_c *>(pou_decl); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
147 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
148 |
if ((NULL == f_decl) && (NULL == fb_decl) && (NULL == p_decl)) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
149 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
150 |
/* OK. Now initialise this object... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
151 |
this->f_decl = pou_decl; |
181 | 152 |
reset(); |
153 |
} |
|
154 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
155 |
|
181 | 156 |
|
157 |
/* Skip to the next parameter. After object creation, |
|
158 |
* the object references on parameter _before_ the first, so |
|
159 |
* this function must be called once to get the object to |
|
160 |
* reference the first parameter... |
|
161 |
* |
|
162 |
* Returns the parameter's name! |
|
163 |
*/ |
|
164 |
identifier_c *function_param_iterator_c::next(void) { |
|
165 |
void *res; |
|
166 |
identifier_c *identifier; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
167 |
|
181 | 168 |
param_count = 0; |
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
169 |
en_eno_param_implicit = false; |
181 | 170 |
next_param++; |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
171 |
current_operation = function_param_iterator_c::iterate_op; |
181 | 172 |
res = f_decl->accept(*this); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
173 |
if (res == NULL) |
181 | 174 |
return NULL; |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
175 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
176 |
symbol_c *sym = (symbol_c *)res; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
177 |
identifier = dynamic_cast<identifier_c *>(sym); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
178 |
if (identifier == NULL) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
179 |
ERROR; |
181 | 180 |
current_param_name = identifier; |
181 |
return current_param_name; |
|
182 |
} |
|
183 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
184 |
/* Search for the value passed to the parameter named <param_name>... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
185 |
identifier_c *function_param_iterator_c::search(symbol_c *param_name) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
186 |
if (NULL == param_name) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
187 |
search_param_name = dynamic_cast<identifier_c *>(param_name); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
188 |
if (NULL == search_param_name) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
189 |
current_operation = function_param_iterator_c::search_op; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
190 |
void *res = f_decl->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
191 |
identifier_c *res_param_name = dynamic_cast<identifier_c *>((symbol_c *)res); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
192 |
return res_param_name; |
181 | 193 |
} |
194 |
||
195 |
/* Returns the currently referenced parameter's default value, |
|
196 |
* or NULL if none is specified in the function declrataion itself. |
|
197 |
*/ |
|
198 |
symbol_c *function_param_iterator_c::default_value(void) { |
|
199 |
return current_param_default_value; |
|
200 |
} |
|
201 |
||
202 |
/* Returns the currently referenced parameter's type name. */ |
|
203 |
symbol_c *function_param_iterator_c::param_type(void) { |
|
204 |
return current_param_type; |
|
205 |
} |
|
206 |
||
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
207 |
/* Returns if currently referenced parameter is an implicit defined EN/ENO parameter. */ |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
208 |
bool function_param_iterator_c::is_en_eno_param_implicit(void) { |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
209 |
return en_eno_param_implicit; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
210 |
} |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
211 |
|
181 | 212 |
/* Returns the currently referenced parameter's data passing direction. |
213 |
* i.e. VAR_INPUT, VAR_OUTPUT or VAR_INOUT |
|
214 |
*/ |
|
215 |
function_param_iterator_c::param_direction_t function_param_iterator_c::param_direction(void) { |
|
216 |
return current_param_direction; |
|
217 |
} |
|
218 |
||
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
219 |
void *function_param_iterator_c::visit(implicit_definition_c *symbol) { |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
220 |
en_eno_param_implicit = current_operation == function_param_iterator_c::iterate_op; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
221 |
return NULL; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
222 |
} |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
223 |
|
181 | 224 |
/****************************************/ |
225 |
/* 1.4.3 - Declaration & Initialisation */ |
|
226 |
/****************************************/ |
|
227 |
void *function_param_iterator_c::visit(input_declarations_c *symbol) { |
|
228 |
TRACE("input_declarations_c"); |
|
229 |
current_param_direction = direction_in; |
|
230 |
return symbol->input_declaration_list->accept(*this); |
|
231 |
} |
|
232 |
||
233 |
void *function_param_iterator_c::visit(input_declaration_list_c *symbol) {TRACE("input_declaration_list_c"); return iterate_list(symbol);} |
|
234 |
||
235 |
void *function_param_iterator_c::visit(edge_declaration_c *symbol) {TRACE("edge_declaration_c"); return symbol->var1_list->accept(*this);} |
|
236 |
||
237 |
void *function_param_iterator_c::visit(en_param_declaration_c *symbol) { |
|
238 |
TRACE("en_param_declaration_c"); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
239 |
/* It is OK to store these values in the current_param_XXX |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
240 |
* variables, because if the desired parameter is not in the |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
241 |
* variable list we will be analysing, the current_param_XXXX |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
242 |
* variables will get overwritten when we visit the next |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
243 |
* var1_init_decl_c list! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
244 |
*/ |
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
245 |
symbol->method->accept(*this); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
246 |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
247 |
current_param_default_value = symbol->value; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
248 |
current_param_type = symbol->type; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
249 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
250 |
return handle_single_param(symbol->name); |
181 | 251 |
} |
252 |
||
253 |
/* var1_list ':' array_spec_init */ |
|
254 |
//SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
235 | 255 |
void *function_param_iterator_c::visit(array_var_init_decl_c *symbol) { |
256 |
TRACE("array_var_init_decl_c"); |
|
257 |
||
258 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->array_spec_init); |
|
259 |
current_param_type = spec_init_sperator_c::get_spec(symbol->array_spec_init); |
|
260 |
||
261 |
return symbol->var1_list->accept(*this); |
|
262 |
} |
|
181 | 263 |
|
264 |
/* var1_list ':' initialized_structure */ |
|
265 |
//SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
235 | 266 |
void *function_param_iterator_c::visit(structured_var_init_decl_c *symbol) { |
267 |
TRACE("structured_var_init_decl_c"); |
|
268 |
||
269 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->initialized_structure); |
|
270 |
current_param_type = spec_init_sperator_c::get_spec(symbol->initialized_structure); |
|
271 |
||
272 |
return symbol->var1_list->accept(*this); |
|
273 |
} |
|
181 | 274 |
|
275 |
void *function_param_iterator_c::visit(output_declarations_c *symbol) { |
|
276 |
TRACE("output_declarations_c"); |
|
277 |
current_param_direction = direction_out; |
|
278 |
return symbol->var_init_decl_list->accept(*this); |
|
279 |
} |
|
280 |
void *function_param_iterator_c::visit(eno_param_declaration_c *symbol) { |
|
281 |
TRACE("eno_param_declaration_c"); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
282 |
/* It is OK to store these values in the current_param_XXX |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
283 |
* variables, because if the desired parameter is not in the |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
284 |
* variable list we will be analysing, the current_param_XXXX |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
285 |
* variables will get overwritten when we visit the next |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
286 |
* var1_init_decl_c list! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
287 |
*/ |
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
288 |
symbol->method->accept(*this); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
289 |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
290 |
current_param_default_value = NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
291 |
current_param_type = symbol->type; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
292 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
293 |
return handle_single_param(symbol->name); |
181 | 294 |
} |
295 |
void *function_param_iterator_c::visit(input_output_declarations_c *symbol) { |
|
296 |
TRACE("input_output_declarations_c"); |
|
297 |
current_param_direction = direction_inout; |
|
298 |
return symbol->var_declaration_list->accept(*this); |
|
299 |
} |
|
300 |
void *function_param_iterator_c::visit(var_declaration_list_c *symbol) {TRACE("var_declaration_list_c"); return iterate_list(symbol);} |
|
301 |
||
302 |
/* var1_list ':' array_specification */ |
|
303 |
//SYM_REF2(array_var_declaration_c, var1_list, array_specification) |
|
237 | 304 |
void *function_param_iterator_c::visit(array_var_declaration_c *symbol) { |
305 |
TRACE("array_var_declaration_c"); |
|
306 |
||
307 |
current_param_default_value = NULL; |
|
308 |
current_param_type = symbol->array_specification; |
|
309 |
||
310 |
return symbol->var1_list->accept(*this); |
|
311 |
} |
|
181 | 312 |
|
313 |
/* var1_list ':' structure_type_name */ |
|
314 |
//SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) |
|
235 | 315 |
void *function_param_iterator_c::visit(structured_var_declaration_c *symbol) { |
316 |
TRACE("structured_var_declaration_c"); |
|
317 |
||
318 |
current_param_default_value = NULL; |
|
319 |
current_param_type = symbol->structure_type_name; |
|
320 |
||
321 |
return symbol->var1_list->accept(*this); |
|
322 |
} |
|
181 | 323 |
|
324 |
/* VAR [CONSTANT] var_init_decl_list END_VAR */ |
|
325 |
void *function_param_iterator_c::visit(var_declarations_c *symbol) {TRACE("var_declarations_c"); return NULL;} |
|
326 |
||
327 |
/*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ |
|
328 |
/* option -> may be NULL ! */ |
|
329 |
// SYM_REF2(external_var_declarations_c, option, external_declaration_list) |
|
330 |
void *function_param_iterator_c::visit(external_var_declarations_c *symbol) { |
|
331 |
TRACE("external_var_declarations_c"); |
|
332 |
current_param_direction = direction_extref; |
|
333 |
return symbol->external_declaration_list->accept(*this); |
|
334 |
} |
|
335 |
||
336 |
/* helper symbol for external_var_declarations */ |
|
337 |
/*| external_declaration_list external_declaration';' */ |
|
338 |
// SYM_LIST(external_declaration_list_c) |
|
339 |
void *function_param_iterator_c::visit(external_declaration_list_c *symbol) {TRACE("external_declaration_list_c"); return iterate_list(symbol);} |
|
340 |
||
341 |
/* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
342 |
//SYM_REF2(external_declaration_c, global_var_name, specification) |
|
343 |
void *function_param_iterator_c::visit(external_declaration_c *symbol) { |
|
344 |
TRACE("external_declaration_c"); |
|
345 |
/* It is OK to store these values in the current_param_XXX |
|
346 |
* variables, because if the desired parameter is not in the |
|
347 |
* variable list we will be analysing, the current_param_XXXX |
|
348 |
* variables will get overwritten when we visit the next |
|
349 |
* var1_init_decl_c list! |
|
350 |
*/ |
|
351 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->specification); |
|
352 |
current_param_type = spec_init_sperator_c::get_spec(symbol->specification); |
|
353 |
||
354 |
return handle_single_param(symbol->global_var_name); |
|
355 |
} |
|
356 |
||
357 |
||
358 |
#if 0 |
|
359 |
/*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ |
|
360 |
/* option -> may be NULL ! */ |
|
361 |
SYM_REF2(global_var_declarations_c, option, global_var_decl_list) |
|
362 |
||
363 |
/* helper symbol for global_var_declarations */ |
|
364 |
/*| global_var_decl_list global_var_decl ';' */ |
|
365 |
SYM_LIST(global_var_decl_list_c) |
|
366 |
||
367 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
368 |
/* type_specification ->may be NULL ! */ |
|
369 |
SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
370 |
||
371 |
/*| global_var_name location */ |
|
372 |
SYM_REF2(global_var_spec_c, global_var_name, location) |
|
373 |
||
374 |
/* AT direct_variable */ |
|
375 |
SYM_REF2(location_c, direct_variable, unused) |
|
376 |
||
377 |
/*| global_var_list ',' global_var_name */ |
|
378 |
SYM_LIST(global_var_list_c) |
|
379 |
||
380 |
/* var1_list ':' single_byte_string_spec */ |
|
381 |
SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) |
|
382 |
||
383 |
/* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ |
|
384 |
/* integer ->may be NULL ! */ |
|
385 |
/* single_byte_character_string ->may be NULL ! */ |
|
386 |
SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) |
|
387 |
||
388 |
/* var1_list ':' double_byte_string_spec */ |
|
389 |
SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) |
|
390 |
||
391 |
/* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ |
|
392 |
/* integer ->may be NULL ! */ |
|
393 |
/* double_byte_character_string ->may be NULL ! */ |
|
394 |
SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) |
|
395 |
||
396 |
/*| VAR [RETAIN|NON_RETAIN] incompl_located_var_decl_list END_VAR */ |
|
397 |
/* option ->may be NULL ! */ |
|
398 |
SYM_REF2(incompl_located_var_declarations_c, option, incompl_located_var_decl_list) |
|
399 |
||
400 |
/* helper symbol for incompl_located_var_declarations */ |
|
401 |
/*| incompl_located_var_decl_list incompl_located_var_decl ';' */ |
|
402 |
SYM_LIST(incompl_located_var_decl_list_c) |
|
403 |
||
404 |
/* variable_name incompl_location ':' var_spec */ |
|
405 |
SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) |
|
406 |
||
407 |
/* AT incompl_location_token */ |
|
408 |
SYM_TOKEN(incompl_location_c) |
|
409 |
#endif |
|
410 |
||
411 |
||
412 |
void *function_param_iterator_c::visit(var1_init_decl_c *symbol) { |
|
413 |
TRACE("var1_init_decl_c"); |
|
414 |
/* It is OK to store these values in the current_param_XXX |
|
415 |
* variables, because if the desired parameter is not in the |
|
416 |
* variable list we will be analysing, the current_param_XXXX |
|
417 |
* variables will get overwritten when we visit the next |
|
418 |
* var1_init_decl_c list! |
|
419 |
*/ |
|
420 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->spec_init); |
|
421 |
current_param_type = spec_init_sperator_c::get_spec(symbol->spec_init); |
|
422 |
||
423 |
return symbol->var1_list->accept(*this); |
|
424 |
} |
|
425 |
||
426 |
||
427 |
||
428 |
void *function_param_iterator_c::visit(var1_list_c *symbol) { |
|
429 |
TRACE("var1_list_c"); |
|
430 |
return handle_param_list(symbol); |
|
431 |
} |
|
432 |
||
433 |
void *function_param_iterator_c::visit(var_init_decl_list_c *symbol) {TRACE("var_init_decl_list_c"); return iterate_list(symbol);} |
|
434 |
||
435 |
||
436 |
/***********************/ |
|
437 |
/* B 1.5.1 - Functions */ |
|
438 |
/***********************/ |
|
439 |
void *function_param_iterator_c::visit(function_declaration_c *symbol) {TRACE("function_declaration_c"); return symbol->var_declarations_list->accept(*this);} |
|
440 |
/* intermediate helper symbol for function_declaration */ |
|
441 |
void *function_param_iterator_c::visit(var_declarations_list_c *symbol) {TRACE("var_declarations_list_c"); return iterate_list(symbol);} |
|
442 |
void *function_param_iterator_c::visit(function_var_decls_c *symbol) {TRACE("function_var_decls_c"); /* ignore */ return NULL;} |
|
443 |
||
444 |
||
445 |
/*****************************/ |
|
446 |
/* B 1.5.2 - Function Blocks */ |
|
447 |
/*****************************/ |
|
448 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
|
449 |
void *function_param_iterator_c::visit(function_block_declaration_c *symbol) {TRACE("function_block_declaration_c"); return symbol->var_declarations->accept(*this);} |
|
450 |
||
451 |
/* intermediate helper symbol for function_declaration */ |
|
452 |
/* { io_var_declarations | other_var_declarations } */ |
|
453 |
/* |
|
454 |
* NOTE: we re-use the var_declarations_list_c |
|
455 |
*/ |
|
456 |
||
457 |
/* VAR_TEMP temp_var_decl_list END_VAR */ |
|
458 |
void *function_param_iterator_c::visit(temp_var_decls_c *symbol) {TRACE("temp_var_decls_c"); /* ignore */ return NULL;} |
|
459 |
void *function_param_iterator_c::visit(temp_var_decls_list_c *symbol) {TRACE("temp_var_decls_list_c"); /* ignore */ return NULL;} |
|
460 |
||
461 |
/* VAR NON_RETAIN var_init_decl_list END_VAR */ |
|
462 |
void *function_param_iterator_c::visit(non_retentive_var_decls_c *symbol) {TRACE("non_retentive_var_decls_c"); /* ignore */ return NULL;} |
|
463 |
||
464 |
||
465 |
/**********************/ |
|
466 |
/* B 1.5.3 - Programs */ |
|
467 |
/**********************/ |
|
468 |
/* PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */ |
|
469 |
// SYM_REF4(program_declaration_c, program_type_name, var_declarations, function_block_body, unused) |
|
470 |
void *function_param_iterator_c::visit(program_declaration_c *symbol) {TRACE("program_declaration_c"); return symbol->var_declarations->accept(*this);} |
|
471 |
||
472 |
/* intermediate helper symbol for program_declaration_c */ |
|
473 |
/* { io_var_declarations | other_var_declarations } */ |
|
474 |
/* |
|
475 |
* NOTE: we re-use the var_declarations_list_c |
|
476 |
*/ |
|
477 |
||
478 |
||
479 |
||
480 |
||
481 |
||
482 |