|
1 /* |
|
2 * matiec - a compiler for the programming languages defined in IEC 61131-3 |
|
3 * |
|
4 * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) |
|
5 * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant |
|
6 * |
|
7 * This program is free software: you can redistribute it and/or modify |
|
8 * it under the terms of the GNU General Public License as published by |
|
9 * the Free Software Foundation, either version 3 of the License, or |
|
10 * (at your option) any later version. |
|
11 * |
|
12 * This program is distributed in the hope that it will be useful, |
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 * GNU General Public License for more details. |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License |
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19 * |
|
20 * |
|
21 * This code is made available on the understanding that it will not be |
|
22 * used in safety-critical situations without a full and competent review. |
|
23 */ |
|
24 |
|
25 /* |
|
26 * An IEC 61131-3 compiler. |
|
27 * |
|
28 * Based on the |
|
29 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
30 * |
|
31 */ |
|
32 |
|
33 |
|
34 /* |
|
35 * Case element iterator. |
|
36 * Iterate through the elements of a case list. |
|
37 * |
|
38 * This is part of the 4th stage that generates |
|
39 * a c++ source program equivalent to the IL and ST |
|
40 * code. |
|
41 */ |
|
42 |
|
43 /* Given a case_list_c and a type of element, iterate through |
|
44 * each element, returning the symbol of each element if from |
|
45 * the good type...case_element_iterator_c |
|
46 */ |
|
47 |
|
48 |
|
49 #include "../absyntax/visitor.hh" |
|
50 |
|
51 |
|
52 class case_element_iterator_c : public null_visitor_c { |
|
53 public: |
|
54 /* A type to specify the type of element. |
|
55 */ |
|
56 typedef enum { |
|
57 element_single, |
|
58 element_subrange, |
|
59 } case_element_t ; |
|
60 |
|
61 |
|
62 private: |
|
63 /* a pointer to the function_block_declaration_c |
|
64 * or function_declaration_c currently being analysed. |
|
65 */ |
|
66 symbol_c *case_list; |
|
67 /* used when called to iterate() for a parameter */ |
|
68 symbol_c *current_case_element; |
|
69 |
|
70 /* used to indicate the type of case element on which iterate */ |
|
71 case_element_t wanted_element_type; |
|
72 |
|
73 private: |
|
74 void* handle_case_element(symbol_c *case_element); |
|
75 |
|
76 void* iterate_list(list_c *list); |
|
77 |
|
78 public: |
|
79 /* start off at the first case element once again... */ |
|
80 void reset(void); |
|
81 |
|
82 /* initialise the iterator object. |
|
83 * We must be given a reference to a case_list_c that will be analysed... |
|
84 */ |
|
85 case_element_iterator_c(symbol_c *list, case_element_t element_type); |
|
86 |
|
87 /* Skip to the next case element of type chosen. After object creation, |
|
88 * the object references on case element _before_ the first, so |
|
89 * this function must be called once to get the object to |
|
90 * reference the first element... |
|
91 * |
|
92 * Returns the case element's symbol! |
|
93 */ |
|
94 symbol_c *next(void); |
|
95 |
|
96 private: |
|
97 |
|
98 /******************************/ |
|
99 /* B 1.2.1 - Numeric Literals */ |
|
100 /******************************/ |
|
101 void *visit(integer_c *symbol); |
|
102 void *visit(neg_integer_c *symbol); |
|
103 |
|
104 /********************************/ |
|
105 /* B 1.3.3 - Derived data types */ |
|
106 /********************************/ |
|
107 /* signed_integer DOTDOT signed_integer */ |
|
108 void *visit(subrange_c *symbol); |
|
109 |
|
110 /* enumerated_type_name '#' identifier */ |
|
111 void *visit(enumerated_value_c *symbol); |
|
112 |
|
113 /********************************/ |
|
114 /* B 3.2.3 Selection Statements */ |
|
115 /********************************/ |
|
116 void *visit(case_list_c *symbol); |
|
117 |
|
118 |
|
119 |
|
120 }; // function_param_iterator_c |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |