Synopsis - Synopsis/SymbolLookup/Display.hh

File: Synopsis/SymbolLookup/Display.hh

     1//
     2// Copyright (C) 2005 Stefan Seefeld
     3// All rights reserved.
     4// Licensed to the public under the terms of the GNU LGPL (>= 2),
     5// see the file COPYING for details.
     6//
     7#ifndef Synopsis_SymbolLookup_Display_hh_
     8#define Synopsis_SymbolLookup_Display_hh_
     9
    10#include <Synopsis/SymbolLookup.hh>
    11
    12namespace Synopsis
    13{
    14namespace SymbolLookup
    15{
    16
    17class SymbolDisplay : private SymbolVisitor
    18{
    19public:
    20  SymbolDisplay(std::ostream &os, size_t indent)
    21    : my_os(os), my_indent(indent, ' ') {}
    22  void display(PTree::Encoding const &, SymbolLookup::Symbol const *);
    23private:
    24  std::ostream &prefix(std::string const &type)
    25  { return my_os << my_indent << type;}
    26  virtual void visit(SymbolLookup::Symbol const *);
    27  virtual void visit(SymbolLookup::VariableName const *);
    28  virtual void visit(SymbolLookup::ConstName const *);
    29  virtual void visit(SymbolLookup::TypeName const *);
    30  virtual void visit(SymbolLookup::TypedefName const *);
    31  virtual void visit(SymbolLookup::ClassName const *);
    32  virtual void visit(SymbolLookup::EnumName const *);
    33  virtual void visit(SymbolLookup::ClassTemplateName const *);
    34  virtual void visit(SymbolLookup::FunctionName const *);
    35  virtual void visit(SymbolLookup::FunctionTemplateName const *);
    36  virtual void visit(SymbolLookup::NamespaceName const *);
    37
    38  std::ostream &my_os;
    39  std::string   my_indent;
    40  std::string   my_name;
    41};
    42
    43//. The ScopeDisplay class provides an annotated view of the symbol table,
    44//. for debugging purposes.
    45class ScopeDisplay : private SymbolLookup::ScopeVisitor
    46{
    47public:
    48  ScopeDisplay(std::ostream &os) : my_os(os), my_indent(0) {}
    49  virtual ~ScopeDisplay() {}
    50  void display(SymbolLookup::Scope const *s)
    51  { const_cast<SymbolLookup::Scope *>(s)->accept(this);}
    52private:
    53  virtual void visit(SymbolLookup::TemplateParameterScope *);
    54  virtual void visit(SymbolLookup::LocalScope *);
    55  virtual void visit(SymbolLookup::PrototypeScope *);
    56  virtual void visit(SymbolLookup::FunctionScope *);
    57  virtual void visit(SymbolLookup::Class *);
    58  virtual void visit(SymbolLookup::Namespace *);
    59
    60  void dump(SymbolLookup::Scope const *);
    61  std::ostream &indent();
    62
    63  std::ostream &my_os;
    64  size_t        my_indent;
    65};
    66
    67inline void display(SymbolLookup::Scope const *s, std::ostream &os)
    68{
    69  ScopeDisplay sd(os);
    70  sd.display(s);
    71}
    72
    73}
    74}
    75
    76#endif

Generated on Thu Apr 16 16:28:02 2009 by
synopsis (version devel)