stage3/lvalue_check.cc
author Edouard Tisserant <edouard@beremiz.fr>
Fri, 05 Apr 2024 12:05:28 +0200
changeset 1100 f7cc4f6ce756
parent 971 8aee27d46208
permissions -rw-r--r--
Change STRING length from int8_t to uint8_t.

This fixes GCC warning when using DELETE function from Standard Library.
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     1
/*
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     3
 *
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     4
 *  Copyright (C) 2009-2012  Mario de Sousa (msousa@fe.up.pt)
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     5
 *  Copyright (C) 2012       Manuele Conti  (conti.ma@alice.it)
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     6
 *
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     7
 *
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     8
 *  This program is free software: you can redistribute it and/or modify
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     9
 *  it under the terms of the GNU General Public License as published by
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    10
 *  the Free Software Foundation, either version 3 of the License, or
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    11
 *  (at your option) any later version.
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    12
 *
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    13
 *  This program is distributed in the hope that it will be useful,
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    16
 *  GNU General Public License for more details.
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    17
 *
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    20
 *
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    21
 *
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    22
 * This code is made available on the understanding that it will not be
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    23
 * used in safety-critical situations without a full and competent review.
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    24
 */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    25
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    26
/*
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    27
 * An IEC 61131-3 compiler.
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    28
 *
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    29
 * Based on the
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    30
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    31
 *
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    32
 */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    33
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    34
553
b654ca7a031a Add some comments...
mjsousa <msousa@fe.up.pt>
parents: 535
diff changeset
    35
b654ca7a031a Add some comments...
mjsousa <msousa@fe.up.pt>
parents: 535
diff changeset
    36
/* Expressions on the left hand side of assignment statements have aditional restrictions on their datatype.
b654ca7a031a Add some comments...
mjsousa <msousa@fe.up.pt>
parents: 535
diff changeset
    37
 * For example, they cannot be literals, CONSTANT type variables, function invocations, etc...
b654ca7a031a Add some comments...
mjsousa <msousa@fe.up.pt>
parents: 535
diff changeset
    38
 * This class wil do those checks.
b654ca7a031a Add some comments...
mjsousa <msousa@fe.up.pt>
parents: 535
diff changeset
    39
 * 
b654ca7a031a Add some comments...
mjsousa <msousa@fe.up.pt>
parents: 535
diff changeset
    40
 * Note that assignment may also be done when passing variables to OUTPUT or IN_OUT function parameters,so we check those too.
b654ca7a031a Add some comments...
mjsousa <msousa@fe.up.pt>
parents: 535
diff changeset
    41
 */
b654ca7a031a Add some comments...
mjsousa <msousa@fe.up.pt>
parents: 535
diff changeset
    42
b654ca7a031a Add some comments...
mjsousa <msousa@fe.up.pt>
parents: 535
diff changeset
    43
b654ca7a031a Add some comments...
mjsousa <msousa@fe.up.pt>
parents: 535
diff changeset
    44
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    45
#include "lvalue_check.hh"
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    46
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    47
#define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order)   ? (symbol1) : (symbol2))
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    48
#define  LAST_(symbol1, symbol2) (((symbol1)->last_order  > (symbol2)->last_order)    ? (symbol1) : (symbol2))
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    49
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    50
#define STAGE3_ERROR(error_level, symbol1, symbol2, ...) {                                                                  \
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    51
  if (current_display_error_level >= error_level) {                                                                         \
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    52
    fprintf(stderr, "%s:%d-%d..%d-%d: error: ",                                                                             \
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    53
            FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    54
                                                 LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column);\
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    55
    fprintf(stderr, __VA_ARGS__);                                                                                           \
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    56
    fprintf(stderr, "\n");                                                                                                  \
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
    57
    error_count++;                                                                                                     \
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    58
  }                                                                                                                         \
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    59
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    60
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    61
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    62
#define STAGE3_WARNING(symbol1, symbol2, ...) {                                                                             \
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    63
    fprintf(stderr, "%s:%d-%d..%d-%d: warning: ",                                                                           \
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    64
            FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    65
                                                 LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column);\
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    66
    fprintf(stderr, __VA_ARGS__);                                                                                           \
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    67
    fprintf(stderr, "\n");                                                                                                  \
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    68
    warning_found = true;                                                                                                   \
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    69
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    70
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    71
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    72
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
    73
	error_count = 0;
