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: /* Decomposes a variable instance name into its constituents, mario@181: * example: mario@181: * window.points[1].coordinate.x mario@181: * mario@181: * will succesfully return mario@181: * - window mario@181: * - points mario@181: * - coordinate mario@181: * - x mario@181: * on succesive calls to decompose_var_instance_name_c::next_part() mario@181: */ mario@181: mario@181: mario@181: mario@181: #include "../absyntax/visitor.hh" mario@181: mario@181: mario@181: mario@181: class decompose_var_instance_name_c: null_visitor_c { mario@181: laurent@382: public: laurent@382: /***********************************/ laurent@382: /* B 1.2 - Operators */ laurent@382: /***********************************/ laurent@382: static identifier_c LD_operator_name; laurent@382: static identifier_c S_operator_name; laurent@382: static identifier_c R_operator_name; laurent@382: static identifier_c S1_operator_name; laurent@382: static identifier_c R1_operator_name; laurent@382: static identifier_c CLK_operator_name; laurent@382: static identifier_c CU_operator_name; laurent@382: static identifier_c CD_operator_name; laurent@382: static identifier_c PV_operator_name; laurent@382: static identifier_c IN_operator_name; laurent@382: static identifier_c PT_operator_name; laurent@382: laurent@382: mario@181: private: mario@181: symbol_c *variable_name; mario@181: symbol_c *next_variable_name; mario@181: symbol_c *current_recursive_variable_name; mario@181: symbol_c *previously_returned_variable_name; mjsousa@826: list_c *current_array_subscript_list; mario@181: mario@181: public: mario@181: decompose_var_instance_name_c(symbol_c *variable_instance_name); mjsousa@826: /* Get the next element in the strcutured variable */ mjsousa@826: symbol_c *get_next(void); mjsousa@826: /* If the current element in the structured variable is an array, return its subscript_list, otherwise return NULL */ mjsousa@826: list_c *get_current_arraysubs_list(void); mario@181: mario@181: private: ccb@202: /*************************/ ccb@202: /* B.1 - Common elements */ ccb@202: /*************************/ ccb@202: /*******************************************/ ccb@202: /* B 1.1 - Letters, digits and identifiers */ ccb@202: /*******************************************/ ccb@202: void *visit(identifier_c *symbol); ccb@202: mario@181: /*********************/ mario@181: /* B 1.4 - Variables */ mario@181: /*********************/ mario@181: void *visit(symbolic_variable_c *symbol); ccb@202: mario@181: /********************************************/ mario@181: /* B.1.4.1 Directly Represented Variables */ mario@181: /********************************************/ mario@181: void *visit(direct_variable_c *symbol); mario@181: mario@181: /*************************************/ mario@181: /* B.1.4.2 Multi-element Variables */ mario@181: /*************************************/ mario@181: /* subscripted_variable '[' subscript_list ']' */ mario@181: // SYM_REF2(array_variable_c, subscripted_variable, subscript_list) mario@181: void *visit(array_variable_c *symbol); mario@181: mario@181: /* record_variable '.' field_selector */ mario@181: /* WARNING: input and/or output variables of function blocks mario@181: * may be accessed as fields of a tructured variable! mario@181: * Code handling a structured_variable_c must take mario@181: * this into account! mario@181: */ mario@181: //SYM_REF2(structured_variable_c, record_variable, field_selector) mario@181: void *visit(structured_variable_c *symbol); mario@181: laurent@382: /********************************/ laurent@382: /* B 2.2 - Operators */ laurent@382: /********************************/ laurent@382: void *visit(LD_operator_c *symbol); laurent@382: void *visit(S_operator_c *symbol); laurent@382: void *visit(R_operator_c *symbol); laurent@382: void *visit(S1_operator_c *symbol); laurent@382: void *visit(R1_operator_c *symbol); laurent@382: void *visit(CLK_operator_c *symbol); laurent@382: void *visit(CU_operator_c *symbol); laurent@382: void *visit(CD_operator_c *symbol); laurent@382: void *visit(PV_operator_c *symbol); laurent@382: void *visit(IN_operator_c *symbol); laurent@382: void *visit(PT_operator_c *symbol); laurent@382: mario@181: }; // decompose_var_instance_name_c mario@181: mario@181: mario@181: mario@181: