stage4/generate_cc/generate_cc_st.cc
author lbessard
Fri, 05 Oct 2007 17:58:44 +0200
changeset 65 c6d41c1287de
parent 64 ab704568fa25
permissions -rwxr-xr-x
Lots of bugs fixed
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, " -");}
65
c6d41c1287de Lots of bugs fixed
lbessard
parents: 64
diff changeset
   352
c6d41c1287de Lots of bugs fixed
lbessard
parents: 64
diff changeset
   353
void *visit(not_expression_c *symbol) {
c6d41c1287de Lots of bugs fixed
lbessard
parents: 64
diff changeset
   354
  symbol_c *exp_type = search_expression_type->get_type(symbol->exp);
c6d41c1287de Lots of bugs fixed
lbessard
parents: 64
diff changeset
   355
  if (!search_expression_type->is_binary_type(exp_type))
c6d41c1287de Lots of bugs fixed
lbessard
parents: 64
diff changeset
   356
     ERROR;
c6d41c1287de Lots of bugs fixed
lbessard
parents: 64
diff changeset
   357
  return print_unary_expression(symbol->exp, search_expression_type->is_bool_type(exp_type)?"!":"~");
c6d41c1287de Lots of bugs fixed
lbessard
parents: 64
diff changeset
   358
}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   359
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   360
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
   361
  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
   362
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   363
  if (f_decl == function_symtable.end_value()) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   364
    /* 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
   365
     * standard function defined in standard */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   366
    
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   367
    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
   368
    if (current_function_type == function_none) ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   369
    
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   370
    symbol_c *function_return_type = search_expression_type->get_type(symbol);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   371
    
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   372
    function_call_param_iterator_c function_call_param_iterator(symbol);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   373
    
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   374
    int nb_param = ((list_c *)symbol->parameter_assignment_list)->n;
33
4507beb2aac6 preliminary std lib support for ST
etisserant
parents: 32
diff changeset
   375
4507beb2aac6 preliminary std lib support for ST
etisserant
parents: 32
diff changeset
   376
#include "st_code_gen.c"
4507beb2aac6 preliminary std lib support for ST
etisserant
parents: 32
diff changeset
   377
4507beb2aac6 preliminary std lib support for ST
etisserant
parents: 32
diff changeset
   378
