Пример #1
0
 def test_all_mem_and_free_funs( self ):
     ns = self.global_ns.ns( '::declarations::calldef' )
     for f in ns.mem_funs():
         decls = parser.parse_string( self.template % f.decl_string, self.config )
         self.failUnless( decls, "Created decl_string for member function containes mistake" )
     for f in ns.free_funs():
         decls = parser.parse_string( self.template % f.decl_string, self.config )
         self.failUnless( decls, "Created decl_string for member function containes mistake" )
Пример #2
0
 def test_all_mem_and_free_funs(self):
     ns = self.global_ns.ns('::declarations::calldef')
     for f in ns.mem_funs():
         decls = parser.parse_string(self.template % f.decl_string,
                                     self.config)
         self.failUnless(
             decls,
             "Created decl_string for member function containes mistake")
     for f in ns.free_funs():
         decls = parser.parse_string(self.template % f.decl_string,
                                     self.config)
         self.failUnless(
             decls,
             "Created decl_string for member function containes mistake")
    def test(self):
        config = autoconfig.xml_generator_config
        code = []
        code.append('struct a{};')
        code.append('struct b{};')
        code.append('struct c{};')
        code.append('struct d : public a{};')
        code.append('struct e : public a, public b{};')
        code.append('struct f{};')
        code.append('struct g : public d, public f{};')
        code.append('struct h : public f{};')
        code.append('struct i : public h, public g{};')
        code.append('struct j{};')
        code.append('struct k{};')

        global_ns = parser.parse_string(os.linesep.join(code), config)
        decls = global_ns[0].declarations
        dorder = creators_factory.findout_desired_order(decls)
        self.assertTrue(
            len(code) == len(dorder),
            'all classes should stay within the list')
        for i in range(1, len(dorder)):
            bases = set(self._findout_base_classes(dorder[i]))
            exported = set(dorder[:i])
            self.assertTrue(
                bases.issubset(exported),
                'for derived class %s not all base classes have been exported'
                % dorder[i].name)
Пример #4
0
    def test_get_declaration(self):
        code = """
            namespace A{
            struct B{
                int c;
            };

            template <class T>
            struct C: public T{
                int d;
            };

            template <class T>
            struct D{
                int dD;
            };

            typedef C<B> easy;
            typedef D<easy> Deasy;

            inline void instantiate(){
                int val = sizeof(easy);
            }

            }
        """

        global_ns = parser.parse_string(code,
                                        autoconfig.cxx_parsers_cfg.config)
        global_ns = declarations.get_global_namespace(global_ns)
        easy = global_ns.typedef('easy')
        declarations.class_traits.get_declaration(easy)
        deasy = global_ns.typedef('Deasy')
        d_a = declarations.class_traits.get_declaration(deasy)
        self.assertTrue(isinstance(d_a, declarations.class_types))
    def test(self):
        code = """
            namespace A{
            struct B{
                int c;
            };

            template <class T>
            struct C: public T{
                int d;
            };

            template <class T>
            struct D{
                int dD;
            };

            typedef C<B> easy;
            typedef D<easy> Deasy;

            inline void instantiate(){
                sizeof(easy);
            }

            }
        """

        global_ns = parser.parse_string( code, autoconfig.cxx_parsers_cfg.gccxml)
        global_ns = declarations.get_global_namespace( global_ns )
        easy = global_ns.typedef( 'easy' )
        c_a = declarations.class_traits.get_declaration( easy )  #this works very well
        deasy = global_ns.typedef( 'Deasy' )
        d_a = declarations.class_traits.get_declaration( deasy )  
        self.failUnless( isinstance( d_a, declarations.class_types ) )
Пример #6
0
 def test_free_function(self):
     return_default_args = self.global_ns.free_fun('return_default_args')
     decls = parser.parse_string(
         self.template %
         return_default_args.decl_string,
         self.config)
     self.assertTrue(
         decls,
         "Created decl_string for global function contains mistake")
Пример #7
0
 def test_member_function(self):
     member_inline_call = self.global_ns.mem_fun('member_inline_call')
     decls = parser.parse_string(
         self.template %
         member_inline_call.decl_string,
         self.config)
     self.assertTrue(
         decls,
         "Created decl_string for member function contains mistake")
Пример #8
0
 def test_free_function(self):
     return_default_args = self.global_ns.free_fun('return_default_args')
     decls = parser.parse_string(
         self.template %
         return_default_args.decl_string,
         self.config)
     self.failUnless(
         decls,
         "Created decl_string for global function containes mistake")
Пример #9
0
 def test_member_function(self):
     member_inline_call = self.global_ns.mem_fun('member_inline_call')
     decls = parser.parse_string(
         self.template %
         member_inline_call.decl_string,
         self.config)
     self.failUnless(
         decls,
         "Created decl_string for member function containes mistake")
Пример #10
0
    def test(self):
        decls = parser.parse_string(code, self.config)
        global_ns = declarations.get_global_namespace(decls)

        # TODO: demangled attribute does not existe for castxml
        # and will not be added. Remove this test once gccxml
        # support is dropped.
        if self.config.xml_generator_from_xml_file.is_gccxml:
            global_ns.decl('A<int>')
            f = global_ns.free_function('f')
            self.assertTrue(f.demangled == 'void f<int>(A<int> const&)')
Пример #11
0
    def test(self):
        decls = parser.parse_string(code, self.config)
        global_ns = declarations.get_global_namespace(decls)

        # TODO: demangled attribute does not existe for castxml
        # and will not be added. Remove this test once gccxml
        # support is dropped.
        if self.config.xml_generator_from_xml_file.is_gccxml:
            global_ns.decl('A<int>')
            f = global_ns.free_function('f')
            self.assertTrue(f.demangled == 'void f<int>(A<int> const&)')
Пример #12
0
 def test(self):
     config = autoconfig.cxx_parsers_cfg.gccxml
     code = "struct const_item{ const int values[10]; };"
     global_ns = parser.parse_string(code, config)[0]
     ci = global_ns.class_('const_item')
     if 'CastXML' in utils.xml_generator:
         # Constructor, copy constructor, destructor, variable
         self.assertTrue(len(ci.declarations) == 4)
     else:
         # Copy constructor, destructor, variable
         self.assertTrue(len(ci.declarations) == 3)
Пример #13
0
 def test(self):
     config = autoconfig.cxx_parsers_cfg.gccxml
     code = "struct const_item{ const int values[10]; };"
     global_ns = parser.parse_string(code, config)[0]
     ci = global_ns.class_('const_item')
     if 'CastXML' in utils.xml_generator:
         # Constructor, copy constructor, destructor, variable
         self.assertTrue(len(ci.declarations) == 4)
     else:
         # Copy constructor, destructor, variable
         self.assertTrue(len(ci.declarations) == 3)
Пример #14
0
 def test(self):
     config = autoconfig.cxx_parsers_cfg.gccxml
     code = "struct const_item{ const int values[10]; };"
     global_ns = parser.parse_string(code, config)[0]
     ci = global_ns.class_('const_item')
     if ("CastXML" not in utils.xml_generator
             or utils.xml_output_version >= 1.138):
         # Prior to version 1.138, CastXML would incorrect create a default
         # constructor definition.
         # See https://github.com/CastXML/CastXML/issues/55
         # Copy constructor, destructor, variable
         self.assertEqual(len(ci.declarations), 3)
Пример #15
0
 def test(self):
     config = autoconfig.cxx_parsers_cfg.gccxml
     code = "struct const_item{ const int values[10]; };"
     global_ns = parser.parse_string(code, config)[0]
     ci = global_ns.class_('const_item')
     if ("CastXML" not in utils.xml_generator or
             utils.xml_output_version >= 1.138):
         # Prior to version 1.138, CastXML would incorrect create a default
         # constructor definition.
         # See https://github.com/CastXML/CastXML/issues/55
         # Copy constructor, destructor, variable
         self.assertEqual(len(ci.declarations), 3)
Пример #16
0
 def test(self):
     config = autoconfig.cxx_parsers_cfg.config
     code = "struct const_item{ const int values[10]; };"
     global_ns = parser.parse_string(code, config)[0]
     ci = global_ns.class_('const_item')
     generator = config.xml_generator_from_xml_file
     if generator.is_castxml1 or (generator.is_castxml and float(
             generator.xml_output_version) >= 1.138):
         # Prior to version 1.138, CastXML would incorrectly create a
         # default constructor definition.
         # See https://github.com/CastXML/CastXML/issues/55
         # Copy constructor, destructor, variable
         self.assertEqual(len(ci.declarations), 3)
Пример #17
0
 def test(self):
     config = autoconfig.cxx_parsers_cfg.config
     code = "struct const_item{ const int values[10]; };"
     global_ns = parser.parse_string(code, config)[0]
     ci = global_ns.class_('const_item')
     generator = config.xml_generator_from_xml_file
     if generator.is_castxml1 or (
             generator.is_castxml and
             float(generator.xml_output_version) >= 1.138):
         # Prior to version 1.138, CastXML would incorrectly create a
         # default constructor definition.
         # See https://github.com/CastXML/CastXML/issues/55
         # Copy constructor, destructor, variable
         self.assertEqual(len(ci.declarations), 3)
Пример #18
0
    def test_castxml_epic_version_check(self):
        """
        Test using a forbidden value for the castxml epic version.

        """

        if self.config.castxml_epic_version != 1:
            # Run this test only with castxml epic version == 1
            return

        self.config.castxml_epic_version = 2
        self.assertRaises(
            RuntimeError, lambda: parser.parse_string("", self.config))

        # Reset castxml epic version
        self.config.castxml_epic_version = 1
Пример #19
0
    def test(self):
        """
        The purpose of this test was to check if changes to GCCXML
        would lead to changes in the outputted xml file (Meaning
        the bug was fixed).

        GCCXML wrongly outputted partial template specialization.
        CastXML does not have this bug. In this case we check if
        the template specialization can not be found; which is the
        expected/wanted behaviour.

        https://github.com/CastXML/CastXML/issues/20

        """

        decls = parser.parse_string(code, self.config)
        global_ns = declarations.get_global_namespace(decls)
        self.assertRaises(declarations.declaration_not_found_t,
                          lambda: global_ns.class_('A<const char [N]>'))
Пример #20
0
    def test_config(self):
        """Test config setup with wrong xml generator setups."""

        # Some code to parse for the example
        code = "int a;"

        # Find the location of the xml generator (castxml or gccxml)
        generator_path, name = utils.find_xml_generator()

        # No xml generator path
        config = parser.xml_generator_configuration_t(xml_generator=name)
        self.assertRaises(
            RuntimeError, lambda: parser.parse_string(code, config))

        # Invalid path
        config = parser.xml_generator_configuration_t(
            xml_generator_path="wrong/path",
            xml_generator=name)
        self.assertRaises(
            RuntimeError, lambda: parser.parse_string(code, config))

        # None path
        config = parser.xml_generator_configuration_t(
            xml_generator_path=None,
            xml_generator=name)
        self.assertRaises(
            RuntimeError, lambda: parser.parse_string(code, config))

        # No name
        config = parser.xml_generator_configuration_t(
            xml_generator_path=generator_path)
        self.assertRaises(
            RuntimeError, lambda: parser.parse_string(code, config))

        # Random name
        config = parser.xml_generator_configuration_t(
            xml_generator_path=generator_path,
            xml_generator="not_a_generator")
        self.assertRaises(
            RuntimeError, lambda: parser.parse_string(code, config))

        # None name
        config = parser.xml_generator_configuration_t(
            xml_generator_path=generator_path,
            xml_generator=None)
        self.assertRaises(
            RuntimeError, lambda: parser.parse_string(code, config))
Пример #21
0
def try_pygccxml():
    from pygccxml import declarations
    from pygccxml import utils
    from pygccxml import parser

    # Find out the c++ parser. This should resolve to the castxml
    # version installed in Docker.
    generator_path, generator_name = utils.find_xml_generator()

    # Configure the xml generator
    config = parser.xml_generator_configuration_t(
        xml_generator_path=generator_path,
        xml_generator=generator_name,
        include_paths=["/usr/include/eigen3"],
        # TODO(eric.cousineau): Why is `compiler_path` necessary?
        compiler_path=generator_path,
        start_with_declarations=["ns"],
    )

    t_start = time.time()
    (global_ns, ) = parser.parse_string(code, config)
    dt = time.time() - t_start
    return dt
