absyntax_utils/get_sizeof_datatype.cc
author Mario de Sousa <msousa@fe.up.pt>
Fri, 01 Apr 2011 10:47:24 +0100
changeset 265 4d222f46f8cc
parent 257 90782e241346
child 279 c0453b7f99df
permissions -rwxr-xr-x
Updating license info (with Edouard's permission for relevant files).
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     1
/*
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     3
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     4
 *  Copyright (C) 2009-2011  Mario de Sousa (msousa@fe.up.pt)
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     5
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     6
 *  This program is free software: you can redistribute it and/or modify
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     7
 *  it under the terms of the GNU General Public License as published by
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     8
 *  the Free Software Foundation, either version 3 of the License, or
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
     9
 *  (at your option) any later version.
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    10
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    11
 *  This program is distributed in the hope that it will be useful,
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    14
 *  GNU General Public License for more details.
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    15
 *
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    16
 *  You should have received a copy of the GNU General Public License
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    18
 *
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    19
 *
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    20
 * This code is made available on the understanding that it will not be
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    21
 * used in safety-critical situations without a full and competent review.
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    22
 */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    23
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    24
/*
265
4d222f46f8cc Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    25
 * An IEC 61131-3 compiler.
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    26
 *
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    27
 * Based on the
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    28
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    29
 *
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    30
 */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    31
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    32
/* Determine the size, in bits, of the data type.
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    33
 * 
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    34
 * NOTE: Currently, only elementary data types with well defined sizes (in the standard) are supported.
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    35
 *       - derived data types are not supported, and these will return 0
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    36
 *       - TIME, DATE, TIME_OF_DAY, and DATE_AND_TIME are not supported, and will return 0
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    37
 *       - STRING and WSTRING are not supported, and the standard merely defines bit per character,
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    38
 *              and not the maximum number of characters, so these will return 0
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    39
 *
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    40
 *       We also support the 'Numeric Literals' Data types.
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    41
 *       i.e., numeric literals are considerd basic data types
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    42
 *       as their data type is undefined (e.g. the datat type of '30'
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    43
 *       could be 'INT' or 'SINT' or 'LINT' or 'USINT' or ...
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    44
 *       NOTE: for base 10 numeric literals, any number taking up more than 64 bits
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    45
 *             will only return a bitsize of 1024!
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    46
 *
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    47
 *       For numeric literals, we return the minimum number of bits
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    48
 *       required to store the value.
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    49
 *
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    50
 * E.g. TYPE new_int_t : INT; END_TYPE;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    51
 *      TYPE new_int2_t : INT = 2; END_TYPE;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    52
 *      TYPE new_subr_t : INT (4..5); END_TYPE;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    53
 *
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    54
 *    sizeof(SINT) ->  8
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    55
 *    sizeof(INT)  -> 16
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    56
 *    sizeof(DINT) -> 32
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    57
 *    sizeof(LINT) -> 64
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    58
 *
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    59
 *    sizeof('1')       ->  1
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    60
 *    sizeof('015')     ->  4    # Leading zeros are ignored!
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    61
 *    sizeof('0')       ->  1    # This is a special case! Even the value 0 needs at least 1 bit to store!
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    62
 *    sizeof('16')      ->  5
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    63
 *    sizeof('2#00101') ->  3
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    64
 *    sizeof('8#334')   ->  9
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    65
 *    sizeof('16#2A')   ->  8
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    66
 *
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    67
 *    sizeof('7.4')     ->  32   # all real literals return 32 bits, the size of a 'REAL'
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    68
 *                               # TODO: study IEC 60559 for the range of values that may be
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    69
 *                               #       stored in a REAL (basic single width floating point format)
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    70
 *                               #       and in a LREAL (basic double width floating point format)
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    71
 *                               #       and see if some real literals need to return 64 instead!
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    72
 */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    73
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    74
#include "get_sizeof_datatype.hh"
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    75
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    76
#include <stdlib.h>
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    77
#include <string.h>
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    78
#include <limits.h>  // get definition of ULLONG_MAX
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    79
/* tell stdint.h we want the definition of UINT64_MAX */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    80
#define __STDC_LIMIT_MACROS
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    81
#include <stdint.h>  // get definition of uint64_t and UINT64_MAX
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    82
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    83
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    84
#define ERROR error_exit(__FILE__,__LINE__)
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    85
/* function defined in main.cc */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    86
extern void error_exit(const char *file_name, int line_no);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    87
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    88
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    89
/* This class is a singleton.
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    90
 * So we need a pointer to the singe instance...
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    91
 */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    92
get_sizeof_datatype_c *get_sizeof_datatype_c::singleton = NULL;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    93
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    94
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    95
#define _encode_int(value)   ((void *)(((char *)NULL) + value))
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    96
#define _decode_int(ptr)     (((char *)ptr) - ((char *)NULL))
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    97
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    98
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    99
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   100
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   101
/* divide a base 10 literal in a string by 2 */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   102
/* returns remainder of division (0 or 1)    */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   103
static int strdivby2(char **strptr) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   104
  char *str = *strptr;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   105
  int carry = 0;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   106
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   107
  while (*str != '\0') {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   108
    /* Assumes ASCII */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   109
    int newcarry;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   110
//     newcarry = ((*str-'0') mod 2);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   111
    newcarry = ((*str-'0') - ((*str-'0')/2)*2);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   112
    *str = (((*str-'0') + 10*carry)/2) + '0';
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   113
    carry = newcarry;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   114
    str++;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   115
  }
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   116
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   117
  /* ignore leading zeros in result... */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   118
  while (**strptr == '0') 
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   119
    (*strptr)++;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   120
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   121
  return carry;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   122
}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   123
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   124
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   125
/* Constructor for the singleton class */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   126
int get_sizeof_datatype_c::getsize(symbol_c *data_type_symbol) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   127
      if (NULL == singleton) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   128
        singleton = new get_sizeof_datatype_c;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   129
        if (NULL == singleton)
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   130
          ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   131
      }
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   132
      return _decode_int(data_type_symbol->accept(*singleton));
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   133
    }
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   134
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   135
/* Destructor for the singleton class */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   136
get_sizeof_datatype_c::~get_sizeof_datatype_c(void) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   137
      if (NULL != singleton) delete singleton;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   138
      singleton = NULL;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   139
    }
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   140
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   141
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   142
/*********************/
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   143
/* B 1.2 - Constants */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   144
/*********************/
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   145
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   146
/******************************/
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   147
/* B 1.2.1 - Numeric Literals */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   148
/******************************/
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   149
 /* Numeric literals without any explicit type cast have unknown data type, 
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   150
  * so we continue considering them as their own basic data types until
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   151
  * they can be resolved (for example, when using '30+x' where 'x' is a LINT variable, the
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   152
  * numeric literal '30' must then be considered a LINT so the ADD function may be called
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   153
  * with all inputs of the same data type.
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   154
  * If 'x' were a SINT, then the '30' would have to be a SINT too!
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   155
  */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   156
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   157
/* NOTE: all integer_c and real_c tokens will always be positive (i.e. no leading '-')
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   158
 * due to the way the source code is parsed by iec.flex.
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   159
 */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   160
