absyntax_utils/type_initial_value.cc
author Edouard Tisserant
Mon, 04 Apr 2011 18:54:55 +0200
changeset 273 beb05fe75e0c
parent 265 4d222f46f8cc
child 279 c0453b7f99df
permissions -rwxr-xr-x
Make semantic error message compatible with beremiz
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
     1
/*
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     3
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     4
 *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     5
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     6
 *  This program is free software: you can redistribute it and/or modify
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     7
 *  it under the terms of the GNU General Public License as published by
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     8
 *  the Free Software Foundation, either version 3 of the License, or
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     9
 *  (at your option) any later version.
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    10
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    11
 *  This program is distributed in the hope that it will be useful,
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    14
 *  GNU General Public License for more details.
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    15
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    16
 *  You should have received a copy of the GNU General Public License
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    18
 *
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    19
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    20
 * This code is made available on the understanding that it will not be
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    21
 * used in safety-critical situations without a full and competent review.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    22
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    23
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    24
/*
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    25
 * An IEC 61131-3 compiler.
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    26
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    27
 * Based on the
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    28
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    29
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    30
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    31
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    32
/*
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    33
 * Determine the default initial value of a type declaration.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    34
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    35
 * This is part of the 4th stage that generates
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    36
 * a c++ source program equivalent to the IL and ST
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    37
 * code.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    38
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    39
/* Given a type definition declration, determine its default
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    40
 * initial value. Note that types based on other types
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    41
 * may have to iterate through each type it is based on
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    42
 * to determine the initial value.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    43
 * E.g.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    44
 *  TYPE
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    45
 *    A_t : INT := 10;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    46
 *    B_t : A_t := 20;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    47
 *    C_t : B_t;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    48
 *    D_t : C_t := 40;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    49
 *  END_TYPE
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    50
 * Where the default initial value for C_t is 20!
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    51
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    52
/* NOTE: The main program only needs one instance of
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    53
 *       this class of object. This class
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    54
 *       is therefore a singleton.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    55
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    56
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    57
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    58
#include "absyntax_utils.hh"
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    59
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    60
//#define DEBUG
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    61
#ifdef DEBUG
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    62
#define TRACE(classname) printf("\n____%s____\n",classname);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    63
#else
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    64
#define TRACE(classname)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    65
#endif
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    66
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    67
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    68
type_initial_value_c *type_initial_value_c::instance(void) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    69
  if (_instance != NULL)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    70
    return _instance;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    71
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    72
  _instance = new type_initial_value_c;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    73
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    74
  real_0 = new real_c("0");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    75
  integer_0 = new integer_c("0");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    76
  integer_1 = new integer_c("1");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    77
  bool_0 = new boolean_literal_c(new bool_type_name_c(),new boolean_false_c());
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    78
  /* FIXME: Our current implementation only allows dates from 1970 onwards,
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    79
   * but the standard defines the date 0001-01-01 as the default value
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    80
   * for the DATE data type. Untill we fix our implementation, we use 1970-01-01
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    81
   * as our default value!!
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    82
   */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    83
    date_literal_0 =  new date_literal_c(integer_1, integer_1, integer_1);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    84
  date_literal_0 =  new date_literal_c(new integer_c("1970"), integer_1, integer_1);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    85
  daytime_literal_0 = new daytime_c(integer_0, integer_0, real_0);
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
    86
  time_0 = new duration_c(new time_type_name_c(), NULL, new seconds_c(integer_0, NULL));  // T#0S
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
    87
  date_0 = new date_c(new date_type_name_c(), date_literal_0);  //  D#0001-01-01
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
    88
  tod_0 = new time_of_day_c(new tod_type_name_c(), daytime_literal_0);  //  TOD#00:00:00
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
    89
  dt_0 = new date_and_time_c(new dt_type_name_c(), date_literal_0, daytime_literal_0);  //  DT#0001-01-01-00:00:00
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    90
  string_0  = new single_byte_character_string_c("''");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    91
  wstring_0 = new double_byte_character_string_c("\"\"");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    92
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    93
  return _instance;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    94
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    95
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    96
type_initial_value_c::type_initial_value_c(void) {}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    97
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    98
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    99
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   100
symbol_c *type_initial_value_c::get(identifier_c *type_name) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   101
  TRACE("type_initial_value_c::get(): called ");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   102
  return (symbol_c *)type_name->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   103
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   104
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   105
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   106
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   107
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   108
void *type_initial_value_c::handle_type_spec(symbol_c *base_type_name, symbol_c *type_spec_init) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   109
  if (type_spec_init != NULL)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   110
     return type_spec_init;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   111
   /* no initial value specified, so we return
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   112
   * the initial value of the type this type is based on...
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   113
    */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   114
  return base_type_name->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   115
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   116
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   117
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   118
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   119
void *type_initial_value_c::visit(identifier_c *type_name) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   120
  /* look up the type declaration... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   121
  symbol_c *type_decl = type_symtable.find_value(type_name);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   122
  if (type_decl == type_symtable.end_value())
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   123
    /* Type declaration not found!! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   124
    /* NOTE: Variables declared out of function block 'data types',
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   125
     *    for eg:  VAR  timer: TON; END_VAR
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   126
     * do not have a default value, so (TON) will never be found in the
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   127
     * type symbol table. This means we cannot simply consider this
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   128
     * an error and abort, but must rather return a NULL.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   129
     */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   130
     return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   131
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   132
  return type_decl->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   133
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   134
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   135
/***********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   136
/* B 1.3.1 - Elementary Data Types */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   137
/***********************************/
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   138
void *type_initial_value_c::visit(time_type_name_c *symbol)         {return (void *)time_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   139
void *type_initial_value_c::visit(bool_type_name_c *symbol)         {return (void *)bool_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   140
void *type_initial_value_c::visit(sint_type_name_c *symbol)         {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   141
void *type_initial_value_c::visit(int_type_name_c *symbol)          {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   142
void *type_initial_value_c::visit(dint_type_name_c *symbol)         {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   143
void *type_initial_value_c::visit(lint_type_name_c *symbol)         {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   144
void *type_initial_value_c::visit(usint_type_name_c *symbol)        {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   145
void *type_initial_value_c::visit(uint_type_name_c *symbol)         {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   146
void *type_initial_value_c::visit(udint_type_name_c *symbol)        {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   147
void *type_initial_value_c::visit(ulint_type_name_c *symbol)        {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   148
void *type_initial_value_c::visit(real_type_name_c *symbol)         {return (void *)real_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   149
void *type_initial_value_c::visit(lreal_type_name_c *symbol)        {return (void *)real_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   150
void *type_initial_value_c::visit(date_type_name_c *symbol)         {return (void *)date_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   151
void *type_initial_value_c::visit(tod_type_name_c *symbol)          {return (void *)tod_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   152
void *type_initial_value_c::visit(dt_type_name_c *symbol)           {return (void *)dt_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   153
void *type_initial_value_c::visit(byte_type_name_c *symbol)         {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   154
void *type_initial_value_c::visit(word_type_name_c *symbol)         {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   155
void *type_initial_value_c::visit(dword_type_name_c *symbol)        {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   156
void *type_initial_value_c::visit(lword_type_name_c *symbol)        {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   157
void *type_initial_value_c::visit(string_type_name_c *symbol)       {return (void *)string_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   158
void *type_initial_value_c::visit(wstring_type_name_c *symbol)      {return (void *)wstring_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   159
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   160
void *type_initial_value_c::visit(safetime_type_name_c *symbol)     {return (void *)time_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   161
void *type_initial_value_c::visit(safebool_type_name_c *symbol)     {return (void *)bool_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   162
void *type_initial_value_c::visit(safesint_type_name_c *symbol)     {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   163
void *type_initial_value_c::visit(safeint_type_name_c *symbol)      {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   164
void *type_initial_value_c::visit(safedint_type_name_c *symbol)     {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   165
void *type_initial_value_c::visit(safelint_type_name_c *symbol)     {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   166
void *type_initial_value_c::visit(safeusint_type_name_c *symbol)    {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   167
void *type_initial_value_c::visit(safeuint_type_name_c *symbol)     {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   168
void *type_initial_value_c::visit(safeudint_type_name_c *symbol)    {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   169
void *type_initial_value_c::visit(safeulint_type_name_c *symbol)    {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   170
void *type_initial_value_c::visit(safereal_type_name_c *symbol)     {return (void *)real_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   171
void *type_initial_value_c::visit(safelreal_type_name_c *symbol)    {return (void *)real_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   172
void *type_initial_value_c::visit(safedate_type_name_c *symbol)     {return (void *)date_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   173
void *type_initial_value_c::visit(safetod_type_name_c *symbol)      {return (void *)tod_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   174
void *type_initial_value_c::visit(safedt_type_name_c *symbol)       {return (void *)dt_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   175
void *type_initial_value_c::visit(safebyte_type_name_c *symbol)     {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   176
void *type_initial_value_c::visit(safeword_type_name_c *symbol)     {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   177
void *type_initial_value_c::visit(safedword_type_name_c *symbol)    {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   178
void *type_initial_value_c::visit(safelword_type_name_c *symbol)    {return (void *)integer_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   179
void *type_initial_value_c::visit(safestring_type_name_c *symbol)   {return (void *)string_0;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   180
void *type_initial_value_c::visit(safewstring_type_name_c *symbol)  {return (void *)wstring_0;}
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   182
/********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   183
/* B 1.3.3 - Derived data types */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   184
/********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   185
/*  simple_type_name ':' simple_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   186
void *type_initial_value_c::visit(simple_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   187
  return symbol->simple_spec_init->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   188
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   189
/* simple_specification ASSIGN constant */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   190
void *type_initial_value_c::visit(simple_spec_init_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   191
  return handle_type_spec(symbol->simple_specification, symbol->constant);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   192
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   193
/*  subrange_type_name ':' subrange_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   194
void *type_initial_value_c::visit(subrange_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   195
  return symbol->subrange_spec_init->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   196
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   197
/* subrange_specification ASSIGN signed_integer */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   198
void *type_initial_value_c::visit(subrange_spec_init_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   199
  return handle_type_spec(symbol->subrange_specification, symbol->signed_integer);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   200
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   201
/*  integer_type_name '(' subrange')' */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   202
void *type_initial_value_c::visit(subrange_specification_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   203
 /* if no initial value explicitly given, then use the lowest value of the subrange */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   204
  if (symbol->subrange != NULL)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   205
    return symbol->subrange->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   206
  else
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   207
    return symbol->integer_type_name->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   208
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   209
/*  signed_integer DOTDOT signed_integer */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   210
void *type_initial_value_c::visit(subrange_c *symbol)	{return symbol->lower_limit;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   211
/*  enumerated_type_name ':' enumerated_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   212
void *type_initial_value_c::visit(enumerated_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   213
  return symbol->enumerated_spec_init->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   214
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   215
/* enumerated_specification ASSIGN enumerated_value */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   216
void *type_initial_value_c::visit(enumerated_spec_init_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   217
  return handle_type_spec(symbol->enumerated_specification, symbol->enumerated_value);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   218
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   219
/* helper symbol for enumerated_specification->enumerated_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   220
/* enumerated_value_list ',' enumerated_value */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   221
void *type_initial_value_c::visit(enumerated_value_list_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   222
 /* if no initial value explicitly given, then use the lowest value of the subrange */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   223
  return (void *)symbol->elements[0];
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   224
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   225
/* enumerated_type_name '#' identifier */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   226
// SYM_REF2(enumerated_value_c, type, value)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   227
void *type_initial_value_c::visit(enumerated_value_c *symbol)	{ERROR; return NULL;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   228
/*  identifier ':' array_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   229
void *type_initial_value_c::visit(array_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   230
  return symbol->array_spec_init->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   231
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   232
/* array_specification [ASSIGN array_initialization} */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   233
/* array_initialization may be NULL ! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   234
void *type_initial_value_c::visit(array_spec_init_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   235
  return handle_type_spec(symbol->array_specification, symbol->array_initialization);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   236
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   237
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   238
void *type_initial_value_c::visit(array_specification_c *symbol)	{
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   239
  //symbol_c *init_value = (symbol_c *)symbol->non_generic_type_name->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   240
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   241
  /* Now build a array_initial_elements_list_c list, and populate it
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   242
   * with 1 element of the array_initial_elements_c class
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   243
   */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   244
  /* The array_initial_elements_c will contain a reference to the init_value,
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   245
   * and another constant representing the number of elements in the array.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   246
   * In essence, we are building the equivilant of the following ST/IL code:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   247
   *    New_array_t : ARRAY [1..30, 51..60] of INT := [40(XXX)];
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   248
   * from the user given code
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   249
   *    New_array_t : ARRAY [1..30, 51..60] of INT;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   250
   * and replacing XXX with the default initial value of INT.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   251
   */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   252
  /* now we need to determine the number of elements in the array... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   253
  /* Easier said than done, as the array may have a list of subranges, as in the
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   254
   * example given above!!
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   255
   */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   256
  /* TODO !!!!!*/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   257
  /* For now, just assume an array with 1 element.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   258
   * I (Mario) want to finish off this part of the code before getting boged down
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   259
   * in something else...
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   260
   */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   261
  // NOTE: We are leaking memory, as the integer will never get free'd!!
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   262
  //integer_c *integer = new integer_c("1");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   263
  // NOTE: We are leaking memory, as the array_initial_elements will never get free'd!!
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   264
  //array_initial_elements_c *array_initial_elements = new array_initial_elements_c(integer, init_value);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   265
  // NOTE: We are leaking memory, as the array_initial_elements_list will never get free'd!!
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   266
  array_initial_elements_list_c *array_initial_elements_list  = new array_initial_elements_list_c();
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   267
  //array_initial_elements_list->add_element(array_initial_elements);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   268
  return array_initial_elements_list;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   269
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   270
/* helper symbol for array_specification */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   271
/* array_subrange_list ',' subrange */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   272
void *type_initial_value_c::visit(array_subrange_list_c *symbol)	{ERROR; return NULL;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   273
/* array_initialization:  '[' array_initial_elements_list ']' */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   274
/* helper symbol for array_initialization */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   275
/* array_initial_elements_list ',' array_initial_elements */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   276
void *type_initial_value_c::visit(array_initial_elements_list_c *symbol)	{ERROR; return NULL;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   277
/* integer '(' [array_initial_element] ')' */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   278
/* array_initial_element may be NULL ! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   279
void *type_initial_value_c::visit(array_initial_elements_c *symbol)	{ERROR; return NULL;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   280
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   281
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   282
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   283
/* TODO: from this point forward... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   284
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   285
/*  structure_type_name ':' structure_specification */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   286
void *type_initial_value_c::visit(structure_type_declaration_c *symbol) {return NULL;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   287
/* structure_type_name ASSIGN structure_initialization */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   288
/* structure_initialization may be NULL ! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   289
void *type_initial_value_c::visit(initialized_structure_c *symbol)	{
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   290
  return handle_type_spec(symbol->structure_type_name, symbol->structure_initialization);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   291
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   292
/* helper symbol for structure_declaration */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   293
/* structure_declaration:  STRUCT structure_element_declaration_list END_STRUCT */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   294
/* structure_element_declaration_list structure_element_declaration ';' */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   295
void *type_initial_value_c::visit(structure_element_declaration_list_c *symbol)	{
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   296
  structure_element_initialization_list_c *structure_element_initialization_list = new structure_element_initialization_list_c();
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   297
  return structure_element_initialization_list;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   298
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   299
/*  structure_element_name ':' *_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   300
void *type_initial_value_c::visit(structure_element_declaration_c *symbol)	{return NULL;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   301
/* helper symbol for structure_initialization */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   302
/* structure_initialization: '(' structure_element_initialization_list ')' */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   303
/* structure_element_initialization_list ',' structure_element_initialization */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   304
void *type_initial_value_c::visit(structure_element_initialization_list_c *symbol)	{return NULL;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   305
/*  structure_element_name ASSIGN value */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   306
void *type_initial_value_c::visit(structure_element_initialization_c *symbol)	{return NULL;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   307
/*  string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   308
/*
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   309
 * NOTE:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   310
 * (Summary: Contrary to what is expected, the
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   311
 *           string_type_declaration_c is not used to store
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   312
 *           simple string type declarations that do not include
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   313
 *           size limits.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   314
 *           For e.g.:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   315
 *             str1_type: STRING := "hello!"
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   316
 *           will be stored in a simple_type_declaration_c
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   317
 *           instead of a string_type_declaration_c.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   318
 *           The following:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   319
 *             str2_type: STRING [64] := "hello!"
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   320
 *           will be stored in a sring_type_declaration_c
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   321
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   322
 *           Read on for why this is done...
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   323
 * End Summary)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   324
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   325
 * According to the spec, the valid construct
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   326
 * TYPE new_str_type : STRING := "hello!"; END_TYPE
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   327
 * has two possible routes to type_declaration...
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   328
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   329
 * Route 1:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   330
 * type_declaration: single_element_type_declaration
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   331
 * single_element_type_declaration: simple_type_declaration
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   332
 * simple_type_declaration: identifier ':' simple_spec_init
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   333
 * simple_spec_init: simple_specification ASSIGN constant
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   334
 * (shift:  identifier <- 'new_str_type')
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   335
 * simple_specification: elementary_type_name
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   336
 * elementary_type_name: STRING
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   337
 * (shift: elementary_type_name <- STRING)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   338
 * (reduce: simple_specification <- elementary_type_name)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   339
 * (shift: constant <- "hello!")
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   340
 * (reduce: simple_spec_init: simple_specification ASSIGN constant)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   341
 * (reduce: ...)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   342
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   343
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   344
 * Route 2:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   345
 * type_declaration: string_type_declaration
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   346
 * string_type_declaration: identifier ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   347
 * (shift:  identifier <- 'new_str_type')
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   348
 * elementary_string_type_name: STRING
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   349
 * (shift: elementary_string_type_name <- STRING)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   350
 * (shift: string_type_declaration_size <-  empty )
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   351
 * string_type_declaration_init: ASSIGN character_string
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   352
 * (shift: character_string <- "hello!")
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   353
 * (reduce: string_type_declaration_init <- ASSIGN character_string)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   354
 * (reduce: string_type_declaration <- identifier ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init )
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   355
 * (reduce: type_declaration <- string_type_declaration)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   356
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   357
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   358
 * At first glance it seems that removing route 1 would make
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   359
 * the most sense. Unfortunately the construct 'simple_spec_init'
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   360
 * shows up multiple times in other rules, so changing this construct
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   361
 * would also mean changing all the rules in which it appears.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   362
 * I (Mario) therefore chose to remove route 2 instead. This means
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   363
 * that the above declaration gets stored in a
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   364
 * simple_type_declaration_c, and not in a string_type_declaration_c
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   365
 * as would be expected!
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   366
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   367
/*  string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   368
#if 0
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   369
SYM_REF4(string_type_declaration_c,	string_type_name,
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   370
					elementary_string_type_name,
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   371
					string_type_declaration_size,
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   372
					string_type_declaration_init) /* may be == NULL! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   373
#endif
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   374
void *type_initial_value_c::visit(string_type_declaration_c *symbol)	{return NULL;}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   375
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   376
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   377
type_initial_value_c	*type_initial_value_c::_instance = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   378
real_c			*type_initial_value_c::real_0 = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   379
integer_c		*type_initial_value_c::integer_0 = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   380
integer_c		*type_initial_value_c::integer_1 = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   381
boolean_literal_c	*type_initial_value_c::bool_0 = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   382
date_literal_c	*type_initial_value_c::date_literal_0 = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   383
daytime_c	*type_initial_value_c::daytime_literal_0 = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   384
duration_c	*type_initial_value_c::time_0 = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   385
date_c	*type_initial_value_c::date_0 = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   386
time_of_day_c	*type_initial_value_c::tod_0 = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   387
date_and_time_c	*type_initial_value_c::dt_0 = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   388
single_byte_character_string_c *type_initial_value_c::string_0 = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   389
double_byte_character_string_c *type_initial_value_c::wstring_0 = NULL;