Exemplo n.º 1
0
    def build_code_creator( self
                       , module_name
                       , boost_python_ns_name='bp'
                       , create_casting_constructor=True
                       , call_policies_resolver_=None
                       , types_db=None
                       , target_configuration=None
                       , enable_indexing_suite=True
                       , doc_extractor=None):
        """
        Creates L{module_t} code creator.

        @param module_name: module name
        @type module_name: string

        @param boost_python_ns_name: boost::python namespace alias, by default
        it is 'bp'
        @type boost_python_ns_name: string

        @param call_policies_resolver_: callable, that will be invoked on every
        calldef object. It should return call policies.
        @type call_policies_resolver_: callable
        @param doc_extractor: callable, that takes as argument reference to declaration
            and returns documentation string
        @type doc_extractor: callable or None
        """
        if not create_casting_constructor:
            msg = os.linesep.join([
                      "create_casting_constructor argument is deprecated."
                    , "If want to disable boost::python::implicitly_convertible code generation, consider to use allow_implicit_conversion constructor property"
                    , ">>> mb = module_builder_t(...)"
                    , ">>> mb.constructors().allow_implicit_conversion = False"])
            warnings.warn(msg, DeprecationWarning, stacklevel=2)

            self.global_ns.constructors(allow_empty=True).allow_implicit_conversion = False

        creator = mcreator_package.creator_t( self.global_ns
                                              , module_name
                                              , boost_python_ns_name
                                              , call_policies_resolver_
                                              , types_db
                                              , target_configuration
                                              , enable_indexing_suite
                                              , doc_extractor)
        self.__code_creator = creator.create()
        self.__code_creator.replace_included_headers(self.__parsed_files)
        #I think I should ask users, what they expect
        #self.__code_creator.user_defined_directories.append( self.__working_dir )
        #map( self.__code_creator.user_defined_directories.append
        #     , self.__parsed_dirs )

        return self.__code_creator
Exemplo n.º 2
0
   def buildCreators(self, moduleName=None, filename=None, useScope=None):
      """ Build creator tree and module from the current declarations.
          See writeModule for parameter documentation.
          In normal usage the user will not call this directly.
          Return the base of the creator tree.

          @rtype: module_t
      """
      if None == self.mDeclRoot:
         self.parse()

      if self.mVerbose:
         print "Decoration time:",self._time2str(time.time()-self.mParseEndTime)
      startTime = time.time()

      if moduleName==None:
         moduleName = self.mModuleName
      if moduleName==None:
         raise ValueError, "No output module name given"
      if useScope==None:
         useScope = self.mUseScope

      # Lock the decoration interface (an attempt to decorate after this
      # call will lead to an error)
      declwrapper.decl_lock = True
      
      if self.mVerbose:
         print "Creating module code creator tree...."
         
      # Filter the exposed decl list to create a final decl list.      
#      def filter(decl):
#         expose = getattr(decl, "_expose_flag", False)
#         return expose
      
#      if self.mVerbose:
#         print "Filtering module..."
         
#      self.mFinalDecls = declarations.filtering.user_defined( self.mDeclRoot, filter)

      # The above filtering is already done in pyplusplus as it stores
      # the "ignore" flag itself. [mbaas]
         
      # Create creator.module_t for the module
      # - override the header files in create since we already know what files we used.
      maker = module_creator.creator_t(self.mDeclRoot, module_name=moduleName)      
#      maker = module_creator.creator_t(self.mFinalDecls, module_name=moduleName)      
      extmodule = maker.create(decl_headers=self.mHeaderFiles)

      # Preprocess the tree
      self._preprocessCreatorTree(extmodule)

      # Let the arg policy manager update the tree...
      self.mArgPolicyManager.updateCreators(extmodule)

      # Handle the extra creators that need added
      mod_body = extmodule.body
      for c in self.mBodyTailCreators:
         mod_body.adopt_creator(c)
      
      for c in self.mEndCreators:
         extmodule.adopt_creator(c)
         
      self.mStartCreators.reverse()
      for c in self.mStartCreators:
         extmodule.adopt_creator(c, extmodule.last_include_index()+1)
         
      for h in self.mExtraIncludes:
         extmodule.adopt_include(code_creators.include_t(h))
         
      if useScope:
         class_creators = filter( lambda c: isinstance( c, code_creators.class_t )
                                 , code_creators.make_flatten( extmodule.body.creators ) )
         for c in class_creators:
            c.always_expose_using_scope = True #better error reporting from compiler   
      
      if self.mLicense:
         extmodule._set_license(self.mLicense)

      if self.mVerbose:
         print "Code creator tree built in %s"%self._time2str(time.time()-startTime)
         
      self.mExtModule = extmodule
      return self.mExtModule
Exemplo n.º 3
0
    def buildCreators(self, moduleName=None, filename=None, useScope=None):
        """ Build creator tree and module from the current declarations.
          See writeModule for parameter documentation.
          In normal usage the user will not call this directly.
          Return the base of the creator tree.

          @rtype: module_t
      """
        if None == self.mDeclRoot:
            self.parse()

        if self.mVerbose:
            print "Decoration time:", self._time2str(time.time() -
                                                     self.mParseEndTime)
        startTime = time.time()

        if moduleName == None:
            moduleName = self.mModuleName
        if moduleName == None:
            raise ValueError, "No output module name given"
        if useScope == None:
            useScope = self.mUseScope

        # Lock the decoration interface (an attempt to decorate after this
        # call will lead to an error)
        declwrapper.decl_lock = True

        if self.mVerbose:
            print "Creating module code creator tree...."

        # Filter the exposed decl list to create a final decl list.


#      def filter(decl):
#         expose = getattr(decl, "_expose_flag", False)
#         return expose

#      if self.mVerbose:
#         print "Filtering module..."

#      self.mFinalDecls = declarations.filtering.user_defined( self.mDeclRoot, filter)

# The above filtering is already done in pyplusplus as it stores
# the "ignore" flag itself. [mbaas]

# Create creator.module_t for the module
# - override the header files in create since we already know what files we used.
        maker = module_creator.creator_t(self.mDeclRoot,
                                         module_name=moduleName)
        #      maker = module_creator.creator_t(self.mFinalDecls, module_name=moduleName)
        extmodule = maker.create(decl_headers=self.mHeaderFiles)

        # Preprocess the tree
        self._preprocessCreatorTree(extmodule)

        # Let the arg policy manager update the tree...
        self.mArgPolicyManager.updateCreators(extmodule)

        # Handle the extra creators that need added
        mod_body = extmodule.body
        for c in self.mBodyTailCreators:
            mod_body.adopt_creator(c)

        for c in self.mEndCreators:
            extmodule.adopt_creator(c)

        self.mStartCreators.reverse()
        for c in self.mStartCreators:
            extmodule.adopt_creator(c, extmodule.last_include_index() + 1)

        for h in self.mExtraIncludes:
            extmodule.adopt_include(code_creators.include_t(h))

        if useScope:
            class_creators = filter(
                lambda c: isinstance(c, code_creators.class_t),
                code_creators.make_flatten(extmodule.body.creators))
            for c in class_creators:
                c.always_expose_using_scope = True  #better error reporting from compiler

        if self.mLicense:
            extmodule._set_license(self.mLicense)

        if self.mVerbose:
            print "Code creator tree built in %s" % self._time2str(
                time.time() - startTime)

        self.mExtModule = extmodule
        return self.mExtModule