absyntax_utils/absyntax_utils.cc
author Mario de Sousa <msousa@fe.up.pt>
Thu, 19 Apr 2012 19:49:11 +0100
changeset 525 77bff42a025e
parent 433 1355adcdad58
child 547 dab341e80664
permissions -rwxr-xr-x
Literals are also part of expressions!
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() */
181
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
#include "../util/symtable.hh"
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    57
#include "../util/dsymtable.hh"
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    58
#include "../absyntax/visitor.hh"
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    59
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    60
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
//#define DEBUG
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    63
#ifdef DEBUG
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    64
#define TRACE(classname) printf("\n____%s____\n",classname);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    65
#else
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    66
#define TRACE(classname)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    67
#endif
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    68
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    69
#define ERROR error_exit(__FILE__,__LINE__)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    70
/* function defined in main.cc */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    71
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
    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
/***********************************************************************/
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
/* returns 0 if the names are equal!! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    81
/* NOTE: it must ignore case!! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    82
int compare_identifiers(symbol_c *ident1, symbol_c *ident2) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    83
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    84
  token_c *name1 = dynamic_cast<token_c *>(ident1);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    85
  token_c *name2 = dynamic_cast<token_c *>(ident2);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    86
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    87
  if ((name1 == NULL) || (name2 == NULL))
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    88
    /* invalid identifiers... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    89
    return -1;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    90
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    91
  if (strcasecmp(name1->value, name2->value) == 0)
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    92
    return 0;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    93
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    94
  /* identifiers do not match! */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    95
  return 1;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
    96
}
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
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 338
diff changeset
    99
/* 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
   100
/* NOTE: it must ignore underscores! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 338
diff changeset
   101
int extract_integer(symbol_c *sym) {
366
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   102
  std::string str = "";
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   103
  integer_c *integer;
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   104
  neg_integer_c * neg_integer;
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   105
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   106
  if ((neg_integer = dynamic_cast<neg_integer_c *>(sym)) != NULL)
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   107
    return - extract_integer((integer_c *)neg_integer->exp);
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   108
  
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   109
  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
   110
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   111
  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
   112
    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
   113
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   114
  return atoi(str.c_str());
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 338
diff changeset
   115
}
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 338
diff changeset
   116
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   117
366
1aeb29ee9381 Ignore underscores when extracting value of integer.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   118
181
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
/***********************************************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   121
/***********************************************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   122
/***********************************************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   123
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   124
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   125
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   126
/* A symbol table with all globally declared functions... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   127
function_declaration_c null_symbol1(NULL,NULL,NULL,NULL);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   128
dsymtable_c<function_declaration_c *, &null_symbol1> function_symtable;
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
/* A symbol table with all globally declared functions block types... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   131
function_block_declaration_c null_symbol2(NULL,NULL,NULL);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   132
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
   133
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   134
/* A symbol table with all globally declared program types... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   135
program_declaration_c null_symbol3(NULL,NULL,NULL);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   136
symtable_c<program_declaration_c *, &null_symbol3> program_type_symtable;
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
/* A symbol table with all user declared type definitions... */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   139
/* Note that function block types and program types have their
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   140
 * 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
   141
 *
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
   142
 * 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
   143
 */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   144
symbol_c null_symbol4;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   145
symtable_c<symbol_c *, &null_symbol4> type_symtable;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   146
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
   147
/* 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
   148
/* 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
   149
 * - 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
   150
 * 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
   151
 *
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
   152
 * - 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
   153
 * (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
   154
 * 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
   155
 *
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
   156
 * - 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
   157
 *   (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
   158
 */
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
   159
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
   160
symtable_c<symbol_c *, &null_symbol5> enumerated_value_symtable;
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   161
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   162
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   163
/***********************************************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   164
/***********************************************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   165
/***********************************************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   166
/***********************************************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   167
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   168
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   169
class populate_symtables_c: public iterator_visitor_c {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   170
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
   171
  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
   172
	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
   173
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
   174
  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
   175
    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
   176
    	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
   177
    };
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   178
    virtual ~populate_symtables_c(void) {}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   179
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   180
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   181
  public:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   182
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   183
  /*************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   184
  /* B.1 - Common elements */
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
  /*******************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   187
  /* B 1.1 - Letters, digits and identifiers */
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
  /*********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   190
  /* B 1.2 - Constants */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   191
  /*********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   192
  /******************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   193
  /* B 1.2.1 - Numeric Literals */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   194
  /******************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   195
  /*******************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   196
  /* B.1.2.2   Character Strings */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   197
  /*******************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   198
  /***************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   199
  /* B 1.2.3 - Time Literals */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   200
  /***************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   201
  /************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   202
  /* B 1.2.3.1 - Duration */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   203
  /************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   204
  /************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   205
  /* B 1.2.3.2 - Time of day and Date */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   206
  /************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   207
  /**********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   208
  /* B.1.3 - Data types */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   209
  /**********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   210
  /***********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   211
  /* B 1.3.1 - Elementary Data Types */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   212
  /***********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   213
  /********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   214
  /* B.1.3.2 - Generic data types */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   215
  /********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   216
  /********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   217
  /* B 1.3.3 - Derived data types */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   218
  /********************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   219
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   220
  /*  subrange_type_name ':' subrange_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   221
  void *visit(subrange_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   222
    TRACE("subrange_type_declaration_c");  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   223
    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
   224
    return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   225
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   226
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   227
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   228
  /*  enumerated_type_name ':' enumerated_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   229
  void *visit(enumerated_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   230
    TRACE("enumerated_type_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   231
    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
   232
    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
   233
    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
   234
    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
   235
    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
   236
  }
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
   237
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
   238
  /* 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
   239
  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
   240
    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
   241
  }
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
   242
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
   243
  /* [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
   244
  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
   245
    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
   246
      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
   247
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
   248
      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
   249
      /* 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
   250
       *       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
   251
       *       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
   252
       *       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
   253
       *       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
   254
       *       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
   255
       *       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
   256
       */
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
   257
      /* 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
   258
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
   259
      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
   260
	/* 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
   261
	 * 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
   262
	 */
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
   263
        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
   264
      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
   265
	/* 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
   266
	 * 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
   267
	 */
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
   268
        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
   269
    }
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
   270
    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
   271
  }
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
  /*  identifier ':' array_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   274
  void *visit(array_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   275
    TRACE("array_type_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   276
    type_symtable.insert(symbol->identifier, symbol->array_spec_init);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   277
    return NULL;
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
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   281
  /*  simple_type_name ':' simple_spec_init */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   282
  void *visit(simple_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   283
    TRACE("simple_type_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   284
    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
   285
    return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   286
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   287
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   288
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   289
  /*  structure_type_name ':' structure_specification */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   290
  void *visit(structure_type_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   291
    TRACE("structure_type_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   292
    type_symtable.insert(symbol->structure_type_name, symbol->structure_specification);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   293
    return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   294
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   295
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   296
  
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
   297
  /*  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
   298
  // 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
   299
  //    					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
   300
  //    					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
   301
  //    					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
   302
  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
   303
    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
   304
    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
   305
    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
   306
}
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
   307
181
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
  /* B 1.4 - Variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   310
  /*********************/
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
  /* B.1.4.1   Directly Represented Variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   313
  /********************************************/
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
  /* B.1.4.2   Multi-element Variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   316
  /*************************************/
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
  /* B 1.4.3 - Declaration & Initialisation */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   319
  /******************************************/
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
  /* B.1.5 - Program organization units */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   322
  /**************************************/
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
  /* B 1.5.1 - Functions */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   325
  /***********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   326
  public:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   327
  /*   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
   328
  /* | 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
   329
  void *visit(function_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   330
    TRACE("function_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   331
    function_symtable.insert(symbol->derived_function_name, symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   332
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   333
    /* symbol->derived_function_name->accept(*this);  */ /* Function name */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   334
    /* symbol->type_name->accept(*this);              */ /* return data type */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   335
    /* symbol->var_declarations_list->accept(*this);  */ /* Function parameters and variables */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   336
    /* symbol->function_body->accept(*this);          */ /* Function body */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   337
    return NULL;
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
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   340
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   341
  /*****************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   342
  /* B 1.5.2 - Function Blocks */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   343
  /*****************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   344
  public:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   345
  /*  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
   346
  //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
   347
  void *visit(function_block_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   348
    TRACE("function_block_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   349
    function_block_type_symtable.insert(symbol->fblock_name, symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   350
  /*
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   351
    symbol->fblock_name->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   352
    symbol->var_declarations->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   353
    symbol->fblock_body->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   354
  */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   355
    return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   356
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   357
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   358
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   359
  /**********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   360
  /* B 1.5.3 - Programs */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   361
  /**********************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   362
  public:
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   363
  /*  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
   364
  //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
   365
  void *visit(program_declaration_c *symbol) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   366
    TRACE("program_declaration_c");
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   367
    program_type_symtable.insert(symbol->program_type_name, symbol);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   368
  /*
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   369
    symbol->program_type_name->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   370
    symbol->var_declarations->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   371
    symbol->function_block_body->accept(*this);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   372
  */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   373
    return NULL;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   374
  }
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   375
  
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   376
}; /* populate_symtables_c */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   377
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   378
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   379
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   380
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   381
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   382
void absyntax_utils_init(symbol_c *tree_root) {
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   383
  populate_symtables_c populate_symbols;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   384
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   385
  tree_root->accept(populate_symbols);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   386
}
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents:
diff changeset
   387