stage3/constant_folding.cc
changeset 590 649667749171
parent 588 3d72d09bd40f
child 592 99a284cec1f2
equal deleted inserted replaced
589:de4c2a058767 590:649667749171
   450 /* | '-' integer	{$$ = new neg_integer_c($2, locloc(@$));} */
   450 /* | '-' integer	{$$ = new neg_integer_c($2, locloc(@$));} */
   451 void *constant_folding_c::visit(neg_integer_c *symbol) {
   451 void *constant_folding_c::visit(neg_integer_c *symbol) {
   452 	symbol->exp->accept(*this);
   452 	symbol->exp->accept(*this);
   453 	DO_UNARY_OPER(int64, -, symbol->exp);
   453 	DO_UNARY_OPER(int64, -, symbol->exp);
   454 	CHECK_OVERFLOW_int64_NEG(symbol, symbol->exp);
   454 	CHECK_OVERFLOW_int64_NEG(symbol, symbol->exp);
       
   455 	/* NOTE 1: INT64_MIN = -(INT64_MAX + 1)   ---> assuming two's complement representation!!!
       
   456 	 * NOTE 2: if the user happens to want INT_MIN, that value will first be parsed as a positive integer, before being negated here.
       
   457 	 * However, the positive value cannot be stored inside an int64! So, in this case, we will get the value from the uint64 cvalue.
       
   458 	 */
       
   459 	// if (INT64_MIN == -INT64_MAX - 1) // We do not really need to check that the platform uses two's complement
       
   460 	if (VALID_CVALUE(uint64, symbol->exp) && (GET_CVALUE(uint64, symbol->exp) == -INT64_MIN)) {
       
   461 		NEW_CVALUE(int64, symbol); // in principle, if the above condition is true, then no new cvalue was created by DO_UNARY_OPER(). Not that it would be a problem to create a new one!
       
   462 		SET_CVALUE(int64, symbol, INT64_MIN);
       
   463 	}
   455 	return NULL;
   464 	return NULL;
   456 }
   465 }
   457 
   466 
   458 
   467 
   459 void *constant_folding_c::visit(binary_integer_c *symbol) {
   468 void *constant_folding_c::visit(binary_integer_c *symbol) {