absyntax_utils/debug_ast.cc
author Mario de Sousa <msousa@fe.up.pt>
Thu, 22 Nov 2012 18:53:37 +0000
changeset 738 e47cc8c954db
parent 736 a591ed23c370
child 767 e7d6619f6145
permissions -rw-r--r--
Start to move enumeration declaration checking to its own class.
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");
735
0304ff59fd7f Fix some important clang++ warnings.
Manuele Conti <conti.ma@alice.it>
parents: 731
diff changeset
   103
  else {
0304ff59fd7f Fix some important clang++ warnings.
Manuele Conti <conti.ma@alice.it>
parents: 731
diff changeset
   104
	  fprintf(stderr, "%s", symbol->datatype->absyntax_cname());
0304ff59fd7f Fix some important clang++ warnings.
Manuele Conti <conti.ma@alice.it>
parents: 731
diff changeset
   105
  }
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   106
  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
   107
  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
   108
    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
   109
  } 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
   110
    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
   111
      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
   112
        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
   113
      else
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   114
        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
   115
  } else {
736
a591ed23c370 Fix warnings previous change introduced when compiling with gcc.
Mario de Sousa <msousa@fe.up.pt>
parents: 735
diff changeset
   116
    fprintf(stderr, "(%lu)\t\t\t\t\t", (unsigned long int)symbol->candidate_datatypes.size());
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   117
  }
731
151f0b57b4e4 Print const values of symbol.
Mario de Sousa <msousa@fe.up.pt>
parents: 725
diff changeset
   118
  fprintf(stderr, "}\t");         
151f0b57b4e4 Print const values of symbol.
Mario de Sousa <msousa@fe.up.pt>
parents: 725
diff changeset
   119
  
151f0b57b4e4 Print const values of symbol.
Mario de Sousa <msousa@fe.up.pt>
parents: 725
diff changeset
   120
  /* print the const values... */
736
a591ed23c370 Fix warnings previous change introduced when compiling with gcc.
Mario de Sousa <msousa@fe.up.pt>
parents: 735
diff changeset
   121
  fprintf(stderr, " constv{f=%f, i=%"PRId64", u=%"PRIu64", b=%d}\t", symbol->const_value._real64.value, symbol->const_value._int64.value, symbol->const_value._uint64.value, symbol->const_value._bool.value?1:0);
731
151f0b57b4e4 Print const values of symbol.
Mario de Sousa <msousa@fe.up.pt>
parents: 725
diff changeset
   122
  
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   123
}
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
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   126
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   127
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
   128
   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
   129
736
a591ed23c370 Fix warnings previous change introduced when compiling with gcc.
Mario de Sousa <msousa@fe.up.pt>
parents: 735
diff changeset
   130
   /* NOTE: std::map.size() returns a size_type, whose type is dependent on compiler/platform. To be portable, we need to do an explicit type cast. */
a591ed23c370 Fix warnings previous change introduced when compiling with gcc.
Mario de Sousa <msousa@fe.up.pt>
parents: 735
diff changeset
   131
  fprintf(stderr, "  next_il_=%lu ", (unsigned long int)symbol->next_il_instruction.size());
a591ed23c370 Fix warnings previous change introduced when compiling with gcc.
Mario de Sousa <msousa@fe.up.pt>
parents: 735
diff changeset
   132
  fprintf(stderr, "  prev_il_=%lu ", (unsigned long int)symbol->prev_il_instruction.size());
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   133
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   134
  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
   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
  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
   137
    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
   138
  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
   139
    fprintf(stderr, "(****,");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   140
  else
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   141
    fprintf(stderr, "(    ,");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   142
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   143
  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
   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
  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
   146
    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
   147
  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
   148
    fprintf(stderr, "****)");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   149
  else 
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   150
    fprintf(stderr, "    )");
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
  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
   153
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   154
  return NULL;
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   155
};
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   156
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   157
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   158
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   159
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   160
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   161
/*********************************/
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   162
/* Class to print an AST         */
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
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   165
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
   166
  public:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   167
    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
   168
    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
   169
    
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   170
  protected:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   171
    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
   172
    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
   173
  
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   174
  private:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   175
    static print_ast_c *singleton;    
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   176
};
678
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
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   179
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   180
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   181
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
   182
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
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
   185
  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
   186
  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
   187
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   188
  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
   189
}
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   190
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   191
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   192
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
   193
  fprintf(stderr, str);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   194
}
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   195
678
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
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
   198
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
   199
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   200
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   201
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   202
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   203
725
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
/* The DEBUG class               */
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   206
/*********************************/
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
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   210
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   211
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
   212
  fprintf(stderr, str);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   213
}
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   214
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   215
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
   216
  print_symbol_c::print(symbol);
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
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
   220
  print_ast_c::print(symbol);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   221
}
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   222
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   223
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   224
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   225
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   226