stage3/array_range_check.hh
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 05 Apr 2024 13:23:53 +0200
changeset 1103 f3c6c938d5ff
parent 664 199a9f84e64c
permissions -rw-r--r--
merge
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;
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    44
    int error_count;
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    45
    int current_display_error_level;
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    46
560
13b5b7faa3d7 Renamed class, remove unused code, delete allocated objects.
mjsousa <msousa@fe.up.pt>
parents: 559
diff changeset
    47
    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
    48
    void check_bounds(array_variable_c *symbol);
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    49
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    50
  public:
560
13b5b7faa3d7 Renamed class, remove unused code, delete allocated objects.
mjsousa <msousa@fe.up.pt>
parents: 559
diff changeset
    51
    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
    52
    virtual ~array_range_check_c(void);
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    53
    int get_error_count();
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    54
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
    55
    /*************************/
99a284cec1f2 Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
Mario de Sousa <msousa@fe.up.pt>
parents: 581
diff changeset
    56
    /* 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
    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
    /**********************/
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
    /* 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
    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
    /********************************/
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
    /* 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
    63
    /********************************/
598
0b1ee7e7123b Fix stupid typos (in calculating array dimension)!
Mario de Sousa <msousa@fe.up.pt>
parents: 592
diff changeset
    64
    /* 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
    65
    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
    66
    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
    67
  
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    68
    /*********************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    69
    /* B 1.4 - Variables */
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
    /*************************************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    72
    /* B 1.4.2 - Multi-element variables */
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
    void *visit(array_variable_c *symbol);
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
    /**************************************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    77
    /* B 1.5 - Program organisation units */
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
    /***********************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    80
    /* B 1.5.1 - Functions */
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
    void *visit(function_declaration_c *symbol);
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
    /*****************************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    85
    /* B 1.5.2 - Function blocks */
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
    void *visit(function_block_declaration_c *symbol);
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
    /**********************/
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    90
    /* B 1.5.3 - Programs */
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
    void *visit(program_declaration_c *symbol);
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    93
560
13b5b7faa3d7 Renamed class, remove unused code, delete allocated objects.
mjsousa <msousa@fe.up.pt>
parents: 559
diff changeset
    94
}; /* array_range_check_c */
559
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    95
a3b8925e640c Start sematinc range check class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    96
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