#if 0
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   379
    for(int current_param = 0; current_param < nb_param; current_param++) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   380
      symbol_c *param_name = NULL;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   381
      switch (current_function_type) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   382
        case function_add:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   383
        case function_and:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   384
        case function_or:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   385
          param_name = generate_param_name("IN%d", current_param + 1);
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
        case function_sub:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   388
          if (current_param < 2)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   389
            param_name = generate_param_name("IN%d", current_param + 1);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   390
          else
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   391
            ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   392
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   393
        default: ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   394
      }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   395
      
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   396
      /* 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
   397
      symbol_c *param_value = function_call_param_iterator.search(param_name);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   398
      delete param_name;
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
      /* Get the value from a foo(<param_value>) style call */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   401
      if (param_value == NULL)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   402
        param_value = function_call_param_iterator.next();
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   403
      
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   404
      if (param_value == NULL) ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   405
      
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   406
      switch (current_function_type) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   407
        case function_add:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   408
          if (search_expression_type->is_time_type(function_return_type)) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   409
            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
   410
              s4o.print("__time_add(");
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   411
              param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   412
            }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   413
            else if (current_param == 1) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   414
              s4o.print(", ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   415
              param_value->accept(*this);
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
            }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   418
            else ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   419
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   420
          else {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   421
            if (current_param == 0)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   422
              s4o.print("(");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   423
            else
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   424
              s4o.print(" + ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   425
            param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   426
            if (current_param == nb_param - 1)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   427
              s4o.print(")");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   428
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   429
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   430
        case function_sub:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   431
          if (search_expression_type->is_time_type(function_return_type)) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   432
            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
   433
              s4o.print("__time_sub(");
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   434
              param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   435
            }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   436
            else if (current_param == 1) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   437
              s4o.print(", ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   438
              param_value->accept(*this);
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
            }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   441
            else ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   442
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   443
          else {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   444
            if (current_param == 0) {
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
              param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   447
            }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   448
            else if (current_param == 1) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   449
              s4o.print(" - ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   450
              param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   451
              s4o.print(")");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   452
            }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   453
            else ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   454
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   455
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   456
        case function_and:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   457
          if (current_param == 0)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   458
            s4o.print("(");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   459
          else
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   460
            if (search_expression_type->is_bool_type(function_return_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   461
              s4o.print(" && ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   462
            else
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   463
              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
   464
          param_value->accept(*this);
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   465
          if (current_param == nb_param - 1)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   466
            s4o.print(")");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   467
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   468
        case function_or:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   469
          if (current_param == 0)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   470
            s4o.print("(");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   471
          else
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   472
            if (search_expression_type->is_bool_type(function_return_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   473
              s4o.print(" || ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   474
            else
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   475
              s4o.print(" | ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   476
          param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   477
          if (current_param == nb_param - 1)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   478
            s4o.print(")");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   479
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   480
        default: ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   481
      }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   482
    } /* for(...) */
33
4507beb2aac6 preliminary std lib support for ST
etisserant
parents: 32
diff changeset
   483
#endif
32
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
  else {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   486
    /* loop through each function parameter, find the value we should pass
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   487
     * to it, and then output the c equivalent...
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
    function_param_iterator_c fp_iterator(f_decl);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   490
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   491
    symbol->function_name->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   492
    s4o.print("(");
42
b45c7f34dec1 IEC std lib test enhanced string ops, from string and to string conv.
etisserant
parents: 41
diff changeset
   493
    s4o.indent_right();
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
    identifier_c *param_name;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   496
    function_call_param_iterator_c function_call_param_iterator(symbol);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   497
    for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   498
      if (i != 1)
42
b45c7f34dec1 IEC std lib test enhanced string ops, from string and to string conv.
etisserant
parents: 41
diff changeset
   499
        s4o.print(",\n"+s4o.indent_spaces);
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   500
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   501
      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
   502
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   503
      /* 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
   504
      symbol_c *param_value = function_call_param_iterator.search(param_name);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   505
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   506
      /* Get the value from a foo(<param_value>) style call */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   507
      if (param_value == NULL)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   508
        param_value = function_call_param_iterator.next();
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   509
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   510
      symbol_c *param_type = fp_iterator.param_type();
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   511
      if (param_type == NULL) ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   512
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   513
      switch (param_direction) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   514
        case function_param_iterator_c::direction_in:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   515
          if (param_value == NULL) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   516
            /* No value given for parameter, so we must use the default... */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   517
            /* First check whether default value specified in function declaration...*/
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   518
            param_value = fp_iterator.default_value();
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   519
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   520
          if (param_value == NULL) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   521
            /* If not, get the default value of this variable's type */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   522
            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
   523
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   524
          if (param_value == NULL) ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   525
          param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   526
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   527
        case function_param_iterator_c::direction_out:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   528
        case function_param_iterator_c::direction_inout:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   529
          if (param_value == NULL) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   530
            /* 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
   531
            std::string *temp_var_name = temp_var_name_factory.new_name();
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   532
            s4o.print(*temp_var_name);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   533
            delete temp_var_name;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   534
          } else {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   535
            param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   536
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   537
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   538
        case function_param_iterator_c::direction_extref:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   539
          /* TODO! */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   540
          ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   541
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   542
      } /* switch */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   543
    } /* for(...) */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   544
    // symbol->parameter_assignment->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   545
    s4o.print(")");
42
b45c7f34dec1 IEC std lib test enhanced string ops, from string and to string conv.
etisserant
parents: 41
diff changeset
   546
    s4o.indent_left();
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   547
  }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   548
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   549
  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
   550
}
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
/* 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
   554
/********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   555
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
   556
  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
   557
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   558
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   559
/*********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   560
/* 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
   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
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
   563
  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
   564
  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
   565
  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
   566
  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
   567
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   568
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   569
/*****************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   570
/* 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
   571
/*****************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   572
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   573
/* 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
   574
/* 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
   575
//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
   576
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
   577
  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
   578
  /* 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
   579
  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
   580
    /* 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
   581
  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
   582
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   583
  /* 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
   584
  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
   585
    /* 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
   586
  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
   587
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   588
  /* 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
   589
   * 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
   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
  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
   592
  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
   593
  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
   594
  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
   595
    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
   596
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   597
    /* 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
   598
    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
   599
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   600
    /* 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
   601
    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
   602
      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
   603
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   604
    /* 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
   605
    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
   606
      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
   607
          (param_direction == function_param_iterator_c::direction_inout)) {
24
7e830409f72a Adding init function on programs
etisserant
parents: 22
diff changeset
   608
        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
   609
        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
   610
        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
   611
        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
   612
        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
   613
        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
   614
        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
   615
      }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   616
  } /* for(...) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   617
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   618
  /* 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
   619
  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
   620
  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
   621
  s4o.print("(&");
24
7e830409f72a Adding init function on programs
etisserant
parents: 22
diff changeset
   622
  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
   623
  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
   624
  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
   625
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   626
  /* 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
   627
   * 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
   628
   */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   629
  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
   630
  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
   631
  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
   632
    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
   633
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   634
    /* 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
   635
    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
   636
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   637
    /* 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
   638
    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
   639
      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
   640
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   641
    /* 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
   642
    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
   643
      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
   644
          (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
   645
        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
   646
        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
   647
        s4o.print(" = ");
24
7e830409f72a Adding init function on programs
etisserant
parents: 22
diff changeset
   648
        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
   649
        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
   650
        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
   651
        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
   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
  } /* for(...) */
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
  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
   656
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   657
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   658
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   659
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   660
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   661
/* 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
   662
/* 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
   663
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
   664
  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
   665
  /* 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
   666
  ERROR;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   667
  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
   668
//  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
   669
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   670
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
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
   673
  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
   674
  /* 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
   675
  ERROR;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   676
  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
   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
  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
   679
  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
   680
  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
   681
  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
   682
*/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   683
}
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
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
   686
  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
   687
  /* 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
   688
  ERROR;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   689
  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
   690
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   691
  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
   692
  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
   693
    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
   694
  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
   695
  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
   696
  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
   697
  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
   698
*/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   699
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   700
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   701
// 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
   702
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
   703
  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
   704
  /* 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
   705
  ERROR;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   706
  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
   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
  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
   709
  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
   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
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   712
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   713
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   714
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   715
/* 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
   716
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   717
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
   718
  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
   719
  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
   720
  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
   721
  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
   722
  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
   723
  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
   724
  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
   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
  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
   727
    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
   728
    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
   729
    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
   730
    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
   731
  }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   732
  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
   733
  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
   734
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   735
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   736
/* 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
   737
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
   738
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   739
/* 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
   740
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
   741
  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
   742
  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
   743
  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
   744
  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
   745
  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
   746
  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
   747
  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
   748
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   749
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   750
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
   751
  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
   752
  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
   753
  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
   754
  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
   755
  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
   756
  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
   757
    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
   758
    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
   759
    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
   760
    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
   761
    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
   762
  }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   763
  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
   764
  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
   765
  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
   766
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   767
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   768
/* 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
   769
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
   770
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   771
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
   772
  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
   773
  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
   774
  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
   775
  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
   776
  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
   777
  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
   778
  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
   779
  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
   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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   782
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
   783
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   784
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   785
/* 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
   786
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   787
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
   788
  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
   789
  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
   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->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
   792
  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
   793
  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
   794
  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
   795
  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
   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
  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
   798
  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
   799
    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
   800
    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
   801
  } else {
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("++");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   803
  }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   804
  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
   805
  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
   806
  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
   807
  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
   808
  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
   809
  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
   810
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   811
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
   812
  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
   813
  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
   814
  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
   815
  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
   816
  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
   817
  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
   818
  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
   819
  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
   820
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   821
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
   822
  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
   823
  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
   824
  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
   825
  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
   826
  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
   827
  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
   828
  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
   829
  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
   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
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
   832
  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
   833
  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
   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
}; /* 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
   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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   842
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   843
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   844
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   845
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   846
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   847