stage3/constant_folding.cc
author Mario de Sousa <msousa@fe.up.pt>
Fri, 08 Jun 2012 19:44:32 +0100
changeset 569 0d1ab9e78574
parent 568 5f79478142d7
child 570 cb704eca7e37
permissions -rw-r--r--
Add data structure for storing overflow of constant values.
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
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    34
/* Do constant folding...
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    35
 *
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    36
 * I.e., Determine the value of all expressions in which only constant values (i.e. literals) are used.
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    37
 * The (constant) result of each operation is stored (annotated) in the respective operation symbol 
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    38
 * (e.g.: add_expression_c) in the abstract syntax tree,
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    39
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    40
 * For example:
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    41
 *       2 + 3         -> the constant value '5'    is stored in the add_expression_c symbol.
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    42
 *       22.2 - 5.0    -> the constant value '17.2' is stored in the add_expression_c symbol.
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    43
 *       etc...
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    44
 *
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    45
 *
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    46
 * NOTE 1 that some operations and constants can have multiple data types. For example,
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    47
 *        1 AND 0
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    48
 *      may be either a BOOL, BYTE, WORD or LWORD.
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    49
 *
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    50
 *      The same happens with 
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    51
 *        1 + 2
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    52
 *      which may be signed (e.g. INT) or unsigned (UINT)
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    53
 *
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    54
 *      For the above reason, instead of storing a single constant value, we actually store 4:
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    55
 *        - bool
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    56
 *        - uint64
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    57
 *        -  int64
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    58
 *        - real64
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    59
 *
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    60
 *      Additionally, since the result of an operation may result in an overflow, we actually
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    61
 *      store the result inside a struct (defined in absyntax.hh)
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    62
 *
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    63
 *             ** During stage 3 (semantic analysis/checking) we will be doing constant folding.
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    64
 *              * That algorithm will anotate the abstract syntax tree with the result of operations
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    65
 *              * on literals (i.e. 44 + 55 will store the result 99).
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    66
 *              * Since the same source code (e.g. 1 + 0) may actually be a BOOL or an ANY_INT,
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    67
 *              * or an ANY_BIT, we need to handle all possibilities, and determine the result of the
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    68
 *              * operation assuming each type.
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    69
 *              * For this reason, we have one entry for each possible type, with some expressions
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    70
 *              * having more than one entry filled in!
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    71
 *              **
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    72
 *             typedef enum { cs_undefined,   // not defined --> const_value is not valid!
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    73
 *                            cs_const_value, // const value is valid
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    74
 *                            cs_overflow     // result produced overflow or underflow --> const_value is not valid!
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    75
 *                          } const_status_t;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    76
 *    
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    77
 *             typedef struct {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    78
 *                 const_status_t status;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    79
 *                 real64_t       value; 
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    80
 *             } const_value_real64_t;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    81
 *             const_value_real64_t *const_value_real64; // when NULL --> UNDEFINED
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    82
 *             
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    83
 *             typedef struct {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    84
 *                 const_status_t status;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    85
 *                 int64_t        value; 
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    86
 *             } const_value_int64_t;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    87
 *             const_value_int64_t *const_value_int64; // when NULL --> UNDEFINED
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    88
 *             
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    89
 *             typedef struct {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    90
 *                 const_status_t status;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    91
 *                 uint64_t       value; 
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    92
 *             } const_value_uint64_t;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    93
 *             const_value_uint64_t *const_value_uint64; // when NULL --> UNDEFINED
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    94
 *             
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    95
 *             typedef struct {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    96
 *                 const_status_t status;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    97
 *                 bool           value; 
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    98
 *             } const_value_bool_t;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    99
 *             const_value_bool_t *const_value_bool; // when NULL --> UNDEFINED
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   100
 *
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   101
 *
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   102
 *
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   103
 * NOTE 2 
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   104
 *    This file does not print out any error messages!
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   105
 *    We cannot really print out error messages when we find an overflow. Since each operation
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   106
 *    (symbol in the absract syntax tree for that operation) will have up to 4 constant results,
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   107
 *    it may happen that some of them overflow, while other do not.
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   108
 *    We must wait for data type checking to determine the exact data type of each expression
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   109
 *    before we can decide whether or not we should print out an overflow error message.
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   110
 *
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   111
 *    For this reason, this visitor merely annotates the abstract syntax tree, and leaves the
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   112
 `    actuall printing of errors for the print_datatype_errors_c class!
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   113
 */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   114
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   115
#include "constant_folding.hh"
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   116
#include <typeinfo>
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   117
#include <limits>
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   118
#include <math.h> /* required for pow function */
565
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   119
#include <stdlib.h> /* required for malloc() */
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   120
568
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   121
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   122
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   123
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   124
#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
   125
