コード例 #1
0
    def __find_out_class_dependencies(self, class_):
        full_name = declarations.full_name
        #class depends on it's base classes
        i_depend_on_them = set(
            [full_name(base.related_class) for base in class_.bases])
        #class depends on all classes that used in function as argument
        # types and those arguments have default value
        calldefs = [
            decl for decl in declarations.make_flatten(class_)
            if isinstance(decl, declarations.calldef_t)
        ]
        for calldef in calldefs:
            for arg in calldef.arguments:
                if declarations.is_enum(arg.type):
                    top_class_inst = self.__get_top_class_inst(
                        declarations.enum_declaration(arg.type))
                    if top_class_inst:
                        i_depend_on_them.add(full_name(top_class_inst))
                    continue
                if not arg.default_value:
                    continue
                if declarations.is_pointer(
                        arg.type) and arg.default_value == 0:
                    continue
                base_type = declarations.base_type(arg.type)
                if not isinstance(base_type, declarations.declarated_t):
                    continue
                top_class_inst = self.__get_top_class_inst(
                    base_type.declaration)
                if top_class_inst:
                    i_depend_on_them.add(full_name(top_class_inst))

        if self.__include_vars:
            vars = [
                decl for decl in declarations.make_flatten(class_)
                if isinstance(decl, declarations.variable_t)
            ]
            for var in vars:
                if declarations.is_pointer(var.type):
                    continue
                base_type = declarations.base_type(var.type)
                if not isinstance(base_type, declarations.declarated_t):
                    continue
                top_class_inst = self.__get_top_class_inst(
                    base_type.declaration)
                if top_class_inst:
                    i_depend_on_them.add(full_name(top_class_inst))

        for internal_cls in class_.classes(allow_empty=True):
            internal_cls_dependencies = self.__find_out_class_dependencies(
                internal_cls)
            i_depend_on_them.update(internal_cls_dependencies)

        i_depend_on_them = list(i_depend_on_them)
        i_depend_on_them.sort()
        return i_depend_on_them
コード例 #2
0
 def test_by_location(self):
     reader = parser.source_reader_t( self.config )
     decls = reader.read_file( self.__fname )
     decls_count = len( declarations.make_flatten( decls ) )
     filtered = declarations.filtering.by_location( decls, [autoconfig.data_directory] )
     flatten_filtered = declarations.make_flatten( filtered )
     self.failUnless( len( flatten_filtered  ) != decls_count )
     for decl in flatten_filtered:
         if decl.location:
             self.failUnless( declarations.filtering.normalize_path( decl.location.file_name )
                              , self.__fpath )
     self.failUnless( declarations.find_declaration( filtered
                                                     , name='color'
                                                     , type=declarations.enumeration_t
                                                     , recursive=False) )
コード例 #3
0
def parseIncludeFile(f, define=[], includes=[], ps=4):
    global ptr_size
    ptr_size = ps

    gccxmlexe = os.getenv("GCCXML", "gccxml")
    config = parser.config_t(gccxml_path=gccxmlexe,
                             define_symbols=define,
                             include_paths=includes)

    functions = {}

    if isinstance(f, list):
        global_ns = parser.parse(f, config)
    else:
        global_ns = parser.parse([f], config)

    all_decls = declarations.make_flatten(global_ns)

    all_functions = filter(lambda decl: isinstance(decl, declarations.free_function_t), \
                           all_decls)

    for f in all_functions:
        if not f.name.startswith("__"):
            # if f.name == "ReadFileEx":
            functions[f.name] = parseFunction(f)

    return functions
コード例 #4
0
    def test_remove_va_list_tag(self):

        if "gccxml" in self.config.xml_generator:
            return True

        self.config.flags = []
        src_reader = parser.source_reader_t(self.config)
        decls = declarations.make_flatten(src_reader.read_string(self.__code))

        classes = [
            i for i in decls if isinstance(i, declarations.class_t)]

        typedefs = [
            i for i in decls if isinstance(i, declarations.typedef_t)]

        variables = [
            i for i in decls if isinstance(i, declarations.variable_t)]

        tag = "__va_list_tag"

        self.assertFalse(tag in [class_.name for class_ in classes])
        self.assertTrue("a" in [class_.name for class_ in classes])
        self.assertTrue(len(classes) == 1)

        self.assertFalse(tag in [ty.name for ty in typedefs])
        self.assertTrue(len(typedefs) == 3)

        self.assertFalse(
            tag in [var.decl_string.split("::")[1] for var in variables])
        self.assertTrue(len(variables) == 0)
