1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
// ast-dump.h -- AST debug dump. -*- C++ -*-
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#ifndef GO_AST_DUMP_H
#define GO_AST_DUMP_H
#include "string-dump.h"
class Expression;
class Expression_list;
class Named_object;
class Statement;
class Gogo;
// This class implements fgo-dump-ast. the
// Abstract syntax tree dump of the Go program.
class Ast_dump_context : public String_dump
{
public:
Ast_dump_context(std::ostream* out = NULL, bool dump_subblocks = true);
// Initialize the dump context.
void
dump(Gogo*, const char* basename);
// Dump spaces to dumpfile as indentation.
void
print_indent();
// Increase current indentation for print_indent().
void
indent()
{ ++this->indent_;}
// Decrease current indentation for print_indent().
void
unindent()
{ --this->indent_;}
// Whether subblocks should be dumped or not.
bool
dump_subblocks()
{ return this->dump_subblocks_; }
// Get dump output stream.
std::ostream&
ostream()
{ return *this->ostream_;}
// Dump a Block to dump file.
void
dump_block(Block*);
// Dump a type to dump file.
void
dump_type(const Type*);
// Dump an expression to dump file.
void
dump_expression(const Expression*);
// Dump an expression list to dump file.
void
dump_expression_list(const Expression_list*, bool as_pairs = false);
// Dump a typed identifier to dump file.
void
dump_typed_identifier(const Typed_identifier*);
// Dump a typed identifier list to dump file.
void
dump_typed_identifier_list(const Typed_identifier_list*);
// Dump temporary variable name to dump file.
void
dump_temp_variable_name(const Statement*);
// Dump unamed lable name to dump file.
void
dump_label_name(const Unnamed_label*);
// Dump operator symbol to dump file.
void
dump_operator(Operator);
// Implementation of String_dump interface.
void
write_c_string(const char*);
// Implements the String_dump interface.
void
write_string(const std::string& s);
// Dump statement to stream.
static void
dump_to_stream(const Statement*, std::ostream*);
// Dump expression to stream.
static void
dump_to_stream(const Expression* expr, std::ostream* out);
private:
// Current indent level.
int indent_;
// Indentation offset.
static const int offset_;
// Whether subblocks of composite statements should be dumped or not.
bool dump_subblocks_;
// Stream on output dump file.
std::ostream* ostream_;
Gogo* gogo_;
};
#endif // GO_AST_DUMP_H
|