pyplusplus.decl_wrappers.decl_wrapper_printer

Package pyplusplus :: Package decl_wrappers :: Module decl_wrapper_printer |

# Source Code for Module pyplusplus.decl_wrappers.decl_wrapper_printer

      1  # Copyright 2004-2008 Roman Yakovenko, 2006 Allen Bierbaum, Matthias Baas
      2  # Distributed under the Boost Software License, Version 1.0. (See
      3  # accompanying file LICENSE_1_0.txt or copy at
      4  # http://www.boost.org/LICENSE_1_0.txt)
      5
      6  """defines class that will print in a user friendly format declarations tree and
      7  declarations Py++ configuration instructions"""
      8
      9  import os
     10  import sys
     11  from pygccxml import declarations
     12
     13 -class decl_wrapper_printer_t( declarations.decl_printer_t ):
     14      """ Helper class for printing declarations tree and Py++ configuration instructions"""
     15      JUSTIFY = 20
     16      INDENT_SIZE = 4
     17
     18 -    def __init__( self, level=0, print_details=True, recursive=True, writer=None ):
     19          declarations.decl_printer_t.__init__(self, level, print_details, recursive, writer)
     20
     21 -    def clone( self, increment_level=True ):
     22          level = self.level
     23          if increment_level:
     24              level += 1
     25          return decl_wrapper_printer_t(level, self.print_details, self.recursive, self.writer)
     26
     27 -    def print_decl_header(self):
     28          super( decl_wrapper_printer_t, self ).print_decl_header()
     29          if not self.print_details:
     30              return
     31          intend_txt = ' ' * (self.level+1) * self.INDENT_SIZE
     32          self.writer( intend_txt + "Alias: " + self.instance.alias + os.linesep )
     33          self.writer( intend_txt + "Ignore: " + str( self.instance.ignore ) + os.linesep )
     34          if not self.instance.ignore:
     35              msgs = self.instance.readme()
     36              if msgs:
     37                  self.writer( intend_txt + "ReadMe: " + os.linesep )
     38                  more_intend_txt = ' ' * (self.level+2) * self.INDENT_SIZE
     39                  for msg in msgs:
     40                      self.writer( more_intend_txt + msg + os.linesep )
     41
     42 -    def print_calldef_wrapper(self):
     43          if not self.print_details:
     44              return
     45          self.writer(  ' ' * (self.level+1) * self.INDENT_SIZE
     46                        + "Call policies: " + str(self.instance.call_policies) + os.linesep )
     47          self.writer(  ' ' * (self.level+1) * self.INDENT_SIZE
     48                        + "Use keywords: " + str(self.instance.use_keywords) + os.linesep )
     49          self.writer(  ' ' * (self.level+1) * self.INDENT_SIZE
     50                        + "Use signature: " + str(self.instance.create_with_signature) + os.linesep )
     51          self.writer(  ' ' * (self.level+1) * self.INDENT_SIZE
     52                        + "Use default arguments: " + str(self.instance.use_default_arguments) + os.linesep )
     53
     54 -    def visit_member_function( self ):
     55          super( decl_wrapper_printer_t, self ).visit_member_function()
     56          self.print_calldef_wrapper()
     57
     58 -    def visit_constructor( self ):
     59          super( decl_wrapper_printer_t, self ).visit_constructor()
     60          self.print_calldef_wrapper()
     61
     62 -    def visit_destructor( self ):
     63          super( decl_wrapper_printer_t, self ).visit_destructor()
     64          self.print_calldef_wrapper()
     65
     66 -    def visit_member_operator( self ):
     67          super( decl_wrapper_printer_t, self ).visit_member_operator()
     68          self.print_calldef_wrapper()
     69
     70 -    def visit_casting_operator( self ):
     71          super( decl_wrapper_printer_t, self ).visit_casting_operator()
     72          self.print_calldef_wrapper()
     73
     74 -    def visit_free_function( self ):
     75          super( decl_wrapper_printer_t, self ).visit_free_function()
     76          self.print_calldef_wrapper()
     77
     78 -    def visit_free_operator( self ):
     79          super( decl_wrapper_printer_t, self ).visit_free_operator()
     80          self.print_calldef_wrapper()
     81
     82 -    def visit_class_declaration(self ):
     83          super( decl_wrapper_printer_t, self ).visit_class_declaration()
     84
     85 -    def visit_class(self ):
     86          super( decl_wrapper_printer_t, self ).visit_class()
     87          self.writer(  ' ' * (self.level+1) * self.INDENT_SIZE
     88                        + "Expose using scope: " + str(self.instance.always_expose_using_scope) + os.linesep )
     89          self.writer(  ' ' * (self.level+1) * self.INDENT_SIZE
     90                        + "Redefine operators: " + str(self.instance.redefine_operators) + os.linesep )
     91          self.writer(  ' ' * (self.level+1) * self.INDENT_SIZE
     92                        + "Held type: " + str(self.instance.held_type) + os.linesep )
     93          self.writer(  ' ' * (self.level+1) * self.INDENT_SIZE
     94                        + "Use noncopyable: " + str(self.instance.noncopyable) + os.linesep )
     95          self.writer(  ' ' * (self.level+1) * self.INDENT_SIZE
     96                        + "Class wrapper alias: " + str(self.instance.wrapper_alias) + os.linesep )
     97
     98 -    def visit_enumeration(self):
     99          super( decl_wrapper_printer_t, self ).visit_enumeration()
    100          self.writer(  ' ' * (self.level+1) * self.INDENT_SIZE
    101                        + "Enumeration value aliases: " + str(self.instance.value_aliases) + os.linesep )
    102          self.writer(  ' ' * (self.level+1) * self.INDENT_SIZE
    103                        + "Enumeration export values: " + str(self.instance.export_values) + os.linesep )
    104
    105 -    def visit_namespace(self ):
    106          super( decl_wrapper_printer_t, self ).visit_namespace()
    107
    108 -    def visit_typedef(self ):
    109          super( decl_wrapper_printer_t, self ).visit_typedef()
    110
    111 -    def visit_variable(self ):
    112          super( decl_wrapper_printer_t, self ).visit_variable()
    113
    114 -def print_declarations( decls, detailed=True, recursive=True, writer=sys.stdout.write ):
    115      """ Print decl tree rooted at each of the included nodes.
    116          decls - either a single decl or a list of decls.
    117      """
    118      prn = decl_wrapper_printer_t(0, detailed, recursive, writer)
    119      if type(decls) is not list:
    120         decls = [decls]
    121      for d in decls:
    122         prn.level = 0
    123         prn.instance = d
    124         declarations.apply_visitor(prn, d)
    125