#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
   126
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   127
#define STAGE3_ERROR(error_level, symbol1, symbol2, ...) {                                                                  \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   128
  if (current_display_error_level >= error_level) {                                                                         \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   129
    fprintf(stderr, "%s:%d-%d..%d-%d: error: ",                                                                             \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   130
            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
   131
                                                 LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column);\
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   132
    fprintf(stderr, __VA_ARGS__);                                                                                           \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   133
    fprintf(stderr, "\n");                                                                                                  \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   134
    error_count++;                                                                                                     \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   135
  }                                                                                                                         \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   136
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   137
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   138
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   139
#define STAGE3_WARNING(symbol1, symbol2, ...) {                                                                             \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   140
    fprintf(stderr, "%s:%d-%d..%d-%d: warning: ",                                                                           \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   141
            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
   142
                                                 LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column);\
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   143
    fprintf(stderr, __VA_ARGS__);                                                                                           \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   144
    fprintf(stderr, "\n");                                                                                                  \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   145
    warning_found = true;                                                                                                   \
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   146
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   147
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   148
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   149
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   150
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   151
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   152
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   153
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   154
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   155
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   156
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   157
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   158
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   159
#define NEW_CVALUE(dtype, symbol) \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   160
 (symbol->const_value_##dtype) = new(symbol_c::const_value_##dtype##_t); \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   161
 if ((symbol->const_value_##dtype) == NULL) ERROR; \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   162
 (symbol->const_value_##dtype)->status = symbol_c::cs_undefined;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   163
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   164
#define SET_CVALUE(dtype, symbol, new_value)  ((symbol)->const_value_##dtype->value) = new_value; ((symbol)->const_value_##dtype->status) = symbol_c::cs_const_value;  
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   165
#define GET_CVALUE(dtype, symbol)             ((symbol)->const_value_##dtype->value) 
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   166
#define SET_OVFLOW(dtype, symbol)             ((symbol)->const_value_##dtype->status) = symbol_c::cs_overflow
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   167
    /* The following test is correct in the presence of a NULL pointer, as the logical evaluation will be suspended as soon as the first condition is false! */
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   168
#define VALID_CVALUE(dtype, symbol)           ((NULL != (symbol)->const_value_##dtype) && (symbol_c::cs_const_value == (symbol)->const_value_##dtype->status))
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   169
#define ISZERO_CVALUE(dtype, symbol)          ((VALID_CVALUE(dtype, symbol)) && (GET_CVALUE(dtype, symbol) == 0))
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   170
#define DO_BIN_OPER(dtype, oper)\
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   171
	if (VALID_CVALUE(dtype, symbol->r_exp) && VALID_CVALUE(dtype, symbol->l_exp)) {                                \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   172
		NEW_CVALUE(dtype, symbol);                                                                             \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   173
		SET_CVALUE(dtype, symbol, GET_CVALUE(dtype, symbol->l_exp) oper GET_CVALUE(dtype, symbol->r_exp));     \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   174
	}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   175
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   176
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   177
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   178
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
constant_folding_c::constant_folding_c(symbol_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   181
    error_count = 0;
568
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   182
    warning_found = false;
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   183
    current_display_error_level = 0;
568
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   184
    
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   185
    /* check whether the platform on which the compiler is being run implements IEC 559 floating point data types. */
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   186
    symbol_c null_symbol;
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   187
    if (! (std::numeric_limits<real64_t>::is_iec559) )
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   188
        STAGE3_WARNING(&null_symbol, &null_symbol, "The platform running the compiler does not implement IEC 559 floating point numbers. "
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   189
                                                   "Any error and/or warning messages related to overflow/underflow of the result of operations on REAL/LREAL literals "
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   190
                                                   " (i.e. constant folding) may themselves be erroneous, although are most probably correct.");
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   191
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   192
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   193
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   194
constant_folding_c::~constant_folding_c(void) {
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
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   197
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   198
int constant_folding_c::get_error_count() {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   199
	return error_count;
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
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   202
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   203
/*********************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   204
/* B 1.2 - Constants */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   205
/*********************/
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
/* B 1.2.1 - Numeric Literals */
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
void *constant_folding_c::visit(real_c *symbol) {
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   210
	NEW_CVALUE(real64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   211
	SET_CVALUE(real64, symbol, extract_real_value(symbol));
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   212
	return NULL;
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   213
}
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   214
564
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
void *constant_folding_c::visit(integer_c *symbol) {
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   217
	NEW_CVALUE( int64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   218
	SET_CVALUE( int64, symbol, extract_integer_value(symbol));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   219
	NEW_CVALUE(uint64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   220
	SET_CVALUE(uint64, symbol, extract_integer_value(symbol));
564
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
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   224
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   225
void *constant_folding_c::visit(neg_real_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   226
	symbol->exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   227
	if (!VALID_CVALUE(real64, symbol->exp))
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   228
		return NULL;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   229
	NEW_CVALUE(real64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   230
	SET_CVALUE(real64, symbol, - GET_CVALUE( real64, symbol->exp));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   231
	return NULL;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   232
}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   233
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   234
/* | '-' integer	{$$ = new neg_integer_c($2, locloc(@$));} */
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   235
void *constant_folding_c::visit(neg_integer_c *symbol) {
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   236
	symbol->exp->accept(*this);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   237
	if (VALID_CVALUE(int64, symbol->exp)) {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   238
		NEW_CVALUE( int64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   239
		SET_CVALUE( int64, symbol, - GET_CVALUE( int64, symbol->exp));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   240
	}
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   241
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   242
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   243
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   244
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   245
void *constant_folding_c::visit(binary_integer_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   246
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   247
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   248
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   249
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   250
void *constant_folding_c::visit(octal_integer_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   251
	return NULL;
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
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   254
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   255
void *constant_folding_c::visit(hex_integer_c *symbol) {
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   256
	NEW_CVALUE( int64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   257
	SET_CVALUE( int64, symbol, extract_hex_value(symbol));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   258
	NEW_CVALUE(uint64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   259
	SET_CVALUE(uint64, symbol, extract_hex_value(symbol));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   260
	return NULL;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   261
}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   262
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   263
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   264
/*
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   265
integer_literal:
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   266
  integer_type_name '#' signed_integer	{$$ = new integer_literal_c($1, $3, locloc(@$));}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   267
| integer_type_name '#' binary_integer	{$$ = new integer_literal_c($1, $3, locloc(@$));}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   268
| integer_type_name '#' octal_integer	{$$ = new integer_literal_c($1, $3, locloc(@$));}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   269
| integer_type_name '#' hex_integer	{$$ = new integer_literal_c($1, $3, locloc(@$));}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   270
*/
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   271
// SYM_REF2(integer_literal_c, type, value)
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   272
void *constant_folding_c::visit(integer_literal_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   273
	symbol->value->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   274
	if (VALID_CVALUE( int64, symbol->value)) {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   275
		NEW_CVALUE( int64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   276
		SET_CVALUE( int64, symbol, GET_CVALUE( int64, symbol->value));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   277
	}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   278
	if (VALID_CVALUE(uint64, symbol->value)) {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   279
		NEW_CVALUE(uint64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   280
		SET_CVALUE(uint64, symbol, GET_CVALUE(uint64, symbol->value));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   281
	}
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   282
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   283
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   284
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   285
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   286
void *constant_folding_c::visit(real_literal_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   287
	symbol->value->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   288
	if (VALID_CVALUE(real64, symbol->value)) {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   289
		NEW_CVALUE(real64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   290
		SET_CVALUE(real64, symbol,  GET_CVALUE(real64, symbol->value));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   291
	}
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   292
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   293
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   294
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   295
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   296
void *constant_folding_c::visit(bit_string_literal_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   297
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   298
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   299
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   300
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   301
void *constant_folding_c::visit(boolean_literal_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   302
	symbol->value->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   303
	if (VALID_CVALUE(bool, symbol->value)) {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   304
		NEW_CVALUE(bool, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   305
		SET_CVALUE(bool, symbol,  GET_CVALUE(  bool, symbol->value));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   306
	}
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   307
	return NULL;
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
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   310
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   311
void *constant_folding_c::visit(boolean_true_c *symbol) {
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   312
	NEW_CVALUE(bool, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   313
	SET_CVALUE(bool, symbol, true);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   314
	return NULL;
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
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   317
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   318
void *constant_folding_c::visit(boolean_false_c *symbol) {
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   319
	NEW_CVALUE(bool, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   320
	SET_CVALUE(bool, symbol, false);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   321
	return NULL;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   322
}
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   323
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   324
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   325
/***************************************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   326
/* B.3 - Language ST (Structured Text) */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   327
/***************************************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   328
/***********************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   329
/* B 3.1 - Expressions */
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
void *constant_folding_c::visit(or_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   332
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   333
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   334
	DO_BIN_OPER(bool,   ||);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   335
	DO_BIN_OPER(uint64, | );
564
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
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   339
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   340
void *constant_folding_c::visit(xor_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   341
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   342
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   343
	DO_BIN_OPER(bool,   ^);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   344
	DO_BIN_OPER(uint64, ^);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   345
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   346
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   347
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   348
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   349
void *constant_folding_c::visit(and_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   350
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   351
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   352
	DO_BIN_OPER(bool,   &&);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   353
	DO_BIN_OPER(uint64, & );
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   354
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   355
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   356
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   357
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   358
void *constant_folding_c::visit(equ_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   359
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   360
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   361
	DO_BIN_OPER(bool,   ==);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   362
	DO_BIN_OPER(uint64, ==);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   363
	DO_BIN_OPER( int64, ==);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   364
	DO_BIN_OPER(real64, ==);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   365
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   366
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   367
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   368
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   369
void *constant_folding_c::visit(notequ_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);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   372
	DO_BIN_OPER(bool,   !=);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   373
	DO_BIN_OPER(uint64, !=);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   374
	DO_BIN_OPER( int64, !=);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   375
	DO_BIN_OPER(real64, !=);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   376
	return NULL;
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
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   379
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   380
void *constant_folding_c::visit(lt_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   381
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   382
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   383
	DO_BIN_OPER(bool,   <);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   384
	DO_BIN_OPER(uint64, <);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   385
	DO_BIN_OPER( int64, <);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   386
	DO_BIN_OPER(real64, <);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   387
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   388
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   389
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   390
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   391
void *constant_folding_c::visit(gt_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   392
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   393
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   394
	DO_BIN_OPER(bool,   >);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   395
	DO_BIN_OPER(uint64, >);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   396
	DO_BIN_OPER( int64, >);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   397
	DO_BIN_OPER(real64, >);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   398
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   399
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   400
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   401
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   402
void *constant_folding_c::visit(le_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   403
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   404
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   405
	DO_BIN_OPER(bool,   <=);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   406
	DO_BIN_OPER(uint64, <=);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   407
	DO_BIN_OPER( int64, <=);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   408
	DO_BIN_OPER(real64, <=);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   409
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   410
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   411
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   412
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   413
void *constant_folding_c::visit(ge_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   414
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   415
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   416
	DO_BIN_OPER(bool,   >=);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   417
	DO_BIN_OPER(uint64, >=);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   418
	DO_BIN_OPER( int64, >=);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   419
	DO_BIN_OPER(real64, >=);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   420
	return NULL;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   421
}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   422
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   423
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   424
#define CHECK_OVERFLOW_SUM(dtype)\
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   425
	if (VALID_CVALUE(dtype, symbol))                                                                                                             \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   426
		if ((((std::numeric_limits< dtype##_t >::max() - GET_CVALUE(dtype, symbol->l_exp)) < (GET_CVALUE(dtype, symbol->r_exp))) ? 1 : 0) || \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   427
		    (((std::numeric_limits< dtype##_t >::min() + GET_CVALUE(dtype, symbol->l_exp)) > (GET_CVALUE(dtype, symbol->r_exp))) ? 1 : 0))   \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   428
			SET_OVFLOW(dtype, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   429
#define CHECK_OVERFLOW_real64  \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   430
	if (VALID_CVALUE(real64, symbol))                                                                                                            \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   431
        	/* NaN => underflow, overflow, number is a higher precision format, is a complex number (IEEE standard) */                           \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   432
		 if (isnan(GET_CVALUE(real64, symbol)))                                                                                              \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   433
			SET_OVFLOW(real64, symbol);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   434
void *constant_folding_c::visit(add_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   435
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   436
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   437
	DO_BIN_OPER(uint64, +);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   438
	DO_BIN_OPER( int64, +);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   439
	DO_BIN_OPER(real64, +);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   440
	CHECK_OVERFLOW_SUM(uint64);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   441
	CHECK_OVERFLOW_SUM( int64);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   442
	CHECK_OVERFLOW_real64;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   443
	return NULL;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   444
}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   445
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   446
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   447
#define CHECK_OVERFLOW_SUB(dtype)\
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   448
	if (VALID_CVALUE(dtype, symbol))                                                                                                             \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   449
		if ((((std::numeric_limits< dtype##_t >::max() - GET_CVALUE(dtype, symbol->l_exp)) < (-GET_CVALUE(dtype, symbol->r_exp))) ? 1 : 0) || \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   450
		    (((std::numeric_limits< dtype##_t >::min() + GET_CVALUE(dtype, symbol->l_exp)) > (-GET_CVALUE(dtype, symbol->r_exp))) ? 1 : 0))   \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   451
			SET_OVFLOW(dtype, symbol);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   452
void *constant_folding_c::visit(sub_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   453
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   454
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   455
	DO_BIN_OPER(uint64, -);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   456
	DO_BIN_OPER( int64, -);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   457
	DO_BIN_OPER(real64, -);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   458
	CHECK_OVERFLOW_SUB(uint64);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   459
	CHECK_OVERFLOW_SUB( int64);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   460
	CHECK_OVERFLOW_real64;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   461
	return NULL;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   462
}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   463
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   464
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   465
/* TODO!!! */
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   466
#define CHECK_OVERFLOW_MUL(dtype)\
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   467
	if (VALID_CVALUE(dtype, symbol))                                                                                                             \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   468
		if (false)                                                                                                                                   \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   469
			SET_OVFLOW(dtype, symbol);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   470
void *constant_folding_c::visit(mul_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   471
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   472
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   473
	DO_BIN_OPER(uint64, *);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   474
	DO_BIN_OPER( int64, *);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   475
	DO_BIN_OPER(real64, *);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   476
	CHECK_OVERFLOW_MUL(uint64);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   477
	CHECK_OVERFLOW_MUL( int64);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   478
	CHECK_OVERFLOW_real64;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   479
	return NULL;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   480
}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   481
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   482
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   483
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   484
/* TODO!!! */
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   485
#define CHECK_OVERFLOW_DIV(dtype)\
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   486
	if (VALID_CVALUE(dtype, symbol))                                                                                                             \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   487
		if (false)                                                                                                                                   \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   488
			SET_OVFLOW(dtype, symbol);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   489
void *constant_folding_c::visit(div_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   490
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   491
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   492
	if (ISZERO_CVALUE(uint64, symbol->r_exp))  {NEW_CVALUE(uint64, symbol); SET_OVFLOW(uint64, symbol);} else {DO_BIN_OPER(uint64, /); CHECK_OVERFLOW_DIV(uint64)};
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   493
	if (ISZERO_CVALUE( int64, symbol->r_exp))  {NEW_CVALUE( int64, symbol); SET_OVFLOW( int64, symbol);} else {DO_BIN_OPER( int64, /); CHECK_OVERFLOW_DIV( int64)};
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   494
	if (ISZERO_CVALUE(real64, symbol->r_exp))  {NEW_CVALUE(real64, symbol); SET_OVFLOW(real64, symbol);} else {DO_BIN_OPER(real64, /); CHECK_OVERFLOW_real64;};
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   495
	return NULL;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   496
}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   497
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   498
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   499
/* TODO!!! */
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   500
#define CHECK_OVERFLOW_MOD(dtype)\
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   501
	if (VALID_CVALUE(dtype, symbol))                                                                                                             \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   502
		if (false)                                                                                                                                   \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   503
			SET_OVFLOW(dtype, symbol);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   504
void *constant_folding_c::visit(mod_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   505
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   506
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   507
	if (ISZERO_CVALUE(uint64, symbol->r_exp))  {NEW_CVALUE(uint64, symbol); SET_OVFLOW(uint64, symbol);} else {DO_BIN_OPER(uint64, %); CHECK_OVERFLOW_MOD(uint64)};
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   508
	if (ISZERO_CVALUE( int64, symbol->r_exp))  {NEW_CVALUE( int64, symbol); SET_OVFLOW( int64, symbol);} else {DO_BIN_OPER( int64, %); CHECK_OVERFLOW_MOD( int64)};
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   509
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   510
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   511
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   512
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   513
void *constant_folding_c::visit(power_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   514
	symbol->l_exp->accept(*this);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   515
	symbol->r_exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   516
	/* NOTE: If the const_value in symbol->r_exp is within the limits of both int64 and uint64, then we do both operations.
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   517
	 *       That is OK, as the result should be identicial (we do create an unnecessary CVALUE variable, but who cares?).
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   518
	 *       If only one is valid, then that is the oper we will do!
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   519
	 */
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   520
	if (VALID_CVALUE(real64, symbol->l_exp) && VALID_CVALUE( int64, symbol->r_exp)) {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   521
		NEW_CVALUE(real64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   522
		SET_CVALUE(real64, symbol, pow(GET_CVALUE(real64, symbol->l_exp), GET_CVALUE( int64, symbol->r_exp)));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   523
	}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   524
	if (VALID_CVALUE(real64, symbol->l_exp) && VALID_CVALUE(uint64, symbol->r_exp)) {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   525
		NEW_CVALUE(real64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   526
		SET_CVALUE(real64, symbol, pow(GET_CVALUE(real64, symbol->l_exp), GET_CVALUE(uint64, symbol->r_exp)));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   527
	}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   528
	CHECK_OVERFLOW_real64;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   529
	return NULL;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   530
}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   531
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   532
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   533
/* TODO!!! */
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   534
#define CHECK_OVERFLOW_NEG(dtype)\
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   535
	if (VALID_CVALUE(dtype, symbol))                                                                                                             \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   536
		if (false)                                                                                                                                   \
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   537
			SET_OVFLOW(dtype, symbol);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   538
void *constant_folding_c::visit(neg_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   539
	symbol->exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   540
	if (VALID_CVALUE( int64, symbol->exp)) {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   541
		NEW_CVALUE( int64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   542
		SET_CVALUE( int64, symbol, - GET_CVALUE( int64, symbol->exp));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   543
	}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   544
	if (VALID_CVALUE(real64, symbol->exp)) {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   545
		NEW_CVALUE(real64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   546
		SET_CVALUE(real64, symbol, - GET_CVALUE(real64, symbol->exp));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   547
	}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   548
	CHECK_OVERFLOW_NEG( int64);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   549
	CHECK_OVERFLOW_real64;
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   550
	return NULL;
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   551
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   552
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   553
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 566
diff changeset
   554
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   555
void *constant_folding_c::visit(not_expression_c *symbol) {
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   556
	symbol->exp->accept(*this);
569
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   557
	if (VALID_CVALUE(  bool, symbol->exp)) {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   558
		NEW_CVALUE(  bool, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   559
		SET_CVALUE(  bool, symbol,  ! GET_CVALUE(  bool, symbol->exp));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   560
	}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   561
	if (VALID_CVALUE(uint64, symbol->exp)) {
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   562
		NEW_CVALUE(uint64, symbol);
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   563
		SET_CVALUE(uint64, symbol,  ~ GET_CVALUE(uint64, symbol->exp));
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   564
	}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   565
	return NULL;
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   566
}
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   567
0d1ab9e78574 Add data structure for storing overflow of constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   568