mario@181: /* msousa@265: * matiec - a compiler for the programming languages defined in IEC 61131-3 mario@181: * msousa@265: * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) Edouard@279: * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant mario@181: * 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: * mario@181: * mario@181: * This code is made available on the understanding that it will not be mario@181: * used in safety-critical situations without a full and competent review. mario@181: */ mario@181: mario@181: /* msousa@265: * An IEC 61131-3 compiler. mario@181: * mario@181: * Based on the mario@181: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) mario@181: * mario@181: */ mario@181: mario@181: mario@181: /* mario@181: * Function call parameter iterator. mario@181: * mario@181: * This is part of the 4th stage that generates mario@181: * a c++ source program equivalent to the IL and ST mario@181: * code. mario@181: */ mario@181: mario@181: mario@181: #include "../absyntax/visitor.hh" mario@181: mario@181: mario@181: mario@181: /* given a function_body_c, iterate through each ccb@202: * function/FB call in that code. mario@181: */ ccb@202: mario@181: class function_call_iterator_c : public iterator_visitor_c { mario@181: mario@181: private: mario@181: symbol_c *start_symbol; mario@181: int next_fcall, fcall_count; mario@181: symbol_c *current_fcall_name; mario@181: symbol_c *current_finvocation; mario@181: mario@181: public: mario@181: /* initialise the iterator object. mario@181: * We must be given a reference to the function declaration mario@181: * that will be analysed... mario@181: */ mario@181: function_call_iterator_c(symbol_c *symbol); mario@181: mario@181: /* Skip to the next function call. After object creation, mario@181: * the object references _before_ the first, so mario@181: * this function must be called once to get the object to mario@181: * reference the first function call... mario@181: * mario@181: * Returns the function_invocation_c! mario@181: */ mario@181: symbol_c *next(void); mario@181: mario@181: /* Returns the name of the currently referenced function invocation */ mario@181: identifier_c *fname(void); mario@181: mario@181: private: mario@181: /***************************************/ mario@181: /* B.3 - Language ST (Structured Text) */ mario@181: /***************************************/ mario@181: /***********************/ mario@181: /* B 3.1 - Expressions */ mario@181: /***********************/ mario@181: void *visit(function_invocation_c *symbol); mario@181: mario@181: /****************************************/ mario@181: /* B.2 - Language IL (Instruction List) */ mario@181: /****************************************/ mario@181: /***********************************/ mario@181: /* B 2.1 Instructions and Operands */ mario@181: /***********************************/ mario@181: mario@181: /* | function_name [il_operand_list] */ mario@181: // SYM_REF2(il_function_call_c, function_name, il_operand_list) mario@181: void *visit(il_function_call_c *symbol); mario@181: mario@181: /* | function_name '(' eol_list [il_param_list] ')' */ mario@181: // SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) mario@181: void *visit(il_formal_funct_call_c *symbol); mario@181: mario@181: }; // class function_call_iterator_c mario@181: mario@181: mario@181: mario@181: