absyntax_utils/debug_ast.cc
author Mario de Sousa <msousa@fe.up.pt>
Fri, 02 Feb 2018 18:31:40 +0000
changeset 1068 222879991f44
parent 1052 f91488700835
child 1101 f7a0e962650d
permissions -rw-r--r--
improve performance of some extensible Standard Functions (ADD, MUL, AND, OR, XOR) -- Add comments!!
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) {
1052
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   123
  fprintf(stderr, "(%s->%03d:%03d..%03d:%03d) \t%s", symbol->first_file, symbol->first_line, symbol->first_column, symbol->last_line, symbol->last_column, symbol->absyntax_cname());
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   124
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   125
  if ((NULL != symbol->token) && (NULL != symbol->token->value))
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   126
    fprintf(stderr, "(%s)", symbol->token->value);
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   127
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   128
  fprintf(stderr, "\t  datatype=");
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   129
  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
   130
    fprintf(stderr, "NULL\t\t");
735
0304ff59fd7f Fix some important clang++ warnings.
Manuele Conti <conti.ma@alice.it>
parents: 731
diff changeset
   131
  else {
1052
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   132
    fprintf(stderr, "%s", symbol->datatype->absyntax_cname());
735
0304ff59fd7f Fix some important clang++ warnings.
Manuele Conti <conti.ma@alice.it>
parents: 731
diff changeset
   133
  }
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   134
  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
   135
  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
   136
    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
   137
  } 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
   138
    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
   139
      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
   140
        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
   141
      else
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, "\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
   143
  } else {
736
a591ed23c370 Fix warnings previous change introduced when compiling with gcc.
Mario de Sousa <msousa@fe.up.pt>
parents: 735
diff changeset
   144
    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
   145
  }
979
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   146
  fprintf(stderr, "}\t ");         
731
151f0b57b4e4 Print const values of symbol.
Mario de Sousa <msousa@fe.up.pt>
parents: 725
diff changeset
   147
  
151f0b57b4e4 Print const values of symbol.
Mario de Sousa <msousa@fe.up.pt>
parents: 725
diff changeset
   148
  /* print the const values... */
979
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   149
  dump_cvalue(symbol->const_value);
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   150
  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
   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
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   155
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
   156
   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
   157
736
a591ed23c370 Fix warnings previous change introduced when compiling with gcc.
Mario de Sousa <msousa@fe.up.pt>
parents: 735
diff changeset
   158
   /* 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. */
1052
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   159
  fprintf(stderr, "  prev_il_=%lu ", (unsigned long int)symbol->prev_il_instruction.size());
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   160
  if (symbol->prev_il_instruction.size() == 0)
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   161
    fprintf(stderr, "(----)");
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   162
  else if (symbol->prev_il_instruction[0]->datatype == NULL)
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   163
    fprintf(stderr, "(NULL)");
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   164
  else if (!get_datatype_info_c::is_type_valid(symbol->prev_il_instruction[0]->datatype))
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   165
    fprintf(stderr, "(****)");
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   166
  else
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   167
    fprintf(stderr, "(    )");
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   168
736
a591ed23c370 Fix warnings previous change introduced when compiling with gcc.
Mario de Sousa <msousa@fe.up.pt>
parents: 735
diff changeset
   169
  fprintf(stderr, "  next_il_=%lu ", (unsigned long int)symbol->next_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
   170
  if (symbol->next_il_instruction.size() == 0)
1052
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   171
    fprintf(stderr, "(----)");
678
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 (symbol->next_il_instruction[0]->datatype == NULL)
1052
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   173
    fprintf(stderr, "(NULL)");
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   174
  else if (!get_datatype_info_c::is_type_valid(symbol->next_il_instruction[0]->datatype))
1052
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   175
    fprintf(stderr, "(****)");
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   176
  else 
1052
f91488700835 Debugging helper class: print value of tokens in debugging output.
Mario de Sousa <msousa@fe.up.pt>
parents: 979
diff changeset
   177
    fprintf(stderr, "(    )");
678
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
  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
   180
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   181
  return 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
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   185
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   186
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   187
725
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
/* Class to print an AST         */
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   190
/*********************************/
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
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
   193
  public:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   194
    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
   195
    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
   196
    
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   197
  protected:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   198
    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
   199
    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
   200
  
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   201
  private:
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   202
    static print_ast_c *singleton;    
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   203
};
678
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
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
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
   209
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   210
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   211
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
   212
  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
   213
  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
   214
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   215
  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
   216
}
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   217
725
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 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
   220
  fprintf(stderr, "%s", str);
725
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
678
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   223
  
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   224
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
   225
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
   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
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   229
01e33dc2a255 Add classes to print status of AST (use only for debugging!)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   230
725
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
/* The DEBUG class               */
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
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   237
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   238
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
   239
  fprintf(stderr, "%s", str);
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   240
}
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   241
979
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   242
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
   243
  dump_cvalue(cvalue);
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   244
}
f8f1d89ff7d5 Add debug_c::print(const_value_c) for printing of const values.
mjsousa
parents: 965
diff changeset
   245
725
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   246
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
   247
  print_symbol_c::print(symbol);
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   248
}
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   249
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   250
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
   251
  print_ast_c::print(symbol);
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
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   256
bfbe4aca6b77 Change the public interface to debug functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 678
diff changeset
   257