stage3/lvalue_check.hh
author Mario de Sousa <msousa@fe.up.pt>
Sun, 15 Apr 2012 19:56:33 +0100
changeset 509 35d391c38a30
parent 508 dc6906338042
child 510 9317e04c1dde
permissions -rw-r--r--
Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
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
#include <vector>
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    35
#include "../absyntax_utils/absyntax_utils.hh"
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    36
#include "datatype_functions.hh"
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    37
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    38
/*
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    39
 *  In this class we implemented all lvalue check.
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    40
 *  With lvalue check we mean all semantic error about
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    41
 *  assignment with wrong access
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    42
 */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    43
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    44
class lvalue_check_c: public iterator_visitor_c {
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    45
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    46
  private:
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
    47
    search_varfb_instance_type_c *search_varfb_instance_type;
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
    48
    search_var_instance_decl_c *search_var_instance_decl;
508
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    49
    search_base_type_c search_base_type;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    50
    int error_found;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    51
    int current_display_error_level;
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    52
    std::vector <symbol_c *> control_variables;
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
    53
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
    54
    void verify_is_lvalue              (symbol_c *lvalue);
35d391c38a30 Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents: 508
diff changeset
    55
    void check_assignment_to_controlvar(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
    56
    void check_assignment_to_output    (symbol_c *lvalue);
35d391c38a30 Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents: 508
diff changeset
    57
    void 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
    58
    void check_assignment_to_expression(symbol_c *lvalue);
35d391c38a30 Fixing some bugs in lvalue checking (other bugs remain - to be fixed later)
Mario de Sousa <msousa@fe.up.pt>
parents: 508
diff changeset
    59
    void 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
    60
    void check_nonformal_call(symbol_c *f_call, symbol_c *f_decl);
508
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
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    63
  public:
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    64
    lvalue_check_c(symbol_c *ignore);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    65
    virtual ~lvalue_check_c(void);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    66
    int get_error_found();
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    67
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    68
    /**************************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    69
    /* B 1.5 - Program organisation units */
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
    /* B 1.5.1 - Functions */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    73
    /***********************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    74
    void *visit(function_declaration_c *symbol);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    75
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    76
    /*****************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    77
    /* B 1.5.2 - Function blocks */
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
    void *visit(function_block_declaration_c *symbol);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    80
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
    /* B 1.5.3 - Programs */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    83
    /**********************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    84
    void *visit(program_declaration_c *symbol);
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
    /***************************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    87
    /* B.3 - Language ST (Structured Text) */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    88
    /***************************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    89
    /***********************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    90
    /* B 3.1 - Expressions */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    91
    /***********************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    92
    void *visit(function_invocation_c *symbol);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    93
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    94
    /*********************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    95
    /* B 3.2.1 Assignment Statements */
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
    void *visit(assignment_statement_c *symbol);
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
    /********************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   100
    /* B 3.2.4 Iteration Statements */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   101
    /********************************/
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   102
    void *visit(for_statement_c *symbol);
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   103
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   104
}; /* lvalue_check_c */
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   105
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   106
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   107
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   108
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   109
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   110
dc6906338042 Add lvalue check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   111