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