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