stage3/array_range_check.hh
author Laurent Bessard
Tue, 11 Sep 2012 01:05:24 +0200
changeset 628 fe0d516fe291
parent 598 0b1ee7e7123b
child 664 199a9f84e64c
permissions -rw-r--r--
Fix bug in SFC generated code. Action state was declared in the list of variables to debug, but wasn't stored using structure with flags. This error had side effects that makes Beremiz debug crash.
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     1
/*
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     3
 *
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     4
 *  Copyright (C) 2009-2012  Mario de Sousa (msousa@fe.up.pt)
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     5
 *  Copyright (C) 2012       Manuele Conti  (conti.ma@alice.it)
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     6
 *
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     7
 *
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     8
 *  This program is free software: you can redistribute it and/or modify
a3b8925e640c Start sematinc range 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
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    10
 *  the Free Software Foundation, either version 3 of the License, or
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    11
 *  (at your option) any later version.
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    12
 *
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    13
 *  This program is distributed in the hope that it will be useful,
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    16
 *  GNU General Public License for more details.
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    17
 *
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    20
 *
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    21
 *
a3b8925e640c Start sematinc range 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
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    23
 * used in safety-critical situations without a full and competent review.
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    24
 */
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    25
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    26
/*
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    27
 * An IEC 61131-3 compiler.
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    28
 *
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    29
 * Based on the
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    30
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    31
 *
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    32
 */
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    33
560
13b5b7faa3d7 Renamed class, remove unused code, delete allocated objects.
mjsousa <msousa@fe.up.pt>
parents: 559
diff changeset
    34
// #include <vector>
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    35
#include "../absyntax_utils/absyntax_utils.hh"
560
13b5b7faa3d7 Renamed class, remove unused code, delete allocated objects.
mjsousa <msousa@fe.up.pt>
parents: 559
diff changeset
    36
// #include "datatype_functions.hh"
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    37
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    38
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    39
560
13b5b7faa3d7 Renamed class, remove unused code, delete allocated objects.
mjsousa <msousa@fe.up.pt>
parents: 559
diff changeset
    40
class array_range_check_c: public iterator_visitor_c {
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    41
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    42
  private:
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    43
    search_varfb_instance_type_c *search_varfb_instance_type;
560
13b5b7faa3d7 Renamed class, remove unused code, delete allocated objects.
mjsousa <msousa@fe.up.pt>
parents: 559
diff changeset
    44
    // search_var_instance_decl_c *search_var_instance_decl;
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    45
    search_base_type_c search_base_type;
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    46
    int error_count;
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    47
    int current_display_error_level;
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    48
560
13b5b7faa3d7 Renamed class, remove unused code, delete allocated objects.
mjsousa <msousa@fe.up.pt>
parents: 559
diff changeset
    49
    void check_dimension_count(array_variable_c *symbol);
581
1e158dc9f9c1 Add check array out of bound.
Manuele Conti <conti.ma@alice.it>
parents: 560
diff changeset
    50
    void check_bounds(array_variable_c *symbol);
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    51
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    52
  public:
560
13b5b7faa3d7 Renamed class, remove unused code, delete allocated objects.
mjsousa <msousa@fe.up.pt>
parents: 559
diff changeset
    53
    array_range_check_c(symbol_c *ignore);
13b5b7faa3d7 Renamed class, remove unused code, delete allocated objects.
mjsousa <msousa@fe.up.pt>
parents: 559
diff changeset
    54
    virtual ~array_range_check_c(void);
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    55
    int get_error_count();
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    56
592
99a284cec1f2 Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
Mario de Sousa <msousa@fe.up.pt>
parents: 581
diff changeset
    57
    /*************************/
99a284cec1f2 Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
Mario de Sousa <msousa@fe.up.pt>
parents: 581
diff changeset
    58
    /* B.1 - Common elements */
99a284cec1f2 Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
Mario de Sousa <msousa@fe.up.pt>
parents: 581
diff changeset
    59
    /*************************/
99a284cec1f2 Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
Mario de Sousa <msousa@fe.up.pt>
parents: 581
diff changeset
    60
    /**********************/
99a284cec1f2 Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
Mario de Sousa <msousa@fe.up.pt>
parents: 581
diff changeset
    61
    /* B.1.3 - Data types */
99a284cec1f2 Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
Mario de Sousa <msousa@fe.up.pt>
parents: 581
diff changeset
    62
    /**********************/
99a284cec1f2 Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
Mario de Sousa <msousa@fe.up.pt>
parents: 581
diff changeset
    63
    /********************************/
99a284cec1f2 Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
Mario de Sousa <msousa@fe.up.pt>
parents: 581
diff changeset
    64
    /* B 1.3.3 - Derived data types */
99a284cec1f2 Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
Mario de Sousa <msousa@fe.up.pt>
parents: 581
diff changeset
    65
    /********************************/
598
0b1ee7e7123b Fix stupid typos (in calculating array dimension)!
Mario de Sousa <msousa@fe.up.pt>
parents: 592
diff changeset
    66
    /* NOTE: we may later want to move the following 2 methods to a visitor that will focus on analysing the data type declarations! */
592
99a284cec1f2 Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
Mario de Sousa <msousa@fe.up.pt>
parents: 581
diff changeset
    67
    void *visit(subrange_c *symbol);
598
0b1ee7e7123b Fix stupid typos (in calculating array dimension)!
Mario de Sousa <msousa@fe.up.pt>
parents: 592
diff changeset
    68
    void *visit(array_initial_elements_c *symbol);
592
99a284cec1f2 Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
Mario de Sousa <msousa@fe.up.pt>
parents: 581
diff changeset
    69
  
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    70
    /*********************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    71
    /* B 1.4 - Variables */
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    72
    /*********************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    73
    /*************************************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    74
    /* B 1.4.2 - Multi-element variables */
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    75
    /*************************************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    76
    void *visit(array_variable_c *symbol);
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    77
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    78
    /**************************************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    79
    /* B 1.5 - Program organisation units */
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    80
    /**************************************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    81
    /***********************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    82
    /* B 1.5.1 - Functions */
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    83
    /***********************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    84
    void *visit(function_declaration_c *symbol);
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    85
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    86
    /*****************************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    87
    /* B 1.5.2 - Function blocks */
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    88
    /*****************************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    89
    void *visit(function_block_declaration_c *symbol);
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    90
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    91
    /**********************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    92
    /* B 1.5.3 - Programs */
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    93
    /**********************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    94
    void *visit(program_declaration_c *symbol);
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    95
560
13b5b7faa3d7 Renamed class, remove unused code, delete allocated objects.
mjsousa <msousa@fe.up.pt>
parents: 559
diff changeset
    96
}; /* array_range_check_c */
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    97
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    98
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    99
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   100
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   101
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   102
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   103