stage3/case_elements_check.hh
author Edouard Tisserant
Fri, 22 Jul 2022 09:24:12 +0200
changeset 1099 cdb045e8be20
parent 1000 556b74055518
permissions -rw-r--r--
In VARIABLES.CSV, RETAIN variable were only flagged as such for GLOBALS, now local POU variable shoud be as well.
1000
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
     1
/*
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
     3
 *
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
     4
 *  Copyright (C) 2015  Mario de Sousa (msousa@fe.up.pt)
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
     5
 *
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
     6
 *
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
     7
 *  This program is free software: you can redistribute it and/or modify
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
     8
 *  it under the terms of the GNU General Public License as published by
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
     9
 *  the Free Software Foundation, either version 3 of the License, or
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    10
 *  (at your option) any later version.
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    11
 *
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    12
 *  This program is distributed in the hope that it will be useful,
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    15
 *  GNU General Public License for more details.
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    16
 *
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    17
 *  You should have received a copy of the GNU General Public License
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    19
 *
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    20
 *
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    21
 * This code is made available on the understanding that it will not be
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    22
 * used in safety-critical situations without a full and competent review.
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    23
 */
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    24
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    25
/*
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    26
 * An IEC 61131-3 compiler.
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    27
 *
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    28
 * Based on the
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    29
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    30
 *
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    31
 */
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    32
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    33
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    34
/*
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    35
 * Case Options Checking:
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    36
 *   - Check whether the options in a case statement are repeated, either directly, or in a range.
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    37
 *       For example:
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    38
 *         case var of
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    39
 *           1: ...   <- OK
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    40
 *           2: ...   <- OK
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    41
 *           1: ...   <- OK (not an error), but produce a warning!
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    42
 *           0..8: ...<- OK (not an error), but produce a warning!
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    43
 */
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    44
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    45
#include "../absyntax_utils/absyntax_utils.hh"
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    46
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    47
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    48
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    49
class case_elements_check_c: public iterator_visitor_c {
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    50
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    51
  private:
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    52
    bool warning_found;
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    53
    int error_count;
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    54
    int current_display_error_level;
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    55
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    56
    std::vector<symbol_c *> case_elements_list;
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    57
    void check_subr_subr(symbol_c *s1, symbol_c *s2);
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    58
    void check_subr_symb(symbol_c *s1, symbol_c *s2);
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    59
    void check_symb_symb(symbol_c *s1, symbol_c *s2);
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    60
  
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    61
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    62
  public:
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    63
    case_elements_check_c(symbol_c *ignore);
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    64
    virtual ~case_elements_check_c(void);
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    65
    int get_error_count();
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    66
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    67
    /***************************************/
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    68
    /* B.3 - Language ST (Structured Text) */
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    69
    /***************************************/
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    70
    /********************/
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    71
    /* B 3.2 Statements */
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    72
    /********************/
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    73
    /********************************/
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    74
    /* B 3.2.3 Selection Statements */
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    75
    /********************************/
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    76
    void *visit(case_statement_c *symbol);
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    77
    void *visit(case_list_c      *symbol);
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    78
}; /* case_elements_check_c */
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    79
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    80
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    81
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    82
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    83
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    84
556b74055518 Add check for repeated elements in a CASE statement. Emit warnings (and not errors) if found.
mjsousa
parents:
diff changeset
    85