absyntax_utils/absyntax_utils.cc
author Mario de Sousa <msousa@fe.up.pt>
Wed, 13 Jun 2012 19:43:12 +0100
changeset 592 99a284cec1f2
parent 591 76bad7199896
child 596 4efb11e44065
permissions -rw-r--r--
Add 'dimension' parameter to subrange_c, fill it correctly, and use it.
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
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 181
diff changeset
     3
 *
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) 2009-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: 181
diff changeset
     6
 *
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
/*
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    35
 * This is the main stage 3a file.
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
 * In stage 3a some helpful symbol tables are instanciated and populated.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    38
 * These symbol tables wll then be used by stage3b and atage4 code generators.
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    39
 */
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
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    43
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    44
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    45
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    46
// #include <stdio.h>  /* required for NULL */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    47
#include <string>
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    48
#include <iostream>
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    49
#include <sstream>
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    50
#include <typeinfo>
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    51
#include <list>
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    52
#include <strings.h>
366
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
    53
#include <string.h>  /* required for strlen() */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 338
diff changeset
    54
#include <stdlib.h>  /* required for atoi() */
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents: 547
diff changeset
    55
#include <errno.h>   /* required for errno */
181
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
#include "../util/symtable.hh"
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    58
#include "../util/dsymtable.hh"
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    59
#include "../absyntax/visitor.hh"
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
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    63
//#define DEBUG
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    64
#ifdef DEBUG
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    65
#define TRACE(classname) printf("\n____%s____\n",classname);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    66
#else
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    67
#define TRACE(classname)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    68
#endif
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    69
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    70
#define ERROR error_exit(__FILE__,__LINE__)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    71
/* function defined in main.cc */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    72
extern void error_exit(const char *file_name, int line_no);
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
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
/***********************************************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    77
/***********************************************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    78
/***********************************************************************/
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
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    81
/* returns 0 if the names are equal!! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    82
/* NOTE: it must ignore case!! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    83
int compare_identifiers(symbol_c *ident1, symbol_c *ident2) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    84
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    85
  token_c *name1 = dynamic_cast<token_c *>(ident1);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    86
  token_c *name2 = dynamic_cast<token_c *>(ident2);
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
  if ((name1 == NULL) || (name2 == NULL))
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    89
    /* invalid identifiers... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    90
    return -1;
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
  if (strcasecmp(name1->value, name2->value) == 0)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    93
    return 0;
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
  /* identifiers do not match! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    96
  return 1;
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
589
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   100
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   101
  /* To allow the compiler to be portable, we cannot assume that int64_t is mapped onto long long int,
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   102
   * so we cannot call strtoll() and strtoull() in extract_int64() and extract_uint64().
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   103
   *
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   104
   * So, we create our own strtouint64() and strtoint64() functions.
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   105
   * (We actually call them matiec_strtoint64() so they will not clash with any function
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   106
   *  that may be added to the standard library in the future).
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   107
   * We actually create several of each, and let the compiler choose which is the correct one,
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   108
   * by having it resolve the call to the overloaded function. For the C++ compiler to be able
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   109
   * to resolve this ambiguity, we need to add a dummy parameter to each function!
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   110
   *
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   111
   * TODO: support platforms in which int64_t is mapped onto int !! Is this really needed?
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   112
   */
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   113
static  int64_t matiec_strtoint64 (         long      int *dummy, const char *nptr, char **endptr, int base) {return strtol  (nptr, endptr, base);}
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   114
static  int64_t matiec_strtoint64 (         long long int *dummy, const char *nptr, char **endptr, int base) {return strtoll (nptr, endptr, base);}
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   115
  
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   116
static uint64_t matiec_strtouint64(unsigned long      int *dummy, const char *nptr, char **endptr, int base) {return strtoul (nptr, endptr, base);}
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   117
static uint64_t matiec_strtouint64(unsigned long long int *dummy, const char *nptr, char **endptr, int base) {return strtoull(nptr, endptr, base);}
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   118
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   119
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 338
diff changeset
   120
/* extract the value of an integer from an integer_c object !! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 338
diff changeset
   121
/* NOTE: it must ignore underscores! */
587
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   122
int64_t extract_int64_value(symbol_c *sym, bool *overflow) {
366
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   123
  std::string str = "";
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   124
  integer_c *integer;
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   125
  neg_integer_c * neg_integer;
587
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   126
  char *endptr;
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   127
  int64_t ret;
366
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   128
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   129
  if ((integer = dynamic_cast<integer_c *>(sym)) == NULL) ERROR;
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   130
  for(unsigned int i = 0; i < strlen(integer->value); i++)
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   131
    if (integer->value[i] != '_')  str += integer->value[i];
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   132
589
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   133
  errno = 0; // since strtoXX() may legally return 0, we must set errno to 0 to detect errors correctly!
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   134
  ret = matiec_strtoint64((int64_t *)NULL, str.c_str(), &endptr, 10);
587
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   135
  if (overflow != NULL)
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   136
    *overflow = (errno == ERANGE);
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   137
  if ((errno != 0) && (errno != ERANGE))
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   138
    ERROR;
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   139
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   140
  return ret;
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   141
}
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   142
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   143
uint64_t extract_uint64_value(symbol_c *sym, bool *overflow) {
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   144
  std::string str = "";
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   145
  integer_c *integer;
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   146
  neg_integer_c * neg_integer;
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   147
  char *endptr;
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   148
  uint64_t ret;
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   149
  
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   150
  if ((integer = dynamic_cast<integer_c *>(sym)) == NULL) ERROR;
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   151
  for(unsigned int i = 0; i < strlen(integer->value); i++)
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   152
    if (integer->value[i] != '_')  str += integer->value[i];
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   153
589
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   154
  errno = 0; // since strtoXX() may legally return 0, we must set errno to 0 to detect errors correctly!
de4c2a058767 Make compiler portable (do not assume int64_t is long long int)
Mario de Sousa <msousa@fe.up.pt>
parents: 587
diff changeset
   155
  ret = matiec_strtouint64((uint64_t *)NULL, str.c_str(), &endptr, 10);
587
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   156
  if (overflow != NULL)
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   157
    *overflow = (errno == ERANGE);
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   158
  if ((errno != 0) && (errno != ERANGE))
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   159
    ERROR;
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   160
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   161
  return ret;
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 338
diff changeset
   162
}
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 338
diff changeset
   163
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   164
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   165
/* extract the value of an hex integer from an hex_integer_c object !! */
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   166
/* NOTE: it must ignore underscores! */
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents: 547
diff changeset
   167
uint64_t extract_hex_value(symbol_c *sym) {
565
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   168
  std::string str = "";
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   169
  char *endptr;
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   170
  hex_integer_c * hex_integer;
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   171
  uint64_t ret;
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   172
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   173
  if ((hex_integer = dynamic_cast<hex_integer_c *>(sym)) == NULL) ERROR;
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   174
  for(unsigned int i = 3; i < strlen(hex_integer->value); i++)
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   175
    if (hex_integer->value[i] != '_') str += hex_integer->value[i];
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   176
    
571
97b85630e496 Re-insert errno=0 before calling strtoXX() (thanks go to Manuele)
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   177
  errno = 0; // since strtoXX() may legally return 0, we must set errno to 0 to detect errors correctly!
565
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   178
  ret = strtoull(str.c_str(), &endptr, 16);
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   179
  if (errno != 0) ERROR;
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   180
8acbddf75333 Fix a few bugs of previous commit.
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
   181
  return ret;
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents: 547
diff changeset
   182
}
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents: 547
diff changeset
   183
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   184
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   185
/* extract the value of a real from an real_c object !! */
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   186
/* NOTE: it must ignore underscores! */
576
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   187
/* From iec_bison.yy
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   188
 *  real:
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   189
 *   real_token		{$$ = new real_c($1, locloc(@$));}
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   190
 * | fixed_point_token	{$$ = new real_c($1, locloc(@$));}
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   191
 *
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   192
 * From iec_flex.ll
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   193
 * {real}			{yylval.ID=strdup(yytext); return real_token;}
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   194
 * {fixed_point}		{yylval.ID=strdup(yytext); return fixed_point_token;}
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   195
 *
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   196
 * real		{integer}\.{integer}{exponent}
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   197
 * fixed_point		{integer}\.{integer}
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   198
 * exponent        [Ee]([+-]?){integer}
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   199
 * integer         {digit}((_?{digit})*)
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   200
 */
587
1ecf916cc397 Fix extract_integer_value.
Manuele Conti <conti.ma@alice.it>
parents: 576
diff changeset
   201
real64_t extract_real_value(symbol_c *sym, bool *overflow) {
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   202
  std::string str = "";
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   203
  real_c * real_sym;
576
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   204
  real64_t ret;
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   205
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   206
  if ((real_sym = dynamic_cast<real_c *>(sym)) == NULL) ERROR;
576
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   207
  for(unsigned int i = 0; i < strlen(real_sym->value); i++)
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   208
    if (real_sym->value[i] != '_') str += real_sym->value[i];
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   209
    
571
97b85630e496 Re-insert errno=0 before calling strtoXX() (thanks go to Manuele)
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   210
  errno = 0; // since strtoXX() may legally return 0, we must set errno to 0 to detect errors correctly!
568
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   211
  #if    (real64_t  == float)
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   212
    ret = strtof(str.c_str(), NULL);
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   213
  #elif  (real64_t  == double)
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   214
    ret = strtod(str.c_str(), NULL);
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   215
  #elif  (real64_t  == long_double)
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   216
    ret = strtold(str.c_str(), NULL);
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   217
  #else 
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   218
    #error Could not determine which data type is being used for real64_t (defined in absyntax.hh). Aborting!
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 567
diff changeset
   219
  #endif
576
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   220
  if (overflow != NULL)
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   221
    *overflow = (errno == ERANGE);
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   222
  if ((errno != 0) && (errno != ERANGE)) 
8368ec909825 Fix extract_real (thanks Manuele), and add check for overflow.
Mario de Sousa <msousa@fe.up.pt>
parents: 571
diff changeset
   223
    ERROR;
567
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   224
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   225
  return ret;
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   226
}
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   227
e5deeb6d4d2f create extract_real_value() in absyntax_utils. NOTE: overflows not yet handled!
Mario de Sousa <msousa@fe.up.pt>
parents: 565
diff changeset
   228
366
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   229
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   230
/***********************************************************************/
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
/***********************************************************************/
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
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
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   237
/* A symbol table with all globally declared functions... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   238
function_declaration_c null_symbol1(NULL,NULL,NULL,NULL);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   239
dsymtable_c<function_declaration_c *, &null_symbol1> function_symtable;
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
/* A symbol table with all globally declared functions block types... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   242
function_block_declaration_c null_symbol2(NULL,NULL,NULL);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   243
symtable_c<function_block_declaration_c *, &null_symbol2> function_block_type_symtable;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   244
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   245
/* A symbol table with all globally declared program types... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   246
program_declaration_c null_symbol3(NULL,NULL,NULL);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   247
symtable_c<program_declaration_c *, &null_symbol3> program_type_symtable;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   248
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   249
/* A symbol table with all user declared type definitions... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   250
/* Note that function block types and program types have their
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   251
 * own symbol tables, so do not get placed in this symbol table!
338
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   252
 *
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   253
 * The symbol_c * associated to the value will point to the data type declaration.
181
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
symbol_c null_symbol4;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   256
symtable_c<symbol_c *, &null_symbol4> type_symtable;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   257
328
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   258
/* A symbol table with all values declared for enumerated type... */
338
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   259
/* Notes:
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   260
 * - if the value is defined multiple times the value
328
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   261
 * is the null pointer.
338
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   262
 *
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   263
 * - The stored symbol_c * associated to the value points to the enumerated_type_name
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   264
 * (i.e. the name of the enumerated data type) in which the the value/identifier
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   265
 * is used/declared.
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   266
 *
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   267
 * - We could re-use the null_symbol4 object, but it is safer to use a distinct object
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   268
 *   (i.e. it might make it easier to find strange bugs).
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   269
 */
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   270
symbol_c null_symbol5;
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   271
symtable_c<symbol_c *, &null_symbol5> enumerated_value_symtable;
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   272
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   273
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   274
/***********************************************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   275
/***********************************************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   276
/***********************************************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   277
/***********************************************************************/
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
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   280
class populate_symtables_c: public iterator_visitor_c {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   281
328
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   282
  private:
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   283
	symbol_c *current_enumerated_type;
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   284
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   285
  public:
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   286
    populate_symtables_c(void) {
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   287
    	current_enumerated_type = NULL;
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   288
    };
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   289
    virtual ~populate_symtables_c(void) {}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   290
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
  public:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   293
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
  /* B.1 - Common elements */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   296
  /*************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   297
  /*******************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   298
  /* B 1.1 - Letters, digits and identifiers */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   299
  /*******************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   300
  /*********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   301
  /* B 1.2 - Constants */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   302
  /*********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   303
  /******************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   304
  /* B 1.2.1 - Numeric Literals */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   305
  /******************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   306
  /*******************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   307
  /* B.1.2.2   Character Strings */
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
  /***************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   310
  /* B 1.2.3 - Time Literals */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   311
  /***************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   312
  /************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   313
  /* B 1.2.3.1 - Duration */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   314
  /************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   315
  /************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   316
  /* B 1.2.3.2 - Time of day and Date */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   317
  /************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   318
  /**********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   319
  /* B.1.3 - Data types */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   320
  /**********************/
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
  /* B 1.3.1 - Elementary Data Types */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   323
  /***********************************/
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
  /* B.1.3.2 - Generic data types */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   326
  /********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   327
  /********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   328
  /* B 1.3.3 - Derived data types */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   329
  /********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   330
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   331
  /*  subrange_type_name ':' subrange_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   332
  void *visit(subrange_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   333
    TRACE("subrange_type_declaration_c");  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   334
    type_symtable.insert(symbol->subrange_type_name, symbol->subrange_spec_init);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   335
    return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   336
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   337
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   338
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   339
  /*  enumerated_type_name ':' enumerated_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   340
  void *visit(enumerated_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   341
    TRACE("enumerated_type_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   342
    type_symtable.insert(symbol->enumerated_type_name, symbol->enumerated_spec_init);
328
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   343
    current_enumerated_type = symbol->enumerated_type_name;
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   344
    symbol->enumerated_spec_init->accept(*this);
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   345
    current_enumerated_type = NULL;
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   346
    return NULL;
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   347
  }
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   348
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   349
  /* enumerated_specification ASSIGN enumerated_value */
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   350
  void *visit(enumerated_spec_init_c *symbol) {
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   351
    return symbol->enumerated_specification->accept(*this);
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   352
  }
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   353
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   354
  /* [enumerated_type_name '#'] identifier */
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   355
  void *visit(enumerated_value_c *symbol) {
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   356
    if (current_enumerated_type != NULL) {
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   357
      if (symbol->type != NULL) ERROR;
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   358
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   359
      symbol_c *value_type = enumerated_value_symtable.find_value(symbol->value);
338
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   360
      /* NOTE: The following condition checks whether the same identifier is used more than once
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   361
       *       when defining the enumerated values of the type declaration of the new enumerated type.
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   362
       *       If this occurs, then the program beeing compiled contains a semantic error, which
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   363
       *       must be caught and reported by the semantic analyser. However, since
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   364
       *       this code is run before the semantic analyser, we must not yet raise the ERROR (internal
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   365
       *       compiler error message).
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   366
       *       For this reason, the follosing check is commented out.
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   367
       */
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   368
      /* if (value_type == current_enumerated_type) ERROR; */
328
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   369
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   370
      if (value_type == enumerated_value_symtable.end_value())
338
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   371
	/* This identifier has not yet been used in any previous declaration of an enumeration data type.
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   372
	 * so we add it to the symbol table.
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   373
	 */
328
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   374
        enumerated_value_symtable.insert(symbol->value, current_enumerated_type);
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   375
      else if (value_type != NULL)
338
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   376
	/* This identifier has already been used in a previous declaration of an enumeration data type.
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   377
	 * so we set the symbol in symbol table pointing to NULL.
3037bb7e8a82 Adding some comments, and removing a check for a semantic error in code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 328
diff changeset
   378
	 */
328
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   379
        enumerated_value_symtable.set(symbol->value, NULL);
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   380
    }
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   381
    return NULL;
66cd5d9893dd Add support for finding type of a constant enumerated value and managing conflict between same identifiers defined in different enumerated data types
laurent
parents: 279
diff changeset
   382
  }
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   383
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   384
  /*  identifier ':' array_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   385
  void *visit(array_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   386
    TRACE("array_type_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   387
    type_symtable.insert(symbol->identifier, symbol->array_spec_init);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   388
    return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   389
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   390
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   391
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   392
  /*  simple_type_name ':' simple_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   393
  void *visit(simple_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   394
    TRACE("simple_type_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   395
    type_symtable.insert(symbol->simple_type_name, symbol->simple_spec_init);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   396
    return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   397
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   398
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   399
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   400
  /*  structure_type_name ':' structure_specification */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   401
  void *visit(structure_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   402
    TRACE("structure_type_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   403
    type_symtable.insert(symbol->structure_type_name, symbol->structure_specification);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   404
    return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   405
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   406
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   407
  
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: 366
diff changeset
   408
  /*  string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
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: 366
diff changeset
   409
  // 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: 366
diff changeset
   410
  //    					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: 366
diff changeset
   411
  //    					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: 366
diff changeset
   412
  //    					string_type_declaration_init) /* may be == NULL! */
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: 366
diff changeset
   413
  void *visit(string_type_declaration_c *symbol)	{
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: 366
diff changeset
   414
    TRACE("string_type_declaration_c");
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: 366
diff changeset
   415
    type_symtable.insert(symbol->string_type_name, symbol);
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: 366
diff changeset
   416
    return NULL;
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: 366
diff changeset
   417
}
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: 366
diff changeset
   418
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   419
  /*********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   420
  /* B 1.4 - Variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   421
  /*********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   422
  /********************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   423
  /* B.1.4.1   Directly Represented Variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   424
  /********************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   425
  /*************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   426
  /* B.1.4.2   Multi-element Variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   427
  /*************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   428
  /******************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   429
  /* B 1.4.3 - Declaration & Initialisation */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   430
  /******************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   431
  /**************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   432
  /* B.1.5 - Program organization units */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   433
  /**************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   434
  /***********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   435
  /* B 1.5.1 - Functions */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   436
  /***********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   437
  public:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   438
  /*   FUNCTION derived_function_name ':' elementary_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   439
  /* | FUNCTION derived_function_name ':' derived_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   440
  void *visit(function_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   441
    TRACE("function_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   442
    function_symtable.insert(symbol->derived_function_name, symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   443
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   444
    /* symbol->derived_function_name->accept(*this);  */ /* Function name */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   445
    /* symbol->type_name->accept(*this);              */ /* return data type */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   446
    /* symbol->var_declarations_list->accept(*this);  */ /* Function parameters and variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   447
    /* symbol->function_body->accept(*this);          */ /* Function body */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   448
    return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   449
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   450
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   451
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   452
  /*****************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   453
  /* B 1.5.2 - Function Blocks */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   454
  /*****************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   455
  public:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   456
  /*  FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   457
  //SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   458
  void *visit(function_block_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   459
    TRACE("function_block_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   460
    function_block_type_symtable.insert(symbol->fblock_name, symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   461
  /*
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   462
    symbol->fblock_name->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   463
    symbol->var_declarations->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   464
    symbol->fblock_body->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   465
  */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   466
    return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   467
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   468
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   469
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   470
  /**********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   471
  /* B 1.5.3 - Programs */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   472
  /**********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   473
  public:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   474
  /*  PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   475
  //SYM_REF4(program_declaration_c, program_type_name, var_declarations, function_block_body, unused)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   476
  void *visit(program_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   477
    TRACE("program_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   478
    program_type_symtable.insert(symbol->program_type_name, symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   479
  /*
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   480
    symbol->program_type_name->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   481
    symbol->var_declarations->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   482
    symbol->function_block_body->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   483
  */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   484
    return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   485
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   486
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   487
}; /* populate_symtables_c */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   488
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   489
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   490
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   491
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   492
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   493
void absyntax_utils_init(symbol_c *tree_root) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   494
  populate_symtables_c populate_symbols;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   495
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   496
  tree_root->accept(populate_symbols);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   497
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   498