stage4/generate_c/generate_c_il.cc
author mjsousa
Sun, 16 Nov 2014 12:54:10 +0000
changeset 945 477393b00f95
parent 885 b2604fc6d25c
child 971 8aee27d46208
permissions -rwxr-xr-x
Add support for relaxed datatype model for array datatypes.
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     1
/*
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     3
 *
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
     4
 *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
     5
 *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
     6
 *
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
     7
 *  This program is free software: you can redistribute it and/or modify
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
     8
 *  it under the terms of the GNU General Public License as published by
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
     9
 *  the Free Software Foundation, either version 3 of the License, or
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    10
 *  (at your option) any later version.
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    11
 *
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    12
 *  This program is distributed in the hope that it will be useful,
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    15
 *  GNU General Public License for more details.
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    16
 *
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    17
 *  You should have received a copy of the GNU General Public License
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 240
diff changeset
    19
 *
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    20
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    21
 * This code is made available on the understanding that it will not be
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    22
 * used in safety-critical situations without a full and competent review.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    23
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    24
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    25
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    26
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    27
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    28
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    29
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    30
/* Returns the data type of an il_operand.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    31
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    32
 * Note that the il_operand may be a variable, in which case
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    33
 * we return the type of the variable instance.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    34
 * The il_operand may also be a constant, in which case
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    35
 * we return the data type of that constant.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    36
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    37
 * The variable instance may be a member of a structured variable,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    38
 * or an element in an array, or any combination of the two.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    39
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    40
 * The class constructor must be given the search scope
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    41
 * (function, function block or program within which
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    42
 * the possible il_operand variable instance was declared).
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    43
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    44
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    45
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    46
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    47
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    48
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    49
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    50
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
    51
/* A new class to ouput the IL implicit variable to c++ code
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    52
 * We use this class, inheriting from symbol_c, so it may be used
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    53
 * as any other symbol_c object in the intermediate parse tree,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    54
 * more specifically, so it can be used as any other il operand.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    55
 * This makes the rest of the code much easier...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    56
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    57
 * Nevertheless, the basic visitor class visitor_c does not know
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    58
 * how to visit this new il_default_variable_c class, so we have
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    59
 * to extend that too.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    60
 * In reality extending the basic symbols doesn't quite work out
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    61
 * as cleanly as desired (we need to use dynamic_cast in the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    62
 * accept method of the il_default_variable_c), but it is cleaner
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    63
 * than the alternative...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    64
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    65
class il_default_variable_c;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    66
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    67
/* This visitor class is not really required, we could place the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    68
 * visit() method directly in genertae_cc_il_c, but doing it in
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    69
 * a seperate class makes the architecture more evident...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    70
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    71
class il_default_variable_visitor_c {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    72
  public:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    73
    virtual void *visit(il_default_variable_c *symbol) = 0;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    74
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    75
    virtual ~il_default_variable_visitor_c(void) {return;}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    76
};
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    77
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    78
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    79
/* A class to print out to the resulting C++ code
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
    80
 * the IL implicit variable name.
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    81
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    82
 * It includes a reference to its name,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    83
 * and the data type of the data currently stored
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    84
 * in this C++ variable... This is required because the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    85
 * C++ variable is a union, and we must know which member
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    86
 * of the union top reference!!
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    87
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    88
 * Note that we also need to keep track of the data type of
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
    89
 * the value currently being stored in the IL implicit variable.
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    90
 * This is required so we can process parenthesis,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    91
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    92
 * e.g. :
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    93
 *         LD var1
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    94
 *         AND (
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    95
 *         LD var2
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    96
 *         OR var3
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    97
 *         )
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    98
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
    99
 * Note that we only execute the 'AND (' operation when we come across
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   100
 * the ')', i.e. once we have evaluated the result of the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   101
 * instructions inside the parenthesis.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   102
 * When we do execute the 'AND (' operation, we need to know the data type
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   103
 * of the operand, which in this case is the result of the evaluation of the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   104
 * instruction list inside the parenthesis. We can only know this if we
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   105
 * keep track of the data type currently stored in the IL implicit variable!
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   106
 *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   107
 * We use the current_type inside the generate_c_il::default_variable_name variable
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   108
 * to track this!
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   109
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   110
class il_default_variable_c: public symbol_c {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   111
  public:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   112
    symbol_c *var_name;  /* in principle, this should point to an indentifier_c */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   113
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   114
  public:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   115
    il_default_variable_c(const char *var_name_str, symbol_c *current_type);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   116
    virtual void *accept(visitor_c &visitor);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   117
};
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   118
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   119
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   120
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   121
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   122
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   123
/***********************************************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   124
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   125
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   126
669
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   127
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   128
945
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 885
diff changeset
   129
class generate_c_il_c: public generate_c_base_and_typeid_c, il_default_variable_visitor_c {
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   130
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   131
  public:
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   132
    typedef enum {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   133
      expression_vg,
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   134
      assignment_vg,
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   135
      complextype_base_vg,
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   136
      complextype_base_assignment_vg,
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   137
      complextype_suffix_vg,
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   138
      fparam_output_vg
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   139
    } variablegeneration_t;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   140
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   141
  private:
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   142
    /* Label to which the current IL jump operation should jump to... */
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   143
    /* This variable is used to pass data from the
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   144
     * il_jump_operation_c visitor
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   145
     * to the il jump operator visitors (i.e. JMP_operator_c,
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   146
     * JMPC_operator_c, JMPCN_operator_c, ...)
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   147
     */
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   148
    symbol_c *jump_label;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   149
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   150
    /* the data type of the IL implicit variable... */
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   151
    #define IL_DEFVAR_T VAR_LEADER "IL_DEFVAR_T"
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   152
    /* The name of the IL implicit variable... */
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   153
    #define IL_DEFVAR   VAR_LEADER "IL_DEFVAR"
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   154
    /* The name of the variable used to pass the result of a
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   155
     * parenthesised instruction list to the immediately preceding
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   156
     * scope ...
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   157
     */
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   158
    #define IL_DEFVAR_BACK   VAR_LEADER "IL_DEFVAR_BACK"
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   159
    
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   160
    il_default_variable_c implicit_variable_current;      /* the current   implicit variable, with the datatype resulting from the previous IL operation */
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   161
    il_default_variable_c implicit_variable_result;       /* the resulting implicit variable, with the datatype resulting from the current  IL operation */
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   162
    il_default_variable_c implicit_variable_result_back;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   163
    
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   164
    /* Operand to the IL operation currently being processed... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   165
    /* These variables are used to pass data from the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   166
     * il_simple_operation_c and il_expression_c visitors
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   167
     * to the il operator visitors (i.e. LD_operator_c,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   168
     * LDN_operator_c, ST_operator_c, STN_operator_c, ...)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   169
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   170
    symbol_c *current_operand;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   171
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   172
    /* When calling a function block, we must first find it's type,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   173
     * by searching through the declarations of the variables currently
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   174
     * in scope.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   175
     * This class does just that...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   176
     * A new class is instantiated whenever we begin generating the code
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   177
     * for a function block type declaration, or a program declaration.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   178
     * This object instance will then later be called while the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   179
     * function block's or the program's body is being handled.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   180
     *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   181
     * Note that functions cannot contain calls to function blocks,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   182
     * so we do not create an object instance when handling
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   183
     * a function declaration.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   184
     */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   185
    search_fb_instance_decl_c *search_fb_instance_decl;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   186
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   187
    search_varfb_instance_type_c *search_varfb_instance_type;
505
21be0f2f242d Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents: 498
diff changeset
   188
    search_var_instance_decl_c   *search_var_instance_decl;
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   189
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   190
    symbol_c* current_array_type;
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   191
    symbol_c* current_param_type;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   192
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   193
    int fcall_number;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   194
    symbol_c *fbname;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   195
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   196
    variablegeneration_t wanted_variablegeneration;
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   197
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   198
  public:
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   199
    generate_c_il_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL)
