Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Parser/C++/syn/synopsis.hh
    1| // Synopsis C++ Parser: synopsis.hh
    2| // Definition of the Synopsis class for mapping the C++ objects to Python
    3| // objects
    4| 
    5| // $Id: synopsis.hh,v 1.32 2003/01/27 06:53:37 chalky Exp $
    6| //
    7| // This file is a part of Synopsis.
    8| // Copyright (C) 2002 Stephen Davies
    9| //
   10| // Synopsis is free software; you can redistribute it and/or modify it
   11| // under the terms of the GNU General Public License as published by
   12| // the Free Software Foundation; either version 2 of the License, or
   13| // (at your option) any later version.
   14| //
   15| // This program is distributed in the hope that it will be useful,
   16| // but WITHOUT ANY WARRANTY; without even the implied warranty of
   17| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   18| // General Public License for more details.
   19| //
   20| // You should have received a copy of the GNU General Public License
   21| // along with this program; if not, write to the Free Software
   22| // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   23| // 02111-1307, USA.
   24| 
   25| #ifndef H_SYNOPSIS_CPP_SYNOPSIS
   26| #define H_SYNOPSIS_CPP_SYNOPSIS
   27| 
   28| #include <iostream>
   29| #include <string>
   30| #include <vector>
   31| #include <list>
   32| #include <stack>
   33| #ifdef PYTHON_INCLUDE
   34| #  include PYTHON_INCLUDE
   35| #else
   36| #  include <Python.h>
   37| #endif
   38| #include "ast.hh"
   39| #include "type.hh"
   40| 
   41| #if DEBUG
   42| #define DO_TRACE
   43| class Trace
   44| {
   45| public:
   46|     Trace(const std::string &s) : scope(s)
   47|     {
   48|         std::cout << indent() << "entering " << scope << std::endl;
   49|         ++level;
   50|     }
   51|     ~Trace()
   52|     {
   53|         --level;
   54|         std::cout << indent() << "leaving " << scope << std::endl;
   55|     }
   56| private:
   57|     std::string indent()
   58|     {
   59|         return std::string(level, ' ');
   60|     }
   61|     static int level;
   62|     std::string scope;
   63| };
   64| #else
   65| class Trace
   66| {
   67| public:
   68|     Trace(const std::string &)
   69|     {}
   70|     ~Trace()
   71|     {}
   72| }
   73| ;
   74| #endif
   75| 
   76| class FileFilter;
   77| 
   78| //. The Synopsis class maps from C++ objects to Python objects
   79| class Synopsis : public AST::Visitorpublic Types::Visitor
   80| {
   81| public:
   82| 
   83|     Synopsis(FileFilter*, PyObject *decls, PyObject *types);
   84|     ~Synopsis();
   85| 
   86|     void translate(AST::Scope* global, PyObject* ast);
   87|     void set_builtin_decls(const AST::Declaration::vector& builtin_decls);
   88| 
   89|     //
   90|     // types from the Synopsis.Type module
   91|     //
   92|     PyObjectBase(Types::Base*);
   93|     PyObjectUnknown(Types::Named*);
   94|     PyObjectDeclared(Types::Declared*);
   95|     PyObjectDependent(Types::Dependent*);
   96|     PyObjectTemplate(Types::Template*);
   97|     PyObjectModifier(Types::Modifier*);
   98|     PyObjectArray(Types::Array*);
   99|     PyObjectParameterized(Types::Parameterized*);
  100|     PyObjectFuncPtr(Types::FuncPtr*);
  101| 
  102|     //
  103|     // types from the Synopsis.AST module
  104|     //
  105|     PyObjectSourceFile(AST::SourceFile*);
  106|     PyObjectInclude(AST::Include*);
  107|     PyObjectDeclaration(AST::Declaration*);
  108|     PyObjectMacro(AST::Macro*);
  109|     PyObjectForward(AST::Forward*);
  110|     PyObjectScope(AST::Scope*);
  111|     PyObjectNamespace(AST::Namespace*);
  112|     PyObjectInheritance(AST::Inheritance*);
  113|     PyObjectClass(AST::Class*);
  114|     PyObjectTypedef(AST::Typedef*);
  115|     PyObjectEnumerator(AST::Enumerator*);
  116|     PyObjectEnum(AST::Enum*);
  117|     PyObjectVariable(AST::Variable*);
  118|     PyObjectConst(AST::Const*);
  119|     PyObjectParameter(AST::Parameter*);
  120|     PyObjectFunction(AST::Function*);
  121|     PyObjectOperation(AST::Operation*);
  122|     PyObjectComment(AST::Comment*);
  123| 
  124|     //
  125|     // AST::Visitor methods
  126|     //
  127|     void visit_declaration(AST::Declaration*);
  128|     void visit_macro(AST::Macro*);
  129|     void visit_scope(AST::Scope*);
  130|     void visit_namespace(AST::Namespace*);
  131|     void visit_class(AST::Class*);
  132|     void visit_inheritance(AST::Inheritance*);
  133|     void visit_forward(AST::Forward*);
  134|     void visit_typedef(AST::Typedef*);
  135|     void visit_variable(AST::Variable*);
  136|     void visit_const(AST::Const*);
  137|     void visit_enum(AST::Enum*);
  138|     void visit_enumerator(AST::Enumerator*);
  139|     void visit_function(AST::Function*);
  140|     void visit_operation(AST::Operation*);
  141|     void visit_parameter(AST::Parameter*);
  142|     void visit_comment(AST::Comment*);
  143| 
  144|     //
  145|     // Types::Visitor methods
  146|     //
  147|     //void visitType(Types::Type*);
  148|     void visit_unknown(Types::Unknown*);
  149|     void visit_modifier(Types::Modifier*);
  150|     void visit_array(Types::Array*);
  151|     //void visitNamed(Types::Named*);
  152|     void visit_base(Types::Base*);
  153|     void visit_dependent(Types::Dependent*);
  154|     void visit_declared(Types::Declared*);
  155|     void visit_template_type(Types::Template*);
  156|     void visit_parameterized(Types::Parameterized*);
  157|     void visit_func_ptr(Types::FuncPtr*);
  158| 
  159| private:
  160|     //. Compiler Firewalled private data
  161|     struct Private;
  162|     friend struct Private;
  163|     Private* m;
  164| 
  165|     //.
  166|     //. helper methods
  167|     //.
  168|     void addComments(PyObject* pydecl, AST::Declaration* cdecl);
  169| 
  170|     ///////// EVERYTHING BELOW HERE SUBJECT TO REVIEW AND DELETION
  171| 
  172| 
  173|     /*
  174|     PyObject *lookupType(const std::string &, PyObject *);
  175|     PyObject *lookupType(const std::string &);
  176|     PyObject *lookupType(const std::vector<std::string>& qualified);
  177| 
  178|     static void addInheritance(PyObject *, const std::vector<PyObject *> &);
  179|     static PyObject *N2L(const std::string &);
  180|     static PyObject *V2L(const std::vector<std::string> &);
  181|     static PyObject *V2L(const std::vector<PyObject *> &);
  182|     static PyObject *V2L(const std::vector<size_t> &);
  183|     void pushClassBases(PyObject* clas);
  184|     PyObject* resolveDeclared(PyObject*);
  185|     void addDeclaration(PyObject *);
  186|     */
  187| private:
  188|     PyObjectm_ast;
  189|     PyObjectm_type;
  190|     PyObjectm_declarations;
  191|     PyObjectm_dictionary;
  192| 
  193|     FileFilter* m_filter;
  194| };
  195| 
  196| #endif
  197| // vim: set ts=8 sts=4 sw=4 et: