115 * |
115 * |
116 * |
116 * |
117 * NOTE 2 |
117 * NOTE 2 |
118 * This file does not print out any error messages! |
118 * This file does not print out any error messages! |
119 * We cannot really print out error messages when we find an overflow. Since each operation |
119 * We cannot really print out error messages when we find an overflow. Since each operation |
120 * (symbol in the absract syntax tree for that operation) will have up to 4 constant results, |
120 * (symbol in the abstract syntax tree for that operation) will have up to 4 constant results, |
121 * it may happen that some of them overflow, while other do not. |
121 * it may happen that some of them overflow, while other do not. |
122 * We must wait for data type checking to determine the exact data type of each expression |
122 * We must wait for data type checking to determine the exact data type of each expression |
123 * before we can decide whether or not we should print out an overflow error message. |
123 * before we can decide whether or not we should print out an overflow error message. |
124 * |
124 * |
125 * For this reason, this visitor merely annotates the abstract syntax tree, and leaves the |
125 * For this reason, this visitor merely annotates the abstract syntax tree, and leaves the |
126 * actuall printing of errors for the print_datatype_errors_c class! |
126 * actually printing of errors for the print_datatype_errors_c class! |
|
127 * |
|
128 * NOTE 3 |
|
129 * Constant Folding class is extended with a implementation constant propagation algorithm |
|
130 * by Mario de Sousa. |
|
131 * Main idea is not to implement a general constant propagation algorithm but to reinterpret it |
|
132 * for visitor classes. |
|
133 * We declared a hash map, it contains a variables list linked with current constant values. |
|
134 * During expression evaluation we can retrieve a constant value to symbolic variables getting it from the map. |
|
135 * Also at join source points we use a meet semilattice rules to merge current values between a block |
|
136 * and adjacent block. |
|
137 * |
127 */ |
138 */ |
128 |
139 |
129 #include "constant_folding.hh" |
140 #include "constant_folding.hh" |
130 #include <stdlib.h> /* required for malloc() */ |
141 #include <stdlib.h> /* required for malloc() */ |
131 |
142 |