stage3/constant_folding.cc
changeset 792 78083edf93d5
parent 791 ab601bdea102
child 890 499486ece119
equal deleted inserted replaced
791:ab601bdea102 792:78083edf93d5
   975 }
   975 }
   976 
   976 
   977 /*********************/
   977 /*********************/
   978 /* B 1.4 - Variables */
   978 /* B 1.4 - Variables */
   979 /*********************/
   979 /*********************/
       
   980 #if DO_CONSTANT_PROPAGATION__
   980 void *constant_folding_c::visit(symbolic_variable_c *symbol) {
   981 void *constant_folding_c::visit(symbolic_variable_c *symbol) {
   981 	std::string varName;
   982 	std::string varName;
   982 
   983 
   983 	varName = get_var_name_c::get_name(symbol->var_name)->value;
   984 	varName = get_var_name_c::get_name(symbol->var_name)->value;
   984 	if (values.count(varName) > 0) {
   985 	if (values.count(varName) > 0) {
   985 		symbol->const_value = values[varName];
   986 		symbol->const_value = values[varName];
   986 	}
   987 	}
   987 	return NULL;
   988 	return NULL;
   988 }
   989 }
       
   990 #endif  // DO_CONSTANT_PROPAGATION__
   989 
   991 
   990 
   992 
   991 /**********************/
   993 /**********************/
   992 /* B 1.5.3 - Programs */
   994 /* B 1.5.3 - Programs */
   993 /**********************/
   995 /**********************/
       
   996 #if DO_CONSTANT_PROPAGATION__
   994 void *constant_folding_c::visit(program_declaration_c *symbol) {
   997 void *constant_folding_c::visit(program_declaration_c *symbol) {
   995 	symbol_c *var_name;
   998 	symbol_c *var_name;
   996 
   999 
   997 	symbol->var_declarations->accept(*this);
  1000 	symbol->var_declarations->accept(*this);
   998 	values.clear(); /* Clear global map */
  1001 	values.clear(); /* Clear global map */
  1005 	}
  1008 	}
  1006 	/* Add all variables declared into Values map and put them to initial value */
  1009 	/* Add all variables declared into Values map and put them to initial value */
  1007 	symbol->function_block_body->accept(*this);
  1010 	symbol->function_block_body->accept(*this);
  1008 	return NULL;
  1011 	return NULL;
  1009 }
  1012 }
       
  1013 #endif  // DO_CONSTANT_PROPAGATION__
  1010 
  1014 
  1011 
  1015 
  1012 /****************************************/
  1016 /****************************************/
  1013 /* B.2 - Language IL (Instruction List) */
  1017 /* B.2 - Language IL (Instruction List) */
  1014 /****************************************/
  1018 /****************************************/
  1277 /* TODO: handle function invocations... */
  1281 /* TODO: handle function invocations... */
  1278 // void *fill_candidate_datatypes_c::visit(function_invocation_c *symbol) {}
  1282 // void *fill_candidate_datatypes_c::visit(function_invocation_c *symbol) {}
  1279 
  1283 
  1280 
  1284 
  1281 
  1285 
  1282 
  1286 #if DO_CONSTANT_PROPAGATION__
  1283 /*********************************/
  1287 /*********************************/
  1284 /* B 3.2.1 Assignment Statements */
  1288 /* B 3.2.1 Assignment Statements */
  1285 /*********************************/
  1289 /*********************************/
  1286 void *constant_folding_c::visit(assignment_statement_c *symbol) {
  1290 void *constant_folding_c::visit(assignment_statement_c *symbol) {
  1287 	std::string varName;
  1291 	std::string varName;
  1397 	values = inner_left_join_values(values_statement_result, values_incoming);
  1401 	values = inner_left_join_values(values_statement_result, values_incoming);
  1398 
  1402 
  1399 	return NULL;
  1403 	return NULL;
  1400 }
  1404 }
  1401 
  1405 
  1402 
  1406 #endif  // DO_CONSTANT_PROPAGATION__
  1403 
  1407 
  1404 
  1408