コード例 #5
0
ファイル: parser.py プロジェクト: cigitalabires/processtap
def parseIncludeFile(f, define = [], includes = [], ps = 4):
    global ptr_size
    ptr_size = ps

    gccxmlexe = os.getenv("GCCXML", "gccxml")
    config = parser.config_t(gccxml_path = gccxmlexe, define_symbols = define, include_paths = includes)

    functions = {}

    if isinstance(f, list):
        global_ns = parser.parse(f, config)
    else:
        global_ns = parser.parse([f], config)
        
    all_decls = declarations.make_flatten(global_ns)

    all_functions = filter(lambda decl: isinstance(decl, declarations.free_function_t), \
                           all_decls)

    for f in all_functions:   
        if not f.name.startswith("__"):
            # if f.name == "ReadFileEx":
            functions[f.name] = parseFunction(f)
        
    return functions
コード例 #6
0
    def test_remove_va_list_tag(self):

        if "gccxml" in self.config.xml_generator:
            return True

        self.config.flags = []
        src_reader = parser.source_reader_t(self.config)
        decls = declarations.make_flatten(src_reader.read_string(self.__code))

        classes = [i for i in decls if isinstance(i, declarations.class_t)]

        typedefs = [i for i in decls if isinstance(i, declarations.typedef_t)]

        variables = [
            i for i in decls if isinstance(i, declarations.variable_t)
        ]

        tag = "__va_list_tag"

        self.assertFalse(tag in [class_.name for class_ in classes])
        self.assertTrue("a" in [class_.name for class_ in classes])
        self.assertTrue(len(classes) == 1)

        self.assertFalse(tag in [ty.name for ty in typedefs])
        self.assertTrue(len(typedefs) == 3)

        self.assertFalse(
            tag in [var.decl_string.split("::")[1] for var in variables])
        self.assertTrue(len(variables) == 0)
コード例 #7
0
    def __find_out_class_dependencies( self, class_ ):
        full_name = declarations.full_name
        #class depends on it's base classes
        i_depend_on_them = set( [ full_name( base.related_class ) for base in class_.bases ] )
        #class depends on all classes that used in function as argument
        # types and those arguments have default value
        calldefs = filter( lambda decl: isinstance( decl, declarations.calldef_t )
                           , declarations.make_flatten( class_ ))
        for calldef in calldefs:
            for arg in calldef.arguments:
                if declarations.is_enum( arg.type ):
                    top_class_inst = self.__get_top_class_inst( declarations.enum_declaration( arg.type ) )
                    if top_class_inst:
                        i_depend_on_them.add( full_name( top_class_inst ) )
                    continue
                if not arg.default_value:
                    continue
                if declarations.is_pointer( arg.type ) and arg.default_value == 0:
                    continue
                base_type = declarations.base_type( arg.type )
                if not isinstance( base_type, declarations.declarated_t ):
                    continue
                top_class_inst = self.__get_top_class_inst( base_type.declaration )
                if top_class_inst:
                    i_depend_on_them.add( full_name( top_class_inst ) )

        for internal_cls in class_.classes(allow_empty=True):
            internal_cls_dependencies = self.__find_out_class_dependencies( internal_cls )
            i_depend_on_them.update( internal_cls_dependencies )

        i_depend_on_them = list( i_depend_on_them )
        i_depend_on_them.sort()
        return i_depend_on_them
コード例 #8
0
    def test_comparison_declaration_by_declaration(self):
        parsed = parser.parse([self.header], self.config)
        copied = copy.deepcopy(parsed)
        parsed = declarations.make_flatten(parsed)
        copied = declarations.make_flatten(copied)
        parsed.sort()
        copied.sort()
        failuers = []
        for parsed_decl, copied_decl, index in \
                zip(parsed, copied, list(range(len(copied)))):

            if parsed_decl != copied_decl:
                failuers.append(("__lt__ and/or __qe__ does not working " +
                                 "properly in case of %s, %s, index %d") %
                                (parsed_decl.__class__.__name__,
                                 copied_decl.__class__.__name__, index))
        self.assertTrue(not failuers, 'Failures: ' + '\n\t'.join(failuers))
コード例 #9
0
    def test_comparison_declaration_by_declaration(self):
        parsed = parser.parse([self.header], self.config)
        copied = copy.deepcopy(parsed)
        parsed = declarations.make_flatten(parsed)
        copied = declarations.make_flatten(copied)
        parsed.sort()
        copied.sort()
        failuers = []
        for parsed_decl, copied_decl, index in \
                zip(parsed, copied, list(range(len(copied)))):

            if parsed_decl != copied_decl:
                failuers.append(
                    ("__lt__ and/or __qe__ does not working " +
                        "properly in case of %s, %s, index %d") %
                    (parsed_decl.__class__.__name__,
                        copied_decl.__class__.__name__, index))
        self.failUnless(not failuers, 'Failures: ' + '\n\t'.join(failuers))
コード例 #10
0
ファイル: patcher.py プロジェクト: glehmann/WrapITK-unstable
 def patch_it(self):
     for decl in declarations.make_flatten( self.decls ):
         if not isinstance( decl, declarations.calldef_t ):
             continue
         for arg in decl.arguments:
             if not arg.default_value:
                 continue
             fixer = self.__find_fixer( decl, arg )
             if fixer:
                 arg.default_value = fixer( decl, arg )
コード例 #11
0
 def test_recursive_derived(self):
     src_reader = parser.source_reader_t( self.config )
     decls = declarations.make_flatten( src_reader.read_string( self.__code ) )
     classes = filter( lambda inst: isinstance( inst, declarations.class_t ), decls )
     for class_ in classes:
         self.failUnless( self.__recursive_derived.has_key( class_.name  ) )
         all_derived = class_.recursive_derived
         control_derived = self.__recursive_derived[ class_.name ]
         self.failUnless( len(control_derived) == len( all_derived ) )
         all_derived_names = map( lambda hi: hi.related_class.name, all_derived )
         self.failUnless( set( all_derived_names ) == control_derived )
コード例 #12
0
 def test_recursive_bases(self):
     src_reader = parser.source_reader_t(self.config)
     decls = declarations.make_flatten(src_reader.read_string(self.__code))
     classes = filter(lambda inst: isinstance(inst, declarations.class_t),
                      decls)
     for class_ in classes:
         self.failUnless(self.__recursive_bases.has_key(class_.name))
         all_bases = class_.recursive_bases
         control_bases = self.__recursive_bases[class_.name]
         self.failUnless(len(control_bases) == len(all_bases))
         all_bases_names = map(lambda hi: hi.related_class.name, all_bases)
         self.failUnless(set(all_bases_names) == control_bases)
コード例 #13
0
 def test_recursive_bases(self):
     src_reader = parser.source_reader_t(self.config)
     decls = declarations.make_flatten(src_reader.read_string(self.__code))
     classes = [
         inst for inst in decls if isinstance(inst, declarations.class_t)]
     for class_ in classes:
         self.assertTrue(class_.name in self.__recursive_bases)
         all_bases = class_.recursive_bases
         control_bases = self.__recursive_bases[class_.name]
         self.assertTrue(len(control_bases) == len(all_bases))
         all_bases_names = [hi.related_class.name for hi in all_bases]
         self.assertTrue(set(all_bases_names) == control_bases)
コード例 #14
0
    def test_keep_va_list_tag(self):

        if "gccxml" in self.config.xml_generator or \
                platform.system() == 'Windows':
            return True

        self.config.flags = ["f1"]
        src_reader = parser.source_reader_t(self.config)
        decls = declarations.make_flatten(src_reader.read_string(self.__code))

        classes = [
            i for i in decls if isinstance(i, declarations.class_t)]

        typedefs = [
            i for i in decls if isinstance(i, declarations.typedef_t)]

        variables = [
            i for i in decls if isinstance(i, declarations.variable_t)]

        tag = "__va_list_tag"

        self.assertTrue(tag in [class_.name for class_ in classes])
        self.assertTrue("a" in [class_.name for class_ in classes])
        if len(classes) == 2:
            for c in self.known_classes:
                self.assertTrue(c in [cl.name for cl in classes])
        elif len(classes) == 3:
            for c in self.known_classes_llvm39:
                # This is for llvm 3.9
                self.assertTrue(c in [cl.name for cl in classes])

        self.assertTrue(len(typedefs) == 4 or len(typedefs) == 5)
        if len(typedefs) == 5:
            # This is for llvm 3.9. The class __va_list_tag struct is still
            # there but the typedef is gone
            for t in self.known_typedefs_llvm39:
                self.assertTrue(t in [ty.name for ty in typedefs])
            self.assertTrue(
                "__NSConstantString_tag" in
                [class_.name for class_ in classes])
            self.assertTrue(
                "__NSConstantString" in [ty.name for ty in typedefs])
        else:
            for t in self.known_typedefs:
                self.assertTrue(t in [ty.name for ty in typedefs])

        self.assertTrue(
            tag in [var.decl_string.split("::")[1] for var in variables])

        # 4 variables in __va_list_tag, and 4 more in __NSConstantString_tag
        # for llvm 3.9
        self.assertTrue(len(variables) == 4 or len(variables) == 8)