945
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 885
diff changeset
   200
    : generate_c_base_and_typeid_c(s4o_ptr),
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   201
      implicit_variable_current    (IL_DEFVAR,      NULL),
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   202
      implicit_variable_result     (IL_DEFVAR,      NULL),
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   203
      implicit_variable_result_back(IL_DEFVAR_BACK, NULL)
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   204
    {
669
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   205
      search_fb_instance_decl    = new search_fb_instance_decl_c   (scope);
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   206
      search_varfb_instance_type = new search_varfb_instance_type_c(scope);
669
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   207
      search_var_instance_decl   = new search_var_instance_decl_c  (scope);
505
21be0f2f242d Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents: 498
diff changeset
   208
      
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   209
      current_operand = NULL;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   210
      current_array_type = NULL;
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   211
      current_param_type = NULL;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   212
      fcall_number = 0;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   213
      fbname = name;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   214
      wanted_variablegeneration = expression_vg;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   215
      this->set_variable_prefix(variable_prefix);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   216
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   217
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   218
    virtual ~generate_c_il_c(void) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   219
      delete search_fb_instance_decl;
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
   220
      delete search_varfb_instance_type;
505
21be0f2f242d Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents: 498
diff changeset
   221
      delete search_var_instance_decl;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   222
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   223
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   224
    void generate(instruction_list_c *il) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   225
      il->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   226
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   227
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   228
  private:
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   229
    /* Declare an implicit IL variable... */
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   230
    void declare_implicit_variable(il_default_variable_c *implicit_var) {
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   231
      s4o.print(s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   232
      s4o.print(IL_DEFVAR_T);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   233
      s4o.print(" ");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   234
      implicit_var->datatype = NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   235
      implicit_var->accept(*this);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   236
      s4o.print(";\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   237
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   238
    
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   239
  public:  
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   240
    /* Declare the default variable, that will store the result of the IL operations */
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   241
    void declare_implicit_variable(void) {
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   242
      declare_implicit_variable(&this->implicit_variable_result);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   243
    }
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   244
    
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   245
    /* Declare the backup to the default variable, that will store the result of the IL operations executed inside a parenthesis... */
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   246
    void declare_implicit_variable_back(void) {
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   247
      declare_implicit_variable(&this->implicit_variable_result_back);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   248
    }
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   249
    
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   250
    void print_implicit_variable_back(void) {
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   251
      this->implicit_variable_result_back.accept(*this);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   252
    }    
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   253
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   254
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   255
  private:
669
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   256
    /* a small helper function */
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   257
    symbol_c *default_literal_type(symbol_c *symbol) {
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   258
      if (get_datatype_info_c::is_ANY_INT_literal(symbol)) {
693
51a2fa6441b9 Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 690
diff changeset
   259
        return &get_datatype_info_c::lint_type_name;
669
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   260
      }
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   261
      else if (get_datatype_info_c::is_ANY_REAL_literal(symbol)) {
693
51a2fa6441b9 Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 690
diff changeset
   262
        return &get_datatype_info_c::lreal_type_name;
669
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   263
      }
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   264
      return symbol;
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   265
    }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   266
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   267
    /* A helper function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   268
    void *XXX_operator(symbol_c *lo, const char *op, symbol_c *ro) {
669
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   269
      if ((NULL == lo) || (NULL == ro) || (NULL == op)) ERROR;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   270
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   271
      lo->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   272
      s4o.print(op);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   273
      ro->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   274
      return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   275
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   276
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   277
    /* A helper function... */
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   278
    void *XXX_function(symbol_c *res, const char *func, symbol_c *lo, symbol_c *ro) {
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   279
      if ((NULL == res) || (NULL == lo) || (NULL == ro)) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   280
      if  (NULL == func) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   281
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   282
      res->accept(*this);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   283
      s4o.print(" = ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   284
      s4o.print(func);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   285
      s4o.print("(");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   286
      lo->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   287
      s4o.print(", ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   288
      ro->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   289
      s4o.print(")");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   290
      return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   291
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   292
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   293
    /* A helper function... used for implicit FB calls: S1, R1, CLK, CU, CD, PV, IN, and PT */
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   294
    void *XXX_CAL_operator(const char *param_name, symbol_c *fb_name) {
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   295
      if (wanted_variablegeneration != expression_vg) {
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   296
        s4o.print(param_name);
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   297
        return NULL;
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   298
      }
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   299
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   300
      if (NULL == fb_name) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   301
      symbolic_variable_c *sv = dynamic_cast<symbolic_variable_c *>(fb_name);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   302
      if (NULL == sv) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   303
      identifier_c *id = dynamic_cast<identifier_c *>(sv->var_name);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   304
      if (NULL == id) ERROR;
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   305
      
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   306
      identifier_c param(param_name);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   307
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   308
      //SYM_REF3(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list)
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   309
      il_assign_operator_c il_assign_operator(&param);
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   310
      il_param_assignment_c il_param_assignment(&il_assign_operator, &this->implicit_variable_current, NULL);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   311
      // SYM_LIST(il_param_list_c)
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   312
      il_param_list_c il_param_list;   
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   313
      il_param_list.add_element(&il_param_assignment);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   314
      CAL_operator_c CAL_operator;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   315
      // SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   316
      il_fb_call_c il_fb_call(&CAL_operator, id, NULL, &il_param_list);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   317
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   318
      il_fb_call.accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   319
      return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   320
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   321
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   322
    /* A helper function... */
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   323
    void *CMP_operator(symbol_c *operand, const char *operation) {
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   324
      if (NULL == operand) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   325
      if (NULL == operand->datatype) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   326
      if (NULL == this->implicit_variable_current.datatype) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   327
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   328
      this->implicit_variable_result.accept(*this);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   329
      s4o.print(" = ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   330
      s4o.print(operation);
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   331
      operand->datatype->accept(*this);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   332
      /* NOTE: we are calling a standard Function: 
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   333
       *         1st parameter: EN  (enable)
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   334
       *         2nd parameter: ENO (enable output)
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   335
       *         3rd parameter: number of operands we will be passing (required because we are calling an extensible standard function!)
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   336
       *         4th parameter: the left  hand side of the comparison expression (in out case, the IL implicit variable)
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   337
       *         4th parameter: the right hand side of the comparison expression (in out case, current operand)
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   338
       */
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   339
      s4o.print("(__BOOL_LITERAL(TRUE), NULL, 2, ");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   340
      this->implicit_variable_current.accept(*this);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   341
      s4o.print(", ");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   342
      operand->accept(*this);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   343
      s4o.print(")");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   344
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   345
      return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   346
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   347
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   348
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   349
    /* A helper function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   350
    void C_modifier(void) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   351
      if (!get_datatype_info_c::is_BOOL_compatible(implicit_variable_current.datatype)) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   352
      s4o.print("if (");
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   353
      this->implicit_variable_current.accept(*this);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   354
      s4o.print(") ");
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   355
    }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   356
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   357
    /* A helper function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   358
    void CN_modifier(void) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   359
      if (!get_datatype_info_c::is_BOOL_compatible(implicit_variable_current.datatype)) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   360
      s4o.print("if (!");
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   361
      this->implicit_variable_current.accept(*this);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   362
      s4o.print(") ");
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   363
    }
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   364
210
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 208
diff changeset
   365
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   366
    void *print_getter(symbol_c *symbol) {
505
21be0f2f242d Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents: 498
diff changeset
   367
      unsigned int vartype = search_var_instance_decl->get_vartype(symbol);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   368
      if (wanted_variablegeneration == fparam_output_vg) {
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   369
        if (vartype == search_var_instance_decl_c::external_vt) {
854
13d0b67de111 Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 852
diff changeset
   370
          if (!get_datatype_info_c::is_type_valid    (symbol->datatype)) ERROR;
13d0b67de111 Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 852
diff changeset
   371
          if ( get_datatype_info_c::is_function_block(symbol->datatype))
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   372
            s4o.print(GET_EXTERNAL_FB_BY_REF);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   373
          else
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   374
            s4o.print(GET_EXTERNAL_BY_REF);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   375
        }
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   376
        else if (vartype == search_var_instance_decl_c::located_vt)
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   377
          s4o.print(GET_LOCATED_BY_REF);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   378
        else
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   379
          s4o.print(GET_VAR_BY_REF);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   380
      }
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   381
      else {
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   382
        if (vartype == search_var_instance_decl_c::external_vt) {
854
13d0b67de111 Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 852
diff changeset
   383
          if (!get_datatype_info_c::is_type_valid    (symbol->datatype)) ERROR;
13d0b67de111 Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 852
diff changeset
   384
          if ( get_datatype_info_c::is_function_block(symbol->datatype))
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   385
            s4o.print(GET_EXTERNAL_FB);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   386
          else
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   387
            s4o.print(GET_EXTERNAL);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   388
        }
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   389
        else if (vartype == search_var_instance_decl_c::located_vt)
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   390
          s4o.print(GET_LOCATED);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   391
        else
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   392
          s4o.print(GET_VAR);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   393
      }
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   394
      s4o.print("(");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   395
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   396
      variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   397
      wanted_variablegeneration = complextype_base_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   398
      symbol->accept(*this);
851
2c59c2b8fca4 Fix bug/issue #33 (correctly access struct/array variables declared inside a FB -> r:=FB1.FB2.struct1.array1[3] )
Mario de Sousa <msousa@fe.up.pt>
parents: 844
diff changeset
   399
      s4o.print(",");
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   400
      wanted_variablegeneration = complextype_suffix_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   401
      symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   402
      s4o.print(")");
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   403
      wanted_variablegeneration = old_wanted_variablegeneration;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   404
      return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   405
    }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   406
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   407
    void *print_setter(symbol_c* symbol,
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   408
            symbol_c* type,
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   409
            symbol_c* value,
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   410
            symbol_c* fb_symbol = NULL,
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   411
            symbol_c* fb_value = NULL,
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   412
            bool negative = false) {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   413
842
2415912b0aa0 Fix C code generation of FB invocation in IL.
mjsousa
parents: 835
diff changeset
   414
      bool type_is_complex = false;
405
7b5d67d1aeef Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents: 399
diff changeset
   415
      if (fb_symbol == NULL) {
505
21be0f2f242d Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents: 498
diff changeset
   416
        unsigned int vartype = search_var_instance_decl->get_vartype(symbol);
852
efb44e892582 Fix bug: allow use, as lvalues, structures/arrays inside FBs (e.g. fb1.struct1.r := 33.3).
Mario de Sousa <msousa@fe.up.pt>
parents: 851
diff changeset
   417
        type_is_complex = analyse_variable_c::contains_complex_type(symbol);
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   418
        if (vartype == search_var_instance_decl_c::external_vt) {
854
13d0b67de111 Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 852
diff changeset
   419
          if (!get_datatype_info_c::is_type_valid    (symbol->datatype)) ERROR;
13d0b67de111 Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 852
diff changeset
   420
          if ( get_datatype_info_c::is_function_block(symbol->datatype))
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   421
            s4o.print(SET_EXTERNAL_FB);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   422
          else
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   423
            s4o.print(SET_EXTERNAL);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   424
        }
405
7b5d67d1aeef Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents: 399
diff changeset
   425
        else if (vartype == search_var_instance_decl_c::located_vt)
7b5d67d1aeef Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents: 399
diff changeset
   426
          s4o.print(SET_LOCATED);
7b5d67d1aeef Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents: 399
diff changeset
   427
        else
7b5d67d1aeef Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents: 399
diff changeset
   428
          s4o.print(SET_VAR);
7b5d67d1aeef Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents: 399
diff changeset
   429
      }
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   430
      else {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   431
        unsigned int vartype = search_var_instance_decl->get_vartype(fb_symbol);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   432
        if (vartype == search_var_instance_decl_c::external_vt)
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   433
          s4o.print(SET_EXTERNAL_FB);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   434
        else
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   435
          s4o.print(SET_VAR);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   436
      }
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   437
      s4o.print("(");
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   438
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   439
      if (fb_symbol != NULL) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   440
        print_variable_prefix();
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   441
        fb_symbol->accept(*this);
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   442
        s4o.print(".,");
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   443
      }
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   444
      else if (type_is_complex)
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   445
        wanted_variablegeneration = complextype_base_assignment_vg;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   446
      else
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   447
        wanted_variablegeneration = assignment_vg;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   448
      symbol->accept(*this);
885
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   449
/*
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   450
      s4o.print(",");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   451
      if (negative) {
835
182036ed6475 cosmetic change only - fix code alignment.
mjsousa
parents: 834
diff changeset
   452
        if (get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype))
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   453
          s4o.print("!");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   454
        else
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   455
          s4o.print("~");
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   456
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   457
      wanted_variablegeneration = expression_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   458
      print_check_function(type, value, fb_value);
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   459
      if (type_is_complex) {
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   460
        s4o.print(",");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   461
        wanted_variablegeneration = complextype_suffix_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   462
        symbol->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   463
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   464
      s4o.print(")");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   465
      wanted_variablegeneration = expression_vg;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   466
      return NULL;
885
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   467
*/
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   468
      s4o.print(",");
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   469
      if (type_is_complex) {
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   470
        wanted_variablegeneration = complextype_suffix_vg;
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   471
        symbol->accept(*this);
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   472
      }
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   473
      s4o.print(",");
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   474
      if (negative) {
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   475
        if (get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype))
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   476
          s4o.print("!");
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   477
        else
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   478
          s4o.print("~");
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   479
      }
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   480
      wanted_variablegeneration = expression_vg;
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   481
      print_check_function(type, value, fb_value);
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   482
      s4o.print(")");
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   483
      wanted_variablegeneration = expression_vg;
b2604fc6d25c Change order of SET_xxx() macros. (this will allow me to simplify the print_setter() methods later on)
mjsousa
parents: 877
diff changeset
   484
      return NULL;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   485
    }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   486
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   487
public:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   488
void *visit(il_default_variable_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   489
  symbol->var_name->accept(*this);
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   490
  if (NULL != symbol->datatype) {
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   491
    s4o.print(".");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   492
    symbol->datatype->accept(*this);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   493
    s4o.print("var");
563
61410284a9b4 little typo in last commited code
Andreas Graeper <agraeper@googemail.com>
parents: 531
diff changeset
   494
  } return NULL;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   495
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   496
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   497
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   498
private:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   499
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
   500
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   501
377
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   502
/********************************/
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   503
/* B 1.3.3 - Derived data types */
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   504
/********************************/
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   505
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   506
/*  signed_integer DOTDOT signed_integer */
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   507
void *visit(subrange_c *symbol) {
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   508
  symbol->lower_limit->accept(*this);
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   509
  return NULL;
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   510
}
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   511
377
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   512
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   513
void *visit(array_specification_c *symbol) {
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   514
  symbol->non_generic_type_name->accept(*this);
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   515
  return NULL;
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   516
}
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   517
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   518
/*********************/
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   519
/* B 1.4 - Variables */
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   520
/*********************/
221
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 220
diff changeset
   521
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   522
void *visit(symbolic_variable_c *symbol) {
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   523
  unsigned int vartype;
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   524
  switch (wanted_variablegeneration) {
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   525
    case complextype_base_assignment_vg:
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   526
    case assignment_vg:
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   527
      this->print_variable_prefix();
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   528
      s4o.print(",");
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   529
      symbol->var_name->accept(*this);
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   530
      break;
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   531
    case complextype_base_vg:
221
c6aed7e5f070 Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents: 220
diff changeset
   532
      generate_c_base_c::visit(symbol);
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   533
      break;
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   534
    case complextype_suffix_vg:
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   535
      break;
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   536
    default:
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   537
      if (this->is_variable_prefix_null()) {
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   538
        vartype = search_var_instance_decl->get_vartype(symbol);
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   539
        if (wanted_variablegeneration == fparam_output_vg) {
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   540
          s4o.print("&(");
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   541
          generate_c_base_c::visit(symbol);
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   542
          s4o.print(")");
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   543
        }
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   544
        else {
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   545
          generate_c_base_c::visit(symbol);
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   546
        }
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   547
      }
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   548
      else
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   549
        print_getter(symbol);
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   550
      break;
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
   551
  }
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   552
  return NULL;
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   553
}
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   554
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   555
/********************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   556
/* B.1.4.1   Directly Represented Variables */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   557
/********************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   558
// direct_variable: direct_variable_token   {$$ = new direct_variable_c($1);};
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   559
void *visit(direct_variable_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   560
  TRACE("direct_variable_c");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   561
  /* Do not use print_token() as it will change everything into uppercase */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   562
  if (strlen(symbol->value) == 0) ERROR;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   563
  if (this->is_variable_prefix_null()) {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   564
    if (wanted_variablegeneration != fparam_output_vg)
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   565
      s4o.print("*(");
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   566
  }
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   567
  else {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   568
    switch (wanted_variablegeneration) {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   569
      case expression_vg:
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   570
        s4o.print(GET_LOCATED);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   571
        s4o.print("(");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   572
        break;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   573
      case fparam_output_vg:
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   574
        s4o.print(GET_LOCATED_BY_REF);
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   575
        s4o.print("(");
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   576
        break;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   577
      default:
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   578
        break;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   579
    }
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   580
  }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   581
  this->print_variable_prefix();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   582
  s4o.printlocation(symbol->value + 1);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   583
  if ((this->is_variable_prefix_null() && wanted_variablegeneration != fparam_output_vg) ||
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   584
      wanted_variablegeneration != assignment_vg)
146
eef5e62048c7 Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents: 123
diff changeset
   585
    s4o.print(")");
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   586
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   587
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   588
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   589
/*************************************/
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   590
/* B.1.4.2   Multi-element Variables */
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   591
/*************************************/
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   592
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   593
// SYM_REF2(structured_variable_c, record_variable, field_selector)
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   594
void *visit(structured_variable_c *symbol) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   595
  TRACE("structured_variable_c");
854
13d0b67de111 Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 852
diff changeset
   596
  bool type_is_complex = analyse_variable_c::is_complex_type(symbol->record_variable);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   597
  switch (wanted_variablegeneration) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   598
    case complextype_base_vg:
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   599
    case complextype_base_assignment_vg:
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   600
      symbol->record_variable->accept(*this);
410
c6486bd97392 Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents: 406
diff changeset
   601
      if (!type_is_complex) {
c6486bd97392 Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents: 406
diff changeset
   602
        s4o.print(".");
c6486bd97392 Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents: 406
diff changeset
   603
        symbol->field_selector->accept(*this);
c6486bd97392 Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents: 406
diff changeset
   604
      }
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   605
      break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   606
    case complextype_suffix_vg:
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   607
      symbol->record_variable->accept(*this);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   608
      if (type_is_complex) {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   609
        s4o.print(".");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   610
        symbol->field_selector->accept(*this);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   611
      }
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   612
      break;
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   613
    case assignment_vg:
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   614
      symbol->record_variable->accept(*this);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   615
      s4o.print(".");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   616
      symbol->field_selector->accept(*this);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   617
      break;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   618
    default:
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   619
      if (this->is_variable_prefix_null()) {
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   620
        symbol->record_variable->accept(*this);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   621
        s4o.print(".");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   622
        symbol->field_selector->accept(*this);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   623
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   624
      else
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   625
        print_getter(symbol);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   626
      break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   627
  }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   628
  return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   629
}
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   630
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   631
/*  subscripted_variable '[' subscript_list ']' */
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   632
//SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   633
void *visit(array_variable_c *symbol) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   634
  switch (wanted_variablegeneration) {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   635
    case complextype_base_vg:
392
9b88b8b6bccd Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents: 382
diff changeset
   636
    case complextype_base_assignment_vg:
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   637
      symbol->subscripted_variable->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   638
      break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   639
    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
   640
      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
   641
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 311
diff changeset
   642
      current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
238
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   643
      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
   644
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   645
      s4o.print(".table");
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   646
      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
   647
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   648
      current_array_type = NULL;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   649
      break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   650
    default:
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   651
      if (this->is_variable_prefix_null()) {
238
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   652
        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
   653
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 311
diff changeset
   654
        current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
238
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   655
        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
   656
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   657
        s4o.print(".table");
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   658
        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
   659
0919986a5c98 Bug when trying to get type of elements in a big complex structure fixed
laurent
parents: 237
diff changeset
   660
        current_array_type = NULL;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   661
      }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   662
      else
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   663
        print_getter(symbol);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   664
      break;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   665
  }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   666
  return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   667
}
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   668
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   669
/* subscript_list ',' subscript */
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   670
void *visit(subscript_list_c *symbol) {
377
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   671
  array_dimension_iterator_c* array_dimension_iterator = new array_dimension_iterator_c(current_array_type);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   672
  for (int i =  0; i < symbol->n; i++) {
377
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   673
    symbol_c* dimension = array_dimension_iterator->next();
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   674
    if (dimension == NULL) ERROR;
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   675
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   676
    s4o.print("[(");
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   677
    symbol->elements[i]->accept(*this);
377
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   678
    s4o.print(") - (");
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   679
    dimension->accept(*this);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   680
    s4o.print(")]");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   681
  }
377
60b012b7793f Adding support for compiling direct array specification inside variable declaration
laurent
parents: 355
diff changeset
   682
  delete array_dimension_iterator;
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   683
  return NULL;
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   684
}
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
   685
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   686
/******************************************/
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   687
/* B 1.4.3 - Declaration & Initialisation */
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   688
/******************************************/
237
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   689
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   690
/* helper symbol for structure_initialization */
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   691
/* structure_element_initialization_list ',' structure_element_initialization */
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   692
void *visit(structure_element_initialization_list_c *symbol) {
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   693
  generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o);
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   694
  structure_initialization->init_structure_default(this->current_param_type);
237
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   695
  structure_initialization->init_structure_values(symbol);
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   696
  delete structure_initialization;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   697
  return NULL;
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   698
}
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   699
237
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   700
/* helper symbol for array_initialization */
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   701
/* array_initial_elements_list ',' array_initial_elements */
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   702
void *visit(array_initial_elements_list_c *symbol) {
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   703
  generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o);
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   704
  array_initialization->init_array_size(this->current_param_type);
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   705
  array_initialization->init_array_values(symbol);
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   706
  delete array_initialization;
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   707
  return NULL;
cece842c7417 Adding support for using arrays in POU interface
laurent
parents: 236
diff changeset
   708
}
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   709
/****************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   710
/* B.2 - Language IL (Instruction List) */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   711
/****************************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   712
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   713
/***********************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   714
/* B 2.1 Instructions and Operands */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   715
/***********************************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   716
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   717
/*| instruction_list il_instruction */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   718
void *visit(instruction_list_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   719
  
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   720
  /* Declare the IL implicit variable, that will store the result of the IL operations... */
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   721
  declare_implicit_variable();
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   722
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   723
  /* Declare the backup to the IL implicit variable, that will store the result of the IL operations executed inside a parenthesis... */
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   724
  declare_implicit_variable_back();
877
c25346eac788 Insert #line directives in generated C code.
mjsousa
parents: 861
diff changeset
   725
  
c25346eac788 Insert #line directives in generated C code.
mjsousa
parents: 861
diff changeset
   726
  for(int i = 0; i < symbol->n; i++) {
c25346eac788 Insert #line directives in generated C code.
mjsousa
parents: 861
diff changeset
   727
    print_line_directive(symbol->elements[i]);
c25346eac788 Insert #line directives in generated C code.
mjsousa
parents: 861
diff changeset
   728
    s4o.print(s4o.indent_spaces);
c25346eac788 Insert #line directives in generated C code.
mjsousa
parents: 861
diff changeset
   729
    symbol->elements[i]->accept(*this);
c25346eac788 Insert #line directives in generated C code.
mjsousa
parents: 861
diff changeset
   730
    s4o.print(";\n");
c25346eac788 Insert #line directives in generated C code.
mjsousa
parents: 861
diff changeset
   731
  }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   732
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   733
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   734
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   735
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   736
/* | label ':' [il_incomplete_instruction] eol_list */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   737
// SYM_REF2(il_instruction_c, label, il_instruction)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   738
void *visit(il_instruction_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   739
  /* all previous IL instructions should have the same datatype (checked in stage3), so we get the datatype from the first previous IL instruction we find */
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   740
  implicit_variable_current.datatype = (symbol->prev_il_instruction.empty())? NULL : symbol->prev_il_instruction[0]->datatype;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   741
  implicit_variable_result .datatype = symbol->datatype;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   742
  
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   743
  if (NULL != symbol->label) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   744
    symbol->label->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   745
    s4o.print(":\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   746
    s4o.print(s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   747
  }
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   748
311
8fcea60029de Allow [EOL] after a label in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 309
diff changeset
   749
  if (NULL != symbol->il_instruction) {
8fcea60029de Allow [EOL] after a label in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 309
diff changeset
   750
    symbol->il_instruction->accept(*this);
8fcea60029de Allow [EOL] after a label in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 309
diff changeset
   751
  }  
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   752
  
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   753
  implicit_variable_result .datatype = NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   754
  implicit_variable_current.datatype = NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   755
  return NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   756
}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   757
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   758
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   759
/* | il_simple_operator [il_operand] */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   760
//SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   761
void *visit(il_simple_operation_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   762
  this->current_operand = symbol->il_operand;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   763
  symbol->il_simple_operator->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   764
  this->current_operand = NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   765
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   766
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   767
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   768
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   769
/* | function_name [il_operand_list] */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   770
// SYM_REF2(il_function_call_c, function_name, il_operand_list)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   771
void *visit(il_function_call_c *symbol) {
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   772
  symbol_c* function_type_prefix = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   773
  symbol_c* function_name = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   774
  symbol_c* function_type_suffix = NULL;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   775
  DECLARE_PARAM_LIST()
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   776
  
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   777
  function_call_param_iterator_c function_call_param_iterator(symbol);
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   778
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   779
  function_declaration_c *f_decl = (function_declaration_c *)symbol->called_function_declaration;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   780
  if (f_decl == NULL) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   781
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   782
  function_name = symbol->function_name;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   783
  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   784
  /* loop through each function parameter, find the value we should pass
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   785
   * to it, and then output the c equivalent...
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   786
   */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   787
  function_param_iterator_c fp_iterator(f_decl);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   788
  identifier_c *param_name;
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   789
    /* flag to remember whether we have already used the value stored in the implicit variable to pass to the first parameter */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   790
  bool used_defvar = false; 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   791
    /* flag to cirreclty handle calls to extensible standard functions (i.e. functions with variable number of input parameters) */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   792
  bool found_first_extensible_parameter = false;  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   793
  for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   794
    if (fp_iterator.is_extensible_param() && (!found_first_extensible_parameter)) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   795
      /* We are calling an extensible function. Before passing the extensible
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   796
       * parameters, we must add a dummy paramater value to tell the called
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   797
       * function how many extensible parameters we will be passing.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   798
       *
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   799
       * Note that stage 3 has already determined the number of extensible
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   800
       * paramters, and stored that info in the abstract syntax tree. We simply
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   801
       * re-use that value.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   802
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   803
      /* NOTE: we are not freeing the malloc'd memory. This is not really a bug.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   804
       *       Since we are writing a compiler, which runs to termination quickly,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   805
       *       we can consider this as just memory required for the compilation process
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   806
       *       that will be free'd when the program terminates.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   807
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   808
      char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   809
      if (tmp == NULL) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   810
      int res = snprintf(tmp, 32, "%d", symbol->extensible_param_count);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   811
      if ((res >= 32) || (res < 0)) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   812
      identifier_c *param_value = new identifier_c(tmp);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   813
      uint_type_name_c *param_type  = new uint_type_name_c();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   814
      identifier_c *param_name = new identifier_c("");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   815
      ADD_PARAM_LIST(param_name, param_value, param_type, function_param_iterator_c::direction_in)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   816
      found_first_extensible_parameter = true;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   817
    }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   818
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   819
    symbol_c *param_type = fp_iterator.param_type();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   820
    if (param_type == NULL) ERROR;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   821
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   822
    function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   823
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   824
    symbol_c *param_value = NULL;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   825
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   826
    /* Get the value from a foo(<param_name> = <param_value>) style call */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   827
    /* NOTE: Since the class il_function_call_c only references a non.formal function call,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   828
     * the following line of code is not required in this case. However, it doesn't
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   829
     * harm to leave it in, as in the case of a non-formal syntax function call,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   830
     * it will always return NULL.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   831
     * We leave it in in case we later decide to merge this part of the code together
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   832
     * with the function calling code in generate_c_st_c, which does require
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   833
     * the following line...
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   834
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   835
    if (param_value == NULL)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   836
      param_value = function_call_param_iterator.search_f(param_name);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   837
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   838
    /* if it is the first parameter in a non-formal function call (which is the
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   839
     * case being handled!), semantics specifies that we should
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   840
     * get the value off the IL implicit variable!
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   841
     *
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   842
     * However, if the parameter is an implicitly defined EN or ENO parameter, we should not
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   843
     * use the IL implicit variable as a source of data to pass to those parameters!
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   844
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   845
    if ((param_value == NULL) &&  (!used_defvar) && !fp_iterator.is_en_eno_param_implicit()) {
683
2d96a47a75b1 Code cleanup: get the datatype of each entity off symbol->datatype (set in stage3 datatype checking), instead of determining it again in stage4. (NOTE: handling of IL parenthesized expressions is not working! Will be fixed later.)
Mario de Sousa <msousa@fe.up.pt>
parents: 682
diff changeset
   846
      if (NULL == implicit_variable_current.datatype) ERROR;
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   847
      param_value = &this->implicit_variable_current;
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   848
      used_defvar = true;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   849
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   850
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   851
    /* Get the value from a foo(<param_value>) style call */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   852
    if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   853
      param_value = function_call_param_iterator.next_nf();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   854
    }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   855
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   856
    /* if no more parameter values in function call, and the current parameter
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   857
     * of the function declaration is an extensible parameter, we
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   858
     * have reached the end, and should simply jump out of the for loop.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   859
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   860
    if ((param_value == NULL) && (fp_iterator.is_extensible_param())) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   861
      break;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   862
    }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   863
    
844
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
   864
    /* We do not yet support embedded IL lists, so we abort the compiler if we find one */
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
   865
    /* Note that in IL function calls the syntax does not allow embeded IL lists, so this check is not necessary here! */
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
   866
    /*
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
   867
    {simple_instr_list_c *instruction_list = dynamic_cast<simple_instr_list_c *>(param_value);
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
   868
     if (NULL != instruction_list) STAGE4_ERROR(param_value, param_value, "The compiler does not yet support formal invocations in IL that contain embedded IL lists. Aborting!");
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
   869
    }
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
   870
    */
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
   871
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   872
    if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   873
      /* No value given for parameter, so we must use the default... */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   874
      /* First check whether default value specified in function declaration...*/
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   875
      param_value = fp_iterator.default_value();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   876
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   877
    
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   878
    ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction())
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   879
  } /* for(...) */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   880
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   881
  if (function_call_param_iterator.next_nf() != NULL) ERROR;
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
   882
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   883
  bool has_output_params = false;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   884
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   885
  if (!this->is_variable_prefix_null()) {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   886
    PARAM_LIST_ITERATOR() {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   887
      if ((PARAM_DIRECTION == function_param_iterator_c::direction_out ||
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   888
           PARAM_DIRECTION == function_param_iterator_c::direction_inout) &&
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   889
           PARAM_VALUE != NULL) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   890
        has_output_params = true;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   891
      }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   892
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   893
  }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   894
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   895
  /* Check whether we are calling an overloaded function! */
721
5dc33058e041 Fix counting bug in dsymbtable_c
Mario de Sousa <msousa@fe.up.pt>
parents: 693
diff changeset
   896
  /* (fdecl_mutiplicity > 1)  => calling overloaded function */
5dc33058e041 Fix counting bug in dsymbtable_c
Mario de Sousa <msousa@fe.up.pt>
parents: 693
diff changeset
   897
  int fdecl_mutiplicity =  function_symtable.count(symbol->function_name);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   898
  if (fdecl_mutiplicity == 0) ERROR;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   899
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
   900
  this->implicit_variable_result.accept(*this);
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   901
  s4o.print(" = ");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   902
    
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   903
  if (function_type_prefix != NULL) {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   904
    s4o.print("(");
669
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   905
    default_literal_type(function_type_prefix)->accept(*this);
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   906
    s4o.print(")");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   907
  }
336
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   908
  if (function_type_suffix != NULL) {
793
268bf4ca5fa1 grand merge
Mario de Sousa <msousa@fe.up.pt>
parents: 762 706
diff changeset
   909
    function_type_suffix = default_literal_type(function_type_suffix);
336
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
   910
  }
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   911
  if (has_output_params) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   912
    fcall_number++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   913
    s4o.print("__");
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   914
    fbname->accept(*this);
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   915
    s4o.print("_");
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   916
    function_name->accept(*this);
721
5dc33058e041 Fix counting bug in dsymbtable_c
Mario de Sousa <msousa@fe.up.pt>
parents: 693
diff changeset
   917
    if (fdecl_mutiplicity > 1) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   918
      /* function being called is overloaded! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   919
      s4o.print("__");
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 405
diff changeset
   920
      print_function_parameter_data_types_c overloaded_func_suf(&s4o);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   921
      f_decl->accept(overloaded_func_suf);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   922
    }
594
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 563
diff changeset
   923
    s4o.print(fcall_number);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   924
  }
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   925
  else {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   926
    if (function_name != NULL) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   927
          function_name->accept(*this);
721
5dc33058e041 Fix counting bug in dsymbtable_c
Mario de Sousa <msousa@fe.up.pt>
parents: 693
diff changeset
   928
          if (fdecl_mutiplicity > 1) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   929
            /* function being called is overloaded! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   930
            s4o.print("__");
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 405
diff changeset
   931
            print_function_parameter_data_types_c overloaded_func_suf(&s4o);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   932
            f_decl->accept(overloaded_func_suf);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   933
          }
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
   934
    }
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   935
    if (function_type_suffix != NULL)
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   936
      function_type_suffix->accept(*this);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   937
  }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   938
  s4o.print("(");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   939
  s4o.indent_right();
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   940
  
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   941
  int nb_param = 0;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   942
  PARAM_LIST_ITERATOR() {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   943
    symbol_c *param_value = PARAM_VALUE;
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   944
    current_param_type = PARAM_TYPE;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   945
    
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   946
    switch (PARAM_DIRECTION) {
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   947
      case function_param_iterator_c::direction_in:
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   948
        if (nb_param > 0)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   949
          s4o.print(",\n"+s4o.indent_spaces);
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   950
        if (param_value == NULL) {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   951
          /* If not, get the default value of this variable's type */
762
a3d917474ae4 Small code cleanup.
Mario de Sousa <msousa@fe.up.pt>
parents: 721
diff changeset
   952
          param_value = type_initial_value_c::get(current_param_type);
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   953
        }
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   954
        if (param_value == NULL) ERROR;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   955
        s4o.print("(");
669
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   956
        if (get_datatype_info_c::is_ANY_INT_literal(current_param_type))
693
51a2fa6441b9 Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 690
diff changeset
   957
          get_datatype_info_c::lint_type_name.accept(*this);
669
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
   958
        else if (get_datatype_info_c::is_ANY_REAL_literal(current_param_type))
693
51a2fa6441b9 Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 690
diff changeset
   959
          get_datatype_info_c::lreal_type_name.accept(*this);
220
f332b62cd2c1 Bug with ULINT correction fixed
laurent
parents: 217
diff changeset
   960
        else
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   961
          current_param_type->accept(*this);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   962
        s4o.print(")");
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
   963
        print_check_function(current_param_type, param_value);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   964
        nb_param++;
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   965
        break;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   966
      case function_param_iterator_c::direction_out:
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   967
      case function_param_iterator_c::direction_inout:
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   968
        if (!has_output_params) {
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   969
          if (nb_param > 0)
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   970
            s4o.print(",\n"+s4o.indent_spaces);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   971
            if (param_value == NULL) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   972
              s4o.print("NULL");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   973
            } else {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   974
              wanted_variablegeneration = fparam_output_vg;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   975
              param_value->accept(*this);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   976
              wanted_variablegeneration = expression_vg;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   977
            }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   978
          nb_param++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   979
        }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   980
        break;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   981
      case function_param_iterator_c::direction_extref:
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   982
        /* TODO! */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   983
        ERROR;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   984
        break;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   985
    } /* switch */
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   986
  }
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   987
  if (has_output_params) {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   988
    if (nb_param > 0)
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
   989
      s4o.print(",\n"+s4o.indent_spaces);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   990
    s4o.print(FB_FUNCTION_PARAM);
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   991
  }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   992
  
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
   993
  s4o.print(")");
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   994
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   995
  CLEAR_PARAM_LIST()
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
   996
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   997
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   998
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
   999
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1000
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1001
/* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1002
//SYM_REF4(il_expression_c, il_expr_operator, il_operand, simple_instr_list, unused)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1003
void *visit(il_expression_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1004
  LD_operator_c           *tmp_LD_operator           = NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1005
  il_simple_operation_c   *tmp_il_simple_operation   = NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1006
  il_simple_instruction_c *tmp_il_simple_instruction = NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1007
  
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1008
  /* We will be recursevely interpreting an instruction list, so we store a backup of the implicit_variable_result/current.
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1009
   * Notice that they will be overwriten while processing the parenthsized instruction list.
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1010
   */
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1011
  il_default_variable_c old_implicit_variable_current = this->implicit_variable_current;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1012
  il_default_variable_c old_implicit_variable_result  = this->implicit_variable_result;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1013
690
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 687
diff changeset
  1014
  /* Stage2 will insert an artificial (and equivalent) LD <il_operand> to the simple_instr_list if necessary. We can therefore ignore the 'il_operand' entry! */
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 687
diff changeset
  1015
  //if (NULL != symbol->il_operand) { do nothing!! }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1016
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1017
  /* Now do the parenthesised instructions... */
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1018
  /* NOTE: the following code line will overwrite the variables implicit_variable_current and implicit_variable_result */
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1019
  symbol->simple_instr_list->accept(*this);
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1020
  
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1021
  /* Now do the operation, using the previous result! */
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1022
  /* NOTE: The result of the previous instruction list in the parenthesis will be stored
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1023
   * in a variable named IL_DEFVAR_BACK. This is done in the visitor
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1024
   * to instruction_list_c objects...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1025
   */
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1026
  this->implicit_variable_result_back.datatype = symbol->simple_instr_list->datatype;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1027
  this->current_operand = &(this->implicit_variable_result_back);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1028
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1029
  this->implicit_variable_current = old_implicit_variable_current;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1030
  this->implicit_variable_result  = old_implicit_variable_result;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1031
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1032
  symbol->il_expr_operator->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1033
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1034
  this->current_operand = NULL;
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1035
  this->implicit_variable_result_back.datatype = NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1036
  return NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1037
}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1038
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1039
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1040
/*  il_jump_operator label */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1041
// SYM_REF2(il_jump_operation_c, il_jump_operator, label)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1042
void *visit(il_jump_operation_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1043
 /* Pass the symbol->label to the il_jump_operation visitor using the jump_label parameter... */
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1044
  this->jump_label = symbol->label;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1045
  symbol->il_jump_operator->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1046
  this->jump_label = NULL;
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1047
  return NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1048
}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1049
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1050
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1051
/*   il_call_operator prev_declared_fb_name
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1052
 * | il_call_operator prev_declared_fb_name '(' ')'
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1053
 * | il_call_operator prev_declared_fb_name '(' eol_list ')'
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1054
 * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1055
 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1056
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1057
// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1058
void *visit(il_fb_call_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1059
  symbol->il_call_operator->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1060
  s4o.print("{\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1061
  s4o.indent_right();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1062
  s4o.print(s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1063
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1064
  /* first figure out what is the name of the function block type of the function block being called... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1065
  symbol_c *function_block_type_name = this->search_fb_instance_decl->get_type_name(symbol->fb_name);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1066
    /* should never occur. The function block instance MUST have been declared... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1067
  if (function_block_type_name == NULL) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1068
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1069
  /* Now find the declaration of the function block type being called... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1070
  function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(function_block_type_name);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1071
    /* should never occur. The function block type being called MUST be in the symtable... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1072
  if (fb_decl == function_block_type_symtable.end_value()) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1073
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1074
  /* loop through each function block parameter, find the value we should pass
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1075
   * to it, and then output the c equivalent...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1076
   */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1077
  function_param_iterator_c fp_iterator(fb_decl);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1078
  identifier_c *param_name;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1079
  function_call_param_iterator_c function_call_param_iterator(symbol);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1080
  for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1081
    function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1082
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1083
    /* Get the value from a foo(<param_name> = <param_value>) style call */
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
  1084
    symbol_c *param_value = function_call_param_iterator.search_f(param_name);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1085
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1086
    /* Get the value from a foo(<param_value>) style call */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1087
    /* When using the informal invocation style, user can not pass values to EN or ENO parameters if these
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1088
     * were implicitly defined!
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1089
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1090
    if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit())
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
  1091
      param_value = function_call_param_iterator.next_nf();
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1092
844
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
  1093
    /* We do not yet support embedded IL lists, so we abort the compiler if we find one */
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
  1094
    {simple_instr_list_c *instruction_list = dynamic_cast<simple_instr_list_c *>(param_value);
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
  1095
     if (NULL != instruction_list) STAGE4_ERROR(param_value, param_value, "The compiler does not yet support formal invocations in IL that contain embedded IL lists. Aborting!");
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
  1096
    }
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
  1097
    
98
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
  1098
    symbol_c *param_type = fp_iterator.param_type();
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
  1099
    if (param_type == NULL) ERROR;
d0cdf1d00b74 Adding support for derived data types.
lbessard
parents: 70
diff changeset
  1100
    
123
a9b4af71cfa4 Fixed some issues on:
lbessard
parents: 98
diff changeset
  1101
        /* now output the value assignment */
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1102
    if (param_value != NULL)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1103
      if ((param_direction == function_param_iterator_c::direction_in) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1104
          (param_direction == function_param_iterator_c::direction_inout)) {
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1105
        if (this->is_variable_prefix_null()) {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1106
          symbol->fb_name->accept(*this);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1107
          s4o.print(".");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1108
          param_name->accept(*this);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1109
          s4o.print(" = ");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1110
          print_check_function(param_type, param_value);
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1111
        }
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1112
        else {
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1113
          print_setter(param_name, param_type, param_value, symbol->fb_name);
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1114
        }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1115
        s4o.print(";\n" + s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1116
      }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1117
  } /* for(...) */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1118
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1119
  /* now call the function... */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1120
  function_block_type_name->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1121
  s4o.print(FB_FUNCTION_SUFFIX);
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1122
  s4o.print("(");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1123
  if (search_var_instance_decl->get_vartype(symbol->fb_name) != search_var_instance_decl_c::external_vt)
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1124
    s4o.print("&");
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1125
  print_variable_prefix();
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1126
  symbol->fb_name->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1127
  s4o.print(")");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1128
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1129
  /* loop through each function parameter, find the variable to which
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1130
   * we should atribute the value of all output or inoutput parameters.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1131
   */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1132
  fp_iterator.reset();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1133
  function_call_param_iterator.reset();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1134
  for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1135
    function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1136
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1137
    /* Get the value from a foo(<param_name> = <param_value>) style call */
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
  1138
    symbol_c *param_value = function_call_param_iterator.search_f(param_name);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1139
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1140
    /* Get the value from a foo(<param_value>) style call */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1141
    /* When using the informal invocation style, user can not pass values to EN or ENO parameters if these
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1142
     * were implicitly defined!
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1143
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1144
    if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit())
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 201
diff changeset
  1145
      param_value = function_call_param_iterator.next_nf();
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1146
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1147
    /* now output the value assignment */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1148
    if (param_value != NULL)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1149
      if ((param_direction == function_param_iterator_c::direction_out) ||
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1150
          (param_direction == function_param_iterator_c::direction_inout)) {
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 311
diff changeset
  1151
        symbol_c *param_type = search_varfb_instance_type->get_type_id(param_value);
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1152
        s4o.print(";\n" + s4o.indent_spaces);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1153
        if (this->is_variable_prefix_null()) {
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1154
          param_value->accept(*this);
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1155
          s4o.print(" = ");
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1156
          print_check_function(param_type, param_name, symbol->fb_name);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1157
        }
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1158
        else {
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1159
          print_setter(param_value, param_type, param_name, NULL, symbol->fb_name);
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1160
        }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1161
      }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1162
  } /* for(...) */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1163
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1164
  s4o.print(";\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1165
  s4o.indent_left();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1166
  s4o.print(s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1167
  s4o.print("}");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1168
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1169
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1170
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1171
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1172
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1173
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1174
/* | function_name '(' eol_list [il_param_list] ')' */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1175
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1176
void *visit(il_formal_funct_call_c *symbol) {
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1177
  symbol_c* function_type_prefix = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1178
  symbol_c* function_name = NULL;
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1179
  symbol_c* function_type_suffix = NULL;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1180
  DECLARE_PARAM_LIST()
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1181
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
  1182
  function_call_param_iterator_c function_call_param_iterator(symbol);
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
  1183
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1184
  function_declaration_c *f_decl = (function_declaration_c *)symbol->called_function_declaration;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1185
  if (f_decl == NULL) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1186
        
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1187
  function_name = symbol->function_name;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1188
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1189
  /* loop through each function parameter, find the value we should pass
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1190
   * to it, and then output the c equivalent...
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1191
   */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1192
  function_param_iterator_c fp_iterator(f_decl);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1193
  identifier_c *param_name;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1194
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1195
    /* flag to cirreclty handle calls to extensible standard functions (i.e. functions with variable number of input parameters) */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1196
  bool found_first_extensible_parameter = false;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1197
  for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1198
    if (fp_iterator.is_extensible_param() && (!found_first_extensible_parameter)) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1199
      /* We are calling an extensible function. Before passing the extensible
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1200
       * parameters, we must add a dummy paramater value to tell the called
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1201
       * function how many extensible parameters we will be passing.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1202
       *
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1203
       * Note that stage 3 has already determined the number of extensible
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1204
       * paramters, and stored that info in the abstract syntax tree. We simply
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1205
       * re-use that value.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1206
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1207
      /* NOTE: we are not freeing the malloc'd memory. This is not really a bug.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1208
       *       Since we are writing a compiler, which runs to termination quickly,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1209
       *       we can consider this as just memory required for the compilation process
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1210
       *       that will be free'd when the program terminates.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1211
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1212
      char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1213
      if (tmp == NULL) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1214
      int res = snprintf(tmp, 32, "%d", symbol->extensible_param_count);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1215
      if ((res >= 32) || (res < 0)) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1216
      identifier_c *param_value = new identifier_c(tmp);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1217
      uint_type_name_c *param_type  = new uint_type_name_c();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1218
      identifier_c *param_name = new identifier_c("");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1219
      ADD_PARAM_LIST(param_name, param_value, param_type, function_param_iterator_c::direction_in)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1220
      found_first_extensible_parameter = true;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1221
    }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1222
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1223
    if (fp_iterator.is_extensible_param()) {      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1224
      /* since we are handling an extensible parameter, we must add the index to the
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1225
       * parameter name so we can go looking for the value passed to the correct
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1226
       * extended parameter (e.g. IN1, IN2, IN3, IN4, ...)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1227
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1228
      char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1229
      int res = snprintf(tmp, 32, "%d", fp_iterator.extensible_param_index());
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1230
      if ((res >= 32) || (res < 0)) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1231
      param_name = new identifier_c(strdup2(param_name->value, tmp));
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1232
      if (param_name->value == NULL) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1233
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1234
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1235
    symbol_c *param_type = fp_iterator.param_type();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1236
    if (param_type == NULL) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1237
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1238
    function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1239
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1240
    symbol_c *param_value = NULL;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1241
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1242
    /* Get the value from a foo(<param_name> = <param_value>) style call */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1243
    if (param_value == NULL)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1244
      param_value = function_call_param_iterator.search_f(param_name);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1245
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1246
    /* Get the value from a foo(<param_value>) style call */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1247
    /* NOTE: the following line of code is not required in this case, but it doesn't
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1248
     * harm to leave it in, as in the case of a formal syntax function call,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1249
     * it will always return NULL.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1250
     * We leave it in in case we later decide to merge this part of the code together
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1251
     * with the function calling code in generate_c_st_c, which does require
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1252
     * the following line...
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1253
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1254
    if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1255
      param_value = function_call_param_iterator.next_nf();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1256
    }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1257
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1258
    /* if no more parameter values in function call, and the current parameter
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1259
     * of the function declaration is an extensible parameter, we
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1260
     * have reached the end, and should simply jump out of the for loop.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1261
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1262
    if ((param_value == NULL) && (fp_iterator.is_extensible_param())) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1263
      break;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1264
    }
169
bea932bc60b0 Bug when function with unconnected input fixed
lbessard
parents: 149
diff changeset
  1265
    
844
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
  1266
    /* We do not yet support embedded IL lists, so we abort the compiler if we find one */
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
  1267
    {simple_instr_list_c *instruction_list = dynamic_cast<simple_instr_list_c *>(param_value);
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
  1268
     if (NULL != instruction_list) STAGE4_ERROR(param_value, param_value, "The compiler does not yet support formal invocations in IL that contain embedded IL lists. Aborting!");
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
  1269
    }
39c755f41ee8 Generate correct error message when encountering IL lists embedded in IL formal invocations.
mjsousa
parents: 842
diff changeset
  1270
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1271
    if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1272
      /* No value given for parameter, so we must use the default... */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1273
      /* First check whether default value specified in function declaration...*/
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1274
      param_value = fp_iterator.default_value();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1275
    }
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1276
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1277
    ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction())
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1278
  }
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1279
  
