stage4/generate_cc/generate_cc_st.cc
author etisserant
Fri, 13 Jul 2007 19:20:26 +0200
changeset 41 8998c8b24b60
parent 33 4507beb2aac6
child 42 b45c7f34dec1
permissions -rwxr-xr-x
First working IEC std lib test, actually test from string and to_string functions.
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
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   145
/***************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   146
/* 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
   147
/***************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   148
/***********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   149
/* 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
   150
/***********************/
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   151
void *visit(or_expression_c *symbol) {
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   152
  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
   153
  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
   154
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   155
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   156
  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
   157
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " || ");
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   158
  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
   159
    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
   160
  ERROR;
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   161
  return NULL;
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   162
}
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   163
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   164
void *visit(xor_expression_c *symbol) {
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   165
  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
   166
  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
   167
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   168
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   169
  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
   170
    s4o.print("(");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   171
    symbol->l_exp->accept(*this);
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   172
    s4o.print(" && !");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   173
    symbol->r_exp->accept(*this);
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   174
    s4o.print(") || (!");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   175
    symbol->l_exp->accept(*this);
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   176
    s4o.print(" && ");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   177
    symbol->r_exp->accept(*this);
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   178
    s4o.print(")");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   179
  }
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   180
  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
   181
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " ^ ");
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   182
  ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   183
  return NULL;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   184
}
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   185
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   186
void *visit(and_expression_c *symbol) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   187
  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
   188
  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
   189
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   190
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   191
  if (search_expression_type->is_bool_type(left_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   192
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " && ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   193
  if (search_expression_type->is_binary_type(left_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   194
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " & ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   195
  ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   196
  return NULL;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   197
}
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   198
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   199
void *visit(equ_expression_c *symbol) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   200
  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
   201
  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
   202
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   203
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   204
  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
   205
    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
   206
  return print_binary_expression(symbol->l_exp, symbol->r_exp, " == ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   207
}
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   208
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   209
void *visit(notequ_expression_c *symbol) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   210
  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
   211
  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
   212
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   213
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   214
  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
   215
    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
   216
  return print_binary_expression(symbol->l_exp, symbol->r_exp, " != ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   217
}
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   218
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   219
void *visit(lt_expression_c *symbol) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   220
  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
   221
  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
   222
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   223
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   224
  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
   225
    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
   226
  return print_binary_expression(symbol->l_exp, symbol->r_exp, " < ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   227
}
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   228
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   229
void *visit(gt_expression_c *symbol) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   230
  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
   231
  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
   232
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   233
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   234
  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
   235
    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
   236
  return print_binary_expression(symbol->l_exp, symbol->r_exp, " > ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   237
}
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   238
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   239
void *visit(le_expression_c *symbol) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   240
  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
   241
  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
   242
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   243
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   244
  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
   245
    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
   246
  return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   247
}
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   248
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   249
void *visit(ge_expression_c *symbol) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   250
  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
   251
  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
   252
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   253
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   254
  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
   255
    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
   256
  return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   257
}
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   258
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   259
void *visit(add_expression_c *symbol) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   260
  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
   261
	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
   262
	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
   263
      (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
   264
      (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
   265
    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
   266
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   267
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   268
  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
   269
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " + ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   270
  ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   271
  return NULL;
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(sub_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(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
   279
      (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
   280
      (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
   281
      (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
   282
      (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
   283
    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
   284
  if (!search_expression_type->is_same_type(left_type, right_type))
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
  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
   287
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " - ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   288
  ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   289
  return NULL;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   290
}
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   291
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   292
void *visit(mul_expression_c *symbol) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   293
  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
   294
  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
   295
  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
   296
      (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
   297
    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
   298
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   299
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   300
  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
   301
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " * ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   302
  ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   303
  return NULL;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   304
}
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
void *visit(div_expression_c *symbol) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   307
  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
   308
  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
   309
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   310
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   311
  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
   312
    return print_binary_expression(symbol->l_exp, symbol->r_exp, " / ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   313
  ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   314
  return NULL;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   315
}
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   316
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   317
void *visit(mod_expression_c *symbol) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   318
  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
   319
  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
   320
  if (!search_expression_type->is_same_type(left_type, right_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   321
      ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   322
  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
   323
    s4o.print("((");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   324
    symbol->r_exp->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   325
    s4o.print(" == 0)?0:");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   326
    print_binary_expression(symbol->l_exp, symbol->r_exp, " % ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   327
    s4o.print(")");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   328
    return NULL;
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   329
  }
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   330
  ERROR;
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   331
  return NULL;
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   332
}
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 0
diff changeset
   333
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   334
/* 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
   335
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
   336
void *visit(neg_expression_c *symbol) {return print_unary_expression(symbol->exp, " -");}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   337
void *visit(not_expression_c *symbol) {return print_unary_expression(symbol->exp, "!");}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   338
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   339
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
   340
  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
   341
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   342
  if (f_decl == function_symtable.end_value()) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   343
    /* 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
   344
     * standard function defined in standard */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   345
    
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   346
    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
   347
    if (current_function_type == function_none) ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   348
    
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   349
    symbol_c *function_return_type = search_expression_type->get_type(symbol);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   350
    
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   351
    function_call_param_iterator_c function_call_param_iterator(symbol);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   352
    
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   353
    int nb_param = ((list_c *)symbol->parameter_assignment_list)->n;
33
4507beb2aac6 preliminary std lib support for ST
etisserant
parents: 32
diff changeset
   354
4507beb2aac6 preliminary std lib support for ST
etisserant
parents: 32
diff changeset
   355
#include "st_code_gen.c"
4507beb2aac6 preliminary std lib support for ST
etisserant
parents: 32
diff changeset
   356
4507beb2aac6 preliminary std lib support for ST
etisserant
parents: 32
diff changeset
   357
#if 0
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   358
    for(int current_param = 0; current_param < nb_param; current_param++) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   359
      symbol_c *param_name = NULL;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   360
      switch (current_function_type) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   361
        case function_add:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   362
        case function_and:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   363
        case function_or:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   364
          param_name = generate_param_name("IN%d", current_param + 1);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   365
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   366
        case function_sub:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   367
          if (current_param < 2)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   368
            param_name = generate_param_name("IN%d", current_param + 1);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   369
          else
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   370
            ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   371
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   372
        default: ERROR;
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
      
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   375
      /* 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
   376
      symbol_c *param_value = function_call_param_iterator.search(param_name);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   377
      delete param_name;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   378
      
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   379
      /* Get the value from a foo(<param_value>) style call */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   380
      if (param_value == NULL)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   381
        param_value = function_call_param_iterator.next();
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   382
      
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   383
      if (param_value == NULL) ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   384
      
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   385
      switch (current_function_type) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   386
        case function_add:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   387
          if (search_expression_type->is_time_type(function_return_type)) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   388
            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
   389
              s4o.print("__time_add(");
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   390
              param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   391
            }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   392
            else if (current_param == 1) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   393
              s4o.print(", ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   394
              param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   395
              s4o.print(")");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   396
            }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   397
            else ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   398
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   399
          else {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   400
            if (current_param == 0)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   401
              s4o.print("(");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   402
            else
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   403
              s4o.print(" + ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   404
            param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   405
            if (current_param == nb_param - 1)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   406
              s4o.print(")");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   407
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   408
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   409
        case function_sub:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   410
          if (search_expression_type->is_time_type(function_return_type)) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   411
            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
   412
              s4o.print("__time_sub(");
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   413
              param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   414
            }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   415
            else if (current_param == 1) {
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
              param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   418
              s4o.print(")");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   419
            }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   420
            else ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   421
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   422
          else {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   423
            if (current_param == 0) {
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
            }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   427
            else if (current_param == 1) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   428
              s4o.print(" - ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   429
              param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   430
              s4o.print(")");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   431
            }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   432
            else ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   433
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   434
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   435
        case function_and:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   436
          if (current_param == 0)
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
          else
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   439
            if (search_expression_type->is_bool_type(function_return_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   440
              s4o.print(" && ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   441
            else
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   442
              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
   443
          param_value->accept(*this);
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   444
          if (current_param == nb_param - 1)
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
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   447
        case function_or:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   448
          if (current_param == 0)
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
          else
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   451
            if (search_expression_type->is_bool_type(function_return_type))
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   452
              s4o.print(" || ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   453
            else
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   454
              s4o.print(" | ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   455
          param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   456
          if (current_param == nb_param - 1)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   457
            s4o.print(")");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   458
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   459
        default: ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   460
      }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   461
    } /* for(...) */
33
4507beb2aac6 preliminary std lib support for ST
etisserant
parents: 32
diff changeset
   462
#endif
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   463
  }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   464
  else {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   465
    /* loop through each function parameter, find the value we should pass
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   466
     * to it, and then output the c equivalent...
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   467
     */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   468
    function_param_iterator_c fp_iterator(f_decl);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   469
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   470
    symbol->function_name->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   471
    s4o.print("(");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   472
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   473
    identifier_c *param_name;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   474
    function_call_param_iterator_c function_call_param_iterator(symbol);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   475
    for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   476
      if (i != 1)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   477
        s4o.print(", ");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   478
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   479
      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
   480
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   481
      /* 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
   482
      symbol_c *param_value = function_call_param_iterator.search(param_name);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   483
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   484
      /* Get the value from a foo(<param_value>) style call */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   485
      if (param_value == NULL)
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   486
        param_value = function_call_param_iterator.next();
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   487
  
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   488
      symbol_c *param_type = fp_iterator.param_type();
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   489
      if (param_type == NULL) ERROR;
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
      switch (param_direction) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   492
        case function_param_iterator_c::direction_in:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   493
          if (param_value == NULL) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   494
            /* No value given for parameter, so we must use the default... */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   495
            /* First check whether default value specified in function declaration...*/
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   496
            param_value = fp_iterator.default_value();
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   497
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   498
          if (param_value == NULL) {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   499
            /* If not, get the default value of this variable's type */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   500
            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
   501
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   502
          if (param_value == NULL) ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   503
          param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   504
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   505
        case function_param_iterator_c::direction_out:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   506
        case function_param_iterator_c::direction_inout:
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
            /* 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
   509
            std::string *temp_var_name = temp_var_name_factory.new_name();
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   510
            s4o.print(*temp_var_name);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   511
            delete temp_var_name;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   512
          } else {
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   513
            param_value->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   514
          }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   515
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   516
        case function_param_iterator_c::direction_extref:
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   517
          /* TODO! */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   518
          ERROR;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   519
          break;
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   520
      } /* switch */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   521
    } /* for(...) */
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   522
    // symbol->parameter_assignment->accept(*this);
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   523
    s4o.print(")");
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   524
  }
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 26
diff changeset
   525
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   526
  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
   527
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   528
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   529
/********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   530
/* 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
   531
/********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   532
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
   533
  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
   534
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   535
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   536
/*********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   537
/* 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
   538
/*********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   539
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
   540
  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
   541
  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
   542
  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
   543
  return NULL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   544
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   545
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   546
/*****************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   547
/* B 3.2.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
   548
/*****************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   549
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   550
/* 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
   551
/* 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
   552
//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
   553
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
   554
  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
   555
  /* 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
   556
  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
   557
    /* 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
   558
  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
   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
  /* 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
   561
  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
   562
    /* 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
   563
  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
   564
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   565
  /* 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
   566
   * 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
   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
  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
   569
  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
   570
  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
   571
  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
   572
    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
   573
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   574
    /* 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
   575
    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
   576
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   577
    /* 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
   578
    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
   579
      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
   580
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   581
    /* 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
   582
    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
   583
      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
   584
          (param_direction == function_param_iterator_c::direction_inout)) {
24
7e830409f72a Adding init function on programs
etisserant
parents: 22
diff changeset
   585
        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
   586
        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
   587
        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
   588
        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
   589
        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
   590
        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
   591
        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
   592
      }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   593
  } /* for(...) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   594
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   595
  /* 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
   596
  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
   597
  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
   598
  s4o.print("(&");
24
7e830409f72a Adding init function on programs
etisserant
parents: 22
diff changeset
   599
  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
   600
  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
   601
  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
   602
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   603
  /* 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
   604
   * 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
   605
   */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   606
  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
   607
  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
   608
  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
   609
    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
   610
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   611
    /* 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
   612
    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
   613
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   614
    /* 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
   615
    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
   616
      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
   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 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
   619
    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
   620
      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
   621
          (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
   622
        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
   623
        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
   624
        s4o.print(" = ");
24
7e830409f72a Adding init function on programs
etisserant
parents: 22
diff changeset
   625
        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
   626
        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
   627
        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
   628
        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
   629
      }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   630
  } /* for(...) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   631
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   632
  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
   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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   635
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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   638
/* 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
   639
/* 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
   640
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
   641
  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
   642
  /* 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
   643
  ERROR;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   644
  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
   645
//  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
   646
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   647
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   648
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   649
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
   650
  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
   651
  /* 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
   652
  ERROR;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   653
  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
   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
  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
   656
  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
   657
  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
   658
  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
   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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   662
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
   663
  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
   664
  /* 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
   665
  ERROR;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   666
  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
   667
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   668
  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
   669
  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
   670
    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
   671
  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
   672
  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
   673
  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
   674
  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
   675
*/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   676
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   677
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   678
// 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
   679
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
   680
  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
   681
  /* this should never be called... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   682
  ERROR;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   683
  return NULL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   684
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   685
  s4o.print("NOT ");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   686
  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
   687
*/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   688
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   689
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
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   692
/* 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
   693
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   694
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
   695
  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
   696
  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
   697
  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
   698
  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
   699
  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
   700
  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
   701
  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
   702
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   703
  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
   704
    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
   705
    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
   706
    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
   707
    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
   708
  }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   709
  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
   710
  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
   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
/* 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
   714
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
   715
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   716
/* 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
   717
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
   718
  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
   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
  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
   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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   727
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
   728
  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
   729
  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
   730
  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
   731
  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
   732
  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
   733
  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
   734
    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
   735
    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
   736
    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
   737
    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
   738
    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
   739
  }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   740
  s4o.indent_left();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   741
  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
   742
  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
   743
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   744
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   745
/* 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
   746
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
   747
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   748
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
   749
  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
   750
  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
   751
  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
   752
  s4o.indent_right();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   753
  symbol->statement_list->accept(*this);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   754
  s4o.print(s4o.indent_spaces + "break;\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   755
  s4o.indent_left();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   756
  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
   757
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   758
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   759
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
   760
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   761
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   762
/* 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
   763
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   764
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
   765
  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
   766
  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
   767
  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
   768
  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
   769
  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
   770
  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
   771
  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
   772
  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
   773
  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
   774
  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
   775
  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
   776
    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
   777
    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
   778
  } else {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   779
    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
   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
  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
   782
  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
   783
  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
   784
  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
   785
  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
   786
  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
   787
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   788
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
   789
  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
   790
  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
   791
  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
   792
  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
   793
  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
   794
  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
   795
  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
   796
  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
   797
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   798
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
   799
  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
   800
  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
   801
  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
   802
  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
   803
  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
   804
  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
   805
  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
   806
  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
   807
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   808
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
   809
  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
   810
  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
   811
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   812
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   813
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   814
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   815
}; /* 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
   816
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   817
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   818
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   819
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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   822
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   823
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   824