Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Parser/C++/syn/dumper.hh
    1| // Synopsis C++ Parser: dumper.hh header file
    2| // The TypeFormatter and Dumper classes
    3| 
    4| // $Id: dumper.hh,v 1.15 2003/01/27 06:53:37 chalky Exp $
    5| //
    6| // This file is a part of Synopsis.
    7| // Copyright (C) 2002 Stephen Davies
    8| //
    9| // Synopsis is free software; you can redistribute it and/or modify it
   10| // under the terms of the GNU General Public License as published by
   11| // the Free Software Foundation; either version 2 of the License, or
   12| // (at your option) any later version.
   13| //
   14| // This program is distributed in the hope that it will be useful,
   15| // but WITHOUT ANY WARRANTY; without even the implied warranty of
   16| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   17| // General Public License for more details.
   18| //
   19| // You should have received a copy of the GNU General Public License
   20| // along with this program; if not, write to the Free Software
   21| // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   22| // 02111-1307, USA.
   23| 
   24| #ifndef H_SYNOPSIS_CPP_DUMPER
   25| #define H_SYNOPSIS_CPP_DUMPER
   26| 
   27| #include "ast.hh"
   28| #include "type.hh"
   29| 
   30| //. Formats Types in a way suitable for output
   31| class TypeFormatter : public Types::Visitor
   32| {
   33| public:
   34|     TypeFormatter();
   35| 
   36|     //. Sets the current scope, pushing the previous onto a stack
   37|     void push_scope(const ScopedName& scope);
   38|     //. Pops the previous scope from the stack
   39|     void pop_scope();
   40| 
   41|     //
   42|     // Type Visitor
   43|     //
   44|     //. Returns a formatter string for given type.
   45|     //. The option string pointer refers to the parameter name (where
   46|     //. applicable) so that it can be put in the right place for function pointer
   47|     //. types. The pointed to pointer will be set to NULL if the identifier is
   48|     //. used
   49|     std::string format(const Types::Type*, const std::string** id = NULL);
   50|     virtual void visit_type(Types::Type*);
   51|     virtual void visit_unknown(Types::Unknown*);
   52|     virtual void visit_modifier(Types::Modifier*);
   53|     virtual void visit_named(Types::Named*);
   54|     virtual void visit_base(Types::Base*);
   55|     virtual void visit_declared(Types::Declared*);
   56|     virtual void visit_template_type(Types::Template*);
   57|     virtual void visit_parameterized(Types::Parameterized*);
   58|     virtual void visit_func_ptr(Types::FuncPtr*);
   59| 
   60| protected:
   61|     //. The Type String
   62|     std::string m_type;
   63|     //. The current scope name
   64|     ScopedName m_scope;
   65|     //. Returns the given Name relative to the current scope
   66|     std::string colonate(const ScopedName& name);
   67|     //. A stack of previous scopes
   68|     std::vector<ScopedNamem_scope_stack;
   69|     //. A pointer to the identifier for function pointers
   70|     const std::string** m_fptr_id;
   71| };
   72| 
   73| //. Dumper displays the AST to the screen
   74| class Dumper : public AST::Visitorpublic TypeFormatter
   75| {
   76| public:
   77|     Dumper();
   78| 
   79|     //. Sets to only show decls with given filename
   80|     void onlyShow(const std::string& fname);
   81| 
   82|     std::string formatParam(AST::Parameter*);
   83|     //
   84|     // AST Visitor
   85|     //
   86|     void visit(const std::vector<AST::Declaration*>&);
   87|     void visit(const std::vector<AST::Comment*>&);
   88|     virtual void visit_macro(AST::Macro*);
   89|     virtual void visit_declaration(AST::Declaration*);
   90|     virtual void visit_scope(AST::Scope*);
   91|     virtual void visit_namespace(AST::Namespace*);
   92|     virtual void visit_forward(AST::Forward*);
   93|     virtual void visit_class(AST::Class*);
   94|     virtual void visit_function(AST::Function*);
   95|     virtual void visit_variable(AST::Variable*);
   96|     virtual void visit_typedef(AST::Typedef*);
   97|     virtual void visit_enum(AST::Enum*);
   98|     virtual void visit_enumerator(AST::Enumerator*);
   99| 
  100| private:
  101|     //. The indent depth
  102|     int m_indent;
  103|     //. The indent string
  104|     std::string m_indent_string;
  105|     //. Increases indent
  106|     void indent();
  107|     //. Decreases indent
  108|     void undent();
  109|     //. Only show this filename, if set
  110|     std::string m_filename;
  111| 
  112| };
  113| 
  114| #endif // header guard
  115| // vim: set ts=8 sts=4 sw=4 et: