stage4/generate_c/generate_c_inlinefcall.cc
author laurent
Tue, 15 Dec 2009 20:50:30 +0100
changeset 238 0919986a5c98
parent 237 cece842c7417
child 279 c0453b7f99df
permissions -rwxr-xr-x
Bug when trying to get type of elements in a big complex structure fixed
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     1
/*
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     2
 * (c) 2007 Mario de Sousa and Laurent Bessard
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     3
 *
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     4
 * Offered to the public under the terms of the GNU General Public License
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     5
 * as published by the Free Software Foundation; either version 2 of the
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     6
 * License, or (at your option) any later version.
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     7
 *
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     8
 * This program is distributed in the hope that it will be useful, but
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    11
 * Public License for more details.
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    12
 *
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    13
 * 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
    14
 * 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
    15
 */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    16
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    17
/*
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    18
 * An IEC 61131-3 IL and ST compiler.
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    19
 *
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    20
 * Based on the
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    21
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    22
 *
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
 * This is one of the versions available for the 4th stage.
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    27
 *
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    28
 * This 4th stage generates a c++ source program equivalent
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    29
 * to the IL and ST code.
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    30
 */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    31
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    32
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    33
#define INLINE_RESULT_TEMP_VAR "__res"
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    34
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
    35
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
    36
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
  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
    38
    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
    39
      expression_vg,
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
    40
      assignment_vg,
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
    41
      complextype_base_vg,
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
    42
      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
    43
    } 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
    44
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    45
  private:
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    46
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    47
    /* The name of the IL default variable... */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    48
	#define IL_DEFVAR   VAR_LEADER "IL_DEFVAR"
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    49
	/* 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
    50
	 * parenthesised instruction list to the immediately preceding
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    51
	 * scope ...
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    52
	 */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    53
	il_default_variable_c default_variable_name;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    54
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
    55
	symbol_c* current_array_type;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
    56
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    57
	int fcall_number;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    58
	symbol_c *fbname;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    59
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    60
    search_expression_type_c *search_expression_type;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    61
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    62
    search_varfb_instance_type_c *search_varfb_instance_type;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    63
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    64
    search_base_type_c search_base_type;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    65
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
    66
    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
    67
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    68
  public:
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
    69
    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
    70
    : generate_c_typedecl_c(s4o_ptr),
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    71
      default_variable_name(IL_DEFVAR, NULL)
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    72
    {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    73
      search_expression_type = new search_expression_type_c(scope);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    74
      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
    75
      this->set_variable_prefix(variable_prefix);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    76
      fcall_number = 0;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    77
      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
    78
      wanted_variablegeneration = expression_vg;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    79
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    80
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
    81
    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
    82
      delete search_expression_type;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    83
      delete search_varfb_instance_type;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    84
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    85
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
    86
    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
    87
      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
    88
      symbol_c* function_call;
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
    89
      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
    90
    	function_call->accept(*this);
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
    91
      }
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
    92
    }
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
    93
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
    94
    void generate_inline(symbol_c *function_name,
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
    95
            symbol_c *function_type_prefix,
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
    96
            symbol_c *function_type_suffix,
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
    97
            std::list<FUNCTION_PARAM*> param_list) {
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
    98
            std::list<FUNCTION_PARAM*>::iterator pt;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    99
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   100
      fcall_number++;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   101
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   102
      s4o.print(s4o.indent_spaces);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   103
      s4o.print("inline ");
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   104
      function_type_prefix->accept(*this);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   105
      s4o.print(" __");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   106
      fbname->accept(*this);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   107
      s4o.print("_");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   108
      function_name->accept(*this);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   109
      if (function_type_suffix)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   110
        function_type_suffix->accept(*this);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   111
      s4o.print_integer(fcall_number);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   112
      s4o.print("(");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   113
      s4o.indent_right();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   114
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   115
      PARAM_LIST_ITERATOR() {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   116
        if (PARAM_DIRECTION == function_param_iterator_c::direction_in) {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   117
          PARAM_TYPE->accept(*this);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   118
          s4o.print(" ");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   119
          PARAM_NAME->accept(*this);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   120
          s4o.print(",\n" + s4o.indent_spaces);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   121
        }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   122
      }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   123
      fbname->accept(*this);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   124
	  s4o.print(" *");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   125
	  s4o.print(FB_FUNCTION_PARAM);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   126
	  s4o.indent_left();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   127
	  s4o.print(")\n" + s4o.indent_spaces);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   128
	  s4o.print("{\n");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   129
      s4o.indent_right();
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
      s4o.print(s4o.indent_spaces);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   132
      function_type_prefix->accept(*this);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   133
      s4o.print(" "),
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   134
      s4o.print(INLINE_RESULT_TEMP_VAR);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   135
      s4o.print(";\n");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   136
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   137
	  PARAM_LIST_ITERATOR() {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   138
		if ((PARAM_DIRECTION == function_param_iterator_c::direction_out ||
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   139
		     PARAM_DIRECTION == function_param_iterator_c::direction_inout) &&
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   140
		    PARAM_VALUE != NULL) {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   141
		  s4o.print(s4o.indent_spaces);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   142
		  PARAM_TYPE->accept(*this);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   143
          s4o.print(" ");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   144
          s4o.print(TEMP_VAR);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   145
          PARAM_NAME->accept(*this);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   146
          s4o.print(" = ");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   147
          print_check_function(PARAM_TYPE, PARAM_VALUE);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   148
          s4o.print(";\n");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   149
		}
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   150
	  }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   151
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   152
	  s4o.print(s4o.indent_spaces + INLINE_RESULT_TEMP_VAR),
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   153
			  s4o.print(" = ");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   154
	  function_name->accept(*this);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   155
	  if (function_type_suffix)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   156
        function_type_suffix->accept(*this);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   157
	  s4o.print("(");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   158
	  s4o.indent_right();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   159
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   160
	  PARAM_LIST_ITERATOR() {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   161
		if (pt != param_list.begin())
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   162
		  s4o.print(",\n" + s4o.indent_spaces);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   163
		if (PARAM_DIRECTION == function_param_iterator_c::direction_in)
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   164
		  PARAM_NAME->accept(*this);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   165
		else if (PARAM_VALUE != NULL){
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   166
          s4o.print("&");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   167
          s4o.print(TEMP_VAR);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   168
          PARAM_NAME->accept(*this);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   169
        }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   170
		else {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   171
		  s4o.print("NULL");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   172
		}
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   173
	  }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   174
	  s4o.print(");\n");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   175
	  s4o.indent_left();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   176
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   177
	  PARAM_LIST_ITERATOR() {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   178
        if ((PARAM_DIRECTION == function_param_iterator_c::direction_out ||
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   179
        	 PARAM_DIRECTION == function_param_iterator_c::direction_inout) &&
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   180
        	PARAM_VALUE != NULL) {
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
          s4o.print(s4o.indent_spaces);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   183
          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
   184
          s4o.print(";\n");
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   185
		}
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   186
	  }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   187
	  s4o.print(s4o.indent_spaces + "return ");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   188
	  s4o.print(INLINE_RESULT_TEMP_VAR);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   189
	  s4o.print(";\n");
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.indent_left();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   192
      s4o.print(s4o.indent_spaces + "}\n\n");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   193
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   194
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   195
  private:
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   196
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   197
    void *print_getter(symbol_c *symbol) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   198
      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
   199
      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
   200
    	s4o.print(GET_EXTERNAL);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   201
      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
   202
    	s4o.print(GET_LOCATED);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   203
      else
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   204
    	s4o.print(GET_VAR);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   205
      s4o.print("(");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   206
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   207
      wanted_variablegeneration = complextype_base_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   208
      symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   209
      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
   210
    	s4o.print(",");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   211
      wanted_variablegeneration = complextype_suffix_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   212
      symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   213
      s4o.print(")");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   214
      wanted_variablegeneration = expression_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   215
      return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   216
    }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   217
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   218
    void *print_setter(symbol_c* symbol,
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   219
    		symbol_c* type,
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   220
    		symbol_c* value) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   221
      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
   222
      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
   223
        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
   224
        /* 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
   225
        if (variable != NULL) {
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   226
          s4o.print(SET_EXTERNAL);
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   227
          s4o.print("(");
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   228
          variable->var_name->accept(*this);
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   229
          s4o.print(",");
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   230
        }
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   231
        else {
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   232
          s4o.print(SET_COMPLEX_EXTERNAL);
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   233
          s4o.print("(");
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   234
        }
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   235
      }
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   236
      else {
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   237
        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
   238
          s4o.print(SET_LOCATED);
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   239
        else
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   240
          s4o.print(SET_VAR);
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   241
        s4o.print("(");
b8527b0abe75 Adding support for forcing global without perturbation from setting external
laurent
parents: 228
diff changeset
   242
      }
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   243
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   244
      wanted_variablegeneration = complextype_base_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   245
      symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   246
      s4o.print(",");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   247
      wanted_variablegeneration = expression_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   248
      print_check_function(type, value, NULL, true);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   249
      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
   250
        s4o.print(",");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   251
        wanted_variablegeneration = complextype_suffix_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   252
        symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   253
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   254
      s4o.print(")");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   255
      wanted_variablegeneration = expression_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   256
      return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   257
    }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   258
219
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
    /* B 1.4 - Variables */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   261
    /*********************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   262
    void *visit(symbolic_variable_c *symbol) {
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   263
      unsigned int vartype;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   264
      if (wanted_variablegeneration == complextype_base_vg)
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   265
        generate_c_base_c::visit(symbol);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   266
      else if (wanted_variablegeneration == complextype_suffix_vg)
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   267
        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
   268
      else
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   269
        print_getter(symbol);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   270
      return NULL;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   271
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   272
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   273
    /********************************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   274
    /* B.1.4.1   Directly Represented Variables */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   275
    /********************************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   276
    // direct_variable: direct_variable_token   {$$ = new direct_variable_c($1);};
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   277
    void *visit(direct_variable_c *symbol) {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   278
      TRACE("direct_variable_c");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   279
      /* 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
   280
      if (strlen(symbol->value) == 0) ERROR;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   281
      s4o.print(GET_LOCATED);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   282
      s4o.print("(");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   283
      this->print_variable_prefix();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   284
      s4o.printlocation(symbol->value + 1);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   285
      s4o.print(")");
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   286
      return NULL;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   287
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   288
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   289
    /*************************************/
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   290
    /* B.1.4.2   Multi-element Variables */
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   291
    /*************************************/
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   292
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   293
    // 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
   294
    void *visit(structured_variable_c *symbol) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   295
      TRACE("structured_variable_c");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   296
      switch (wanted_variablegeneration) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   297
        case complextype_base_vg:
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   298
          symbol->record_variable->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   299
          break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   300
        case complextype_suffix_vg:
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   301
          symbol->record_variable->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   302
          s4o.print(".");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   303
          symbol->field_selector->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   304
          break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   305
        default:
237
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 235
diff changeset
   306
          print_getter(symbol);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   307
          break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   308
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   309
      return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   310
    }
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
    /*  subscripted_variable '[' subscript_list ']' */
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   313
    //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
   314
    void *visit(array_variable_c *symbol) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   315
      switch (wanted_variablegeneration) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   316
        case complextype_base_vg:
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   317
          symbol->subscripted_variable->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   318
          break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   319
        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
   320
          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
   321
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   322
          current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable);
238
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   323
          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
   324
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   325
          s4o.print(".table");
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   326
          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
   327
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   328
          current_array_type = NULL;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   329
          break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   330
        default:
237
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 235
diff changeset
   331
          print_getter(symbol);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   332
          break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   333
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   334
      return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   335
    }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 221
diff changeset
   336
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   337
    /****************************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   338
    /* B.2 - Language IL (Instruction List) */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   339
    /****************************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   340
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   341
    /***********************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   342
    /* B 2.1 Instructions and Operands */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   343
    /***********************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   344
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   345
    void *visit(il_function_call_c *symbol) {
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   346
      symbol_c* function_type_prefix = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   347
      symbol_c* function_name = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   348
      symbol_c* function_type_suffix = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   349
      DECLARE_PARAM_LIST()
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   350
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   351
      symbol_c *param_data_type = default_variable_name.current_type;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   352
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   353
      function_call_param_iterator_c function_call_param_iterator(symbol);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   354
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   355
      function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   356
	  if (f_decl == function_symtable.end_value()) {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   357
        function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   358
        if (current_function_type == function_none) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   359
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   360
        function_type_prefix = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   361
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   362
        symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN"));
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   363
        /* Add the value from EN param */
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   364
        ADD_PARAM_LIST(en_param_name,
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   365
                       (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())),
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   366
                       (symbol_c*)(new bool_type_name_c()),
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   367
                       function_param_iterator_c::direction_in)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   368
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   369
        symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO"));
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   370
        /* Add the value from ENO param */
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   371
        ADD_PARAM_LIST(eno_param_name, NULL, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   372
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   373
        int nb_param = 1;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   374
        if (symbol->il_operand_list != NULL)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   375
          nb_param += ((list_c *)symbol->il_operand_list)->n;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   376
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   377
        #include "il_code_gen.c"
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   378
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   379
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   380
	  else {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   381
		function_name = symbol->function_name;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   382
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   383
		/* determine the base data type returned by the function being called... */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   384
		search_base_type_c search_base_type;
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   385
		function_type_prefix = (symbol_c *)f_decl->type_name->accept(search_base_type);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   386
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   387
		/* loop through each function parameter, find the value we should pass
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   388
		 * to it, and then output the c equivalent...
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   389
		 */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   390
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   391
		function_param_iterator_c fp_iterator(f_decl);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   392
		identifier_c *param_name;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   393
		for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   394
		  symbol_c *param_type = fp_iterator.param_type();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   395
		  if (param_type == NULL) ERROR;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   396
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   397
		  function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   398
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   399
		  symbol_c *param_value = NULL;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   400
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   401
		  /* if it is the first parameter, semantics specifies that we should
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   402
		   * get the value off the IL default variable!
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   403
		   */
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   404
		  if (1 == i)
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   405
		    param_value = &this->default_variable_name;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   406
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   407
		  /* Get the value from a foo(<param_name> = <param_value>) style call */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   408
		  /* NOTE: the following line of code is not required in this case, but it doesn't
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   409
		   * harm to leave it in, as in the case of a non-formal syntax function call,
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   410
		   * it will always return NULL.
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   411
		   * We leave it in in case we later decide to merge this part of the code together
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   412
		   * with the function calling code in generate_c_st_c, which does require
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   413
		   * the following line...
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   414
		   */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   415
		  if (param_value == NULL)
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   416
			param_value = function_call_param_iterator.search_f(param_name);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   417
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   418
		  /* Get the value from a foo(<param_value>) style call */
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   419
          if (param_value == NULL) {
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   420
            param_value = function_call_param_iterator.next_nf();
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   421
            if (param_value != NULL && fp_iterator.is_en_eno_param_implicit()) ERROR;
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   422
          }
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   423
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   424
		  if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   425
			/* No value given for parameter, so we must use the default... */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   426
			/* First check whether default value specified in function declaration...*/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   427
			param_value = fp_iterator.default_value();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   428
		  }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   429
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   430
		  ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction())
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   431
		} /* for(...) */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   432
	  }
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   433
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   434
	  if (function_call_param_iterator.next_nf() != NULL) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   435
      if (NULL == function_type_prefix) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   436
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   437
      bool has_output_params = false;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   438
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   439
      PARAM_LIST_ITERATOR() {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   440
        if ((PARAM_DIRECTION == function_param_iterator_c::direction_out ||
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   441
             PARAM_DIRECTION == function_param_iterator_c::direction_inout) &&
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   442
             PARAM_VALUE != NULL) {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   443
          has_output_params = true;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   444
        }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   445
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   446
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   447
      if (has_output_params)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   448
        generate_inline(function_name, function_type_prefix, function_type_suffix, param_list);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   449
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   450
      CLEAR_PARAM_LIST()
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   451
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   452
      return NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   453
    }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   454
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   455
    /* | function_name '(' eol_list [il_param_list] ')' */
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   456
    // 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
   457
    void *visit(il_formal_funct_call_c *symbol) {
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   458
      symbol_c* function_type_prefix = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   459
      symbol_c* function_name = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   460
      symbol_c* function_type_suffix = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   461
      DECLARE_PARAM_LIST()
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   462
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   463
      function_call_param_iterator_c function_call_param_iterator(symbol);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   464
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   465
      function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   466
      if (f_decl == function_symtable.end_value()) {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   467
        function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   468
        if (current_function_type == function_none) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   469
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   470
        function_type_prefix = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   471
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   472
        int nb_param = 0;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   473
        if (symbol->il_param_list != NULL)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   474
          nb_param += ((list_c *)symbol->il_param_list)->n;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   475
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   476
        symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN"));
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   477
        /* Get the value from EN param */
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   478
        symbol_c *EN_param_value = function_call_param_iterator.search_f(en_param_name);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   479
        if (EN_param_value == NULL)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   480
          EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c()));
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   481
        else
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   482
          nb_param --;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   483
        ADD_PARAM_LIST(en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   484
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   485
        symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO"));
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   486
        /* Get the value from ENO param */
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   487
        symbol_c *ENO_param_value = function_call_param_iterator.search_f(eno_param_name);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   488
        if (ENO_param_value != NULL)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   489
          nb_param --;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   490
        ADD_PARAM_LIST(eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   491
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   492
        #include "st_code_gen.c"
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   493
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   494
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   495
      else {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   496
        function_name = symbol->function_name;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   497
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   498
		/* determine the base data type returned by the function being called... */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   499
		search_base_type_c search_base_type;
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   500
		function_type_prefix = (symbol_c *)f_decl->type_name->accept(search_base_type);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   501
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   502
		/* loop through each function parameter, find the value we should pass
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   503
		 * to it, and then output the c equivalent...
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   504
		 */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   505
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   506
		function_param_iterator_c fp_iterator(f_decl);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   507
		identifier_c *param_name;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   508
		for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   509
		  symbol_c *param_type = fp_iterator.param_type();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   510
		  if (param_type == NULL) ERROR;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   511
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   512
		  function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   513
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   514
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   515
		  symbol_c *param_value = NULL;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   516
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   517
		  /* Get the value from a foo(<param_name> = <param_value>) style call */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   518
		  if (param_value == NULL)
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   519
			param_value = function_call_param_iterator.search_f(param_name);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   520
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   521
		  /* Get the value from a foo(<param_value>) style call */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   522
		  /* NOTE: the following line of code is not required in this case, but it doesn't
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   523
		   * harm to leave it in, as in the case of a formal syntax function call,
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   524
		   * it will always return NULL.
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   525
		   * We leave it in in case we later decide to merge this part of the code together
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   526
		   * with the function calling code in generate_c_st_c, which does require
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   527
		   * the following line...
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   528
		   */
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   529
		  if (param_value == NULL) {
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   530
            param_value = function_call_param_iterator.next_nf();
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   531
            if (param_value != NULL && fp_iterator.is_en_eno_param_implicit()) ERROR;
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   532
          }
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   533
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   534
		  if (param_value == NULL) {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   535
			/* No value given for parameter, so we must use the default... */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   536
			/* First check whether default value specified in function declaration...*/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   537
			param_value = fp_iterator.default_value();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   538
		  }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   539
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   540
		  ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction())
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   541
		}
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   542
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   543
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   544
      if (function_call_param_iterator.next_nf() != NULL) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   545
      if (NULL == function_type_prefix) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   546
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   547
      bool has_output_params = false;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   548
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   549
      PARAM_LIST_ITERATOR() {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   550
        if ((PARAM_DIRECTION == function_param_iterator_c::direction_out ||
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   551
             PARAM_DIRECTION == function_param_iterator_c::direction_inout) &&
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   552
             PARAM_VALUE != NULL) {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   553
          has_output_params = true;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   554
        }
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   555
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   556
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   557
      if (has_output_params)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   558
        generate_inline(function_name, function_type_prefix, function_type_suffix, param_list);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   559
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   560
      CLEAR_PARAM_LIST()
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   561
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   562
      return NULL;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   563
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   564
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   565
    /***************************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   566
    /* B.3 - Language ST (Structured Text) */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   567
    /***************************************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   568
    /***********************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   569
    /* B 3.1 - Expressions */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   570
    /***********************/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   571
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   572
    void *visit(function_invocation_c *symbol) {
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   573
      symbol_c* function_type_prefix = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   574
      symbol_c* function_name = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   575
      symbol_c* function_type_suffix = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   576
      DECLARE_PARAM_LIST()
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   577
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   578
      symbol_c *parameter_assignment_list = NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   579
      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
   580
      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
   581
      if (NULL == parameter_assignment_list) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   582
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   583
      function_call_param_iterator_c function_call_param_iterator(symbol);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   584
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   585
      function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   586
      if (f_decl == function_symtable.end_value()) {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   587
        /* The function called is not in the symtable, so we test if it is a
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   588
         * standard function defined in standard */
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   589
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   590
        function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   591
        if (current_function_type == function_none) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   592
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   593
        function_type_prefix = search_expression_type->get_type(symbol);
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
        int nb_param = ((list_c *)parameter_assignment_list)->n;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   596
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   597
        symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN"));
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   598
        /* Get the value from EN param */
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   599
        symbol_c *EN_param_value = function_call_param_iterator.search_f(en_param_name);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   600
        if (EN_param_value == NULL)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   601
          EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c()));
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   602
        else
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   603
          nb_param --;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   604
        ADD_PARAM_LIST(en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   605
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   606
        symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO"));
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   607
        /* Get the value from ENO param */
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   608
        symbol_c *ENO_param_value = function_call_param_iterator.search_f(eno_param_name);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   609
        if (ENO_param_value != NULL)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   610
          nb_param --;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   611
        ADD_PARAM_LIST(eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   612
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   613
        #include "st_code_gen.c"
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   614
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   615
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   616
      else {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   617
        function_name = symbol->function_name;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   618
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   619
	    /* determine the base data type returned by the function being called... */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   620
		search_base_type_c search_base_type;
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   621
		function_type_prefix = (symbol_c *)f_decl->type_name->accept(search_base_type);
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   622
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   623
    	/* loop through each function parameter, find the value we should pass
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   624
         * to it, and then output the c equivalent...
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   625
         */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   626
        function_param_iterator_c fp_iterator(f_decl);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   627
        identifier_c *param_name;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   628
        for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   629
          symbol_c *param_type = fp_iterator.param_type();
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   630
          if (param_type == NULL) ERROR;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   631
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   632
          function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   633
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   634
          /* Get the value from a foo(<param_name> = <param_value>) style call */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   635
          symbol_c *param_value = function_call_param_iterator.search_f(param_name);
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   636
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   637
          /* Get the value from a foo(<param_value>) style call */
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   638
          if (param_value == NULL) {
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   639
            param_value = function_call_param_iterator.next_nf();
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   640
            if (param_value != NULL && fp_iterator.is_en_eno_param_implicit()) ERROR;
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   641
          }
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   642
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   643
          if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) {
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   644
            /* No value given for parameter, so we must use the default... */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   645
            /* First check whether default value specified in function declaration...*/
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   646
            param_value = fp_iterator.default_value();
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   647
          }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   648
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   649
          ADD_PARAM_LIST(param_name, param_value, param_type, param_direction)
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   650
        } /* for(...) */
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   651
        // symbol->parameter_assignment->accept(*this);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   652
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   653
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   654
      if (function_call_param_iterator.next_nf() != NULL) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   655
      if (NULL == function_type_prefix) ERROR;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   656
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   657
	  bool has_output_params = false;
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
	  PARAM_LIST_ITERATOR() {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   660
        if ((PARAM_DIRECTION == function_param_iterator_c::direction_out ||
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   661
             PARAM_DIRECTION == function_param_iterator_c::direction_inout) &&
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   662
             PARAM_VALUE != NULL) {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   663
          has_output_params = true;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   664
        }
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   665
      }
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
      if (has_output_params)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   668
        generate_inline(function_name, function_type_prefix, function_type_suffix, param_list);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   669
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   670
      CLEAR_PARAM_LIST()
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 234
diff changeset
   671
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   672
	  return NULL;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   673
    }
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
   674
234
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   675
};  /* generate_c_inlinefcall_c */
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   676
e4d31cd0e6d8 Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents: 233
diff changeset
   677