1258 void *constant_folding_c::visit(if_statement_c *symbol) { |
1259 void *constant_folding_c::visit(if_statement_c *symbol) { |
1259 std::map <std::string, symbol_c::const_value_t> values_incoming; |
1260 std::map <std::string, symbol_c::const_value_t> values_incoming; |
1260 std::map <std::string, symbol_c::const_value_t> values_statement_result; |
1261 std::map <std::string, symbol_c::const_value_t> values_statement_result; |
1261 std::map <std::string, symbol_c::const_value_t> values_elsestatement_result; |
1262 std::map <std::string, symbol_c::const_value_t> values_elsestatement_result; |
1262 std::map <std::string, symbol_c::const_value_t>::iterator itr; |
1263 std::map <std::string, symbol_c::const_value_t>::iterator itr; |
|
1264 |
|
1265 /* Optimize dead code */ |
|
1266 symbol->expression->accept(*this); |
|
1267 if (VALID_CVALUE(bool, symbol->expression) && GET_CVALUE(bool, symbol->expression) == false) |
|
1268 return NULL; |
|
1269 |
1263 values_incoming = values; /* save incoming status */ |
1270 values_incoming = values; /* save incoming status */ |
1264 |
|
1265 symbol->statement_list->accept(*this); |
1271 symbol->statement_list->accept(*this); |
1266 values_statement_result = values; |
1272 values_statement_result = values; |
1267 if (NULL != symbol->else_statement_list) { |
1273 if (NULL != symbol->else_statement_list) { |
1268 values = values_incoming; |
1274 values = values_incoming; |
1269 symbol->else_statement_list->accept(*this); |
1275 symbol->else_statement_list->accept(*this); |
1285 COMPUTE_MEET_SEMILATTICE ( bool, c1, c2, value); |
1291 COMPUTE_MEET_SEMILATTICE ( bool, c1, c2, value); |
1286 } else |
1292 } else |
1287 value = values_statement_result[name]; |
1293 value = values_statement_result[name]; |
1288 values[name] = value; |
1294 values[name] = value; |
1289 } |
1295 } |
1290 return NULL; |
1296 |
1291 } |
1297 return NULL; |
1292 |
1298 } |
1293 |
1299 |
1294 |
1300 /********************************/ |
|
1301 /* B 3.2.4 Iteration Statements */ |
|
1302 /********************************/ |
|
1303 void *constant_folding_c::visit(for_statement_c *symbol) { |
|
1304 std::map <std::string, symbol_c::const_value_t> values_incoming; |
|
1305 std::map <std::string, symbol_c::const_value_t> values_statement_result; |
|
1306 std::map <std::string, symbol_c::const_value_t>::iterator itr; |
|
1307 |
|
1308 values_incoming = values; /* save incoming status */ |
|
1309 symbol->statement_list->accept(*this); |
|
1310 values_statement_result = values; |
|
1311 values.clear(); |
|
1312 itr = values_statement_result.begin(); |
|
1313 for ( ; itr != values_statement_result.end(); ++itr) { |
|
1314 std::string name = itr->first; |
|
1315 symbol_c::const_value_t value; |
|
1316 |
|
1317 if (values_incoming.count(name) > 0) { |
|
1318 symbol_c::const_value_t c1 = itr->second; |
|
1319 symbol_c::const_value_t c2 = values_incoming[name]; |
|
1320 COMPUTE_MEET_SEMILATTICE (real64, c1, c2, value); |
|
1321 COMPUTE_MEET_SEMILATTICE (uint64, c1, c2, value); |
|
1322 COMPUTE_MEET_SEMILATTICE ( int64, c1, c2, value); |
|
1323 COMPUTE_MEET_SEMILATTICE ( bool, c1, c2, value); |
|
1324 } else |
|
1325 value = values_statement_result[name]; |
|
1326 values[name] = value; |
|
1327 } |
|
1328 |
|
1329 return NULL; |
|
1330 } |
|
1331 |
|
1332 void *constant_folding_c::visit(while_statement_c *symbol) { |
|
1333 std::map <std::string, symbol_c::const_value_t> values_incoming; |
|
1334 std::map <std::string, symbol_c::const_value_t> values_statement_result; |
|
1335 std::map <std::string, symbol_c::const_value_t>::iterator itr; |
|
1336 |
|
1337 /* Optimize dead code */ |
|
1338 symbol->expression->accept(*this); |
|
1339 if (VALID_CVALUE(bool, symbol->expression) && GET_CVALUE(bool, symbol->expression) == false) |
|
1340 return NULL; |
|
1341 |
|
1342 values_incoming = values; /* save incoming status */ |
|
1343 symbol->statement_list->accept(*this); |
|
1344 values_statement_result = values; |
|
1345 values.clear(); |
|
1346 itr = values_statement_result.begin(); |
|
1347 for ( ; itr != values_statement_result.end(); ++itr) { |
|
1348 std::string name = itr->first; |
|
1349 symbol_c::const_value_t value; |
|
1350 |
|
1351 if (values_incoming.count(name) > 0) { |
|
1352 symbol_c::const_value_t c1 = itr->second; |
|
1353 symbol_c::const_value_t c2 = values_incoming[name]; |
|
1354 COMPUTE_MEET_SEMILATTICE (real64, c1, c2, value); |
|
1355 COMPUTE_MEET_SEMILATTICE (uint64, c1, c2, value); |
|
1356 COMPUTE_MEET_SEMILATTICE ( int64, c1, c2, value); |
|
1357 COMPUTE_MEET_SEMILATTICE ( bool, c1, c2, value); |
|
1358 } else |
|
1359 value = values_statement_result[name]; |
|
1360 values[name] = value; |
|
1361 } |
|
1362 |
|
1363 |
|
1364 return NULL; |
|
1365 } |
|
1366 |
|
1367 void *constant_folding_c::visit(repeat_statement_c *symbol) { |
|
1368 std::map <std::string, symbol_c::const_value_t> values_incoming; |
|
1369 std::map <std::string, symbol_c::const_value_t> values_statement_result; |
|
1370 std::map <std::string, symbol_c::const_value_t>::iterator itr; |
|
1371 |
|
1372 /* Optimize dead code */ |
|
1373 symbol->expression->accept(*this); |
|
1374 if (VALID_CVALUE(bool, symbol->expression) && GET_CVALUE(bool, symbol->expression) == false) |
|
1375 return NULL; |
|
1376 |
|
1377 values_incoming = values; /* save incoming status */ |
|
1378 symbol->statement_list->accept(*this); |
|
1379 values_statement_result = values; |
|
1380 values.clear(); |
|
1381 itr = values_statement_result.begin(); |
|
1382 for ( ; itr != values_statement_result.end(); ++itr) { |
|
1383 std::string name = itr->first; |
|
1384 symbol_c::const_value_t value; |
|
1385 |
|
1386 if (values_incoming.count(name) > 0) { |
|
1387 symbol_c::const_value_t c1 = itr->second; |
|
1388 symbol_c::const_value_t c2 = values_incoming[name]; |
|
1389 COMPUTE_MEET_SEMILATTICE (real64, c1, c2, value); |
|
1390 COMPUTE_MEET_SEMILATTICE (uint64, c1, c2, value); |
|
1391 COMPUTE_MEET_SEMILATTICE ( int64, c1, c2, value); |
|
1392 COMPUTE_MEET_SEMILATTICE ( bool, c1, c2, value); |
|
1393 } else |
|
1394 value = values_statement_result[name]; |
|
1395 values[name] = value; |
|
1396 } |
|
1397 |
|
1398 |
|
1399 return NULL; |
|
1400 } |
|
1401 |
|
1402 |
|
1403 |