author | Mario de Sousa <msousa@fe.up.pt> |
Sun, 15 Apr 2012 19:56:33 +0100 | |
changeset 509 | 35d391c38a30 |
parent 508 | dc6906338042 |
child 510 | 9317e04c1dde |
permissions | -rw-r--r-- |
508 | 1 |
/* |
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
|
3 |
* |
|
4 |
* Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt) |
|
5 |
* Copyright (C) 2012 Manuele Conti (conti.ma@alice.it) |
|
6 |
* |
|
7 |
* |
|
8 |
* This program is free software: you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation, either version 3 of the License, or |
|
11 |
* (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20 |
* |
|
21 |
* |
|
22 |
* This code is made available on the understanding that it will not be |
|
23 |
* used in safety-critical situations without a full and competent review. |
|
24 |
*/ |
|
25 |
||
26 |
/* |
|
27 |
* An IEC 61131-3 compiler. |
|
28 |
* |
|
29 |
* Based on the |
|
30 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
31 |
* |
|
32 |
*/ |
|
33 |
||
34 |
||
35 |
#include "lvalue_check.hh" |
|
36 |
||
37 |
#define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order) ? (symbol1) : (symbol2)) |
|
38 |
#define LAST_(symbol1, symbol2) (((symbol1)->last_order > (symbol2)->last_order) ? (symbol1) : (symbol2)) |
|
39 |
||
40 |
#define STAGE3_ERROR(error_level, symbol1, symbol2, ...) { \ |
|
41 |
if (current_display_error_level >= error_level) { \ |
|
42 |
fprintf(stderr, "%s:%d-%d..%d-%d: error: ", \ |
|
43 |
FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\ |
|
44 |
LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column);\ |
|
45 |
fprintf(stderr, __VA_ARGS__); \ |
|
46 |
fprintf(stderr, "\n"); \ |
|
47 |
error_found = true; \ |
|
48 |
} \ |
|
49 |
} |
|
50 |
||
51 |
||
52 |
#define STAGE3_WARNING(symbol1, symbol2, ...) { \ |
|
53 |
fprintf(stderr, "%s:%d-%d..%d-%d: warning: ", \ |
|
54 |
FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\ |
|
55 |
LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column);\ |
|
56 |
fprintf(stderr, __VA_ARGS__); \ |
|
57 |
fprintf(stderr, "\n"); \ |
|
58 |
warning_found = true; \ |
|
59 |
} |
|
60 |
||
61 |
||
62 |
lvalue_check_c::lvalue_check_c(symbol_c *ignore) { |
|
63 |
error_found = false; |
|
64 |
} |
|
65 |
||
66 |
lvalue_check_c::~lvalue_check_c(void) { |
|
67 |
} |
|
68 |
||
69 |
int lvalue_check_c::get_error_found() { |
|
70 |
return error_found; |
|
71 |
} |
|
72 |
||
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
73 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
74 |
#include <strings.h> |
508 | 75 |
/* No writing to iterator variables (used in FOR loops) inside the loop itself */ |
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
76 |
void lvalue_check_c::check_assignment_to_controlvar(symbol_c *lvalue) { |
508 | 77 |
for (unsigned int i = 0; i < control_variables.size(); i++) { |
78 |
symbolic_variable_c *cvar = (symbolic_variable_c *)control_variables[i]; |
|
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
79 |
if (strcasecmp(((identifier_c *)((symbolic_variable_c *)lvalue)->var_name)->value, ((identifier_c *)((symbolic_variable_c *)cvar)->var_name)->value) == 0) { |
508 | 80 |
STAGE3_ERROR(0, lvalue, lvalue, "Assignment to FOR control variable are not be allowed."); |
81 |
break; |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
||
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
86 |
|
508 | 87 |
/* fb_instance.var := ... is not valid if var is output (not input ??) variable */ |
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
88 |
void lvalue_check_c::check_assignment_to_output(symbol_c * lvalue) { |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
89 |
symbol_c *type_id = search_varfb_instance_type->get_basetype_id(lvalue); |
508 | 90 |
if (NULL != type_id) { |
91 |
function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(type_id); |
|
92 |
if (function_block_type_symtable.end_value() != fb_decl) { |
|
93 |
search_var_instance_decl_c search_var_instance_decl(fb_decl); |
|
94 |
structured_variable_c * str_var = (structured_variable_c *)lvalue; |
|
95 |
unsigned int vartype = search_var_instance_decl.get_vartype(str_var->field_selector); |
|
96 |
if (vartype == search_var_instance_decl_c::output_vt) |
|
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
97 |
STAGE3_ERROR(0, lvalue, lvalue, "Assignment to FB output field variable is not be allowed."); |
508 | 98 |
} |
99 |
} |
|
100 |
} |
|
101 |
||
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
102 |
|
508 | 103 |
/* No writing to CONSTANTs */ |
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
104 |
void lvalue_check_c::check_assignment_to_constant(symbol_c *lvalue) { |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
105 |
unsigned int option = search_var_instance_decl->get_option(lvalue); |
508 | 106 |
if (option == search_var_instance_decl_c::constant_opt) { |
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
107 |
STAGE3_ERROR(0, lvalue, lvalue, "Assignment to CONSTANT variables is not be allowed."); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
108 |
} |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
109 |
} |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
110 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
111 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
112 |
/* No assigning values to expressions. */ |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
113 |
void lvalue_check_c::check_assignment_to_expression(symbol_c *lvalue) { |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
114 |
/* TODO: check whether the lvalue is an expresion! */ |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
115 |
/* This may occur in function invocations, when passing values (possibly an expression) to one |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
116 |
* of the function's OUTPUT parameters. |
508 | 117 |
*/ |
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
118 |
} |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
119 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
120 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
121 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
122 |
void lvalue_check_c::verify_is_lvalue(symbol_c *lvalue) { |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
123 |
check_assignment_to_controlvar(lvalue); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
124 |
check_assignment_to_output(lvalue); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
125 |
check_assignment_to_constant(lvalue); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
126 |
check_assignment_to_expression(lvalue); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
127 |
} |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
128 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
129 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
130 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
131 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
132 |
/* check whether all values passed to OUT or IN_OUT parameters are legal lvalues. */ |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
133 |
void lvalue_check_c::check_nonformal_call(symbol_c *f_call, symbol_c *f_decl) { |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
134 |
/* TODO */ |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
135 |
} |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
136 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
137 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
138 |
/* check whether all values passed to OUT or IN_OUT parameters are legal lvalues. */ |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
139 |
void lvalue_check_c::check_formal_call(symbol_c *f_call, symbol_c *f_decl) { |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
140 |
/* if data type semantic verification was unable to determine which function is being called, |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
141 |
* then it does not make sense to go ahead and check for lvalues to unknown parameters. |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
142 |
* We simply bug out! |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
143 |
*/ |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
144 |
if (NULL == f_decl) return; |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
145 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
146 |
symbol_c *call_param_name; |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
147 |
function_param_iterator_c fp_iterator(f_decl); |
508 | 148 |
function_call_param_iterator_c fcp_iterator(f_call); |
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
149 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
150 |
/* Iterating through the formal parameters of the function call */ |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
151 |
while((call_param_name = fcp_iterator.next_f()) != NULL) { |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
152 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
153 |
/* Obtaining the value being passed in the function call */ |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
154 |
symbol_c *call_param_value = fcp_iterator.get_current_value(); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
155 |
if (NULL == call_param_value) ERROR; |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
156 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
157 |
/* Find the corresponding parameter in function declaration, and it's direction (IN, OUT, IN_OUT) */ |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
158 |
identifier_c *param_name = fp_iterator.search(call_param_name); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
159 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
160 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
161 |
/* We only check if 'call_param_value' is a valid lvalue if the value is being passed |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
162 |
* to a valid paramater of the function being called, and that parameter is either OUT or IN_OUT. |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
163 |
*/ |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
164 |
if ((param_name != NULL) && |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
165 |
((function_param_iterator_c::direction_out == param_direction) || (function_param_iterator_c::direction_inout == param_direction))) { |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
166 |
verify_is_lvalue(call_param_value); |
508 | 167 |
} |
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
168 |
} |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
169 |
} |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
170 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
171 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
172 |
|
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
173 |
|
508 | 174 |
|
175 |
||
176 |
||
177 |
/**************************************/ |
|
178 |
/* B 1.5 - Program organisation units */ |
|
179 |
/**************************************/ |
|
180 |
/***********************/ |
|
181 |
/* B 1.5.1 - Functions */ |
|
182 |
/***********************/ |
|
183 |
void *lvalue_check_c::visit(function_declaration_c *symbol) { |
|
184 |
search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
185 |
search_var_instance_decl = new search_var_instance_decl_c(symbol); |
|
186 |
symbol->function_body->accept(*this); |
|
187 |
delete search_varfb_instance_type; |
|
188 |
delete search_var_instance_decl; |
|
189 |
search_varfb_instance_type = NULL; |
|
190 |
search_var_instance_decl = NULL; |
|
191 |
return NULL; |
|
192 |
} |
|
193 |
||
194 |
/*****************************/ |
|
195 |
/* B 1.5.2 - Function blocks */ |
|
196 |
/*****************************/ |
|
197 |
void *lvalue_check_c::visit(function_block_declaration_c *symbol) { |
|
198 |
search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
199 |
search_var_instance_decl = new search_var_instance_decl_c(symbol); |
|
200 |
symbol->fblock_body->accept(*this); |
|
201 |
delete search_varfb_instance_type; |
|
202 |
delete search_var_instance_decl; |
|
203 |
search_varfb_instance_type = NULL; |
|
204 |
search_var_instance_decl = NULL; |
|
205 |
return NULL; |
|
206 |
} |
|
207 |
||
208 |
/**********************/ |
|
209 |
/* B 1.5.3 - Programs */ |
|
210 |
/**********************/ |
|
211 |
void *lvalue_check_c::visit(program_declaration_c *symbol) { |
|
212 |
search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
213 |
search_var_instance_decl = new search_var_instance_decl_c(symbol); |
|
214 |
symbol->function_block_body->accept(*this); |
|
215 |
delete search_varfb_instance_type; |
|
216 |
delete search_var_instance_decl; |
|
217 |
search_varfb_instance_type = NULL; |
|
218 |
search_var_instance_decl = NULL; |
|
219 |
return NULL; |
|
220 |
} |
|
221 |
||
222 |
/***************************************/ |
|
223 |
/* B.3 - Language ST (Structured Text) */ |
|
224 |
/***************************************/ |
|
225 |
/***********************/ |
|
226 |
/* B 3.1 - Expressions */ |
|
227 |
/***********************/ |
|
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
228 |
// SYM_REF3(function_invocation_c, function_name, formal_param_list, nonformal_param_list, symbol_c *called_function_declaration; int extensible_param_count; std::vector <symbol_c *> candidate_functions;) |
508 | 229 |
void *lvalue_check_c::visit(function_invocation_c *symbol) { |
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
230 |
if (NULL != symbol->formal_param_list) |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
231 |
check_formal_call(symbol, symbol->called_function_declaration); |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
232 |
if (NULL != symbol->nonformal_param_list) |
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
233 |
check_nonformal_call(symbol, symbol->called_function_declaration); |
508 | 234 |
return NULL; |
235 |
} |
|
236 |
||
237 |
/*********************************/ |
|
238 |
/* B 3.2.1 Assignment Statements */ |
|
239 |
/*********************************/ |
|
240 |
void *lvalue_check_c::visit(assignment_statement_c *symbol) { |
|
509
35d391c38a30
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents:
508
diff
changeset
|
241 |
verify_is_lvalue(symbol->l_exp); |
508 | 242 |
/* We call visit r_exp to check function_call */ |
243 |
symbol->r_exp->accept(*this); |
|
244 |
return NULL; |
|
245 |
} |
|
246 |
||
247 |
/********************************/ |
|
248 |
/* B 3.2.4 Iteration Statements */ |
|
249 |
/********************************/ |
|
250 |
void *lvalue_check_c::visit(for_statement_c *symbol) { |
|
251 |
control_variables.push_back(symbol->control_variable); |
|
252 |
symbol->statement_list->accept(*this); |
|
253 |
control_variables.pop_back(); |
|
254 |
return NULL; |
|
255 |
} |
|
256 |
||
257 |
||
258 |
||
259 |
||
260 |
||
261 |
||
262 |