absyntax_utils/debug_ast.cc
author Mario de Sousa <msousa@fe.up.pt>
Wed, 14 Nov 2012 14:03:57 +0000
changeset 728 3700fd83e5de
parent 725 bfbe4aca6b77
child 731 151f0b57b4e4
permissions -rw-r--r--
Fix datatype checking of enumerated datatype declarations. We now follow the fill->narrow algorithm correctly.
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     1
/*
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     3
 *  Copyright (C) 2012  Mario de Sousa (msousa@fe.up.pt)
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     4
 *
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     5
 *  This program is free software: you can redistribute it and/or modify
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     6
 *  it under the terms of the GNU General Public License as published by
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     7
 *  the Free Software Foundation, either version 3 of the License, or
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     8
 *  (at your option) any later version.
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     9
 *
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    10
 *  This program is distributed in the hope that it will be useful,
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    13
 *  GNU General Public License for more details.
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    14
 *
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    15
 *  You should have received a copy of the GNU General Public License
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    17
 *
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    18
 *
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    19
 * This code is made available on the understanding that it will not be
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    20
 * used in safety-critical situations without a full and competent review.
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    21
 */
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    22
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    23
/*
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    24
 * An IEC 61131-3 compiler.
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    25
 *
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    26
 * Based on the
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    27
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    28
 *
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    29
 */
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    30
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    31
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    32
/*
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    33
 * Some classes to help with debuging.
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    34
 *
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    35
 * These classes will print out the current state of a symbol or a portion of the Abstract Syntax Tree.
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    36
 */
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    37
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    38
/* TODO: Use a class similar to stage4out_c so that we can have nice indentation when printing an AST
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    39
 *       Create a template so that we can TRACE the execution of other visitor classes doing usefull work!
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    40
 */
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    41
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    42
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    43
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    44
#include <unistd.h>
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    45
#include <stdio.h>  /* required for NULL */
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    46
#include "absyntax_utils.hh"
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    47
#include "../absyntax/visitor.hh"
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    48
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    49
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    50
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    51
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    52
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    53
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    54
/*********************************/
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    55
/* Class to print a symbol       */
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    56
/*********************************/
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    57
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    58
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    59
class print_symbol_c: public fcall_visitor_c { 
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    60
  public:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    61
    static void print(symbol_c *symbol);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    62
    
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    63
  protected:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    64
    void fcall(symbol_c *symbol);  
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    65
    /* AST symbols with extra data have their own specialised methods for printing that data */
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    66
    void *visit(il_instruction_c *symbol);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    67
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    68
  private:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    69
    static print_symbol_c *singleton;
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    70
    
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    71
    void dump_symbol(symbol_c* symbol);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    72
};
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    73
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    74
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    75
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    76
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    77
print_symbol_c *print_symbol_c::singleton = NULL;
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    78
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    79
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    80
void print_symbol_c::print(symbol_c* symbol) {
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    81
  if (NULL == singleton)   singleton = new print_symbol_c();
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    82
  if (NULL == singleton)   ERROR;
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    83
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    84
  symbol->accept(*singleton);
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    85
}
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    86
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    87
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    88
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    89
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    90
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    91
void print_symbol_c::fcall(symbol_c* symbol) {
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    92
  dump_symbol(symbol);
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    93
  fprintf(stderr, "\n");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    94
}
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    95
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    96
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    97
void print_symbol_c::dump_symbol(symbol_c* symbol) {
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    98
  fprintf(stderr, "(%03d:%03d..%03d:%03d) \t%s\t", symbol->first_line, symbol->first_column, symbol->last_line, symbol->last_column, symbol->absyntax_cname());
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    99
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   100
  fprintf(stderr, "  datatype=");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   101
  if (NULL == symbol->datatype)
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   102
    fprintf(stderr, "NULL\t\t");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   103
  else 
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   104
    fprintf(stderr, symbol->datatype->absyntax_cname());
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   105
  fprintf(stderr, "\t<-{");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   106
  if (symbol->candidate_datatypes.size() == 0) {
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   107
    fprintf(stderr, "\t\t\t\t\t");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   108
  } else if (symbol->candidate_datatypes.size() <= 2) {
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   109
    for (unsigned int i = 0; i < 2; i++)
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   110
      if (i < symbol->candidate_datatypes.size())
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   111
        fprintf(stderr, " %s,", symbol->candidate_datatypes[i]->absyntax_cname());
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   112
      else
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   113
        fprintf(stderr, "\t\t\t");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   114
  } else {
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   115
    fprintf(stderr, "(%d)\t\t\t\t\t", symbol->candidate_datatypes.size());
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   116
  }
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   117
  fprintf(stderr, "}\t");          
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   118
}
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   119
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   120
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   121
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   122
void *print_symbol_c::visit(il_instruction_c *symbol) {
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   123
   dump_symbol(symbol);
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   124
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   125
  fprintf(stderr, "  next_il_=%d ", symbol->next_il_instruction.size());
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   126
  fprintf(stderr, "  prev_il_=%d ", symbol->prev_il_instruction.size());
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   127
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   128
  if (symbol->prev_il_instruction.size() == 0)
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   129
    fprintf(stderr, "(----,");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   130
  else if (symbol->prev_il_instruction[0]->datatype == NULL)
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   131
    fprintf(stderr, "(NULL,");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   132
  else if (!get_datatype_info_c::is_type_valid(symbol->prev_il_instruction[0]->datatype))
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   133
    fprintf(stderr, "(****,");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   134
  else
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   135
    fprintf(stderr, "(    ,");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   136
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   137
  if (symbol->next_il_instruction.size() == 0)
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   138
    fprintf(stderr, "----)");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   139
  else if (symbol->next_il_instruction[0]->datatype == NULL)
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   140
    fprintf(stderr, "NULL)");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   141
  else if (!get_datatype_info_c::is_type_valid(symbol->next_il_instruction[0]->datatype))
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   142
    fprintf(stderr, "****)");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   143
  else 
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   144
    fprintf(stderr, "    )");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   145
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   146
  fprintf(stderr, "\n");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   147
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   148
  return NULL;
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   149
};
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   150
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   151
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   152
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   153
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   154
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   155
/*********************************/
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   156
/* Class to print an AST         */
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   157
/*********************************/
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   158
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   159
class print_ast_c: public fcall_iterator_visitor_c { 
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   160
  public:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   161
    static void print(symbol_c *symbol);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   162
    static void print(const char *str);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   163
    
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   164
  protected:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   165
    void prefix_fcall(symbol_c *symbol);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   166
    void suffix_fcall(symbol_c *symbol);  
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   167
  
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   168
  private:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   169
    static print_ast_c *singleton;    
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   170
};
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   171
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   172
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   173
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   174
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   175
print_ast_c *print_ast_c::singleton = NULL;
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   176
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   177
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   178
void print_ast_c::print(symbol_c* symbol) {
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   179
  if (NULL == singleton)   singleton = new print_ast_c();
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   180
  if (NULL == singleton)   ERROR;
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   181
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   182
  symbol->accept(*singleton);
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   183
}
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   184
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   185
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   186
void print_ast_c::print(const char *str) {
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   187
  fprintf(stderr, str);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   188
}
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   189
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   190
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   191
void print_ast_c::prefix_fcall(symbol_c* symbol) {print_symbol_c::print(symbol);}
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   192
void print_ast_c::suffix_fcall(symbol_c* symbol) {}
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   193
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   194
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   195
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   196
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   197
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   198
/*********************************/
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   199
/* The DEBUG class               */
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   200
/*********************************/
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   201
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   202
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   203
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   204
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   205
void debug_c::print(const char *str) {
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   206
  fprintf(stderr, str);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   207
}
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   208
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   209
void debug_c::print(symbol_c *symbol) {
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   210
  print_symbol_c::print(symbol);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   211
}
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   212
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   213
void debug_c::print_ast(symbol_c *symbol) {
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   214
  print_ast_c::print(symbol);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   215
}
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   216
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   217
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   218
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   219
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   220