absyntax_utils/spec_init_separator.cc
author mjsousa
Sun, 14 Dec 2014 19:15:29 +0000
changeset 964 5f4dfe6670da
parent 958 7474d2cd1d6e
permissions -rwxr-xr-x
Fix bugs introduced in previous commit (once again do constant folding of all literals in type declarations)
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: 181
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
     3
 *
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 181
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
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
     6
 *
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 181
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: 181
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: 181
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: 181
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: 181
diff changeset
    11
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 181
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: 181
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: 181
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: 181
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: 181
diff changeset
    16
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 181
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: 181
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: 181
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: 181
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
 * Seperation of type specification and default value constructs
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    35
 * (for e.g. simple_spec_init_c), into a type specificiation part,
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    36
 * and a default value part.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    37
 */
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
#include "spec_init_separator.hh"
596
4efb11e44065 Add ERROR_MSG macro && move extract_XXX() functions to constant_folding.cc
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
    40
#include "../main.hh" // required for ERROR() and ERROR_MSG() macros.
4efb11e44065 Add ERROR_MSG macro && move extract_XXX() functions to constant_folding.cc
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
    41
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    42
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    43
//#define DEBUG
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    44
#ifdef DEBUG
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    45
#define TRACE(classname) printf("\n____%s____\n",classname);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    46
#else
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    47
#define TRACE(classname)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    48
#endif
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    49
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    50
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
spec_init_sperator_c *spec_init_sperator_c::get_class_instance(void) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    53
  if (NULL == class_instance)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    54
    class_instance = new spec_init_sperator_c();
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
  if (NULL == class_instance)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    57
    ERROR;
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
  return class_instance;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    60
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    61
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    62
 /* the only two public functions... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    63
symbol_c *spec_init_sperator_c::get_spec(symbol_c *spec_init) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    64
   search_what = search_spec;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    65
   return (symbol_c *)spec_init->accept(*get_class_instance());
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
symbol_c *spec_init_sperator_c::get_init(symbol_c *spec_init) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    69
   search_what = search_init;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    70
   return (symbol_c *)spec_init->accept(*get_class_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
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
/* B 1.1 - Letters, digits and identifiers */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    75
/*******************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    76
// SYM_TOKEN(identifier_c)
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 945
diff changeset
    77
/* visitor for identifier_c should no longer be necessary. All references to derived datatypes are now stored in then */
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 945
diff changeset
    78
/* AST using either poutype_identifier_c or derived_datatype_identifier_c                                             */
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 945
diff changeset
    79
void *spec_init_sperator_c::visit(                 identifier_c *symbol) { ERROR; return NULL;} /* should never occur */
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 945
diff changeset
    80
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 945
diff changeset
    81
void *spec_init_sperator_c::visit(         poutype_identifier_c *symbol) {
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 945
diff changeset
    82
  TRACE("spec_init_sperator_c::poutype_identifier_c");
945
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 912
diff changeset
    83
  switch (search_what) {
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 912
diff changeset
    84
    /* if we ever get called sith a simple identifier_c, then it must be a previously declared type... */
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 912
diff changeset
    85
    case search_spec: return symbol;
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 912
diff changeset
    86
    case search_init: return NULL;
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 912
diff changeset
    87
  }
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 912
diff changeset
    88
  ERROR; /* should never occur */
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 912
diff changeset
    89
  return NULL;
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 912
diff changeset
    90
  }
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 912
diff changeset
    91
  
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 912
diff changeset
    92
  
477393b00f95 Add support for relaxed datatype model for array datatypes.
mjsousa
parents: 912
diff changeset
    93
void *spec_init_sperator_c::visit(derived_datatype_identifier_c *symbol) {
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 945
diff changeset
    94
  TRACE("spec_init_sperator_c::derived_datatype_identifier_c");
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    95
  switch (search_what) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    96
    /* if we ever get called sith a simple identifier_c, then it must be a previously declared type... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    97
    case search_spec: return symbol;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    98
    case search_init: return NULL;
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
  ERROR; /* should never occur */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   101
  return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   102
}
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
/* B 1.3.3 - Derived data types */
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
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   109
/* simple_specification ASSIGN constant */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   110
void *spec_init_sperator_c::visit(simple_spec_init_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   111
  TRACE("spec_init_sperator_c::simple_spec_init_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   112
  switch (search_what) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   113
    case search_spec: return symbol->simple_specification;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   114
    case search_init: return symbol->constant;
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
  ERROR; /* should never occur */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   117
  return NULL;
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
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   120
/* subrange_specification ASSIGN signed_integer */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   121
void *spec_init_sperator_c::visit(subrange_spec_init_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   122
  TRACE("spec_init_sperator_c::subrange_spec_init_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   123
  switch (search_what) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   124
    case search_spec: return symbol->subrange_specification->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   125
    case search_init: return symbol->signed_integer;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   126
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   127
  ERROR; /* should never occur */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   128
  return 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
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   131
/*  integer_type_name '(' subrange')' */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   132
void *spec_init_sperator_c::visit(subrange_specification_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   133
  TRACE("spec_init_sperator_c::subrange_specification_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   134
  switch (search_what) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   135
    case search_spec: return symbol->integer_type_name;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   136
    case search_init: return NULL; /* should never occur */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   137
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   138
  ERROR; /* should never occur */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   139
  return NULL;
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
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   142
/* array_specification [ASSIGN array_initialization} */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   143
/* array_initialization may be NULL ! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   144
void *spec_init_sperator_c::visit(array_spec_init_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   145
  TRACE("spec_init_sperator_c::array_spec_init_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   146
  switch (search_what) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   147
    case search_spec: return symbol->array_specification;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   148
    case search_init: return symbol->array_initialization;
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
  return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   151
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   152
912
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   153
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   154
/* NOTE: this symbol may be used directly in implictly defined variables in VAR_TEMP!! 
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   155
 *       so we must consider it here too!
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   156
 */
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   157
void *spec_init_sperator_c::visit(array_specification_c *symbol) {
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   158
  TRACE("spec_init_sperator_c::array_spec_init_c");
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   159
  switch (search_what) {
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   160
    case search_spec: return symbol;
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   161
    case search_init: return NULL;
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   162
  }
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   163
  return NULL;
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   164
}
252a69d6ecae array_specification_c may be used as a datatype! Add it to spec_init_separator_c
mjsousa
parents: 909
diff changeset
   165
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   166
/* enumerated_specification ASSIGN enumerated_value */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   167
void *spec_init_sperator_c::visit(enumerated_spec_init_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   168
  TRACE("spec_init_sperator_c::enumerated_spec_init_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   169
  switch (search_what) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   170
    case search_spec: return symbol->enumerated_specification;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   171
    case search_init: return symbol->enumerated_value;
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
  ERROR; /* should never occur */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   174
  return NULL;
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
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   177
/* structure_type_name ASSIGN structure_initialization */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   178
/* structure_initialization may be NULL ! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   179
//SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   180
void *spec_init_sperator_c::visit(initialized_structure_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   181
  TRACE("spec_init_sperator_c::initialized_structure_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   182
  switch (search_what) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   183
    case search_spec: return symbol->structure_type_name;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   184
    case search_init: return symbol->structure_initialization;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   185
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   186
  ERROR; /* should never occur */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   187
  return NULL;
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
810
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 596
diff changeset
   190
/*  function_block_type_name ASSIGN structure_initialization */
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 596
diff changeset
   191
/* structure_initialization -> may be NULL ! */
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 596
diff changeset
   192
//SYM_REF2(fb_spec_init_c, function_block_type_name, structure_initialization)
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 596
diff changeset
   193
void *spec_init_sperator_c::visit(fb_spec_init_c *symbol) {
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 596
diff changeset
   194
  TRACE("spec_init_sperator_c::fb_spec_init_c");
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 596
diff changeset
   195
  switch (search_what) {
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 596
diff changeset
   196
    case search_spec: return symbol->function_block_type_name;
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 596
diff changeset
   197
    case search_init: return symbol->structure_initialization;
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 596
diff changeset
   198
  }
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 596
diff changeset
   199
  ERROR; /* should never occur */
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 596
diff changeset
   200
  return NULL;
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 596
diff changeset
   201
}
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   202
909
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   203
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   204
/* ref_spec:  REF_TO (non_generic_type_name | function_block_type_name) */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   205
// SYM_REF1(ref_spec_c, type_name)
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   206
void *spec_init_sperator_c::visit(ref_spec_c *symbol) {
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   207
  TRACE("spec_init_sperator_c::ref_spec_c");
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   208
  /* This visitor should never really be called, but there is no harm in including it... */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   209
  switch (search_what) {
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   210
    case search_spec: return symbol;
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   211
    case search_init: return NULL; /* should never occur */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   212
  }
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   213
  ERROR; /* should never occur */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   214
  return NULL;
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   215
}
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   216
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   217
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   218
/* For the moment, we do not support initialising reference data types */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   219
/* ref_spec_init: ref_spec [ ASSIGN ref_initialization ] */ 
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   220
/* NOTE: ref_initialization may be NULL!! */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   221
// SYM_REF2(ref_spec_init_c, ref_spec, ref_initialization)
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   222
void *spec_init_sperator_c::visit(ref_spec_init_c *symbol) {
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   223
  TRACE("spec_init_sperator_c::ref_spec_init_c");
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   224
  switch (search_what) {
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   225
    case search_spec: return symbol->ref_spec;
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   226
    case search_init: return symbol->ref_initialization;
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   227
  }
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   228
  ERROR; /* should never occur */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   229
  return NULL;
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 945
diff changeset
   230
909
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   231
}
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   232
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   233
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 810
diff changeset
   234
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   235
/******************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   236
/* B 1.4.3 - Declaration & Initialisation */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   237
/******************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   238
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   239
/* STRING '[' integer ']' 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   240
 * STRING ASSIGN single_byte_character_string
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   241
 * STRING '[' integer ']' ASSIGN single_byte_character_string
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   242
 */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   243
void *spec_init_sperator_c::visit(single_byte_string_spec_c *symbol) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   244
  TRACE("spec_init_sperator_c::single_byte_string_spec_c");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   245
  switch (search_what) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   246
    case search_spec: return symbol->string_spec;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   247
    case search_init: return symbol->single_byte_character_string;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   248
  }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   249
  ERROR; /* should never occur */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   250
  return NULL;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   251
}
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   252
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   253
/* WSTRING '[' integer ']' 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   254
 * WSTRING ASSIGN double_byte_character_string
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   255
 * WSTRING '[' integer ']' ASSIGN double_byte_character_string
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   256
 */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   257
void *spec_init_sperator_c::visit(double_byte_string_spec_c *symbol) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   258
  TRACE("spec_init_sperator_c::double_byte_string_spec_c");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   259
  switch (search_what) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   260
    case search_spec: return symbol->string_spec;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   261
    case search_init: return symbol->double_byte_character_string;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   262
  }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   263
  ERROR; /* should never occur */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   264
  return NULL;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   265
}
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   266
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   267
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   268
spec_init_sperator_c *spec_init_sperator_c ::class_instance = NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   269
spec_init_sperator_c::search_what_t spec_init_sperator_c::search_what;