absyntax_utils/debug_ast.cc
author mjsousa
Sat, 06 Jun 2015 18:58:50 +0100
changeset 1001 f6ed7dcfc53e
parent 979 f8f1d89ff7d5
child 1052 f91488700835
permissions -rw-r--r--
Delete unused code.
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
979
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    52
static void dump_cvalue(const_value_c const_value) {
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    53
  fprintf(stderr, "constv{");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    54
  if      (const_value._real64.is_valid   ()) fprintf(stderr, "%f",        const_value._real64.get());
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    55
  else if (const_value._real64.is_overflow()) fprintf(stderr, "ov");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    56
  else if (const_value._real64.is_nonconst()) fprintf(stderr, "nc");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    57
  else                                        fprintf(stderr, "?");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    58
  fprintf(stderr, ", i=");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    59
  if      (const_value. _int64.is_valid   ()) fprintf(stderr, "%"PRId64"", const_value. _int64.get());
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    60
  else if (const_value. _int64.is_overflow()) fprintf(stderr, "ov");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    61
  else if (const_value. _int64.is_nonconst()) fprintf(stderr, "nc");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    62
  else                                        fprintf(stderr, "?");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    63
  fprintf(stderr, ", u=");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    64
  if      (const_value._uint64.is_valid   ()) fprintf(stderr, "%"PRIu64"", const_value._uint64.get());
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    65
  else if (const_value._uint64.is_overflow()) fprintf(stderr, "ov");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    66
  else if (const_value._uint64.is_nonconst()) fprintf(stderr, "nc");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    67
  else                                        fprintf(stderr, "?");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    68
  fprintf(stderr, ", b=");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    69
  if      (const_value.  _bool.is_valid   ()) fprintf(stderr, "%d",        const_value.  _bool.get()?1:0);
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    70
  else if (const_value.  _bool.is_overflow()) fprintf(stderr, "ov");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    71
  else if (const_value.  _bool.is_nonconst()) fprintf(stderr, "nc");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    72
  else                                        fprintf(stderr, "?");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    73
  fprintf(stderr, "}");
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    74
}
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
    75
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    76
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    77
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    78
/*********************************/
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    79
/* Class to print a symbol       */
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    80
/*********************************/
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    81
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    82
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    83
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
    84
  public:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    85
    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
    86
    
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    87
  protected:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    88
    void fcall(symbol_c *symbol);  
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    89
    /* 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
    90
    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
    91
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    92
  private:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    93
    static print_symbol_c *singleton;
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    94
    
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
    95
    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
    96
};
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    97
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    98
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
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   101
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
   102
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   103
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   104
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
   105
  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
   106
  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
   107
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   108
  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
   109
}
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   110
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   111
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   112
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   113
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   114
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   115
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
   116
  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
   117
  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
   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
979
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   121
678
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::dump_symbol(symbol_c* symbol) {
809
9204559768f1 Print filename when debugging abstract symbol table.
Mario de Sousa <msousa@fe.up.pt>
parents: 767
diff changeset
   123
  fprintf(stderr, "(%s->%03d:%03d..%03d:%03d) \t%s\t", symbol->first_file, symbol->first_line, symbol->first_column, symbol->last_line, symbol->last_column, symbol->absyntax_cname());
678
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, "  datatype=");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   126
  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
   127
    fprintf(stderr, "NULL\t\t");
735
0304ff59fd7f Fix some important clang++ warnings.
Manuele Conti <conti.ma@alice.it>
parents: 731
diff changeset
   128
  else {
0304ff59fd7f Fix some important clang++ warnings.
Manuele Conti <conti.ma@alice.it>
parents: 731
diff changeset
   129
	  fprintf(stderr, "%s", symbol->datatype->absyntax_cname());
0304ff59fd7f Fix some important clang++ warnings.
Manuele Conti <conti.ma@alice.it>
parents: 731
diff changeset
   130
  }
678
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, "\t<-{");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   132
  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
   133
    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
   134
  } 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
   135
    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
   136
      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
   137
        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
   138
      else
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, "\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
   140
  } else {
736
a591ed23c370 Fix warnings previous change introduced when compiling with gcc.
Mario de Sousa <msousa@fe.up.pt>
parents: 735
diff changeset
   141
    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
   142
  }
979
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   143
  fprintf(stderr, "}\t ");         
731
151f0b57b4e4 Print const values of symbol.
Mario de Sousa <msousa@fe.up.pt>
parents: 725
diff changeset
   144
  
151f0b57b4e4 Print const values of symbol.
Mario de Sousa <msousa@fe.up.pt>
parents: 725
diff changeset
   145
  /* print the const values... */
979
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   146
  dump_cvalue(symbol->const_value);
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   147
  fprintf(stderr, "\t");
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   148
}
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
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
   153
   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
   154
736
a591ed23c370 Fix warnings previous change introduced when compiling with gcc.
Mario de Sousa <msousa@fe.up.pt>
parents: 735
diff changeset
   155
   /* 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
   156
  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
   157
  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
   158
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   159
  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
   160
    fprintf(stderr, "(----,");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   161
  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
   162
    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
   163
  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
   164
    fprintf(stderr, "(****,");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   165
  else
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   166
    fprintf(stderr, "(    ,");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   167
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   168
  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
   169
    fprintf(stderr, "----)");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   170
  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
   171
    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
   172
  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
   173
    fprintf(stderr, "****)");
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   174
  else 
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   175
    fprintf(stderr, "    )");
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
  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
   178
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   179
  return NULL;
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
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
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   185
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   186
/*********************************/
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   187
/* Class to print an AST         */
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
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   190
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
   191
  public:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   192
    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
   193
    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
   194
    
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   195
  protected:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   196
    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
   197
    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
   198
  
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   199
  private:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   200
    static print_ast_c *singleton;    
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   201
};
678
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
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   204
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   205
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   206
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
   207
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   208
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   209
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
   210
  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
   211
  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
   212
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   213
  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
   214
}
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   215
725
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
void print_ast_c::print(const char *str) {
767
e7d6619f6145 Fix warning about call fprintf without format string.
Manuele Conti <conti.ma@alice.it>
parents: 736
diff changeset
   218
  fprintf(stderr, "%s", str);
725
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
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   221
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   222
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
   223
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
   224
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   225
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   226
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   227
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   228
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   229
/*********************************/
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   230
/* The DEBUG class               */
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   231
/*********************************/
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   232
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   233
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   234
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   235
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   236
void debug_c::print(const char *str) {
767
e7d6619f6145 Fix warning about call fprintf without format string.
Manuele Conti <conti.ma@alice.it>
parents: 736
diff changeset
   237
  fprintf(stderr, "%s", str);
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   238
}
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   239
979
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   240
void debug_c::print(const_value_c cvalue) {
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   241
  dump_cvalue(cvalue);
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   242
}
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   243
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   244
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
   245
  print_symbol_c::print(symbol);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   246
}
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   247
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   248
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
   249
  print_ast_c::print(symbol);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   250
}
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   251
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   252
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   253
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   254
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   255