233
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
  1280
  if (function_call_param_iterator.next_nf() != NULL) ERROR;
3d23a68183d3 Bug on standard functions called with literals fixed
laurent
parents: 231
diff changeset
  1281
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1282
  bool has_output_params = false;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1283
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1284
  if (!this->is_variable_prefix_null()) {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1285
    PARAM_LIST_ITERATOR() {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1286
      if ((PARAM_DIRECTION == function_param_iterator_c::direction_out ||
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1287
           PARAM_DIRECTION == function_param_iterator_c::direction_inout) &&
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1288
           PARAM_VALUE != NULL) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1289
        has_output_params = true;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1290
      }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1291
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1292
  }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1293
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1294
  /* Check whether we are calling an overloaded function! */
721
5dc33058e041 Fix counting bug in dsymbtable_c
Mario de Sousa <msousa@fe.up.pt>
parents: 693
diff changeset
  1295
  /* (fdecl_mutiplicity > 1)  => calling overloaded function */
5dc33058e041 Fix counting bug in dsymbtable_c
Mario de Sousa <msousa@fe.up.pt>
parents: 693
diff changeset
  1296
  int fdecl_mutiplicity =  function_symtable.count(symbol->function_name);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1297
  if (fdecl_mutiplicity == 0) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1298
  if (fdecl_mutiplicity == 1) 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1299
    /* function being called is NOT overloaded! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1300
    f_decl = NULL; 
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1301
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1302
  this->implicit_variable_result.accept(*this);
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1303
  s4o.print(" = ");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1304
  
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1305
  if (function_type_prefix != NULL) {
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1306
    s4o.print("(");
669
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
  1307
    default_literal_type(function_type_prefix)->accept(*this);
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1308
    s4o.print(")");
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1309
  }
336
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
  1310
  if (function_type_suffix != NULL) {
793
268bf4ca5fa1 grand merge
Mario de Sousa <msousa@fe.up.pt>
parents: 762 706
diff changeset
  1311
    function_type_suffix = default_literal_type(function_type_suffix);
336
229eb3e29216 Fix bug in function calls with literal parameters
laurent
parents: 321
diff changeset
  1312
  }
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1313
  if (has_output_params) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1314
    fcall_number++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1315
    s4o.print("__");
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1316
    fbname->accept(*this);
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1317
    s4o.print("_");
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1318
    function_name->accept(*this);
721
5dc33058e041 Fix counting bug in dsymbtable_c
Mario de Sousa <msousa@fe.up.pt>
parents: 693
diff changeset
  1319
    if (fdecl_mutiplicity > 1) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1320
      /* function being called is overloaded! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1321
      s4o.print("__");
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 405
diff changeset
  1322
      print_function_parameter_data_types_c overloaded_func_suf(&s4o);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1323
      f_decl->accept(overloaded_func_suf);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1324
    }
594
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 563
diff changeset
  1325
    s4o.print(fcall_number);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1326
  }
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1327
  else {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1328
    if (function_name != NULL) {
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1329
      function_name->accept(*this);
721
5dc33058e041 Fix counting bug in dsymbtable_c
Mario de Sousa <msousa@fe.up.pt>
parents: 693
diff changeset
  1330
      if (fdecl_mutiplicity > 1) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1331
        /* function being called is overloaded! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1332
        s4o.print("__");
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 405
diff changeset
  1333
        print_function_parameter_data_types_c overloaded_func_suf(&s4o);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1334
        f_decl->accept(overloaded_func_suf);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1335
      }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1336
    }  
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1337
    if (function_type_suffix != NULL)
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1338
      function_type_suffix->accept(*this);
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1339
  }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1340
  s4o.print("(");
149
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1341
  s4o.indent_right();
05ca171a3d57 Adding support for EN/ENO in standard functions
lbessard
parents: 146
diff changeset
  1342
  
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1343
  int nb_param = 0;
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1344
  PARAM_LIST_ITERATOR() {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1345
    symbol_c *param_value = PARAM_VALUE;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1346
    current_param_type = PARAM_TYPE;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1347
    switch (PARAM_DIRECTION) {
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1348
      case function_param_iterator_c::direction_in:
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1349
        if (nb_param > 0)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1350
          s4o.print(",\n"+s4o.indent_spaces);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1351
        if (param_value == NULL) {
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1352
          /* If not, get the default value of this variable's type */
762
a3d917474ae4 Small code cleanup.
Mario de Sousa <msousa@fe.up.pt>
parents: 721
diff changeset
  1353
          param_value = type_initial_value_c::get(current_param_type);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1354
        }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1355
        if (param_value == NULL) ERROR;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1356
        s4o.print("(");
693
51a2fa6441b9 Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 690
diff changeset
  1357
        if      (get_datatype_info_c::is_ANY_INT_literal(current_param_type))
51a2fa6441b9 Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 690
diff changeset
  1358
                 get_datatype_info_c::lint_type_name.accept(*this);
669
7049fd6fe515 Deprecate use of search_expression_type_c (prepare for complete removal!)
Mario de Sousa <msousa@fe.up.pt>
parents: 667
diff changeset
  1359
        else if (get_datatype_info_c::is_ANY_REAL_literal(current_param_type))
693
51a2fa6441b9 Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 690
diff changeset
  1360
                 get_datatype_info_c::lreal_type_name.accept(*this);
220
f332b62cd2c1 Bug with ULINT correction fixed
laurent
parents: 217
diff changeset
  1361
        else
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
  1362
          current_param_type->accept(*this);
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1363
        s4o.print(")");
235
ed66dc50f31a Bug on generate_c_inlinefcall fixed
laurent
parents: 233
diff changeset
  1364
        print_check_function(current_param_type, param_value);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1365
        nb_param++;
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1366
        break;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1367
      case function_param_iterator_c::direction_out:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1368
      case function_param_iterator_c::direction_inout:
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1369
        if (!has_output_params) {
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1370
          if (nb_param > 0)
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1371
            s4o.print(",\n"+s4o.indent_spaces);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1372
          if (param_value == NULL) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1373
            s4o.print("NULL");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1374
          } else {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1375
            wanted_variablegeneration = fparam_output_vg;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1376
            param_value->accept(*this);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1377
            wanted_variablegeneration = expression_vg;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1378
          }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1379
        }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1380
        break;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1381
      case function_param_iterator_c::direction_extref:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1382
        /* TODO! */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1383
        ERROR;
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 336
diff changeset
  1384
        break;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1385
    } /* switch */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1386
  } /* for(...) */
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1387
  if (has_output_params) {
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1388
    if (nb_param > 0)
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1389
      s4o.print(",\n"+s4o.indent_spaces);
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1390
    s4o.print(FB_FUNCTION_PARAM);
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1391
  }
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1392
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1393
  // symbol->parameter_assignment->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1394
  s4o.print(")");
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1395
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1396
  CLEAR_PARAM_LIST()
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1397
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1398
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1399
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1400
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1401
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1402
/* | il_operand_list ',' il_operand */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1403
// SYM_LIST(il_operand_list_c)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1404
void *visit(il_operand_list_c *symbol) {ERROR; return NULL;} // should never get called!
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1405
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1406
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1407
/* | simple_instr_list il_simple_instruction */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1408
// SYM_LIST(simple_instr_list_c)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1409
void *visit(simple_instr_list_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1410
  /* A simple_instr_list_c is used to store a list of il operations being done within parenthesis...
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1411
   *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1412
   * e.g.:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1413
   *         LD var1
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1414
   *         AND ( var2
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1415
   *         OR var3
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1416
   *         OR var4
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1417
   *         )
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1418
   *
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1419
   * NOTE 1:
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1420
   * This will be converted to C++ by defining a new scope
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1421
   * with a new il implicit variable, and executing the il operands
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1422
   * within this new scope.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1423
   * At the end of the scope the result, i.e. the value currently stored
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1424
   * in the il implicit variable is copied to the variable used to take this
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1425
   * value to the outside scope...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1426
   *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1427
   * The above example will result in the following C++ code:
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1428
   * {__IL_DEFVAR_T __IL_DEFVAR_BACK;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1429
   *  __IL_DEFVAR_T __IL_DEFVAR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1430
   *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1431
   *  __IL_DEFVAR.INTvar = var1;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1432
   *  {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1433
   *    __IL_DEFVAR_T __IL_DEFVAR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1434
   *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1435
   *    __IL_DEFVAR.INTvar = var2;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1436
   *    __IL_DEFVAR.INTvar |= var3;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1437
   *    __IL_DEFVAR.INTvar |= var4;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1438
   *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1439
   *    __IL_DEFVAR_BACK = __IL_DEFVAR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1440
   *  }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1441
   *  __IL_DEFVAR.INTvar &= __IL_DEFVAR_BACK.INTvar;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1442
   *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1443
   * }
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1444
   *
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1445
   * NOTE 2:
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1446
   *  If the intial value of the il implicit variable (in the above
690
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 687
diff changeset
  1447
   * example 'var2') exists, then stage2 will insert an equivalent
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 687
diff changeset
  1448
   * LD operation into the parenthesized instruction list. This means we do not
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1449
   * need to do anything here to handle this special situation!
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1450
   */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1451
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1452
  /* Declare the IL implicit variable, that will store the result of the IL operations... */
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1453
  s4o.print("{\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1454
  s4o.indent_right();
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1455
  declare_implicit_variable();
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1456
    
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1457
  print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1458
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1459
  /* copy the result in the IL implicit variable to the variable
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1460
   * used to pass the data out to the scope enclosing the current scope!
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1461
   */
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1462
  this->implicit_variable_result_back.datatype = symbol->datatype;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1463
  this->implicit_variable_result     .datatype = symbol->datatype;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1464
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1465
  s4o.print("\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1466
  s4o.print(s4o.indent_spaces);
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1467
  this->implicit_variable_result_back.accept(*this);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1468
  s4o.print(" = ");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1469
  this->implicit_variable_result.accept(*this);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1470
  s4o.print(";\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1471
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1472
  s4o.indent_left();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1473
  s4o.print(s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1474
  s4o.print("}\n");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1475
  s4o.print(s4o.indent_spaces);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1476
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1477
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1478
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1479
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 392
diff changeset
  1480
// SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;)
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1481
void *visit(il_simple_instruction_c *symbol) {
687
81dcb3987cbb Fix handling of IL parenthesized expressions in generate_c_il_c
Mario de Sousa <msousa@fe.up.pt>
parents: 683
diff changeset
  1482
  /* all previous IL instructions should have the same datatype (checked in stage3), so we get the datatype from the first previous IL instruction we find */
81dcb3987cbb Fix handling of IL parenthesized expressions in generate_c_il_c
Mario de Sousa <msousa@fe.up.pt>
parents: 683
diff changeset
  1483
  implicit_variable_current.datatype = (symbol->prev_il_instruction.empty())? NULL : symbol->prev_il_instruction[0]->datatype;
81dcb3987cbb Fix handling of IL parenthesized expressions in generate_c_il_c
Mario de Sousa <msousa@fe.up.pt>
parents: 683
diff changeset
  1484
  implicit_variable_result .datatype = symbol->datatype;
81dcb3987cbb Fix handling of IL parenthesized expressions in generate_c_il_c
Mario de Sousa <msousa@fe.up.pt>
parents: 683
diff changeset
  1485
  
81dcb3987cbb Fix handling of IL parenthesized expressions in generate_c_il_c
Mario de Sousa <msousa@fe.up.pt>
parents: 683
diff changeset
  1486
  symbol->il_simple_instruction->accept(*this);
81dcb3987cbb Fix handling of IL parenthesized expressions in generate_c_il_c
Mario de Sousa <msousa@fe.up.pt>
parents: 683
diff changeset
  1487
  
81dcb3987cbb Fix handling of IL parenthesized expressions in generate_c_il_c
Mario de Sousa <msousa@fe.up.pt>
parents: 683
diff changeset
  1488
  implicit_variable_result .datatype = NULL;
81dcb3987cbb Fix handling of IL parenthesized expressions in generate_c_il_c
Mario de Sousa <msousa@fe.up.pt>
parents: 683
diff changeset
  1489
  implicit_variable_current.datatype = NULL;
81dcb3987cbb Fix handling of IL parenthesized expressions in generate_c_il_c
Mario de Sousa <msousa@fe.up.pt>
parents: 683
diff changeset
  1490
  return NULL;
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 392
diff changeset
  1491
}
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 392
diff changeset
  1492
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 392
diff changeset
  1493
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1494
/* | il_initial_param_list il_param_instruction */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1495
// SYM_LIST(il_param_list_c)
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1496
void *visit(il_param_list_c *symbol)            {ERROR; return NULL;} // should never get called!
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1497
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1498
/*  il_assign_operator il_operand
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1499
 * | il_assign_operator '(' eol_list simple_instr_list ')'
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1500
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1501
// SYM_REF4(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list, unused)
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1502
void *visit(il_param_assignment_c *symbol)      {ERROR; return NULL;} // should never get called!
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1503
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1504
/*  il_assign_out_operator variable */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1505
// SYM_REF2(il_param_out_assignment_c, il_assign_out_operator, variable);
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1506
void *visit(il_param_out_assignment_c *symbol)  {ERROR; return NULL;} // should never get called!
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1507
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1508
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1509
/*******************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1510
/* B 2.2 Operators */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1511
/*******************/
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1512
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1513
void *visit(LD_operator_c *symbol) {
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1514
  if (wanted_variablegeneration != expression_vg) {
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1515
    s4o.print("LD");
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1516
    return NULL;
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1517
  }
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1518
  XXX_operator(&(this->implicit_variable_result), " = ", this->current_operand);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1519
  return NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1520
}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1521
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1522
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1523
void *visit(LDN_operator_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1524
  XXX_operator(&(this->implicit_variable_result), get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype)?" = !":" = ~", this->current_operand);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1525
  return NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1526
}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1527
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1528
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1529
void *visit(ST_operator_c *symbol) {
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1530
  if (this->is_variable_prefix_null()) {
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1531
    this->current_operand->accept(*this);
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1532
    s4o.print(" = ");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1533
    print_check_function(this->current_operand->datatype, (symbol_c*)&(this->implicit_variable_current));
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1534
  }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1535
  else {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1536
    print_setter(this->current_operand, this->current_operand->datatype, (symbol_c*)&(this->implicit_variable_current));
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1537
  }
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1538
  return NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1539
}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1540
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1541
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1542
void *visit(STN_operator_c *symbol) {
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1543
  if (this->is_variable_prefix_null()) {
217
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1544
    this->current_operand->accept(*this);
f5dfadf5de54 Adding support for declare, init, get and set macros
laurent
parents: 216
diff changeset
  1545
    s4o.print(" = ");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1546
    if (get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype))
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1547
      s4o.print("!");
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1548
    else
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1549
      s4o.print("~");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1550
    this->implicit_variable_current.accept(*this);
228
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1551
  }
43831b683764 Adding support for setter and getter on complex datatype in IL
berem
parents: 226
diff changeset
  1552
  else {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1553
    print_setter(this->current_operand, this->current_operand->datatype, (symbol_c*)&(this->implicit_variable_current), NULL, NULL, true);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1554
  }
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1555
  return NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1556
}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1557
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1558
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1559
void *visit(NOT_operator_c *symbol) {
470
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
  1560
  /* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
  1561
   *              NOT [<il_operand>]
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
  1562
   *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
  1563
   *       We therefore consider it an error if an il_operand is specified!
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
  1564
   *       The error is caught in stage 3!
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
  1565
   */  
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1566
  if (NULL != this->current_operand) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1567
  XXX_operator(&(this->implicit_variable_result), get_datatype_info_c::is_BOOL_compatible(symbol->datatype)?" = !":" = ~", &(this->implicit_variable_current));
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1568
  return NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1569
}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1570
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1571
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1572
void *visit(S_operator_c *symbol) {
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1573
  /* This operator must implement one of two possible semantics: 
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1574
   *     - FB call
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1575
   *     - Set all the bits of an ANY_BIT type variable to 1
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1576
   */
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1577
  
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1578
  /* Check whether we must implement the FB call semantics... */
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1579
  if (NULL != symbol->called_fb_declaration)
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1580
    return XXX_CAL_operator( "S", this->current_operand);
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1581
  
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1582
  /* Implement the bit setting semantics... */
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1583
  if (wanted_variablegeneration != expression_vg) {
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1584
    s4o.print("LD");
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1585
    return NULL;
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1586
  }
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1587
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1588
  if ((NULL == this->current_operand) || (NULL == this->current_operand->datatype)) ERROR;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1589
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1590
  C_modifier();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1591
  this->current_operand->accept(*this);
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1592
  s4o.print(" = __");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1593
  if        (get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype)) {
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1594
    s4o.print("BOOL_LITERAL(TRUE)");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1595
  } else if (get_datatype_info_c::is_ANY_INT_compatible(this->current_operand->datatype)) {
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1596
    this->current_operand->datatype->accept(*this);
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1597
    s4o.print("_LITERAL(1)");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1598
  } else
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1599
    ERROR;
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1600
  return NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1601
}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1602
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1603
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1604
void *visit(R_operator_c *symbol) {
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1605
  /* This operator must implement one of two possible semantics: 
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1606
   *     - FB call
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1607
   *     - Set all the bits of an ANY_BIT type variable to 0
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1608
   */
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1609
  
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1610
  /* Check whether we must implement the FB call semantics... */
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1611
  if (NULL != symbol->called_fb_declaration)
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1612
    return XXX_CAL_operator( "R", this->current_operand);
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1613
  
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 793
diff changeset
  1614
  /* Implement the bit setting semantics... */
382
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1615
  if (wanted_variablegeneration != expression_vg) {
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1616
    s4o.print("LD");
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1617
    return NULL;
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1618
  }
ac6dfec701c9 Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents: 377
diff changeset
  1619
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1620
  if ((NULL == this->current_operand) || (NULL == this->current_operand->datatype)) ERROR;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1621
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1622
  C_modifier();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1623
  this->current_operand->accept(*this);
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1624
  s4o.print(" = __");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1625
  if        (get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype)) {
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1626
    s4o.print("BOOL_LITERAL(FALSE)");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1627
  } else if (get_datatype_info_c::is_ANY_INT_compatible(this->current_operand->datatype)) {
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1628
    this->current_operand->datatype->accept(*this);
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1629
    s4o.print("_LITERAL(0)");
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1630
  } else
240
f78fa87bb4cb Bugs fixed:
laurent
parents: 238
diff changeset
  1631
    ERROR;
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1632
  /* the data type resulting from this operation is unchanged! */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1633
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1634
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1635
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1636
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1637
void *visit( S1_operator_c *symbol)	{return XXX_CAL_operator( "S1", this->current_operand);}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1638
void *visit( R1_operator_c *symbol)	{return XXX_CAL_operator( "R1", this->current_operand);}
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1639
void *visit(CLK_operator_c *symbol)	{return XXX_CAL_operator("CLK", this->current_operand);}
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1640
void *visit( CU_operator_c *symbol)	{return XXX_CAL_operator( "CU", this->current_operand);}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1641
void *visit( CD_operator_c *symbol)	{return XXX_CAL_operator( "CD", this->current_operand);}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1642
void *visit( PV_operator_c *symbol)	{return XXX_CAL_operator( "PV", this->current_operand);}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1643
void *visit( IN_operator_c *symbol)	{return XXX_CAL_operator( "IN", this->current_operand);}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1644
void *visit( PT_operator_c *symbol)	{return XXX_CAL_operator( "PT", this->current_operand);}
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1645
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1646
void *visit(AND_operator_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1647
  if (!get_datatype_info_c::is_ANY_BIT_compatible(symbol->datatype)) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1648
  XXX_operator(&(this->implicit_variable_result), " &= ", this->current_operand);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1649
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1650
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1651
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1652
void *visit(OR_operator_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1653
  if (!get_datatype_info_c::is_ANY_BIT_compatible(symbol->datatype)) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1654
  XXX_operator(&(this->implicit_variable_result), " |= ", this->current_operand);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1655
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1656
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1657
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1658
void *visit(XOR_operator_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1659
  if (!get_datatype_info_c::is_ANY_BIT_compatible(symbol->datatype)) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1660
  // '^' is a bit by bit exclusive OR !! Also seems to work with boolean types!
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1661
  XXX_operator(&(this->implicit_variable_result), " ^= ", this->current_operand);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1662
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1663
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1664
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1665
void *visit(ANDN_operator_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1666
  if (!get_datatype_info_c::is_ANY_BIT_compatible(symbol->datatype)) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1667
  XXX_operator(&(this->implicit_variable_result), get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype)?" &= !":" &= ~", this->current_operand);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1668
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1669
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1670
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1671
void *visit(ORN_operator_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1672
  if (!get_datatype_info_c::is_ANY_BIT_compatible(symbol->datatype)) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1673
  XXX_operator(&(this->implicit_variable_result), get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype)?" |= !":" |= ~", this->current_operand);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1674
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1675
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1676
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1677
void *visit(XORN_operator_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1678
  if (!get_datatype_info_c::is_ANY_BIT_compatible(symbol->datatype)) ERROR;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1679
  // bit by bit exclusive OR !! Also seems to work with boolean types!
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1680
  XXX_operator(&(this->implicit_variable_result), get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype)?" ^= !":" ^= ~", this->current_operand);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1681
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1682
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1683
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1684
void *visit(ADD_operator_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1685
  if (get_datatype_info_c::is_TIME_compatible(symbol->datatype) || get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype)) 
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1686
        XXX_function(&(this->implicit_variable_result), "__time_add", &(this->implicit_variable_current), this->current_operand);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1687
  else  XXX_operator(&(this->implicit_variable_result), " += ", this->current_operand);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1688
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1689
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1690
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1691
void *visit(SUB_operator_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1692
  if (get_datatype_info_c::is_TIME_compatible(symbol->datatype) || get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype))
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1693
        XXX_function(&(this->implicit_variable_result), "__time_sub", &(this->implicit_variable_current), this->current_operand);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1694
  else  XXX_operator(&(this->implicit_variable_result), " -= ", this->current_operand);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1695
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1696
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1697
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1698
void *visit(MUL_operator_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1699
  if (get_datatype_info_c::is_TIME_compatible(symbol->datatype))
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1700
        XXX_function(&(this->implicit_variable_result), "__time_mul", &(this->implicit_variable_current), this->current_operand);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1701
  else  XXX_operator(&(this->implicit_variable_result), " *= ", this->current_operand);
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1702
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1703
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1704
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1705
void *visit(DIV_operator_c *symbol) {
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1706
  if (get_datatype_info_c::is_TIME_compatible(symbol->datatype))
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1707
        XXX_function(&(this->implicit_variable_result), "__time_div", &(this->implicit_variable_current), this->current_operand);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1708
  else  XXX_operator(&(this->implicit_variable_result), " /= ", this->current_operand);
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1709
  return NULL;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1710
}
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1711
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1712
void *visit(MOD_operator_c *symbol)	{XXX_operator(&(this->implicit_variable_result), " %= ", this->current_operand); return NULL;}
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1713
653
ea78924a1f60 Deleting datatype checks no longer needed (with a view of making search_expression_type_c redundant).
Mario de Sousa <msousa@fe.up.pt>
parents: 594
diff changeset
  1714
void *visit(GT_operator_c *symbol)	{CMP_operator(this->current_operand, "GT_"); return NULL;}
ea78924a1f60 Deleting datatype checks no longer needed (with a view of making search_expression_type_c redundant).
Mario de Sousa <msousa@fe.up.pt>
parents: 594
diff changeset
  1715
void *visit(GE_operator_c *symbol)	{CMP_operator(this->current_operand, "GE_"); return NULL;}
ea78924a1f60 Deleting datatype checks no longer needed (with a view of making search_expression_type_c redundant).
Mario de Sousa <msousa@fe.up.pt>
parents: 594
diff changeset
  1716
void *visit(EQ_operator_c *symbol)	{CMP_operator(this->current_operand, "EQ_"); return NULL;}
ea78924a1f60 Deleting datatype checks no longer needed (with a view of making search_expression_type_c redundant).
Mario de Sousa <msousa@fe.up.pt>
parents: 594
diff changeset
  1717
void *visit(LT_operator_c *symbol)	{CMP_operator(this->current_operand, "LT_"); return NULL;}
ea78924a1f60 Deleting datatype checks no longer needed (with a view of making search_expression_type_c redundant).
Mario de Sousa <msousa@fe.up.pt>
parents: 594
diff changeset
  1718
void *visit(LE_operator_c *symbol)	{CMP_operator(this->current_operand, "LE_"); return NULL;}
ea78924a1f60 Deleting datatype checks no longer needed (with a view of making search_expression_type_c redundant).
Mario de Sousa <msousa@fe.up.pt>
parents: 594
diff changeset
  1719
void *visit(NE_operator_c *symbol)	{CMP_operator(this->current_operand, "NE_"); return NULL;}
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1720
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1721
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1722
//SYM_REF0(CAL_operator_c)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1723
// This method will be called from within the il_fb_call_c visitor method
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1724
void *visit(CAL_operator_c *symbol) {return NULL;}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1725
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1726
//SYM_REF0(CALC_operator_c)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1727
// This method will be called from within the il_fb_call_c visitor method
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1728
void *visit(CALC_operator_c *symbol) {C_modifier(); return NULL;}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1729
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1730
//SYM_REF0(CALCN_operator_c)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1731
// This method will be called from within the il_fb_call_c visitor method
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1732
void *visit(CALCN_operator_c *symbol) {CN_modifier(); return NULL;}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1733
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1734
/* NOTE: The semantics of the RET operator requires us to return a value
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1735
 *       if the IL code is inside a function, but simply return no value if
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1736
 *       the IL code is inside a function block or program!
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1737
 *       Nevertheless, it is the generate_c_c class itself that
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1738
 *       introduces the 'reaturn <value>' into the c++ code at the end
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1739
 *       of every function. This class does not know whether the IL code
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1740
 *       is inside a function or a function block.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1741
 *       We work around this by jumping to the end of the code,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1742
 *       that will be marked by the END_LABEL label in the
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1743
 *       instruction_list_c visitor...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1744
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1745
// SYM_REF0(RET_operator_c)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1746
void *visit(RET_operator_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1747
  s4o.print("goto ");s4o.print(END_LABEL);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1748
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1749
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1750
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1751
// SYM_REF0(RETC_operator_c)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1752
void *visit(RETC_operator_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1753
  C_modifier();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1754
  s4o.print("goto ");s4o.print(END_LABEL);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1755
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1756
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1757
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1758
// SYM_REF0(RETCN_operator_c)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1759
void *visit(RETCN_operator_c *symbol) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1760
  CN_modifier();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1761
  s4o.print("goto ");s4o.print(END_LABEL);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1762
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1763
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1764
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1765
//SYM_REF0(JMP_operator_c)
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1766
void *visit(JMP_operator_c *symbol) {
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1767
  if (NULL == this->jump_label) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1768
  s4o.print("goto ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1769
  this->jump_label->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1770
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1771
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1772
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1773
// SYM_REF0(JMPC_operator_c)
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1774
void *visit(JMPC_operator_c *symbol) {
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1775
  if (NULL == this->jump_label) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1776
  C_modifier();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1777
  s4o.print("goto ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1778
  this->jump_label->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1779
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1780
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1781
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1782
// SYM_REF0(JMPCN_operator_c)
706
31553c22f318 Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents: 625
diff changeset
  1783
void *visit(JMPCN_operator_c *symbol) {
70
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1784
  if (NULL == this->jump_label) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1785
  CN_modifier();
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1786
  s4o.print("goto ");
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1787
  this->jump_label->accept(*this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1788
  return NULL;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1789
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1790
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1791
#if 0
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1792
/*| [NOT] any_identifier SENDTO */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1793
SYM_REF2(il_assign_out_operator_c, option, variable_name)
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1794
#endif
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1795
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1796
}; /* generate_c_il_c */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1797
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1798
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1799
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1800
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1801
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1802
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1803
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1804
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1805
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1806
/* The implementation of the single visit() member function
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1807
 * of il_default_variable_c.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1808
 * It can only come after the full declaration of
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1809
 * generate_c_il_c. Since we define and declare
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1810
 * generate_c_il_c simultaneously, it can only come
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1811
 * after the definition...
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1812
 */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1813
void *il_default_variable_c::accept(visitor_c &visitor) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1814
  /* An ugly hack!! */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1815
  /* This is required because we need to over-ride the base
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1816
   * accept(visitor_c &) method of the class symbol_c,
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1817
   * so this method may be called through a symbol_c *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1818
   * reference!
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1819
   *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1820
   * But, the visitor_c does not include a visitor to
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1821
   * an il_default_variable_c, which means that we couldn't
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1822
   * simply call visitor.visit(this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1823
   *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1824
   * We therefore need to use the dynamic_cast hack!!
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1825
   *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1826
   * Note too that we can't cast a visitor_c to a
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1827
   * il_default_variable_visitor_c, since they are not related.
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1828
   * Nor may the il_default_variable_visitor_c inherit from
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1829
   * visitor_c, because then generate_c_il_c would contain
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1830
   * two visitor_c base classes, one each through
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1831
   * il_default_variable_visitor_c and generate_c_type_c
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1832
   *
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1833
   * We could use virtual inheritance of the visitor_c, but it
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1834
   * would probably create more problems than it is worth!
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1835
   */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1836
  generate_c_il_c *v;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1837
  v = dynamic_cast<generate_c_il_c *>(&visitor);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1838
  if (v == NULL) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1839
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1840
  return v->visit(this);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1841
}
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1842
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1843
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1844
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1845
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1846
il_default_variable_c::il_default_variable_c(const char *var_name_str, symbol_c *current_type) {
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1847
  if (NULL == var_name_str) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1848
  /* Note: current_type may start off with NULL */
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1849
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1850
  this->var_name = new identifier_c(var_name_str);
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1851
  if (NULL == this->var_name) ERROR;
e1f0ebd2d9ec Change generate_cc to generate_c
lbessard
parents:
diff changeset
  1852
682
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1853
  this->datatype = current_type;
966f32af570d Major code cleanup: IL code generation now uses symbol.datatype (filled in during stage3 data type checking) instead of determining the symbol's datatype by itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 669
diff changeset
  1854
}