stage4/generate_c/generate_c_il.cc
author Laurent Bessard
Thu, 15 Nov 2012 22:28:53 +0100
changeset 706 31553c22f318
parent 625 c0bda77b37a0
child 793 268bf4ca5fa1
permissions -rwxr-xr-x
Adding support for declaring function block instances as global and external variables
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     1
/*
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     3
 *
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
     4
 *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
     5
 *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     6
 *
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
     7
 *  This program is free software: you can redistribute it and/or modify
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
     8
 *  it under the terms of the GNU General Public License as published by
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
     9
 *  the Free Software Foundation, either version 3 of the License, or
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    10
 *  (at your option) any later version.
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    11
 *
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    12
 *  This program is distributed in the hope that it will be useful,
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    15
 *  GNU General Public License for more details.
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    16
 *
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    17
 *  You should have received a copy of the GNU General Public License
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    19
 *
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    20
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    21
 * This code is made available on the understanding that it will not be
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    22
 * used in safety-critical situations without a full and competent review.
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
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    28
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    29
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    30
/* Returns the data type of an il_operand.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    31
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    32
 * Note that the il_operand may be a variable, in which case
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    33
 * we return the type of the variable instance.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    34
 * The il_operand may also be a constant, in which case
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    35
 * we return the data type of that constant.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    36
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    37
 * The variable instance may be a member of a structured variable,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    38
 * or an element in an array, or any combination of the two.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    39
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    40
 * The class constructor must be given the search scope
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    41
 * (function, function block or program within which
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    42
 * the possible il_operand variable instance was declared).
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    43
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    44
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    45
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    46
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    47
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    48
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    49
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    50
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    51
/* A new class to ouput the il default variable to c++ code
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    52
 * We use this class, inheriting from symbol_c, so it may be used
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    53
 * as any other symbol_c object in the intermediate parse tree,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    54
 * more specifically, so it can be used as any other il operand.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    55
 * This makes the rest of the code much easier...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    56
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    57
 * Nevertheless, the basic visitor class visitor_c does not know
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    58
 * how to visit this new il_default_variable_c class, so we have
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    59
 * to extend that too.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    60
 * In reality extending the basic symbols doesn't quite work out
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    61
 * as cleanly as desired (we need to use dynamic_cast in the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    62
 * accept method of the il_default_variable_c), but it is cleaner
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    63
 * than the alternative...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    64
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    65
class il_default_variable_c;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    66
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    67
/* This visitor class is not really required, we could place the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    68
 * visit() method directly in genertae_cc_il_c, but doing it in
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    69
 * a seperate class makes the architecture more evident...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    70
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    71
class il_default_variable_visitor_c {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    72
  public:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    73
    virtual void *visit(il_default_variable_c *symbol) = 0;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    74
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    75
    virtual ~il_default_variable_visitor_c(void) {return;}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    76
};
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    77
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    78
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    79
/* A class to print out to the resulting C++ code
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    80
 * the IL default variable name.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    81
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    82
 * It includes a reference to its name,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    83
 * and the data type of the data currently stored
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    84
 * in this C++ variable... This is required because the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    85
 * C++ variable is a union, and we must know which member
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    86
 * of the union top reference!!
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    87
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    88
 * Note that we also need to keep track of the data type of
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    89
 * the value currently being stored in the default variable.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    90
 * This is required so we can process parenthesis,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    91
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    92
 * e.g. :
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    93
 *         LD var1
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    94
 *         AND (
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    95
 *         LD var2
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    96
 *         OR var3
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    97
 *         )
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    98
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    99
 * Note that we only execute the 'AND (' operation when we come across
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   100
 * the ')', i.e. once we have evaluated the result of the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   101
 * instructions inside the parenthesis.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   102
 * When we do execute the 'AND (' operation, we need to know the data type
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   103
 * of the operand, which in this case is the result of the evaluation of the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   104
 * instruction list inside the parenthesis. We can only know this if we
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   105
 * keep track of the data type currently stored in the default variable!
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   106
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   107
 * We use the current_type inside the generate_c_il::default_variable_name variable
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   108
 * to track this!
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   109
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   110
class il_default_variable_c: public symbol_c {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   111
  public:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   112
    symbol_c *var_name;  /* in principle, this should point to an indentifier_c */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   113
    symbol_c *current_type;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   114
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   115
  public:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   116
    il_default_variable_c(const char *var_name_str, symbol_c *current_type);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   117
    virtual void *accept(visitor_c &visitor);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   118
};
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   119
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   120
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   121
/***********************************************************************/
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
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   126
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   127
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   128
class generate_c_il_c: public generate_c_typedecl_c, il_default_variable_visitor_c {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   129
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   130
  public:
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   131
    typedef enum {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   132
      expression_vg,
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   133
      assignment_vg,
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   134
      complextype_base_vg,
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   135
      complextype_base_assignment_vg,
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   136
      complextype_suffix_vg,
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   137
      fparam_output_vg
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   138
    } variablegeneration_t;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   139
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   140
  private:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   141
    /* When compiling il code, it becomes necessary to determine the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   142
     * data type of il operands. To do this, we must first find the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   143
     * il operand's declaration, within the scope of the function block
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   144
     * or function currently being processed.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   145
     * The following object does just that...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   146
     * This object instance will then later be called while the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   147
     * remaining il code is being handled.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   148
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   149
    search_expression_type_c *search_expression_type;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   150
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   151
    /* The initial value that should be given to the IL default variable
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   152
     * imediately after a parenthesis is opened.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   153
     * This variable is only used to pass data from the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   154
     * il_expression_c visitor to the simple_instr_list_c visitor.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   155
     *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   156
     * e.g.:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   157
     *         LD var1
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   158
     *         AND ( var2
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   159
     *         OR var3
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   160
     *         )
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   161
     *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   162
     * In the above code sample, the line 'AND ( var2' constitutes
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   163
     * an il_expression_c, where var2 should be loaded into the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   164
     * il default variable before continuing with the expression
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   165
     * inside the parenthesis.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   166
     * Unfortunately, only the simple_instr_list_c may do the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   167
     * initial laoding of the var2 bariable following the parenthesis,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   168
     * so the il_expression_c visitor will have to pass 'var2' as a
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   169
     * parameter to the simple_instr_list_c visitor.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   170
     * Ergo, the existance of the following parameter...!
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   171
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   172
    symbol_c *il_default_variable_init_value;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   173
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   174
    /* Operand to the IL operation currently being processed... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   175
    /* These variables are used to pass data from the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   176
     * il_simple_operation_c and il_expression_c visitors
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   177
     * to the il operator visitors (i.e. LD_operator_c,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   178
     * LDN_operator_c, ST_operator_c, STN_operator_c, ...)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   179
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   180
    symbol_c *current_operand;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   181
    symbol_c *current_operand_type;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   182
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   183
    /* Label to which the current IL jump operation should jump to... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   184
    /* This variable is used to pass data from the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   185
     * il_jump_operation_c visitor
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   186
     * to the il jump operator visitors (i.e. JMP_operator_c,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   187
     * JMPC_operator_c, JMPCN_operator_c, ...)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   188
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   189
    symbol_c *jump_label;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   190
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   191
    /* The result of the comparison IL operations (GT, EQ, LT, ...)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   192
     * is a boolean variable.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   193
     * This class keeps track of the current data type stored in the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   194
     * il default variable. This is usually done by keeping a reference
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   195
     * to the data type of the last operand. Nevertheless, in the case of
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   196
     * the comparison IL operators, the data type of the result (a boolean)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   197
     * is not the data type of the operand. We therefore need an object
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   198
     * of the boolean data type to keep as a reference of the current
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   199
     * data type.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   200
     * The following object is it...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   201
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   202
    bool_type_name_c bool_type;
210
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   203
    lint_type_name_c lint_type;
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   204
    lword_type_name_c lword_type;
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   205
    lreal_type_name_c lreal_type;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   206
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   207
    /* the data type of the IL default variable... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   208
    #define IL_DEFVAR_T VAR_LEADER "IL_DEFVAR_T"
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   209
    /* The name of the IL default variable... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   210
    #define IL_DEFVAR   VAR_LEADER "IL_DEFVAR"
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   211
    /* The name of the variable used to pass the result of a
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   212
     * parenthesised instruction list to the immediately preceding
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   213
     * scope ...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   214
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   215
    #define IL_DEFVAR_BACK   VAR_LEADER "IL_DEFVAR_BACK"
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   216
    il_default_variable_c default_variable_name;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   217
    il_default_variable_c default_variable_back_name;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   218
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   219
    /* When calling a function block, we must first find it's type,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   220
     * by searching through the declarations of the variables currently
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   221
     * in scope.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   222
     * This class does just that...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   223
     * A new class is instantiated whenever we begin generating the code
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   224
     * for a function block type declaration, or a program declaration.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   225
     * This object instance will then later be called while the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   226
     * function block's or the program's body is being handled.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   227
     *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   228
     * Note that functions cannot contain calls to function blocks,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   229
     * so we do not create an object instance when handling
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   230
     * a function declaration.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   231
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   232
    search_fb_instance_decl_c *search_fb_instance_decl;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   233
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   234
    search_varfb_instance_type_c *search_varfb_instance_type;
505
21be0f2f242d Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents: 498
diff changeset
   235
    search_var_instance_decl_c   *search_var_instance_decl;
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   236
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   237
    search_base_type_c search_base_type;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   238
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   239
    symbol_c* current_array_type;
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   240
    symbol_c* current_param_type;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   241
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   242
    int fcall_number;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   243
    symbol_c *fbname;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   244
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   245
    variablegeneration_t wanted_variablegeneration;
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   246
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   247
  public:
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   248
    generate_c_il_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL)
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   249
    : generate_c_typedecl_c(s4o_ptr),
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   250
      default_variable_name(IL_DEFVAR, NULL),
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   251
      default_variable_back_name(IL_DEFVAR_BACK, NULL)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   252
    {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   253
      search_expression_type = new search_expression_type_c(scope);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   254
      search_fb_instance_decl = new search_fb_instance_decl_c(scope);
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   255
      search_varfb_instance_type = new search_varfb_instance_type_c(scope);
505
21be0f2f242d Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents: 498
diff changeset
   256
      search_var_instance_decl   = new search_var_instance_decl_c(scope);
21be0f2f242d Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents: 498
diff changeset
   257
      
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   258
      current_operand = NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   259
      current_operand_type = NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   260
      il_default_variable_init_value = NULL;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   261
      current_array_type = NULL;
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   262
      current_param_type = NULL;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   263
      fcall_number = 0;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   264
      fbname = name;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   265
      wanted_variablegeneration = expression_vg;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   266
      this->set_variable_prefix(variable_prefix);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   267
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   268
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   269
    virtual ~generate_c_il_c(void) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   270
      delete search_fb_instance_decl;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   271
      delete search_expression_type;
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   272
      delete search_varfb_instance_type;
505
21be0f2f242d Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents: 498
diff changeset
   273
      delete search_var_instance_decl;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   274
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   275
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   276
    void generate(instruction_list_c *il) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   277
      il->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   278
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   279
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   280
    /* Declare the backup to the default variable, that will store the result
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   281
     * of the IL operations executed inside a parenthesis...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   282
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   283
    void declare_backup_variable(void) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   284
      s4o.print(s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   285
      s4o.print(IL_DEFVAR_T);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   286
      s4o.print(" ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   287
      print_backup_variable();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   288
      s4o.print(";\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   289
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   290
    
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   291
    void print_backup_variable(void) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   292
      this->default_variable_back_name.accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   293
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   294
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   295
    void reset_default_variable_name(void) {
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   296
      this->default_variable_name.current_type = NULL;
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   297
      this->default_variable_back_name.current_type = NULL;
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   298
    }
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   299
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   300
  private:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   301
    /* A helper function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   302
    /*
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   303
    bool is_bool_type(symbol_c *type_symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   304
      return (NULL != dynamic_cast<bool_type_name_c *>(type_symbol));
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
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   308
    /* A helper function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   309
    void *XXX_operator(symbol_c *lo, const char *op, symbol_c *ro) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   310
      if ((NULL == lo) || (NULL == ro)) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   311
      if (NULL == op) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   312
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   313
      lo->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   314
      s4o.print(op);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   315
      ro->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   316
      return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   317
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   318
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   319
    /* A helper function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   320
    void *XXX_function(const char *func, symbol_c *lo, symbol_c *ro) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   321
      if ((NULL == lo) || (NULL == ro)) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   322
      if (NULL == func) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   323
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   324
      lo->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   325
      s4o.print(" = ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   326
      s4o.print(func);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   327
      s4o.print("(");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   328
      lo->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   329
      s4o.print(", ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   330
      ro->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   331
      s4o.print(")");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   332
      return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   333
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   334
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   335
    /* A helper function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   336
    void *XXX_CAL_operator(const char *param_name, symbol_c *fb_name) {
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   337
      if (wanted_variablegeneration != expression_vg) {
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   338
        s4o.print(param_name);
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   339
        return NULL;
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   340
      }
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   341
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   342
      if (NULL == fb_name) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   343
      symbolic_variable_c *sv = dynamic_cast<symbolic_variable_c *>(fb_name);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   344
      if (NULL == sv) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   345
      identifier_c *id = dynamic_cast<identifier_c *>(sv->var_name);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   346
      if (NULL == id) ERROR;
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   347
      
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   348
      identifier_c param(param_name);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   349
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   350
      //SYM_REF3(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list)
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   351
      il_assign_operator_c il_assign_operator(&param);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   352
      il_param_assignment_c il_param_assignment(&il_assign_operator, &this->default_variable_name, NULL);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   353
      // SYM_LIST(il_param_list_c)
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   354
      il_param_list_c il_param_list;   
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   355
      il_param_list.add_element(&il_param_assignment);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   356
      CAL_operator_c CAL_operator;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   357
      // SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   358
      il_fb_call_c il_fb_call(&CAL_operator, id, NULL, &il_param_list);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   359
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   360
      il_fb_call.accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   361
      return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   362
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   363
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   364
    /* A helper function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   365
    void *CMP_operator(symbol_c *o, const char *operation) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   366
      if (NULL == o) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   367
      if (NULL == this->default_variable_name.current_type) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   368
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   369
      symbol_c *backup = this->default_variable_name.current_type;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   370
      this->default_variable_name.current_type = &(this->bool_type);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   371
      this->default_variable_name.accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   372
      this->default_variable_name.current_type = backup;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   373
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
      s4o.print(operation);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   376
      this->default_variable_name.current_type->accept(*this);
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   377
      s4o.print("(__BOOL_LITERAL(TRUE), NULL, 2, ");
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   378
      this->default_variable_name.accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   379
      s4o.print(", ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   380
      o->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   381
      s4o.print(")");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   382
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   383
      /* the data type resulting from this operation... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   384
      this->default_variable_name.current_type = &(this->bool_type);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   385
      return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   386
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   387
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   388
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   389
    /* A helper function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   390
    void C_modifier(void) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   391
      if (search_expression_type->is_bool_type(default_variable_name.current_type)) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   392
        s4o.print("if (");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   393
        this->default_variable_name.accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   394
        s4o.print(") ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   395
      }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   396
      else {ERROR;}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   397
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   398
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   399
    /* A helper function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   400
    void CN_modifier(void) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   401
      if (search_expression_type->is_bool_type(default_variable_name.current_type)) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   402
        s4o.print("if (!");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   403
        this->default_variable_name.accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   404
        s4o.print(") ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   405
      }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   406
      else {ERROR;}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   407
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   408
210
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   409
    void BYTE_operator_result_type(void) {
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   410
      if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) {
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   411
        if (search_expression_type->is_literal_integer_type(this->current_operand_type))
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   412
          this->default_variable_name.current_type = &(this->lword_type);
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   413
        else
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   414
          this->default_variable_name.current_type = this->current_operand_type;
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   415
      }
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   416
      else if (search_expression_type->is_literal_integer_type(this->current_operand_type))
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   417
    	  this->current_operand_type = this->default_variable_name.current_type;
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   418
    }
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   419
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   420
    void NUM_operator_result_type(void) {
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   421
      if (search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) {
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   422
        if (search_expression_type->is_literal_integer_type(this->current_operand_type) ||
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   423
            search_expression_type->is_literal_real_type(this->current_operand_type))
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   424
          this->default_variable_name.current_type = &(this->lreal_type);
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   425
        else
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   426
          this->default_variable_name.current_type = this->current_operand_type;
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   427
      }
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   428
      else if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) {
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   429
        if (search_expression_type->is_literal_integer_type(this->current_operand_type))
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   430
          this->default_variable_name.current_type = &(this->lint_type);
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   431
        else if (search_expression_type->is_literal_real_type(this->current_operand_type))
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   432
          this->default_variable_name.current_type = &(this->lreal_type);
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   433
        else
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   434
          this->default_variable_name.current_type = this->current_operand_type;
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   435
      }
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   436
      else if (search_expression_type->is_literal_integer_type(this->current_operand_type) ||
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   437
               search_expression_type->is_literal_real_type(this->current_operand_type))
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   438
        this->current_operand_type = this->default_variable_name.current_type;
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   439
    }
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   440
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   441
    void *print_getter(symbol_c *symbol) {
505
21be0f2f242d Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents: 498
diff changeset
   442
      unsigned int vartype = search_var_instance_decl->get_vartype(symbol);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   443
      if (wanted_variablegeneration == fparam_output_vg) {
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   444
        if (vartype == search_var_instance_decl_c::external_vt) {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   445
          if (search_var_instance_decl->type_is_fb(symbol))
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   446
            s4o.print(GET_EXTERNAL_FB_BY_REF);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   447
          else
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   448
            s4o.print(GET_EXTERNAL_BY_REF);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   449
        }
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   450
        else if (vartype == search_var_instance_decl_c::located_vt)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   451
          s4o.print(GET_LOCATED_BY_REF);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   452
        else
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   453
          s4o.print(GET_VAR_BY_REF);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   454
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   455
      else {
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   456
        if (vartype == search_var_instance_decl_c::external_vt) {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   457
          if (search_var_instance_decl->type_is_fb(symbol))
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   458
            s4o.print(GET_EXTERNAL_FB);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   459
          else
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   460
            s4o.print(GET_EXTERNAL);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   461
        }
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   462
        else if (vartype == search_var_instance_decl_c::located_vt)
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   463
          s4o.print(GET_LOCATED);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   464
        else
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   465
          s4o.print(GET_VAR);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   466
      }
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   467
      s4o.print("(");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   468
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   469
      variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   470
      wanted_variablegeneration = complextype_base_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   471
      symbol->accept(*this);
531
e7d6f28fc882 Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents: 505
diff changeset
   472
      if (search_var_instance_decl->type_is_complex(symbol))
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   473
        s4o.print(",");
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   474
      wanted_variablegeneration = complextype_suffix_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   475
      symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   476
      s4o.print(")");
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   477
      wanted_variablegeneration = old_wanted_variablegeneration;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   478
      return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   479
    }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   480
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   481
    void *print_setter(symbol_c* symbol,
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   482
            symbol_c* type,
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   483
            symbol_c* value,
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   484
            symbol_c* fb_symbol = NULL,
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   485
            symbol_c* fb_value = NULL,
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   486
            bool negative = false) {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   487
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   488
      bool type_is_complex = search_var_instance_decl->type_is_complex(symbol);
405
7b5d67d1aeef Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents: 399
diff changeset
   489
      if (fb_symbol == NULL) {
505
21be0f2f242d Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents: 498
diff changeset
   490
        unsigned int vartype = search_var_instance_decl->get_vartype(symbol);
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   491
        if (vartype == search_var_instance_decl_c::external_vt) {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   492
          if (search_var_instance_decl->type_is_fb(symbol))
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   493
            s4o.print(SET_EXTERNAL_FB);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   494
          else
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   495
            s4o.print(SET_EXTERNAL);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   496
        }
405
7b5d67d1aeef Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents: 399
diff changeset
   497
        else if (vartype == search_var_instance_decl_c::located_vt)
7b5d67d1aeef Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents: 399
diff changeset
   498
          s4o.print(SET_LOCATED);
7b5d67d1aeef Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents: 399
diff changeset
   499
        else
7b5d67d1aeef Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents: 399
diff changeset
   500
          s4o.print(SET_VAR);
7b5d67d1aeef Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents: 399
diff changeset
   501
      }
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   502
      else {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   503
        unsigned int vartype = search_var_instance_decl->get_vartype(fb_symbol);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   504
        if (vartype == search_var_instance_decl_c::external_vt)
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   505
          s4o.print(SET_EXTERNAL_FB);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   506
        else
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   507
          s4o.print(SET_VAR);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   508
      }
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   509
      s4o.print("(");
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   510
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   511
      if (fb_symbol != NULL) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   512
        print_variable_prefix();
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   513
        fb_symbol->accept(*this);
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   514
        s4o.print(".,");
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   515
      }
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   516
      else if (type_is_complex)
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   517
        wanted_variablegeneration = complextype_base_assignment_vg;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   518
      else
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   519
        wanted_variablegeneration = assignment_vg;
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   520
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   521
      symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   522
      s4o.print(",");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   523
      if (negative) {
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   524
        if (search_expression_type->is_bool_type(this->current_operand_type))
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   525
          s4o.print("!");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   526
        else
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   527
          s4o.print("~");
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   528
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   529
      wanted_variablegeneration = expression_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   530
      print_check_function(type, value, fb_value);
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   531
      if (type_is_complex) {
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   532
        s4o.print(",");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   533
        wanted_variablegeneration = complextype_suffix_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   534
        symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   535
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   536
      s4o.print(")");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   537
      wanted_variablegeneration = expression_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   538
      return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   539
    }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   540
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   541
public:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   542
void *visit(il_default_variable_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   543
  symbol->var_name->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   544
  if (NULL != symbol->current_type) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   545
    s4o.print(".");
563
61410284a9b4 little typo in last commited code
Andreas Graeper <agraeper@googemail.com>
parents: 531
diff changeset
   546
    if      ( search_expression_type->is_literal_integer_type(symbol->current_type))                  this->lint_type.accept(*this);
61410284a9b4 little typo in last commited code
Andreas Graeper <agraeper@googemail.com>
parents: 531
diff changeset
   547
    else if ( search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) this->lreal_type.accept(*this);
61410284a9b4 little typo in last commited code
Andreas Graeper <agraeper@googemail.com>
parents: 531
diff changeset
   548
    else if ( search_expression_type->is_bool_type(this->default_variable_name.current_type))         this->bool_type.accept(*this); 
61410284a9b4 little typo in last commited code
Andreas Graeper <agraeper@googemail.com>
parents: 531
diff changeset
   549
    else symbol->current_type->accept(*this);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   550
    s4o.print("var");
563
61410284a9b4 little typo in last commited code
Andreas Graeper <agraeper@googemail.com>
parents: 531
diff changeset
   551
  } return NULL;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   552
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   553
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   554
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   555
private:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   556
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   557
#if 0
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   558
I NEED TO FIX THIS!!!
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   559
TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   560
void *visit(eno_param_c *symbol) {
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   561
  if (this->is_variable_prefix_null()) {
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   562
    s4o.print("*");
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   563
  }
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   564
  else {
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   565
    this->print_variable_prefix();
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   566
  }
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   567
  s4o.print("ENO");
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   568
  return NULL;
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   569
}
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   570
TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   571
#endif
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   572
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   573
377
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   574
/********************************/
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   575
/* B 1.3.3 - Derived data types */
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   576
/********************************/
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   577
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   578
/*  signed_integer DOTDOT signed_integer */
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   579
void *visit(subrange_c *symbol) {
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   580
  symbol->lower_limit->accept(*this);
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   581
  return NULL;
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   582
}
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   583
377
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   584
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   585
void *visit(array_specification_c *symbol) {
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   586
  symbol->non_generic_type_name->accept(*this);
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   587
  return NULL;
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   588
}
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   589
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   590
/*********************/
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   591
/* B 1.4 - Variables */
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   592
/*********************/
221
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 220
diff changeset
   593
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   594
void *visit(symbolic_variable_c *symbol) {
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   595
  unsigned int vartype;
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   596
  switch (wanted_variablegeneration) {
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   597
    case complextype_base_assignment_vg:
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   598
    case assignment_vg:
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   599
      this->print_variable_prefix();
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   600
      s4o.print(",");
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   601
      symbol->var_name->accept(*this);
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   602
      break;
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   603
    case complextype_base_vg:
221
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 220
diff changeset
   604
      generate_c_base_c::visit(symbol);
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   605
      break;
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   606
    case complextype_suffix_vg:
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   607
      break;
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   608
    default:
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   609
      if (this->is_variable_prefix_null()) {
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   610
        vartype = search_var_instance_decl->get_vartype(symbol);
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   611
        if (wanted_variablegeneration == fparam_output_vg) {
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   612
          s4o.print("&(");
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   613
          generate_c_base_c::visit(symbol);
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   614
          s4o.print(")");
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   615
        }
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   616
        else {
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   617
          generate_c_base_c::visit(symbol);
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   618
        }
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   619
      }
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   620
      else
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   621
        print_getter(symbol);
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   622
      break;
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   623
  }
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   624
  return NULL;
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   625
}
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   626
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   627
/********************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   628
/* B.1.4.1   Directly Represented Variables */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   629
/********************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   630
// direct_variable: direct_variable_token   {$$ = new direct_variable_c($1);};
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   631
void *visit(direct_variable_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   632
  TRACE("direct_variable_c");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   633
  /* Do not use print_token() as it will change everything into uppercase */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   634
  if (strlen(symbol->value) == 0) ERROR;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   635
  if (this->is_variable_prefix_null()) {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   636
    if (wanted_variablegeneration != fparam_output_vg)
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   637
      s4o.print("*(");
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   638
  }
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   639
  else {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   640
    switch (wanted_variablegeneration) {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   641
      case expression_vg:
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   642
        s4o.print(GET_LOCATED);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   643
        s4o.print("(");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   644
        break;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   645
      case fparam_output_vg:
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   646
        s4o.print(GET_LOCATED_BY_REF);
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   647
        s4o.print("(");
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   648
        break;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   649
      default:
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   650
        break;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   651
    }
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   652
  }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   653
  this->print_variable_prefix();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   654
  s4o.printlocation(symbol->value + 1);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   655
  if ((this->is_variable_prefix_null() && wanted_variablegeneration != fparam_output_vg) ||
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   656
      wanted_variablegeneration != assignment_vg)
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   657
    s4o.print(")");
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   658
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   659
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   660
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   661
/*************************************/
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   662
/* B.1.4.2   Multi-element Variables */
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   663
/*************************************/
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   664
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   665
// SYM_REF2(structured_variable_c, record_variable, field_selector)
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   666
void *visit(structured_variable_c *symbol) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   667
  TRACE("structured_variable_c");
625
c0bda77b37a0 Merge with c2546c6e0cfa5ad55b288895f17f1b9f2a228f3b
Laurent Bessard
parents: 411 594
diff changeset
   668
  bool type_is_complex = search_var_instance_decl->type_is_complex(symbol->record_variable);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   669
  switch (wanted_variablegeneration) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   670
    case complextype_base_vg:
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   671
    case complextype_base_assignment_vg:
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   672
      symbol->record_variable->accept(*this);
410
c6486bd97392 Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents: 406
diff changeset
   673
      if (!type_is_complex) {
c6486bd97392 Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents: 406
diff changeset
   674
        s4o.print(".");
c6486bd97392 Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents: 406
diff changeset
   675
        symbol->field_selector->accept(*this);
c6486bd97392 Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents: 406
diff changeset
   676
      }
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   677
      break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   678
    case complextype_suffix_vg:
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   679
      symbol->record_variable->accept(*this);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   680
      if (type_is_complex) {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   681
        s4o.print(".");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   682
        symbol->field_selector->accept(*this);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   683
      }
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   684
      break;
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   685
    case assignment_vg:
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   686
      symbol->record_variable->accept(*this);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   687
      s4o.print(".");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   688
      symbol->field_selector->accept(*this);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   689
      break;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   690
    default:
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   691
      if (this->is_variable_prefix_null()) {
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   692
        symbol->record_variable->accept(*this);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   693
        s4o.print(".");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   694
        symbol->field_selector->accept(*this);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   695
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   696
      else
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   697
        print_getter(symbol);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   698
      break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   699
  }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   700
  return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   701
}
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   702
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   703
/*  subscripted_variable '[' subscript_list ']' */
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   704
//SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   705
void *visit(array_variable_c *symbol) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   706
  switch (wanted_variablegeneration) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   707
    case complextype_base_vg:
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   708
    case complextype_base_assignment_vg:
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   709
      symbol->subscripted_variable->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   710
      break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   711
    case complextype_suffix_vg:
238
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   712
      symbol->subscripted_variable->accept(*this);
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   713
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 311
diff changeset
   714
      current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
238
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   715
      if (current_array_type == NULL) ERROR;
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   716
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   717
      s4o.print(".table");
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   718
      symbol->subscript_list->accept(*this);
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   719
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   720
      current_array_type = NULL;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   721
      break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   722
    default:
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   723
      if (this->is_variable_prefix_null()) {
238
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   724
        symbol->subscripted_variable->accept(*this);
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   725
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 311
diff changeset
   726
        current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
238
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   727
        if (current_array_type == NULL) ERROR;
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   728
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   729
        s4o.print(".table");
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   730
        symbol->subscript_list->accept(*this);
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   731
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   732
        current_array_type = NULL;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   733
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   734
      else
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   735
        print_getter(symbol);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   736
      break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   737
  }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   738
  return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   739
}
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   740
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   741
/* subscript_list ',' subscript */
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   742
void *visit(subscript_list_c *symbol) {
377
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   743
  array_dimension_iterator_c* array_dimension_iterator = new array_dimension_iterator_c(current_array_type);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   744
  for (int i =  0; i < symbol->n; i++) {
377
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   745
    symbol_c* dimension = array_dimension_iterator->next();
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   746
    if (dimension == NULL) ERROR;
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   747
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   748
    s4o.print("[(");
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   749
    symbol->elements[i]->accept(*this);
377
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   750
    s4o.print(") - (");
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   751
    dimension->accept(*this);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   752
    s4o.print(")]");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   753
  }
377
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   754
  delete array_dimension_iterator;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   755
  return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   756
}
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   757
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   758
/******************************************/
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   759
/* B 1.4.3 - Declaration & Initialisation */
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   760
/******************************************/
237
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   761
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   762
/* helper symbol for structure_initialization */
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   763
/* structure_element_initialization_list ',' structure_element_initialization */
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   764
void *visit(structure_element_initialization_list_c *symbol) {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   765
  generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   766
  structure_initialization->init_structure_default(this->current_param_type);
237
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   767
  structure_initialization->init_structure_values(symbol);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   768
  delete structure_initialization;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   769
  return NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   770
}
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   771
237
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   772
/* helper symbol for array_initialization */
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   773
/* array_initial_elements_list ',' array_initial_elements */
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   774
void *visit(array_initial_elements_list_c *symbol) {
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   775
  generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o);
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   776
  array_initialization->init_array_size(this->current_param_type);
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   777
  array_initialization->init_array_values(symbol);
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   778
  delete array_initialization;
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   779
  return NULL;
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   780
}
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   781
/****************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   782
/* B.2 - Language IL (Instruction List) */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   783
/****************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   784
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   785
/***********************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   786
/* B 2.1 Instructions and Operands */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   787
/***********************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   788
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   789
/*| instruction_list il_instruction */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   790
void *visit(instruction_list_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   791
  
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   792
  /* Declare the backup to the default variable, that will store the result
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   793
   * of the IL operations executed inside a parenthesis...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   794
   */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   795
  declare_backup_variable();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   796
  
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   797
  /* Declare the default variable, that will store the result of the IL operations... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   798
  s4o.print(s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   799
  s4o.print(IL_DEFVAR_T);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   800
  s4o.print(" ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   801
  this->default_variable_name.accept(*this);
211
5249d313ff7c Remove warnings when compiling IL generated C code
laurent
parents: 210
diff changeset
   802
  s4o.print(";\n");
5249d313ff7c Remove warnings when compiling IL generated C code
laurent
parents: 210
diff changeset
   803
  s4o.print(s4o.indent_spaces);
5249d313ff7c Remove warnings when compiling IL generated C code
laurent
parents: 210
diff changeset
   804
  print_backup_variable();
5249d313ff7c Remove warnings when compiling IL generated C code
laurent
parents: 210
diff changeset
   805
  s4o.print(".INTvar = 0;\n\n");
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   806
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   807
  print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   808
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   809
  return NULL;
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
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   813
/* | label ':' [il_incomplete_instruction] eol_list */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   814
// SYM_REF2(il_instruction_c, label, il_instruction)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   815
void *visit(il_instruction_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   816
  if (NULL != symbol->label) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   817
    symbol->label->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   818
    s4o.print(":\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   819
    s4o.print(s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   820
  }
311
8fcea60029de Allow [EOL] after a label in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 309
diff changeset
   821
  if (NULL != symbol->il_instruction) {
8fcea60029de Allow [EOL] after a label in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 309
diff changeset
   822
    symbol->il_instruction->accept(*this);
8fcea60029de Allow [EOL] after a label in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 309
diff changeset
   823
  }  
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   824
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   825
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   826
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   827
/* | il_simple_operator [il_operand] */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   828
//SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   829
void *visit(il_simple_operation_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   830
  this->current_operand = symbol->il_operand;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   831
  if (NULL == this->current_operand) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   832
    this->current_operand_type = NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   833
  } else {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   834
    this->current_operand_type = search_expression_type->get_type(this->current_operand);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   835
    if (NULL == this->current_operand_type) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   836
  }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   837
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   838
  symbol->il_simple_operator->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   839
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   840
  this->current_operand = NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   841
  this->current_operand_type = NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   842
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   843
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   844
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   845
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   846
/* | function_name [il_operand_list] */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   847
// SYM_REF2(il_function_call_c, function_name, il_operand_list)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   848
void *visit(il_function_call_c *symbol) {
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   849
  symbol_c* function_type_prefix = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   850
  symbol_c* function_name = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   851
  symbol_c* function_type_suffix = NULL;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   852
  DECLARE_PARAM_LIST()
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   853
  
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   854
  symbol_c *param_data_type = default_variable_name.current_type;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   855
  symbol_c *return_data_type = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   856
  
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   857
  function_call_param_iterator_c function_call_param_iterator(symbol);
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   858
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   859
  function_declaration_c *f_decl = (function_declaration_c *)symbol->called_function_declaration;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   860
  if (f_decl == NULL) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   861
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   862
  /* determine the base data type returned by the function being called... */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   863
  search_base_type_c search_base_type;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   864
  return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   865
  if (NULL == return_data_type) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   866
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   867
  function_name = symbol->function_name;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   868
  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   869
  /* loop through each function parameter, find the value we should pass
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   870
   * to it, and then output the c equivalent...
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   871
   */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   872
  function_param_iterator_c fp_iterator(f_decl);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   873
  identifier_c *param_name;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   874
    /* flag to remember whether we have already used the value stored in the default variable to pass to the first parameter */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   875
  bool used_defvar = false; 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   876
    /* flag to cirreclty handle calls to extensible standard functions (i.e. functions with variable number of input parameters) */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   877
  bool found_first_extensible_parameter = false;  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   878
  for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   879
    if (fp_iterator.is_extensible_param() && (!found_first_extensible_parameter)) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   880
      /* We are calling an extensible function. Before passing the extensible
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   881
       * parameters, we must add a dummy paramater value to tell the called
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   882
       * function how many extensible parameters we will be passing.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   883
       *
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   884
       * Note that stage 3 has already determined the number of extensible
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   885
       * paramters, and stored that info in the abstract syntax tree. We simply
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   886
       * re-use that value.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   887
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   888
      /* NOTE: we are not freeing the malloc'd memory. This is not really a bug.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   889
       *       Since we are writing a compiler, which runs to termination quickly,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   890
       *       we can consider this as just memory required for the compilation process
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   891
       *       that will be free'd when the program terminates.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   892
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   893
      char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   894
      if (tmp == NULL) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   895
      int res = snprintf(tmp, 32, "%d", symbol->extensible_param_count);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   896
      if ((res >= 32) || (res < 0)) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   897
      identifier_c *param_value = new identifier_c(tmp);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   898
      uint_type_name_c *param_type  = new uint_type_name_c();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   899
      identifier_c *param_name = new identifier_c("");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   900
      ADD_PARAM_LIST(param_name, param_value, param_type, function_param_iterator_c::direction_in)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   901
      found_first_extensible_parameter = true;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   902
    }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   903
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   904
    symbol_c *param_type = fp_iterator.param_type();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   905
    if (param_type == NULL) ERROR;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   906
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   907
    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
   908
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   909
    symbol_c *param_value = NULL;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   910
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   911
    /* Get the value from a foo(<param_name> = <param_value>) style call */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   912
    /* NOTE: Since the class il_function_call_c only references a non.formal function call,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   913
     * the following line of code is not required in this case. However, it doesn't
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   914
     * harm to leave it in, as in the case of a non-formal syntax function call,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   915
     * it will always return NULL.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   916
     * We leave it in in case we later decide to merge this part of the code together
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   917
     * with the function calling code in generate_c_st_c, which does require
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   918
     * the following line...
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   919
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   920
    if (param_value == NULL)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   921
      param_value = function_call_param_iterator.search_f(param_name);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   922
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   923
    /* if it is the first parameter in a non-formal function call (which is the
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   924
     * case being handled!), semantics specifies that we should
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   925
     * get the value off the IL default variable!
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   926
     *
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   927
     * However, if the parameter is an implicitly defined EN or ENO parameter, we should not
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   928
     * use the default variable as a source of data to pass to those parameters!
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   929
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   930
    if ((param_value == NULL) &&  (!used_defvar) && !fp_iterator.is_en_eno_param_implicit()) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   931
      param_value = &this->default_variable_name;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   932
      used_defvar = true;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   933
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   934
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   935
    /* Get the value from a foo(<param_value>) style call */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   936
    if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   937
      param_value = function_call_param_iterator.next_nf();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   938
    }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   939
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   940
    /* if no more parameter values in function call, and the current parameter
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   941
     * of the function declaration is an extensible parameter, we
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   942
     * have reached the end, and should simply jump out of the for loop.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   943
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   944
    if ((param_value == NULL) && (fp_iterator.is_extensible_param())) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   945
      break;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   946
    }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   947
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   948
    if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   949
      /* No value given for parameter, so we must use the default... */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   950
      /* First check whether default value specified in function declaration...*/
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   951
      param_value = fp_iterator.default_value();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   952
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   953
    
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   954
    ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction())
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   955
  } /* for(...) */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   956
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   957
  if (function_call_param_iterator.next_nf() != NULL) ERROR;
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   958
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   959
  bool has_output_params = false;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   960
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   961
  if (!this->is_variable_prefix_null()) {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   962
    PARAM_LIST_ITERATOR() {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   963
      if ((PARAM_DIRECTION == function_param_iterator_c::direction_out ||
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   964
           PARAM_DIRECTION == function_param_iterator_c::direction_inout) &&
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   965
           PARAM_VALUE != NULL) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   966
        has_output_params = true;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   967
      }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   968
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   969
  }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   970
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   971
  /* Check whether we are calling an overloaded function! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   972
  /* (fdecl_mutiplicity==2)  => calling overloaded function */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   973
  int fdecl_mutiplicity =  function_symtable.multiplicity(symbol->function_name);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   974
  if (fdecl_mutiplicity == 0) ERROR;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   975
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   976
  default_variable_name.current_type = return_data_type;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   977
  this->default_variable_name.accept(*this);
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   978
  default_variable_name.current_type = param_data_type;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   979
  s4o.print(" = ");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   980
    
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   981
  if (function_type_prefix != NULL) {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   982
    s4o.print("(");
336
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   983
    search_expression_type->default_literal_type(function_type_prefix)->accept(*this);
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   984
    s4o.print(")");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   985
  }
336
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   986
  if (function_type_suffix != NULL) {
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   987
    function_type_suffix = search_expression_type->default_literal_type(function_type_suffix);
336
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   988
  }
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   989
  if (has_output_params) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   990
    fcall_number++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   991
    s4o.print("__");
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   992
    fbname->accept(*this);
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   993
    s4o.print("_");
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   994
    function_name->accept(*this);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   995
    if (fdecl_mutiplicity == 2) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   996
      /* function being called is overloaded! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   997
      s4o.print("__");
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 405
diff changeset
   998
      print_function_parameter_data_types_c overloaded_func_suf(&s4o);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   999
      f_decl->accept(overloaded_func_suf);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1000
    }
594
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 563
diff changeset
  1001
    s4o.print(fcall_number);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1002
  }
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1003
  else {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1004
    if (function_name != NULL) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1005
          function_name->accept(*this);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1006
          if (fdecl_mutiplicity == 2) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1007
            /* function being called is overloaded! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1008
            s4o.print("__");
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 405
diff changeset
  1009
            print_function_parameter_data_types_c overloaded_func_suf(&s4o);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1010
            f_decl->accept(overloaded_func_suf);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1011
          }
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1012
    }
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1013
    if (function_type_suffix != NULL)
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1014
      function_type_suffix->accept(*this);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1015
  }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1016
  s4o.print("(");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1017
  s4o.indent_right();
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1018
  
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1019
  int nb_param = 0;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1020
  PARAM_LIST_ITERATOR() {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1021
    symbol_c *param_value = PARAM_VALUE;
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
  1022
    current_param_type = PARAM_TYPE;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1023
    
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1024
    switch (PARAM_DIRECTION) {
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1025
      case function_param_iterator_c::direction_in:
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1026
        if (nb_param > 0)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1027
          s4o.print(",\n"+s4o.indent_spaces);
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1028
        if (param_value == NULL) {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1029
          /* If not, get the default value of this variable's type */
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
  1030
          param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance());
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1031
        }
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1032
        if (param_value == NULL) ERROR;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1033
        s4o.print("(");
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
  1034
        if (search_expression_type->is_literal_integer_type(current_param_type))
220
f332b62cd2c1 Bug with ULINT correction fixed
laurent
parents: 217
diff changeset
  1035
          search_expression_type->lint_type_name.accept(*this);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
  1036
        else if (search_expression_type->is_literal_real_type(current_param_type))
220
f332b62cd2c1 Bug with ULINT correction fixed
laurent
parents: 217
diff changeset
  1037
          search_expression_type->lreal_type_name.accept(*this);
f332b62cd2c1 Bug with ULINT correction fixed
laurent
parents: 217
diff changeset
  1038
        else
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
  1039
          current_param_type->accept(*this);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1040
        s4o.print(")");
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
  1041
        print_check_function(current_param_type, param_value);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1042
        nb_param++;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1043
        break;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1044
      case function_param_iterator_c::direction_out:
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1045
      case function_param_iterator_c::direction_inout:
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1046
        if (!has_output_params) {
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1047
          if (nb_param > 0)
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1048
            s4o.print(",\n"+s4o.indent_spaces);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1049
            if (param_value == NULL) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1050
              s4o.print("NULL");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1051
            } else {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1052
              wanted_variablegeneration = fparam_output_vg;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1053
              param_value->accept(*this);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1054
              wanted_variablegeneration = expression_vg;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1055
            }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1056
          nb_param++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1057
        }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1058
        break;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1059
      case function_param_iterator_c::direction_extref:
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1060
        /* TODO! */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1061
        ERROR;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1062
        break;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1063
    } /* switch */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1064
  }
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1065
  if (has_output_params) {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1066
    if (nb_param > 0)
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1067
      s4o.print(",\n"+s4o.indent_spaces);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1068
    s4o.print(FB_FUNCTION_PARAM);
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1069
  }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1070
  
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1071
  s4o.print(")");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1072
  /* the data type returned by the function, and stored in the il default variable... */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1073
  default_variable_name.current_type = return_data_type;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1074
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1075
  CLEAR_PARAM_LIST()
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1076
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1077
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1078
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1079
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1080
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1081
/* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1082
//SYM_REF4(il_expression_c, il_expr_operator, il_operand, simple_instr_list, unused)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1083
void *visit(il_expression_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1084
  /* We will be recursevely interpreting an instruction list,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1085
   * so we store a backup of the data type of the value currently stored
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1086
   * in the default variable, and set the current data type to NULL
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1087
   */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1088
  symbol_c *old_current_default_variable_data_type = this->default_variable_name.current_type;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1089
  this->default_variable_name.current_type = NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1090
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1091
 /* Pass the symbol->il_operand to the simple_instr_list visitor
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1092
  * using the il_default_variable_init_value parameter...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1093
  * Note that the simple_instr_list_c visitor will set this parameter
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1094
  * to NULL as soon as it does not require it any longer,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1095
  * so we don't do it here again after the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1096
  *   symbol->simple_instr_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1097
  * returns...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1098
  */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1099
  this->il_default_variable_init_value = symbol->il_operand;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1100
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1101
  /* Now do the parenthesised instructions... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1102
  /* NOTE: the following code line will get the variable
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1103
   * this->default_variable_name.current_type updated!
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1104
   */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1105
  symbol->simple_instr_list->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1106
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1107
  /* Now do the operation, using the previous result! */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1108
  /* NOTE: The result of the previous instruction list will be stored
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1109
   * in a variable named IL_DEFVAR_BACK. This is done in the visitor
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1110
   * to instruction_list_c objects...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1111
   */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1112
  this->current_operand = &(this->default_variable_back_name);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1113
  this->current_operand_type = this->default_variable_back_name.current_type;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1114
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1115
  this->default_variable_name.current_type = old_current_default_variable_data_type;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1116
  if (NULL == this->current_operand_type) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1117
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1118
  symbol->il_expr_operator->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1119
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1120
  this->current_operand = NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1121
  this->current_operand_type = NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1122
  this->default_variable_back_name.current_type = NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1123
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1124
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1125
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1126
/*  il_jump_operator label */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1127
// SYM_REF2(il_jump_operation_c, il_jump_operator, label)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1128
void *visit(il_jump_operation_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1129
 /* Pass the symbol->label to the il_jump_operation visitor
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1130
  * using the jump_label parameter...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1131
  */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1132
  this->jump_label = symbol->label;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1133
  symbol->il_jump_operator->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1134
  this->jump_label = NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1135
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1136
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1137
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1138
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1139
/*   il_call_operator prev_declared_fb_name
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1140
 * | il_call_operator prev_declared_fb_name '(' ')'
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1141
 * | il_call_operator prev_declared_fb_name '(' eol_list ')'
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1142
 * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1143
 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1144
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1145
// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1146
void *visit(il_fb_call_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1147
  symbol->il_call_operator->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1148
  s4o.print("{\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1149
  s4o.indent_right();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1150
  s4o.print(s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1151
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1152
  /* 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
  1153
  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
  1154
    /* should never occur. The function block instance MUST have been declared... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1155
  if (function_block_type_name == NULL) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1156
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1157
  /* Now find the declaration of the function block type being called... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1158
  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
  1159
    /* 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
  1160
  if (fb_decl == function_block_type_symtable.end_value()) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1161
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1162
  /* loop through each function block parameter, find the value we should pass
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1163
   * to it, and then output the c equivalent...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1164
   */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1165
  function_param_iterator_c fp_iterator(fb_decl);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1166
  identifier_c *param_name;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1167
  function_call_param_iterator_c function_call_param_iterator(symbol);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1168
  for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1169
    function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1170
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1171
    /* 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: 201
diff changeset
  1172
    symbol_c *param_value = function_call_param_iterator.search_f(param_name);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1173
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1174
    /* Get the value from a foo(<param_value>) style call */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1175
    /* When using the informal invocation style, user can not pass values to EN or ENO parameters if these
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1176
     * were implicitly defined!
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1177
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1178
    if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit())
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
  1179
      param_value = function_call_param_iterator.next_nf();
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1180
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
  1181
    symbol_c *param_type = fp_iterator.param_type();
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
  1182
    if (param_type == NULL) ERROR;
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
  1183
    
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 98
diff changeset
  1184
        /* now output the value assignment */
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1185
    if (param_value != NULL)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1186
      if ((param_direction == function_param_iterator_c::direction_in) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1187
          (param_direction == function_param_iterator_c::direction_inout)) {
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1188
        if (this->is_variable_prefix_null()) {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1189
          symbol->fb_name->accept(*this);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1190
          s4o.print(".");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1191
          param_name->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1192
          s4o.print(" = ");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1193
          print_check_function(param_type, param_value);
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1194
        }
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1195
        else {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1196
          print_setter(param_name, param_type, param_value, symbol->fb_name);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1197
        }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1198
        s4o.print(";\n" + s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1199
      }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1200
  } /* for(...) */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1201
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1202
  /* now call the function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1203
  function_block_type_name->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1204
  s4o.print(FB_FUNCTION_SUFFIX);
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1205
  s4o.print("(");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1206
  if (search_var_instance_decl->get_vartype(symbol->fb_name) != search_var_instance_decl_c::external_vt)
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1207
    s4o.print("&");
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1208
  print_variable_prefix();
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1209
  symbol->fb_name->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1210
  s4o.print(")");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1211
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1212
  /* loop through each function parameter, find the variable to which
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1213
   * we should atribute the value of all output or inoutput parameters.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1214
   */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1215
  fp_iterator.reset();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1216
  function_call_param_iterator.reset();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1217
  for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1218
    function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1219
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1220
    /* 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: 201
diff changeset
  1221
    symbol_c *param_value = function_call_param_iterator.search_f(param_name);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1222
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1223
    /* Get the value from a foo(<param_value>) style call */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1224
    /* When using the informal invocation style, user can not pass values to EN or ENO parameters if these
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1225
     * were implicitly defined!
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1226
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1227
    if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit())
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
  1228
      param_value = function_call_param_iterator.next_nf();
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1229
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1230
    /* now output the value assignment */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1231
    if (param_value != NULL)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1232
      if ((param_direction == function_param_iterator_c::direction_out) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1233
          (param_direction == function_param_iterator_c::direction_inout)) {
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 311
diff changeset
  1234
        symbol_c *param_type = search_varfb_instance_type->get_type_id(param_value);
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1235
        s4o.print(";\n" + s4o.indent_spaces);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1236
        if (this->is_variable_prefix_null()) {
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1237
          param_value->accept(*this);
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1238
          s4o.print(" = ");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1239
          print_check_function(param_type, param_name, symbol->fb_name);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1240
        }
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1241
        else {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1242
          print_setter(param_value, param_type, param_name, NULL, symbol->fb_name);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1243
        }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1244
      }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1245
  } /* for(...) */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1246
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1247
  s4o.print(";\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1248
  s4o.indent_left();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1249
  s4o.print(s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1250
  s4o.print("}");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1251
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1252
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1253
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1254
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1255
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1256
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1257
/* | function_name '(' eol_list [il_param_list] ')' */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1258
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1259
void *visit(il_formal_funct_call_c *symbol) {
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1260
  symbol_c* function_type_prefix = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1261
  symbol_c* function_name = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1262
  symbol_c* function_type_suffix = NULL;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1263
  DECLARE_PARAM_LIST()
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1264
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1265
  symbol_c *return_data_type = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1266
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
  1267
  function_call_param_iterator_c function_call_param_iterator(symbol);
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
  1268
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1269
  function_declaration_c *f_decl = (function_declaration_c *)symbol->called_function_declaration;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1270
  if (f_decl == NULL) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1271
        
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1272
  /* determine the base data type returned by the function being called... */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1273
  search_base_type_c search_base_type;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1274
  return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1275
  if (NULL == return_data_type) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1276
  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1277
  function_name = symbol->function_name;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1278
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1279
  /* loop through each function parameter, find the value we should pass
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1280
   * to it, and then output the c equivalent...
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1281
   */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1282
  function_param_iterator_c fp_iterator(f_decl);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1283
  identifier_c *param_name;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1284
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1285
    /* flag to cirreclty handle calls to extensible standard functions (i.e. functions with variable number of input parameters) */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1286
  bool found_first_extensible_parameter = false;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1287
  for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1288
    if (fp_iterator.is_extensible_param() && (!found_first_extensible_parameter)) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1289
      /* We are calling an extensible function. Before passing the extensible
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1290
       * parameters, we must add a dummy paramater value to tell the called
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1291
       * function how many extensible parameters we will be passing.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1292
       *
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1293
       * Note that stage 3 has already determined the number of extensible
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1294
       * paramters, and stored that info in the abstract syntax tree. We simply
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1295
       * re-use that value.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1296
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1297
      /* NOTE: we are not freeing the malloc'd memory. This is not really a bug.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1298
       *       Since we are writing a compiler, which runs to termination quickly,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1299
       *       we can consider this as just memory required for the compilation process
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1300
       *       that will be free'd when the program terminates.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1301
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1302
      char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1303
      if (tmp == NULL) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1304
      int res = snprintf(tmp, 32, "%d", symbol->extensible_param_count);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1305
      if ((res >= 32) || (res < 0)) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1306
      identifier_c *param_value = new identifier_c(tmp);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1307
      uint_type_name_c *param_type  = new uint_type_name_c();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1308
      identifier_c *param_name = new identifier_c("");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1309
      ADD_PARAM_LIST(param_name, param_value, param_type, function_param_iterator_c::direction_in)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1310
      found_first_extensible_parameter = true;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1311
    }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1312
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1313
    if (fp_iterator.is_extensible_param()) {      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1314
      /* since we are handling an extensible parameter, we must add the index to the
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1315
       * parameter name so we can go looking for the value passed to the correct
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1316
       * extended parameter (e.g. IN1, IN2, IN3, IN4, ...)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1317
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1318
      char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1319
      int res = snprintf(tmp, 32, "%d", fp_iterator.extensible_param_index());
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1320
      if ((res >= 32) || (res < 0)) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1321
      param_name = new identifier_c(strdup2(param_name->value, tmp));
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1322
      if (param_name->value == NULL) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1323
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1324
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1325
    symbol_c *param_type = fp_iterator.param_type();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1326
    if (param_type == NULL) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1327
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1328
    function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1329
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1330
    symbol_c *param_value = NULL;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1331
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1332
    /* Get the value from a foo(<param_name> = <param_value>) style call */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1333
    if (param_value == NULL)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1334
      param_value = function_call_param_iterator.search_f(param_name);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1335
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1336
    /* Get the value from a foo(<param_value>) style call */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1337
    /* NOTE: the following line of code is not required in this case, but it doesn't
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1338
     * harm to leave it in, as in the case of a formal syntax function call,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1339
     * it will always return NULL.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1340
     * We leave it in in case we later decide to merge this part of the code together
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1341
     * with the function calling code in generate_c_st_c, which does require
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1342
     * the following line...
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1343
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1344
    if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1345
      param_value = function_call_param_iterator.next_nf();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1346
    }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1347
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1348
    /* if no more parameter values in function call, and the current parameter
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1349
     * of the function declaration is an extensible parameter, we
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sous&#