Ejemplo n.º 1
0
 def has_hdf5_scheme(self, c):
     """True iif the class c has a static method std::string hdf5_scheme()"""
     keep = lambda m : CL.is_public(m)
     for m in CL.get_methods(c, True, keep):
         if m.spelling == "hdf5_scheme" and m.is_static_method() and ('string' in m.result_type.spelling) and len(list(CL.get_params(m))) == 0: 
            return True
     return False
Ejemplo n.º 2
0
    def generate_desc_file(self, output_filename, verbose=True):
        """ Makes the desc file"""

        # First treat the parameter class if any (classes passed by dictionnary that MUST be converted)
        param_cls_list = list(self.get_all_param_classes())

        # Precompute
        self.all_enums = list(self.all_enums_gen())
        self.all_classes = list(self.all_classes_gen())
        self.all_functions = list(self.all_functions_gen())
        self.param_cls_list = param_cls_list

        # checks
        for c in param_cls_list:
            for m in CL.get_members(c, True):
                assert CL.is_public(
                    m
                ), "Parameter class : all members must be public. %s::%s is not" % (
                    c.spelling, m.spelling)

        # analyse the modules and converters that need to be added
        print "Analysing dependencies"
        types_being_wrapped_or_converted = param_cls_list + self.all_classes + self.all_enums
        import_list, converters_list = self.DE(
            self.get_all_params_ret_type(param_cls_list),
            types_being_wrapped_or_converted)

        # Reporting
        if self.all_classes:
            print "Wrapping classes:"
            for c in self.all_classes:
                print "   ", c.spelling
        if self.all_enums:
            print "Wrapping enums:"
            for c in self.all_enums:
                print "   ", c.spelling
        if self.all_functions:
            print "Wrapping functions:"
            for c in self.all_functions:
                print "   ", c.spelling
        if param_cls_list:
            print "Generating converters for :"
            for c in param_cls_list:
                print "   ", c.spelling

        # Render mako
        print "Generating " + output_filename
        tpl = Template(filename=util.script_path() + '/mako/desc.py',
                       strict_undefined=True)
        rendered = tpl.render(W=self,
                              CL=CL,
                              doc=doc,
                              util=util,
                              import_list=import_list,
                              converters_list=converters_list,
                              using_list=list(self.namespaces) +
                              list(self.namespace_to_factor))
        open(output_filename,
             "w").write(util.clean_end_and_while_char(rendered))
Ejemplo n.º 3
0
 def has_hdf5_scheme(self, c):
     """True iif the class c has a static method std::string hdf5_scheme()"""
     keep = lambda m: CL.is_public(m)
     for m in CL.get_methods(c, True, keep):
         if m.spelling == "hdf5_scheme" and m.is_static_method() and (
                 'string' in m.result_type.spelling) and len(
                     list(CL.get_params(m))) == 0:
             return True
     return False
Ejemplo n.º 4
0
    def generate_desc_file(self, output_filename, verbose  = True):
        """ Makes the desc file"""
         
        # First treat the parameter class if any (classes passed by dictionnary that MUST be converted)
        param_cls_list = list(self.get_all_param_classes())
        for c in param_cls_list : 
            open('parameters_%s.rst'%c.spelling, 'w').write(doc.doc_param_dict_format(CL.get_members(c, True)))

        # Precompute
        self.all_enums     = list(self.all_enums_gen())
        self.all_classes   = list(self.all_classes_gen())
        self.all_functions = list(self.all_functions_gen())
        self.param_cls_list = param_cls_list
       
        # checks
        for c in param_cls_list:
            for m in CL.get_members(c, True):
                assert CL.is_public(m), "Parameter class : all members must be public. %s::%s is not"%(c.spelling, m.spelling) 

        # analyse the modules and converters that need to be added
        print "Analysing dependencies"
        types_being_wrapped_or_converted = param_cls_list + self.all_classes + self.all_enums 
        import_list, converters_list = self.DE(self.get_all_params_ret_type(param_cls_list), types_being_wrapped_or_converted)
        if any(map(self.has_hdf5_scheme, self.all_classes)):
            converters_list.append("triqs/cpp2py_converters/h5.hpp")
   
        # Reporting 
        if self.all_classes:
            print "Wrapping classes:"
            for c in self.all_classes: 
                print "   ", c.spelling
        if self.all_enums:
            print "Wrapping enums:"
            for c in self.all_enums: 
                print "   ", c.spelling
        if self.all_functions:
            print "Wrapping functions:"
            for c in self.all_functions: 
                print "   ", c.spelling
        if param_cls_list:
            print "Generating converters for :"
            for c in param_cls_list: 
                print "   ", c.spelling

        # Render mako
        print "Generating " + output_filename
        tpl = Template(filename= util.script_path() + '/mako/desc.py', strict_undefined = True)
        rendered = tpl.render(W = self, CL = CL, doc = doc, util = util,  
                              import_list = import_list, converters_list = converters_list, using_list = list(self.namespaces) + list(self.namespace_to_factor))
        open(output_filename, "w").write(util.clean_end_and_while_char(rendered))
Ejemplo n.º 5
0
    def get_public_methods(self, c):
        """
        Parameters
        -----------

        c:  AST node
            a cursor to a class
        
        Returns
        --------
        A list of cursors to the methods
        return : a tuple (proplist, methodlist) where proplist : a list of property_  and methodlist : the others methods
        """
        keep = lambda m : CL.is_public(m) and not CL.is_template(m) and not ("ignore_in_python" in CL.get_annotations(m)) and not m.spelling.startswith('operator')
        return CL.get_methods(c, True, keep)
Ejemplo n.º 6
0
    def get_public_methods(self, c):
        """
        Parameters
        -----------

        c:  AST node
            a cursor to a class
        
        Returns
        --------
        A list of cursors to the methods
        return : a tuple (proplist, methodlist) where proplist : a list of property_  and methodlist : the others methods
        """
        keep = lambda m: CL.is_public(m) and not m.spelling.startswith(
            'operator')
        return CL.get_methods(c, True, keep)
Ejemplo n.º 7
0
    def get_public_methods(self, c):
        """
        Parameters
        -----------

        c:  AST node
            a cursor to a class
        
        Returns
        --------
        A list of cursors to the methods
        return : a tuple (proplist, methodlist) where proplist : a list of property_  and methodlist : the others methods
        """
        keep = lambda m: CL.is_public(m) and not CL.is_template(
            m) and not ("ignore_in_python" in CL.get_annotations(m)
                        ) and not (m.spelling.startswith('operator') and not m.
                                   spelling == "operator()")
        return CL.get_methods(c, True, keep)