ccb@202: /* ccb@202: * (c) 2009 Mario de Sousa ccb@202: * ccb@202: * Offered to the public under the terms of the GNU General Public License ccb@202: * as published by the Free Software Foundation; either version 2 of the ccb@202: * License, or (at your option) any later version. ccb@202: * ccb@202: * This program is distributed in the hope that it will be useful, but ccb@202: * WITHOUT ANY WARRANTY; without even the implied warranty of ccb@202: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General ccb@202: * Public License for more details. ccb@202: * ccb@202: * This code is made available on the understanding that it will not be ccb@202: * used in safety-critical situations without a full and competent review. ccb@202: */ ccb@202: ccb@202: /* ccb@202: * An IEC 61131-3 IL and ST compiler. ccb@202: * ccb@202: * Based on the ccb@202: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) ccb@202: * ccb@202: */ ccb@202: ccb@202: ccb@202: /* ccb@202: * Iterate through all declared functions and Function Blocks, ccb@202: * and, for each function/FB, add a declaration of the EN and ENO ccb@202: * parameters, if they have not already been explicitly declared. ccb@202: * ccb@202: * EN and ENO parameters declared explicitly (by the user in the source code) ccb@202: * and implicitly (by the comnpiler, i.e. by this visitor class) may be ccb@202: * distinguished later on by the 'method' flag in the en_param_declaration_c ccb@202: * and eno_param_declaration_c objects. ccb@202: */ ccb@202: ccb@202: #include "../absyntax/visitor.hh" ccb@202: ccb@202: ccb@202: class add_en_eno_param_decl_c : public null_visitor_c { ccb@202: public: ccb@202: static symbol_c *add_to(symbol_c *tree_root); ccb@202: ~add_en_eno_param_decl_c(void); ccb@202: ccb@202: private: ccb@202: /* this class is a singleton. So we need a pointer to the single instance... */ ccb@202: static add_en_eno_param_decl_c *singleton; ccb@202: ccb@202: /* flags to remember whether the EN and/or ENO parameters have already ccb@202: * been explicitly declared by the user in the IEC 61131-3 source code we are parsing... ccb@202: */ ccb@202: bool en_declared; ccb@202: bool eno_declared; ccb@202: ccb@202: private: ccb@202: void* iterate_list(list_c *list); ccb@202: input_declarations_c *build_en_param (void); ccb@202: output_declarations_c *build_eno_param(void); ccb@202: ccb@202: private: ccb@202: /***************************/ ccb@202: /* B 0 - Programming Model */ ccb@202: /***************************/ ccb@202: void *visit(library_c *symbol); ccb@202: ccb@202: /***********************/ ccb@202: /* B 1.5.1 - Functions */ ccb@202: /***********************/ ccb@202: void *visit(function_declaration_c *symbol); ccb@202: /* intermediate helper symbol for function_declaration */ ccb@202: void *visit(var_declarations_list_c *symbol); ccb@202: ccb@202: /******************************************/ ccb@202: /* B 1.4.3 - Declaration & Initialisation */ ccb@202: /******************************************/ ccb@202: void *visit(input_declarations_c *symbol); ccb@202: void *visit(input_declaration_list_c *symbol); ccb@202: void *visit(en_param_declaration_c *symbol); ccb@202: void *visit(eno_param_declaration_c *symbol); ccb@202: void *visit(output_declarations_c *symbol); ccb@202: void *visit(var_init_decl_list_c *symbol); ccb@202: ccb@202: /*****************************/ ccb@202: /* B 1.5.2 - Function Blocks */ ccb@202: /*****************************/ ccb@202: /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ ccb@202: void *visit(function_block_declaration_c *symbol); ccb@202: ccb@202: }; // function_param_iterator_c ccb@202: ccb@202: ccb@202: ccb@202: ccb@202: ccb@202: ccb@202: