absyntax_utils/type_initial_value.hh
author mjsousa
Sun, 19 Oct 2014 11:53:36 +0100
changeset 937 887e7d90445a
parent 925 a942c55fb769
child 945 477393b00f95
permissions -rwxr-xr-x
Fix bug with multple dereferencing (bool_var := bool_ptr_ptr^^;)
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)
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 265
diff changeset
     5
 *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     6
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     7
 *  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
     8
 *  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
     9
 *  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
    10
 *  (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
    11
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    12
 *  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
    13
 *  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
    14
 *  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
    15
 *  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
    16
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    17
 *  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
    18
 *  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
    19
 *
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    20
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    21
 * 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
    22
 * 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
    23
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    24
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    25
/*
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    26
 * An IEC 61131-3 compiler.
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    27
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    28
 * Based on the
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    29
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
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
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
 * Determine the default initial value of a type declaration.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    36
 *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    37
 * This is part of the 4th stage that generates
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    38
 * a c++ source program equivalent to the IL and ST
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    39
 * code.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    40
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    41
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    42
/* Given a type definition declration, determine its default
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    43
 * initial value. Note that types based on other types
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    44
 * 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
    45
 * to determine the initial value.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    46
 * E.g.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    47
 *  TYPE
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    48
 *    A_t : INT := 10;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    49
 *    B_t : A_t := 20;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    50
 *    C_t : B_t;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    51
 *    D_t : C_t := 40;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    52
 *  END_TYPE
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    53
 * Where the default initial value for C_t is 20!
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    54
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    55
/* NOTE: The main program only needs one instance of
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    56
 *       this class of object. This class
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    57
 *       is therefore a singleton.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    58
 */
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
class type_initial_value_c : public null_visitor_c {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    61
762
a3d917474ae4 Small code cleanup.
Mario de Sousa <msousa@fe.up.pt>
parents: 433
diff changeset
    62
  public:
a3d917474ae4 Small code cleanup.
Mario de Sousa <msousa@fe.up.pt>
parents: 433
diff changeset
    63
    static symbol_c *get(symbol_c *type);
a3d917474ae4 Small code cleanup.
Mario de Sousa <msousa@fe.up.pt>
parents: 433
diff changeset
    64
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    65
  private:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    66
    /* constants for the default values of elementary data types... */
925
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
    67
    static ref_value_null_literal_c       *null_literal;
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
    68
    static real_c                         *real_0;
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
    69
    static integer_c                      *integer_0, *integer_1;
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
    70
    static boolean_literal_c              *bool_0;
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
    71
    static date_literal_c                 *date_literal_0;
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
    72
    static daytime_c                      *daytime_literal_0;
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
    73
    static duration_c                     *time_0;
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
    74
    static date_c                         *date_0;
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
    75
    static time_of_day_c                  *tod_0;
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
    76
    static date_and_time_c                *dt_0;
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    77
    static single_byte_character_string_c *string_0;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    78
    static double_byte_character_string_c *wstring_0;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    79
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    80
  protected:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    81
    type_initial_value_c(void);
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
  private:
762
a3d917474ae4 Small code cleanup.
Mario de Sousa <msousa@fe.up.pt>
parents: 433
diff changeset
    84
    static type_initial_value_c *_instance;
a3d917474ae4 Small code cleanup.
Mario de Sousa <msousa@fe.up.pt>
parents: 433
diff changeset
    85
    static type_initial_value_c *instance(void);
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    86
    void *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
    87
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    88
  private:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    89
    void *visit(identifier_c *type_name);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    90
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    91
    /***********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    92
    /* B 1.3.1 - Elementary Data Types */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    93
    /***********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    94
    void *visit(time_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    95
    void *visit(bool_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    96
    void *visit(sint_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    97
    void *visit(int_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    98
    void *visit(dint_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    99
    void *visit(lint_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   100
    void *visit(usint_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   101
    void *visit(uint_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   102
    void *visit(udint_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   103
    void *visit(ulint_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   104
    void *visit(real_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   105
    void *visit(lreal_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   106
    void *visit(date_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   107
    void *visit(tod_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   108
    void *visit(dt_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   109
    void *visit(byte_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   110
    void *visit(word_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   111
    void *visit(dword_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   112
    void *visit(lword_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   113
    void *visit(string_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   114
    void *visit(wstring_type_name_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   115
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   116
    void *visit(safetime_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   117
    void *visit(safebool_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   118
    void *visit(safesint_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   119
    void *visit(safeint_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   120
    void *visit(safedint_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   121
    void *visit(safelint_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   122
    void *visit(safeusint_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   123
    void *visit(safeuint_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   124
    void *visit(safeudint_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   125
    void *visit(safeulint_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   126
    void *visit(safereal_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   127
    void *visit(safelreal_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   128
    void *visit(safedate_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   129
    void *visit(safetod_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   130
    void *visit(safedt_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   131
    void *visit(safebyte_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   132
    void *visit(safeword_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   133
    void *visit(safedword_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   134
    void *visit(safelword_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   135
    void *visit(safestring_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   136
    void *visit(safewstring_type_name_c *symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
   137
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   138
    /********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   139
    /* B 1.3.3 - Derived data types */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   140
    /********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   141
    /*  simple_type_name ':' simple_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   142
    void *visit(simple_type_declaration_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   143
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   144
    /* simple_specification ASSIGN constant */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   145
    void *visit(simple_spec_init_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   146
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   147
    /*  subrange_type_name ':' subrange_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   148
    void *visit(subrange_type_declaration_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   149
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   150
    /* subrange_specification ASSIGN signed_integer */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   151
    void *visit(subrange_spec_init_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   152
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   153
    /*  integer_type_name '(' subrange')' */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   154
    void *visit(subrange_specification_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   155
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   156
    /*  signed_integer DOTDOT signed_integer */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   157
    void *visit(subrange_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   158
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   159
    /*  enumerated_type_name ':' enumerated_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   160
    void *visit(enumerated_type_declaration_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   161
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   162
    /* enumerated_specification ASSIGN enumerated_value */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   163
    void *visit(enumerated_spec_init_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   164
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   165
    /* helper symbol for enumerated_specification->enumerated_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   166
    /* enumerated_value_list ',' enumerated_value */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   167
    void *visit(enumerated_value_list_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   168
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   169
    /* enumerated_type_name '#' identifier */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   170
    // SYM_REF2(enumerated_value_c, type, value)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   171
    void *visit(enumerated_value_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   172
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   173
    /*  identifier ':' array_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   174
    void *visit(array_type_declaration_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   175
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   176
    /* array_specification [ASSIGN array_initialization} */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   177
    /* array_initialization may be NULL ! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   178
    void *visit(array_spec_init_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   179
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   180
    /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   181
    void *visit(array_specification_c *symbol);
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
    /* helper symbol for array_specification */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   184
    /* array_subrange_list ',' subrange */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   185
    void *visit(array_subrange_list_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   186
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   187
    /* array_initialization:  '[' array_initial_elements_list ']' */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   188
    /* helper symbol for array_initialization */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   189
    /* array_initial_elements_list ',' array_initial_elements */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   190
    void *visit(array_initial_elements_list_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   191
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   192
    /* integer '(' [array_initial_element] ')' */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   193
    /* array_initial_element may be NULL ! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   194
    void *visit(array_initial_elements_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   195
    
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   196
    /*  structure_type_name ':' structure_specification */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   197
    void *visit(structure_type_declaration_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   198
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   199
    /* structure_type_name ASSIGN structure_initialization */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   200
    /* structure_initialization may be NULL ! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   201
    void *visit(initialized_structure_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   202
     
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   203
    /* helper symbol for structure_declaration */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   204
    /* structure_declaration:  STRUCT structure_element_declaration_list END_STRUCT */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   205
    /* structure_element_declaration_list structure_element_declaration ';' */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   206
    void *visit(structure_element_declaration_list_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   207
    
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   208
    /*  structure_element_name ':' *_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   209
    void *visit(structure_element_declaration_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   210
    
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   211
    /* helper symbol for structure_initialization */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   212
    /* structure_initialization: '(' structure_element_initialization_list ')' */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   213
    /* structure_element_initialization_list ',' structure_element_initialization */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   214
    void *visit(structure_element_initialization_list_c *symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   215
    
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   216
    /*  structure_element_name ASSIGN value */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   217
    void *visit(structure_element_initialization_c *symbol);
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
    /*  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
   220
    /*
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   221
     * NOTE:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   222
     * (Summary: Contrary to what is expected, the
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   223
     *           string_type_declaration_c is not used to store
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   224
     *           simple string type declarations that do not include
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   225
     *           size limits.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   226
     *           For e.g.:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   227
     *             str1_type: STRING := "hello!"
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   228
     *           will be stored in a simple_type_declaration_c
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   229
     *           instead of a string_type_declaration_c.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   230
     *           The following:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   231
     *             str2_type: STRING [64] := "hello!"
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   232
     *           will be stored in a sring_type_declaration_c
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   233
     *
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   234
     *           Read on for why this is done...
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   235
     * End Summary)
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
     * According to the spec, the valid construct
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   238
     * TYPE new_str_type : STRING := "hello!"; END_TYPE
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   239
     * has two possible routes to type_declaration...
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
     * Route 1:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   242
     * type_declaration: single_element_type_declaration
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   243
     * single_element_type_declaration: simple_type_declaration
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   244
     * simple_type_declaration: identifier ':' simple_spec_init
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   245
     * simple_spec_init: simple_specification ASSIGN constant
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   246
     * (shift:  identifier <- 'new_str_type')
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   247
     * simple_specification: elementary_type_name
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   248
     * elementary_type_name: STRING
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   249
     * (shift: elementary_type_name <- STRING)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   250
     * (reduce: simple_specification <- elementary_type_name)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   251
     * (shift: constant <- "hello!")
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   252
     * (reduce: simple_spec_init: simple_specification ASSIGN constant)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   253
     * (reduce: ...)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   254
     *
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
     * Route 2:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   257
     * type_declaration: string_type_declaration
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   258
     * 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
   259
     * (shift:  identifier <- 'new_str_type')
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   260
     * elementary_string_type_name: STRING
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   261
     * (shift: elementary_string_type_name <- STRING)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   262
     * (shift: string_type_declaration_size <-  empty )
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   263
     * string_type_declaration_init: ASSIGN character_string
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   264
     * (shift: character_string <- "hello!")
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   265
     * (reduce: string_type_declaration_init <- ASSIGN character_string)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   266
     * (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
   267
     * (reduce: type_declaration <- string_type_declaration)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   268
     *
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
     * 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
   271
     * the most sense. Unfortunately the construct 'simple_spec_init'
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   272
     * 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
   273
     * 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
   274
     * 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
   275
     * that the above declaration gets stored in a
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   276
     * 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
   277
     * as would be expected!
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   278
     */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   279
    /*  string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
433
1355adcdad58 Add, to types symbol table, string datatypes with limited length (my_string_type: STRING[33]) (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   280
     // SYM_REF4(string_type_declaration_c,	string_type_name,
1355adcdad58 Add, to types symbol table, string datatypes with limited length (my_string_type: STRING[33]) (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   281
     //					elementary_string_type_name,
1355adcdad58 Add, to types symbol table, string datatypes with limited length (my_string_type: STRING[33]) (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   282
     //					string_type_declaration_size,
1355adcdad58 Add, to types symbol table, string datatypes with limited length (my_string_type: STRING[33]) (Thanks Andreas!)
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   283
     // 				string_type_declaration_init) /* may be == NULL! */
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   284
    void *visit(string_type_declaration_c *symbol);
925
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
   285
    
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
   286
    /* REF_TO (non_generic_type_name | function_block_type_name) */
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
   287
    void *visit(ref_spec_c *symbol);
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
   288
    /* ref_spec [ ASSIGN ref_initialization ]; */
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
   289
    void *visit(ref_spec_init_c *symbol);
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
   290
    /* identifier ':' ref_spec_init */
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
   291
    void *visit(ref_type_decl_c *symbol);
a942c55fb769 Initialise REF_TO variables to NULL.
mjsousa
parents: 762
diff changeset
   292
    
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   293
}; // type_initial_value_c
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   294
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   295
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   296