absyntax_utils/add_en_eno_param_decl.hh
changeset 205 96d8b6e006f0
parent 202 da1a8186f86f
child 265 4d222f46f8cc
equal deleted inserted replaced
200:fde2d08ebaee 205:96d8b6e006f0
       
     1 /*
       
     2  * (c) 2009 Mario de Sousa
       
     3  *
       
     4  * Offered to the public under the terms of the GNU General Public License
       
     5  * as published by the Free Software Foundation; either version 2 of the
       
     6  * License, or (at your option) any later version.
       
     7  *
       
     8  * This program is distributed in the hope that it will be useful, but
       
     9  * WITHOUT ANY WARRANTY; without even the implied warranty of
       
    10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
       
    11  * Public License for more details.
       
    12  *
       
    13  * This code is made available on the understanding that it will not be
       
    14  * used in safety-critical situations without a full and competent review.
       
    15  */
       
    16 
       
    17 /*
       
    18  * An IEC 61131-3 IL and ST compiler.
       
    19  *
       
    20  * Based on the
       
    21  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
       
    22  *
       
    23  */
       
    24 
       
    25 
       
    26 /*
       
    27  * Iterate through all declared functions and Function Blocks, 
       
    28  * and, for each function/FB, add a declaration of the EN and ENO 
       
    29  * parameters, if they have not already been explicitly declared.
       
    30  *
       
    31  * EN and ENO parameters declared explicitly (by the user in the source code)
       
    32  * and implicitly (by the comnpiler, i.e. by this visitor class) may be
       
    33  * distinguished later on by the 'method' flag in the en_param_declaration_c
       
    34  * and eno_param_declaration_c objects.
       
    35  */
       
    36 
       
    37 #include "../absyntax/visitor.hh"
       
    38 
       
    39 
       
    40 class add_en_eno_param_decl_c : public null_visitor_c {
       
    41   public:
       
    42     static symbol_c *add_to(symbol_c *tree_root);
       
    43     ~add_en_eno_param_decl_c(void);
       
    44 
       
    45   private:
       
    46     /* this class is a singleton. So we need a pointer to the single instance... */
       
    47     static add_en_eno_param_decl_c *singleton;
       
    48 
       
    49     /* flags to remember whether the EN and/or ENO parameters have already
       
    50      * been explicitly declared by the user in the IEC 61131-3 source code we are parsing...
       
    51      */
       
    52     bool en_declared;
       
    53     bool eno_declared;
       
    54 
       
    55   private:
       
    56     void* iterate_list(list_c *list);
       
    57     input_declarations_c  *build_en_param (void);
       
    58     output_declarations_c *build_eno_param(void);
       
    59 
       
    60   private:
       
    61     /***************************/
       
    62     /* B 0 - Programming Model */
       
    63     /***************************/
       
    64     void *visit(library_c *symbol);
       
    65 
       
    66     /***********************/
       
    67     /* B 1.5.1 - Functions */
       
    68     /***********************/
       
    69     void *visit(function_declaration_c *symbol);
       
    70     /* intermediate helper symbol for function_declaration */
       
    71     void *visit(var_declarations_list_c *symbol);
       
    72 
       
    73     /******************************************/
       
    74     /* B 1.4.3 - Declaration & Initialisation */
       
    75     /******************************************/
       
    76     void *visit(input_declarations_c *symbol);
       
    77     void *visit(input_declaration_list_c *symbol);
       
    78     void *visit(en_param_declaration_c *symbol);
       
    79     void *visit(eno_param_declaration_c *symbol);
       
    80     void *visit(output_declarations_c *symbol);
       
    81     void *visit(var_init_decl_list_c *symbol);
       
    82 
       
    83     /*****************************/
       
    84     /* B 1.5.2 - Function Blocks */
       
    85     /*****************************/
       
    86     /*  FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */
       
    87     void *visit(function_block_declaration_c *symbol);
       
    88 
       
    89 }; // function_param_iterator_c
       
    90 
       
    91 
       
    92 
       
    93 
       
    94 
       
    95 
       
    96