28 * Based on the |
28 * Based on the |
29 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
29 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
30 * |
30 * |
31 */ |
31 */ |
32 |
32 |
33 /* Determine the data type of an constant expression. |
33 /* Determine the value of an constant expression. |
34 * A reference to the relevant type definition is returned. |
34 * A reference to the relevant type definition is returned. |
35 * |
35 * |
36 * For example: |
36 * For example: |
37 * 2 + 3 -> returns reference |
37 * 2 + 3 -> returns reference |
38 * 22.2 - 5 -> returns reference |
38 * 22.2 - 5 -> returns reference |
40 */ |
40 */ |
41 |
41 |
42 #include <vector> |
42 #include <vector> |
43 #include "../absyntax_utils/absyntax_utils.hh" |
43 #include "../absyntax_utils/absyntax_utils.hh" |
44 |
44 |
45 |
|
46 class convert_c : public iterator_visitor_c { |
|
47 std::string text; |
|
48 |
|
49 public: |
|
50 convert_c(symbol_c *symbol = NULL) { |
|
51 text = ""; |
|
52 } |
|
53 |
|
54 std::string toString(symbol_c *symbol) { |
|
55 symbol->accept(*this); |
|
56 return text; |
|
57 } |
|
58 |
|
59 void *visit(identifier_c *symbol) { |
|
60 text = symbol->value; |
|
61 return NULL; |
|
62 } |
|
63 |
|
64 void *visit(symbolic_variable_c *symbol) { |
|
65 symbol->var_name->accept(*this); |
|
66 return NULL; |
|
67 } |
|
68 }; |
|
69 |
45 |
70 class constant_folding_c : public iterator_visitor_c { |
46 class constant_folding_c : public iterator_visitor_c { |
71 search_varfb_instance_type_c *search_varfb_instance_type; |
47 search_varfb_instance_type_c *search_varfb_instance_type; |
72 int error_count; |
48 int error_count; |
73 bool warning_found; |
49 bool warning_found; |
74 int current_display_error_level; |
50 int current_display_error_level; |
75 /* Pointer to the previous IL instruction, which contains the current cvalue of the data stored in the IL stack, i.e. the default variable, a.k.a. accumulator */ |
51 /* Pointer to the previous IL instruction, which contains the current cvalue of the data stored in the IL stack, i.e. the default variable, a.k.a. accumulator */ |
76 symbol_c *prev_il_instruction; |
52 symbol_c *prev_il_instruction; |
77 /* the current IL operand being analyzed */ |
53 /* the current IL operand being analyzed */ |
78 symbol_c *il_operand; |
54 symbol_c *il_operand; |
79 convert_c convert; |
|
80 |
55 |
81 public: |
56 public: |
82 constant_folding_c(symbol_c *symbol = NULL); |
57 constant_folding_c(symbol_c *symbol = NULL); |
83 virtual ~constant_folding_c(void); |
58 virtual ~constant_folding_c(void); |
84 int get_error_count(); |
59 int get_error_count(); |
220 |
195 |
221 /********************************/ |
196 /********************************/ |
222 /* B 3.2.3 Selection Statements */ |
197 /* B 3.2.3 Selection Statements */ |
223 /********************************/ |
198 /********************************/ |
224 void *visit(if_statement_c *symbol); |
199 void *visit(if_statement_c *symbol); |
|
200 |
|
201 /********************************/ |
|
202 /* B 3.2.4 Iteration Statements */ |
|
203 /********************************/ |
|
204 void *visit(for_statement_c *symbol); |
|
205 void *visit(while_statement_c *symbol); |
|
206 void *visit(repeat_statement_c *symbol); |
225 }; |
207 }; |
226 |
208 |