ccb@202: /* msousa@265: * matiec - a compiler for the programming languages defined in IEC 61131-3 ccb@202: * msousa@265: * Copyright (C) 2009-2011 Mario de Sousa (msousa@fe.up.pt) Edouard@279: * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant ccb@202: * msousa@265: * This program is free software: you can redistribute it and/or modify msousa@265: * it under the terms of the GNU General Public License as published by msousa@265: * the Free Software Foundation, either version 3 of the License, or msousa@265: * (at your option) any later version. msousa@265: * msousa@265: * This program is distributed in the hope that it will be useful, msousa@265: * but WITHOUT ANY WARRANTY; without even the implied warranty of msousa@265: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the msousa@265: * GNU General Public License for more details. msousa@265: * msousa@265: * You should have received a copy of the GNU General Public License msousa@265: * along with this program. If not, see . msousa@265: * 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: /* msousa@265: * An IEC 61131-3 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: