author | Mario de Sousa <msousa@fe.up.pt> |
Tue, 24 Apr 2012 19:17:53 +0100 | |
changeset 530 | 1eacd7afcab1 |
parent 529 | 629105224e57 |
child 532 | cb78940b2cb8 |
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"); \ |
|
510
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
47 |
error_count++; \ |
508 | 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) { |
|
510
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
63 |
error_count = 0; |
528
6510ee2eaab9
Remove erroneous check for S1 and R1, and add missing declrataion.
Mario de Sousa <msousa@fe.up.pt>
parents:
527
diff
changeset
|
64 |
current_il_operand = NULL; |
508 | 65 |
} |
66 |
||
67 |
lvalue_check_c::~lvalue_check_c(void) { |
|
68 |
} |
|
69 |
||
510
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
70 |
int lvalue_check_c::get_error_count() { |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
71 |
return error_count; |
508 | 72 |
} |
73 |
||
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
|
74 |
|
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
|
75 |
#include <strings.h> |
508 | 76 |
/* 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
|
77 |
void lvalue_check_c::check_assignment_to_controlvar(symbol_c *lvalue) { |
508 | 78 |
for (unsigned int i = 0; i < control_variables.size(); i++) { |
512
f915ab676d7e
Fixing check for assingment to FOR control variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
510
diff
changeset
|
79 |
token_c *lvalue_name = get_var_name_c::get_name(lvalue); |
f915ab676d7e
Fixing check for assingment to FOR control variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
510
diff
changeset
|
80 |
if (compare_identifiers(lvalue_name, control_variables[i]) == 0) { |
f915ab676d7e
Fixing check for assingment to FOR control variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
510
diff
changeset
|
81 |
STAGE3_ERROR(0, lvalue, lvalue, "Assignment to FOR control variable is not allowed."); |
508 | 82 |
break; |
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
||
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
|
87 |
|
510
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
88 |
/* fb_instance.var := ... is not valid if var is output variable */ |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
89 |
/* NOTE, if a fb_instance1.fb_instance2.fb_instance3.var is used, we must iteratively check that none of the |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
90 |
* FB records are declared as OUTPUT variables!! |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
91 |
* This is the reason why we have the while() loop in this function! |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
92 |
*/ |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
93 |
void lvalue_check_c::check_assignment_to_output(symbol_c *lvalue) { |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
94 |
decompose_var_instance_name_c decompose_lvalue(lvalue); |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
95 |
search_base_type_c search_base_type; |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
96 |
|
519 | 97 |
/* Get the first element/record of the potentially structured variable symbol */ |
98 |
/* Note that if symbol is pointing to an expression (or simply a literal value), it will return a NULL. |
|
99 |
* Once we have implemented the check_assignment_to_expression() method, and abort calling the other checks (including this one) |
|
100 |
* when an expression is found, we may replace this check with an assertion... |
|
101 |
* if (NULL == struct_elem) ERROR; |
|
102 |
*/ |
|
510
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
103 |
symbol_c *struct_elem = decompose_lvalue.next_part(); |
518
a0a32a0c61ef
Fix Segmentation fault in check_assignment_to_output lvalue method.
Conti Manuele <conti.ma@alice.it>
parents:
513
diff
changeset
|
104 |
if (NULL == struct_elem) return; |
519 | 105 |
|
510
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
106 |
symbol_c *type_decl = search_var_instance_decl->get_decl(struct_elem); |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
107 |
// symbol_c *type_id = spec_init_sperator_c::get_spec(type_decl); /* this is not required! search_base_type_c can handle spec_init symbols! */ |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
108 |
symbol_c *basetype_id = search_base_type.get_basetype_id(/*type_id*/ type_decl); |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
109 |
/* If we can not determine the data type of the element, then the code must have a data type semantic error. |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
110 |
* This will have been caught by the data type semantic verifier, so we do not bother with this anymore! |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
111 |
*/ |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
112 |
if (NULL == basetype_id) return; |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
113 |
|
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
114 |
/* Determine if the record/structure element is of a FB type. */ |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
115 |
/* NOTE: If the structure element is not a FB type, then we can quit this check. |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
116 |
* Remember that the standard does not allow a STRUCT data type to have elements that are FB instances! |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
117 |
* Similarly, arrays of FB instances is also not allowed. |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
118 |
* So, as soon as we find one record/structure element that is not a FB, no other record/structure element |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
119 |
* will be of FB type, which means we can quit this check! |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
120 |
*/ |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
121 |
function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(basetype_id); |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
122 |
if (function_block_type_symtable.end_value() == fb_decl) return; |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
123 |
|
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
124 |
while (NULL != (struct_elem = decompose_lvalue.next_part())) { |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
125 |
search_var_instance_decl_c fb_search_var_instance_decl(fb_decl); |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
126 |
if (search_var_instance_decl_c::output_vt == fb_search_var_instance_decl.get_vartype(struct_elem)) { |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
127 |
STAGE3_ERROR(0, struct_elem, struct_elem, "Assignment to FB output variable is not allowed."); |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
128 |
return; /* no need to carry on checking once the first error is found! */ |
508 | 129 |
} |
510
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
130 |
|
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
131 |
/* prepare for any possible further record/structure elements */ |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
132 |
type_decl = fb_search_var_instance_decl.get_decl(struct_elem); |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
133 |
basetype_id = search_base_type.get_basetype_id(type_decl); |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
134 |
if (NULL == basetype_id) return; /* same comment as above... */ |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
135 |
fb_decl = function_block_type_symtable.find_value(basetype_id); |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
136 |
if (function_block_type_symtable.end_value() == fb_decl) return; /* same comment as above... */ |
508 | 137 |
} |
138 |
} |
|
139 |
||
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
|
140 |
|
508 | 141 |
/* 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
|
142 |
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
|
143 |
unsigned int option = search_var_instance_decl->get_option(lvalue); |
508 | 144 |
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
|
145 |
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
|
146 |
} |
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 |
} |
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
|
148 |
|
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 |
/* 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
|
151 |
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
|
152 |
/* This may occur in function invocations, when passing values (possibly an expression) to one |
510
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
153 |
* of the function's OUTPUT or IN_OUT parameters. |
508 | 154 |
*/ |
524
52b18b3c7490
Implement check_assignment_to_expression in lvalue_check_c class.
Conti Manuele <conti.ma@alice.it>
parents:
519
diff
changeset
|
155 |
/* This may occur in function invocations, when passing values (possibly an expression) to one |
52b18b3c7490
Implement check_assignment_to_expression in lvalue_check_c class.
Conti Manuele <conti.ma@alice.it>
parents:
519
diff
changeset
|
156 |
* of the function's OUTPUT or IN_OUT parameters. |
52b18b3c7490
Implement check_assignment_to_expression in lvalue_check_c class.
Conti Manuele <conti.ma@alice.it>
parents:
519
diff
changeset
|
157 |
*/ |
525
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
158 |
if ( |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
159 |
/*********************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
160 |
/* B 1.2 - Constants */ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
161 |
/*********************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
162 |
/******************************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
163 |
/* B 1.2.1 - Numeric Literals */ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
164 |
/******************************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
165 |
(typeid( *lvalue ) == typeid( real_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
166 |
(typeid( *lvalue ) == typeid( integer_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
167 |
(typeid( *lvalue ) == typeid( binary_integer_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
168 |
(typeid( *lvalue ) == typeid( octal_integer_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
169 |
(typeid( *lvalue ) == typeid( hex_integer_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
170 |
(typeid( *lvalue ) == typeid( neg_real_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
171 |
(typeid( *lvalue ) == typeid( neg_integer_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
172 |
(typeid( *lvalue ) == typeid( integer_literal_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
173 |
(typeid( *lvalue ) == typeid( real_literal_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
174 |
(typeid( *lvalue ) == typeid( bit_string_literal_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
175 |
(typeid( *lvalue ) == typeid( boolean_literal_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
176 |
(typeid( *lvalue ) == typeid( boolean_true_c )) || /* should not really be needed */ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
177 |
(typeid( *lvalue ) == typeid( boolean_false_c )) || /* should not really be needed */ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
178 |
/*******************************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
179 |
/* B.1.2.2 Character Strings */ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
180 |
/*******************************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
181 |
(typeid( *lvalue ) == typeid( double_byte_character_string_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
182 |
(typeid( *lvalue ) == typeid( single_byte_character_string_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
183 |
/***************************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
184 |
/* B 1.2.3 - Time Literals */ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
185 |
/***************************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
186 |
/************************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
187 |
/* B 1.2.3.1 - Duration */ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
188 |
/************************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
189 |
(typeid( *lvalue ) == typeid( duration_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
190 |
/************************************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
191 |
/* B 1.2.3.2 - Time of day and Date */ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
192 |
/************************************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
193 |
(typeid( *lvalue ) == typeid( time_of_day_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
194 |
(typeid( *lvalue ) == typeid( daytime_c )) || /* should not really be needed */ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
195 |
(typeid( *lvalue ) == typeid( date_c )) || /* should not really be needed */ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
196 |
(typeid( *lvalue ) == typeid( date_literal_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
197 |
(typeid( *lvalue ) == typeid( date_and_time_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
198 |
/***************************************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
199 |
/* B.3 - Language ST (Structured Text) */ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
200 |
/***************************************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
201 |
/***********************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
202 |
/* B 3.1 - Expressions */ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
203 |
/***********************/ |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
204 |
(typeid( *lvalue ) == typeid( or_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
205 |
(typeid( *lvalue ) == typeid( xor_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
206 |
(typeid( *lvalue ) == typeid( and_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
207 |
(typeid( *lvalue ) == typeid( equ_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
208 |
(typeid( *lvalue ) == typeid( notequ_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
209 |
(typeid( *lvalue ) == typeid( lt_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
210 |
(typeid( *lvalue ) == typeid( gt_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
211 |
(typeid( *lvalue ) == typeid( le_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
212 |
(typeid( *lvalue ) == typeid( ge_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
213 |
(typeid( *lvalue ) == typeid( add_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
214 |
(typeid( *lvalue ) == typeid( sub_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
215 |
(typeid( *lvalue ) == typeid( mul_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
216 |
(typeid( *lvalue ) == typeid( div_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
217 |
(typeid( *lvalue ) == typeid( mod_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
218 |
(typeid( *lvalue ) == typeid( power_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
219 |
(typeid( *lvalue ) == typeid( neg_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
220 |
(typeid( *lvalue ) == typeid( not_expression_c )) || |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
221 |
(typeid( *lvalue ) == typeid( function_invocation_c ))) |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
222 |
STAGE3_ERROR(0, lvalue, lvalue, "Assigning an expression to an OUT or IN_OUT parameter is not allowed."); |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
223 |
} |
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
224 |
|
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
225 |
|
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
226 |
|
77bff42a025e
Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents:
524
diff
changeset
|
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 |
|
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
|
229 |
|
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 |
|
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 |
void lvalue_check_c::verify_is_lvalue(symbol_c *lvalue) { |
529
629105224e57
Stop lvalue checks after finding an error in the expression.
Mario de Sousa <msousa@fe.up.pt>
parents:
528
diff
changeset
|
232 |
int init_error_count = error_count; /* stop the checks once an error has been found... */ |
629105224e57
Stop lvalue checks after finding an error in the expression.
Mario de Sousa <msousa@fe.up.pt>
parents:
528
diff
changeset
|
233 |
if (error_count == init_error_count) check_assignment_to_expression(lvalue); |
629105224e57
Stop lvalue checks after finding an error in the expression.
Mario de Sousa <msousa@fe.up.pt>
parents:
528
diff
changeset
|
234 |
if (error_count == init_error_count) check_assignment_to_controlvar(lvalue); |
629105224e57
Stop lvalue checks after finding an error in the expression.
Mario de Sousa <msousa@fe.up.pt>
parents:
528
diff
changeset
|
235 |
if (error_count == init_error_count) check_assignment_to_output(lvalue); |
629105224e57
Stop lvalue checks after finding an error in the expression.
Mario de Sousa <msousa@fe.up.pt>
parents:
528
diff
changeset
|
236 |
if (error_count == init_error_count) check_assignment_to_constant(lvalue); |
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
|
237 |
} |
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
|
238 |
|
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
|
239 |
|
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
|
240 |
|
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 |
|
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
|
242 |
/* check whether all values passed to OUT or IN_OUT parameters are legal lvalues. */ |
513
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
243 |
/* |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
244 |
* All parameters being passed to the called function MUST be in the parameter list to which f_call points to! |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
245 |
* This means that, for non formal function calls in IL, de current (default value) must be artificially added to the |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
246 |
* beginning of the parameter list BEFORE calling handle_function_call(). |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
247 |
*/ |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
248 |
#include <string.h> /* required for strcmp() */ |
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
|
249 |
void lvalue_check_c::check_nonformal_call(symbol_c *f_call, symbol_c *f_decl) { |
513
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
250 |
symbol_c *call_param_value; |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
251 |
identifier_c *param_name; |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
252 |
function_param_iterator_c fp_iterator(f_decl); |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
253 |
function_call_param_iterator_c fcp_iterator(f_call); |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
254 |
|
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
255 |
/* Iterating through the non-formal parameters of the function call */ |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
256 |
while((call_param_value = fcp_iterator.next_nf()) != NULL) { |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
257 |
/* Iterate to the next parameter of the function being called. |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
258 |
* Get the name of that parameter, and ignore if EN or ENO. |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
259 |
*/ |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
260 |
do { |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
261 |
param_name = fp_iterator.next(); |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
262 |
/* If there is no other parameter declared, then we are passing too many parameters... */ |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
263 |
/* This error should have been caught in data type verification, so we simply abandon our check! */ |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
264 |
if(param_name == NULL) return; |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
265 |
} while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0)); |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
266 |
|
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
267 |
/* Find the corresponding parameter in function declaration, and it's direction (IN, OUT, IN_OUT) */ |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
268 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
269 |
|
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
270 |
/* We only check if 'call_param_value' is a valid lvalue if the value is being passed |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
271 |
* to a valid paramater of the function being called, and that parameter is either OUT or IN_OUT. |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
272 |
*/ |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
273 |
if ((param_name != NULL) && ((function_param_iterator_c::direction_out == param_direction) || (function_param_iterator_c::direction_inout == param_direction))) { |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
274 |
verify_is_lvalue(call_param_value); |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
275 |
} |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
276 |
} |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
277 |
} |
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
278 |
|
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
279 |
|
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
280 |
|
99aa36a77703
Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents:
512
diff
changeset
|
281 |
|
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
|
282 |
|
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
|
283 |
|
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
|
284 |
/* 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
|
285 |
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
|
286 |
/* 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
|
287 |
* 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
|
288 |
* 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
|
289 |
*/ |
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
|
290 |
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
|
291 |
|
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
|
292 |
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
|
293 |
function_param_iterator_c fp_iterator(f_decl); |
508 | 294 |
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
|
295 |
|
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
|
296 |
/* 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
|
297 |
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
|
298 |
|
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
|
299 |
/* 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
|
300 |
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
|
301 |
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
|
302 |
|
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
|
303 |
/* 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
|
304 |
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
|
305 |
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
|
306 |
|
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
|
307 |
/* 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
|
308 |
* 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
|
309 |
*/ |
510
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
310 |
if ((param_name != NULL) && ((function_param_iterator_c::direction_out == param_direction) || (function_param_iterator_c::direction_inout == param_direction))) { |
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
|
311 |
verify_is_lvalue(call_param_value); |
508 | 312 |
} |
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
|
313 |
} |
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
|
314 |
} |
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
|
315 |
|
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
|
316 |
|
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
|
317 |
|
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
|
318 |
|
508 | 319 |
|
320 |
||
321 |
||
322 |
/**************************************/ |
|
323 |
/* B 1.5 - Program organisation units */ |
|
324 |
/**************************************/ |
|
325 |
/***********************/ |
|
326 |
/* B 1.5.1 - Functions */ |
|
327 |
/***********************/ |
|
328 |
void *lvalue_check_c::visit(function_declaration_c *symbol) { |
|
329 |
search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
330 |
search_var_instance_decl = new search_var_instance_decl_c(symbol); |
|
331 |
symbol->function_body->accept(*this); |
|
332 |
delete search_varfb_instance_type; |
|
333 |
delete search_var_instance_decl; |
|
334 |
search_varfb_instance_type = NULL; |
|
335 |
search_var_instance_decl = NULL; |
|
336 |
return NULL; |
|
337 |
} |
|
338 |
||
339 |
/*****************************/ |
|
340 |
/* B 1.5.2 - Function blocks */ |
|
341 |
/*****************************/ |
|
342 |
void *lvalue_check_c::visit(function_block_declaration_c *symbol) { |
|
343 |
search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
344 |
search_var_instance_decl = new search_var_instance_decl_c(symbol); |
|
345 |
symbol->fblock_body->accept(*this); |
|
346 |
delete search_varfb_instance_type; |
|
347 |
delete search_var_instance_decl; |
|
348 |
search_varfb_instance_type = NULL; |
|
349 |
search_var_instance_decl = NULL; |
|
350 |
return NULL; |
|
351 |
} |
|
352 |
||
353 |
/**********************/ |
|
354 |
/* B 1.5.3 - Programs */ |
|
355 |
/**********************/ |
|
356 |
void *lvalue_check_c::visit(program_declaration_c *symbol) { |
|
357 |
search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
358 |
search_var_instance_decl = new search_var_instance_decl_c(symbol); |
|
359 |
symbol->function_block_body->accept(*this); |
|
360 |
delete search_varfb_instance_type; |
|
361 |
delete search_var_instance_decl; |
|
362 |
search_varfb_instance_type = NULL; |
|
363 |
search_var_instance_decl = NULL; |
|
364 |
return NULL; |
|
365 |
} |
|
366 |
||
527
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
367 |
/****************************************/ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
368 |
/* B.2 - Language IL (Instruction List) */ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
369 |
/****************************************/ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
370 |
/***********************************/ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
371 |
/* B 2.1 Instructions and Operands */ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
372 |
/***********************************/ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
373 |
void *lvalue_check_c::visit(il_instruction_c *symbol) { |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
374 |
symbol->il_instruction->accept(*this); |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
375 |
return NULL; |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
376 |
} |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
377 |
|
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
378 |
void *lvalue_check_c::visit(il_simple_operation_c *symbol) { |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
379 |
/* recursive call to fill the candidate data types list */ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
380 |
current_il_operand = symbol->il_operand; |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
381 |
symbol->il_simple_operator->accept(*this); |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
382 |
current_il_operand = NULL; |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
383 |
return NULL; |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
384 |
} |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
385 |
|
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
386 |
|
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
387 |
/*******************/ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
388 |
/* B 2.2 Operators */ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
389 |
/*******************/ |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
390 |
void *lvalue_check_c::visit(ST_operator_c *symbol) { |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
391 |
verify_is_lvalue(current_il_operand); |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
392 |
return NULL; |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
393 |
} |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
394 |
|
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
395 |
void *lvalue_check_c::visit(STN_operator_c *symbol) { |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
396 |
verify_is_lvalue(current_il_operand); |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
397 |
return NULL; |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
398 |
} |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
399 |
|
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
400 |
void *lvalue_check_c::visit(S_operator_c *symbol) { |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
401 |
verify_is_lvalue(current_il_operand); |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
402 |
return NULL; |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
403 |
} |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
404 |
|
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
405 |
void *lvalue_check_c::visit(R_operator_c *symbol) { |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
406 |
verify_is_lvalue(current_il_operand); |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
407 |
return NULL; |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
408 |
} |
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
409 |
|
1d83209aabfe
Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents:
526
diff
changeset
|
410 |
|
508 | 411 |
/***************************************/ |
412 |
/* B.3 - Language ST (Structured Text) */ |
|
413 |
/***************************************/ |
|
414 |
/***********************/ |
|
415 |
/* B 3.1 - Expressions */ |
|
416 |
/***********************/ |
|
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
|
417 |
// 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 | 418 |
void *lvalue_check_c::visit(function_invocation_c *symbol) { |
510
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
419 |
if (NULL != symbol->formal_param_list ) check_formal_call (symbol, symbol->called_function_declaration); |
9317e04c1dde
Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
509
diff
changeset
|
420 |
if (NULL != symbol->nonformal_param_list) check_nonformal_call(symbol, symbol->called_function_declaration); |
508 | 421 |
return NULL; |
422 |
} |
|
423 |
||
424 |
/*********************************/ |
|
425 |
/* B 3.2.1 Assignment Statements */ |
|
426 |
/*********************************/ |
|
427 |
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
|
428 |
verify_is_lvalue(symbol->l_exp); |
508 | 429 |
/* We call visit r_exp to check function_call */ |
430 |
symbol->r_exp->accept(*this); |
|
431 |
return NULL; |
|
432 |
} |
|
433 |
||
526
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
525
diff
changeset
|
434 |
/*****************************************/ |
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
525
diff
changeset
|
435 |
/* B 3.2.2 Subprogram Control Statements */ |
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
525
diff
changeset
|
436 |
/*****************************************/ |
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
525
diff
changeset
|
437 |
void *lvalue_check_c::visit(fb_invocation_c *symbol) { |
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
525
diff
changeset
|
438 |
if (NULL != symbol->formal_param_list ) check_formal_call (symbol, symbol->called_fb_declaration); |
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
525
diff
changeset
|
439 |
if (NULL != symbol->nonformal_param_list) check_nonformal_call(symbol, symbol->called_fb_declaration); |
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
525
diff
changeset
|
440 |
return NULL; |
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
525
diff
changeset
|
441 |
} |
6e610449861a
Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents:
525
diff
changeset
|
442 |
|
508 | 443 |
/********************************/ |
444 |
/* B 3.2.4 Iteration Statements */ |
|
445 |
/********************************/ |
|
446 |
void *lvalue_check_c::visit(for_statement_c *symbol) { |
|
512
f915ab676d7e
Fixing check for assingment to FOR control variables.
Mario de Sousa <msousa@fe.up.pt>
parents:
510
diff
changeset
|
447 |
control_variables.push_back(get_var_name_c::get_name(symbol->control_variable)); |
508 | 448 |
symbol->statement_list->accept(*this); |
449 |
control_variables.pop_back(); |
|
450 |
return NULL; |
|
451 |
} |
|
452 |
||
453 |
||
454 |
||
455 |
||
456 |
||
457 |
||
458 |