conti@508: /* conti@508: * matiec - a compiler for the programming languages defined in IEC 61131-3 conti@508: * conti@508: * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt) conti@508: * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it) conti@508: * conti@508: * conti@508: * This program is free software: you can redistribute it and/or modify conti@508: * it under the terms of the GNU General Public License as published by conti@508: * the Free Software Foundation, either version 3 of the License, or conti@508: * (at your option) any later version. conti@508: * conti@508: * This program is distributed in the hope that it will be useful, conti@508: * but WITHOUT ANY WARRANTY; without even the implied warranty of conti@508: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the conti@508: * GNU General Public License for more details. conti@508: * conti@508: * You should have received a copy of the GNU General Public License conti@508: * along with this program. If not, see . conti@508: * conti@508: * conti@508: * This code is made available on the understanding that it will not be conti@508: * used in safety-critical situations without a full and competent review. conti@508: */ conti@508: conti@508: /* conti@508: * An IEC 61131-3 compiler. conti@508: * conti@508: * Based on the conti@508: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) conti@508: * conti@508: */ conti@508: conti@508: #include conti@508: #include "../absyntax_utils/absyntax_utils.hh" conti@508: #include "datatype_functions.hh" conti@508: msousa@553: msousa@553: /* Expressions on the left hand side of assignment statements have aditional restrictions on their datatype. msousa@553: * For example, they cannot be literals, CONSTANT type variables, function invocations, etc... msousa@553: * This class wil do those checks. msousa@553: * msousa@553: * Note that assignment may also be done when passing variables to OUTPUT or IN_OUT function parameters,so we check those too. conti@508: */ conti@508: msousa@553: msousa@553: conti@508: class lvalue_check_c: public iterator_visitor_c { conti@508: conti@508: private: msousa@509: search_varfb_instance_type_c *search_varfb_instance_type; msousa@509: search_var_instance_decl_c *search_var_instance_decl; msousa@510: int error_count; conti@508: int current_display_error_level; msousa@512: std::vector control_variables; msousa@528: symbol_c *current_il_operand; msousa@509: msousa@509: void verify_is_lvalue (symbol_c *lvalue); msousa@509: void check_assignment_to_controlvar(symbol_c *lvalue); msousa@509: void check_assignment_to_output (symbol_c *lvalue); msousa@509: void check_assignment_to_constant (symbol_c *lvalue); msousa@509: void check_assignment_to_expression(symbol_c *lvalue); mjsousa@845: void check_assignment_to_il_list (symbol_c *lvalue); mjsousa@845: msousa@509: void check_formal_call (symbol_c *f_call, symbol_c *f_decl); msousa@509: void check_nonformal_call(symbol_c *f_call, symbol_c *f_decl); conti@508: conti@508: conti@508: public: conti@508: lvalue_check_c(symbol_c *ignore); conti@508: virtual ~lvalue_check_c(void); msousa@510: int get_error_count(); conti@508: conti@508: /**************************************/ conti@508: /* B 1.5 - Program organisation units */ conti@508: /**************************************/ conti@508: /***********************/ conti@508: /* B 1.5.1 - Functions */ conti@508: /***********************/ conti@508: void *visit(function_declaration_c *symbol); conti@508: conti@508: /*****************************/ conti@508: /* B 1.5.2 - Function blocks */ conti@508: /*****************************/ conti@508: void *visit(function_block_declaration_c *symbol); conti@508: conti@508: /**********************/ conti@508: /* B 1.5.3 - Programs */ conti@508: /**********************/ conti@508: void *visit(program_declaration_c *symbol); conti@508: conti@527: /****************************************/ conti@527: /* B.2 - Language IL (Instruction List) */ conti@527: /****************************************/ conti@527: /***********************************/ conti@527: /* B 2.1 Instructions and Operands */ conti@527: /***********************************/ conti@527: void *visit(il_instruction_c *symbol); conti@527: void *visit(il_simple_operation_c *symbol); msousa@535: void *visit(il_function_call_c *symbol); msousa@535: void *visit(il_fb_call_c *symbol); msousa@535: void *visit(il_formal_funct_call_c *symbol); conti@527: conti@527: /*******************/ conti@527: /* B 2.2 Operators */ conti@527: /*******************/ conti@527: void *visit(ST_operator_c *symbol); conti@527: void *visit(STN_operator_c *symbol); conti@527: void *visit(S_operator_c *symbol); conti@527: void *visit(R_operator_c *symbol); conti@527: conti@508: /***************************************/ conti@508: /* B.3 - Language ST (Structured Text) */ conti@508: /***************************************/ conti@508: /***********************/ conti@508: /* B 3.1 - Expressions */ conti@508: /***********************/ conti@508: void *visit(function_invocation_c *symbol); conti@508: conti@508: /*********************************/ conti@508: /* B 3.2.1 Assignment Statements */ conti@508: /*********************************/ conti@508: void *visit(assignment_statement_c *symbol); conti@508: conti@526: /*****************************************/ conti@526: /* B 3.2.2 Subprogram Control Statements */ conti@526: /*****************************************/ conti@526: void *visit(fb_invocation_c *symbol); conti@526: conti@508: /********************************/ conti@508: /* B 3.2.4 Iteration Statements */ conti@508: /********************************/ conti@508: void *visit(for_statement_c *symbol); conti@508: conti@508: }; /* lvalue_check_c */ conti@508: conti@508: conti@508: conti@508: conti@508: conti@508: conti@508: