stage3/constant_folding.cc
author Manuele Conti <conti.ma@alice.it>
Tue, 05 Jun 2012 19:17:29 +0200
changeset 564 dabffc3086dc
child 565 8acbddf75333
permissions -rw-r--r--
Start constant_folding class.
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     1
/*
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     3
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     4
 *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     5
 *  Copyright (C) 2012       Manuele Conti (conti.ma@alice.it)
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     6
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     7
 *  This program is free software: you can redistribute it and/or modify
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     8
 *  it under the terms of the GNU General Public License as published by
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     9
 *  the Free Software Foundation, either version 3 of the License, or
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    10
 *  (at your option) any later version.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    11
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    12
 *  This program is distributed in the hope that it will be useful,
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    15
 *  GNU General Public License for more details.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    16
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    17
 *  You should have received a copy of the GNU General Public License
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    19
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    20
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    21
 * This code is made available on the understanding that it will not be
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    22
 * used in safety-critical situations without a full and competent review.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    23
 */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    24
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    25
/*
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    26
 * An IEC 61131-3 compiler.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    27
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    28
 * Based on the
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    29
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    30
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    31
 */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    32
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    33
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    34
/* Determine the value of an ST expression.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    35
 * Filling in all symbols the correct value.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    36
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    37
 * For example:
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    38
 *       2 + 3         -> returns constant_value_integer = 5
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    39
 *       22.2 - 5.0    -> returns constant_value_real    = 17.2
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    40
 *       etc...
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    41
 */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    42
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    43
#include "constant_folding.hh"
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    44
#include <typeinfo>
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    45
#include <limits>
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    46
#include <math.h> /* required for pow function */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    47
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    48
#define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order)   ? (symbol1) : (symbol2))
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    49
#define  LAST_(symbol1, symbol2) (((symbol1)->last_order  > (symbol2)->last_order)    ? (symbol1) : (symbol2))
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    50
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    51
#define STAGE3_ERROR(error_level, symbol1, symbol2, ...) {                                                                  \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    52
  if (current_display_error_level >= error_level) {                                                                         \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    53
    fprintf(stderr, "%s:%d-%d..%d-%d: error: ",                                                                             \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    54
            FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    55
                                                 LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column);\
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    56
    fprintf(stderr, __VA_ARGS__);                                                                                           \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    57
    fprintf(stderr, "\n");                                                                                                  \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    58
    error_count++;                                                                                                     \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    59
  }                                                                                                                         \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    60
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    61
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    62
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    63
#define STAGE3_WARNING(symbol1, symbol2, ...) {                                                                             \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    64
    fprintf(stderr, "%s:%d-%d..%d-%d: warning: ",                                                                           \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    65
            FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    66
                                                 LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column);\
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    67
    fprintf(stderr, __VA_ARGS__);                                                                                           \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    68
    fprintf(stderr, "\n");                                                                                                  \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    69
    warning_found = true;                                                                                                   \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    70
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    71
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    72
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    73
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    74
#define DO_OPER(dtype)\
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    75
    (NULL != symbol->r_exp->const_value_##dtype ) && \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    76
    (NULL != symbol->l_exp->const_value_##dtype )
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    77
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    78
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    79
#define CHECK_OVERFLOW_SUM(a, b, type)\
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    80
	((((std::numeric_limits< type >::max() - a) < (b)) ? 1 : 0) || \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    81
	 (((std::numeric_limits< type >::min() + a) > (b)) ? 1 : 0))
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    82
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    83
#define CHECK_OVERFLOW_SUB(a, b, type)\
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    84
	((((std::numeric_limits< type >::max() - a) < (-b)) ? 1 : 0) || \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    85
	 (((std::numeric_limits< type >::min() + a) > (-b)) ? 1 : 0))
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    86
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    87
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    88
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    89
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    90
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    91
constant_folding_c::constant_folding_c(symbol_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    92
    error_count = 0;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    93
    current_display_error_level = 0;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    94
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    95
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    96
constant_folding_c::~constant_folding_c(void) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    97
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    98
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    99
int constant_folding_c::get_error_count() {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   100
	return error_count;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   101
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   102
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   103
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   104
/*********************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   105
/* B 1.2 - Constants */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   106
/*********************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   107
/******************************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   108
/* B 1.2.1 - Numeric Literals */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   109
/******************************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   110
void *constant_folding_c::visit(real_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   111
	double *real_value;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   112
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   113
	real_value = (double *)malloc(sizeof(double));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   114
	sscanf(symbol->value, "%lf", real_value);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   115
	symbol->const_value_real = real_value;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   116
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   117
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   118
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   119
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   120
void *constant_folding_c::visit(integer_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   121
	int64_t *integer_value;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   122
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   123
	integer_value = (int64_t *)malloc(sizeof(int64_t));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   124
	*integer_value = extract_integer_value(symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   125
	symbol->const_value_integer = integer_value;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   126
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   127
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   128
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   129
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   130
void *constant_folding_c::visit(neg_real_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   131
	double *real_value;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   132
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   133
	real_value = (double *)malloc(sizeof(double));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   134
	symbol->exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   135
	if (NULL == symbol->exp->const_value_real)
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   136
		ERROR;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   137
	*real_value = - *(symbol->exp->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   138
	symbol->const_value_real = real_value;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   139
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   140
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   141
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   142
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   143
void *constant_folding_c::visit(neg_integer_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   144
	int64_t *integer_value;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   145
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   146
	integer_value = (int64_t *)malloc(sizeof(int64_t));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   147
	*integer_value = extract_integer_value(symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   148
	symbol->const_value_integer = integer_value;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   149
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   150
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   151
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   152
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   153
void *constant_folding_c::visit(binary_integer_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   154
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   155
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   156
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   157
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   158
void *constant_folding_c::visit(octal_integer_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   159
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   160
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   161
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   162
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   163
void *constant_folding_c::visit(hex_integer_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   164
	int64_t *integer_value;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   165
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   166
	integer_value = (int64_t *)malloc(sizeof(int64_t));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   167
	*integer_value = extract_hex_value(symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   168
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   169
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   170
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   171
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   172
void *constant_folding_c::visit(integer_literal_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   173
	int64_t *integer_value;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   174
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   175
	symbol->value->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   176
	if (NULL == symbol->value->const_value_integer) ERROR;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   177
	*(symbol->const_value_integer) = *(symbol->value->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   178
	integer_value = (int64_t *)malloc(sizeof(int64_t));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   179
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   180
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   181
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   182
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   183
void *constant_folding_c::visit(real_literal_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   184
	double *real_value;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   185
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   186
	real_value = (double *)malloc(sizeof(double));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   187
	symbol->value->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   188
	if (NULL == symbol->value->const_value_real)
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   189
		ERROR;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   190
	*real_value = *(symbol->value->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   191
	symbol->const_value_real = real_value;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   192
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   193
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   194
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   195
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   196
void *constant_folding_c::visit(bit_string_literal_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   197
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   198
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   199
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   200
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   201
void *constant_folding_c::visit(boolean_literal_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   202
	symbol->value->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   203
	if (NULL == symbol->value->const_value_bool) ERROR;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   204
	symbol->const_value_bool = (bool *)malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   205
	*(symbol->const_value_bool) = *(symbol->value->const_value_bool);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   206
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   207
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   208
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   209
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   210
void *constant_folding_c::visit(boolean_true_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   211
	symbol->const_value_bool = (bool *)malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   212
	*(symbol->const_value_bool) = true;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   213
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   214
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   215
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   216
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   217
void *constant_folding_c::visit(boolean_false_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   218
	symbol->const_value_bool = (bool *)malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   219
	*(symbol->const_value_bool) = false;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   220
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   221
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   222
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   223
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   224
/***************************************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   225
/* B.3 - Language ST (Structured Text) */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   226
/***************************************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   227
/***********************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   228
/* B 3.1 - Expressions */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   229
/***********************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   230
void *constant_folding_c::visit(or_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   231
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   232
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   233
	if (DO_OPER(bool)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   234
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   235
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_bool) || *(symbol->r_exp->const_value_bool);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   236
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   237
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   238
		symbol->const_value_integer = (int64_t*) malloc(sizeof(int64_t));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   239
		*(symbol->const_value_integer) = *(symbol->l_exp->const_value_integer) | *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   240
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   241
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   242
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   243
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   244
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   245
void *constant_folding_c::visit(xor_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   246
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   247
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   248
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   249
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   250
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_integer) ^ *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   251
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   252
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   253
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   254
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   255
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   256
void *constant_folding_c::visit(and_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   257
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   258
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   259
	if (DO_OPER(bool)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   260
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   261
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_bool) && *(symbol->r_exp->const_value_bool);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   262
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   263
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   264
		symbol->const_value_integer = (int64_t*) malloc(sizeof(int64_t));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   265
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_integer) & *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   266
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   267
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   268
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   269
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   270
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   271
void *constant_folding_c::visit(equ_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   272
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   273
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   274
	if (DO_OPER(bool)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   275
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   276
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_bool) == *(symbol->r_exp->const_value_bool);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   277
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   278
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   279
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   280
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_integer) == *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   281
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   282
	if (DO_OPER(real)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   283
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   284
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_real) == *(symbol->r_exp->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   285
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   286
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   287
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   288
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   289
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   290
void *constant_folding_c::visit(notequ_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   291
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   292
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   293
	if (DO_OPER(bool)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   294
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   295
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_bool) != *(symbol->r_exp->const_value_bool);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   296
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   297
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   298
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   299
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_integer) != *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   300
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   301
	if (DO_OPER(real)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   302
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   303
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_real) != *(symbol->r_exp->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   304
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   305
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   306
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   307
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   308
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   309
void *constant_folding_c::visit(lt_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   310
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   311
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   312
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   313
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   314
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_integer) < *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   315
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   316
	if (DO_OPER(real)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   317
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   318
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_real) < *(symbol->r_exp->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   319
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   320
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   321
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   322
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   323
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   324
void *constant_folding_c::visit(gt_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   325
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   326
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   327
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   328
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   329
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_integer) > *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   330
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   331
	if (DO_OPER(real)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   332
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   333
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_real) > *(symbol->r_exp->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   334
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   335
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   336
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   337
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   338
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   339
void *constant_folding_c::visit(le_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   340
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   341
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   342
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   343
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   344
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_integer) <= *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   345
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   346
	if (DO_OPER(real)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   347
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   348
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_real) <= *(symbol->r_exp->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   349
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   350
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   351
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   352
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   353
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   354
void *constant_folding_c::visit(ge_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   355
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   356
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   357
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   358
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   359
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_integer) >= *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   360
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   361
	if (DO_OPER(real)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   362
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   363
		*(symbol->const_value_bool) = *(symbol->l_exp->const_value_real) >= *(symbol->r_exp->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   364
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   365
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   366
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   367
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   368
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   369
void *constant_folding_c::visit(add_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   370
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   371
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   372
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   373
		if (CHECK_OVERFLOW_SUM(*(symbol->l_exp->const_value_integer), *(symbol->r_exp->const_value_integer), int64_t))
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   374
			STAGE3_ERROR(0, symbol, symbol, "Overflow in constant expression.");
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   375
		symbol->const_value_integer = (int64_t*) malloc(sizeof(int64_t));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   376
		*(symbol->const_value_integer) = *(symbol->l_exp->const_value_integer) + *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   377
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   378
	if (DO_OPER(real)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   379
		if (CHECK_OVERFLOW_SUM(*(symbol->l_exp->const_value_real), *(symbol->r_exp->const_value_real), double))
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   380
			STAGE3_ERROR(0, symbol, symbol, "Overflow in constant expression.");
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   381
		symbol->const_value_real = (double*) malloc(sizeof(double));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   382
		*(symbol->const_value_real) = *(symbol->l_exp->const_value_real) + *(symbol->r_exp->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   383
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   384
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   385
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   386
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   387
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   388
void *constant_folding_c::visit(sub_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   389
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   390
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   391
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   392
		if (CHECK_OVERFLOW_SUB(*(symbol->l_exp->const_value_integer), *(symbol->r_exp->const_value_integer), int64_t))
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   393
			STAGE3_ERROR(0, symbol, symbol, "Overflow in constant expression.");
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   394
		symbol->const_value_integer = (int64_t*) malloc(sizeof(int64_t));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   395
		*(symbol->const_value_integer) = *(symbol->l_exp->const_value_integer) - *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   396
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   397
	if (DO_OPER(real)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   398
		if (CHECK_OVERFLOW_SUB(*(symbol->l_exp->const_value_real), *(symbol->r_exp->const_value_real), double))
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   399
			STAGE3_ERROR(0, symbol, symbol, "Overflow in constant expression.");
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   400
		symbol->const_value_real = (double*) malloc(sizeof(double));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   401
		*(symbol->const_value_real) = *(symbol->l_exp->const_value_real) - *(symbol->r_exp->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   402
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   403
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   404
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   405
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   406
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   407
void *constant_folding_c::visit(mul_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   408
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   409
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   410
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   411
		symbol->const_value_integer = (int64_t*) malloc(sizeof(int64_t));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   412
		if ((*(symbol->l_exp->const_value_integer) == 0) ||
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   413
			(*(symbol->r_exp->const_value_integer) == 0)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   414
			*(symbol->const_value_integer) = 0;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   415
			return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   416
		}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   417
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   418
		*(symbol->const_value_integer) = *(symbol->l_exp->const_value_integer) * *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   419
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   420
	if (DO_OPER(real)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   421
		symbol->const_value_real = (double*) malloc(sizeof(double));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   422
		*(symbol->const_value_real) = *(symbol->l_exp->const_value_real) * *(symbol->r_exp->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   423
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   424
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   425
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   426
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   427
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   428
void *constant_folding_c::visit(div_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   429
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   430
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   431
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   432
		if (*(symbol->r_exp->const_value_integer) == 0)
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   433
			STAGE3_ERROR(0, symbol, symbol, "Division by zero in constant expression.");
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   434
		symbol->const_value_integer = (int64_t*) malloc(sizeof(int64_t));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   435
		*(symbol->const_value_integer) = *(symbol->l_exp->const_value_integer) / *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   436
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   437
	if (DO_OPER(real)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   438
		if (*(symbol->r_exp->const_value_real) == 0)
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   439
			STAGE3_ERROR(0, symbol, symbol, "Division by zero in constant expression.");
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   440
		symbol->const_value_real = (double*) malloc(sizeof(double));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   441
		*(symbol->const_value_real) = *(symbol->l_exp->const_value_real) / *(symbol->r_exp->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   442
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   443
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   444
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   445
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   446
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   447
void *constant_folding_c::visit(mod_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   448
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   449
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   450
	if (DO_OPER(integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   451
		if (*(symbol->r_exp->const_value_integer) == 0)
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   452
			STAGE3_ERROR(0, symbol, symbol, "Division by zero in constant expression.");
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   453
		symbol->const_value_integer = (int64_t*) malloc(sizeof(int64_t));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   454
		*(symbol->const_value_integer) = *(symbol->l_exp->const_value_integer) % *(symbol->r_exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   455
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   456
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   457
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   458
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   459
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   460
void *constant_folding_c::visit(power_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   461
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   462
	symbol->r_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   463
	if ((NULL != symbol->l_exp->const_value_real) && (NULL != symbol->r_exp->const_value_integer)) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   464
		symbol->const_value_real = (double*) malloc(sizeof(double));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   465
		*(symbol->const_value_real) = pow(*(symbol->l_exp->const_value_real), *(symbol->r_exp->const_value_integer));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   466
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   467
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   468
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   469
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   470
void *constant_folding_c::visit(neg_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   471
	symbol->exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   472
	if (NULL != symbol->exp->const_value_integer) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   473
		symbol->const_value_integer = (int64_t*) malloc(sizeof(int64_t));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   474
		*(symbol->const_value_integer) = - *(symbol->exp->const_value_integer);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   475
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   476
	if (NULL != symbol->exp->const_value_real) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   477
		symbol->const_value_real = (double*) malloc(sizeof(double));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   478
		*(symbol->const_value_real) = - *(symbol->exp->const_value_real);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   479
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   480
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   481
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   482
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   483
void *constant_folding_c::visit(not_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   484
	symbol->exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   485
	if (NULL != symbol->exp->const_value_bool) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   486
		symbol->const_value_bool = (bool*) malloc(sizeof(bool));
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   487
		*(symbol->const_value_bool) = !*(symbol->exp->const_value_bool);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   488
	}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   489
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   490
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   491
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   492
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   493
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   494