stage4/generate_c/generate_c_inlinefcall.cc
author laurent
Wed, 12 Oct 2011 16:09:29 +0200
changeset 383 0b81b59f333b
parent 380 b78e59ed4269
child 388 17eaad42ba88
permissions -rwxr-xr-x
Fix bug generate_c_inlinefcall in inline function name generated
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     1
/*
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 238
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     3
 *
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 238
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: 238
diff changeset
     5
 *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     6
 *
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 238
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: 238
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: 238
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: 238
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: 238
diff changeset
    11
 *
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 238
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: 238
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: 238
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: 238
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: 238
diff changeset
    16
 *
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 238
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: 238
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: 238
diff changeset
    19
 *
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    20
 *
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    21
 * This code is made available on the understanding that it will not be
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    22
 * used in safety-critical situations without a full and competent review.
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    23
 */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    24
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    25
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    26
#define INLINE_RESULT_TEMP_VAR "__res"
380
b78e59ed4269 Fix bug in generate_c_inlinefcall.cc that prevent to use extendible standard functions
laurent
parents: 355
diff changeset
    27
#define INLINE_PARAM_COUNT "__PARAM_COUNT"
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    28
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
    29
class generate_c_inlinefcall_c: public generate_c_typedecl_c {
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    30
221
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 219
diff changeset
    31
  public:
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 219
diff changeset
    32
    typedef enum {
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 219
diff changeset
    33
      expression_vg,
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
    34
      assignment_vg,
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
    35
      complextype_base_vg,
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
    36
      complextype_suffix_vg
221
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 219
diff changeset
    37
    } variablegeneration_t;
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 219
diff changeset
    38
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    39
  private:
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    40
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    41
    /* The initial value that should be given to the IL default variable
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    42
	 * imediately after a parenthesis is opened.
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    43
	 * This variable is only used to pass data from the
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    44
	 * il_expression_c visitor to the simple_instr_list_c visitor.
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    45
	 *
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    46
	 * e.g.:
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    47
	 *         LD var1
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    48
	 *         AND ( var2
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    49
	 *         OR var3
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    50
	 *         )
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    51
	 *
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    52
	 * In the above code sample, the line 'AND ( var2' constitutes
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    53
	 * an il_expression_c, where var2 should be loaded into the
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    54
	 * il default variable before continuing with the expression
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    55
	 * inside the parenthesis.
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    56
	 * Unfortunately, only the simple_instr_list_c may do the
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    57
	 * initial laoding of the var2 bariable following the parenthesis,
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    58
	 * so the il_expression_c visitor will have to pass 'var2' as a
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    59
	 * parameter to the simple_instr_list_c visitor.
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    60
	 * Ergo, the existance of the following parameter...!
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    61
	 */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    62
	symbol_c *il_default_variable_init_value;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    63
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    64
    /* Operand to the IL operation currently being processed... */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    65
	/* These variables are used to pass data from the
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    66
	 * il_simple_operation_c and il_expression_c visitors
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    67
	 * to the il operator visitors (i.e. LD_operator_c,
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    68
	 * LDN_operator_c, ST_operator_c, STN_operator_c, ...)
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    69
	 */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    70
	symbol_c *current_operand;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    71
	symbol_c *current_operand_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    72
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    73
	 /* The result of the comparison IL operations (GT, EQ, LT, ...)
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    74
	 * is a boolean variable.
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    75
	 * This class keeps track of the current data type stored in the
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    76
	 * il default variable. This is usually done by keeping a reference
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    77
	 * to the data type of the last operand. Nevertheless, in the case of
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    78
	 * the comparison IL operators, the data type of the result (a boolean)
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    79
	 * is not the data type of the operand. We therefore need an object
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    80
	 * of the boolean data type to keep as a reference of the current
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    81
	 * data type.
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    82
	 * The following object is it...
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    83
	 */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    84
	bool_type_name_c bool_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    85
	lint_type_name_c lint_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    86
	lword_type_name_c lword_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    87
	lreal_type_name_c lreal_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    88
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    89
    /* The name of the IL default variable... */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    90
	#define IL_DEFVAR   VAR_LEADER "IL_DEFVAR"
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    91
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    92
	/* The name of the variable used to pass the result of a
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    93
	 * parenthesised instruction list to the immediately preceding
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    94
	 * scope ...
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    95
	 */
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    96
    #define IL_DEFVAR_BACK   VAR_LEADER "IL_DEFVAR_BACK"
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    97
    il_default_variable_c default_variable_name;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
    98
	il_default_variable_c default_variable_back_name;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    99
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   100
	symbol_c* current_array_type;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   101
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   102
	int fcall_number;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   103
	symbol_c *fbname;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   104
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   105
    search_expression_type_c *search_expression_type;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   106
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   107
    search_varfb_instance_type_c *search_varfb_instance_type;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   108
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   109
    search_base_type_c search_base_type;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   110
221
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 219
diff changeset
   111
    variablegeneration_t wanted_variablegeneration;
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 219
diff changeset
   112
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   113
  public:
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   114
    generate_c_inlinefcall_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL)
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   115
    : generate_c_typedecl_c(s4o_ptr),
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   116
      default_variable_name(IL_DEFVAR, NULL),
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   117
      default_variable_back_name(IL_DEFVAR_BACK, NULL)
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   118
    {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   119
      search_expression_type = new search_expression_type_c(scope);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   120
      search_varfb_instance_type = new search_varfb_instance_type_c(scope);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   121
      this->set_variable_prefix(variable_prefix);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   122
      fcall_number = 0;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   123
      fbname = name;
221
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 219
diff changeset
   124
      wanted_variablegeneration = expression_vg;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   125
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   126
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   127
    virtual ~generate_c_inlinefcall_c(void) {
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   128
      delete search_expression_type;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   129
      delete search_varfb_instance_type;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   130
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   131
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   132
    void print(symbol_c* symbol) {
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   133
      function_call_iterator_c fc_iterator(symbol);
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   134
      symbol_c* function_call;
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   135
      while ((function_call = fc_iterator.next()) != NULL) {
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   136
    	function_call->accept(*this);
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   137
      }
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   138
    }
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   139
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   140
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   141
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   142
    void generate_inline(symbol_c *function_name,
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   143
            symbol_c *function_type_prefix,
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   144
            symbol_c *function_type_suffix,
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   145
            std::list<FUNCTION_PARAM*> param_list,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   146
            function_declaration_c *f_decl = NULL) {
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   147
            std::list<FUNCTION_PARAM*>::iterator pt;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   148
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   149
      fcall_number++;
336
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 332
diff changeset
   150
      function_type_prefix = search_expression_type->default_literal_type(function_type_prefix);
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 332
diff changeset
   151
      if (function_type_suffix) {
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 332
diff changeset
   152
        function_type_suffix = search_expression_type->default_literal_type(function_type_suffix);
332
0f1d91a37506 Fix bug in inline function calls when using function with undetermined type interface with literals as input
laurent
parents: 321
diff changeset
   153
      }
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   154
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   155
      s4o.print(s4o.indent_spaces);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   156
      s4o.print("inline ");
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   157
      function_type_prefix->accept(*this);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   158
      s4o.print(" __");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   159
      fbname->accept(*this);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   160
      s4o.print("_");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   161
      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
   162
      if (f_decl != NULL) {
383
0b81b59f333b Fix bug generate_c_inlinefcall in inline function name generated
laurent
parents: 380
diff changeset
   163
        /* function being called is overloaded! */
0b81b59f333b Fix bug generate_c_inlinefcall in inline function name generated
laurent
parents: 380
diff changeset
   164
        s4o.print("__");
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   165
        print_function_parameter_data_types_c overloaded_func_suf(&s4o);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   166
        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
   167
      }	
336
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 332
diff changeset
   168
      if (function_type_suffix) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   169
        function_type_suffix->accept(*this);
336
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 332
diff changeset
   170
      }
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   171
      s4o.print_integer(fcall_number);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   172
      s4o.print("(");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   173
      s4o.indent_right();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   174
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   175
      PARAM_LIST_ITERATOR() {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   176
        if (PARAM_DIRECTION == function_param_iterator_c::direction_in) {
336
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 332
diff changeset
   177
          search_expression_type->default_literal_type(PARAM_TYPE)->accept(*this);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   178
          s4o.print(" ");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   179
          PARAM_NAME->accept(*this);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   180
          s4o.print(",\n" + s4o.indent_spaces);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   181
        }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   182
      }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   183
      fbname->accept(*this);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   184
      s4o.print(" *");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   185
      s4o.print(FB_FUNCTION_PARAM);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   186
      s4o.indent_left();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   187
      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
   188
      s4o.print("{\n");
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   189
      s4o.indent_right();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   190
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   191
      s4o.print(s4o.indent_spaces);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   192
      function_type_prefix->accept(*this);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   193
      s4o.print(" "),
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   194
      s4o.print(INLINE_RESULT_TEMP_VAR);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   195
      s4o.print(";\n");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   196
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   197
      PARAM_LIST_ITERATOR() {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   198
        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
   199
             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
   200
             PARAM_VALUE != NULL) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   201
          s4o.print(s4o.indent_spaces);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   202
          PARAM_TYPE->accept(*this);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   203
          s4o.print(" ");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   204
          s4o.print(TEMP_VAR);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   205
          PARAM_NAME->accept(*this);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   206
          s4o.print(" = ");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   207
          print_check_function(PARAM_TYPE, PARAM_VALUE);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   208
          s4o.print(";\n");
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   209
          }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   210
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   211
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   212
      s4o.print(s4o.indent_spaces + INLINE_RESULT_TEMP_VAR),
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   213
      s4o.print(" = ");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   214
      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
   215
      if (f_decl != NULL) {
383
0b81b59f333b Fix bug generate_c_inlinefcall in inline function name generated
laurent
parents: 380
diff changeset
   216
    	/* function being called is overloaded! */
0b81b59f333b Fix bug generate_c_inlinefcall in inline function name generated
laurent
parents: 380
diff changeset
   217
    	s4o.print("__");
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   218
        print_function_parameter_data_types_c overloaded_func_suf(&s4o);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   219
        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
   220
      }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   221
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   222
      if (function_type_suffix)
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   223
        function_type_suffix->accept(*this);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   224
      s4o.print("(");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   225
      s4o.indent_right();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   226
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   227
      PARAM_LIST_ITERATOR() {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   228
        if (pt != param_list.begin())
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   229
        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
   230
        if (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
   231
          PARAM_NAME->accept(*this);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   232
        else if (PARAM_VALUE != NULL){
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   233
          s4o.print("&");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   234
          s4o.print(TEMP_VAR);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   235
          PARAM_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
   236
        } else {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   237
          s4o.print("NULL");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   238
         }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   239
      }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   240
      s4o.print(");\n");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   241
      s4o.indent_left();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   242
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   243
      PARAM_LIST_ITERATOR() {
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   244
        if ((PARAM_DIRECTION == function_param_iterator_c::direction_out ||
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   245
             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
   246
             PARAM_VALUE != NULL) {
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   247
          s4o.print(s4o.indent_spaces);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   248
          print_setter(PARAM_VALUE, PARAM_TYPE, PARAM_NAME);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   249
          s4o.print(";\n");
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   250
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   251
      }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   252
      s4o.print(s4o.indent_spaces + "return ");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   253
      s4o.print(INLINE_RESULT_TEMP_VAR);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   254
      s4o.print(";\n");
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   255
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   256
      s4o.indent_left();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   257
      s4o.print(s4o.indent_spaces + "}\n\n");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   258
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   259
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   260
  private:
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   261
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   262
    /* A helper function... */
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   263
	void CMP_operator_result_type() {
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   264
	  /* the data type resulting from this operation... */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   265
	  this->default_variable_name.current_type = &(this->bool_type);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   266
	}
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   267
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   268
	/* A helper function... */
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   269
    void BYTE_operator_result_type(void) {
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   270
	  if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   271
		if (search_expression_type->is_literal_integer_type(this->current_operand_type))
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   272
		  this->default_variable_name.current_type = &(this->lword_type);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   273
		else
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   274
		  this->default_variable_name.current_type = this->current_operand_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   275
	  }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   276
	  else if (search_expression_type->is_literal_integer_type(this->current_operand_type))
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   277
		  this->current_operand_type = this->default_variable_name.current_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   278
	}
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   279
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   280
    /* A helper function... */
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   281
    void NUM_operator_result_type(void) {
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   282
	  if (search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   283
		if (search_expression_type->is_literal_integer_type(this->current_operand_type) ||
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   284
			search_expression_type->is_literal_real_type(this->current_operand_type))
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   285
		  this->default_variable_name.current_type = &(this->lreal_type);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   286
		else
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   287
		  this->default_variable_name.current_type = this->current_operand_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   288
	  }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   289
	  else if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   290
		if (search_expression_type->is_literal_integer_type(this->current_operand_type))
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   291
		  this->default_variable_name.current_type = &(this->lint_type);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   292
		else if (search_expression_type->is_literal_real_type(this->current_operand_type))
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   293
		  this->default_variable_name.current_type = &(this->lreal_type);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   294
		else
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   295
		  this->default_variable_name.current_type = this->current_operand_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   296
	  }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   297
	  else if (search_expression_type->is_literal_integer_type(this->current_operand_type) ||
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   298
			   search_expression_type->is_literal_real_type(this->current_operand_type))
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   299
		this->current_operand_type = this->default_variable_name.current_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   300
	}
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   301
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   302
    void *print_getter(symbol_c *symbol) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   303
      unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   304
      if (vartype == search_var_instance_decl_c::external_vt)
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   305
    	s4o.print(GET_EXTERNAL);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   306
      else if (vartype == search_var_instance_decl_c::located_vt)
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   307
    	s4o.print(GET_LOCATED);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   308
      else
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   309
    	s4o.print(GET_VAR);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   310
      s4o.print("(");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   311
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   312
      wanted_variablegeneration = complextype_base_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   313
      symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   314
      if (search_varfb_instance_type->type_is_complex())
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   315
    	s4o.print(",");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   316
      wanted_variablegeneration = complextype_suffix_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   317
      symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   318
      s4o.print(")");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   319
      wanted_variablegeneration = expression_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   320
      return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   321
    }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   322
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   323
    void *print_setter(symbol_c* symbol,
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   324
    		symbol_c* type,
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   325
    		symbol_c* value) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   326
      unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
231
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   327
      if (vartype == search_var_instance_decl_c::external_vt) {
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   328
        symbolic_variable_c *variable = dynamic_cast<symbolic_variable_c *>(symbol);
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   329
        /* TODO Find a solution for forcing global complex variables */
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   330
        if (variable != NULL) {
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   331
          s4o.print(SET_EXTERNAL);
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   332
          s4o.print("(");
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   333
          variable->var_name->accept(*this);
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   334
          s4o.print(",");
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   335
        }
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   336
        else {
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   337
          s4o.print(SET_COMPLEX_EXTERNAL);
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   338
          s4o.print("(");
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   339
        }
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   340
      }
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   341
      else {
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   342
        if (vartype == search_var_instance_decl_c::located_vt)
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   343
          s4o.print(SET_LOCATED);
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   344
        else
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   345
          s4o.print(SET_VAR);
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   346
        s4o.print("(");
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   347
      }
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   348
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   349
      wanted_variablegeneration = complextype_base_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   350
      symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   351
      s4o.print(",");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   352
      wanted_variablegeneration = expression_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   353
      print_check_function(type, value, NULL, true);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   354
      if (search_varfb_instance_type->type_is_complex()) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   355
        s4o.print(",");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   356
        wanted_variablegeneration = complextype_suffix_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   357
        symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   358
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   359
      s4o.print(")");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   360
      wanted_variablegeneration = expression_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   361
      return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   362
    }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   363
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   364
    /*********************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   365
    /* B 1.4 - Variables */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   366
    /*********************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   367
    void *visit(symbolic_variable_c *symbol) {
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   368
      unsigned int vartype;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   369
      if (wanted_variablegeneration == complextype_base_vg)
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   370
        generate_c_base_c::visit(symbol);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   371
      else if (wanted_variablegeneration == complextype_suffix_vg)
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   372
        return NULL;
221
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 219
diff changeset
   373
      else
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   374
        print_getter(symbol);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   375
      return NULL;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   376
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   377
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   378
    /********************************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   379
    /* B.1.4.1   Directly Represented Variables */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   380
    /********************************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   381
    // direct_variable: direct_variable_token   {$$ = new direct_variable_c($1);};
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   382
    void *visit(direct_variable_c *symbol) {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   383
      TRACE("direct_variable_c");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   384
      /* Do not use print_token() as it will change everything into uppercase */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   385
      if (strlen(symbol->value) == 0) ERROR;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   386
      s4o.print(GET_LOCATED);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   387
      s4o.print("(");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   388
      this->print_variable_prefix();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   389
      s4o.printlocation(symbol->value + 1);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   390
      s4o.print(")");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   391
      return NULL;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   392
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   393
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   394
    /*************************************/
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   395
    /* B.1.4.2   Multi-element Variables */
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   396
    /*************************************/
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   397
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   398
    // SYM_REF2(structured_variable_c, record_variable, field_selector)
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   399
    void *visit(structured_variable_c *symbol) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   400
      TRACE("structured_variable_c");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   401
      switch (wanted_variablegeneration) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   402
        case complextype_base_vg:
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   403
          symbol->record_variable->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   404
          break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   405
        case complextype_suffix_vg:
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   406
          symbol->record_variable->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   407
          s4o.print(".");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   408
          symbol->field_selector->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   409
          break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   410
        default:
237
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 235
diff changeset
   411
          print_getter(symbol);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   412
          break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   413
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   414
      return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   415
    }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   416
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   417
    /*  subscripted_variable '[' subscript_list ']' */
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   418
    //SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   419
    void *visit(array_variable_c *symbol) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   420
      switch (wanted_variablegeneration) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   421
        case complextype_base_vg:
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   422
          symbol->subscripted_variable->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   423
          break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   424
        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
   425
          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
   426
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   427
          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
   428
          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
   429
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   430
          s4o.print(".table");
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   431
          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
   432
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   433
          current_array_type = NULL;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   434
          break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   435
        default:
237
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 235
diff changeset
   436
          print_getter(symbol);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   437
          break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   438
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   439
      return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   440
    }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   441
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   442
    /****************************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   443
    /* B.2 - Language IL (Instruction List) */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   444
    /****************************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   445
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   446
    /***********************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   447
    /* B 2.1 Instructions and Operands */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   448
    /***********************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   449
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   450
    /* | label ':' [il_incomplete_instruction] eol_list */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   451
    // SYM_REF2(il_instruction_c, label, il_instruction)
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   452
    void *visit(il_instruction_c *symbol) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   453
      if (NULL != symbol->il_instruction) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   454
        symbol->il_instruction->accept(*this);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   455
      }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   456
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   457
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   458
    /* | il_simple_operator [il_operand] */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   459
    //SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand)
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   460
    void *visit(il_simple_operation_c *symbol) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   461
      this->current_operand = symbol->il_operand;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   462
      if (NULL == this->current_operand) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   463
        this->current_operand_type = NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   464
      } else {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   465
        this->current_operand_type = search_expression_type->get_type(this->current_operand);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   466
        if (NULL == this->current_operand_type) ERROR;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   467
      }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   468
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   469
      symbol->il_simple_operator->accept(*this);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   470
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   471
      this->current_operand = NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   472
      this->current_operand_type = NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   473
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   474
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   475
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   476
    void *visit(il_function_call_c *symbol) {
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   477
      symbol_c* function_type_prefix = NULL;
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   478
      symbol_c* function_name = NULL;     
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   479
      symbol_c* function_type_suffix = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   480
      DECLARE_PARAM_LIST()
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   481
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   482
      symbol_c *param_data_type = default_variable_name.current_type;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   483
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   484
      function_call_param_iterator_c function_call_param_iterator(symbol);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   485
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   486
      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
   487
      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
   488
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   489
      /* 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
   490
      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
   491
      function_type_prefix = (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
   492
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   493
      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
   494
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   495
      /* 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
   496
       * 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
   497
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   498
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   499
      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
   500
      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
   501
        /* 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
   502
      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
   503
        /* 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
   504
      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
   505
      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
   506
        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
   507
          /* 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
   508
           * 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
   509
           * 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
   510
           *
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   511
           * 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
   512
           * 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
   513
           * 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
   514
           */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   515
          /* 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
   516
           *       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
   517
           *       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
   518
           *       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
   519
           */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   520
          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
   521
          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
   522
          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
   523
          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
   524
          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
   525
          uint_type_name_c *param_type  = new uint_type_name_c();
380
b78e59ed4269 Fix bug in generate_c_inlinefcall.cc that prevent to use extendible standard functions
laurent
parents: 355
diff changeset
   526
          identifier_c *param_name = new identifier_c(INLINE_PARAM_COUNT);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   527
          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
   528
          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
   529
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   530
    
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   531
        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
   532
        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
   533
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   534
        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
   535
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   536
        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
   537
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   538
        /* 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
   539
        /* 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
   540
         * 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
   541
         * 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
   542
         * 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
   543
         * 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
   544
         * the following line...
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   545
         */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   546
        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
   547
          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
   548
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   549
        /* 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
   550
         * 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
   551
         * 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
   552
         *
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   553
         * 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
   554
         * 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
   555
         */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   556
        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
   557
          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
   558
          used_defvar = true;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   559
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   560
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   561
        /* 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
   562
        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
   563
          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
   564
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   565
        
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   566
        /* 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
   567
         * 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
   568
         * 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
   569
         */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   570
        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
   571
          break;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   572
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   573
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   574
        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
   575
          /* 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
   576
          /* 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
   577
          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
   578
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   579
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   580
        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
   581
      } /* for(...) */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   582
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   583
      if (function_call_param_iterator.next_nf() != NULL) ERROR;
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   584
      if (NULL == function_type_prefix) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   585
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   586
      bool has_output_params = false;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   587
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   588
      PARAM_LIST_ITERATOR() {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   589
        if ((PARAM_DIRECTION == function_param_iterator_c::direction_out ||
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   590
             PARAM_DIRECTION == function_param_iterator_c::direction_inout) &&
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   591
             PARAM_VALUE != NULL) {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   592
          has_output_params = true;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   593
        }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   594
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   595
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   596
      /* 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
   597
      /* (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
   598
      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
   599
      if (fdecl_mutiplicity == 0) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   600
      if (fdecl_mutiplicity == 1) 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   601
        /* function being called is NOT overloaded! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   602
        f_decl = NULL; 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   603
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   604
      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
   605
        generate_inline(function_name, function_type_prefix, function_type_suffix, param_list, f_decl);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   606
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   607
      CLEAR_PARAM_LIST()
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   608
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   609
      /* the data type resulting from this operation... */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   610
      default_variable_name.current_type = function_type_prefix;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   611
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   612
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   613
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   614
    /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   615
    //SYM_REF4(il_expression_c, il_expr_operator, il_operand, simple_instr_list, unused)
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   616
    void *visit(il_expression_c *symbol) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   617
      /* We will be recursevely interpreting an instruction list,
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   618
       * so we store a backup of the data type of the value currently stored
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   619
       * in the default variable, and set the current data type to NULL
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   620
       */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   621
      symbol_c *old_current_default_variable_data_type = this->default_variable_name.current_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   622
      this->default_variable_name.current_type = NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   623
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   624
     /* Pass the symbol->il_operand to the simple_instr_list visitor
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   625
      * using the il_default_variable_init_value parameter...
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   626
      * Note that the simple_instr_list_c visitor will set this parameter
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   627
      * to NULL as soon as it does not require it any longer,
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   628
      * so we don't do it here again after the
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   629
      *   symbol->simple_instr_list->accept(*this);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   630
      * returns...
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   631
      */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   632
      this->il_default_variable_init_value = symbol->il_operand;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   633
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   634
      /* Now do the parenthesised instructions... */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   635
      /* NOTE: the following code line will get the variable
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   636
       * this->default_variable_name.current_type updated!
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   637
       */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   638
      symbol->simple_instr_list->accept(*this);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   639
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   640
      /* Now do the operation, using the previous result! */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   641
      /* NOTE: The result of the previous instruction list will be stored
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   642
       * in a variable named IL_DEFVAR_BACK. This is done in the visitor
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   643
       * to instruction_list_c objects...
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   644
       */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   645
      this->current_operand = &(this->default_variable_back_name);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   646
      this->current_operand_type = this->default_variable_back_name.current_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   647
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   648
      this->default_variable_name.current_type = old_current_default_variable_data_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   649
      if (NULL == this->current_operand_type) ERROR;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   650
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   651
      symbol->il_expr_operator->accept(*this);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   652
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   653
      this->current_operand = NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   654
      this->current_operand_type = NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   655
      this->default_variable_back_name.current_type = NULL;
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   656
      return NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   657
    }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   658
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   659
    /* | function_name '(' eol_list [il_param_list] ')' */
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   660
    // SYM_REF2(il_formal_funct_call_c, function_name, il_param_list)
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   661
    void *visit(il_formal_funct_call_c *symbol) {
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   662
      symbol_c* function_type_prefix = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   663
      symbol_c* function_name = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   664
      symbol_c* function_type_suffix = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   665
      DECLARE_PARAM_LIST()
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   666
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   667
      function_call_param_iterator_c function_call_param_iterator(symbol);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   668
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   669
      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
   670
      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
   671
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   672
      /* 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
   673
      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
   674
      function_type_prefix = (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
   675
      if (NULL == function_type_prefix) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   676
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   677
      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
   678
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   679
      /* 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
   680
       * 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
   681
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   682
      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
   683
      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
   684
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   685
        /* 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
   686
      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
   687
      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
   688
        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
   689
          /* 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
   690
           * 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
   691
           * 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
   692
           *
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   693
           * 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
   694
           * 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
   695
           * 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
   696
           */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   697
          /* 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
   698
           *       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
   699
           *       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
   700
           *       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
   701
           */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   702
          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
   703
          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
   704
          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
   705
          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
   706
          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
   707
          uint_type_name_c *param_type  = new uint_type_name_c();
380
b78e59ed4269 Fix bug in generate_c_inlinefcall.cc that prevent to use extendible standard functions
laurent
parents: 355
diff changeset
   708
          identifier_c *param_name = new identifier_c(INLINE_PARAM_COUNT);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   709
          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
   710
          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
   711
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   712
        
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   713
        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
   714
          /* 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
   715
           * 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
   716
           * 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
   717
           */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   718
          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
   719
          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
   720
          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
   721
          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
   722
          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
   723
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   724
    
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   725
        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
   726
        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
   727
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   728
        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
   729
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   730
        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
   731
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   732
        /* 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
   733
        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
   734
          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
   735
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   736
        /* 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
   737
        /* 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
   738
         * 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
   739
         * 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
   740
         * 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
   741
         * 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
   742
         * the following line...
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   743
         */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   744
        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
   745
          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
   746
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   747
        
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   748
        /* 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
   749
         * 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
   750
         * 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
   751
         */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   752
        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
   753
          break;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   754
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   755
    
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   756
        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
   757
          /* 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
   758
          /* 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
   759
          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
   760
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   761
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   762
        ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction())
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   763
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   764
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   765
      if (function_call_param_iterator.next_nf() != NULL) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   766
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   767
      bool has_output_params = false;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   768
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   769
      PARAM_LIST_ITERATOR() {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   770
        if ((PARAM_DIRECTION == function_param_iterator_c::direction_out ||
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   771
             PARAM_DIRECTION == function_param_iterator_c::direction_inout) &&
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   772
             PARAM_VALUE != NULL) {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   773
          has_output_params = true;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   774
        }
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   775
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   776
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   777
      /* 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
   778
      /* (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
   779
      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
   780
      if (fdecl_mutiplicity == 0) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   781
      if (fdecl_mutiplicity == 1) 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   782
        /* function being called is NOT overloaded! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   783
        f_decl = NULL; 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   784
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   785
      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
   786
        generate_inline(function_name, function_type_prefix, function_type_suffix, param_list, f_decl);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   787
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   788
      CLEAR_PARAM_LIST()
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   789
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   790
      /* the data type resulting from this operation... */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   791
      default_variable_name.current_type = function_type_prefix;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   792
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   793
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   794
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   795
    /* | simple_instr_list il_simple_instruction */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   796
    // SYM_LIST(simple_instr_list_c)
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   797
    void *visit(simple_instr_list_c *symbol) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   798
      /* Check whether we should initiliase the il default variable... */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   799
      if (NULL != this->il_default_variable_init_value) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   800
        /* Yes, we must... */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   801
        /* We will do it by instatiating a LD operator, and having this
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   802
         * same generate_c_il_c class visiting it!
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   803
         */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   804
        LD_operator_c ld_oper;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   805
        il_simple_operation_c il_simple_oper(&ld_oper, this->il_default_variable_init_value);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   806
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   807
        il_simple_oper.accept(*this);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   808
      }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   809
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   810
      /* this parameter no longer required... */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   811
      this->il_default_variable_init_value = NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   812
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   813
      iterator_visitor_c::visit(symbol);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   814
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   815
      /* copy the result in the default variable to the variable
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   816
	   * used to pass the data out to the scope enclosing
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   817
	   * the current scope!
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   818
	   *
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   819
	   * We also need to update the data type currently stored within
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   820
	   * the variable used to pass the data to the outside scope...
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   821
	   */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   822
	  this->default_variable_back_name.current_type = this->default_variable_name.current_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   823
	  return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   824
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   825
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   826
    void *visit(LD_operator_c *symbol)	{
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   827
      /* the data type resulting from this operation... */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   828
      this->default_variable_name.current_type = this->current_operand_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   829
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   830
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   831
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   832
    void *visit(LDN_operator_c *symbol)	{
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   833
      /* the data type resulting from this operation... */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   834
      this->default_variable_name.current_type = this->current_operand_type;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   835
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   836
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   837
346
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   838
    void *visit(AND_operator_c *symbol)	{
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   839
      if (search_expression_type->is_binary_type(this->default_variable_name.current_type) &&
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   840
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   841
    	BYTE_operator_result_type();
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   842
      }
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   843
      else {ERROR;}
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   844
      return NULL;
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   845
    }
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   846
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   847
    void *visit(OR_operator_c *symbol)	{
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   848
      if (search_expression_type->is_binary_type(this->default_variable_name.current_type) &&
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   849
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   850
    	BYTE_operator_result_type();
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   851
      }
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   852
      else {ERROR;}
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   853
      return NULL;
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   854
    }
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   855
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   856
    void *visit(XOR_operator_c *symbol)	{
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   857
      if (search_expression_type->is_binary_type(this->default_variable_name.current_type) &&
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   858
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   859
    	BYTE_operator_result_type();
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   860
      }
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   861
      else {ERROR;}
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   862
      return NULL;
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   863
    }
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   864
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   865
    void *visit(ANDN_operator_c *symbol)	{
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   866
      if (search_expression_type->is_binary_type(this->default_variable_name.current_type) &&
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   867
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   868
    	BYTE_operator_result_type();
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   869
      }
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   870
      else {ERROR;}
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   871
      return NULL;
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   872
    }
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   873
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   874
    void *visit(ORN_operator_c *symbol)	{
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   875
      if (search_expression_type->is_binary_type(this->default_variable_name.current_type) &&
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   876
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   877
    	BYTE_operator_result_type();
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   878
      }
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   879
      else {ERROR;}
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   880
      return NULL;
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   881
    }
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   882
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   883
    void *visit(XORN_operator_c *symbol)	{
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   884
      if (search_expression_type->is_binary_type(this->default_variable_name.current_type) &&
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   885
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   886
    	BYTE_operator_result_type();
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   887
      }
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   888
      else {ERROR;}
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   889
      return NULL;
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   890
    }
620fd98a021d Adding BYTE operators visit functions in inlinefcall
laurent
parents: 345
diff changeset
   891
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   892
    void *visit(ADD_operator_c *symbol)	{
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   893
      if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   894
          search_expression_type->is_time_type(this->current_operand_type)) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   895
        /* the data type resulting from this operation... */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   896
        this->default_variable_name.current_type = this->current_operand_type;
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   897
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   898
      else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   899
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   900
        NUM_operator_result_type();
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   901
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   902
      else {ERROR;}
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   903
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   904
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   905
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   906
    void *visit(SUB_operator_c *symbol)	{
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   907
      if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   908
          search_expression_type->is_time_type(this->current_operand_type)) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   909
        /* the data type resulting from this operation... */
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   910
        this->default_variable_name.current_type = this->current_operand_type;
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   911
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   912
      else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   913
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   914
    	NUM_operator_result_type();
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   915
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   916
      else {ERROR;}
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   917
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   918
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   919
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   920
    void *visit(MUL_operator_c *symbol)	{
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   921
      if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   922
          search_expression_type->is_integer_type(this->current_operand_type)) {
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   923
        /* the data type resulting from this operation is unchanged! */
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   924
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   925
      else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   926
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   927
    	NUM_operator_result_type();
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   928
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   929
      else {ERROR;}
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   930
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   931
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   932
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   933
    void *visit(DIV_operator_c *symbol)	{
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   934
      if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   935
          search_expression_type->is_integer_type(this->current_operand_type)) {
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   936
        /* the data type resulting from this operation is unchanged! */
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   937
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   938
      else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   939
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   940
        NUM_operator_result_type();
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   941
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   942
      else {ERROR;}
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   943
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   944
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   945
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   946
    void *visit(MOD_operator_c *symbol)	{
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   947
      if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   948
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   949
        NUM_operator_result_type();
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   950
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   951
      else {ERROR;}
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   952
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   953
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   954
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   955
    void *visit(GT_operator_c *symbol)	{
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   956
      if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   957
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   958
        CMP_operator_result_type();
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   959
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   960
      else {ERROR;}
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   961
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   962
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   963
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   964
    void *visit(GE_operator_c *symbol)	{
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   965
      if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   966
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   967
        CMP_operator_result_type();
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   968
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   969
      else {ERROR;}
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   970
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   971
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   972
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   973
    void *visit(EQ_operator_c *symbol)	{
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   974
      if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   975
        CMP_operator_result_type();
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   976
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   977
      else {ERROR;}
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   978
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   979
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   980
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   981
    void *visit(LT_operator_c *symbol)	{
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   982
      if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   983
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   984
        CMP_operator_result_type();
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   985
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   986
      else {ERROR;}
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   987
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   988
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   989
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   990
    void *visit(LE_operator_c *symbol)	{
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   991
      if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   992
          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   993
        CMP_operator_result_type();
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   994
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
   995
      else {ERROR;}
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   996
      return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   997
    }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   998
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
   999
    void *visit(NE_operator_c *symbol)	{
345
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
  1000
      if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
  1001
        CMP_operator_result_type();
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
  1002
      }
894c0e6d951c Fix bug with DIV and MOD operator in IL code generator
laurent
parents: 337
diff changeset
  1003
      else {ERROR;}
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1004
      return NULL;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1005
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1006
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1007
    /***************************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1008
    /* B.3 - Language ST (Structured Text) */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1009
    /***************************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1010
    /***********************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1011
    /* B 3.1 - Expressions */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1012
    /***********************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1013
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
  1014
    void *visit(statement_list_c *symbol) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
  1015
	  function_call_iterator_c fc_iterator(symbol);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
  1016
	  symbol_c* function_call;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
  1017
	  while ((function_call = fc_iterator.next()) != NULL) {
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
  1018
		function_call->accept(*this);
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
  1019
	  }
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
  1020
	  return NULL;
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
  1021
	}
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
  1022
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1023
    void *visit(function_invocation_c *symbol) {
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1024
      symbol_c* function_type_prefix = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1025
      symbol_c* function_name = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1026
      symbol_c* function_type_suffix = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1027
      DECLARE_PARAM_LIST()
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1028
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1029
      symbol_c *parameter_assignment_list = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1030
      if (NULL != symbol->   formal_param_list) parameter_assignment_list = symbol->   formal_param_list;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1031
      if (NULL != symbol->nonformal_param_list) parameter_assignment_list = symbol->nonformal_param_list;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1032
      if (NULL == parameter_assignment_list) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1033
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1034
      function_call_param_iterator_c function_call_param_iterator(symbol);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1035
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1036
      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
  1037
      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
  1038
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1039
      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
  1040
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1041
      /* 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
  1042
      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
  1043
      function_type_prefix = (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
  1044
      if (NULL == function_type_prefix) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1045
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1046
      /* 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
  1047
       * 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
  1048
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1049
      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
  1050
      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
  1051
        /* 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
  1052
      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
  1053
      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
  1054
        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
  1055
          /* 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
  1056
           * 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
  1057
           * 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
  1058
           *
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1059
           * 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
  1060
           * 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
  1061
           * 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
  1062
           */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1063
          /* 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
  1064
           *       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
  1065
           *       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
  1066
           *       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
  1067
           */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1068
          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
  1069
          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
  1070
          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
  1071
          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
  1072
          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
  1073
          uint_type_name_c *param_type  = new uint_type_name_c();
380
b78e59ed4269 Fix bug in generate_c_inlinefcall.cc that prevent to use extendible standard functions
laurent
parents: 355
diff changeset
  1074
          identifier_c *param_name = new identifier_c(INLINE_PARAM_COUNT);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1075
          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
  1076
          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
  1077
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1078
    
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1079
        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
  1080
          /* 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
  1081
           * 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
  1082
           * 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
  1083
           */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1084
          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
  1085
          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
  1086
          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
  1087
          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
  1088
          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
  1089
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1090
        
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1091
        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
  1092
        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
  1093
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1094
        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
  1095
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1096
        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
  1097
    
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1098
        /* 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
  1099
        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
  1100
          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
  1101
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1102
        /* 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
  1103
        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
  1104
          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
  1105
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1106
        
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1107
        /* 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
  1108
         * 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
  1109
         * have reached the end, and should simply jump out of the for loop.
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1110
         */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1111
        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
  1112
          break;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1113
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1114
    
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1115
        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
  1116
          /* 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
  1117
          /* 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
  1118
          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
  1119
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1120
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1121
        ADD_PARAM_LIST(param_name, param_value, param_type, param_direction)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1122
      } /* for(...) */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1123
      // symbol->parameter_assignment->accept(*this);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1124
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1125
      if (function_call_param_iterator.next_nf() != NULL) ERROR;
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1126
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1127
      bool has_output_params = false;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1128
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1129
      PARAM_LIST_ITERATOR() {
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1130
        if ((PARAM_DIRECTION == function_param_iterator_c::direction_out ||
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1131
             PARAM_DIRECTION == function_param_iterator_c::direction_inout) &&
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1132
             PARAM_VALUE != NULL) {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1133
          has_output_params = true;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1134
        }
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1135
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1136
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1137
      /* 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
  1138
      /* (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
  1139
      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
  1140
      if (fdecl_mutiplicity == 0) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1141
      if (fdecl_mutiplicity == 1) 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1142
        /* function being called is NOT overloaded! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1143
        f_decl = NULL; 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1144
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1145
      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
  1146
        generate_inline(function_name, function_type_prefix, function_type_suffix, param_list, f_decl);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1147
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1148
      CLEAR_PARAM_LIST()
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
  1149
337
9a2262fb7994 Fix bug with inline function call in POU programmed in IL
laurent
parents: 336
diff changeset
  1150
      return NULL;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1151
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
  1152
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
  1153
};  /* generate_c_inlinefcall_c */
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
  1154
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
  1155