555
da6e089d0006 Fix bug: initialise un-initialised variable.
mjsousa <msousa@fe.up.pt>
parents: 554
diff changeset
    74
	current_display_error_level = 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
    75
	current_il_operand = NULL;
661
f537c3315f83 Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents: 615
diff changeset
    76
	search_varfb_instance_type = NULL;
f537c3315f83 Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents: 615
diff changeset
    77
	search_var_instance_decl = NULL;
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    78
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    79
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    80
lvalue_check_c::~lvalue_check_c(void) {
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    81
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    82
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
    83
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
    84
	return error_count;
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    85
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    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
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
#include <strings.h>
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    89
/* 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
    90
void lvalue_check_c::check_assignment_to_controlvar(symbol_c *lvalue) {
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    91
	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
    92
		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
    93
		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
    94
			STAGE3_ERROR(0, lvalue, lvalue, "Assignment to FOR control variable is not allowed.");
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    95
			break;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    96
		}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    97
	}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    98
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    99
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
   100
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   101
/* 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
   102
/* 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
   103
 *       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
   104
 *       This is the reason why we have the while() loop in this function!
615
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   105
 * 
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   106
 *       Note, however, that the first record (fb_instance1 in the above example) may be an output variable!
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   107
 */
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   108
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
   109
	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
   110
519
018093957030 Add comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 518
diff changeset
   111
	/* Get the first element/record of the potentially structured variable symbol */
018093957030 Add comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 518
diff changeset
   112
	/* Note that if symbol is pointing to an expression (or simply a literal value), it will return a NULL.
018093957030 Add comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 518
diff changeset
   113
	 * Once we have implemented the check_assignment_to_expression() method, and abort calling the other checks (including this one)
018093957030 Add comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 518
diff changeset
   114
	 * when an expression is found, we may replace this check with an assertion...
018093957030 Add comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 518
diff changeset
   115
	 * if (NULL == struct_elem) ERROR;
018093957030 Add comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 518
diff changeset
   116
	 */
826
1e6bf9839ece Add capability of returning array subscript list while decomposing a struct/array variable.
mjsousa
parents: 718
diff changeset
   117
	symbol_c *struct_elem = decompose_lvalue.get_next();
518
a0a32a0c61ef Fix Segmentation fault in check_assignment_to_output lvalue method.
Conti Manuele <conti.ma@alice.it>
parents: 513
diff changeset
   118
	if (NULL == struct_elem) return;
519
018093957030 Add comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 518
diff changeset
   119
	
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   120
	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
   121
	// 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! */
718
a9f8cc778444 Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents: 661
diff changeset
   122
	symbol_c *basetype_id = search_base_type_c::get_basetype_id(/*type_id*/ type_decl);
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   123
	/* 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
   124
	 * 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
   125
	 */
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   126
	if (NULL == basetype_id) return;
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   127
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   128
	/* 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
   129
	/* 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
   130
	 *       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
   131
	 *       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
   132
	 *       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
   133
	 *       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
   134
	 */
971
8aee27d46208 Change symbtable_c -> use design pattern used by C++ standard library (STL)
mjsousa
parents: 926
diff changeset
   135
	function_block_type_symtable_t::iterator iter = function_block_type_symtable.find(basetype_id);
8aee27d46208 Change symbtable_c -> use design pattern used by C++ standard library (STL)
mjsousa
parents: 926
diff changeset
   136
	if (function_block_type_symtable.end() == iter) return;
8aee27d46208 Change symbtable_c -> use design pattern used by C++ standard library (STL)
mjsousa
parents: 926
diff changeset
   137
	function_block_declaration_c *fb_decl = iter->second;
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   138
826
1e6bf9839ece Add capability of returning array subscript list while decomposing a struct/array variable.
mjsousa
parents: 718
diff changeset
   139
	while (NULL != (struct_elem = decompose_lvalue.get_next())) {
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   140
		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
   141
		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
   142
			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
   143
			return; /* no need to carry on checking once the first error is found! */
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   144
		}
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   145
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   146
		/* 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
   147
		type_decl   = fb_search_var_instance_decl.get_decl(struct_elem);
718
a9f8cc778444 Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents: 661
diff changeset
   148
		basetype_id = search_base_type_c::get_basetype_id(type_decl);
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 509
diff changeset
   149
		if (NULL == basetype_id) return; /* same comment as above... */
971
8aee27d46208 Change symbtable_c -> use design pattern used by C++ standard library (STL)
mjsousa
parents: 926
diff changeset
   150
8aee27d46208 Change symbtable_c -> use design pattern used by C++ standard library (STL)
mjsousa
parents: 926
diff changeset
   151
		iter = function_block_type_symtable.find(basetype_id);
8aee27d46208 Change symbtable_c -> use design pattern used by C++ standard library (STL)
mjsousa
parents: 926
diff changeset
   152
		if (function_block_type_symtable.end() == iter) return; /* same comment as above... */
8aee27d46208 Change symbtable_c -> use design pattern used by C++ standard library (STL)
mjsousa
parents: 926
diff changeset
   153
		fb_decl = iter->second;  
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   154
	}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   155
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   156
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
   157
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   158
/*  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
   159
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
   160
	unsigned int option = search_var_instance_decl->get_option(lvalue);
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   161
	if (option == search_var_instance_decl_c::constant_opt) {
846
24d0be6c31f7 Change error message text so as to become more suitable to where they might occur in the source code.
mjs
parents: 845
diff changeset
   162
		STAGE3_ERROR(0, lvalue, lvalue, "Assignment to CONSTANT variables is not allowed.");
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
   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
}
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
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
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
   167
/*  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
   168
void lvalue_check_c::check_assignment_to_expression(symbol_c *lvalue) {
524
52b18b3c7490 Implement check_assignment_to_expression in lvalue_check_c class.
Conti Manuele <conti.ma@alice.it>
parents: 519
diff changeset
   169
	/* 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
   170
	 * 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
   171
	 */
525
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   172
	if ( 
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   173
	     /*********************/
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   174
	     /* B 1.2 - Constants */
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   175
	     /*********************/
926
b8538c5d0aeb in lvalue, add check for REF() fucntion invocation, and the NULL literal
mjsousa
parents: 846
diff changeset
   176
	     /*********************************/
b8538c5d0aeb in lvalue, add check for REF() fucntion invocation, and the NULL literal
mjsousa
parents: 846
diff changeset
   177
	     /* B 1.2.XX - Reference Literals */
b8538c5d0aeb in lvalue, add check for REF() fucntion invocation, and the NULL literal
mjsousa
parents: 846
diff changeset
   178
	     /*********************************/
b8538c5d0aeb in lvalue, add check for REF() fucntion invocation, and the NULL literal
mjsousa
parents: 846
diff changeset
   179
	     (typeid( *lvalue ) == typeid( ref_value_null_literal_c       )) || /* defined in IEC 61131-3 v3 - Basically the 'NULL' keyword! */
525
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
	     /* B 1.2.1 - Numeric Literals */
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   182
	     /******************************/
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   183
	     (typeid( *lvalue ) == typeid( real_c                         )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   184
	     (typeid( *lvalue ) == typeid( integer_c                      )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   185
	     (typeid( *lvalue ) == typeid( binary_integer_c               )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   186
	     (typeid( *lvalue ) == typeid( octal_integer_c                )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   187
	     (typeid( *lvalue ) == typeid( hex_integer_c                  )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   188
	     (typeid( *lvalue ) == typeid( neg_real_c                     )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   189
	     (typeid( *lvalue ) == typeid( neg_integer_c                  )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   190
	     (typeid( *lvalue ) == typeid( integer_literal_c              )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   191
	     (typeid( *lvalue ) == typeid( real_literal_c                 )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   192
	     (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
   193
	     (typeid( *lvalue ) == typeid( boolean_literal_c              )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   194
	     (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
   195
	     (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
   196
	     /*******************************/
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   197
	     /* B.1.2.2   Character Strings */
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
	     (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
   200
	     (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
   201
	     /***************************/
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   202
	     /* B 1.2.3 - Time Literals */
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
	     /************************/
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   205
	     /* B 1.2.3.1 - Duration */
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   206
	     /************************/
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   207
	     (typeid( *lvalue ) == typeid( duration_c                     )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   208
	     /************************************/
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   209
	     /* 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
   210
	     /************************************/
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   211
	     (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
   212
	     (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
   213
	     (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
   214
	     (typeid( *lvalue ) == typeid( date_literal_c                 )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   215
	     (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
   216
	     /***************************************/
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   217
	     /* B.3 - Language ST (Structured Text) */
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   218
	     /***************************************/
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   219
	     /***********************/
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   220
	     /* B 3.1 - Expressions */
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   221
	     /***********************/
926
b8538c5d0aeb in lvalue, add check for REF() fucntion invocation, and the NULL literal
mjsousa
parents: 846
diff changeset
   222
	     (typeid( *lvalue ) == typeid( ref_expression_c               )) || /* an extension to the IEC 61131-3 standard - based on the IEC 61131-3 v3 standard. Returns address of the variable! */
525
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   223
	     (typeid( *lvalue ) == typeid( or_expression_c                )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   224
	     (typeid( *lvalue ) == typeid( xor_expression_c               )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   225
	     (typeid( *lvalue ) == typeid( and_expression_c               )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   226
	     (typeid( *lvalue ) == typeid( equ_expression_c               )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   227
	     (typeid( *lvalue ) == typeid( notequ_expression_c            )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   228
	     (typeid( *lvalue ) == typeid( lt_expression_c                )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   229
	     (typeid( *lvalue ) == typeid( gt_expression_c                )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   230
	     (typeid( *lvalue ) == typeid( le_expression_c                )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   231
	     (typeid( *lvalue ) == typeid( ge_expression_c                )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   232
	     (typeid( *lvalue ) == typeid( add_expression_c               )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   233
	     (typeid( *lvalue ) == typeid( sub_expression_c               )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   234
	     (typeid( *lvalue ) == typeid( mul_expression_c               )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   235
	     (typeid( *lvalue ) == typeid( div_expression_c               )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   236
	     (typeid( *lvalue ) == typeid( mod_expression_c               )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   237
	     (typeid( *lvalue ) == typeid( power_expression_c             )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   238
	     (typeid( *lvalue ) == typeid( neg_expression_c               )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   239
	     (typeid( *lvalue ) == typeid( not_expression_c               )) ||
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   240
	     (typeid( *lvalue ) == typeid( function_invocation_c          )))
846
24d0be6c31f7 Change error message text so as to become more suitable to where they might occur in the source code.
mjs
parents: 845
diff changeset
   241
		STAGE3_ERROR(0, lvalue, lvalue, "Assignment to an expression or a literal value is not allowed.");
525
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   242
}                                                                  
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   243
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   244
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   245
845
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   246
/*  No assigning values to IL lists. */
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   247
void lvalue_check_c::check_assignment_to_il_list(symbol_c *lvalue) {
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   248
	/* This may occur in formal invocations in IL, where an embedded IL list may be used instead of a symbolic_variable
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   249
	 * when passing an IN_OUT parameter! Note that it will never occur to OUT parameters, as the syntax does not allow it,
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   250
	 * although this does not affect out algorithm here!
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   251
	 */
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   252
	if ( 
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   253
	     /****************************************/
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   254
	     /* B.2 - Language IL (Instruction List) */
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   255
	     /****************************************/
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   256
	     /***********************************/
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   257
	     /* B 2.1 Instructions and Operands */
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   258
	     /***********************************/
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   259
	     (typeid( *lvalue ) == typeid( simple_instr_list_c)))
846
24d0be6c31f7 Change error message text so as to become more suitable to where they might occur in the source code.
mjs
parents: 845
diff changeset
   260
		STAGE3_ERROR(0, lvalue, lvalue, "Assigning an IL list to an IN_OUT parameter is not allowed.");
845
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   261
}                                                                  
525
77bff42a025e Literals are also part of expressions!
Mario de Sousa <msousa@fe.up.pt>
parents: 524
diff changeset
   262
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
   263
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
   264
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
   265
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
   266
void lvalue_check_c::verify_is_lvalue(symbol_c *lvalue) {
833
27f246b35ac2 Stop lvalue check from segfaulting when coming across buggy IL code (IL operator with no operand!)
mjsousa
parents: 831
diff changeset
   267
	if (NULL == lvalue) return; // missing operand in source code being compiled. Error will be caught and reported by datatype checking!
529
629105224e57 Stop lvalue checks after finding an error in the expression.
Mario de Sousa <msousa@fe.up.pt>
parents: 528
diff changeset
   268
	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
   269
	if (error_count == init_error_count)  check_assignment_to_expression(lvalue);
845
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   270
	if (error_count == init_error_count)  check_assignment_to_il_list   (lvalue);
529
629105224e57 Stop lvalue checks after finding an error in the expression.
Mario de Sousa <msousa@fe.up.pt>
parents: 528
diff changeset
   271
	if (error_count == init_error_count)  check_assignment_to_controlvar(lvalue);
845
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   272
	if (error_count == init_error_count)  check_assignment_to_output    (lvalue);
5fa872f3d073 Add code to check if an IN_OUT variable is being passed an IL list in formal IL FB/function invocations.
mjsousa
parents: 833
diff changeset
   273
	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
   274
}
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
   275
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
   276
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
   277
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
   278
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
   279
/* 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
   280
/*
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   281
 * 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
   282
 * 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
   283
 * 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
   284
 */
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   285
#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
   286
void lvalue_check_c::check_nonformal_call(symbol_c *f_call, symbol_c *f_decl) {
828
a5f08df62002 Fix segfault when doing lvalue check of buggy IEC 61131-3 source code
mjsousa
parents: 826
diff changeset
   287
	/* if data type semantic verification was unable to determine which function is being called,
a5f08df62002 Fix segfault when doing lvalue check of buggy IEC 61131-3 source code
mjsousa
parents: 826
diff changeset
   288
	 * then it does not make sense to go ahead and check for lvalues to unknown parameters.
a5f08df62002 Fix segfault when doing lvalue check of buggy IEC 61131-3 source code
mjsousa
parents: 826
diff changeset
   289
	 * We simply bug out!
a5f08df62002 Fix segfault when doing lvalue check of buggy IEC 61131-3 source code
mjsousa
parents: 826
diff changeset
   290
	 */
a5f08df62002 Fix segfault when doing lvalue check of buggy IEC 61131-3 source code
mjsousa
parents: 826
diff changeset
   291
	if (NULL == f_decl) return;
a5f08df62002 Fix segfault when doing lvalue check of buggy IEC 61131-3 source code
mjsousa
parents: 826
diff changeset
   292
	
513
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   293
	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
   294
	identifier_c *param_name;
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   295
	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
   296
	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
   297
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   298
	/* 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
   299
	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
   300
		/* 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
   301
		 * 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
   302
		 */
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   303
		do {
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   304
			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
   305
			/* 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
   306
			/* 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
   307
			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
   308
		} 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
   309
535
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   310
		/* Determine the direction (IN, OUT, IN_OUT) of the parameter... */
513
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   311
		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
   312
		
615
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   313
		/* We only process the parameter value if the paramater itself is valid... */
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   314
		if (param_name != NULL) {
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   315
			/* If the parameter is either OUT or IN_OUT, we check if 'call_param_value' is a valid lvalue */
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   316
			if ((function_param_iterator_c::direction_out == param_direction) || (function_param_iterator_c::direction_inout == param_direction)) 
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   317
				verify_is_lvalue(call_param_value);
831
691e1cc38d3a Do lvalue check of function output parameters (since they may contain expressions inside array subscripts!)
mjsousa
parents: 828
diff changeset
   318
			/* parameter values to IN  parameters may be expressions with function invocations that must also be checked! */
691e1cc38d3a Do lvalue check of function output parameters (since they may contain expressions inside array subscripts!)
mjsousa
parents: 828
diff changeset
   319
			/* parameter values to OUT or IN_OUT parameters may contain arrays, whose subscripts contain expressions that must be checked! */
691e1cc38d3a Do lvalue check of function output parameters (since they may contain expressions inside array subscripts!)
mjsousa
parents: 828
diff changeset
   320
			call_param_value->accept(*this);  
513
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   321
		}
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   322
	}
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   323
}
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   324
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   325
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   326
99aa36a77703 Add lvalue check for non formal function invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 512
diff changeset
   327
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
   328
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
   329
  
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
   330
/* 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
   331
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
   332
	/* 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
   333
	 * 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
   334
	 * 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
   335
	 */
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
   336
	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
   337
	
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
   338
	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
   339
	function_param_iterator_c       fp_iterator(f_decl);
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   340
	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
   341
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
   342
	/* 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
   343
	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
   344
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
   345
		/* 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
   346
		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
   347
		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
   348
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
   349
		/* 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
   350
		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
   351
		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
   352
		
615
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   353
		/* We only process the parameter value if the paramater itself is valid... */
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   354
		if (param_name != NULL) {
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   355
			/* If the parameter is either OUT or IN_OUT, we check if 'call_param_value' is a valid lvalue */
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   356
			if ((function_param_iterator_c::direction_out == param_direction) || (function_param_iterator_c::direction_inout == param_direction)) 
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   357
				verify_is_lvalue(call_param_value);
831
691e1cc38d3a Do lvalue check of function output parameters (since they may contain expressions inside array subscripts!)
mjsousa
parents: 828
diff changeset
   358
			/* parameter values to IN  parameters may be expressions with function invocations that must also be checked! */
691e1cc38d3a Do lvalue check of function output parameters (since they may contain expressions inside array subscripts!)
mjsousa
parents: 828
diff changeset
   359
			/* parameter values to OUT or IN_OUT parameters may contain arrays, whose subscripts contain expressions that must be checked! */
691e1cc38d3a Do lvalue check of function output parameters (since they may contain expressions inside array subscripts!)
mjsousa
parents: 828
diff changeset
   360
			call_param_value->accept(*this);  
615
509b79602f7c Check lvalues in expressions passed to Function/FB IN parameters.
Mario de Sousa <msousa@fe.up.pt>
parents: 557
diff changeset
   361
 		}
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
   362
	}
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
   363
}
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
   364
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
   365
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
   366
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
   367
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   368
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   369
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   370
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   371
/**************************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   372
/* B 1.5 - Program organisation units */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   373
/**************************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   374
/***********************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   375
/* B 1.5.1 - Functions */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   376
/***********************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   377
void *lvalue_check_c::visit(function_declaration_c *symbol) {
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   378
	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   379
	search_var_instance_decl = new search_var_instance_decl_c(symbol);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   380
	symbol->function_body->accept(*this);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   381
	delete search_varfb_instance_type;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   382
	delete search_var_instance_decl;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   383
	search_varfb_instance_type = NULL;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   384
	search_var_instance_decl = NULL;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   385
	return NULL;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   386
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   387
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   388
/*****************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   389
/* B 1.5.2 - Function blocks */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   390
/*****************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   391
void *lvalue_check_c::visit(function_block_declaration_c *symbol) {
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   392
	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   393
	search_var_instance_decl = new search_var_instance_decl_c(symbol);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   394
	symbol->fblock_body->accept(*this);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   395
	delete search_varfb_instance_type;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   396
	delete search_var_instance_decl;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   397
	search_varfb_instance_type = NULL;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   398
	search_var_instance_decl = NULL;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   399
	return NULL;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   400
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   401
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   402
/**********************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   403
/* B 1.5.3 - Programs */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   404
/**********************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   405
void *lvalue_check_c::visit(program_declaration_c *symbol) {
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   406
	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   407
	search_var_instance_decl = new search_var_instance_decl_c(symbol);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   408
	symbol->function_block_body->accept(*this);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   409
	delete search_varfb_instance_type;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   410
	delete search_var_instance_decl;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   411
	search_varfb_instance_type = NULL;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   412
	search_var_instance_decl = NULL;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   413
	return NULL;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   414
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   415
527
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   416
/****************************************/
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   417
/* B.2 - Language IL (Instruction List) */
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   418
/****************************************/
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   419
/***********************************/
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   420
/* B 2.1 Instructions and Operands */
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   421
/***********************************/
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   422
void *lvalue_check_c::visit(il_instruction_c *symbol) {
532
cb78940b2cb8 Remove access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents: 529
diff changeset
   423
	/* il_instruction will be NULL when parsing a label with no instruction
cb78940b2cb8 Remove access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents: 529
diff changeset
   424
	 * e.g.:   label1:          <---- il_instruction = NULL!
cb78940b2cb8 Remove access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents: 529
diff changeset
   425
	 *                 LD 33
cb78940b2cb8 Remove access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents: 529
diff changeset
   426
	 *                 ...
cb78940b2cb8 Remove access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents: 529
diff changeset
   427
	 */
cb78940b2cb8 Remove access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents: 529
diff changeset
   428
	if (NULL != symbol->il_instruction)
cb78940b2cb8 Remove access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents: 529
diff changeset
   429
		symbol->il_instruction->accept(*this);
527
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   430
	return NULL;
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   431
}
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   432
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   433
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
   434
	current_il_operand = symbol->il_operand;
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   435
	symbol->il_simple_operator->accept(*this);
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   436
	current_il_operand = NULL;
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   437
	return NULL;
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   438
}
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   439
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   440
535
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   441
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   442
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   443
/* | function_name [il_operand_list] */
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   444
/* NOTE: The parameters 'called_function_declaration' and 'extensible_param_count' are used to pass data between the stage 3 and stage 4. */
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   445
// SYM_REF2(il_function_call_c, function_name, il_operand_list, symbol_c *called_function_declaration; int extensible_param_count;)
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   446
void *lvalue_check_c::visit(il_function_call_c *symbol) {
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   447
	/* The first parameter of a non formal function call in IL will be the 'current value' (i.e. the prev_il_instruction)
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   448
	 * In order to be able to handle this without coding special cases, we will simply prepend that symbol
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   449
	 * to the il_operand_list, and remove it after calling handle_function_call().
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   450
	 *
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   451
	 * However, if no further paramters are given, then il_operand_list will be NULL, and we will
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   452
	 * need to create a new object to hold the pointer to prev_il_instruction.
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   453
	 * This change will also be undone at the end of this method.
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   454
	 */
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   455
	/* TODO: Copying the location data will result in confusing error message. 
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   456
	 *       We need to make this better, by inserting code to handle this special situation explicitly!
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   457
	 */
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   458
	/* NOTE: When calling a function, using the 'current value' as the first parameter of the function invocation
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   459
	 *       implies that we can only call functions whose first parameter is IN. It would not do to pass
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   460
	 *       the 'current value' to an OUT or IN_OUT parameter.
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   461
	 *       In order to make sure that this will be caught by the check_nonformal_call() function,
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   462
	 *       we add a symbol that cannot be an lvalue; in this case, a real_c (REAL literal).
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   463
	 */
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   464
	real_c param_value(NULL);
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   465
	*((symbol_c *)(&param_value)) = *((symbol_c *)symbol); /* copy the symbol location (file, line, offset) data */
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   466
	if (NULL == symbol->il_operand_list)  symbol->il_operand_list = new il_operand_list_c;
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   467
	if (NULL == symbol->il_operand_list)  ERROR;
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   468
	((list_c *)symbol->il_operand_list)->insert_element(&param_value, 0);
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   469
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   470
	check_nonformal_call(symbol, symbol->called_function_declaration);
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   471
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   472
	/* Undo the changes to the abstract syntax tree we made above... */
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   473
	((list_c *)symbol->il_operand_list)->remove_element(0);
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   474
	if (((list_c *)symbol->il_operand_list)->n == 0) {
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   475
		/* if the list becomes empty, then that means that it did not exist before we made these changes, so we delete it! */
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   476
		delete 	symbol->il_operand_list;
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   477
		symbol->il_operand_list = NULL;
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   478
	}
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   479
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   480
	return NULL;
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   481
}
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   482
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   483
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   484
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   485
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   486
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   487
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   488
/*   il_call_operator prev_declared_fb_name
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   489
 * | il_call_operator prev_declared_fb_name '(' ')'
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   490
 * | il_call_operator prev_declared_fb_name '(' eol_list ')'
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   491
 * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   492
 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   493
 */
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   494
/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   495
// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration)
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   496
void *lvalue_check_c::visit(il_fb_call_c *symbol) {
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   497
	if (NULL != symbol->il_operand_list)  check_nonformal_call(symbol, symbol->called_fb_declaration);
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   498
	if (NULL != symbol->  il_param_list)     check_formal_call(symbol, symbol->called_fb_declaration);
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   499
	return NULL;
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   500
}
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   501
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   502
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   503
/* | function_name '(' eol_list [il_param_list] ')' */
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   504
/* NOTE: The parameter 'called_function_declaration' is used to pass data between the stage 3 and stage 4. */
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   505
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list, symbol_c *called_function_declaration; int extensible_param_count;)
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   506
void *lvalue_check_c::visit(il_formal_funct_call_c *symbol) {
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   507
	check_formal_call(symbol, symbol->called_function_declaration);
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   508
	return NULL;
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   509
}
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   510
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   511
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   512
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   513
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   514
70140bd7fe67 Add lvalue checking for IL function and FB invocations.
Mario de Sousa <msousa@fe.up.pt>
parents: 532
diff changeset
   515
527
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   516
/*******************/
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   517
/* B 2.2 Operators */
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   518
/*******************/
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   519
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
   520
	verify_is_lvalue(current_il_operand);
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   521
	return NULL;
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   522
}
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   523
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   524
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
   525
	verify_is_lvalue(current_il_operand);
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   526
	return NULL;
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   527
}
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   528
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   529
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
   530
	verify_is_lvalue(current_il_operand);
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   531
	return NULL;
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   532
}
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   533
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   534
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
   535
	verify_is_lvalue(current_il_operand);
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   536
	return NULL;
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   537
}
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   538
1d83209aabfe Start implement lvalue check in IL instruction.
Manuele Conti <conti.ma@alice.it>
parents: 526
diff changeset
   539
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   540
/***************************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   541
/* B.3 - Language ST (Structured Text) */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   542
/***************************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   543
/***********************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   544
/* B 3.1 - Expressions */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   545
/***********************/
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
   546
// 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
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   547
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
   548
	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
   549
	if (NULL != symbol->nonformal_param_list)  check_nonformal_call(symbol, symbol->called_function_declaration);
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   550
	return NULL;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   551
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   552
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   553
/*********************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   554
/* B 3.2.1 Assignment Statements */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   555
/*********************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   556
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
   557
	verify_is_lvalue(symbol->l_exp);
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   558
	/* We call visit r_exp to check function_call */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   559
	symbol->r_exp->accept(*this);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   560
	return NULL;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   561
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   562
526
6e610449861a Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents: 525
diff changeset
   563
/*****************************************/
6e610449861a Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents: 525
diff changeset
   564
/* B 3.2.2 Subprogram Control Statements */
6e610449861a Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents: 525
diff changeset
   565
/*****************************************/
6e610449861a Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents: 525
diff changeset
   566
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
   567
	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
   568
	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
   569
	return NULL;
6e610449861a Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents: 525
diff changeset
   570
}
6e610449861a Add lvalue check on fb invocation.
Manuele Conti <conti.ma@alice.it>
parents: 525
diff changeset
   571
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   572
/********************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   573
/* B 3.2.4 Iteration Statements */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   574
/********************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   575
void *lvalue_check_c::visit(for_statement_c *symbol) {
557
95a2fe60a15c Add verify_is_lvalue to control_variable in for_statement.
Manuele Conti <conti.ma@alice.it>
parents: 555
diff changeset
   576
        verify_is_lvalue(symbol->control_variable);
512
f915ab676d7e Fixing check for assingment to FOR control variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 510
diff changeset
   577
	control_variables.push_back(get_var_name_c::get_name(symbol->control_variable));
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   578
	symbol->statement_list->accept(*this);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   579
	control_variables.pop_back();
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   580
	return NULL;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   581
}
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   582
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   583
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   584
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   585
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   586
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   587
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   588