laurent@347: /* laurent@347: * matiec - a compiler for the programming languages defined in IEC 61131-3 laurent@347: * laurent@347: * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) laurent@347: * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant laurent@347: * laurent@347: * This program is free software: you can redistribute it and/or modify laurent@347: * it under the terms of the GNU General Public License as published by laurent@347: * the Free Software Foundation, either version 3 of the License, or laurent@347: * (at your option) any later version. laurent@347: * laurent@347: * This program is distributed in the hope that it will be useful, laurent@347: * but WITHOUT ANY WARRANTY; without even the implied warranty of laurent@347: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the laurent@347: * GNU General Public License for more details. laurent@347: * laurent@347: * You should have received a copy of the GNU General Public License laurent@347: * along with this program. If not, see . laurent@347: * laurent@347: * laurent@347: * This code is made available on the understanding that it will not be laurent@347: * used in safety-critical situations without a full and competent review. laurent@347: */ laurent@347: laurent@347: /* laurent@347: * An IEC 61131-3 compiler. laurent@347: * laurent@347: * Based on the laurent@347: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) laurent@347: * laurent@347: */ laurent@347: laurent@347: laurent@347: /* laurent@347: * Case element iterator. laurent@347: * Iterate through the elements of a case list. laurent@347: * laurent@347: * This is part of the 4th stage that generates laurent@347: * a c++ source program equivalent to the IL and ST laurent@347: * code. laurent@347: */ laurent@347: laurent@347: /* Given a case_list_c and a type of element, iterate through laurent@347: * each element, returning the symbol of each element if from laurent@347: * the good type...case_element_iterator_c laurent@347: */ laurent@347: laurent@347: laurent@347: #include "../absyntax/visitor.hh" laurent@347: laurent@347: laurent@347: class case_element_iterator_c : public null_visitor_c { laurent@347: public: laurent@347: /* A type to specify the type of element. laurent@347: */ laurent@347: typedef enum { laurent@347: element_single, conti@661: element_subrange laurent@347: } case_element_t ; laurent@347: laurent@347: laurent@347: private: laurent@377: /* a pointer to the case_list_c currently being analyzed */ laurent@347: symbol_c *case_list; laurent@347: /* used when called to iterate() for a parameter */ laurent@347: symbol_c *current_case_element; laurent@347: laurent@347: /* used to indicate the type of case element on which iterate */ laurent@347: case_element_t wanted_element_type; laurent@347: laurent@347: private: laurent@347: void* handle_case_element(symbol_c *case_element); laurent@347: laurent@347: void* iterate_list(list_c *list); laurent@347: laurent@347: public: laurent@347: /* start off at the first case element once again... */ laurent@347: void reset(void); laurent@347: laurent@377: /* initialize the iterator object. laurent@377: * We must be given a reference to a case_list_c that will be analyzed... laurent@347: */ laurent@347: case_element_iterator_c(symbol_c *list, case_element_t element_type); laurent@347: laurent@347: /* Skip to the next case element of type chosen. After object creation, laurent@347: * the object references on case element _before_ the first, so laurent@347: * this function must be called once to get the object to laurent@347: * reference the first element... laurent@347: * laurent@347: * Returns the case element's symbol! laurent@347: */ laurent@347: symbol_c *next(void); laurent@347: laurent@347: private: laurent@347: laurent@347: /******************************/ laurent@347: /* B 1.2.1 - Numeric Literals */ laurent@347: /******************************/ laurent@347: void *visit(integer_c *symbol); laurent@347: void *visit(neg_integer_c *symbol); laurent@347: laurent@347: /********************************/ laurent@347: /* B 1.3.3 - Derived data types */ laurent@347: /********************************/ laurent@347: /* signed_integer DOTDOT signed_integer */ laurent@347: void *visit(subrange_c *symbol); laurent@347: laurent@347: /* enumerated_type_name '#' identifier */ laurent@347: void *visit(enumerated_value_c *symbol); laurent@347: laurent@347: /********************************/ laurent@347: /* B 3.2.3 Selection Statements */ laurent@347: /********************************/ laurent@347: void *visit(case_list_c *symbol); laurent@347: laurent@347: laurent@347: laurent@347: }; // function_param_iterator_c laurent@347: laurent@347: laurent@347: laurent@347: laurent@347: laurent@347: laurent@347: