stage4/generate_c/generate_c_st.cc
author Mario de Sousa <msousa@fe.up.pt>
Wed, 30 Mar 2011 19:53:32 +0100
changeset 257 90782e241346
parent 202 da1a8186f86f
child 258 d7d92b2f87e9
permissions -rwxr-xr-x
Huge change.
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     1
/*
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     2
 * (c) 2003 Mario de Sousa
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     3
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     4
 * Offered to the public under the terms of the GNU General Public License
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     5
 * as published by the Free Software Foundation; either version 2 of the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     6
 * License, or (at your option) any later version.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     7
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     8
 * This program is distributed in the hope that it will be useful, but
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    11
 * Public License for more details.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    12
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    13
 * This code is made available on the understanding that it will not be
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    14
 * used in safety-critical situations without a full and competent review.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    15
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    16
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    17
/*
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    18
 * An IEC 61131-3 IL and ST compiler.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    19
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    20
 * Based on the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    21
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    22
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    23
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    24
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    25
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    26
/*
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    27
 * Conversion of st statements (i.e. ST code).
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    28
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    29
 * This is part of the 4th stage that generates
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    30
 * a c++ source program equivalent to the IL and ST
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    31
 * code.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    32
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    33
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    34
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    35
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    36
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    37
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    38
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    39
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    40
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    41
class generate_c_st_c: public generate_c_typedecl_c {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    42
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    43
  private:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    44
    /* When calling a function block, we must first find it's type,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    45
     * by searching through the declarations of the variables currently
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    46
     * in scope.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    47
     * This class does just that...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    48
     * A new class is instantiated whenever we begin generating the code
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    49
     * for a function block type declaration, or a program declaration.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    50
     * This object instance will then later be called while the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    51
     * function block's or the program's body is being handled.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    52
     *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    53
     * Note that functions cannot contain calls to function blocks,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    54
     * so we do not create an object instance when handling
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    55
     * a function declaration.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    56
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    57
    search_fb_instance_decl_c *search_fb_instance_decl;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    58
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    59
    /* When compiling st code, it becomes necessary to determine the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    60
     * data type of st expressions. To do this, we must first find the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    61
     * st operand's declaration, within the scope of the function block
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    62
     * or function currently being processed.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    63
     * The following object does just that...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    64
     * This object instance will then later be called while the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    65
     * remaining st code is being handled.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    66
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    67
    search_expression_type_c *search_expression_type;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    68
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    69
    search_varfb_instance_type_c *search_varfb_instance_type;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    70
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
    71
    search_base_type_c search_base_type;
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
    72
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
    73
    symbol_c* current_array_type;
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
    74
145
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
    75
    bool current_param_is_pointer;
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
    76
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    77
  public:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    78
    generate_c_st_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    79
    : generate_c_typedecl_c(s4o_ptr) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    80
      search_fb_instance_decl = new search_fb_instance_decl_c(scope);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    81
      search_expression_type = new search_expression_type_c(scope);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    82
      search_varfb_instance_type = new search_varfb_instance_type_c(scope);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    83
      this->set_variable_prefix(variable_prefix);
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
    84
      current_array_type = NULL;
145
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
    85
      current_param_is_pointer = false;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    86
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    87
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    88
    virtual ~generate_c_st_c(void) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    89
      delete search_fb_instance_decl;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    90
      delete search_expression_type;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    91
      delete search_varfb_instance_type;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    92
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    93
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    94
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    95
  public:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    96
    void generate(statement_list_c *stl) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    97
      stl->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    98
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    99
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   100
  private:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   101
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 145
diff changeset
   102
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   103
/*********************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   104
/* B 1.4 - Variables */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   105
/*********************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   106
void *visit(symbolic_variable_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   107
  unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
145
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
   108
  if (!current_param_is_pointer && (vartype == search_var_instance_decl_c::external_vt || vartype == search_var_instance_decl_c::located_vt)) {
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   109
    s4o.print("*(");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   110
    generate_c_base_c::visit(symbol);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   111
    s4o.print(")");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   112
  }
145
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
   113
  else if (current_param_is_pointer && vartype != search_var_instance_decl_c::external_vt && vartype != search_var_instance_decl_c::located_vt) {
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
   114
    s4o.print("&(");
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
   115
    generate_c_base_c::visit(symbol);
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
   116
    s4o.print(")");
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
   117
  }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   118
  else {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   119
    generate_c_base_c::visit(symbol);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   120
  }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   121
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   122
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   123
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   124
/********************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   125
/* B.1.4.1   Directly Represented Variables */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   126
/********************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   127
// direct_variable: direct_variable_token   {$$ = new direct_variable_c($1);};
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   128
void *visit(direct_variable_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   129
  TRACE("direct_variable_c");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   130
  /* Do not use print_token() as it will change everything into uppercase */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   131
  if (strlen(symbol->value) == 0) ERROR;
145
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
   132
  if (!current_param_is_pointer) {
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
   133
    s4o.print("*(");
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
   134
  }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   135
  this->print_variable_prefix();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   136
  s4o.printlocation(symbol->value + 1);
145
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
   137
  if (!current_param_is_pointer) {
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
   138
    s4o.print(")");
72ae82e65dbc Adding support for ouput variables in functions
lbessard
parents: 130
diff changeset
   139
  }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   140
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   141
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   142
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   143
/*************************************/
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   144
/* B.1.4.2   Multi-element Variables */
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   145
/*************************************/
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   146
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   147
/*  subscripted_variable '[' subscript_list ']' */
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   148
//SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   149
void *visit(array_variable_c *symbol) {
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   150
  current_array_type = search_varfb_instance_type->get_type(symbol->subscripted_variable, false);
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   151
  symbol->subscripted_variable->accept(*this);
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   152
  if (current_array_type != NULL) {
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   153
    symbol->subscript_list->accept(*this);
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   154
    current_array_type = NULL;
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   155
  }
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   156
  return NULL;
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   157
}
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   158
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   159
/* subscript_list ',' subscript */
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   160
void *visit(subscript_list_c *symbol) {
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   161
  for (int i =  0; i < symbol->n; i++) {
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   162
    s4o.print("[__");
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   163
    current_array_type->accept(*this);
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   164
    s4o.print("_TRANSIDX");
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   165
    print_integer(i);
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   166
    s4o.print("(");
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   167
    symbol->elements[i]->accept(*this);
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   168
    s4o.print(")]");
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   169
  }
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   170
  return NULL;
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   171
}
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   172
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   173
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   174
/***************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   175
/* B.3 - Language ST (Structured Text) */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   176
/***************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   177
/***********************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   178
/* B 3.1 - Expressions */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   179
/***********************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   180
void *visit(or_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   181
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   182
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   183
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   184
      ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   185
  if (search_expression_type->is_bool_type(left_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   186
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " || ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   187
  if (search_expression_type->is_binary_type(left_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   188
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " | ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   189
  ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   190
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   191
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   192
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   193
void *visit(xor_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   194
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   195
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   196
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   197
      ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   198
  if (search_expression_type->is_bool_type(left_type)) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   199
    s4o.print("(");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   200
    symbol->l_exp->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   201
    s4o.print(" && !");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   202
    symbol->r_exp->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   203
    s4o.print(") || (!");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   204
    symbol->l_exp->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   205
    s4o.print(" && ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   206
    symbol->r_exp->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   207
    s4o.print(")");
130
a8263f33123f Fixed missing return in XOR operator code gen.
etisserant
parents: 123
diff changeset
   208
    return NULL;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   209
  }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   210
  if (search_expression_type->is_binary_type(left_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   211
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " ^ ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   212
  ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   213
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   214
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   215
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   216
void *visit(and_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   217
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   218
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   219
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   220
      ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   221
  if (search_expression_type->is_bool_type(left_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   222
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " && ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   223
  if (search_expression_type->is_binary_type(left_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   224
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " & ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   225
  ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   226
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   227
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   228
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   229
void *visit(equ_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   230
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   231
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   232
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   233
      ERROR;
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   234
  if (search_expression_type->is_time_type(left_type) ||
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   235
      search_expression_type->is_string_type(left_type))
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   236
    return print_compare_function("__eq_", left_type, symbol->l_exp, symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   237
  return print_binary_expression(symbol->l_exp, symbol->r_exp, " == ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   238
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   239
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   240
void *visit(notequ_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   241
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   242
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   243
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   244
      ERROR;
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   245
  if (search_expression_type->is_time_type(left_type) ||
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   246
      search_expression_type->is_string_type(left_type))
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   247
    return print_compare_function("__ne_", left_type, symbol->l_exp, symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   248
  return print_binary_expression(symbol->l_exp, symbol->r_exp, " != ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   249
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   250
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   251
void *visit(lt_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   252
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   253
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   254
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   255
      ERROR;
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   256
  if (search_expression_type->is_time_type(left_type) ||
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   257
      search_expression_type->is_string_type(left_type))
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   258
    return print_compare_function("__lt_", left_type, symbol->l_exp, symbol->r_exp);
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   259
  if (!search_base_type.type_is_enumerated(left_type))
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   260
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " < ");
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   261
  ERROR;
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   262
  return NULL;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   263
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   264
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   265
void *visit(gt_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   266
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   267
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   268
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   269
      ERROR;
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   270
  if (search_expression_type->is_time_type(left_type) ||
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   271
      search_expression_type->is_string_type(left_type))
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   272
    return print_compare_function("__gt_", left_type, symbol->l_exp, symbol->r_exp);
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   273
  if (!search_base_type.type_is_enumerated(left_type))
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   274
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " > ");
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   275
  ERROR;
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   276
  return NULL;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   277
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   278
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   279
void *visit(le_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   280
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   281
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   282
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   283
      ERROR;
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   284
  if (search_expression_type->is_time_type(left_type) ||
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   285
      search_expression_type->is_string_type(left_type))
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   286
    return print_compare_function("__le_", left_type, symbol->l_exp, symbol->r_exp);
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   287
  if (!search_base_type.type_is_enumerated(left_type))
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   288
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= ");
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   289
  ERROR;
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   290
  return NULL;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   291
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   292
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   293
void *visit(ge_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   294
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   295
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   296
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   297
      ERROR;
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   298
  if (search_expression_type->is_time_type(left_type) ||
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   299
      search_expression_type->is_string_type(left_type))
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   300
    return print_compare_function("__ge_", left_type, symbol->l_exp, symbol->r_exp);
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   301
  if (!search_base_type.type_is_enumerated(left_type))
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   302
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= ");
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   303
  ERROR;
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   304
  return NULL;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   305
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   306
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   307
void *visit(add_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   308
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   309
	symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   310
	if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   311
      (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   312
      (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)))
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   313
    return print_binary_function("__TIME_ADD", symbol->l_exp, symbol->r_exp);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   314
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   315
      ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   316
  if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   317
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " + ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   318
  ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   319
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   320
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   321
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   322
void *visit(sub_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   323
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   324
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   325
  if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   326
      (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   327
      (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   328
      (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   329
      (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   330
      (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c)))
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   331
    return print_binary_function("__TIME_SUB", symbol->l_exp, symbol->r_exp);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   332
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   333
      ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   334
  if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   335
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " - ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   336
  ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   337
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   338
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   339
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   340
void *visit(mul_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   341
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   342
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   343
  if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   344
      (typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type)))
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   345
    return print_binary_function("__TIME_MUL", symbol->l_exp, symbol->r_exp);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   346
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   347
      ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   348
  if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   349
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " * ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   350
  ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   351
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   352
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   353
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   354
void *visit(div_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   355
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   356
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   357
  if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) ||
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   358
      (typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type)))
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   359
    return print_binary_function("__TIME_DIV", symbol->l_exp, symbol->r_exp);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   360
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   361
      ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   362
  if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   363
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " / ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   364
  ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   365
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   366
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   367
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   368
void *visit(mod_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   369
  symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   370
  symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   371
  if (!search_expression_type->is_same_type(left_type, right_type))
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   372
      ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   373
  if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   374
    s4o.print("((");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   375
    symbol->r_exp->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   376
    s4o.print(" == 0)?0:");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   377
    print_binary_expression(symbol->l_exp, symbol->r_exp, " % ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   378
    s4o.print(")");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   379
    return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   380
  }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   381
  ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   382
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   383
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   384
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   385
/* TODO: power expression... */
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   386
void *visit(power_expression_c *symbol) {
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   387
  ERROR; 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   388
  return print_binary_expression(symbol->l_exp, symbol->r_exp, " ** ");
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   389
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   390
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   391
void *visit(neg_expression_c *symbol) {
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   392
  return print_unary_expression(symbol->exp, " -");
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   393
}
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   394
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   395
void *visit(not_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   396
  symbol_c *exp_type = search_expression_type->get_type(symbol->exp);
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   397
  if (search_expression_type->is_binary_type(exp_type))
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   398
    return print_unary_expression(symbol->exp, search_expression_type->is_bool_type(exp_type)?"!":"~");
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   399
  ERROR;
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   400
  return NULL;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   401
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   402
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   403
void *visit(function_invocation_c *symbol) {
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   404
  symbol_c* function_type_prefix = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   405
  symbol_c* function_name = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   406
  symbol_c* function_type_suffix = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   407
  std::list<FUNCTION_PARAM> param_list;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   408
  FUNCTION_PARAM *param;
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   409
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   410
  symbol_c *parameter_assignment_list = NULL;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   411
  if (NULL != symbol->   formal_param_list) parameter_assignment_list = symbol->   formal_param_list;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   412
  if (NULL != symbol->nonformal_param_list) parameter_assignment_list = symbol->nonformal_param_list;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   413
  if (NULL == parameter_assignment_list) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   414
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   415
  function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   416
  if (f_decl == function_symtable.end_value()) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   417
    /* The function called is not in the symtable, so we test if it is a
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   418
     * standard function defined in standard */
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   419
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   420
    function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   421
    if (current_function_type == function_none) ERROR;
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   422
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   423
    symbol_c *function_return_type = search_expression_type->get_type(symbol);
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   424
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   425
    function_call_param_iterator_c function_call_param_iterator(symbol);
167
ae423926bc84 Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents: 162
diff changeset
   426
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   427
    int nb_param = ((list_c *)parameter_assignment_list)->n;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   428
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   429
    identifier_c en_param_name("EN");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   430
    /* Get the value from EN param */
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   431
    symbol_c *EN_param_value = function_call_param_iterator.search_f(&en_param_name);
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   432
    if (EN_param_value == NULL)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   433
      EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c()));
167
ae423926bc84 Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents: 162
diff changeset
   434
    else
ae423926bc84 Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents: 162
diff changeset
   435
      nb_param --;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   436
    ADD_PARAM_LIST(EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in)
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   437
162
60a124678842 Fixed typo in EN/ENO parameters handling for std library functions
etisserant
parents: 160
diff changeset
   438
    identifier_c eno_param_name("ENO");
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   439
    /* Get the value from ENO param */
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   440
    symbol_c *ENO_param_value = function_call_param_iterator.search_f(&eno_param_name);
167
ae423926bc84 Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents: 162
diff changeset
   441
    if (ENO_param_value != NULL)
ae423926bc84 Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents: 162
diff changeset
   442
      nb_param --;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   443
    ADD_PARAM_LIST(ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out)
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   444
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   445
    #define search(x) search_f(x)
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   446
    #define next() next_nf()
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   447
//     #define search_constant_type_c::constant_int_type_name  search_expression_type_c::integer
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   448
    #define constant_int_type_name  integer
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 145
diff changeset
   449
    #include "st_code_gen.c"
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   450
    #undef constant_int_type_name
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   451
//     #undef search_constant_type_c::constant_int_type_name
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   452
    #undef next
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   453
    #undef  search
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   454
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   455
  }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   456
  else {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   457
    /* loop through each function parameter, find the value we should pass
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   458
     * to it, and then output the c equivalent...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   459
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   460
    function_param_iterator_c fp_iterator(f_decl);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   461
  
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   462
    function_name = symbol->function_name;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   463
  
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   464
    identifier_c *param_name;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   465
    function_call_param_iterator_c function_call_param_iterator(symbol);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   466
    for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   467
      
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   468
      function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   469
      
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   470
      /* Get the value from a foo(<param_name> = <param_value>) style call */
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   471
      symbol_c *param_value = function_call_param_iterator.search_f(param_name);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   472
  
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   473
      /* Get the value from a foo(<param_value>) style call */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   474
      if (param_value == NULL)
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   475
        param_value = function_call_param_iterator.next_nf();
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   476
      
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   477
      if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   478
        /* No value given for parameter, so we must use the default... */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   479
        /* First check whether default value specified in function declaration...*/
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   480
        param_value = fp_iterator.default_value();
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   481
      }
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   482
      
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   483
      symbol_c *param_type = fp_iterator.param_type();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   484
      if (param_type == NULL) ERROR;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   485
      
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   486
      ADD_PARAM_LIST(param_value, param_type, param_direction)
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   487
    } /* for(...) */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   488
    // symbol->parameter_assignment->accept(*this);
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   489
  }
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   490
  
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   491
  if (function_type_prefix != NULL) {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   492
    s4o.print("(");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   493
    function_type_prefix->accept(*this);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   494
    s4o.print(")");
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   495
  }
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   496
  if (function_name != NULL)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   497
    function_name->accept(*this);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   498
  if (function_type_suffix != NULL)
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   499
    function_type_suffix->accept(*this);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   500
  s4o.print("(");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   501
  s4o.indent_right();
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   502
  
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   503
  std::list<FUNCTION_PARAM>::iterator pt;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   504
  for(pt = param_list.begin(); pt != param_list.end(); pt++) {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   505
    if (pt != param_list.begin())
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   506
      s4o.print(",\n"+s4o.indent_spaces);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   507
    symbol_c *param_value = pt->param_value;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   508
    symbol_c *param_type = pt->param_type;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   509
          
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   510
    switch (pt->param_direction) {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   511
      case function_param_iterator_c::direction_in:
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   512
        if (param_value == NULL) {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   513
          /* If not, get the default value of this variable's type */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   514
          param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance());
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   515
        }
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   516
        if (param_value == NULL) ERROR;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   517
        if (search_base_type.type_is_subrange(param_type)) {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   518
          s4o.print("__CHECK_");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   519
          param_type->accept(*this);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   520
          s4o.print("(");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   521
        }
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   522
        param_value->accept(*this);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   523
        if (search_base_type.type_is_subrange(param_type))
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   524
          s4o.print(")");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   525
        break;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   526
      case function_param_iterator_c::direction_out:
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   527
      case function_param_iterator_c::direction_inout:
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   528
        current_param_is_pointer = true;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   529
        if (param_value == NULL) {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   530
          s4o.print("NULL");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   531
        } else {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   532
          param_value->accept(*this);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   533
        }
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   534
        current_param_is_pointer = false;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   535
        break;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   536
      case function_param_iterator_c::direction_extref:
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   537
        /* TODO! */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   538
        ERROR;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   539
        break;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   540
    } /* switch */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   541
  }  
169
bea932bc60b0 Bug when function with unconnected input fixed
lbessard
parents: 167
diff changeset
   542
  
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   543
  s4o.print(")");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   544
  s4o.indent_left();
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   545
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   546
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   547
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   548
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   549
/********************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   550
/* B 3.2 Statements */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   551
/********************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   552
void *visit(statement_list_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   553
  return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   554
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   555
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   556
/*********************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   557
/* B 3.2.1 Assignment Statements */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   558
/*********************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   559
void *visit(assignment_statement_c *symbol) {
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   560
  symbol_c *left_type = search_varfb_instance_type->get_type(symbol->l_exp, false);
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   561
  
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   562
  symbol->l_exp->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   563
  s4o.print(" = ");
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   564
  if (search_base_type.type_is_subrange(left_type)) {
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   565
    s4o.print("__CHECK_");
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   566
    left_type->accept(*this);
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   567
    s4o.print("(");
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   568
  }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   569
  symbol->r_exp->accept(*this);
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   570
  if (search_base_type.type_is_subrange(left_type))
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   571
    s4o.print(")");
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   572
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   573
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   574
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   575
/*****************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   576
/* B 3.2.2 Subprogram Control Statements */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   577
/*****************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   578
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   579
/* fb_name '(' [param_assignment_list] ')' */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   580
/* param_assignment_list -> may be NULL ! */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   581
//SYM_REF2(fb_invocation_c, fb_name, param_assignment_list)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   582
void *visit(fb_invocation_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   583
  TRACE("fb_invocation_c");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   584
  /* first figure out what is the name of the function block type of the function block being called... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   585
  symbol_c *function_block_type_name = this->search_fb_instance_decl->get_type_name(symbol->fb_name);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   586
    /* should never occur. The function block instance MUST have been declared... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   587
  if (function_block_type_name == NULL) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   588
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   589
  /* Now find the declaration of the function block type being called... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   590
  function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(function_block_type_name);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   591
    /* should never occur. The function block type being called MUST be in the symtable... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   592
  if (fb_decl == function_block_type_symtable.end_value()) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   593
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   594
  /* loop through each function block parameter, find the value we should pass
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   595
   * to it, and then output the c equivalent...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   596
   */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   597
  function_param_iterator_c fp_iterator(fb_decl);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   598
  identifier_c *param_name;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   599
  function_call_param_iterator_c function_call_param_iterator(symbol);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   600
  for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   601
    function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
160
59d58f5e6caa Adding support for compiling struct data types
lbessard
parents: 149
diff changeset
   602
    
162
60a124678842 Fixed typo in EN/ENO parameters handling for std library functions
etisserant
parents: 160
diff changeset
   603
    /*fprintf(stderr, "param : %s\n", param_name->value);*/
160
59d58f5e6caa Adding support for compiling struct data types
lbessard
parents: 149
diff changeset
   604
    
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   605
    /* Get the value from a foo(<param_name> = <param_value>) style call */
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   606
    symbol_c *param_value = function_call_param_iterator.search_f(param_name);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   607
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   608
    /* Get the value from a foo(<param_value>) style call */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   609
    if (param_value == NULL)
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   610
      param_value = function_call_param_iterator.next_nf();
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   611
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   612
    symbol_c *param_type = fp_iterator.param_type();
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   613
    if (param_type == NULL) ERROR;
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   614
    
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   615
    /* now output the value assignment */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   616
    if (param_value != NULL)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   617
      if ((param_direction == function_param_iterator_c::direction_in) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   618
          (param_direction == function_param_iterator_c::direction_inout)) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   619
        print_variable_prefix();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   620
        symbol->fb_name->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   621
        s4o.print(".");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   622
        param_name->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   623
        s4o.print(" = ");
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   624
        if (search_base_type.type_is_subrange(param_type)) {
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   625
          s4o.print("__CHECK_");
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   626
          param_type->accept(*this);
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   627
          s4o.print("(");
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   628
        }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   629
        param_value->accept(*this);
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   630
        if (search_base_type.type_is_subrange(param_type))
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   631
          s4o.print(")");
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   632
        s4o.print(";\n" + s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   633
      }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   634
  } /* for(...) */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   635
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   636
  /* now call the function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   637
  function_block_type_name->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   638
  s4o.print(FB_FUNCTION_SUFFIX);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   639
  s4o.print("(&");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   640
  print_variable_prefix();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   641
  symbol->fb_name->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   642
  s4o.print(")");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   643
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   644
  /* loop through each function parameter, find the variable to which
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   645
   * we should atribute the value of all output or inoutput parameters.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   646
   */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   647
  fp_iterator.reset();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   648
  function_call_param_iterator.reset();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   649
  for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   650
    function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   651
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   652
    /* Get the value from a foo(<param_name> = <param_value>) style call */
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   653
    symbol_c *param_value = function_call_param_iterator.search_f(param_name);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   654
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   655
    /* Get the value from a foo(<param_value>) style call */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   656
    if (param_value == NULL)
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 169
diff changeset
   657
      param_value = function_call_param_iterator.next_nf();
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   658
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   659
    /* now output the value assignment */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   660
    if (param_value != NULL)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   661
      if ((param_direction == function_param_iterator_c::direction_out) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   662
          (param_direction == function_param_iterator_c::direction_inout)) {
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   663
        symbol_c *param_type = search_varfb_instance_type->get_type(param_value, false);
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   664
        
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   665
        s4o.print(";\n"+ s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   666
        param_value->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   667
        s4o.print(" = ");
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   668
        if (search_base_type.type_is_subrange(param_type)) {
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   669
          s4o.print("__CHECK_");
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   670
          param_type->accept(*this);
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   671
          s4o.print("(");
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   672
        }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   673
        print_variable_prefix();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   674
        symbol->fb_name->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   675
        s4o.print(".");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   676
        param_name->accept(*this);
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 101
diff changeset
   677
        if (search_base_type.type_is_subrange(param_type))
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   678
          s4o.print(")");
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   679
      }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   680
  } /* for(...) */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   681
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   682
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   683
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   684
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   685
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   686
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   687
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   688
/* helper symbol for fb_invocation */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   689
/* param_assignment_list ',' param_assignment */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   690
void *visit(param_assignment_list_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   691
  TRACE("param_assignment_list_c");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   692
  /* this should never be called... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   693
  ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   694
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   695
//  return print_list(symbol, "", ", ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   696
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   697
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   698
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   699
void *visit(input_variable_param_assignment_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   700
  TRACE("input_variable_param_assignment_c");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   701
  /* this should never be called... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   702
  ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   703
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   704
/*
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   705
  symbol->variable_name->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   706
  s4o.print(" = ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   707
  symbol->expression->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   708
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   709
*/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   710
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   711
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   712
void *visit(output_variable_param_assignment_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   713
  TRACE("output_variable_param_assignment_c");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   714
  /* this should never be called... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   715
  ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   716
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   717
/*
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   718
  s4o.print(s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   719
  if (symbol->not_param != NULL)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   720
    symbol->not_param->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   721
  symbol->variable_name->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   722
  s4o.print(" => ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   723
  symbol->variable->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   724
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   725
*/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   726
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   727
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   728
// TODO: the NOT symbol in function (block) calls...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   729
void *visit(not_paramassign_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   730
  TRACE("not_paramassign_c");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   731
  /* this should never be called... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   732
  ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   733
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   734
/*
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   735
  s4o.print("NOT ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   736
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   737
*/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   738
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   739
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   740
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   741
/********************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   742
/* B 3.2.3 Selection Statements */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   743
/********************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   744
void *visit(if_statement_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   745
  s4o.print("if (");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   746
  symbol->expression->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   747
  s4o.print(") {\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   748
  s4o.indent_right();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   749
  symbol->statement_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   750
  s4o.indent_left();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   751
  symbol->elseif_statement_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   752
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   753
  if (symbol->else_statement_list != NULL) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   754
    s4o.print(s4o.indent_spaces); s4o.print("} else {\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   755
    s4o.indent_right();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   756
    symbol->else_statement_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   757
    s4o.indent_left();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   758
  }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   759
  s4o.print(s4o.indent_spaces); s4o.print("}");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   760
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   761
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   762
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   763
/* helper symbol for if_statement */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   764
void *visit(elseif_statement_list_c *symbol) {return print_list(symbol);}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   765
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   766
/* helper symbol for elseif_statement_list */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   767
void *visit(elseif_statement_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   768
  s4o.print(s4o.indent_spaces); s4o.print("} else if (");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   769
  symbol->expression->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   770
  s4o.print(") {\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   771
  s4o.indent_right();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   772
  symbol->statement_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   773
  s4o.indent_left();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   774
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   775
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   776
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   777
void *visit(case_statement_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   778
  s4o.print("switch(");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   779
  symbol->expression->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   780
  s4o.print(") {\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   781
  s4o.indent_right();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   782
  symbol->case_element_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   783
  if (symbol->statement_list != NULL) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   784
    s4o.print(s4o.indent_spaces + "default:\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   785
    s4o.indent_right();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   786
    symbol->statement_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   787
    s4o.print(s4o.indent_spaces + "break;\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   788
    s4o.indent_left();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   789
  }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   790
  s4o.indent_left();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   791
  s4o.print(s4o.indent_spaces + "}");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   792
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   793
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   794
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   795
/* helper symbol for case_statement */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   796
void *visit(case_element_list_c *symbol) {return print_list(symbol);}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   797
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   798
void *visit(case_element_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   799
  s4o.print(s4o.indent_spaces + "case ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   800
  symbol->case_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   801
  s4o.print(" :\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   802
  s4o.indent_right();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   803
  symbol->statement_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   804
  s4o.print(s4o.indent_spaces + "break;\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   805
  s4o.indent_left();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   806
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   807
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   808
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   809
void *visit(case_list_c *symbol) {return print_list(symbol, "", ", ");}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   810
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   811
/********************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   812
/* B 3.2.4 Iteration Statements */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   813
/********************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   814
void *visit(for_statement_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   815
  s4o.print("for(");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   816
  symbol->control_variable->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   817
  s4o.print(" = ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   818
  symbol->beg_expression->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   819
  s4o.print("; ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   820
  symbol->control_variable->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   821
  s4o.print(" != ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   822
  symbol->end_expression->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   823
  s4o.print("; ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   824
  symbol->control_variable->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   825
  if (symbol->by_expression != NULL) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   826
    s4o.print(" += ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   827
    symbol->by_expression->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   828
  } else {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   829
    s4o.print("++");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   830
  }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   831
  s4o.print(") {\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   832
  s4o.indent_right();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   833
  symbol->statement_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   834
  s4o.indent_left();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   835
  s4o.print(s4o.indent_spaces); s4o.print("}");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   836
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   837
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   838
void *visit(while_statement_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   839
  s4o.print("while (");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   840
  symbol->expression->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   841
  s4o.print(") {\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   842
  s4o.indent_right();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   843
  symbol->statement_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   844
  s4o.indent_left();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   845
  s4o.print(s4o.indent_spaces); s4o.print("}");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   846
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   847
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   848
void *visit(repeat_statement_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   849
  s4o.print("do {\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   850
  s4o.indent_right();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   851
  symbol->statement_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   852
  s4o.indent_left();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   853
  s4o.print(s4o.indent_spaces); s4o.print("} while(");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   854
  symbol->expression->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   855
  s4o.print(")");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   856
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   857
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   858
void *visit(exit_statement_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   859
  s4o.print("exit(0)");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   860
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   861
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   862
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   863
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   864
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   865
}; /* generate_c_st_c */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   866
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   867
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   868
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   869
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   870
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   871
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   872
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   873
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   874