Пример #22
0
    def test(self):
        config = parser.config_t( gccxml_path=autoconfig.gccxml.executable )
        code = []
        code.append('struct a{};')
        code.append('struct b{};')
        code.append('struct c{};')
        code.append('struct d : public a{};')
        code.append('struct e : public a, public b{};')
        code.append('struct f{};')
        code.append('struct g : public d, public f{};')
        code.append('struct h : public f{};')
        code.append('struct i : public h, public g{};')
        code.append('struct j{};')
        code.append('struct k{};')

        global_ns = parser.parse_string( os.linesep.join( code ), config )
        decls = global_ns[0].declarations
        dorder = module_creator.findout_desired_order( decls )
        self.failUnless( len( code ) == len( dorder ), 'all classes should stay within the list' )
        for i in range( 1, len(dorder) ):
            bases = set( self._findout_base_classes( dorder[i] ) )
            exported = set( dorder[:i])
            self.failUnless( bases.issubset( exported )
                             , 'for derived class %s not all base classes have been exported' % dorder[i].name )
Пример #23
0
    def test(self):
        config = parser.config_t( gccxml_path=autoconfig.gccxml.executable, compiler=pygccxml.utils.native_compiler.get_gccxml_compiler() )
        code = []
        code.append('struct a{};')
        code.append('struct b{};')
        code.append('struct c{};')
        code.append('struct d : public a{};')
        code.append('struct e : public a, public b{};')
        code.append('struct f{};')
        code.append('struct g : public d, public f{};')
        code.append('struct h : public f{};')
        code.append('struct i : public h, public g{};')
        code.append('struct j{};')
        code.append('struct k{};')

        global_ns = parser.parse_string( os.linesep.join( code ), config )
        decls = global_ns[0].declarations
        dorder = creators_factory.findout_desired_order( decls )
        self.failUnless( len( code ) == len( dorder ), 'all classes should stay within the list' )
        for i in range( 1, len(dorder) ):
            bases = set( self._findout_base_classes( dorder[i] ) )
            exported = set( dorder[:i])
            self.failUnless( bases.issubset( exported )
                             , 'for derived class %s not all base classes have been exported' % dorder[i].name )
Пример #24
0
    def test_get_declaration(self):
        code = """
            namespace A{
            struct B{
                int c;
            };

            template <class T>
            struct C: public T{
                int d;
            };

            template <class T>
            struct D{
                int dD;
            };

            typedef C<B> easy;
            typedef D<easy> Deasy;

            inline void instantiate(){
                int val = sizeof(easy);
            }

            }
        """

        global_ns = parser.parse_string(
            code,
            autoconfig.cxx_parsers_cfg.config)
        global_ns = declarations.get_global_namespace(global_ns)
        easy = global_ns.typedef('easy')
        declarations.class_traits.get_declaration(easy)
        deasy = global_ns.typedef('Deasy')
        d_a = declarations.class_traits.get_declaration(deasy)
        self.assertTrue(isinstance(d_a, declarations.class_types))
Пример #25
0
    def test(self):
        """
        The purpose of this test was to check if changes to GCCXML
        would lead to changes in the outputted xml file (Meaning
        the bug was fixed).

        GCCXML wrongly outputted partial template specialization.
        CastXML does not have this bug. In this case we check if
        the template specialization can not be found; which is the
        expected/wanted behaviour.

        https://github.com/CastXML/CastXML/issues/20

        """

        decls = parser.parse_string(code, self.config)
        global_ns = declarations.get_global_namespace(decls)
        if self.config.xml_generator_from_xml_file.is_gccxml:
            a = global_ns.class_('A<const char [N]>')
            a.member_function('size')
        elif self.config.xml_generator_from_xml_file.is_castxml:
            self.assertRaises(
                declarations.declaration_not_found_t,
                lambda: global_ns.class_('A<const char [N]>'))
Пример #26
0
    def test_config(self):
        """Test config setup with wrong xml generator setups."""

        # Some code to parse for the example
        code = "int a;"

        # Find the location of the xml generator (castxml or gccxml)
        generator_path, name = utils.find_xml_generator()

        # No xml generator path
        config = parser.xml_generator_configuration_t(xml_generator=name)
        self.assertRaises(RuntimeError,
                          lambda: parser.parse_string(code, config))

        # Invalid path
        config = parser.xml_generator_configuration_t(
            xml_generator_path="wrong/path", xml_generator=name)
        self.assertRaises(RuntimeError,
                          lambda: parser.parse_string(code, config))

        # None path
        config = parser.xml_generator_configuration_t(xml_generator_path=None,
                                                      xml_generator=name)
        self.assertRaises(RuntimeError,
                          lambda: parser.parse_string(code, config))

        # No name
        config = parser.xml_generator_configuration_t(
            xml_generator_path=generator_path)
        self.assertRaises(RuntimeError,
                          lambda: parser.parse_string(code, config))

        # Random name
        config = parser.xml_generator_configuration_t(
            xml_generator_path=generator_path, xml_generator="not_a_generator")
        self.assertRaises(RuntimeError,
                          lambda: parser.parse_string(code, config))

        # None name
        config = parser.xml_generator_configuration_t(
            xml_generator_path=generator_path, xml_generator=None)
        self.assertRaises(RuntimeError,
                          lambda: parser.parse_string(code, config))
Пример #27
0
 def test(self):
     decls = parser.parse_string(code, self.config)
     global_ns = declarations.get_global_namespace(decls)
     self.assertTrue(global_ns.variable('a').bits == 1)
     self.assertTrue(global_ns.variable('unused').bits == 31)
Пример #28
0
            return dat[:16]

    def get_formatted(self, data):
        return repr(data)[1:]


with open(os.path.join(os.path.dirname(__file__), "../stm/src/common/slots.h"),
          "r") as f:
    full_text = f.read()

# parse the file
gp, gn = utils.find_xml_generator()
xml_generator_config = parser.xml_generator_configuration_t(
    xml_generator_path=gp, xml_generator=gn)

declarations_in_file = parser.parse_string(full_text, xml_generator_config)


def _convert_opaque_to_token(x):
    """
    convert either a string from re or a value from pygccxml to a struct token
    """

    if type(x) is str:
        return {
            "BOOL": "?",
            "UINT8_T": "B",
            "INT8_T": "b",
            "UINT16_T": "H",
            "INT16_T": "h",
            "UINT32_T": "I",
Пример #29
0
 def test(self):
     decls = parser.parse_string(code, self.config)
     global_ns = declarations.get_global_namespace(decls)
     self.assertTrue(global_ns.variable('a').bits == 1)
     self.assertTrue(global_ns.variable('unused').bits == 31)
Пример #30
0
 def test(self):
     config = autoconfig.cxx_parsers_cfg.gccxml
     code = "struct const_item{ const int values[10]; };"
     global_ns = parser.parse_string(code, config)[0]
     ci = global_ns.class_('const_item')
     self.failUnless(len(ci.declarations) == 3)
Пример #31
0
# Copyright 2014-2016 Insight Software Consortium.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

from pygccxml import utils
from pygccxml import declarations
from pygccxml import parser

import warnings
warnings.simplefilter("error", Warning)

# Find the location of the xml generator (castxml or gccxml)
generator_path, generator_name = utils.find_xml_generator()

# Configure the xml generator
xml_generator_config = parser.xml_generator_configuration_t(
    xml_generator_path=generator_path, xml_generator=generator_name)

# Write a string containing some c++ code
code = """
    class MyClass {
        int a;
    };
"""

# Parse the code
decls = parser.parse_string(code, xml_generator_config)

# Get access to the global namespace
global_ns = declarations.get_global_namespace(decls)
Пример #32
0
 def test(self):
     config = autoconfig.cxx_parsers_cfg.gccxml
     code = "struct const_item{ const int values[10]; };"
     global_ns = parser.parse_string(code, config)[0]
     ci = global_ns.class_('const_item')
     self.failUnless(len(ci.declarations) == 3)
Пример #33
0
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

from pygccxml import utils
from pygccxml import declarations
from pygccxml import parser

import warnings
warnings.simplefilter("error", Warning)

# Find the location of the xml generator (castxml or gccxml)
generator_path, generator_name = utils.find_xml_generator()

# Configure the xml generator
xml_generator_config = parser.xml_generator_configuration_t(
    xml_generator_path=generator_path,
    xml_generator=generator_name)

# Write a string containing some c++ code
code = """
    class MyClass {
        int a;
    };
"""

# Parse the code
decls = parser.parse_string(code, xml_generator_config)

# Get access to the global namespace
global_ns = declarations.get_global_namespace(decls)