void *get_sizeof_datatype_c::visit(real_c *symbol) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   161
  return _encode_int(32);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   162
}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   163
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   164
void *get_sizeof_datatype_c::visit(neg_real_c *symbol) {
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   165
  return symbol->exp->accept(*this);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   166
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   167
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   168
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   169
/* NOTE: all integer_c and real_c literal tokens will always be positive (i.e. no leading '-')
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   170
 * due to the way the source code is parsed by iec.flex.
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   171
 */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   172
void *get_sizeof_datatype_c::visit(integer_c *symbol) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   173
  int bitsize = 0;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   174
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   175
  if (NULL ==   symbol->value ) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   176
  if ('\0' == *(symbol->value)) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   177
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   178
#if 0
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   179
  char *endptr;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   180
  /* Convert the string to an unsigned 64 bit integer */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   181
  /* We can use strtoull(), but we are not guaranteed that an unsigned long long int
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   182
   * is 64 bits wide. First make sure that it is...
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   183
   *
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   184
   * We could also use the strtouq() instead, which converts
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   185
   * to a quad word (64 bits). However, this requires either GCC or BSD extensions.
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   186
   */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   187
  #ifdef strtoull // this ifdef does not work!!
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   188
    /* we have long long int, use it... */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   189
    #define ival_MAX ULLONG_MAX
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   190
    unsigned long long int ival = 0;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   191
    ival = strtoull (symbol->value, &endptr, 10 /* base */);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   192
  #else
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   193
    /* use long int ... */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   194
    #define ival_MAX ULONG_MAX
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   195
    unsigned long int ival = 0;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   196
    ival = strtoul (symbol->value, &endptr, 10 /* base */);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   197
  #endif
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   198
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   199
  #if (ival_MAX < UINT64_MAX)
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   200
  #error Largest strtoint() conversion function converts to an int less than 64 bits wide!
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   201
  #endif
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   203
  if (NULL ==  endptr) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   204
  if ('\0' != *endptr) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   205
  // TODO: return _encode_int(1024) if value takes up more than 64 bits! 
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   206
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   207
  /* determine the number of bits used... */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   208
  for (bitsize = 0; ival > 0; ival /= 2, bitsize++);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   209
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   210
  /* special case... if (value == 0) <=> (bitsize == 0), return bit size of 1 ! */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   211
  if (0 == bitsize) bitsize = 1;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   212
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   213
  return _encode_int(bitsize);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   214
#endif
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   215
  /* We could first convert from string to some kind of integer, and then
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   216
   * determine the the bitsize using integer aritmetic.
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   217
   * However, we are then limited to the bit size of the widest available integer
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   218
   * (usually 64 bits), which is not good at all!
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   219
   */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   220
  /* Let's try to determine bitsize by converting directly from the string!! */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   221
  char *sval = strdup(symbol->value);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   222
  char *oval = sval;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   223
  if (NULL ==  sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   224
  if ('\0' == *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   225
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   226
  for (bitsize = 0; *sval != '\0'; strdivby2(&sval), bitsize ++);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   227
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   228
  /* Even for (value == 0), the above loop will return bitsize == 1!, 
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   229
   * so we don't need to handle the special case...
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   230
   */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   231
  /* special case... if (value == 0) <=> (bitsize == 0), return bit size of 1 ! */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   232
  // if (0 == bitsize) bitsize = 1;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   233
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   234
  free(oval);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   235
  return _encode_int(bitsize);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   236
}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   237
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   238
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   239
void *get_sizeof_datatype_c::visit(neg_integer_c *symbol) {
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   240
  return symbol->exp->accept(*this);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   241
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   242
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   243
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   244
/* NOTE: all binary_integer_c tokens will always be positive (i.e. no leading '-')
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   245
 * due to the syntax definition of IEC 61131-3.
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   246
 */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   247
void *get_sizeof_datatype_c::visit(binary_integer_c *symbol) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   248
  const char *sval = symbol->value;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   249
  int bitsize = 0;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   250
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   251
  /* first 2 characters had better be "2#" ! */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   252
  if (NULL ==  sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   253
  if ('\0' == *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   254
  if ( '2' != *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   255
  sval++;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   256
  if ('\0' == *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   257
  if ( '#' != *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   258
  sval++;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   259
  if ('\0' == *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   260
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   261
  /* determine the number of bits used... */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   262
  for (bitsize = 0; '\0' != *sval; sval++, bitsize++) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   263
    /* consistency check: make sure we only have binary digits! */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   264
    if (('0' != *sval) && ('1' != *sval))
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   265
      ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   266
  }
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   267
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   268
  /* special case... if (value == 0) <=> (bitsize == 0), return bit size of 1 ! */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   269
  if (0 == bitsize) bitsize = 1;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   270
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   271
  return _encode_int(bitsize);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   272
}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   273
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   274
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   275
/* NOTE: all octal_integer_c tokens will always be positive (i.e. no leading '-')
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   276
 * due to the syntax definition of IEC 61131-3.
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   277
 */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   278
void *get_sizeof_datatype_c::visit(octal_integer_c *symbol) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   279
  const char *sval = symbol->value;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   280
  int bitsize = 0;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   281
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   282
  /* first 2 characters had better be "8#" ! */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   283
  if (NULL ==  sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   284
  if ('\0' == *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   285
  if ( '8' != *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   286
  sval++;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   287
  if ('\0' == *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   288
  if ( '#' != *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   289
  sval++;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   290
  if ('\0' == *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   291
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   292
  /* determine the number of bits used... */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   293
  for (bitsize = 0; '\0' != *sval; sval++, bitsize += 3 /* 3 bits per octal digit */) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   294
    /* consistency check: make sure we only have octal digits! */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   295
    /* Assumes ASCII */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   296
    if (('0' > *sval) || ('7' < *sval))
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   297
      ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   298
  }
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   299
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   300
  /* special case... if (value == 0) <=> (bitsize == 0), return bit size of 1 ! */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   301
  if (0 == bitsize) bitsize = 1;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   302
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   303
  return _encode_int(bitsize);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   304
}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   305
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   306
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   307
/* NOTE: all hex_integer_c tokens will always be positive (i.e. no leading '-')
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   308
 * due to the syntax definition of IEC 61131-3.
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   309
 */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   310
void *get_sizeof_datatype_c::visit(hex_integer_c *symbol) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   311
  const char *sval = symbol->value;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   312
  int bitsize = 0;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   313
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   314
  /* first 3 characters had better be "16#" ! */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   315
  if (NULL ==  sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   316
  if ('\0' == *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   317
  if ( '1' != *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   318
  sval++;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   319
  if ('\0' == *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   320
  if ( '6' != *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   321
  sval++;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   322
  if ('\0' == *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   323
  if ( '#' != *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   324
  sval++;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   325
  if ('\0' == *sval) ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   326
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   327
  /* determine the number of bits used... */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   328
  for (bitsize = 0; '\0' != *sval; sval++, bitsize += 4 /* 4 bits per hex digit */) {
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   329
    /* consistency check: make sure we only have hex digits! */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   330
    /* Assumes ASCII */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   331
    if (!(('0' <= *sval) && ('9' >= *sval)) && 
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   332
        !(('A' <= *sval) && ('F' >= *sval)) &&
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   333
        !(('a' <= *sval) && ('b' >= *sval)))
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   334
      ERROR;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   335
  }
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   336
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   337
  /* special case... if (value == 0) <=> (bitsize == 0), return bit size of 1 ! */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   338
  if (0 == bitsize) bitsize = 1;
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   339
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   340
  return _encode_int(bitsize);
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   341
}
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   342
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   343
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   344
/***********************************/
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   345
/* B 1.3.1 - Elementary Data Types */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   346
/***********************************/
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   347
// void *get_sizeof_datatype_c::visit(time_type_name_c *symbol) {return _encode_int(0); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   348
void *get_sizeof_datatype_c::visit(bool_type_name_c *symbol)    {return _encode_int(1); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   349
void *get_sizeof_datatype_c::visit(sint_type_name_c *symbol)    {return _encode_int(8); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   350
void *get_sizeof_datatype_c::visit(int_type_name_c *symbol)     {return _encode_int(16);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   351
void *get_sizeof_datatype_c::visit(dint_type_name_c *symbol)    {return _encode_int(32);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   352
void *get_sizeof_datatype_c::visit(lint_type_name_c *symbol)    {return _encode_int(64);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   353
void *get_sizeof_datatype_c::visit(usint_type_name_c *symbol)   {return _encode_int(8); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   354
void *get_sizeof_datatype_c::visit(uint_type_name_c *symbol)    {return _encode_int(16);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   355
void *get_sizeof_datatype_c::visit(udint_type_name_c *symbol)   {return _encode_int(32);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   356
void *get_sizeof_datatype_c::visit(ulint_type_name_c *symbol)   {return _encode_int(64);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   357
void *get_sizeof_datatype_c::visit(real_type_name_c *symbol)    {return _encode_int(32);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   358
void *get_sizeof_datatype_c::visit(lreal_type_name_c *symbol)   {return _encode_int(64);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   359
// void *get_sizeof_datatype_c::visit(date_type_name_c *symbol) {return _encode_int(0); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   360
// void *get_sizeof_datatype_c::visit(tod_type_name_c *symbol)  {return _encode_int(0); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   361
// void *get_sizeof_datatype_c::visit(dt_type_name_c *symbol)   {return _encode_int(0); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   362
void *get_sizeof_datatype_c::visit(byte_type_name_c *symbol)    {return _encode_int(8); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   363
void *get_sizeof_datatype_c::visit(word_type_name_c *symbol)    {return _encode_int(16);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   364
void *get_sizeof_datatype_c::visit(dword_type_name_c *symbol)   {return _encode_int(32);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   365
void *get_sizeof_datatype_c::visit(lword_type_name_c *symbol)   {return _encode_int(64);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   366
// void *get_sizeof_datatype_c::visit(string_type_name_c *symbol)    {return _encode_int(0); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   367
// void *get_sizeof_datatype_c::visit(wstring_type_name_c *symbol)   {return _encode_int(0); }
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   368
/******************************************************/
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   369
/* Extensions to the base standard as defined in      */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   370
/* "Safety Software Technical Specification,          */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   371
/*  Part 1: Concepts and Function Blocks,             */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   372
/*  Version 1.0 – Official Release"                   */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   373
/* by PLCopen - Technical Committee 5 - 2006-01-31    */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   374
/******************************************************/
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   375
//     void *get_sizeof_datatype_c::visit(safetime_type_name_c *symbol); {return _encode_int(0); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   376
void *get_sizeof_datatype_c::visit(safebool_type_name_c *symbol)         {return _encode_int(1); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   377
void *get_sizeof_datatype_c::visit(safesint_type_name_c *symbol)         {return _encode_int(8); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   378
void *get_sizeof_datatype_c::visit(safeint_type_name_c *symbol)          {return _encode_int(16);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   379
void *get_sizeof_datatype_c::visit(safedint_type_name_c *symbol)         {return _encode_int(32);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   380
void *get_sizeof_datatype_c::visit(safelint_type_name_c *symbol)         {return _encode_int(64);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   381
void *get_sizeof_datatype_c::visit(safeusint_type_name_c *symbol)        {return _encode_int(8); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   382
void *get_sizeof_datatype_c::visit(safeuint_type_name_c *symbol)         {return _encode_int(16);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   383
void *get_sizeof_datatype_c::visit(safeudint_type_name_c *symbol)        {return _encode_int(32);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   384
void *get_sizeof_datatype_c::visit(safeulint_type_name_c *symbol)        {return _encode_int(64);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   385
void *get_sizeof_datatype_c::visit(safereal_type_name_c *symbol)         {return _encode_int(32);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   386
void *get_sizeof_datatype_c::visit(safelreal_type_name_c *symbol)        {return _encode_int(64);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   387
//     void *get_sizeof_datatype_c::visit(safedate_type_name_c *symbol); {return _encode_int(0); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   388
//     void *get_sizeof_datatype_c::visit(safetod_type_name_c *symbol);  {return _encode_int(0); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   389
//     void *get_sizeof_datatype_c::visit(safedt_type_name_c *symbol);   {return _encode_int(0); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   390
void *get_sizeof_datatype_c::visit(safebyte_type_name_c *symbol)         {return _encode_int(8); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   391
void *get_sizeof_datatype_c::visit(safeword_type_name_c *symbol)         {return _encode_int(16);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   392
void *get_sizeof_datatype_c::visit(safedword_type_name_c *symbol)        {return _encode_int(32);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   393
void *get_sizeof_datatype_c::visit(safelword_type_name_c *symbol)        {return _encode_int(64);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   394
//     void *get_sizeof_datatype_c::visit(safestring_type_name_c *symbol);  {return _encode_int(0); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   395
//     void *get_sizeof_datatype_c::visit(safewstring_type_name_c *symbol); {return _encode_int(0); }
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   396
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   397
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   398
/********************************/
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   399
/* B 1.3.3 - Derived data types */
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   400
/********************************/
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   401
// Not yet supported...