stage4/generate_c/generate_c.cc
changeset 592 99a284cec1f2
parent 587 1ecf916cc397
child 594 c8092e909886
equal deleted inserted replaced
591:76bad7199896 592:99a284cec1f2
    29 #include <list>
    29 #include <list>
    30 #include <map>
    30 #include <map>
    31 #include <sstream>
    31 #include <sstream>
    32 #include <strings.h>
    32 #include <strings.h>
    33 
    33 
       
    34 
    34 #include "../../util/symtable.hh"
    35 #include "../../util/symtable.hh"
    35 #include "../../util/dsymtable.hh"
    36 #include "../../util/dsymtable.hh"
    36 #include "../../absyntax/visitor.hh"
    37 #include "../../absyntax/visitor.hh"
    37 #include "../../absyntax_utils/absyntax_utils.hh"
    38 #include "../../absyntax_utils/absyntax_utils.hh"
    38 
    39 
    49 /* function defined in main.cc */
    50 /* function defined in main.cc */
    50 extern void error_exit(const char *file_name, int line_no);
    51 extern void error_exit(const char *file_name, int line_no);
    51 
    52 
    52 
    53 
    53 #define STAGE4_ERROR(symbol1, symbol2, ...) {stage4err("while generating C code", symbol1, symbol2, __VA_ARGS__); exit(EXIT_FAILURE);}
    54 #define STAGE4_ERROR(symbol1, symbol2, ...) {stage4err("while generating C code", symbol1, symbol2, __VA_ARGS__); exit(EXIT_FAILURE);}
       
    55 
       
    56 
       
    57 /* Macros to access the constant value of each expression (if it exists) from the annotation introduced to the symbol_c object by constant_folding_c in stage3! */
       
    58 /* NOTE: 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! */
       
    59 #define VALID_CVALUE(dtype, symbol)           ((NULL != (symbol)->const_value_##dtype) && (symbol_c::cs_const_value == (symbol)->const_value_##dtype->status))
       
    60 #define GET_CVALUE(dtype, symbol)             ((symbol)->const_value_##dtype->value) 
    54 
    61 
    55 
    62 
    56 
    63 
    57 /***********************************************************************/
    64 /***********************************************************************/
    58 
    65 
   780     }
   787     }
   781 
   788 
   782     /*  signed_integer DOTDOT signed_integer */
   789     /*  signed_integer DOTDOT signed_integer */
   783     //SYM_REF2(subrange_c, lower_limit, upper_limit)
   790     //SYM_REF2(subrange_c, lower_limit, upper_limit)
   784     void *visit(subrange_c *symbol) {
   791     void *visit(subrange_c *symbol) {
   785       int dimension = extract_int64_value(symbol->upper_limit) - extract_int64_value(symbol->lower_limit) + 1;
       
   786       switch (current_mode) {
   792       switch (current_mode) {
   787         case arrayname_im:
   793         case arrayname_im:
   788           current_array_name += "_";
   794           current_array_name += "_";
   789           {
   795           {
   790             std::stringstream ss;
   796             std::stringstream ss;
   791             ss << dimension;
   797             ss << symbol->dimension;
   792             current_array_name += ss.str();
   798             current_array_name += ss.str();
   793           }
   799           }
   794           break;
   800           break;
   795         case arraydeclaration_im:
   801         case arraydeclaration_im:
   796           s4o_incl.print("[");
   802           s4o_incl.print("[");
   797           s4o_incl.print_integer(dimension);
   803           s4o_incl.print_integer(symbol->dimension);
   798           s4o_incl.print("]");
   804           s4o_incl.print("]");
   799         default:
   805         default:
   800           generate_c_typedecl_c::visit(symbol);
   806           generate_c_typedecl_c::visit(symbol);
   801           break;
   807           break;
   802       }
   808       }