コード例 #15
0
 def __apply_decls_defaults(self, decls):
     flatten_decls = decls_package.make_flatten( decls )
     self.__filter_by_location( flatten_decls )
     call_policies_resolver = creators_factory.built_in_resolver_t()
     calldefs = [decl for decl in flatten_decls if isinstance( decl, decls_package.calldef_t )]
     for calldef in calldefs:
         calldef.set_call_policies( call_policies_resolver( calldef ) )
     mem_vars = [decl for decl in flatten_decls if isinstance( decl, decls_package.variable_t )
                                     and isinstance( decl.parent, decls_package.class_t )]
     for mem_var in mem_vars:
         mem_var.set_getter_call_policies( call_policies_resolver( mem_var, 'get' ) )
     for mem_var in mem_vars:
         mem_var.set_setter_call_policies( call_policies_resolver( mem_var, 'set' ) )
コード例 #16
0
    def test_keep_va_list_tag(self):

        if "gccxml" in self.config.xml_generator:
            return True

        self.config.flags = ["f1"]
        src_reader = parser.source_reader_t(self.config)
        decls = declarations.make_flatten(src_reader.read_string(self.__code))

        classes = [
            i for i in decls if isinstance(i, declarations.class_t)]

        typedefs = [
            i for i in decls if isinstance(i, declarations.typedef_t)]

        variables = [
            i for i in decls if isinstance(i, declarations.variable_t)]

        tag = "__va_list_tag"

        self.assertTrue(tag in [class_.name for class_ in classes])
        self.assertTrue("a" in [class_.name for class_ in classes])
        if len(classes) == 2:
            for c in self.known_classes:
                self.assertTrue(c in [cl.name for cl in classes])
        elif len(classes) == 3:
            for c in self.known_classes_llvm39:
                # This is for llvm 3.9
                self.assertTrue(c in [cl.name for cl in classes])

        self.assertTrue(len(typedefs) == 4 or len(typedefs) == 5)
        if len(typedefs) == 5:
            # This is for llvm 3.9. The class __va_list_tag struct is still
            # there but the typedef is gone
            for t in self.known_typedefs_llvm39:
                self.assertTrue(t in [ty.name for ty in typedefs])
            self.assertTrue(
                "__NSConstantString_tag" in
                [class_.name for class_ in classes])
            self.assertTrue(
                "__NSConstantString" in [ty.name for ty in typedefs])
        else:
            for t in self.known_typedefs:
                self.assertTrue(t in [ty.name for ty in typedefs])

        self.assertTrue(
            tag in [var.decl_string.split("::")[1] for var in variables])

        # 4 variables in __va_list_tag, and 4 more in __NSConstantString_tag
        # for llvm 3.9
        self.assertTrue(len(variables) == 4 or len(variables) == 8)
コード例 #17
0
    def test_template_split_std_vector(self):
        """
        Demonstrate error in pattern parser, see #60

        """

        if self.config.xml_generator == "gccxml":
            return

        decls = parser.parse([self.header], self.config)

        for decl in declarations.make_flatten(decls):
            if "myClass" in decl.name:
                _ = decl.partial_name
コード例 #18
0
 def test_recursive_derived(self):
     src_reader = parser.source_reader_t(self.config)
     decls = declarations.make_flatten(src_reader.read_string(self.__code))
     classes = [
         inst for inst in decls if isinstance(
             inst,
             declarations.class_t)]
     for class_ in classes:
         self.failUnless(class_.name in self.__recursive_derived)
         all_derived = class_.recursive_derived
         control_derived = self.__recursive_derived[class_.name]
         self.failUnless(len(control_derived) == len(all_derived))
         all_derived_names = [hi.related_class.name for hi in all_derived]
         self.failUnless(set(all_derived_names) == control_derived)
コード例 #19
0
    def test_template_split_std_vector(self):
        """
        Demonstrate error in pattern parser, see #60

        """

        if self.config.xml_generator == "gccxml":
            return

        decls = parser.parse([self.header], self.config)

        for decl in declarations.make_flatten(decls):
            if "myClass" in decl.name:
                _ = decl.partial_name
コード例 #20
0
 def register_opaque( self, creator, decl_or_decls ):
     opaque_decls = []
     for decl in declarations.make_flatten( decl_or_decls ):
         opaque_decls.extend( self.__find_out_opaque_decls( decl ) )
         
     for decl in opaque_decls:
         opaque_type_registrator = None
         if id(decl) not in self.__exposed_opaque_decls.keys():
             opaque_type_registrator = code_creators.opaque_type_registrator_t( decl )
             self.__exposed_opaque_decls[ id(decl) ] = opaque_type_registrator
             self.__extmodule.adopt_declaration_creator( opaque_type_registrator )
         else:
             opaque_type_registrator = self.__exposed_opaque_decls[ id(decl) ]
         creator.associated_decl_creators.append(opaque_type_registrator)
コード例 #21
0
 def __apply_decls_defaults(self, decls):
     flatten_decls = decls_package.make_flatten( decls )
     self.__filter_by_location( flatten_decls )
     call_policies_resolver = mcreator_package.built_in_resolver_t()
     calldefs = filter( lambda decl: isinstance( decl, decls_package.calldef_t )
                        , flatten_decls )
     map( lambda calldef: calldef.set_call_policies( call_policies_resolver( calldef ) )
          , calldefs )
     mem_vars = filter( lambda decl: isinstance( decl, decls_package.variable_t )
                                     and isinstance( decl.parent, decls_package.class_t )
                        , flatten_decls )
     map( lambda mem_var: mem_var.set_getter_call_policies( call_policies_resolver( mem_var, 'get' ) )
          , mem_vars )
     map( lambda mem_var: mem_var.set_setter_call_policies( call_policies_resolver( mem_var, 'set' ) )
          , mem_vars )
コード例 #22
0
    def register_opaque(self, creator, decl_or_decls):
        opaque_decls = []
        for decl in declarations.make_flatten(decl_or_decls):
            opaque_decls.extend(self.__find_out_opaque_decls(decl))

        for decl in opaque_decls:
            opaque_type_registrator = None
            if id(decl) not in self.__exposed_opaque_decls.keys():
                opaque_type_registrator = code_creators.opaque_type_registrator_t(
                    decl)
                self.__exposed_opaque_decls[id(decl)] = opaque_type_registrator
                self.__extmodule.adopt_declaration_creator(
                    opaque_type_registrator)
            else:
                opaque_type_registrator = self.__exposed_opaque_decls[id(decl)]
            creator.associated_decl_creators.append(opaque_type_registrator)
コード例 #23
0
 def test_recursive_bases(self):
     src_reader = parser.source_reader_t(self.config)
     decls = declarations.make_flatten(src_reader.read_string(self.__code))
     classes = [
         inst for inst in decls if isinstance(inst, declarations.class_t)]
     for class_ in classes:
         if "CastXML" in utils.xml_generator and \
                 class_.name == "__va_list_tag":
             # With CastXML; there is a __va_list_tag which is generated by
             # clang. Do not run the tests for it.
             continue
         self.failUnless(class_.name in self.__recursive_bases)
         all_bases = class_.recursive_bases
         control_bases = self.__recursive_bases[class_.name]
         self.failUnless(len(control_bases) == len(all_bases))
         all_bases_names = [hi.related_class.name for hi in all_bases]
         self.failUnless(set(all_bases_names) == control_bases)
コード例 #24
0
    def test(self):
        mb = module_builder.module_builder_t(
            self._get_files(),
            gccxml_path=autoconfig.gccxml.executable,
            include_paths=[autoconfig.boost.include],
            undefine_symbols=['__MINGW32__'],
            compiler=pygccxml.utils.native_compiler.get_gccxml_compiler())
        classes = [
            d for d in declarations.make_flatten(mb.global_ns)
            if isinstance(d, module_builder.class_t)
        ]

        mdw = module_builder.mdecl_wrapper_t(classes)
        #check set to property functionality
        for d in mdw:
            d.always_expose_using_scope = False

        mdw.always_expose_using_scope = True

        all_true = True
        for d in mdw:
            all_true &= d.always_expose_using_scope

        self.failUnless(all_true)

        #check call method functionality
        for d in mdw:
            d.ignore = True

        mdw.include()

        all_false = False
        for d in mdw:
            all_true |= d.ignore

        self.failUnless(not all_false)

        #check for exception:
        try:
            mdw.call_policies = None
            self.fail("Runtime error has not been raised.")
        except RuntimeError as err:
            pass
コード例 #25
0
    def test_remove_va_list_tag(self):

        if "gccxml" in self.config.xml_generator or \
                platform.system() == 'Windows':
            return True

        self.config.flags = []
        src_reader = parser.source_reader_t(self.config)
        decls = declarations.make_flatten(src_reader.read_string(self.__code))

        classes = [
            i for i in decls if isinstance(i, declarations.class_t)]

        typedefs = [
            i for i in decls if isinstance(i, declarations.typedef_t)]

        variables = [
            i for i in decls if isinstance(i, declarations.variable_t)]

        tag = "__va_list_tag"

        self.assertFalse(tag in [class_.name for class_ in classes])
        self.assertTrue("a" in [class_.name for class_ in classes])
        self.assertTrue(len(classes) == 1)

        self.assertFalse(tag in [ty.name for ty in typedefs])
        self.assertTrue(len(typedefs) == 3 or len(typedefs) == 4)
        if len(typedefs) == 4:
            # This is for llvm 3.9
            for t in self.known_typedefs_llvm39:
                self.assertTrue(t in [ty.name for ty in typedefs])
            self.assertFalse(
                "__NSConstantString_tag"
                in [class_.name for class_ in classes])
            self.assertFalse(
                "__NSConstantString" in [ty.name for ty in typedefs])
        else:
            for t in self.known_typedefs:
                self.assertTrue(t in [ty.name for ty in typedefs])

        self.assertFalse(
            tag in [var.decl_string.split("::")[1] for var in variables])
        self.assertTrue(len(variables) == 0)
コード例 #26
0
    def test_remove_va_list_tag(self):

        if "gccxml" in self.config.xml_generator or \
                platform.system() == 'Windows':
            return True

        self.config.flags = []
        src_reader = parser.source_reader_t(self.config)
        decls = declarations.make_flatten(src_reader.read_string(self.__code))

        classes = [i for i in decls if isinstance(i, declarations.class_t)]

        typedefs = [i for i in decls if isinstance(i, declarations.typedef_t)]

        variables = [
            i for i in decls if isinstance(i, declarations.variable_t)
        ]

        tag = "__va_list_tag"

        self.assertFalse(tag in [class_.name for class_ in classes])
        self.assertTrue("a" in [class_.name for class_ in classes])
        self.assertTrue(len(classes) == 1)

        self.assertFalse(tag in [ty.name for ty in typedefs])
        self.assertTrue(len(typedefs) == 3 or len(typedefs) == 4)
        if len(typedefs) == 4:
            # This is for llvm 3.9
            for t in self.known_typedefs_llvm39:
                self.assertTrue(t in [ty.name for ty in typedefs])
            self.assertFalse("__NSConstantString_tag" in
                             [class_.name for class_ in classes])
            self.assertFalse(
                "__NSConstantString" in [ty.name for ty in typedefs])
        else:
            for t in self.known_typedefs:
                self.assertTrue(t in [ty.name for ty in typedefs])

        self.assertFalse(
            tag in [var.decl_string.split("::")[1] for var in variables])
        self.assertTrue(len(variables) == 0)
コード例 #27
0
    def _prepare_decls( self, decls ):
        to_be_exposed = []
        for decl in declarations.make_flatten( decls ):
            if decl.ignore:
                continue

            if isinstance( decl, declarations.namespace_t ):
                continue

            if isinstance( decl, declarations.class_types ):
                if decl.opaque:
                    continue

            if not decl.exportable:
                #leave only decls that user wants to export and that could be exported
                self.__print_readme( decl )
                continue

            if decl.already_exposed:
                #check wether this is already exposed in other module
                continue

            if isinstance( decl.parent, declarations.namespace_t ):
                #leave only declarations defined under namespace, but remove namespaces
                to_be_exposed.append( decl )

            #Right now this functionality introduce a bug: declarations that should
            #not be exported for some reason are not marked as such. I will need to
            #find out.
            #if isinstance( decl, declarations.calldef_t ) and not isinstance( decl, declarations.destructor_t ):
                #self.__types_db.update( decl )
                #if None is decl.call_policies:
                    #decl.call_policies = self.__call_policies_resolver( decl )

            #if isinstance( decl, declarations.variable_t ):
                #self.__types_db.update( decl )

            self.__print_readme( decl )

        return to_be_exposed
コード例 #28
0
    def test(self):
        mb = module_builder.module_builder_t(
            self._get_files(),
            gccxml_path=autoconfig.gccxml.executable,
            include_paths=[autoconfig.boost.include],
            undefine_symbols=["__MINGW32__"],
        )
        classes = filter(lambda d: isinstance(d, module_builder.class_t), declarations.make_flatten(mb.global_ns))

        mdw = module_builder.mdecl_wrapper_t(classes)
        # check set to property functionality
        for d in mdw:
            d.always_expose_using_scope = False

        mdw.always_expose_using_scope = True

        all_true = True
        for d in mdw:
            all_true &= d.always_expose_using_scope

        self.failUnless(all_true)

        # check call method functionality
        for d in mdw:
            d.ignore = True

        mdw.include()

        all_false = False
        for d in mdw:
            all_true |= d.ignore

        self.failUnless(not all_false)

        # check for exception:
        try:
            mdw.call_policies = None
            self.fail("Runtime error has not been raised.")
        except RuntimeError, err:
            pass
コード例 #29
0
 def test__str__(self):
     decls = declarations.make_flatten(self.decls)
     for decl in decls:
         str(decl)
コード例 #30
0
 def test__str__(self):
     decls = declarations.make_flatten(self.decls)
     for decl in decls:
         str(decl)
コード例 #31
0
ファイル: modulebuilder.py プロジェクト: laxris/pyplusplus
    def parse(self):
        """Parse the header files and setup the known declarations.
      
      Currently this method can only be called once.
      This method can be called anytime after initialization and all
      Template() calls have been made.

      :rtype: Returns the root of the declaration tree
      @rtype: L{IDecl<declwrapper.IDecl>}
      @postcondition: This class can act as a wrapper for namespace("::") and all declarations are set to be ignored.
      """
        if self.mHeaderFiles == []:
            raise ValueError, "No header files specified"

        if self.mVerbose:
            print "Parsing headers: ", self.mHeaderFiles

        # Record the time when parsing started...
        self.mStartTime = time.time()

        # Create and initialize the config object
        parser_cfg = parser.config_t(self.mGccXmlPath,
                                     self.mWorkingDir,
                                     self.mIncludePaths,
                                     define_symbols=self.mDefines,
                                     undefine_symbols=self.mUndefines,
                                     start_with_declarations=None)

        full_header_list = self.mHeaderFiles[:]

        # Handle template instantiation as needed
        temp_file, temp_filename = (None, None)
        template_instantiation_text = self.buildTemplateFileContents()
        if None != template_instantiation_text:
            temp_filename = pygccxml.utils.create_temp_file_name(suffix=".h")
            temp_file = file(temp_filename, 'w')
            temp_file.write(template_instantiation_text)
            temp_file.close()
            if self.mVerbose:
                print "   creating template instantiation file: ", temp_filename
            full_header_list.append(temp_filename)

        # Create the cache object...
        if self.mCacheDir != None:
            if self.mVerbose:
                print "Using directory cache in '%s'" % self.mCacheDir
            cache = parser.directory_cache_t(self.mCacheDir)
        elif self.mCacheFile != None:
            if self.mVerbose:
                print "Using file cache '%s'" % self.mCacheFile
            cache = parser.file_cache_t(self.mCacheFile)
        else:
            if self.mVerbose:
                print "No cache in use"
            cache = None

        # Create the parser object...
        the_parser = parser.project_reader_t(
            config=parser_cfg,
            cache=cache,
            decl_factory=decl_wrappers.dwfactory_t())
        # ...and parse the headers
        parsed_decls = the_parser.read_files(
            full_header_list,
            parser.project_reader.COMPILATION_MODE.FILE_BY_FILE)

        assert len(parsed_decls) == 1  # assume that we get root of full tree
        self.mDeclRoot = parsed_decls[0]

        # Parse the files and add to decl root
        # - then traverse tree setting everything to ignore
        self.mDeclRootWrapper = DeclWrapper(self.mDeclRoot)
        # Set the module builder instance (this is done here and not in the
        # constructor so that Allen's DeclWrapper object still work as well)
        self.mDeclRootWrapper.modulebuilder = self
        self.mDeclRootWrapper.ignore()

        # Cleanup
        if temp_filename:
            pygccxml.utils.remove_file_no_raise(temp_filename)

        typedef_decls = declarations.make_flatten(parsed_decls)
        typedef_decls = decls = filter(
            lambda x:
            (isinstance(x, declarations.typedef_t) and not x.name.startswith(
                '__') and x.location.file_name != "<internal>"), typedef_decls)

        self.mTypeDefMap = {}
        for d in typedef_decls:
            type_def_name = d.name
            full_name = declarations.full_name(d)
            if full_name.startswith("::"):  # Remove the base namespace
                full_name = full_name[2:]
            real_type_name = d.type.decl_string
            if real_type_name.startswith("::"):  # Remove base namespace
                real_type_name = real_type_name[2:]
            self.mTypeDefMap[full_name] = real_type_name

        self.mParseEndTime = time.time()
        if self.mVerbose:
            print "Completed parsing in %s." % self._time2str(
                self.mParseEndTime - self.mStartTime)

        return self.mDeclRootWrapper
