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:
conti@508: /*
conti@508: * In this class we implemented all lvalue check.
conti@508: * With lvalue check we mean all semantic error about
conti@508: * assignment with wrong access
conti@508: */
conti@508:
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;
conti@508: search_base_type_c search_base_type;
msousa@510: int error_count;
conti@508: int current_display_error_level;
msousa@512: std::vector control_variables;
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);
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@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@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: