Beispiel #1
0
def get_decl_param_class(f):
    """ Given a node f of a function, returns the node of declaration of the param class or None"""
    if 'use_parameter_class' not in CL.get_annotations(f) : 
        return None
    p = list(CL.get_params(f))
    assert len(p) == 1, "A function/method with PARAM technique must have exacly one parameter"
    return CL.jump_to_declaration(p[0].type)
Beispiel #2
0
def get_decl_param_class(f):
    """ Given a node f of a function, returns the node of declaration of the param class or None"""
    if 'use_parameter_class' not in CL.get_annotations(f):
        return None
    p = list(CL.get_params(f))
    assert len(
        p
    ) == 1, "A function/method with PARAM technique must have exacly one parameter"
    return CL.jump_to_declaration(p[0].type)
Beispiel #3
0
    def make_h5(self, cls):

        print CL.get_annotations(cls)
        """cls : AST node for a class. Returns the h5_read/write code"""
        # FIXME : treat template !
        h5w = '\n'.join('h5_write(gr, "%s", %s);'%(x.spelling, x.spelling) for x in CL.get_members(cls, False))
        h5 = """
void h5_write(triqs::h5::group h5group, std::string const & subgroup_name, {cls_name} const &x) {{
auto gr = h5group.create_group(subgroup_name);
{h5w}
}}

void h5_read(triqs::h5::group h5group, std::string const & subgroup_name,{cls_name} &x) {{
auto gr = h5group.open_group(subgroup_name);
{h5r}
}}
        """.format(cls_name = cls.spelling, h5w = h5w, h5r = h5w.replace('write', 'read'))
        ns = ':'.join(CL.get_namespace_list(cls))
        r = "namespace %s {{\n {H5} \n}}"%ns if ns else '' "{H5}"  
        return r.format(H5 = h5)
Beispiel #4
0
 def keep_cls(self, c):
     """ 
        The filter to keep a class/struct or an enum : 
         if we a namespace list, it must be in it. 
         if we have an explicit self.classes : c must be into it
         if target_file_only it has to be in the file given to c++2py
     """
     if CL.is_template(c) or ("ignore_in_python" in CL.get_annotations(c)): return False
     if self.namespaces:
         qualified_ns = CL.get_namespace(c)
         if not any((x in qualified_ns) for x in self.namespaces) : return False
     if self.classes: 
         return c.spelling in self.classes or CL.fully_qualified(c) in self.classes
     return (c.location.file.name == self.filename) if self.target_file_only else True
Beispiel #5
0
 def keep_cls(self, c):
     """ 
        The filter to keep a class/struct or an enum : 
         if we a namespace list, it must be in it. 
         if we have an explicit self.classes : c must be into it
         else it has to be in the file given to c++2py 
     """
     if CL.is_template(c) or ("ignore_in_python" in CL.get_annotations(c)):
         return False
     if self.namespaces:
         ns = CL.get_namespace(c)
         if not any((x in ns) for x in self.namespaces): return False
     if self.classes:
         return c.spelling in self.classes or CL.fully_qualified(
             c) in self.classes
     return c.location.file.name == self.filename
Beispiel #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 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)
Beispiel #7
0
    def get_all_params_ret_type(self, param_cls_list):
        """Yields every parameters and return type of every methods and functions"""
       
        for f in self.all_functions_gen():
            yield getattr(f, 'result_type', None)
            for p in CL.get_params(f) : 
                yield p.type

        for x in itertools.chain(param_cls_list, self.all_classes_gen()): 
            for m in CL.get_members(x, False): # False : no inherited
                yield m.type
            for m in itertools.chain(CL.get_constructors(x), CL.get_methods(x)):
                # A minimal filter, do not reuse self.keep_fnt here, because the namespace is N1::N2:...::ClassName
                if CL.is_template(m) or ("ignore_in_python" in CL.get_annotations(m)): continue
                yield getattr(m, 'result_type', None)
                for p in CL.get_params(m) : 
                    yield p.type
Beispiel #8
0
    def get_all_params_ret_type(self, param_cls_list):
        """Yields every parameters and return type of every methods and functions"""

        for f in self.all_functions_gen():
            yield getattr(f, 'result_type', None)
            for p in CL.get_params(f):
                yield p.type

        for x in itertools.chain(param_cls_list, self.all_classes_gen()):
            for m in CL.get_members(x, False):  # False : no inherited
                yield m.type
            for m in itertools.chain(CL.get_constructors(x),
                                     CL.get_methods(x)):
                # A minimal filter, do not reuse self.keep_fnt here, because the namespace is N1::N2:...::ClassName
                if CL.is_template(m) or ("ignore_in_python"
                                         in CL.get_annotations(m)):
                    continue
                yield getattr(m, 'result_type', None)
                for p in CL.get_params(m):
                    yield p.type
Beispiel #9
0
def use_parameter_class(m):
    return 'use_parameter_class' in CL.get_annotations(m)
Beispiel #10
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)
Beispiel #11
0
def use_parameter_class(m): 
    return 'use_parameter_class' in CL.get_annotations(m)