1 /* |
|
2 * (c) 2003 Mario de Sousa |
|
3 * |
|
4 * Offered to the public under the terms of the GNU General Public License |
|
5 * as published by the Free Software Foundation; either version 2 of the |
|
6 * License, or (at your option) any later version. |
|
7 * |
|
8 * This program is distributed in the hope that it will be useful, but |
|
9 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 * Public License for more details. |
|
12 * |
|
13 * This code is made available on the understanding that it will not be |
|
14 * used in safety-critical situations without a full and competent review. |
|
15 */ |
|
16 |
|
17 /* |
|
18 * An IEC 61131-3 IL and ST compiler. |
|
19 * |
|
20 * Based on the |
|
21 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 * |
|
23 */ |
|
24 |
|
25 |
|
26 |
|
27 /* Determine the data type of a specific constant or variable. |
|
28 * A reference to the relevant type definition is returned. |
|
29 * |
|
30 * For example: |
|
31 * 22 -> returns reference to a int_type_name_c object. |
|
32 * 22.2 -> returns reference to a real_type_name_c object. |
|
33 * LREAL#22.2 -> returns reference to a lreal_type_name_c object. |
|
34 * etc... |
|
35 */ |
|
36 class search_constant_type_c: public search_visitor_c { |
|
37 |
|
38 public: |
|
39 /**********************/ |
|
40 /* B.1.3 - Data types */ |
|
41 /**********************/ |
|
42 /***********************************/ |
|
43 /* B 1.3.1 - Elementary Data Types */ |
|
44 /***********************************/ |
|
45 static real_type_name_c real_type_name; |
|
46 static sint_type_name_c sint_type_name; |
|
47 static lint_type_name_c lint_type_name; |
|
48 static dint_type_name_c dint_type_name; |
|
49 static date_type_name_c date_type_name; |
|
50 static dword_type_name_c dword_type_name; |
|
51 static dt_type_name_c dt_type_name; |
|
52 static tod_type_name_c tod_type_name; |
|
53 static udint_type_name_c udint_type_name; |
|
54 static word_type_name_c word_type_name; |
|
55 static wstring_type_name_c wstring_type_name; |
|
56 static string_type_name_c string_type_name; |
|
57 static lword_type_name_c lword_type_name; |
|
58 static uint_type_name_c uint_type_name; |
|
59 static lreal_type_name_c lreal_type_name; |
|
60 static byte_type_name_c byte_type_name; |
|
61 static usint_type_name_c usint_type_name; |
|
62 static ulint_type_name_c ulint_type_name; |
|
63 static bool_type_name_c bool_type_name; |
|
64 static time_type_name_c time_type_name; |
|
65 static int_type_name_c int_type_name; |
|
66 |
|
67 static constant_real_type_name_c constant_real_type_name; |
|
68 static constant_int_type_name_c constant_int_type_name; |
|
69 static direct_variable_type_name_c direct_variable_type_name; |
|
70 |
|
71 /******************************************************/ |
|
72 /* Extensions to the base standard as defined in */ |
|
73 /* "Safety Software Technical Specification, */ |
|
74 /* Part 1: Concepts and Function Blocks, */ |
|
75 /* Version 1.0 – Official Release" */ |
|
76 /* by PLCopen - Technical Committee 5 - 2006-01-31 */ |
|
77 /******************************************************/ |
|
78 static safebool_type_name_c safebool_type_name; |
|
79 |
|
80 |
|
81 public: |
|
82 symbol_c *get_type(symbol_c *constant) { |
|
83 return (symbol_c *)constant->accept(*this); |
|
84 } |
|
85 |
|
86 public: |
|
87 |
|
88 /*********************/ |
|
89 /* B 1.2 - Constants */ |
|
90 /*********************/ |
|
91 |
|
92 /******************************/ |
|
93 /* B 1.2.1 - Numeric Literals */ |
|
94 /******************************/ |
|
95 void *visit(real_c *symbol) {return (void *)&constant_real_type_name;} |
|
96 void *visit(integer_c *symbol) {return (void *)&constant_int_type_name;} |
|
97 void *visit(binary_integer_c *symbol) {return (void *)&constant_int_type_name;} |
|
98 void *visit(octal_integer_c *symbol) {return (void *)&constant_int_type_name;} |
|
99 void *visit(hex_integer_c *symbol) {return (void *)&constant_int_type_name;} |
|
100 |
|
101 void *visit(numeric_literal_c *symbol) |
|
102 {return (void *)((symbol->type!=NULL)?symbol->type:symbol->value->accept(*this));} |
|
103 void *visit(integer_literal_c *symbol) |
|
104 {return (void *)((symbol->type!=NULL)?symbol->type:symbol->value->accept(*this));} |
|
105 void *visit(real_literal_c *symbol) |
|
106 {return (void *)((symbol->type!=NULL)?symbol->type:symbol->value->accept(*this));} |
|
107 void *visit(bit_string_literal_c *symbol) |
|
108 {return (void *)((symbol->type!=NULL)?symbol->type:symbol->value->accept(*this));} |
|
109 void *visit(boolean_literal_c *symbol) |
|
110 {return (void *)((symbol->type!=NULL)?symbol->type:symbol->value->accept(*this));} |
|
111 |
|
112 /*******************************/ |
|
113 /* B.1.2.2 Character Strings */ |
|
114 /*******************************/ |
|
115 void *visit(double_byte_character_string_c *symbol) {return (void *)&wstring_type_name;} |
|
116 void *visit(single_byte_character_string_c *symbol) {return (void *)&string_type_name;} |
|
117 |
|
118 /***************************/ |
|
119 /* B 1.2.3 - Time Literals */ |
|
120 /***************************/ |
|
121 /************************/ |
|
122 /* B 1.2.3.1 - Duration */ |
|
123 /************************/ |
|
124 void *visit(neg_time_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ |
|
125 void *visit(duration_c *symbol) {return (void *)&time_type_name;} |
|
126 void *visit(fixed_point_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ |
|
127 void *visit(days_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ |
|
128 void *visit(hours_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ |
|
129 void *visit(minutes_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ |
|
130 void *visit(seconds_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ |
|
131 void *visit(milliseconds_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ |
|
132 |
|
133 /************************************/ |
|
134 /* B 1.2.3.2 - Time of day and Date */ |
|
135 /************************************/ |
|
136 void *visit(time_of_day_c *symbol) {return (void *)&tod_type_name;} |
|
137 void *visit(daytime_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ |
|
138 void *visit(date_c *symbol) {return (void *)&date_type_name;} |
|
139 void *visit(date_literal_c *symbol) {ERROR; return NULL;} /* this member function should never be called. */ |
|
140 void *visit(date_and_time_c *symbol) {return (void *)&dt_type_name;} |
|
141 }; |
|
142 |
|
143 real_type_name_c search_constant_type_c::real_type_name; |
|
144 sint_type_name_c search_constant_type_c::sint_type_name; |
|
145 lint_type_name_c search_constant_type_c::lint_type_name; |
|
146 dint_type_name_c search_constant_type_c::dint_type_name; |
|
147 date_type_name_c search_constant_type_c::date_type_name; |
|
148 dword_type_name_c search_constant_type_c::dword_type_name; |
|
149 dt_type_name_c search_constant_type_c::dt_type_name; |
|
150 tod_type_name_c search_constant_type_c::tod_type_name; |
|
151 udint_type_name_c search_constant_type_c::udint_type_name; |
|
152 word_type_name_c search_constant_type_c::word_type_name; |
|
153 wstring_type_name_c search_constant_type_c::wstring_type_name; |
|
154 string_type_name_c search_constant_type_c::string_type_name; |
|
155 lword_type_name_c search_constant_type_c::lword_type_name; |
|
156 uint_type_name_c search_constant_type_c::uint_type_name; |
|
157 lreal_type_name_c search_constant_type_c::lreal_type_name; |
|
158 byte_type_name_c search_constant_type_c::byte_type_name; |
|
159 usint_type_name_c search_constant_type_c::usint_type_name; |
|
160 ulint_type_name_c search_constant_type_c::ulint_type_name; |
|
161 bool_type_name_c search_constant_type_c::bool_type_name; |
|
162 time_type_name_c search_constant_type_c::time_type_name; |
|
163 int_type_name_c search_constant_type_c::int_type_name; |
|
164 |
|
165 constant_real_type_name_c search_constant_type_c::constant_real_type_name; |
|
166 constant_int_type_name_c search_constant_type_c::constant_int_type_name; |
|
167 direct_variable_type_name_c search_constant_type_c::direct_variable_type_name; |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|