コード例 #32
0
ファイル: patcher.py プロジェクト: glehmann/WrapITK-unstable
 def patch_it(self):
     for decl in declarations.make_flatten( self.decls ):
         if not isinstance( decl, declarations.casting_operator_t):
             continue
         decl.name = 'operator ' + decl.return_type.decl_string
コード例 #33
0
ファイル: modulebuilder.py プロジェクト: ChrisCarlsen/tortuga
   def parse(self):
      """Parse the header files and setup the known declarations.
      
      Currently this method can only be called once.
      This method can be called anytime after initialization and all
      Template() calls have been made.

      @returns: Returns the root of the declaration tree
      @rtype: L{IDecl<declwrapper.IDecl>}
      @postcondition: This class can act as a wrapper for namespace("::") and all declarations are set to be ignored.
      """
      if self.mHeaderFiles==[]:
         raise ValueError, "No header files specified"
      
      if self.mVerbose:
         print "Parsing headers: ", self.mHeaderFiles

      # Record the time when parsing started...
      self.mStartTime = time.time()

      # Create and initialize the config object
      parser_cfg = parser.config_t(self.mGccXmlPath,
                                   self.mWorkingDir,
                                   self.mIncludePaths,
                                   define_symbols=self.mDefines,
                                   undefine_symbols=self.mUndefines,
                                   start_with_declarations=None)

      full_header_list = self.mHeaderFiles[:]
      
      # Handle template instantiation as needed      
      temp_file, temp_filename = (None,None)
      template_instantiation_text = self.buildTemplateFileContents()
      if None != template_instantiation_text:
         temp_filename = pygccxml.utils.create_temp_file_name(suffix=".h")
         temp_file = file(temp_filename, 'w')
         temp_file.write(template_instantiation_text)
         temp_file.close()
         if self.mVerbose:
            print "   creating template instantiation file: ", temp_filename
         full_header_list.append(temp_filename)      

      # Create the cache object...
      if self.mCacheDir!=None:
         if self.mVerbose:
            print "Using directory cache in '%s'"%self.mCacheDir
         cache = parser.directory_cache_t(self.mCacheDir)
      elif self.mCacheFile!=None:
         if self.mVerbose:
            print "Using file cache '%s'"%self.mCacheFile
         cache = parser.file_cache_t(self.mCacheFile)         
      else:
         if self.mVerbose:
            print "No cache in use"
         cache = None

      # Create the parser object...
      the_parser = parser.project_reader_t(config=parser_cfg, 
                                           cache=cache,
                                           decl_factory=decl_wrappers.dwfactory_t())
      # ...and parse the headers
      parsed_decls = the_parser.read_files(full_header_list, 
                                           parser.project_reader.COMPILATION_MODE.FILE_BY_FILE)
      
      assert len(parsed_decls) == 1    # assume that we get root of full tree
      self.mDeclRoot = parsed_decls[0]
      
      # Parse the files and add to decl root
      # - then traverse tree setting everything to ignore
      self.mDeclRootWrapper = DeclWrapper(self.mDeclRoot)
      # Set the module builder instance (this is done here and not in the
      # constructor so that Allen's DeclWrapper object still work as well)
      self.mDeclRootWrapper.modulebuilder = self
      self.mDeclRootWrapper.ignore()
      
      # Cleanup
      if temp_filename:
         pygccxml.utils.remove_file_no_raise( temp_filename )
      
      typedef_decls = declarations.make_flatten(parsed_decls)
      typedef_decls = decls = filter( lambda x: (isinstance( x, declarations.typedef_t ) and 
                                                 not x.name.startswith('__') and 
                                                 x.location.file_name != "<internal>")
                                      , typedef_decls )

      self.mTypeDefMap = {}
      for d in typedef_decls:
         type_def_name = d.name
         full_name = declarations.full_name(d)
         if full_name.startswith("::"):    # Remove the base namespace
            full_name = full_name[2:]
         real_type_name = d.type.decl_string
         if real_type_name.startswith("::"):    # Remove base namespace
            real_type_name = real_type_name[2:]   
         self.mTypeDefMap[full_name] = real_type_name

      self.mParseEndTime = time.time()
      if self.mVerbose:
         print "Completed parsing in %s."%self._time2str(self.mParseEndTime-self.mStartTime)

      return self.mDeclRootWrapper