├── .binder ├── .dockerignore ├── Dockerfile └── README.md ├── .coveragerc ├── .dockerignore ├── .gitattributes ├── .github └── workflows │ └── tests.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE.rst ├── Makefile ├── NOTICE ├── README.rst ├── docs ├── conf.py ├── declarations_uml.png ├── design.rst ├── documentation.rst ├── examples.rst ├── examples │ ├── artificial │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst │ ├── caching │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst │ ├── compound │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst │ ├── elaborated │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst │ ├── equality │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst │ ├── function-pointer │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst │ ├── functions │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst │ ├── nested-types │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst │ ├── notebook │ │ └── example.ipynb │ ├── parsing-string │ │ ├── example.py │ │ └── example.rst │ ├── parsing │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst │ ├── print-example │ │ ├── example.hpp │ │ ├── example.hpp.rst │ │ ├── example.hpp.xml │ │ ├── example.hpp.xml.rst │ │ ├── example.py │ │ ├── example.py.rst │ │ ├── example.rst │ │ ├── output.txt │ │ └── output.txt.rst │ ├── searching │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst │ ├── searching1 │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst │ ├── templates │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst │ └── variables │ │ ├── example.hpp │ │ ├── example.py │ │ └── example.rst ├── faq.rst ├── history.rst ├── index.rst ├── install.rst ├── links.rst ├── make.bat ├── parser_uml.png ├── pygccxml_uml.vsd ├── query_interface.rst ├── releasing.rst ├── upgrade_issues.rst └── users.rst ├── pyproject.toml ├── src └── pygccxml │ ├── __init__.py │ ├── declarations │ ├── __init__.py │ ├── algorithm.py │ ├── algorithms_cache.py │ ├── byte_info.py │ ├── call_invocation.py │ ├── calldef.py │ ├── calldef_members.py │ ├── calldef_types.py │ ├── class_declaration.py │ ├── comment.py │ ├── container_traits.py │ ├── cpptypes.py │ ├── decl_factory.py │ ├── decl_printer.py │ ├── decl_visitor.py │ ├── declaration.py │ ├── declaration_utils.py │ ├── declarations_matchers.py │ ├── dependencies.py │ ├── elaborated_info.py │ ├── enumeration.py │ ├── free_calldef.py │ ├── function_traits.py │ ├── has_operator_matcher.py │ ├── location.py │ ├── matchers.py │ ├── mdecl_wrapper.py │ ├── namespace.py │ ├── pattern_parser.py │ ├── pointer_traits.py │ ├── runtime_errors.py │ ├── scopedef.py │ ├── templates.py │ ├── traits_impl_details.py │ ├── type_traits.py │ ├── type_traits_classes.py │ ├── type_visitor.py │ ├── typedef.py │ ├── variable.py │ └── xml_generators.py │ ├── parser │ ├── __init__.py │ ├── config.py │ ├── declarations_cache.py │ ├── declarations_joiner.py │ ├── directory_cache.py │ ├── etree_scanner.py │ ├── linker.py │ ├── patcher.py │ ├── project_reader.py │ ├── scanner.py │ └── source_reader.py │ └── utils │ ├── __init__.py │ ├── utils.py │ └── xml_generators.py └── tests ├── __init__.py ├── autoconfig.py ├── conftest.py ├── data ├── abstract_classes.hpp ├── attributes_castxml.hpp ├── attributes_gccxml.hpp ├── better_templates_matcher_tester.hpp ├── binary_parsers │ ├── libconfig.h │ ├── mydll.cpp │ ├── mydll.h │ ├── sconscript │ └── sconstruct ├── bit_fields.hpp ├── classes.hpp ├── complex_types.hpp ├── const_volatile_arg.hpp ├── core_cache.hpp ├── core_class_hierarchy.hpp ├── core_class_hierarchy.hpp.xml ├── core_diamand_hierarchy_base.hpp ├── core_diamand_hierarchy_derived1.hpp ├── core_diamand_hierarchy_derived2.hpp ├── core_diamand_hierarchy_final_derived.hpp ├── core_membership.hpp ├── core_ns_join_1.hpp ├── core_ns_join_2.hpp ├── core_ns_join_3.hpp ├── core_overloads_1.hpp ├── core_overloads_2.hpp ├── core_types.hpp ├── covariant_returns.hpp ├── cpp_standards.hpp ├── decl_cache_file1.txt ├── decl_cache_file1_duplicate.txt ├── decl_cache_file2.txt ├── declaration_string.hpp ├── declarations_calldef.hpp ├── declarations_comparison.hpp ├── declarations_enums.hpp ├── declarations_for_filtering.hpp ├── declarations_variables.hpp ├── find_noncopyable_vars.hpp ├── free_operators.hpp ├── has_public_binary_operator_traits.hpp ├── include_all.hpp ├── include_std.hpp ├── indexing_suites2.hpp ├── inline_specifier.hpp ├── itkImage.xml ├── merge_free_functions.hpp ├── msvc_build │ ├── all.cpp │ ├── msvc_build.sln │ └── msvc_build.vcproj ├── non_copyable_classes.hpp ├── noncopyable.hpp ├── null_comparison.hpp ├── ogre.1.7.xml.bz2 ├── patcher.hpp ├── patcher_tester_64bit.xml ├── plain_c.c ├── remove_template_defaults.hpp ├── separate_compilation │ ├── all.h │ ├── base.h │ ├── data.h │ └── derived.h ├── string_traits.hpp ├── test_argument_without_name.hpp ├── test_array_argument.hpp ├── test_ccflags.hpp ├── test_comments.hpp ├── test_copy_constructor.hpp ├── test_deprecation.hpp ├── test_dynamic_exception.hpp ├── test_elaborated_types.hpp ├── test_function_pointer.hpp ├── test_map_gcc5.hpp ├── test_non_copyable_recursive.hpp ├── test_order.hpp ├── test_overrides.hpp ├── test_pattern_parser.hpp ├── test_smart_pointer.hpp ├── type_as_exception_bug.h ├── type_traits.hpp ├── typedefs1.hpp ├── typedefs2.hpp ├── typedefs_base.hpp ├── unnamed_classes.hpp ├── unnamed_enums_bug1.hpp ├── unnamed_enums_bug2.hpp ├── unnamed_ns_bug.hpp └── vector_traits.hpp ├── example_tester_wrap.py ├── test_algorithms_cache.py ├── test_argument_without_name.py ├── test_array_argument.py ├── test_array_bug.py ├── test_attributes.py ├── test_better_templates_matcher.py ├── test_bit_fields.py ├── test_cache_enums.py ├── test_cached_source_file.py ├── test_call_invocation.py ├── test_calldef_matcher.py ├── test_calling_convention.py ├── test_castxml_wrong_epic.py ├── test_ccflags.py ├── test_comments.py ├── test_complex_types.py ├── test_config.py ├── test_const_volatile_arg.py ├── test_copy_constructor.py ├── test_copy_constructor2.py ├── test_core.py ├── test_cpp_standards.py ├── test_create_decl_string.py ├── test_decl_printer.py ├── test_decl_string.py ├── test_declaration_files.py ├── test_declaration_matcher.py ├── test_declarations.py ├── test_declarations_cache.py ├── test_declarations_comparison.py ├── test_dependencies.py ├── test_deprecation.py ├── test_directory_cache.py ├── test_dynamic_exception.py ├── test_elaborated_types.py ├── test_example.py ├── test_file_cache.py ├── test_filters_tester.py ├── test_find_container_traits.py ├── test_find_noncopyable_vars.py ├── test_free_operators.py ├── test_function_pointer.py ├── test_function_traits.py ├── test_gccxml10184.py ├── test_gccxml10185.py ├── test_has_binary_operator_traits.py ├── test_hash.py ├── test_hierarchy_traveling.py ├── test_inline_specifier.py ├── test_map_gcc5.py ├── test_namespace_matcher.py ├── test_non_copyable_classes.py ├── test_non_copyable_recursive.py ├── test_null_comparison.py ├── test_order.py ├── test_overrides.py ├── test_parser_raise.py ├── test_patcher.py ├── test_pattern_parser.py ├── test_plain_c.py ├── test_project_reader_correctness.py ├── test_remove_template_defaults.py ├── test_smart_pointer.py ├── test_source_reader.py ├── test_start_with_declarations.py ├── test_string_traits.py ├── test_templates.py ├── test_text_reader.py ├── test_type_as_exception_bug.py ├── test_type_traits.py ├── test_typedefs.py ├── test_unnamed_classes.py ├── test_unnamed_enums_bug.py ├── test_utils.py ├── test_variable_matcher.py ├── test_vector_traits.py ├── test_warn_missing_include_dirs.py ├── test_xml_generators.py ├── test_xmlfile_reader.py └── xml_generator.cfg /.binder/.dockerignore: -------------------------------------------------------------------------------- 1 | README.md 2 | -------------------------------------------------------------------------------- /.binder/README.md: -------------------------------------------------------------------------------- 1 | # Docker Image for Binder 2 | 3 | 7 | 8 | *Note that due to Binder conventions, this directory MUST always be in the root 9 | of the repository and named either `binder` or `.binder`. This image is NOT 10 | intended for use by most developers or users.* 11 | 12 | These instructions are for running the image locally. For Binder itself, you 13 | should only need to visit the link from the root-level README. 14 | 15 | To create a Docker image and run a Docker container similar to those used by 16 | [Binder](https://mybinder.org) for local debugging purposes, execute the 17 | following `build` and `run` commands from the top level of this Git repository: 18 | 19 | ```bash 20 | docker build -f .binder/Dockerfile -t binder . 21 | docker run --rm -it --name mybinder -p 8888:8888 binder 22 | ``` 23 | 24 | For the URLs printed, only open the `127.0.0.1:8888` URL (including the login 25 | token) in a web browser on your host system. 26 | 27 | To stop the running container, simply exit it from the terminal with Ctrl+C. 28 | 29 | *Note*: If you want to test the Docker image with the current source tree 30 | (without copying, so you can modify source files), insert the arguments 31 | `-v "${PWD}:/home/jovyan/pygccxml"` to `docker run`, before the image name 32 | (`binder`), to mount it directly. This will *not* act on any changes to 33 | `./setup.py`. 34 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | source = pygccxml,docs/examples,unittests 3 | # unittest/misc contains some tests that are just there for debugging 4 | # purposes and which do not need to be covered. 5 | omit = unittests/misc,unittests/demangled_tester.py 6 | parallel = True 7 | 8 | [report] 9 | # Regexes for lines to exclude from consideration 10 | exclude_lines = 11 | # Have to re-enable the standard pragma 12 | pragma: no cover 13 | 14 | # Don't complain about missing debug-only code: 15 | def __repr__ 16 | if self\.debug 17 | 18 | # Don't complain if tests don't hit defensive assertion code: 19 | raise AssertionError 20 | raise NotImplementedError 21 | 22 | # Don't complain if non-runnable code isn't run: 23 | if 0: 24 | if __name__ == .__main__.: 25 | 26 | # Unittests runner 27 | unittest.TextTestRunner\( 28 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .gitignore -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | README.rst merge=ours 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.pyo 3 | *~ 4 | docs/_build 5 | tests/temp 6 | tests/data/pygccxml.cache 7 | tests/data/directory_cache_test 8 | tests/data/ogre.1.7.xml 9 | unittests/temp 10 | unittests/data/pygccxml.cache 11 | unittests/data/directory_cache_test 12 | unittests/data/ogre.1.7.xml 13 | .idea 14 | dist 15 | build 16 | pygccxml.egg-info 17 | *.prof 18 | .coverage* 19 | docs/examples/caching/example.hpp.xml 20 | test_cost.log 21 | docs/apidocs 22 | htmlcov 23 | /venv/ 24 | -------------------------------------------------------------------------------- /LICENSE.rst: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | pygccxml 2 | Copyright Insight Software Consortium 3 | 4 | This software is distributed under the Boost Software License - Version 1.0. 5 | 6 | See LICENSE file for details. 7 | 8 | ----------------------------------------------------------------------- 9 | 10 | Historical Note: 11 | 12 | pygccxml was initially developed by Roman Yakovenko. 13 | It is maintained by the Insight Software Consortium since 2014. 14 | -------------------------------------------------------------------------------- /docs/declarations_uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CastXML/pygccxml/26f63dc1f473114f836a43c309eaf5f65e5c5554/docs/declarations_uml.png -------------------------------------------------------------------------------- /docs/documentation.rst: -------------------------------------------------------------------------------- 1 | Building the documentation 2 | ========================== 3 | 4 | Building the documentation locally 5 | ---------------------------------- 6 | 7 | You can build the documentation yourself. In order for this to work you need 8 | sphinx doc (http://sphinx-doc.org) and the readthedocs theme: 9 | 10 | .. code-block:: shell 11 | 12 | pip install .[docs] 13 | 14 | Then just run the following command in the root folder: 15 | 16 | .. code-block:: shell 17 | 18 | make html 19 | 20 | This will build the documentation locally in the ``docs/_build/html`` folder. 21 | 22 | For each commit on the master and develop branches, the documentation is 23 | automatically built and can be found here: https://readthedocs.org/projects/pygccxml/ 24 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | ======== 2 | Examples 3 | ======== 4 | 5 | Setting up pygccxml and parsing c/c++ code 6 | ------------------------------------------ 7 | 8 | .. toctree:: 9 | :maxdepth: 1 10 | 11 | examples/parsing/example.rst 12 | examples/parsing-string/example.rst 13 | 14 | First examples 15 | -------------- 16 | 17 | .. toctree:: 18 | :maxdepth: 1 19 | 20 | examples/variables/example.rst 21 | examples/searching1/example.rst 22 | examples/searching/example.rst 23 | examples/equality/example.rst 24 | examples/functions/example.rst 25 | examples/nested-types/example.rst 26 | examples/artificial/example.rst 27 | examples/compound/example.rst 28 | examples/templates/example.rst 29 | 30 | Advanced examples 31 | ----------------- 32 | 33 | .. toctree:: 34 | :maxdepth: 1 35 | 36 | examples/elaborated/example.rst 37 | examples/function-pointer/example.rst 38 | examples/caching/example.rst 39 | examples/print-example/example.rst 40 | 41 | -------------------------------------------------------------------------------- /docs/examples/artificial/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | namespace ns{ 7 | class Test { 8 | public: 9 | Test(); // This is the constructor 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /docs/examples/artificial/example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from pygccxml import utils 7 | from pygccxml import declarations 8 | from pygccxml import parser 9 | 10 | import os 11 | import sys 12 | import warnings 13 | warnings.simplefilter("error", Warning) 14 | # Find out the file location within the sources tree 15 | this_module_dir_path = os.path.abspath( 16 | os.path.dirname(sys.modules[__name__].__file__)) 17 | 18 | # Find out the c++ parser 19 | generator_path, generator_name = utils.find_xml_generator() 20 | 21 | # Configure the xml generator 22 | xml_generator_config = parser.xml_generator_configuration_t( 23 | xml_generator_path=generator_path, 24 | xml_generator=generator_name) 25 | 26 | # The c++ file we want to parse 27 | filename = "example.hpp" 28 | filename = this_module_dir_path + "/" + filename 29 | 30 | decls = parser.parse([filename], xml_generator_config) 31 | global_namespace = declarations.get_global_namespace(decls) 32 | ns = global_namespace.namespace("ns") 33 | 34 | # We have just one declaration in ns, which is our Test class: 35 | classTest = ns.declarations[0] 36 | print(classTest.name, type(classTest)) 37 | # > 'Test', ns::Test::Test() [constructor], False 43 | # > ns::Test::Test(ns::Test const & arg0) [constructor], True 44 | -------------------------------------------------------------------------------- /docs/examples/artificial/example.rst: -------------------------------------------------------------------------------- 1 | ======================================== 2 | Explicit and implicit class declarations 3 | ======================================== 4 | 5 | Even if a class has no explicit constructor, ``pygccxml`` will provide 6 | a constructor declaration. This is due to ``CastXML`` and ``GCC-XML`` generating 7 | implicit constructors (for example copy constructors) in their XML output. 8 | The same thing holds for assignment operators and destructors. 9 | 10 | To be able to discriminate between the different types of declarations, 11 | the ``decl.is_artificial`` attribute can be used. 12 | 13 | Let’s consider the following c++ file (example.hpp): 14 | 15 | .. literalinclude:: example.hpp 16 | :language: c++ 17 | :lines: 5- 18 | 19 | In this example, the constructor is explicitly defined. The declaration tree 20 | will contain two constructors. The first one is the one we defined explicitly, 21 | and is not marked as artificial. The second one is the copy constructor, which was 22 | implicitly added, and is marked as artificial. 23 | 24 | .. literalinclude:: example.py 25 | :language: python 26 | :lines: 6,7,8,17-27,29- 27 | -------------------------------------------------------------------------------- /docs/examples/caching/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | namespace ns{ 7 | int a = 1; 8 | } 9 | -------------------------------------------------------------------------------- /docs/examples/caching/example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from pygccxml import utils 7 | from pygccxml import declarations 8 | from pygccxml import parser 9 | 10 | import os 11 | import sys 12 | import warnings 13 | warnings.simplefilter("error", Warning) 14 | # Find out the file location within the sources tree 15 | this_module_dir_path = os.path.abspath( 16 | os.path.dirname(sys.modules[__name__].__file__)) 17 | 18 | # Find out the c++ parser 19 | generator_path, generator_name = utils.find_xml_generator() 20 | 21 | # Configure the xml generator 22 | xml_generator_config = parser.xml_generator_configuration_t( 23 | xml_generator_path=generator_path, 24 | xml_generator=generator_name) 25 | 26 | # The c++ file we want to parse 27 | filename = "example.hpp" 28 | filename = this_module_dir_path + "/" + filename 29 | 30 | file_config = parser.file_configuration_t( 31 | data=filename, 32 | content_type=parser.CONTENT_TYPE.CACHED_SOURCE_FILE) 33 | 34 | project_reader = parser.project_reader_t(xml_generator_config) 35 | decls = project_reader.read_files( 36 | [file_config], 37 | compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE) 38 | 39 | global_namespace = declarations.get_global_namespace(decls) 40 | 41 | value = global_namespace.namespace("ns") 42 | print("My name is: " + value.name) 43 | -------------------------------------------------------------------------------- /docs/examples/caching/example.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | Caching 3 | ======= 4 | 5 | This example shows how to use caching. This can be useful 6 | for big projects where you don't want the c++ to be parsed 7 | again and again. 8 | 9 | Let's consider the following c++ file: 10 | 11 | .. literalinclude:: example.hpp 12 | :language: c++ 13 | :lines: 5- 14 | 15 | To enable caching, you can use the following code: 16 | 17 | .. literalinclude:: example.py 18 | :language: python 19 | :lines: 6,7,8,17-27,29- 20 | 21 | The first time you run this example, the c++ file will be read and a xml 22 | file will be generated: 23 | 24 | INFO Creating xml file "example.hpp.xml" from source file "example.hpp" ... 25 | INFO Parsing xml file "example.hpp.xml" ... 26 | My name is: ns 27 | 28 | The second time you run the example the xml file will not be regenerated: 29 | 30 | INFO Parsing xml file "example.hpp.xml" ... 31 | My name is: ns 32 | 33 | Of course the performance gain will be small for this example, 34 | but can be intersting for bigger projects. 35 | -------------------------------------------------------------------------------- /docs/examples/compound/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | int const c1 = 0; 7 | const int c2 = 0; 8 | 9 | volatile const int cv1 = 0; 10 | const volatile int cv2 = 0; 11 | 12 | const int * const cptr1 = 0; 13 | -------------------------------------------------------------------------------- /docs/examples/compound/example.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | Compound types 3 | ============== 4 | 5 | A type is a compound_t type (in pygccxml) if it is one of the following: 6 | *volatile_t*, *restrict_t*, *const_t*, *pointer_t*, *reference_t*, 7 | *elaborated_t*, *array_t* or *member_variable_type_t*. 8 | 9 | The exact c++ definition of compound types embraces more types, but for different 10 | reasons (mostly legacy), the definition in pygccxml is slightly different. 11 | 12 | Let's consider the following c++ file: 13 | 14 | .. literalinclude:: example.hpp 15 | :language: c++ 16 | :lines: 5- 17 | 18 | The following code will show what to expect from compound types, how they are 19 | chained, and how their order is defined in pygccxml. 20 | 21 | .. literalinclude:: example.py 22 | :language: python 23 | :lines: 6,7,8,17-27,29- 24 | -------------------------------------------------------------------------------- /docs/examples/elaborated/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | class A {}; 7 | 8 | A a1; 9 | class A a2; 10 | 11 | void function(A arg1, class A arg2); 12 | -------------------------------------------------------------------------------- /docs/examples/elaborated/example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from pygccxml import utils 7 | from pygccxml import declarations 8 | from pygccxml import parser 9 | 10 | import os 11 | import sys 12 | import warnings 13 | warnings.simplefilter("error", Warning) 14 | # Find out the file location within the sources tree 15 | this_module_dir_path = os.path.abspath( 16 | os.path.dirname(sys.modules[__name__].__file__)) 17 | 18 | # Find out the c++ parser 19 | generator_path, generator_name = utils.find_xml_generator() 20 | 21 | # Configure the xml generator 22 | xml_generator_config = parser.xml_generator_configuration_t( 23 | xml_generator_path=generator_path, 24 | xml_generator=generator_name, 25 | castxml_epic_version=1) 26 | 27 | # The c++ file we want to parse 28 | filename = "example.hpp" 29 | filename = this_module_dir_path + "/" + filename 30 | 31 | decls = parser.parse([filename], xml_generator_config) 32 | global_namespace = declarations.get_global_namespace(decls) 33 | 34 | a1 = global_namespace.variable("a1") 35 | print(str(a1.decl_type), type(a1.decl_type)) 36 | # > 'A', 37 | 38 | print(declarations.is_elaborated(a1.decl_type)) 39 | # > False 40 | 41 | a2 = global_namespace.variable("a2") 42 | print(str(a2.decl_type), type(a2.decl_type)) 43 | # > 'class ::A', 44 | 45 | print(declarations.is_elaborated(a2.decl_type)) 46 | # > True 47 | 48 | base = declarations.remove_elaborated(a2.decl_type) 49 | print(str(base), type(base)) 50 | # > 'A', 51 | 52 | # The same can be done with function arguments: 53 | fun = global_namespace.free_function("function") 54 | print(type(fun.arguments[0].decl_type), type(fun.arguments[1].decl_type)) 55 | # > , 56 | # 57 | -------------------------------------------------------------------------------- /docs/examples/elaborated/example.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | Elaborated type specifiers 3 | ========================== 4 | 5 | Elaborated type specifiers are one of these four possibilities: *class*, *struct*, *union* or *enum*. 6 | 7 | In C++ they can often be skipped (but may be useful; see `this interesting topic`_ for example). 8 | In C code they are mandatory. 9 | 10 | Let's consider the following c++ file: 11 | 12 | .. literalinclude:: example.hpp 13 | :language: c++ 14 | :lines: 5- 15 | 16 | The following code will show how the elaborated type specifiers are treated in pygccxml. 17 | Please note that this feature is only available since recent versions of *CastXML* (Mar 1, 2017), 18 | and a special flag needs to be passed to pygccxml to make this work (castxml_epic_version=1). 19 | 20 | .. literalinclude:: example.py 21 | :language: python 22 | :lines: 6,7,8,17-27,29- 23 | 24 | .. _`this interesting topic`: http://stackoverflow.com/questions/1675351/typedef-struct-vs-struct-definitions/1675446#1675446 -------------------------------------------------------------------------------- /docs/examples/equality/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | namespace ns{ 7 | void func1(int a) { 8 | int b = a; 9 | } 10 | 11 | void func2(int a) { 12 | int b = a; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /docs/examples/equality/example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from pygccxml import utils 7 | from pygccxml import declarations 8 | from pygccxml import parser 9 | 10 | import os 11 | import sys 12 | import warnings 13 | warnings.simplefilter("error", Warning) 14 | # Find out the file location within the sources tree 15 | this_module_dir_path = os.path.abspath( 16 | os.path.dirname(sys.modules[__name__].__file__)) 17 | 18 | # Find the location of the xml generator (castxml or gccxml) 19 | generator_path, generator_name = utils.find_xml_generator() 20 | 21 | # Configure the xml generator 22 | xml_generator_config = parser.xml_generator_configuration_t( 23 | xml_generator_path=generator_path, 24 | xml_generator=generator_name) 25 | 26 | # The c++ file we want to parse 27 | filename = "example.hpp" 28 | filename = this_module_dir_path + "/" + filename 29 | 30 | # Parse the c++ file 31 | decls = parser.parse([filename], xml_generator_config) 32 | 33 | global_namespace = declarations.get_global_namespace(decls) 34 | 35 | ns_namespace = global_namespace.namespace("ns") 36 | 37 | # Search for the function called func1 38 | criteria = declarations.calldef_matcher(name="func1") 39 | func1a = declarations.matcher.get_single(criteria, ns_namespace) 40 | 41 | # Search for the function called func2 42 | criteria = declarations.calldef_matcher(name="func2") 43 | func2a = declarations.matcher.get_single(criteria, ns_namespace) 44 | 45 | # You can also write a loop on the declaration tree 46 | func1b = None 47 | for decl in ns_namespace.declarations: 48 | if decl.name == "func1": 49 | func1b = decl 50 | 51 | # The declarations can be compared (prints (True, False)) 52 | print(func1a == func1b, func1a == func2a) 53 | -------------------------------------------------------------------------------- /docs/examples/equality/example.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | Comparing two declarations 3 | ========================== 4 | 5 | This example shows how two declarations can be compared. 6 | 7 | Let's consider the following c++ file (example.hpp): 8 | 9 | .. literalinclude:: example.hpp 10 | :language: c++ 11 | :lines: 5- 12 | 13 | The following code will show you how to search for two functions, using 14 | different ways. Both declarations are then compared. 15 | 16 | .. literalinclude:: example.py 17 | :language: python 18 | :lines: 6,7,8,17-27,29- 19 | -------------------------------------------------------------------------------- /docs/examples/function-pointer/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // Copyright 2004-2009 Roman Yakovenko. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // A function pointer 7 | void (*myFuncPointer)(int, double); 8 | -------------------------------------------------------------------------------- /docs/examples/function-pointer/example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from pygccxml import utils 7 | from pygccxml import declarations 8 | from pygccxml import parser 9 | 10 | import os 11 | import sys 12 | import warnings 13 | warnings.simplefilter("error", Warning) 14 | # Find out the file location within the sources tree 15 | this_module_dir_path = os.path.abspath( 16 | os.path.dirname(sys.modules[__name__].__file__)) 17 | 18 | # Find out the c++ parser 19 | generator_path, generator_name = utils.find_xml_generator() 20 | 21 | # Configure the xml generator 22 | xml_generator_config = parser.xml_generator_configuration_t( 23 | xml_generator_path=generator_path, 24 | xml_generator=generator_name) 25 | 26 | # The c++ file we want to parse 27 | filename = "example.hpp" 28 | filename = this_module_dir_path + "/" + filename 29 | 30 | decls = parser.parse([filename], xml_generator_config) 31 | global_namespace = declarations.get_global_namespace(decls) 32 | 33 | function_ptr = global_namespace.variables()[0] 34 | 35 | # Print the name of the function pointer 36 | print(function_ptr.name) 37 | # > myFuncPointer 38 | 39 | # Print the type of the declaration 40 | print(function_ptr.decl_type) 41 | # > void (*)( int,double ) 42 | 43 | # Print the real type of the declaration (it's just a pointer) 44 | print(type(function_ptr.decl_type)) 45 | # > 46 | 47 | # Check if this is a function pointer 48 | print(declarations.is_calldef_pointer(function_ptr.decl_type)) 49 | # > True 50 | 51 | # Remove the pointer part, to access the function's type 52 | f_type = declarations.remove_pointer(function_ptr.decl_type) 53 | 54 | # Print the type 55 | print(type(f_type)) 56 | # > 57 | 58 | # Print the return type and the arguments of the function 59 | print(f_type.return_type) 60 | # > void 61 | 62 | # Print the return type and the arguments 63 | print(str(f_type.arguments_types[0]), str(f_type.arguments_types[1])) 64 | # > int, double 65 | -------------------------------------------------------------------------------- /docs/examples/function-pointer/example.rst: -------------------------------------------------------------------------------- 1 | ================= 2 | Function pointers 3 | ================= 4 | 5 | This example shows how to work with function pointers. 6 | 7 | Let's consider the following c++ file: 8 | 9 | .. literalinclude:: example.hpp 10 | :language: c++ 11 | :lines: 5- 12 | 13 | The following code allows you to extract information about the function pointer: 14 | 15 | .. literalinclude:: example.py 16 | :language: python 17 | :lines: 6,7,8,17-27,29- 18 | -------------------------------------------------------------------------------- /docs/examples/functions/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #include 7 | using namespace std; 8 | 9 | namespace ns{ 10 | int myFunction(int a, const std::string& x1) { 11 | return a + 1; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /docs/examples/functions/example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from pygccxml import utils 7 | from pygccxml import declarations 8 | from pygccxml import parser 9 | 10 | import os 11 | import sys 12 | import warnings 13 | warnings.simplefilter("error", Warning) 14 | # Find out the file location within the sources tree 15 | this_module_dir_path = os.path.abspath( 16 | os.path.dirname(sys.modules[__name__].__file__)) 17 | 18 | # Find out the c++ parser 19 | generator_path, generator_name = utils.find_xml_generator() 20 | 21 | # Configure the xml generator 22 | xml_generator_config = parser.xml_generator_configuration_t( 23 | xml_generator_path=generator_path, 24 | xml_generator=generator_name) 25 | 26 | # The c++ file we want to parse 27 | filename = "example.hpp" 28 | filename = this_module_dir_path + "/" + filename 29 | 30 | decls = parser.parse([filename], xml_generator_config) 31 | global_namespace = declarations.get_global_namespace(decls) 32 | ns = global_namespace.namespace("ns") 33 | 34 | # Use the free_functions method to find our function 35 | func = ns.free_function(name="myFunction") 36 | 37 | # There are two arguments: 38 | print(len(func.arguments)) 39 | 40 | # We can loop over them and print some information: 41 | for arg in func.arguments: 42 | print( 43 | arg.name, 44 | str(arg.decl_type), 45 | declarations.is_std_string(arg.decl_type), 46 | declarations.is_reference(arg.decl_type)) 47 | -------------------------------------------------------------------------------- /docs/examples/functions/example.rst: -------------------------------------------------------------------------------- 1 | ======================= 2 | Functions and arguments 3 | ======================= 4 | 5 | This example shows how to work with function arguments 6 | 7 | Let's consider the following c++ file: 8 | 9 | .. literalinclude:: example.hpp 10 | :language: c++ 11 | :lines: 5- 12 | 13 | The following code can be used to find the different arguments of a function and 14 | do some basic operations on them: 15 | 16 | .. literalinclude:: example.py 17 | :language: python 18 | :lines: 6,7,8,17-27,29- 19 | -------------------------------------------------------------------------------- /docs/examples/nested-types/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | namespace ns{ 7 | const int a = 0; 8 | const volatile int *b = 0; 9 | } 10 | -------------------------------------------------------------------------------- /docs/examples/nested-types/example.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Nested types 3 | ============ 4 | 5 | This example shows how to work with types. 6 | 7 | Let's consider the following c++ file: 8 | 9 | .. literalinclude:: example.hpp 10 | :language: c++ 11 | :lines: 5- 12 | 13 | The following code allows you to extract information about the types of variables: 14 | 15 | .. literalinclude:: example.py 16 | :language: python 17 | :lines: 6,7,8,17-27,29- 18 | -------------------------------------------------------------------------------- /docs/examples/parsing-string/example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from pygccxml import utils 7 | from pygccxml import declarations 8 | from pygccxml import parser 9 | 10 | import warnings 11 | warnings.simplefilter("error", Warning) 12 | 13 | # Find the location of the xml generator (castxml or gccxml) 14 | generator_path, generator_name = utils.find_xml_generator() 15 | 16 | # Configure the xml generator 17 | xml_generator_config = parser.xml_generator_configuration_t( 18 | xml_generator_path=generator_path, 19 | xml_generator=generator_name) 20 | 21 | # Write a string containing some c++ code 22 | code = """ 23 | class MyClass { 24 | int a; 25 | }; 26 | """ 27 | 28 | # Parse the code 29 | decls = parser.parse_string(code, xml_generator_config) 30 | 31 | # Get access to the global namespace 32 | global_ns = declarations.get_global_namespace(decls) 33 | -------------------------------------------------------------------------------- /docs/examples/parsing-string/example.rst: -------------------------------------------------------------------------------- 1 | ================================ 2 | Parsing a string containing code 3 | ================================ 4 | 5 | This example shows how to setup pygccxml to parse a string containing c++ code, 6 | and how to access the declaration tree. Often, pygccxml is used to parse files 7 | containing code, but there may be reasons to parse a string (for example 8 | for debugging purposes). 9 | 10 | The following code will show you how to create a configuration for 11 | the xml generator (an external tool, either castxml or gccxml), 12 | and how to parse the string containing the c++ code: 13 | 14 | .. literalinclude:: example.py 15 | :language: python 16 | :lines: 6,7,8,12- 17 | -------------------------------------------------------------------------------- /docs/examples/parsing/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | namespace ns{ 7 | int a = 1; 8 | } 9 | -------------------------------------------------------------------------------- /docs/examples/parsing/example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from pygccxml import utils 7 | from pygccxml import declarations 8 | from pygccxml import parser 9 | 10 | import os 11 | import sys 12 | import warnings 13 | warnings.simplefilter("error", Warning) 14 | # Find out the file location within the sources tree 15 | this_module_dir_path = os.path.abspath( 16 | os.path.dirname(sys.modules[__name__].__file__)) 17 | 18 | # Find the location of the xml generator (castxml or gccxml) 19 | generator_path, generator_name = utils.find_xml_generator() 20 | 21 | # Configure the xml generator 22 | xml_generator_config = parser.xml_generator_configuration_t( 23 | xml_generator_path=generator_path, 24 | xml_generator=generator_name) 25 | 26 | # The c++ file we want to parse 27 | filename = "example.hpp" 28 | filename = this_module_dir_path + "/" + filename 29 | 30 | # Parse the c++ file 31 | decls = parser.parse([filename], xml_generator_config) 32 | 33 | # Get access to the global namespace 34 | global_namespace = declarations.get_global_namespace(decls) 35 | 36 | # Get access to the 'ns' namespace 37 | ns = global_namespace.namespace("ns") 38 | -------------------------------------------------------------------------------- /docs/examples/parsing/example.rst: -------------------------------------------------------------------------------- 1 | ================== 2 | Parsing a c++ file 3 | ================== 4 | 5 | This example shows how to setup pygccxml to parse a c++ file, and how 6 | to access the declaration tree. 7 | 8 | Let's consider the following c++ file (example.hpp): 9 | 10 | .. literalinclude:: example.hpp 11 | :language: c++ 12 | :lines: 5- 13 | 14 | The following code will show you how to create a configuration for 15 | the xml generator (an external tool, either castxml or gccxml), 16 | and how to parse the c++ file: 17 | 18 | .. literalinclude:: example.py 19 | :language: python 20 | :lines: 6,7,8,17-27,29- 21 | -------------------------------------------------------------------------------- /docs/examples/print-example/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef example_hpp_12_10_2006 7 | #define example_hpp_12_10_2006 8 | 9 | 10 | namespace unittests{ 11 | 12 | struct test_results{ 13 | 14 | enum status{ ok, fail, error }; 15 | 16 | void update( const char* test_name, status result ); 17 | }; 18 | 19 | struct test_case{ 20 | 21 | test_case( const char* test_case_name ); 22 | 23 | virtual void set_up(){} 24 | 25 | virtual void tear_down(){} 26 | 27 | virtual void run() = 0; 28 | 29 | private: 30 | const char* m_name; 31 | }; 32 | 33 | class test_container; 34 | 35 | struct test_suite : public test_case{ 36 | 37 | test_suite( const char* name, const test_container& tests ); 38 | 39 | void run(); 40 | 41 | const test_results& get_results() const 42 | { return m_results; } 43 | 44 | private: 45 | test_container* m_tests; 46 | test_results m_results; 47 | }; 48 | 49 | } 50 | 51 | #endif//example_hpp_12_10_2006 52 | -------------------------------------------------------------------------------- /docs/examples/print-example/example.hpp.rst: -------------------------------------------------------------------------------- 1 | =============== 2 | C++ header file 3 | =============== 4 | 5 | .. literalinclude:: example.hpp 6 | :language: c++ 7 | :lines: 5- 8 | -------------------------------------------------------------------------------- /docs/examples/print-example/example.hpp.xml.rst: -------------------------------------------------------------------------------- 1 | ====================== 2 | GCC-XML generated file 3 | ====================== 4 | 5 | .. literalinclude:: ./example.hpp.xml 6 | :language: xml 7 | -------------------------------------------------------------------------------- /docs/examples/print-example/example.py.rst: -------------------------------------------------------------------------------- 1 | ========================= 2 | Python API usage example 3 | ========================= 4 | 5 | .. literalinclude:: example.py 6 | :language: python 7 | :lines: 5- 8 | 9 | -------------------------------------------------------------------------------- /docs/examples/print-example/example.rst: -------------------------------------------------------------------------------- 1 | ====================== 2 | Print all declarations 3 | ====================== 4 | 5 | This example prints all declarations found in :doc:`example.hpp ` 6 | file. 7 | 8 | For every class, it prints it's base and derived classes. 9 | 10 | The example consists from few files: 11 | 12 | .. toctree:: 13 | :maxdepth: 1 14 | 15 | example.hpp.rst 16 | example.hpp.xml.rst 17 | example.py.rst 18 | output.txt.rst 19 | -------------------------------------------------------------------------------- /docs/examples/print-example/output.txt.rst: -------------------------------------------------------------------------------- 1 | ====== 2 | Output 3 | ====== 4 | 5 | .. literalinclude:: ./output.txt 6 | :language: text 7 | -------------------------------------------------------------------------------- /docs/examples/searching/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | namespace ns{ 7 | int a = 1; 8 | int b = 2; 9 | double c = 3.0; 10 | 11 | int func1(int a) { 12 | int b = a + 2; 13 | return b; 14 | } 15 | 16 | double func2(double a) { 17 | double b = a + 2.0; 18 | return b; 19 | } 20 | 21 | double func3(double a) { 22 | double b = a + 3.0; 23 | return b; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /docs/examples/searching/example.rst: -------------------------------------------------------------------------------- 1 | ============================================ 2 | Searching for a declaration (using matchers) 3 | ============================================ 4 | 5 | This example shows how to search for a specific declaration using different criteria. 6 | 7 | Let's consider the following c++ file (example.hpp): 8 | 9 | .. literalinclude:: example.hpp 10 | :language: c++ 11 | :lines: 5- 12 | 13 | The following code will show you how to search for functions and variables 14 | 15 | .. literalinclude:: example.py 16 | :language: python 17 | :lines: 6,7,8,17-27,29- 18 | -------------------------------------------------------------------------------- /docs/examples/searching1/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | namespace ns{ 7 | int a = 1; 8 | int b = 2; 9 | double c = 3.0; 10 | 11 | double func2(double a) { 12 | double b = a + 2.0; 13 | return b; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /docs/examples/searching1/example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from pygccxml import utils 7 | from pygccxml import declarations 8 | from pygccxml import parser 9 | 10 | import os 11 | import sys 12 | import warnings 13 | warnings.simplefilter("error", Warning) 14 | # Find out the file location within the sources tree 15 | this_module_dir_path = os.path.abspath( 16 | os.path.dirname(sys.modules[__name__].__file__)) 17 | 18 | # Find the location of the xml generator (castxml or gccxml) 19 | generator_path, generator_name = utils.find_xml_generator() 20 | 21 | # Configure the xml generator 22 | xml_generator_config = parser.xml_generator_configuration_t( 23 | xml_generator_path=generator_path, 24 | xml_generator=generator_name) 25 | 26 | # The c++ file we want to parse 27 | filename = "example.hpp" 28 | filename = this_module_dir_path + "/" + filename 29 | 30 | # Parse the c++ file 31 | decls = parser.parse([filename], xml_generator_config) 32 | 33 | global_namespace = declarations.get_global_namespace(decls) 34 | 35 | ns_namespace = global_namespace.namespace("ns") 36 | 37 | int_type = declarations.cpptypes.int_t() 38 | double_type = declarations.cpptypes.double_t() 39 | 40 | for decl in ns_namespace.declarations: 41 | print(decl) 42 | 43 | # This prints all the declarations in the namespace declaration tree: 44 | # ns::a [variable] 45 | # ns::b [variable] 46 | # ns::c [variable] 47 | # double ns::func2(double a) [free function] 48 | 49 | # Let's search for specific declarations 50 | for decl in ns_namespace.declarations: 51 | if decl.name == "b": 52 | print(decl) 53 | if isinstance(decl, declarations.free_function_t): 54 | print(decl) 55 | 56 | # This prints: 57 | # ns::b [variable] 58 | # double ns::func2(double a) [free function] 59 | -------------------------------------------------------------------------------- /docs/examples/searching1/example.rst: -------------------------------------------------------------------------------- 1 | ========================================== 2 | Searching for a declaration (using a loop) 3 | ========================================== 4 | 5 | This example shows how to search for a specific declaration using a loop on the declarations tree. 6 | 7 | Let's consider the following c++ file (example.hpp): 8 | 9 | .. literalinclude:: example.hpp 10 | :language: c++ 11 | :lines: 5- 12 | 13 | The following code will show you how to loop on the tree and find a declaration 14 | 15 | .. literalinclude:: example.py 16 | :language: python 17 | :lines: 6,7,8,17-27,29- 18 | -------------------------------------------------------------------------------- /docs/examples/templates/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | namespace ns { 7 | 8 | struct B { 9 | struct D { bool d; }; 10 | }; 11 | struct D {}; 12 | 13 | template 14 | struct T {}; 15 | 16 | T function(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /docs/examples/templates/example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from pygccxml import utils 7 | from pygccxml import declarations 8 | from pygccxml import parser 9 | 10 | import os 11 | import sys 12 | import warnings 13 | warnings.simplefilter("error", Warning) 14 | # Find out the file location within the sources tree 15 | this_module_dir_path = os.path.abspath( 16 | os.path.dirname(sys.modules[__name__].__file__)) 17 | 18 | # Find out the c++ parser 19 | generator_path, generator_name = utils.find_xml_generator() 20 | 21 | # Configure the xml generator 22 | xml_generator_config = parser.xml_generator_configuration_t( 23 | xml_generator_path=generator_path, 24 | xml_generator=generator_name) 25 | 26 | # The c++ file we want to parse 27 | filename = "example.hpp" 28 | filename = this_module_dir_path + "/" + filename 29 | 30 | decls = parser.parse([filename], xml_generator_config) 31 | global_namespace = declarations.get_global_namespace(decls) 32 | ns = global_namespace.namespace("ns") 33 | 34 | class_t_decl = [] 35 | for d in ns.declarations: 36 | if isinstance(d, declarations.class_declaration_t): 37 | class_declaration_t = d 38 | if isinstance(d, declarations.class_t): 39 | class_t_decl.append(d) 40 | if isinstance(d, declarations.free_function_t): 41 | free_function_t_decl = d 42 | 43 | print(class_t_decl[0]) 44 | # > ns::B [struct] 45 | 46 | print(class_t_decl[1]) 47 | # > ns::D [struct] 48 | 49 | print(class_declaration_t) 50 | # > ns::T [class declaration] 51 | 52 | print(free_function_t_decl) 53 | # > ns::T ns::function() [free function] 54 | 55 | print(declarations.templates.is_instantiation(class_declaration_t.name)) 56 | # > True 57 | 58 | name, parameter_list = declarations.templates.split(class_declaration_t.name) 59 | print(name, parameter_list) 60 | # > 'T', ['ns::B::D', 'bool'] 61 | -------------------------------------------------------------------------------- /docs/examples/templates/example.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | C++ Templates 3 | ============= 4 | 5 | pygccxml has minimal support for c++ templates, but there is some information 6 | that can be extracted from templated declarations. 7 | 8 | Let's consider the following c++ file (example.hpp): 9 | 10 | .. literalinclude:: example.hpp 11 | :language: c++ 12 | :lines: 5- 13 | 14 | This example show how to extract template parameters from the template declaration. 15 | 16 | .. literalinclude:: example.py 17 | :language: python 18 | :lines: 6,7,8,17-27,29- 19 | -------------------------------------------------------------------------------- /docs/examples/variables/example.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | namespace ns{ 7 | int a = 1; 8 | int b = 2; 9 | double c = 3.0; 10 | } 11 | -------------------------------------------------------------------------------- /docs/examples/variables/example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from pygccxml import utils 7 | from pygccxml import declarations 8 | from pygccxml import parser 9 | 10 | import os 11 | import sys 12 | import warnings 13 | warnings.simplefilter("error", Warning) 14 | # Find out the file location within the sources tree 15 | this_module_dir_path = os.path.abspath( 16 | os.path.dirname(sys.modules[__name__].__file__)) 17 | 18 | # Find out the c++ parser 19 | generator_path, generator_name = utils.find_xml_generator() 20 | 21 | # Configure the xml generator 22 | xml_generator_config = parser.xml_generator_configuration_t( 23 | xml_generator_path=generator_path, 24 | xml_generator=generator_name) 25 | 26 | # The c++ file we want to parse 27 | filename = "example.hpp" 28 | filename = this_module_dir_path + "/" + filename 29 | 30 | decls = parser.parse([filename], xml_generator_config) 31 | global_namespace = declarations.get_global_namespace(decls) 32 | ns = global_namespace.namespace("ns") 33 | 34 | # The variables() method will return a list of variables. 35 | # We know that the c variable is the third one in the list: 36 | c = ns.variables()[2] 37 | print("My name is: " + c.name) 38 | print("My type is: " + str(c.decl_type)) 39 | print("My value is: " + c.value) 40 | 41 | # Of course you can also loop over the list and look for the right name 42 | for var in ns.variables(): 43 | if var.name == "c": 44 | print("My name is: " + var.name) 45 | print("My type is: " + str(var.decl_type)) 46 | print("My value is: " + var.value) 47 | 48 | # One way to get a variable is to use the variable() method and 49 | # a lambda function. This is the most flexible way as you can implement 50 | # your own lambda function to filter out variables following your 51 | # specific criteria. 52 | c = ns.variable(lambda v: v.name == "c") 53 | print("My name is: " + c.name) 54 | print("My type is: " + str(c.decl_type)) 55 | print("My value is: " + c.value) 56 | -------------------------------------------------------------------------------- /docs/examples/variables/example.rst: -------------------------------------------------------------------------------- 1 | ========= 2 | Variables 3 | ========= 4 | 5 | This example shows how to find variables and find information about them. 6 | 7 | Let's consider the following c++ file: 8 | 9 | .. literalinclude:: example.hpp 10 | :language: c++ 11 | :lines: 5- 12 | 13 | The following code can be use to find the variable named "c" using different 14 | strategies, and to print information about it: 15 | 16 | .. literalinclude:: example.py 17 | :language: python 18 | :lines: 6,7,8,17-27,29- 19 | -------------------------------------------------------------------------------- /docs/history.rst: -------------------------------------------------------------------------------- 1 | History and Credits 2 | =================== 3 | 4 | History 5 | ------- 6 | 7 | The original author and maintainer for pygccxml was Roman Yakovenko (2004-2011). 8 | 9 | Holger Frydrych forked the project to work on python 3 support. Finally, Mark Moll 10 | forked the project a second time to carry on the work of porting the code 11 | to python 3 (keeping it compatible with python 2). 12 | 13 | In Mai 2014, Michka Popoff and the Insight Software Consortium revived pygccxml 14 | by setting up a git repositery on GitHub, hosted along with gccxml. 15 | 16 | The full changelog can be found in the CHANGELOG.md file. 17 | 18 | Contributors 19 | ------------ 20 | 21 | Thanks to all the people that have contributed patches, bug reports and suggestions, 22 | or supported this project. 23 | 24 | * Roman Yakovenko (original author) 25 | * Michka Popoff (actual maintainer) 26 | 27 | A special thanks to the Insight Software Consortium for their help and collaboration, 28 | especially: 29 | 30 | * Brad King 31 | * Matt Mccormick 32 | 33 | Contributors can be found on github's contributors page: https://github.com/gccxml/pygccxml/graphs/contributors 34 | 35 | Here is the original list of contributors from before the GitHub migration. 36 | 37 | * Roman Yakovenko's wife - Yulia 38 | * Mark Moll 39 | * Holger Frydrych 40 | * John Pallister 41 | * Matthias Baas 42 | * Allen Bierbaum 43 | * Georgiy Dernovoy 44 | * Darren Garnier 45 | * Gottfried Ganssauge 46 | * Gaetan Lehmann 47 | * Martin Preisler 48 | * Miguel Lobo 49 | * Jeremy Sanders 50 | * Ben Schleimer 51 | * Gustavo Carneiro 52 | * Christopher Bruns 53 | * Alejandro Dubrovsky 54 | * Aron Xu 55 | -------------------------------------------------------------------------------- /docs/install.rst: -------------------------------------------------------------------------------- 1 | Download & Install 2 | ================== 3 | 4 | Prerequisite: CastXML 5 | --------------------- 6 | 7 | `CastXML`_ needs to be installed on your system. 8 | 9 | 1) If you are on linux or mac, your package manager may already provide a "castxml" package. 10 | 11 | 2) You can download pre-compiled binaries for `Linux`_, for `OS X`_ and for `Windows`_. 12 | 13 | 3) You can compile CastXML from source, either with the `SuperBuild`_, or by following the `full install instructions`_ . 14 | 15 | 16 | Installation of pygccxml 17 | ------------------------ 18 | 19 | You can use pip to install pygccxml: 20 | 21 | .. code-block:: shell 22 | 23 | pip install pygccxml 24 | 25 | To install from source, you can use the usual procedure: 26 | 27 | .. code-block:: shell 28 | 29 | pip install . 30 | 31 | For development 32 | %%%%%%%%%%%%%%% 33 | 34 | You should use a ``virtualenv`` when possible. Example recipe: 35 | 36 | .. code-block:: shell 37 | 38 | cd pygccxml # git root 39 | python -m virtualenv ./venv 40 | source ./venv/bin/activate 41 | pip install --editable .[test] 42 | 43 | GCC-XML (Legacy) 44 | ---------------- 45 | 46 | These instructions are only here for historical reasons. `GCC-XML`_ was the tool used 47 | to generate the xml files before CastXML existed. 48 | 49 | **From version v1.8.0 on, pygccxml uses CastXML by default. 50 | The support for GCC-XML was finally dropped in pygccxml v2.0.0.** 51 | 52 | There are few different ways to install GCC-XML on your system: 53 | 54 | 1) Most Linux system provide the "gccxml" package through their package manager. 55 | 56 | 2) See the `instructions`_ to install GCC-XML from source. 57 | 58 | .. _`instructions`: http://gccxml.org/HTML/Install.html 59 | .. _`GCC-XML`: http://www.gccxml.org 60 | .. _`CastXML`: https://github.com/CastXML/CastXML 61 | .. _`Linux`: https://github.com/CastXML/CastXMLSuperbuild/releases/latest 62 | .. _`OS X`: https://github.com/CastXML/CastXMLSuperbuild/releases/latest 63 | .. _`Windows`: https://github.com/CastXML/CastXMLSuperbuild/releases/latest 64 | .. _`SuperBuild`: https://github.com/thewtex/CastXMLSuperbuild 65 | .. _`full install instructions`: https://github.com/CastXML/CastXML#build 66 | -------------------------------------------------------------------------------- /docs/links.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | C++ Reflection 3 | ============== 4 | 5 | ----- 6 | Links 7 | ----- 8 | 9 | * `CppReflect`_ - extracts reflection information from executables, which were 10 | build with debug information. It works with executables that has COFF or ELF 11 | format. 12 | 13 | * `XTI An Extended Type Information Library`_ - Bjarne Stroustrup talk about adding 14 | reflection information to C++ program. 15 | 16 | .. _`CppReflect` : http://www.garret.ru/~knizhnik/cppreflection/docs/reflect.html 17 | .. _`XTI An Extended Type Information Library` : http://lcgapp.cern.ch/project/architecture/XTI_accu.pdf 18 | -------------------------------------------------------------------------------- /docs/parser_uml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CastXML/pygccxml/26f63dc1f473114f836a43c309eaf5f65e5c5554/docs/parser_uml.png -------------------------------------------------------------------------------- /docs/pygccxml_uml.vsd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CastXML/pygccxml/26f63dc1f473114f836a43c309eaf5f65e5c5554/docs/pygccxml_uml.vsd -------------------------------------------------------------------------------- /docs/releasing.rst: -------------------------------------------------------------------------------- 1 | Releasing 2 | ========= 3 | 4 | Preparation 5 | ----------- 6 | 7 | Run `git checkout develop`. 8 | 9 | To build a new release, modify the version number in `pyproject.toml`. 10 | 11 | This version number will then automatically be used to build 12 | the documentation and by the build script when building the wheels. 13 | 14 | Run `git add . && git commit -m "Bump version major.minor.minor"`. 15 | 16 | Do not forget to document the latest changes in the ``CHANGELOG.md`` file. 17 | 18 | Merging and releasing 19 | --------------------- 20 | 21 | Merge develop into master: 22 | 23 | Run `git checkout master`. 24 | 25 | Run `git merge develop master`. 26 | 27 | Tag the version (do not forget the v): 28 | 29 | Run `git tag vmajor.minor.minor`. 30 | 31 | Run `git push origin vmajor.minor.minor && git push origin master` 32 | 33 | Wait for the CI to be done and all green. 34 | 35 | Go to the releases page on github and use the "draft a new release" button 36 | to create a new release. Use the exisiting tag. You can copy-past the 37 | changelog's content there if you want to. 38 | 39 | Once you are done, you can upload the release to pypi. 40 | 41 | Uploading to pypi 42 | ----------------- 43 | 44 | The documentation for the building and uploading can be found here: `pypi`_ 45 | 46 | Cleanup your dist: 47 | 48 | ``rm -rf dist`` 49 | 50 | Make sur your build tools are up to date 51 | 52 | `python3 -m pip install --upgrade build` 53 | 54 | The wheels and the source distribution are built with: 55 | 56 | ``python3 -m build`` 57 | 58 | They are uploaded with: 59 | 60 | ``twine upload dist/*`` 61 | 62 | 63 | .. _`pypi`: http://python-packaging-user-guide.readthedocs.org/en/latest/distributing/ 64 | -------------------------------------------------------------------------------- /docs/users.rst: -------------------------------------------------------------------------------- 1 | Who is using pygccxml? 2 | ====================== 3 | 4 | Users 5 | ----- 6 | 7 | * The Insight Toolkit is using pygccxml (http://www.itk.org). 8 | 9 | * `PyBindGen`_ - is a Python module that is geared to generating C/C++ code 10 | that binds a C/C++ library for Python. 11 | 12 | * your project name ... :-) 13 | 14 | pygccxml in blogs 15 | ----------------- 16 | 17 | - http://blog.susheelspace.com/?p=88 18 | 19 | " ... I have used pygccxml for parsing c++ code, it was a lot of fun to use " 20 | 21 | - http://cysquatch.net/blog/2007/09/01/c-code-metrics-with-pygccxml 22 | 23 | pygccxml is used to calculate the Weighted Methods per Class (WMC) metric. 24 | 25 | - http://www.garagegames.com/blogs/4280/13907 26 | 27 | pygccxml is used to generate input files for `SIP`_ code generator. 28 | 29 | - http://blogs.sun.com/thorsten/entry/more_on_source_code_grokking 30 | 31 | Short listing of C++ parsers and their description. 32 | 33 | .. _`PyBindGen` : https://launchpad.net/pybindgen 34 | .. _`SIP` : http://www.riverbankcomputing.com/software/sip/intro 35 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "pygccxml" 7 | description = "Python package for easy C++ declarations navigation." 8 | authors = [ 9 | {name = "Michka Popoff", email = "michkapopoff@gmail.com"}, 10 | {name = "Insight Software Consortium", email = "castxml@public.kitware.com"}, 11 | {name = "Roman Yakovenko", email = "romanyakovenko@gmail.com"}, 12 | ] 13 | readme = "README.rst" 14 | license = {file = "LICENSE.rst"} 15 | keywords = [ 16 | "C++", 17 | "XML", 18 | "declaration parser", 19 | "CastXML", 20 | "gccxml", 21 | ] 22 | version = "3.0.2" 23 | 24 | classifiers = [ 25 | "Development Status :: 5 - Production/Stable", 26 | "Environment :: Console", 27 | "Intended Audience :: Developers", 28 | "Operating System :: MacOS :: MacOS X", 29 | "Operating System :: Microsoft :: Windows", 30 | "Operating System :: POSIX", 31 | "Programming Language :: Python :: 3.9", 32 | "Programming Language :: Python :: 3.10", 33 | "Programming Language :: Python :: 3.11", 34 | "Programming Language :: Python :: 3.12", 35 | "Programming Language :: Python :: 3.13", 36 | "Programming Language :: Python :: Implementation :: CPython", 37 | "Programming Language :: Python :: Implementation :: PyPy", 38 | "Topic :: Software Development", 39 | ] 40 | 41 | dependencies = [ 42 | 'importlib-metadata >= 4.6; python_version < "3.10"', # Not required for 3.8+, but fixes a stdlib bug 43 | ] 44 | 45 | [project.urls] 46 | Homepage = "https://github.com/CastXML/pygccxml" 47 | Documentation = "https://readthedocs.org/projects/pygccxml/" 48 | Repository = "https://github.com/CastXML/pygccxml" 49 | Changelog = "https://github.com/CastXML/pygccxml/CHANGELOG.md" 50 | 51 | [options] 52 | python_requires = ">=3.9" 53 | 54 | [project.optional-dependencies] 55 | test = [ 56 | "coverage", 57 | "coveralls", 58 | "pycodestyle", 59 | "pytest", 60 | ] 61 | docs = [ 62 | "sphinx", 63 | "sphinx_rtd_theme", 64 | ] 65 | examples = [ 66 | "notebook", 67 | ] 68 | -------------------------------------------------------------------------------- /src/pygccxml/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | """Python CastXML front end. 7 | 8 | This package provides functionality to extract and inspect 9 | declarations from C/C++ header files. This is accomplished 10 | by invoking an external tool like CastXML, 11 | which parses a header file and dumps the declarations as a 12 | XML file. This XML file is then read by pygccxml and the contents 13 | are made available as appropriate Python objects. 14 | 15 | To parse a set of C/C++ header files you use the :func:`parse ` 16 | function in the :mod:parser sub package which returns a tree that contains all 17 | declarations found in the header files. The root of the tree represents the 18 | main namespace `::` and the children nodes represent the namespace contents 19 | such as other namespaces, classes, functions, etc. Each node in the tree is an 20 | object of a type derived from the :class:`declaration_t` class. An inner node 21 | is always either a namespace :class:`declarations.namespace_t` or a class 22 | :class:`declarations.class_t`, which are both derived from 23 | :class:`declarations.scopedef_t` class. Everything else (free functions, 24 | member functions, enumerations, variables, etc.) are always a leaf. You will 25 | find all those declaration classes in the :mod:declarations sub-package. 26 | 27 | """ 28 | 29 | import sys 30 | import warnings 31 | 32 | from . import declarations 33 | from . import parser 34 | from . import utils 35 | 36 | # Always show deprecation warnings. 37 | # These are hidden by default since python 2.7. 38 | # pygccxml is a tool for developers, and these need 39 | # to know what is deprecated. 40 | warnings.simplefilter("always", DeprecationWarning) 41 | 42 | version = sys.version_info 43 | 44 | if version < (3, 8): 45 | import importlib_metadata as metadata 46 | elif version < (3, 9, 10) or (3, 10, 0) <= version < (3, 10, 2): 47 | try: 48 | import importlib_metadata as metadata 49 | except ModuleNotFoundError: 50 | from importlib import metadata 51 | else: 52 | from importlib import metadata 53 | 54 | __version__ = metadata.version("pygccxml") 55 | -------------------------------------------------------------------------------- /src/pygccxml/declarations/byte_info.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | 7 | class byte_info(object): 8 | 9 | """ 10 | This class stores information about the byte size and byte align 11 | values from a declaration/type. 12 | 13 | """ 14 | 15 | def __init__(self): 16 | self._byte_size = 0 17 | self._byte_align = 0 18 | 19 | @property 20 | def byte_size(self): 21 | """ 22 | Size of this declaration/type in bytes 23 | 24 | Returns: 25 | int: Size of this declaration/type in bytes 26 | """ 27 | return self._byte_size 28 | 29 | @byte_size.setter 30 | def byte_size(self, new_byte_size): 31 | """ 32 | Set size of this declaration/type in bytes 33 | 34 | Args: 35 | new_byte_size (int): Size of this declaration/type in bytes 36 | """ 37 | self._byte_size = new_byte_size 38 | 39 | @property 40 | def byte_align(self): 41 | """ 42 | Alignment of this declaration/type in bytes 43 | 44 | Returns: 45 | int: Alignment of this declaration/type in bytes 46 | """ 47 | return self._byte_align 48 | 49 | @byte_align.setter 50 | def byte_align(self, new_byte_align): 51 | """ 52 | Set size of alignment of this declaration/type in bytes 53 | 54 | Args: 55 | new_byte_align (int): Alignment of this declaration/type in bytes 56 | """ 57 | self._byte_align = new_byte_align 58 | -------------------------------------------------------------------------------- /src/pygccxml/declarations/calldef_types.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import re 7 | 8 | 9 | class VIRTUALITY_TYPES(object): 10 | 11 | """class that defines "virtuality" constants""" 12 | NOT_VIRTUAL = 'not virtual' 13 | VIRTUAL = 'virtual' 14 | PURE_VIRTUAL = 'pure virtual' 15 | ALL = [NOT_VIRTUAL, VIRTUAL, PURE_VIRTUAL] 16 | 17 | 18 | # preserving backward compatebility 19 | FUNCTION_VIRTUALITY_TYPES = VIRTUALITY_TYPES 20 | 21 | 22 | class CALLING_CONVENTION_TYPES(object): 23 | 24 | """class that defines "calling convention" constants""" 25 | UNKNOWN = '' 26 | CDECL = 'cdecl' 27 | STDCALL = 'stdcall' 28 | THISCALL = 'thiscall' 29 | FASTCALL = 'fastcall' 30 | SYSTEM_DEFAULT = '<<>>' 31 | 32 | all = (UNKNOWN, CDECL, STDCALL, THISCALL, FASTCALL, SYSTEM_DEFAULT) 33 | 34 | pattern = re.compile( 35 | r'.*(?:^|\s)(?:__)?(?Pcdecl|stdcall|thiscall|fastcall)(?:__)?.*') 36 | 37 | @staticmethod 38 | def extract(text, default=UNKNOWN): 39 | """extracts calling convention from the text. If the calling convention 40 | could not be found, the "default"is used""" 41 | if not text: 42 | return default 43 | found = CALLING_CONVENTION_TYPES.pattern.match(text) 44 | if found: 45 | return found.group('cc') 46 | 47 | return default 48 | -------------------------------------------------------------------------------- /src/pygccxml/declarations/decl_visitor.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | """ 7 | defines declarations visitor class interface 8 | """ 9 | 10 | 11 | class decl_visitor_t(object): 12 | 13 | """ 14 | declarations visitor interface 15 | 16 | All functions within this class should be redefined in derived classes. 17 | """ 18 | 19 | def __init__(self): 20 | object.__init__(self) 21 | 22 | def visit_member_function(self): 23 | raise NotImplementedError() 24 | 25 | def visit_constructor(self): 26 | raise NotImplementedError() 27 | 28 | def visit_destructor(self): 29 | raise NotImplementedError() 30 | 31 | def visit_member_operator(self): 32 | raise NotImplementedError() 33 | 34 | def visit_casting_operator(self): 35 | raise NotImplementedError() 36 | 37 | def visit_free_function(self): 38 | raise NotImplementedError() 39 | 40 | def visit_free_operator(self): 41 | raise NotImplementedError() 42 | 43 | def visit_class_declaration(self): 44 | raise NotImplementedError() 45 | 46 | def visit_class(self): 47 | raise NotImplementedError() 48 | 49 | def visit_enumeration(self): 50 | raise NotImplementedError() 51 | 52 | def visit_namespace(self): 53 | raise NotImplementedError() 54 | 55 | def visit_typedef(self): 56 | raise NotImplementedError() 57 | 58 | def visit_variable(self): 59 | raise NotImplementedError() 60 | 61 | def visit_comment(self): 62 | raise NotImplementedError() 63 | -------------------------------------------------------------------------------- /src/pygccxml/declarations/elaborated_info.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | 7 | class elaborated_info(object): 8 | """ 9 | This class stores the name of the elaborated type specifier. 10 | 11 | """ 12 | 13 | def __init__(self, elaborated_type_specifier): 14 | self._elaborated_type_specifier = elaborated_type_specifier 15 | 16 | @property 17 | def elaborated_type_specifier(self): 18 | """ 19 | Elaborated specifier (can be: struct, union, class or enum). 20 | 21 | Returns: 22 | str: elaborated specifier 23 | """ 24 | return self._elaborated_type_specifier 25 | -------------------------------------------------------------------------------- /src/pygccxml/declarations/location.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | 7 | class location_t(object): 8 | """ 9 | Provides information about the location of the declaration within the 10 | source file. 11 | 12 | """ 13 | 14 | def __init__(self, file_name='', line=-1): 15 | self._file_name = file_name 16 | self._line = line 17 | 18 | def __eq__(self, other): 19 | if not isinstance(other, self.__class__): 20 | return False 21 | return self.line == other.line \ 22 | and self.file_name == other.file_name 23 | 24 | def __hash__(self): 25 | return hash(self.__class__) ^ hash(self.line) ^ hash(self.file_name) 26 | 27 | def __ne__(self, other): 28 | return not self.__eq__(other) 29 | 30 | def __lt__(self, other): 31 | if not isinstance(other, location_t): 32 | return self.__class__.__name__ < other.__class__.__name__ 33 | return (self.file_name, self.line) < (other.file_name, other.line) 34 | 35 | @property 36 | def file_name(self): 37 | """ 38 | Absolute source file name, type string. 39 | 40 | """ 41 | 42 | return self._file_name 43 | 44 | @file_name.setter 45 | def file_name(self, new_file_name): 46 | self._file_name = new_file_name 47 | 48 | @property 49 | def line(self): 50 | """ 51 | Line number, type int. 52 | 53 | """ 54 | 55 | return self._line 56 | 57 | @line.setter 58 | def line(self, new_line): 59 | self._line = new_line 60 | 61 | def as_tuple(self): 62 | """ 63 | Return tuple(self.file_name, self.line) 64 | 65 | """ 66 | 67 | return self.file_name, self.line 68 | -------------------------------------------------------------------------------- /src/pygccxml/declarations/runtime_errors.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | 7 | class declaration_not_found_t(RuntimeError): 8 | """Exception raised when the declaration could not be found""" 9 | 10 | def __init__(self, decl_matcher): 11 | RuntimeError.__init__(self) 12 | self._decl_matcher = decl_matcher 13 | 14 | def __str__(self): 15 | return ( 16 | "Unable to find declaration. Matcher: [%s]" % str( 17 | self._decl_matcher) 18 | ) 19 | 20 | 21 | class multiple_declarations_found_t(RuntimeError): 22 | """Exception raised when more than one declaration was found""" 23 | 24 | def __init__(self, decl_matcher): 25 | RuntimeError.__init__(self) 26 | self._decl_matcher = decl_matcher 27 | 28 | def __str__(self): 29 | return ( 30 | "Multiple declarations have been found. Matcher: [%s]" % str( 31 | self._decl_matcher) 32 | ) 33 | 34 | 35 | class visit_function_has_not_been_found_t(RuntimeError): 36 | """ 37 | Exception that is raised, from :func:`apply_visitor`, when a visitor could 38 | not be applied. 39 | 40 | """ 41 | 42 | def __init__(self, visitor, decl_inst): 43 | RuntimeError.__init__(self) 44 | self.__msg = ( 45 | "Unable to find visit function. Visitor class: %s. " + 46 | "Declaration instance class: %s'") \ 47 | % (visitor.__class__.__name__, decl_inst.__class__.__name__) 48 | 49 | def __str__(self): 50 | return self.__msg 51 | -------------------------------------------------------------------------------- /src/pygccxml/declarations/typedef.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | """ 7 | defines class that describes C++ typedef declaration 8 | """ 9 | 10 | from . import declaration 11 | from . import byte_info 12 | 13 | 14 | class typedef_t(declaration.declaration_t, byte_info.byte_info): 15 | 16 | """describes C++ typedef declaration""" 17 | 18 | def __init__(self, name='', decl_type=None): 19 | """creates class that describes C++ typedef""" 20 | declaration.declaration_t.__init__(self, name) 21 | byte_info.byte_info.__init__(self) 22 | self._decl_type = decl_type 23 | if not isinstance(decl_type, str) and decl_type is not None: 24 | self.byte_size = decl_type.byte_size 25 | self.byte_align = decl_type.byte_align 26 | 27 | def _get__cmp__items(self): 28 | """implementation details""" 29 | return [self.decl_type] 30 | 31 | def __eq__(self, other): 32 | if not declaration.declaration_t.__eq__(self, other): 33 | return False 34 | return self.decl_type == other.decl_type 35 | 36 | __hash__ = declaration.declaration_t.__hash__ 37 | 38 | @property 39 | def decl_type(self): 40 | """reference to the original :class:`decl_type `""" 41 | return self._decl_type 42 | 43 | @decl_type.setter 44 | def decl_type(self, decl_type): 45 | self._decl_type = decl_type 46 | self.byte_size = decl_type.byte_size 47 | self.byte_align = decl_type.byte_align 48 | 49 | def i_depend_on_them(self, recursive=True): 50 | self._warn_deprecated() 51 | # Deprecated method. The cyclic import will be removed with the method 52 | # in the next release, so we can disable the cyclic import check here. 53 | from . import dependencies # pylint: disable=R0401 54 | return [dependencies.dependency_info_t(self, self.decl_type)] 55 | -------------------------------------------------------------------------------- /src/pygccxml/declarations/xml_generators.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | """ 7 | Contains enumeration of all xml_generators supported by the project. 8 | 9 | """ 10 | 11 | gccxml_06 = "GCC-XML 0.6" 12 | gccxml_07 = "GCC-XML 0.7" 13 | gccxml_09 = "GCC-XML 0.9" 14 | gccxml_09_buggy = "GCC-XML 0.9 BUGGY" 15 | # revision 122: 16 | # After this fix, all constructors and destructors that exist for a class 17 | # are dumped whether the user declared them or not. Those that were 18 | # implicitly declared by the xml_generator are marked as "artificial". 19 | 20 | # CastXML has no version number for the moment so "None" is used. 21 | castxml_none = "CastXML None" 22 | 23 | 24 | def on_missing_functionality(xml_generator, functionality): 25 | raise NotImplementedError( 26 | '"%s" xml_generator doesn\'t support functionality "%s"' % 27 | (xml_generator, functionality)) 28 | -------------------------------------------------------------------------------- /src/pygccxml/parser/etree_scanner.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | # keep py2exe happy 7 | import xml.etree.ElementTree # pylint: disable=W0611 8 | 9 | import xml.etree.cElementTree as ElementTree 10 | 11 | from . import scanner 12 | 13 | 14 | class ietree_scanner_t(scanner.scanner_t): 15 | 16 | def __init__(self, xml_file, decl_factory, *args): 17 | scanner.scanner_t.__init__(self, xml_file, decl_factory, *args) 18 | 19 | def read(self): 20 | context = ElementTree.iterparse( 21 | self.xml_file, 22 | events=("start", "end")) 23 | for event, elem in context: 24 | if event == 'start': 25 | self.startElement(elem.tag, elem.attrib) 26 | else: 27 | self.endElement(elem.tag) 28 | elem.clear() 29 | self.endDocument() 30 | -------------------------------------------------------------------------------- /src/pygccxml/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | """ 7 | The utils package contains tools used internally by pygccxml. 8 | 9 | """ 10 | 11 | from .utils import get_architecture 12 | from .utils import loggers 13 | from .utils import create_temp_file_name 14 | from .utils import remove_file_no_raise 15 | from .utils import normalize_path 16 | from .utils import find_xml_generator 17 | from .utils import get_tr1 18 | from .utils import cxx_standard 19 | from .xml_generators import xml_generators 20 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CastXML/pygccxml/26f63dc1f473114f836a43c309eaf5f65e5c5554/tests/__init__.py -------------------------------------------------------------------------------- /tests/autoconfig.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import os 7 | import sys 8 | import logging 9 | import warnings 10 | import platform 11 | 12 | # Prevents copy.deepcopy RecursionError in some tests (Travis build) 13 | sys.setrecursionlimit(10000) 14 | 15 | this_module_dir_path = os.path.abspath( 16 | os.path.dirname(sys.modules[__name__].__file__)) 17 | 18 | data_directory = os.path.join(this_module_dir_path, 'data') 19 | build_directory = os.path.join(this_module_dir_path, 'temp') 20 | 21 | if not os.path.exists(build_directory): 22 | os.makedirs(build_directory) 23 | 24 | sys.path.insert(1, os.path.join(os.curdir, '..')) 25 | # The tests are run on the parent pygccxml directory, not the one 26 | # in site-packages. Insert the directory's path. 27 | sys.path.insert(1, "../src/pygccxml") 28 | 29 | from pygccxml import parser # nopep8 30 | from pygccxml import utils # nopep8 31 | 32 | # We want to make sure we throw an error for ALL the warnings during the 33 | # tests. This will allow us to be notified by the build bots, so that the 34 | # warnings can be fixed. 35 | warnings.simplefilter("error", Warning) 36 | 37 | # Set logging level 38 | utils.loggers.set_level(logging.CRITICAL) 39 | 40 | # Find out the c++ parser (gccxml or castxml) 41 | generator_path, generator_name = utils.find_xml_generator() 42 | 43 | 44 | class cxx_parsers_cfg(object): 45 | config = parser.load_xml_generator_configuration( 46 | os.path.normpath(this_module_dir_path + '/xml_generator.cfg'), 47 | xml_generator_path=generator_path, 48 | working_directory=data_directory, 49 | xml_generator=generator_name) 50 | 51 | if platform.system() == 'Windows': 52 | config.define_symbols.append('_HAS_EXCEPTIONS=0') 53 | 54 | 55 | if cxx_parsers_cfg.config.xml_generator: 56 | generator_name = cxx_parsers_cfg.config.xml_generator 57 | if cxx_parsers_cfg.config.xml_generator_path: 58 | generator_path = cxx_parsers_cfg.config.xml_generator_path 59 | -------------------------------------------------------------------------------- /tests/conftest.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | 9 | class Helpers: 10 | @staticmethod 11 | def _test_type_composition(type_, expected_compound, expected_base): 12 | assert isinstance(type_, expected_compound) 13 | assert isinstance(type_.base, expected_base) 14 | 15 | @staticmethod 16 | def _test_calldef_args(calldef, expected_args): 17 | assert len(calldef.arguments) == len(expected_args) 18 | 19 | for i, expected_arg in enumerate(expected_args): 20 | arg = calldef.arguments[i] 21 | assert arg == expected_arg 22 | 23 | @staticmethod 24 | def _test_calldef_return_type(calldef, expected_type): 25 | assert isinstance(calldef.return_type, expected_type) 26 | 27 | @staticmethod 28 | def _test_calldef_exceptions(global_ns, calldef, exceptions): 29 | # exceptions is list of classes names 30 | exception_decls = [] 31 | for name in exceptions: 32 | exception_decl = global_ns.class_(name) 33 | assert exception_decl is not None 34 | exception_decls.append(exception_decl) 35 | exception_decls.sort() 36 | assert len(calldef.exceptions) == len(exception_decls) 37 | exceptions_indeed = sorted(calldef.exceptions[:]) 38 | assert exception_decls == exceptions_indeed 39 | 40 | 41 | @pytest.fixture 42 | def helpers(): 43 | return Helpers 44 | -------------------------------------------------------------------------------- /tests/data/abstract_classes.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __abstract_classes_hpp__ 7 | #define __abstract_classes_hpp__ 8 | 9 | namespace abstract_classes{ 10 | 11 | class abstract_i{ 12 | virtual int do_your_things() const = 0; 13 | }; 14 | 15 | class derived_abstract_i: public abstract_i{ 16 | }; 17 | 18 | class implementation : public abstract_i{ 19 | virtual int do_your_things() const 20 | { return 1; } 21 | }; 22 | 23 | } 24 | 25 | #endif//__abstract_classes_hpp__ 26 | 27 | -------------------------------------------------------------------------------- /tests/data/attributes_castxml.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __attributes_castxml_hpp__ 7 | #define __attributes_castxml_hpp__ 8 | 9 | #define _out_ __attribute__ ((annotate ("out"))) 10 | #define _sealed_ __attribute__ ((annotate ("sealed"))) 11 | #define _no_throw_ __attribute__ ((annotate ("no throw"))) 12 | 13 | namespace attributes{ 14 | 15 | struct _sealed_ numeric_t{ 16 | 17 | _no_throw_ void do_nothing( _out_ int& x ){} 18 | 19 | }; 20 | 21 | } 22 | 23 | #endif//__attributes_castxml_hpp__ 24 | 25 | -------------------------------------------------------------------------------- /tests/data/attributes_gccxml.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __attributes_hpp__ 7 | #define __attributes_hpp__ 8 | 9 | #ifdef __GCCXML__ 10 | 11 | #define _out_ __attribute( (gccxml( "out" ) ) ) 12 | #define _sealed_ __attribute( (gccxml( "sealed" ) ) ) 13 | #define _no_throw_ __attribute( (gccxml( "no throw" ) ) ) 14 | 15 | namespace attributes{ 16 | 17 | _sealed_ struct numeric_t{ 18 | 19 | _no_throw_ void do_nothing( _out_ int& x ){} 20 | 21 | }; 22 | 23 | } 24 | 25 | #endif//__GCCXML__ 26 | 27 | #endif//__attributes_hpp__ 28 | 29 | -------------------------------------------------------------------------------- /tests/data/better_templates_matcher_tester.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #include 7 | #include 8 | 9 | namespace Ogre{ 10 | struct PlaneBoundedVolume{}; 11 | 12 | struct Plane{}; 13 | 14 | std::vector do_smth(){ 15 | return std::vector(); 16 | } 17 | 18 | std::vector do_smth2(){ 19 | return std::vector(); 20 | } 21 | 22 | template< class X > 23 | struct Singleton{ 24 | }; 25 | 26 | struct PCZoneFactoryManager{}; 27 | 28 | Singleton do_smth3(){ 29 | return Singleton(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/data/binary_parsers/libconfig.h: -------------------------------------------------------------------------------- 1 | #if defined _WIN32 || defined __CYGWIN__ 2 | #define IMPORT_SYMBOL __declspec(dllimport) 3 | #define EXPORT_SYMBOL __declspec(dllexport) 4 | #define PRIVATE_SYMBOL 5 | #else 6 | #if __GNUC__ >= 4 7 | #define IMPORT_SYMBOL __attribute__ ((visibility("default"))) 8 | #define EXPORT_SYMBOL __attribute__ ((visibility("default"))) 9 | #define PRIVATE_SYMBOL __attribute__ ((visibility("hidden"))) 10 | #else 11 | #define IMPORT_SYMBOL 12 | #define EXPORT_SYMBOL 13 | #define PRIVATE_SYMBOL 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /tests/data/binary_parsers/sconscript: -------------------------------------------------------------------------------- 1 | Import('*') 2 | 3 | target_name = 'mydll' 4 | shlib = env.SharedLibrary( target=target_name, source=[ target_name + '.cpp' ] ) 5 | env.Alias( target_name, shlib ) 6 | -------------------------------------------------------------------------------- /tests/data/binary_parsers/sconstruct: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | vars = Variables() 5 | 6 | if 'win32' in sys.platform: 7 | vars.Add( EnumVariable( 'msvc_compiler' 8 | , 'prefered msvc compiler' 9 | , 'msvc71' 10 | , ['msvc71', 'msvc80', 'msvc90'] ) ) 11 | 12 | env = Environment(variables=vars) 13 | 14 | if 'win32' in sys.platform: 15 | Help(opts.GenerateHelpText(env)) 16 | if env["msvc_compiler"] == "msvc71": 17 | env["MSVS"] = {"VERSION": "7.1"} 18 | env["MSVS_VERSION"] = "7.1" 19 | Tool("msvc")(env) 20 | elif env["msvc_compiler"] == "vc8": 21 | env["MSVS"] = {"VERSION": "8.0"} 22 | env["MSVS_VERSION"] = "8.0" 23 | Tool("msvc")(env) 24 | 25 | if os.path.exists( r'E:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib' ): 26 | env.Append( LIBPATH=[ r'E:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib' 27 | , r'E:\Program Files\Microsoft Visual Studio 9.0\VC\lib'] ) 28 | env.Append( CPPPATH=[r"E:\Program Files\Microsoft SDKs\Windows\v6.0A\Include" 29 | , r"E:\Program Files\Microsoft Visual Studio 9.0\VC\include"]) 30 | 31 | if 'win32' in sys.platform: 32 | env.AppendUnique( CCFLAGS=[ r"/MD",r"/EHsc",r"/GR",r"/Zc:wchar_t",r"/Zc:forScope" ] ) 33 | env.AppendUnique( LINKFLAGS=[r"/MAP:${TARGET.base}.map", r"/MAPINFO:EXPORTS"] ) 34 | 35 | SConscript( 'sconscript', variant_dir='#binaries', duplicate=0, exports=["env"] ) 36 | -------------------------------------------------------------------------------- /tests/data/bit_fields.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __bit_fields_hpp__ 7 | #define __bit_fields_hpp__ 8 | 9 | namespace bit_fields{ 10 | 11 | struct fields_t{ 12 | unsigned int x : 1; 13 | unsigned int y : 7; 14 | unsigned int z; 15 | }; 16 | 17 | } 18 | 19 | #endif//__bit_fields_hpp__ 20 | -------------------------------------------------------------------------------- /tests/data/classes.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __classes_hpp__ 7 | #define __classes_hpp__ 8 | 9 | struct cls{}; 10 | typedef struct {} cls2; 11 | typedef class { 12 | int i; 13 | } cls3; 14 | 15 | namespace ns{ 16 | 17 | struct nested_cls{}; 18 | typedef class {} nested_cls2; 19 | typedef struct nested_cls3 {} nested_cls3; 20 | 21 | } 22 | 23 | #endif//__classes_hpp__ 24 | -------------------------------------------------------------------------------- /tests/data/complex_types.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __complex_types_hpp__ 7 | #define __complex_types_hpp__ 8 | 9 | #ifndef WIN32 10 | #include 11 | #endif 12 | 13 | #endif//__complex_types_hpp__ 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/data/const_volatile_arg.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __const_volatile_arg_hpp__ 7 | #define __const_volatile_arg_hpp__ 8 | 9 | void pygccxml_bug(int const volatile* icv); 10 | 11 | #endif//__const_volatile_arg_hpp__ 12 | 13 | -------------------------------------------------------------------------------- /tests/data/core_cache.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __core_cache_hpp__ 7 | #define __core_cache_hpp__ 8 | 9 | #include "core_types.hpp" 10 | #include "core_diamand_hierarchy_base.hpp" 11 | #include "core_diamand_hierarchy_derived1.hpp" 12 | #include "core_diamand_hierarchy_derived2.hpp" 13 | #include "core_diamand_hierarchy_final_derived.hpp" 14 | #include "core_overloads_1.hpp" 15 | #include "core_overloads_2.hpp" 16 | 17 | namespace core{ namespace cache{ 18 | 19 | typedef int Int; 20 | 21 | } } 22 | 23 | #endif//__core_cache_hpp__ 24 | -------------------------------------------------------------------------------- /tests/data/core_class_hierarchy.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __core_class_hierarchy_hpp__ 7 | #define __core_class_hierarchy_hpp__ 8 | 9 | namespace core{ namespace class_hierarchy{ 10 | 11 | class base_t{ 12 | public: 13 | virtual ~base_t(){}; 14 | }; 15 | 16 | class other_base_t{ 17 | }; 18 | 19 | class derived_public_t : public base_t{ 20 | }; 21 | 22 | class derived_protected_t : protected base_t{ 23 | }; 24 | 25 | class derived_private_t : private virtual base_t{ 26 | }; 27 | 28 | class multi_derived_t : derived_private_t, protected virtual base_t, private other_base_t{ 29 | }; 30 | 31 | } } 32 | 33 | #endif//__core_class_hierarchy_hpp__ 34 | -------------------------------------------------------------------------------- /tests/data/core_diamand_hierarchy_base.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __core_diamand_hierarchy_base_hpp__ 7 | #define __core_diamand_hierarchy_base_hpp__ 8 | 9 | namespace core{ namespace diamand_hierarchy{ 10 | 11 | class base_t{ 12 | }; 13 | 14 | } } 15 | 16 | #endif//__core_diamand_hierarchy_base_hpp__ 17 | -------------------------------------------------------------------------------- /tests/data/core_diamand_hierarchy_derived1.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __core_diamand_hierarchy_derived1_hpp__ 7 | #define __core_diamand_hierarchy_derived1_hpp__ 8 | 9 | #include "core_diamand_hierarchy_base.hpp" 10 | 11 | namespace core{ namespace diamand_hierarchy{ 12 | 13 | class derived1_t : public virtual base_t{ 14 | }; 15 | 16 | } } 17 | 18 | #endif//__core_diamand_hierarchy_derived1_hpp__ 19 | -------------------------------------------------------------------------------- /tests/data/core_diamand_hierarchy_derived2.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __core_diamand_hierarchy_derived2_hpp__ 7 | #define __core_diamand_hierarchy_derived2_hpp__ 8 | 9 | #include "core_diamand_hierarchy_base.hpp" 10 | 11 | namespace core{ namespace diamand_hierarchy{ 12 | 13 | class derived2_t : public virtual base_t{ 14 | }; 15 | 16 | } } 17 | 18 | #endif//__core_diamand_hierarchy_derived2_hpp__ 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/data/core_diamand_hierarchy_final_derived.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __core_diamand_hierarchy_final_derived_hpp__ 7 | #define __core_diamand_hierarchy_final_derived_hpp__ 8 | 9 | #include "core_diamand_hierarchy_derived1.hpp" 10 | #include "core_diamand_hierarchy_derived2.hpp" 11 | 12 | namespace core{ namespace diamand_hierarchy{ 13 | 14 | class final_derived_t : public virtual derived1_t, public virtual derived2_t{ 15 | }; 16 | 17 | } } 18 | 19 | #endif//__core_diamand_hierarchy_final_derived_hpp__ 20 | -------------------------------------------------------------------------------- /tests/data/core_membership.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __core_membership_hpp__ 7 | #define __core_membership_hpp__ 8 | 9 | enum{ GLOBAL_NS_UNNAMED_ENUM = 18 }; 10 | enum EGlobal{ GLOBAL_NS }; 11 | 12 | namespace core{ namespace membership{ 13 | 14 | namespace enums_ns{ 15 | enum{ WITHIN_NS_UNNAMED_ENUM = 3 }; 16 | enum EWithin{ WITHIN_NS }; 17 | } 18 | 19 | namespace{//unnamed namespace 20 | enum{ WITHIN_UNNAMED_NS_UNNAMED_ENUM = 1977 }; 21 | enum EWithinUnnamed{ WITHIN_UNNAMED_NS }; 22 | } 23 | 24 | class class_for_nested_enums_t{ 25 | public: 26 | enum ENestedPublic{ nested_enum_public }; 27 | protected: 28 | enum ENestedProtected{ nested_enum_protected }; 29 | private: 30 | enum ENestedPrivate{ nested_enum_private }; 31 | }; 32 | 33 | } } 34 | 35 | #endif//__core_membership_hpp__ 36 | 37 | -------------------------------------------------------------------------------- /tests/data/core_ns_join_1.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __core_ns_join_1_hpp__ 7 | #define __core_ns_join_1_hpp__ 8 | 9 | enum E11{ e11 }; 10 | 11 | namespace ns{ 12 | 13 | enum E12{ e12 }; 14 | 15 | namespace ns12{ 16 | enum E13{ e13 }; 17 | } 18 | 19 | namespace{ 20 | enum E14{ e14 }; 21 | } 22 | } 23 | 24 | #endif//__core_ns_join_1_hpp__ 25 | -------------------------------------------------------------------------------- /tests/data/core_ns_join_2.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __core_ns_join_2_hpp__ 7 | #define __core_ns_join_2_hpp__ 8 | 9 | enum E21{ e21 }; 10 | 11 | namespace ns{ 12 | 13 | enum E22{ e22 }; 14 | 15 | namespace ns22{ 16 | enum E23{ e23 }; 17 | } 18 | 19 | namespace{ 20 | enum E24{ e24 }; 21 | } 22 | } 23 | 24 | #endif//__core_ns_join_2_hpp__ 25 | -------------------------------------------------------------------------------- /tests/data/core_ns_join_3.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __core_ns_join_3_hpp__ 7 | #define __core_ns_join_3_hpp__ 8 | 9 | enum E31{ e31 }; 10 | 11 | namespace ns{ 12 | 13 | enum E32{ e32 }; 14 | 15 | namespace ns32{ 16 | enum E33{ e33 }; 17 | } 18 | 19 | namespace{ 20 | enum E34{ e34 }; 21 | } 22 | } 23 | 24 | #endif//__core_ns_join_3_hpp__ 25 | -------------------------------------------------------------------------------- /tests/data/core_overloads_1.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __core_overloads_1_hpp__ 7 | #define __core_overloads_1_hpp__ 8 | 9 | #include 10 | 11 | namespace core{ namespace overloads{ 12 | 13 | void do_nothing( std::string ); 14 | void do_nothing( std::wstring ); 15 | 16 | } } 17 | 18 | #endif//__core_overloads_1_hpp__ 19 | 20 | -------------------------------------------------------------------------------- /tests/data/core_overloads_2.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __core_overloads_2_hpp__ 7 | #define __core_overloads_2_hpp__ 8 | #include 9 | #include 10 | namespace core{ namespace overloads{ 11 | 12 | void do_nothing( std::set< std::string > ); 13 | void do_nothing( std::set< std::wstring > ); 14 | 15 | } } 16 | 17 | #endif//__core_overloads_2_hpp__ 18 | 19 | -------------------------------------------------------------------------------- /tests/data/covariant_returns.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __bug_virtual_functions_overload_to_be_exported_hpp__ 7 | #define __bug_virtual_functions_overload_to_be_exported_hpp__ 8 | 9 | struct data_t { 10 | int i; 11 | }; 12 | 13 | struct more_data_t : public data_t{ 14 | }; 15 | 16 | struct algorithm_t{ 17 | algorithm_t(){}; 18 | virtual data_t* f(){ 19 | data_t* d = new data_t(); 20 | d->i = 0; 21 | return d; 22 | } 23 | }; 24 | 25 | class better_algorithm_t : public algorithm_t{ 26 | public: 27 | better_algorithm_t(){}; 28 | virtual more_data_t* f(){ 29 | more_data_t* d = new more_data_t(); 30 | d->i = 1; 31 | return d; 32 | } 33 | 34 | }; 35 | 36 | #endif//__bug_virtual_functions_overload_to_be_exported_hpp__ 37 | -------------------------------------------------------------------------------- /tests/data/cpp_standards.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // A good test for different cpp standards. iostream is one of the first 7 | // things to fail when the wrong flags are used. 8 | 9 | #include 10 | -------------------------------------------------------------------------------- /tests/data/decl_cache_file1.txt: -------------------------------------------------------------------------------- 1 | // Line 1: Test file for declaration_cache testing 2 | -------------------------------------------------------------------------------- /tests/data/decl_cache_file1_duplicate.txt: -------------------------------------------------------------------------------- 1 | // Line 1: Test file for declaration_cache testing 2 | -------------------------------------------------------------------------------- /tests/data/decl_cache_file2.txt: -------------------------------------------------------------------------------- 1 | // Line 1: Test file for declaration_cache testing 2 | // Line 2: 3 | -------------------------------------------------------------------------------- /tests/data/declaration_string.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | int myfunc (int a, int b) 7 | { 8 | int r; 9 | r=a+b; 10 | return r; 11 | } 12 | 13 | class Box 14 | { 15 | public: 16 | short myinternfunc() 17 | { 18 | return _x; 19 | } 20 | private: 21 | short _x; 22 | }; 23 | -------------------------------------------------------------------------------- /tests/data/declarations_calldef.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __declarations_calldef_hpp__ 7 | #define __declarations_calldef_hpp__ 8 | 9 | namespace declarations{ namespace calldef{ 10 | 11 | class some_exception_t{}; 12 | 13 | class other_exception_t{}; 14 | 15 | void no_return_no_args(); 16 | 17 | int return_no_args(); 18 | 19 | void no_return_1_arg(int arg); 20 | 21 | int return_default_args( int arg=1, bool flag=false ); 22 | 23 | extern void static_call(); 24 | 25 | struct calldefs_t{ 26 | calldefs_t(); 27 | 28 | explicit calldefs_t(char); 29 | 30 | calldefs_t(some_exception_t); 31 | 32 | calldefs_t(int,double); 33 | 34 | calldefs_t(const calldefs_t&); 35 | 36 | virtual ~calldefs_t(); 37 | 38 | calldefs_t& operator=( const calldefs_t& ); 39 | bool operator==( const calldefs_t& ); 40 | operator char*() const; 41 | virtual operator double(); 42 | 43 | static void static_call(); 44 | 45 | inline int member_inline_call(int i){ return i;} 46 | 47 | virtual void member_virtual_call(); 48 | 49 | virtual void member_pure_virtual_call() = 0; 50 | 51 | void member_const_call() const; 52 | 53 | calldefs_t* do_smth(const calldefs_t& other); 54 | }; 55 | 56 | namespace std{ 57 | class iostream; 58 | } 59 | 60 | std::iostream& operator<<( std::iostream&, const calldefs_t& ); 61 | std::iostream& operator>>( std::iostream&, calldefs_t& ); 62 | 63 | namespace ellipsis_tester{ 64 | 65 | struct ellipsis{ 66 | void do_smth( int, ... ); 67 | }; 68 | 69 | void do_smth_else( int, ... ); 70 | 71 | }//ellipsis_tester 72 | 73 | } } 74 | 75 | #endif//__declarations_calldef_hpp__ 76 | -------------------------------------------------------------------------------- /tests/data/declarations_comparison.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __declarations_comparison_hpp__ 7 | #define __declarations_comparison_hpp__ 8 | 9 | #include "core_ns_join_1.hpp" 10 | #include "core_ns_join_2.hpp" 11 | #include "core_ns_join_3.hpp" 12 | #include "core_membership.hpp" 13 | #include "core_class_hierarchy.hpp" 14 | #include "core_types.hpp" 15 | #include "core_diamand_hierarchy_base.hpp" 16 | #include "core_diamand_hierarchy_derived1.hpp" 17 | #include "core_diamand_hierarchy_derived2.hpp" 18 | #include "core_diamand_hierarchy_final_derived.hpp" 19 | #include "core_overloads_1.hpp" 20 | #include "core_overloads_2.hpp" 21 | 22 | #endif//__declarations_comparison_hpp__ 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /tests/data/declarations_enums.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __declarations_enums_hpp__ 7 | #define __declarations_enums_hpp__ 8 | 9 | namespace declarations{ namespace enums{ 10 | 11 | enum ENumbers{ e0, e1, e2, e3, e4, e5, e6, e7, e8, e9 }; 12 | 13 | class data{ 14 | public: 15 | enum EColor{ red, green, blue, black, white }; 16 | private: 17 | enum EPrivColor{ priv_red, priv_green, priv_blue, priv_black, priv_white }; 18 | 19 | void do_smth(EPrivColor x){} 20 | EColor favorite_color; 21 | }; 22 | 23 | } } 24 | 25 | #endif//__declarations_enums_hpp__ 26 | 27 | -------------------------------------------------------------------------------- /tests/data/declarations_for_filtering.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __declarations_for_filter_hpp__ 7 | #define __declarations_for_filter_hpp__ 8 | 9 | //those 2 includes wll bring a few declarations 10 | #include 11 | #include 12 | 13 | namespace declarations{ namespace filter{ 14 | 15 | enum color{ red, green, blue }; 16 | 17 | } } 18 | 19 | #endif//__declarations_for_filter_hpp__ 20 | 21 | -------------------------------------------------------------------------------- /tests/data/declarations_variables.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __declarations_variables_hpp__ 7 | #define __declarations_variables_hpp__ 8 | 9 | namespace declarations{ namespace variables{ 10 | 11 | const long unsigned int initialized = 10122004; 12 | int array[255]; 13 | 14 | static int static_var; 15 | extern int extern_var; 16 | 17 | struct struct_variables_t{ 18 | mutable int m_mutable; 19 | }; 20 | 21 | struct struct_variables_holder_t{ 22 | struct_variables_t m_struct_variables; 23 | }; 24 | 25 | struct struct_static_variables_t{ 26 | static const int ssv_static_var; 27 | static const int ssv_static_var_value = 1; 28 | }; 29 | 30 | } } 31 | 32 | #endif//__declarations_variables_hpp__ 33 | 34 | -------------------------------------------------------------------------------- /tests/data/find_noncopyable_vars.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | struct abstract{ 7 | virtual void do_smth() = 0; 8 | }; 9 | 10 | struct holder{ 11 | abstract* ptr1; 12 | abstract* const ptr2; 13 | }; 14 | -------------------------------------------------------------------------------- /tests/data/free_operators.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __free_operators_to_be_exported_hpp__ 7 | #define __free_operators_to_be_exported_hpp__ 8 | 9 | namespace free_operators{ 10 | 11 | struct number{ 12 | int i; 13 | 14 | number operator*( int ii ) const { 15 | number n2 = { i * ii }; 16 | return n2; 17 | } 18 | }; 19 | 20 | struct rational{ 21 | int x, y; 22 | }; 23 | 24 | number operator+( const number& x, int y ){ 25 | number z; 26 | z.i = x.i + y; 27 | return z; 28 | } 29 | 30 | bool operator!( const number& x ){ 31 | return !x.i; 32 | } 33 | 34 | number operator*( const number& n, double i ){ 35 | number n2 = { static_cast(n.i * i) }; 36 | return n2; 37 | } 38 | 39 | number operator*( double i, const number& n ){ 40 | number n2 = { static_cast(n.i * i) }; 41 | return n2; 42 | } 43 | 44 | rational operator*( int i, const rational& r ){ 45 | rational rr = { r.x * i, r.y }; 46 | return rr; 47 | } 48 | 49 | bool operator!( const rational& x ){ 50 | return !x.x; 51 | } 52 | 53 | 54 | } 55 | 56 | 57 | #endif//__free_operators_to_be_exported_hpp__ 58 | -------------------------------------------------------------------------------- /tests/data/has_public_binary_operator_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #include 7 | #include 8 | 9 | namespace binary_operator{ 10 | namespace yesequal{ 11 | typedef std::string yes1; 12 | 13 | struct trivial{ 14 | bool operator==(const trivial& other); 15 | }; 16 | 17 | typedef trivial yes2; 18 | 19 | struct external{ 20 | }; 21 | 22 | bool operator==( const external& left, const external& right ); 23 | 24 | typedef external yes3; 25 | } 26 | namespace noequal{ 27 | 28 | struct x1{ 29 | private: 30 | bool operator==( const x1& other ); 31 | }; 32 | 33 | typedef x1 no1; 34 | } 35 | namespace yesless{ 36 | typedef std::string yes1; 37 | 38 | struct trivial{ 39 | bool operator<(const trivial& other); 40 | }; 41 | 42 | typedef trivial yes2; 43 | 44 | struct external{ 45 | }; 46 | 47 | bool operator<( const external& left, const external& right ); 48 | 49 | typedef external yes3; 50 | } 51 | namespace noless{ 52 | 53 | struct x1{ 54 | private: 55 | bool operator<( const x1& other ); 56 | }; 57 | 58 | typedef x1 no1; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /tests/data/include_all.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __include_all_hpp__ 7 | #define __include_all_hpp__ 8 | 9 | #include "core_cache.hpp" 10 | #include "core_class_hierarchy.hpp" 11 | #include "core_diamand_hierarchy_base.hpp" 12 | #include "core_diamand_hierarchy_derived1.hpp" 13 | #include "core_diamand_hierarchy_derived2.hpp" 14 | #include "core_diamand_hierarchy_final_derived.hpp" 15 | #include "core_membership.hpp" 16 | #include "core_ns_join_1.hpp" 17 | #include "core_ns_join_2.hpp" 18 | #include "core_ns_join_3.hpp" 19 | #include "core_overloads_1.hpp" 20 | #include "core_overloads_2.hpp" 21 | #include "core_types.hpp" 22 | #include "declarations_calldef.hpp" 23 | #include "declarations_comparison.hpp" 24 | #include "declarations_enums.hpp" 25 | #include "declarations_variables.hpp" 26 | 27 | #endif//__include_all_hpp__ 28 | 29 | 30 | -------------------------------------------------------------------------------- /tests/data/include_std.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | 7 | #ifndef __include_std_hpp__ 8 | #define __include_std_hpp__ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace instantiate{ 19 | std::string str_a; 20 | std::wstring str_w; 21 | std::set set_of_int; 22 | std::list list_of_int; 23 | std::vector vector_of_int; 24 | std::map< std::pair< std::wstring, std::string >, int > map_of_smth; 25 | } 26 | 27 | #endif//__include_std_hpp__ 28 | 29 | 30 | -------------------------------------------------------------------------------- /tests/data/inline_specifier.hpp: -------------------------------------------------------------------------------- 1 | struct text_t{ 2 | inline bool inlined() const { return true; } 3 | unsigned long not_inlined() const; 4 | }; 5 | 6 | 7 | inline bool inlined(text_t){ return true; } 8 | unsigned long not_inlined(text_t); 9 | -------------------------------------------------------------------------------- /tests/data/merge_free_functions.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __merge_free_functions_hpp__ 7 | #define __merge_free_functions_hpp__ 8 | 9 | #include 10 | 11 | /* 12 | namespace n1{ 13 | 14 | struct s1{}; 15 | struct s2{}; 16 | 17 | template 18 | bool has_facet(int i) throw(){ 19 | return false; 20 | } 21 | 22 | void do_smth(){ 23 | has_facet( 12 ); 24 | has_facet( 12 ); 25 | } 26 | 27 | } 28 | */ 29 | 30 | 31 | #endif//__merge_free_functions_hpp__ 32 | 33 | -------------------------------------------------------------------------------- /tests/data/msvc_build/msvc_build.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual C++ Express 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msvc_build", "msvc_build.vcproj", "{FEC30A07-68D0-49A3-B7DE-431E5E3B9B6D}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {FEC30A07-68D0-49A3-B7DE-431E5E3B9B6D}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {FEC30A07-68D0-49A3-B7DE-431E5E3B9B6D}.Debug|Win32.Build.0 = Debug|Win32 14 | {FEC30A07-68D0-49A3-B7DE-431E5E3B9B6D}.Release|Win32.ActiveCfg = Release|Win32 15 | {FEC30A07-68D0-49A3-B7DE-431E5E3B9B6D}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /tests/data/noncopyable.hpp: -------------------------------------------------------------------------------- 1 | // Boost noncopyable.hpp header file --------------------------------------// 2 | 3 | // (C) Copyright Beman Dawes 1999-2003. Distributed under the Boost 4 | // Software License, Version 1.0. (See accompanying file 5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // See http://www.boost.org/libs/utility for documentation. 8 | 9 | #ifndef BOOST_NONCOPYABLE_HPP_INCLUDED 10 | #define BOOST_NONCOPYABLE_HPP_INCLUDED 11 | 12 | namespace boost { 13 | 14 | // Private copy constructor and copy assignment ensure classes derived from 15 | // class noncopyable cannot be copied. 16 | 17 | // Contributed by Dave Abrahams 18 | 19 | namespace noncopyable_ // protection from unintended ADL 20 | { 21 | class noncopyable 22 | { 23 | protected: 24 | noncopyable() {} 25 | ~noncopyable() {} 26 | private: // emphasize the following members are private 27 | noncopyable( const noncopyable& ); 28 | const noncopyable& operator=( const noncopyable& ); 29 | }; 30 | } 31 | 32 | typedef noncopyable_::noncopyable noncopyable; 33 | 34 | } // namespace boost 35 | 36 | #endif // BOOST_NONCOPYABLE_HPP_INCLUDED 37 | -------------------------------------------------------------------------------- /tests/data/null_comparison.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | namespace ns{ 5 | class Test 6 | { 7 | public: 8 | string var; 9 | }; 10 | 11 | int TestFunction1(Test a, Test b) 12 | { 13 | return 0; 14 | } 15 | 16 | int TestFunction2(Test a, Test b=Test()) 17 | { 18 | return 0; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/data/ogre.1.7.xml.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CastXML/pygccxml/26f63dc1f473114f836a43c309eaf5f65e5c5554/tests/data/ogre.1.7.xml.bz2 -------------------------------------------------------------------------------- /tests/data/plain_c.c: -------------------------------------------------------------------------------- 1 | #ifndef __HELLO_H__ 2 | #define __HELLO_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | 10 | void hello_print(const char *message); 11 | double hello_sum(double x, double y); 12 | void do_smth( int, ... ); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | 18 | #endif /* __HELLO_H__ */ 19 | -------------------------------------------------------------------------------- /tests/data/separate_compilation/all.h: -------------------------------------------------------------------------------- 1 | #ifndef __all_h_10062009__ 2 | #define __all_h_10062009__ 1 3 | 4 | #include "data.h" 5 | #include "base.h" 6 | #include "derived.h" 7 | 8 | #endif//__all_h_10062009__ 9 | -------------------------------------------------------------------------------- /tests/data/separate_compilation/base.h: -------------------------------------------------------------------------------- 1 | #ifndef __base_h_10062009__ 2 | #define __base_h_10062009__ 1 3 | 4 | #include "data.h" 5 | 6 | namespace buggy{ 7 | 8 | struct base_t{ 9 | virtual ~base_t() {}; 10 | virtual data_t* get_data() const = 0; 11 | }; 12 | 13 | } 14 | 15 | #endif//__base_h_10062009__ 16 | -------------------------------------------------------------------------------- /tests/data/separate_compilation/data.h: -------------------------------------------------------------------------------- 1 | #ifndef __data_h_10062009__ 2 | #define __data_h_10062009__ 1 3 | 4 | namespace std{ 5 | 6 | template 7 | struct pair{ 8 | typedef pair _Myt; 9 | typedef T1 first_type; 10 | typedef T2 second_type; 11 | 12 | pair(): first(T1()), second(T2()) 13 | {} 14 | 15 | pair(const T1& t1, const T2& t2) 16 | : first(t1), second(t2) 17 | {} 18 | 19 | T1 first; // the first stored value 20 | T2 second; // the second stored value 21 | }; 22 | } 23 | 24 | namespace buggy{ 25 | 26 | struct data_t{ 27 | typedef std::pair pair_t; 28 | }; 29 | 30 | } 31 | 32 | #endif//__data_h_10062009__ 33 | -------------------------------------------------------------------------------- /tests/data/separate_compilation/derived.h: -------------------------------------------------------------------------------- 1 | #ifndef __derived_h_10062009__ 2 | #define __derived_h_10062009__ 1 3 | 4 | #include "base.h" 5 | 6 | namespace buggy{ 7 | 8 | class derived_t: public base_t{ 9 | public: 10 | 11 | virtual ~derived_t() {}; 12 | virtual data_t* get_data() const; 13 | 14 | private: 15 | data_t::pair_t data_pair; 16 | }; 17 | 18 | } 19 | 20 | #endif//__derived_h_10062009__ 21 | -------------------------------------------------------------------------------- /tests/data/string_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #include 7 | 8 | namespace string_traits{ 9 | namespace yes{ 10 | typedef std::string x1; 11 | typedef const std::string x2; 12 | typedef std::string& x3; 13 | typedef const std::string& x4; 14 | } 15 | 16 | namespace no{ 17 | typedef int x1; 18 | typedef const int x2; 19 | typedef const int& x3; 20 | } 21 | 22 | } 23 | 24 | namespace wstring_traits{ 25 | namespace yes{ 26 | typedef std::wstring x1; 27 | typedef const std::wstring x2; 28 | typedef std::wstring& x3; 29 | typedef const std::wstring& x4; 30 | } 31 | 32 | namespace no{ 33 | typedef int x1; 34 | typedef const int x2; 35 | typedef const int& x3; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /tests/data/test_argument_without_name.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // Demonstrate some code where a struct without name is passed to a 7 | // templated function. See bug #55 8 | 9 | template 10 | void 11 | function(type &var) {}; 12 | 13 | int main() 14 | { 15 | // Create foo, a struct with no name 16 | struct { } foo; 17 | function(foo); 18 | } 19 | -------------------------------------------------------------------------------- /tests/data/test_array_argument.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | class test 7 | { 8 | public: 9 | // A constructor 10 | test(const float & t0){}; 11 | 12 | void function(int arg1[1024], int arg2[512]) {}; 13 | }; 14 | -------------------------------------------------------------------------------- /tests/data/test_ccflags.hpp: -------------------------------------------------------------------------------- 1 | // Will only be defined when -fopenmp flag is included 2 | // in ccflags of corresponding config object. 3 | #ifdef _OPENMP 4 | namespace ccflags_test_namespace{} 5 | #endif 6 | -------------------------------------------------------------------------------- /tests/data/test_comments.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | //! Namespace Comment 7 | //! Across multiple lines 8 | namespace comment { 9 | 10 | /** class comment */ 11 | class test 12 | { 13 | public: 14 | // Non-doc comment before. 15 | /** doc comment */ 16 | // Non-doc comment after. 17 | test(); 18 | 19 | /// cxx comment 20 | /// with multiple lines 21 | int hello(); 22 | 23 | //! mutable field comment 24 | int val1 = 0; 25 | /// bit field comment 26 | double val2=2; 27 | 28 | /// inside class enum comment 29 | enum test_enum { 30 | One = 1, 31 | Two = 2 32 | }; 33 | }; 34 | 35 | /// Outside Class enum comment 36 | enum com_enum { 37 | One = 1, 38 | Two = 2 39 | }; 40 | } -------------------------------------------------------------------------------- /tests/data/test_copy_constructor.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | typedef const int & myvar; 7 | 8 | class test 9 | { 10 | public: 11 | // The copy constructor 12 | test(const test & t0){}; 13 | 14 | // A constructor 15 | test(const float & t0){}; 16 | 17 | // A constructor with a typedef 18 | test(myvar t0){}; 19 | }; 20 | 21 | // An empty class; C++ will automatically create a copy constructor 22 | class test2 {}; 23 | -------------------------------------------------------------------------------- /tests/data/test_deprecation.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Insight Software Consortium. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // See http://www.boost.org/LICENSE_1_0.txt 4 | 5 | namespace deprecation { 6 | 7 | 8 | class __attribute__((deprecated("Test class Deprecated"))) test 9 | { 10 | public: 11 | test(); 12 | __attribute__((deprecated("One arg constructor is Deprecated"))) test(int a); 13 | 14 | int hello(); 15 | void __attribute__((deprecated("Function is deprecated"))) goodbye(); 16 | }; 17 | enum __attribute__((deprecated("Enumeration is Deprecated"))) com_enum { 18 | One = 1, 19 | Two = 2 20 | }; 21 | } -------------------------------------------------------------------------------- /tests/data/test_dynamic_exception.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | 7 | namespace declarations { 8 | namespace calldef { 9 | 10 | class some_exception_t{}; 11 | 12 | class other_exception_t{}; 13 | 14 | void calldef_with_throw() throw( some_exception_t, other_exception_t ); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/data/test_function_pointer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // func1 is a function pointer 7 | // In this case, func1 is the declaration of a function which has two arguments 8 | // (on the right) and returns nothing (void on the left) 9 | void (*func1)(int, double); 10 | 11 | // Another pointer, but not a function pointer 12 | int const volatile* myPointer; 13 | 14 | // A struct 15 | struct some_struct_t{}; 16 | 17 | // Another function pointer 18 | typedef void (some_struct_t::*x8)(); 19 | -------------------------------------------------------------------------------- /tests/data/test_map_gcc5.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #include 7 | 8 | using namespace std; 9 | 10 | class mytest { 11 | map mymap; 12 | }; 13 | -------------------------------------------------------------------------------- /tests/data/test_non_copyable_recursive.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2016 Insight Software Consortium. 2 | // Copyright 2004-2008 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #include 7 | 8 | // Demonstration of the real problem with basic c++ 9 | namespace Test1 { 10 | 11 | // Forward declaration 12 | class Base2; 13 | 14 | // Base 1, with pointer to Base2 15 | class Base1 { 16 | private: 17 | Base1(); 18 | 19 | protected: 20 | Base2* aBasePtr2; 21 | }; 22 | 23 | // Base 2, child class of Base1 24 | class Base2: public Base1 { 25 | private: 26 | Base2(); 27 | }; 28 | 29 | // Child class of Base2 30 | // Holds a pointer to Base2 31 | class Child: public Base2 { 32 | private: 33 | Child(); 34 | 35 | protected: 36 | Base2* aBasePtr2; 37 | }; 38 | 39 | } 40 | 41 | // Real-life test with std::istream where this happened 42 | namespace Test2 { 43 | 44 | class FileStreamDataStream { 45 | public: 46 | FileStreamDataStream(const std::istream* s) {} 47 | 48 | protected: 49 | std::istream* mInStream; 50 | }; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/data/test_order.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | const int c1 = 0; 7 | int const c2 = 0; 8 | 9 | const int * const cptr1 = 0; 10 | int const * const cptr2 = 0; 11 | 12 | volatile int v1 = 0; 13 | int volatile v2 = 0; 14 | 15 | volatile int * volatile vptr1 = 0; 16 | int volatile * volatile vptr2 = 0; 17 | 18 | const volatile int cv1 = 0; 19 | int const volatile cv2 = 0; 20 | volatile const int cv3 = 0; 21 | int volatile const cv4 = 0; 22 | 23 | const volatile int * const volatile cvptr1 = 0; 24 | int const volatile * const volatile cvptr2 = 0; 25 | volatile const int * volatile const cvptr3 = 0; 26 | int volatile const * volatile const cvptr4 = 0; 27 | 28 | const int ac1[2] = {}; 29 | int const ac2[2] = {}; 30 | 31 | const int * const acptr1[2] = {}; 32 | int const * const acptr2[2] = {}; 33 | 34 | class A {}; 35 | const class A classA = {}; -------------------------------------------------------------------------------- /tests/data/test_overrides.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Insight Software Consortium. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // See http://www.boost.org/LICENSE_1_0.txt 4 | #ifndef simple_h 5 | #define simple_h 6 | 7 | #include 8 | class base 9 | { 10 | public: 11 | base() {}; 12 | ~base() {}; 13 | virtual int goodbye(int num_ref, int num_times) = 0; 14 | }; 15 | 16 | class simple : public base 17 | { 18 | public: 19 | simple() {}; 20 | ~simple() {}; 21 | int hello() { return 0; }; 22 | int goodbye(int , int) override 23 | { 24 | std::cout << "goodbye\n"; 25 | return 10; 26 | } ; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /tests/data/test_pattern_parser.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | template 11 | class myClass {}; 12 | 13 | template 14 | class myClass2 {}; 15 | 16 | template 17 | class myClass3 {}; 18 | 19 | int main () { 20 | myClass(const std::string &, const std::string &)> m1; 21 | 22 | myClass(const int &, const int &)> m2; 23 | 24 | myClass2(const int &, const int &), std::vector> m3; 25 | 26 | myClass2, std::vector(const int &, const int &)> m4; 27 | 28 | myClass3, std::vector(const int &, const int &), std::vector(const int &, const int &)> m5; 29 | 30 | myClass3(const int &, const int &), std::vector, std::vector(const int &, const int &)> m6; 31 | 32 | myClass3(const int &, const int &), std::vector(const int &, const int &), std::vector> m7; 33 | 34 | myClass3(const int &, const int &), std::vector(double &)> m8; 35 | 36 | return 0; 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/data/test_smart_pointer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | std::shared_ptr yes1(new int { 6 }); 12 | std::auto_ptr yes2( new double { 7.0 } ); 13 | 14 | std::vector no1; 15 | std::set< std::string > no2; 16 | -------------------------------------------------------------------------------- /tests/data/type_as_exception_bug.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __key_error_bug_h__ 7 | #define __key_error_bug_h__ 8 | 9 | struct ExpressionError{}; 10 | 11 | struct xxx{ 12 | virtual void buggy() throw( ExpressionError& ); 13 | }; 14 | 15 | #endif//__key_error_bug_h__ 16 | -------------------------------------------------------------------------------- /tests/data/typedefs1.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __typedefs1_hpp__ 7 | #define __typedefs1_hpp__ 8 | 9 | #include "typedefs_base.hpp" 10 | 11 | namespace typedefs{ 12 | 13 | typedef item_t Item1; 14 | 15 | typedef int my_int_t; 16 | 17 | } 18 | 19 | #endif//__typedefs1_hpp__ 20 | -------------------------------------------------------------------------------- /tests/data/typedefs2.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __typedefs2_hpp__ 7 | #define __typedefs2_hpp__ 8 | 9 | #include "typedefs_base.hpp" 10 | 11 | namespace typedefs{ 12 | 13 | typedef item_t Item2; 14 | 15 | } 16 | 17 | #endif//__typedefs2_hpp__ 18 | -------------------------------------------------------------------------------- /tests/data/typedefs_base.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __typedefs_hpp__ 7 | #define __typedefs_hpp__ 8 | 9 | namespace typedefs{ 10 | 11 | struct item_t{}; 12 | 13 | typedef item_t Item; 14 | 15 | } 16 | 17 | #endif//__typedefs_hpp__ 18 | -------------------------------------------------------------------------------- /tests/data/unnamed_classes.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __unnamed_classes_hpp__ 7 | #define __unnamed_classes_hpp__ 8 | 9 | namespace unnamed{ 10 | 11 | struct S1{ 12 | struct S2{ 13 | union Flags{ 14 | struct{ 15 | unsigned int hasItemIdList : 1; 16 | unsigned int pointsToFileOrDir : 1; 17 | unsigned int hasDescription : 1; 18 | unsigned int hasRelativePath : 1; 19 | unsigned int hasWorkingDir : 1; 20 | unsigned int hasCmdLineArgs : 1; 21 | unsigned int hasCustomIcon : 1; 22 | unsigned int useWorkingDir : 1; // Seems to need to be set to enable working dir 23 | unsigned int unused : 24; 24 | }; 25 | unsigned int raw; 26 | } flags; 27 | 28 | union { 29 | struct{ 30 | unsigned int isReadOnly : 1; 31 | unsigned int isHidden : 1; 32 | unsigned int isSystem : 1; 33 | unsigned int isVolumeLabel : 1; 34 | unsigned int isDir : 1; 35 | unsigned int isModified : 1; // =archive bit set, ie; is a file normally 36 | unsigned int isEncrypted : 1; 37 | unsigned int isNormal : 1; // Doesn't seem to get set 38 | unsigned int isTemporary : 1; 39 | unsigned int isSparse : 1; 40 | unsigned int hasReparsePoint : 1; 41 | unsigned int isCompressed : 1; 42 | unsigned int isOffline : 1; 43 | unsigned int unused : 19; 44 | }; 45 | unsigned int raw; 46 | } fileattribs; // in GetFileAttributes() format 47 | } header; 48 | 49 | struct S3{ 50 | union 51 | { 52 | char anon_mem_c; 53 | int anon_mem_i; 54 | }; 55 | long s3_mem; 56 | S2 s2; 57 | }; 58 | }; 59 | 60 | } // namespace 61 | #endif//__unnamed_classes_hpp__ 62 | -------------------------------------------------------------------------------- /tests/data/unnamed_enums_bug1.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __unnamed_enums_bug1_hpp__ 7 | #define __unnamed_enums_bug1_hpp__ 8 | 9 | enum{ x1, x2 }; 10 | enum{ y1, y2 }; 11 | 12 | 13 | #endif//__unnamed_enums_bug1_hpp__ 14 | -------------------------------------------------------------------------------- /tests/data/unnamed_enums_bug2.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __unnamed_enums_bug2_hpp__ 7 | #define __unnamed_enums_bug2_hpp__ 8 | 9 | enum{ z1, z2 }; 10 | 11 | #endif//__unnamed_enums_bug2_hpp__ 12 | -------------------------------------------------------------------------------- /tests/data/unnamed_ns_bug.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #ifndef __unnamed_ns_bug_hpp__ 7 | #define __unnamed_ns_bug_hpp__ 8 | 9 | // unnamed namespace 10 | namespace{ 11 | bool bool_var; 12 | } 13 | 14 | namespace ns{ 15 | 16 | class test_t{ 17 | public: 18 | int var; 19 | }; 20 | 21 | } 22 | 23 | 24 | #endif//__unnamed_ns_bug_hpp__ 25 | -------------------------------------------------------------------------------- /tests/data/vector_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 Insight Software Consortium. 2 | // Copyright 2004-2009 Roman Yakovenko. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #include 7 | #include 8 | 9 | 10 | 11 | struct _0_{}; 12 | 13 | typedef std::vector< _0_ > container; 14 | 15 | 16 | namespace vector_traits{ 17 | namespace yes{ 18 | struct _1_{ 19 | typedef int value_type; 20 | typedef std::vector< int > container; 21 | 22 | container do_nothing(){ return container(0); }; 23 | }; 24 | 25 | struct _2_{ 26 | typedef _0_ value_type; 27 | typedef std::vector< _0_ > container; 28 | 29 | container do_nothing(){ return container(0); }; 30 | }; 31 | 32 | struct _3_{ 33 | typedef std::string value_type; 34 | typedef std::vector< std::string > container; 35 | 36 | container do_nothing(){ return container(0); }; 37 | }; 38 | 39 | struct _4_{ 40 | typedef std::vector value_type; 41 | typedef std::vector< std::vector > container; 42 | 43 | container do_nothing(){ return container(0); }; 44 | }; 45 | 46 | struct _5_{ 47 | typedef int value_type; 48 | typedef const std::vector< int > container; 49 | 50 | container do_nothing(){ return container(0); }; 51 | }; 52 | 53 | } 54 | 55 | namespace no{ 56 | struct _1_{ 57 | template< class T > 58 | struct vector{}; 59 | 60 | typedef vector container; 61 | }; 62 | 63 | struct _2_{ 64 | typedef const std::vector< const int >& container; 65 | }; 66 | } 67 | 68 | } 69 | 70 | void do_nothing( std::vector< std::wstring >& ); 71 | -------------------------------------------------------------------------------- /tests/example_tester_wrap.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import os 7 | import sys 8 | 9 | # This wrapper layer allows to execute the examples for the unittests 10 | # in a separate environment, where the sys.path has been hacked to point 11 | # to the pygccxml source tree (we do not want to pickup any pygccxml installed 12 | # on the system). Unfortunately passing the PYTHONPATH as env variable to 13 | # subprocess just appends to the sys.path ... here we want to insert at 14 | # position 1 so that the right pygccxml is found 15 | 16 | 17 | example_file = sys.argv[1] 18 | example_folder = os.path.dirname(example_file) 19 | root = os.path.normpath( 20 | os.path.dirname(sys.modules[__name__].__file__) + "/../") 21 | 22 | # Add the root folder to the path, so that the examples are not run against 23 | # whatever pygccxml version is installed 24 | sys.path.insert(1, root) 25 | 26 | # Hack the __file__ location, so that the example thinks it is in the 27 | # docs/examples folder 28 | sys.modules[__name__].__file__ = example_file 29 | 30 | # Run the example 31 | with open(example_file) as f: 32 | code = compile(f.read(), example_file, "exec") 33 | exec(code, None, None) 34 | -------------------------------------------------------------------------------- /tests/test_algorithms_cache.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = ['core_membership.hpp'] 15 | 16 | 17 | @pytest.fixture 18 | def global_ns(): 19 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 20 | config = autoconfig.cxx_parsers_cfg.config.clone() 21 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 22 | global_ns = declarations.get_global_namespace(decls) 23 | global_ns.init_optimizer() 24 | return global_ns 25 | 26 | 27 | def test_name_based(global_ns): 28 | cls = global_ns.class_(name='class_for_nested_enums_t') 29 | 30 | cls_full_name = declarations.full_name(cls) 31 | assert cls.cache.full_name == cls_full_name 32 | 33 | cls_declaration_path = declarations.declaration_path(cls) 34 | assert cls.cache.declaration_path == cls_declaration_path 35 | 36 | enum = cls.enumeration('ENestedPublic') 37 | 38 | enum_full_name = declarations.full_name(enum) 39 | assert enum.cache.full_name == enum_full_name 40 | 41 | enum_declaration_path = declarations.declaration_path(enum) 42 | assert enum.cache.declaration_path == enum_declaration_path 43 | 44 | # now we change class name, all internal decls cache should be cleared 45 | cls.name = "new_name" 46 | assert not cls.cache.full_name 47 | assert not cls.cache.declaration_path 48 | 49 | assert not enum.cache.full_name 50 | assert not enum.cache.declaration_path 51 | 52 | 53 | def test_access_type(global_ns): 54 | cls = global_ns.class_(name='class_for_nested_enums_t') 55 | enum = cls.enumeration('ENestedPublic') 56 | assert enum.cache.access_type == 'public' 57 | enum.cache.reset_access_type() 58 | assert not enum.cache.access_type 59 | assert 'public' == cls.find_out_member_access_type(enum) 60 | assert enum.cache.access_type == 'public' 61 | -------------------------------------------------------------------------------- /tests/test_argument_without_name.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = ['test_argument_without_name.hpp'] 14 | 15 | 16 | @pytest.fixture 17 | def global_ns(): 18 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 19 | config = autoconfig.cxx_parsers_cfg.config.clone() 20 | config.cflags = "-std=c++11" 21 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 22 | global_ns = declarations.get_global_namespace(decls) 23 | global_ns.init_optimizer() 24 | return global_ns 25 | 26 | 27 | def test_argument_without_name(global_ns): 28 | """ 29 | Test passing an object without name to a templated function. 30 | 31 | The test was failing when building the declaration string. 32 | The declaration string will be 'void (*)( & )'. If the passed 33 | object had a name the result would then be 'void (*)(Name & )'. 34 | 35 | See bug #55 36 | 37 | """ 38 | 39 | criteria = declarations.calldef_matcher(name="function") 40 | free_funcs = declarations.matcher.find(criteria, global_ns) 41 | for free_func in free_funcs: 42 | decl_string = free_func.create_decl_string(with_defaults=False) 43 | assert decl_string == "void (*)( & )" 44 | -------------------------------------------------------------------------------- /tests/test_array_argument.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = ['test_array_argument.hpp'] 14 | 15 | 16 | @pytest.fixture 17 | def global_ns(): 18 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 19 | config = autoconfig.cxx_parsers_cfg.config.clone() 20 | config.cflags = "-std=c++11" 21 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 22 | global_ns = declarations.get_global_namespace(decls) 23 | global_ns.init_optimizer() 24 | return global_ns 25 | 26 | 27 | def test_array_argument(global_ns): 28 | 29 | """ 30 | Test to ensure that function arguments' array size are kept intact 31 | rather than presented as pointers. 32 | 33 | """ 34 | 35 | criteria = declarations.calldef_matcher(name="function") 36 | free_funcs = declarations.matcher.find(criteria, global_ns) 37 | for free_func in free_funcs: 38 | decl_string = free_func.create_decl_string(with_defaults=False) 39 | assert decl_string == "void ( ::test::* )( int [1024],int [512] )" 40 | arg1 = free_func.arguments[0] 41 | arg2 = free_func.arguments[1] 42 | assert arg1.decl_type.decl_string == "int [1024]" 43 | assert arg1.name == "arg1" 44 | assert declarations.type_traits.array_size(arg1.decl_type) == 1024 45 | assert isinstance( 46 | declarations.type_traits.array_item_type(arg1.decl_type), 47 | declarations.cpptypes.int_t 48 | ) is True 49 | assert arg2.decl_type.decl_string == "int [512]" 50 | assert arg2.name == "arg2" 51 | assert declarations.type_traits.array_size(arg2.decl_type) == 512 52 | assert isinstance( 53 | declarations.type_traits.array_item_type(arg2.decl_type), 54 | declarations.cpptypes.int_t 55 | ) is True 56 | -------------------------------------------------------------------------------- /tests/test_attributes.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = [ 14 | # TODO: once gccxml is removed; rename this to something like 15 | # annotate_tester 16 | "attributes_castxml.hpp", 17 | ] 18 | 19 | 20 | @pytest.fixture 21 | def global_ns(): 22 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 23 | INIT_OPTIMIZER = True 24 | config = autoconfig.cxx_parsers_cfg.config.clone() 25 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 26 | global_ns = declarations.get_global_namespace(decls) 27 | if INIT_OPTIMIZER: 28 | global_ns.init_optimizer() 29 | return global_ns 30 | 31 | 32 | def test_attributes(global_ns): 33 | numeric = global_ns.class_('numeric_t') 34 | do_nothing = numeric.member_function('do_nothing') 35 | arg = do_nothing.arguments[0] 36 | assert "annotate(sealed)" == numeric.attributes 37 | assert "annotate(no throw)" == do_nothing.attributes 38 | assert "annotate(out)" == arg.attributes 39 | assert numeric.member_operators(name="=")[0].attributes is None 40 | 41 | 42 | def test_attributes_thiscall(): 43 | """ 44 | Test attributes with the "f2" flag 45 | 46 | """ 47 | 48 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 49 | config = autoconfig.cxx_parsers_cfg.config.clone() 50 | 51 | config.flags = ["f2"] 52 | config.castxml_epic_version = 1 53 | 54 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 55 | global_ns = declarations.get_global_namespace(decls) 56 | global_ns.init_optimizer() 57 | 58 | numeric = global_ns.class_('numeric_t') 59 | do_nothing = numeric.member_function('do_nothing') 60 | arg = do_nothing.arguments[0] 61 | 62 | assert "annotate(sealed)" == numeric.attributes 63 | assert "annotate(out)" == arg.attributes 64 | 65 | assert "annotate(no throw)" == do_nothing.attributes 66 | assert numeric.member_operators(name="=")[0].attributes is None 67 | -------------------------------------------------------------------------------- /tests/test_better_templates_matcher.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = [ 14 | "better_templates_matcher_tester.hpp", 15 | ] 16 | 17 | 18 | @pytest.fixture 19 | def global_ns(): 20 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 21 | INIT_OPTIMIZER = True 22 | config = autoconfig.cxx_parsers_cfg.config.clone() 23 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 24 | global_ns = declarations.get_global_namespace(decls) 25 | if INIT_OPTIMIZER: 26 | global_ns.init_optimizer() 27 | return global_ns 28 | 29 | 30 | def test_better_templates_matcher(global_ns): 31 | classes = [ 32 | "::Ogre::PlaneBoundedVolume", 33 | "::Ogre::Plane", 34 | "::Ogre::Singleton", 35 | "::Ogre::PCZoneFactoryManager", 36 | ] 37 | for i in classes: 38 | global_ns.class_(i) 39 | -------------------------------------------------------------------------------- /tests/test_bit_fields.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = [ 14 | "bit_fields.hpp", 15 | ] 16 | 17 | 18 | @pytest.fixture 19 | def global_ns(): 20 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 21 | INIT_OPTIMIZER = True 22 | config = autoconfig.cxx_parsers_cfg.config.clone() 23 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 24 | global_ns = declarations.get_global_namespace(decls) 25 | if INIT_OPTIMIZER: 26 | global_ns.init_optimizer() 27 | return global_ns 28 | 29 | 30 | def test_bit_fields(global_ns): 31 | bf_x = global_ns.variable('x') 32 | assert bf_x.bits == 1 33 | 34 | bf_y = global_ns.variable('y') 35 | assert bf_y.bits == 7 36 | 37 | mv_z = global_ns.variable('z') 38 | assert mv_z.bits is None 39 | -------------------------------------------------------------------------------- /tests/test_cache_enums.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import os 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = [ 15 | "declarations_enums.hpp", 16 | ] 17 | 18 | 19 | def test_cache(): 20 | cache_file = os.path.join(autoconfig.data_directory, 'pygccxml.cache') 21 | if os.path.exists(cache_file) and os.path.isfile(cache_file): 22 | os.remove(cache_file) 23 | 24 | config = autoconfig.cxx_parsers_cfg.config.clone() 25 | 26 | cache = parser.file_cache_t(cache_file) 27 | reader = parser.source_reader_t(config, cache) 28 | decls1 = reader.read_file(TEST_FILES[0]) 29 | cache.flush() 30 | cache = parser.file_cache_t(cache_file) 31 | reader = parser.source_reader_t(config, cache) 32 | decls2 = reader.read_file(TEST_FILES[0]) 33 | 34 | enum_matcher = declarations.declaration_matcher_t( 35 | name="EColor", 36 | decl_type=declarations.enumeration_t 37 | ) 38 | 39 | color1 = declarations.matcher.get_single(enum_matcher, decls1) 40 | color2 = declarations.matcher.get_single(enum_matcher, decls2) 41 | assert color1.values == color2.values 42 | -------------------------------------------------------------------------------- /tests/test_cached_source_file.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import os 7 | import stat 8 | 9 | from . import autoconfig 10 | 11 | from pygccxml import utils 12 | from pygccxml import parser 13 | 14 | TEST_FILES = [ 15 | "core_types.hpp", 16 | ] 17 | 18 | 19 | def test_cached_source_file(): 20 | 21 | config = autoconfig.cxx_parsers_cfg.config.clone() 22 | 23 | fconfig = parser.file_configuration_t( 24 | data=TEST_FILES[0], 25 | content_type=parser.CONTENT_TYPE.CACHED_SOURCE_FILE) 26 | try: 27 | prj_reader = parser.project_reader_t(config) 28 | prj_reader.read_files( 29 | [fconfig], 30 | compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE) 31 | assert os.path.exists(fconfig.cached_source_file) 32 | mtime1 = os.stat(fconfig.cached_source_file)[stat.ST_MTIME] 33 | prj_reader.read_files( 34 | [fconfig], 35 | compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE) 36 | mtime2 = os.stat(fconfig.cached_source_file)[stat.ST_MTIME] 37 | assert mtime1 == mtime2 38 | finally: 39 | utils.remove_file_no_raise(fconfig.cached_source_file, config) 40 | -------------------------------------------------------------------------------- /tests/test_calldef_matcher.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = [ 15 | "declarations_calldef.hpp", 16 | ] 17 | 18 | 19 | @pytest.fixture 20 | def decls(): 21 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 22 | config = autoconfig.cxx_parsers_cfg.config.clone() 23 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 24 | return decls 25 | 26 | 27 | def test_calldef_matcher(decls): 28 | criteria = declarations.calldef_matcher_t( 29 | name='return_default_args', 30 | return_type='int', 31 | arg_types=[None, declarations.bool_t()]) 32 | rda = declarations.matcher.get_single(criteria, decls) 33 | assert rda is not None 34 | -------------------------------------------------------------------------------- /tests/test_calling_convention.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from pygccxml import declarations 7 | 8 | 9 | def test_extract(): 10 | data = [ 11 | ('thiscall', 12 | '(public: __thiscall std::auto_ptr' + 13 | '::auto_ptr(class std::auto_ptr' + 14 | ' &))'), 15 | ('', "(const pof::number_t::`vftable')")] 16 | 17 | for expected, text in data: 18 | got = declarations.CALLING_CONVENTION_TYPES.extract(text) 19 | assert got == expected 20 | -------------------------------------------------------------------------------- /tests/test_castxml_wrong_epic.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | 12 | 13 | def test_castxml_epic_version_check(): 14 | """ 15 | Test using a forbidden value for the castxml epic version. 16 | 17 | """ 18 | 19 | config = autoconfig.cxx_parsers_cfg.config.clone() 20 | config.castxml_epic_version = 2 21 | with pytest.raises(RuntimeError): 22 | parser.parse_string("", config) 23 | -------------------------------------------------------------------------------- /tests/test_ccflags.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2021 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = [ 15 | "test_ccflags.hpp", 16 | ] 17 | 18 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 19 | 20 | 21 | @pytest.fixture 22 | def config(): 23 | config = autoconfig.cxx_parsers_cfg.config.clone() 24 | config.castxml_epic_version = 1 25 | config.append_cflags("-fopenmp") 26 | return config 27 | 28 | 29 | def test_ccflags(config): 30 | # First check that macro is not defined. 31 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 32 | global_ns = declarations.get_global_namespace(decls) 33 | 34 | namespace_names = [ 35 | n.name for n in global_ns.namespaces(allow_empty=True) 36 | ] 37 | assert "ccflags_test_namespace" not in namespace_names 38 | 39 | # Next check that macro is defined when passed directly as ccflag 40 | 41 | if "clang++" in config.compiler_path: 42 | config.append_ccflags("-Xpreprocessor") 43 | config.append_ccflags("-fopenmp") 44 | 45 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 46 | global_ns = declarations.get_global_namespace(decls) 47 | 48 | namespace_names = [n.name for n in global_ns.namespaces()] 49 | assert "ccflags_test_namespace" in namespace_names 50 | -------------------------------------------------------------------------------- /tests/test_complex_types.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import declarations 11 | from pygccxml import parser 12 | 13 | 14 | TEST_FILES = [ 15 | "complex_types.hpp", 16 | ] 17 | 18 | 19 | @pytest.fixture 20 | def global_ns(): 21 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 22 | INIT_OPTIMIZER = True 23 | config = autoconfig.cxx_parsers_cfg.config.clone() 24 | config.castxml_epic_version = 1 25 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 26 | global_ns = declarations.get_global_namespace(decls) 27 | if INIT_OPTIMIZER: 28 | global_ns.init_optimizer() 29 | return global_ns 30 | 31 | 32 | def test_complex_types(): 33 | """ 34 | This test tests presence of complex long double, float within 35 | FUNDAMENTAL_TYPES map 36 | """ 37 | pass 38 | # TODO: write test 39 | -------------------------------------------------------------------------------- /tests/test_config.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from pygccxml import parser 9 | from pygccxml import utils 10 | 11 | 12 | def test_config(): 13 | """Test config setup with wrong xml generator setups.""" 14 | 15 | # Some code to parse for the example 16 | code = "int a;" 17 | 18 | # Find the location of the xml generator (castxml) 19 | generator_path, name = utils.find_xml_generator() 20 | 21 | # No xml generator path 22 | config = parser.xml_generator_configuration_t(xml_generator=name) 23 | with pytest.raises(RuntimeError): 24 | parser.parse_string(code, config) 25 | 26 | # Invalid path 27 | config = parser.xml_generator_configuration_t( 28 | xml_generator_path="wrong/path", 29 | xml_generator=name) 30 | with pytest.raises(RuntimeError): 31 | parser.parse_string(code, config) 32 | 33 | # None path 34 | config = parser.xml_generator_configuration_t( 35 | xml_generator_path=None, 36 | xml_generator=name) 37 | with pytest.raises(RuntimeError): 38 | parser.parse_string(code, config) 39 | 40 | # No name 41 | config = parser.xml_generator_configuration_t( 42 | xml_generator_path=generator_path) 43 | with pytest.raises(RuntimeError): 44 | parser.parse_string(code, config) 45 | 46 | # Random name 47 | config = parser.xml_generator_configuration_t( 48 | xml_generator_path=generator_path, 49 | xml_generator="not_a_generator") 50 | with pytest.raises(RuntimeError): 51 | parser.parse_string(code, config) 52 | 53 | # None name 54 | config = parser.xml_generator_configuration_t( 55 | xml_generator_path=generator_path, 56 | xml_generator=None) 57 | with pytest.raises(RuntimeError): 58 | parser.parse_string(code, config) 59 | -------------------------------------------------------------------------------- /tests/test_const_volatile_arg.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = [ 15 | "const_volatile_arg.hpp", 16 | ] 17 | 18 | 19 | @pytest.fixture 20 | def global_ns(): 21 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 22 | INIT_OPTIMIZER = True 23 | config = autoconfig.cxx_parsers_cfg.config.clone() 24 | config.castxml_epic_version = 1 25 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 26 | global_ns = declarations.get_global_namespace(decls) 27 | if INIT_OPTIMIZER: 28 | global_ns.init_optimizer() 29 | return global_ns 30 | 31 | 32 | def test_const_volatile_arg(global_ns): 33 | f = global_ns.free_function('pygccxml_bug') 34 | t = f.arguments[0].decl_type 35 | assert isinstance(t, declarations.pointer_t) 36 | assert isinstance(t.base, declarations.volatile_t) 37 | assert isinstance(t.base.base, declarations.const_t) 38 | assert declarations.is_integral(t.base.base.base) 39 | -------------------------------------------------------------------------------- /tests/test_copy_constructor.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = [ 14 | "test_copy_constructor.hpp", 15 | ] 16 | 17 | 18 | @pytest.fixture 19 | def global_ns(): 20 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 21 | INIT_OPTIMIZER = True 22 | config = autoconfig.cxx_parsers_cfg.config.clone() 23 | config.castxml_epic_version = 1 24 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 25 | global_ns = declarations.get_global_namespace(decls) 26 | if INIT_OPTIMIZER: 27 | global_ns.init_optimizer() 28 | return global_ns 29 | 30 | 31 | def test_copy_constructor(global_ns): 32 | """ 33 | Check the is_copy_constructor method. 34 | 35 | This fails when using CastXML, see issue #27. 36 | 37 | """ 38 | 39 | tclass = global_ns.class_("test") 40 | ctors = [] 41 | for decl in tclass.declarations: 42 | if isinstance(decl, declarations.constructor_t): 43 | ctors.append(decl) 44 | 45 | # test::test(test const & t0) [copy constructor] 46 | assert declarations.is_copy_constructor(ctors[0]) 47 | # test::test(float const & t0) [constructor] 48 | assert not declarations.is_copy_constructor(ctors[1]) 49 | # test::test(myvar t0) [constructor] 50 | assert not declarations.is_copy_constructor(ctors[2]) 51 | 52 | t2class = global_ns.class_("test2") 53 | ctors = [] 54 | for decl in t2class.declarations: 55 | if isinstance(decl, declarations.constructor_t): 56 | ctors.append(decl) 57 | 58 | # test2::test2() [constructor] 59 | assert not declarations.is_copy_constructor(ctors[0]) 60 | # test2::test2(test2 const & arg0) [copy constructor] 61 | assert declarations.is_copy_constructor(ctors[1]) 62 | -------------------------------------------------------------------------------- /tests/test_copy_constructor2.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import os 7 | import bz2 8 | 9 | from . import autoconfig 10 | 11 | from pygccxml import parser 12 | from pygccxml import declarations 13 | 14 | 15 | def test_copy_constructor2(): 16 | # Extract the xml file from the bz2 archive 17 | bz2_path = os.path.join( 18 | autoconfig.data_directory, 19 | 'ogre.1.7.xml.bz2') 20 | xml_path = os.path.join( 21 | autoconfig.data_directory, 22 | 'ogre.1.7.xml') 23 | with open(xml_path, 'wb') as new_file: 24 | # bz2.BZ2File can not be used in a with statement in python 2.6 25 | bz2_file = bz2.BZ2File(bz2_path, 'rb') 26 | for data in iter(lambda: bz2_file.read(100 * 1024), b''): 27 | new_file.write(data) 28 | bz2_file.close() 29 | 30 | reader = parser.source_reader_t(autoconfig.cxx_parsers_cfg.config) 31 | global_ns = declarations.get_global_namespace( 32 | reader.read_xml_file(xml_path) 33 | ) 34 | global_ns.init_optimizer() 35 | 36 | for x in global_ns.typedefs('SettingsMultiMap'): 37 | assert declarations.is_noncopyable(x) is False 38 | 39 | for x in global_ns.typedefs('SettingsIterator'): 40 | assert declarations.is_noncopyable(x) is False 41 | 42 | for x in global_ns.typedefs('SectionIterator'): 43 | assert declarations.is_noncopyable(x) is False 44 | 45 | os.remove(xml_path) 46 | -------------------------------------------------------------------------------- /tests/test_cpp_standards.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | import platform 9 | 10 | from . import autoconfig 11 | 12 | from pygccxml import parser 13 | 14 | 15 | def test_cpp_standards(): 16 | """ 17 | Test different compilation standards by setting cflags. 18 | 19 | """ 20 | 21 | config = autoconfig.cxx_parsers_cfg.config.clone() 22 | 23 | cflags_common = "" 24 | 25 | if platform.system() == "Darwin": 26 | cflags_common = " -Dat_quick_exit=atexit -Dquick_exit=exit" 27 | # https://fr.mathworks.com/matlabcentral/answers/2013982-clibgen-generatelibrarydefinition-error-the-global-scope-has-no-quick_exit-on-mac-m2#answer_1439856 28 | # https://github.com/jetbrains/kotlin/commit/d50f585911dedec5723213da8835707ac95e1c01 29 | 30 | parser.parse(["cpp_standards.hpp"], config) 31 | 32 | if platform.system() != 'Windows': 33 | config.cflags = "-std=c++98" + cflags_common 34 | parser.parse(["cpp_standards.hpp"], config) 35 | 36 | config.cflags = "-std=c++03" + cflags_common 37 | parser.parse(["cpp_standards.hpp"], config) 38 | 39 | config.cflags = "-std=c++11" + cflags_common 40 | 41 | parser.parse(["cpp_standards.hpp"], config) 42 | 43 | config.cflags = "-std=c++14" + cflags_common 44 | parser.parse(["cpp_standards.hpp"], config) 45 | 46 | config.cflags = "-std=c++1z" + cflags_common 47 | parser.parse(["cpp_standards.hpp"], config) 48 | 49 | # Pass down a flag that does not exist. 50 | # This should raise an exception. 51 | config.cflags = "-std=c++00" + cflags_common 52 | with pytest.raises(RuntimeError): 53 | parser.parse(["cpp_standards.hpp"], config) 54 | -------------------------------------------------------------------------------- /tests/test_create_decl_string.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = [ 15 | "declaration_string.hpp", 16 | ] 17 | 18 | 19 | @pytest.fixture 20 | def global_ns(): 21 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 22 | INIT_OPTIMIZER = True 23 | config = autoconfig.cxx_parsers_cfg.config.clone() 24 | config.castxml_epic_version = 1 25 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 26 | global_ns = declarations.get_global_namespace(decls) 27 | if INIT_OPTIMIZER: 28 | global_ns.init_optimizer() 29 | return global_ns 30 | 31 | 32 | def test_create_decl_string(global_ns): 33 | """ 34 | Test the create_decl_string method. 35 | 36 | """ 37 | 38 | myfunc = global_ns.free_function("myfunc") 39 | 40 | decl = declarations.free_function_type_t.create_decl_string( 41 | myfunc.return_type, myfunc.argument_types) 42 | 43 | assert decl != "('int (*)( int,int )', 'int (*)( int,int )')" 44 | 45 | box = global_ns.class_("Box") 46 | myinternfunc = box.member_function("myinternfunc") 47 | decl = declarations.member_function_type_t.create_decl_string( 48 | myinternfunc.return_type, 49 | box.decl_string, 50 | myinternfunc.argument_types, 51 | myinternfunc.has_const) 52 | 53 | assert decl != "short int ( ::Box::* )( ) " 54 | -------------------------------------------------------------------------------- /tests/test_decl_printer.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import sys 7 | import pytest 8 | 9 | from . import autoconfig 10 | 11 | from pygccxml import parser 12 | from pygccxml import declarations 13 | 14 | 15 | TEST_FILES = [ 16 | 'core_ns_join_1.hpp', 17 | 'core_ns_join_2.hpp', 18 | 'core_ns_join_3.hpp', 19 | 'core_membership.hpp', 20 | 'core_class_hierarchy.hpp', 21 | 'core_types.hpp', 22 | 'core_diamand_hierarchy_base.hpp', 23 | 'core_diamand_hierarchy_derived1.hpp', 24 | 'core_diamand_hierarchy_derived2.hpp', 25 | 'core_diamand_hierarchy_final_derived.hpp', 26 | 'core_overloads_1.hpp', 27 | 'core_overloads_2.hpp', 28 | 'typedefs_base.hpp', 29 | ] 30 | 31 | 32 | @pytest.fixture 33 | def decls(): 34 | COMPILATION_MODE = parser.COMPILATION_MODE.FILE_BY_FILE 35 | config = autoconfig.cxx_parsers_cfg.config.clone() 36 | config.castxml_epic_version = 1 37 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 38 | return decls 39 | 40 | 41 | def test_printer(decls): 42 | # Redirect sys.stdout to a class with a writer doing nothing 43 | # This greatly reduces the size of the test output and makes 44 | # test log files readable. 45 | # Note: flush needs to be defined; because if not this will 46 | # result in an AttributeError on call. 47 | class DontPrint(object): 48 | def write(*args): 49 | pass 50 | 51 | def flush(*args): 52 | pass 53 | sys.stdout = DontPrint() 54 | 55 | declarations.print_declarations(decls) 56 | 57 | 58 | def test__str__(decls): 59 | decls = declarations.make_flatten(decls) 60 | for decl in decls: 61 | str(decl) 62 | -------------------------------------------------------------------------------- /tests/test_decl_string.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = [ 15 | "declarations_calldef.hpp", 16 | ] 17 | 18 | 19 | @pytest.fixture 20 | def global_ns(): 21 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 22 | INIT_OPTIMIZER = True 23 | config = autoconfig.cxx_parsers_cfg.config.clone() 24 | config.castxml_epic_version = 1 25 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 26 | global_ns = declarations.get_global_namespace(decls) 27 | if INIT_OPTIMIZER: 28 | global_ns.init_optimizer() 29 | return global_ns 30 | 31 | 32 | TEMPLATE = """ 33 | //test generated declaration string using gcc(xml) compiler 34 | #include "declarations_calldef.hpp" 35 | void test_generated_decl_string( %s ); 36 | """ 37 | 38 | 39 | def test_member_function(global_ns): 40 | config = autoconfig.cxx_parsers_cfg.config.clone() 41 | member_inline_call = \ 42 | global_ns.member_function('member_inline_call') 43 | decls = parser.parse_string( 44 | TEMPLATE % 45 | member_inline_call.decl_string, 46 | config) 47 | assert decls is not None 48 | 49 | 50 | def test_free_function(global_ns): 51 | config = autoconfig.cxx_parsers_cfg.config.clone() 52 | return_default_args = \ 53 | global_ns.free_function('return_default_args') 54 | decls = parser.parse_string( 55 | TEMPLATE % 56 | return_default_args.decl_string, 57 | config) 58 | assert decls is not None 59 | 60 | 61 | def test_all_mem_and_free_funs(global_ns): 62 | config = autoconfig.cxx_parsers_cfg.config.clone() 63 | ns = global_ns.namespace('::declarations::calldef') 64 | for f in ns.member_functions(): 65 | decls = parser.parse_string( 66 | TEMPLATE % f.decl_string, config) 67 | assert decls is not None 68 | for f in ns.free_functions(): 69 | decls = parser.parse_string( 70 | TEMPLATE % f.decl_string, config) 71 | assert decls is not None 72 | -------------------------------------------------------------------------------- /tests/test_declaration_files.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import os 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = [ 15 | 'core_ns_join_1.hpp', 16 | 'core_ns_join_2.hpp', 17 | 'core_ns_join_3.hpp', 18 | 'core_membership.hpp', 19 | 'core_class_hierarchy.hpp', 20 | 'core_types.hpp', 21 | 'core_diamand_hierarchy_base.hpp', 22 | 'core_diamand_hierarchy_derived1.hpp', 23 | 'core_diamand_hierarchy_derived2.hpp', 24 | 'core_diamand_hierarchy_final_derived.hpp', 25 | 'core_overloads_1.hpp', 26 | 'core_overloads_2.hpp', 27 | 'typedefs_base.hpp', 28 | ] 29 | 30 | 31 | def test_declaration_files(): 32 | config = autoconfig.cxx_parsers_cfg.config.clone() 33 | prj_reader = parser.project_reader_t(config) 34 | decls = prj_reader.read_files( 35 | TEST_FILES, 36 | compilation_mode=parser.COMPILATION_MODE.ALL_AT_ONCE) 37 | files = declarations.declaration_files(decls) 38 | result = set() 39 | for fn in files: 40 | result.add(os.path.split(fn)[1]) 41 | assert set(TEST_FILES).issubset(result) is True 42 | -------------------------------------------------------------------------------- /tests/test_declaration_matcher.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = [ 14 | "classes.hpp", 15 | ] 16 | 17 | 18 | @pytest.fixture 19 | def global_ns(): 20 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 21 | INIT_OPTIMIZER = True 22 | config = autoconfig.cxx_parsers_cfg.config.clone() 23 | config.castxml_epic_version = 1 24 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 25 | global_ns = declarations.get_global_namespace(decls) 26 | if INIT_OPTIMIZER: 27 | global_ns.init_optimizer() 28 | return global_ns 29 | 30 | 31 | def test_global(global_ns): 32 | global_ns.class_('cls') 33 | global_ns.class_('::cls') 34 | 35 | 36 | def test_typedefs(global_ns): 37 | global_ns.class_('cls2') 38 | global_ns.typedef('cls2') 39 | global_ns.class_('::cls2') 40 | 41 | global_ns.class_('cls3') 42 | global_ns.typedef('cls3') 43 | cls3 = global_ns.class_('::cls3') 44 | cls3.variable('i') 45 | 46 | 47 | def test_ns1(global_ns): 48 | ns1 = global_ns.namespace('ns') 49 | 50 | global_ns.class_('nested_cls') 51 | with pytest.raises(Exception): 52 | global_ns.class_('ns::nested_cls') 53 | global_ns.class_('::ns::nested_cls') 54 | 55 | with pytest.raises(Exception): 56 | ns1.class_('::nested_cls') 57 | ns1.class_('nested_cls') 58 | ns1.class_('::ns::nested_cls') 59 | 60 | global_ns.class_('nested_cls2') 61 | with pytest.raises(Exception): 62 | global_ns.class_('ns::nested_cls2') 63 | global_ns.class_('::ns::nested_cls2') 64 | 65 | global_ns.class_('nested_cls3') 66 | with pytest.raises(Exception): 67 | global_ns.class_('ns::nested_cls3') 68 | global_ns.class_('::ns::nested_cls3') 69 | -------------------------------------------------------------------------------- /tests/test_deprecation.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Insight Software Consortium. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # See http://www.boost.org/LICENSE_1_0.txt 4 | 5 | import pytest 6 | 7 | from . import autoconfig 8 | 9 | from pygccxml import parser 10 | from pygccxml import declarations 11 | 12 | 13 | TEST_FILES = [ 14 | "test_deprecation.hpp", 15 | ] 16 | 17 | 18 | @pytest.fixture 19 | def global_ns(): 20 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 21 | INIT_OPTIMIZER = True 22 | config = autoconfig.cxx_parsers_cfg.config.clone() 23 | config.castxml_epic_version = 1 24 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 25 | global_ns = declarations.get_global_namespace(decls) 26 | if INIT_OPTIMIZER: 27 | global_ns.init_optimizer() 28 | return global_ns 29 | 30 | 31 | def _check_text_content(desired_text, deprecation_string): 32 | assert desired_text == deprecation_string 33 | 34 | 35 | def test_comment_deprecation(global_ns): 36 | """ 37 | Check the comment parsing 38 | """ 39 | 40 | tnamespace = global_ns.namespace("deprecation") 41 | 42 | tenumeration = tnamespace.enumeration("com_enum") 43 | assert "deprecation" in dir(tenumeration) 44 | _check_text_content( 45 | 'Enumeration is Deprecated', 46 | tenumeration.deprecation) 47 | 48 | tclass = tnamespace.class_("test") 49 | assert "deprecation" in dir(tclass) 50 | _check_text_content( 51 | "Test class Deprecated", 52 | tclass.deprecation) 53 | 54 | tmethod = tclass.member_functions()[0] 55 | tmethod_dep = tclass.member_functions()[1] 56 | 57 | assert "deprecation", dir(tmethod) 58 | assert tmethod.deprecation is None 59 | _check_text_content( 60 | "Function is deprecated", 61 | tmethod_dep.deprecation) 62 | 63 | tconstructor = tclass.constructors()[0] 64 | tconstructor_dep = tclass.constructors()[1] 65 | 66 | assert tconstructor.deprecation is None 67 | assert "deprecation" in dir(tconstructor_dep) 68 | _check_text_content( 69 | "One arg constructor is Deprecated", 70 | tconstructor_dep.deprecation) 71 | -------------------------------------------------------------------------------- /tests/test_elaborated_types.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = ['test_elaborated_types.hpp'] 15 | 16 | 17 | @pytest.fixture 18 | def global_ns(): 19 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 20 | config = autoconfig.cxx_parsers_cfg.config.clone() 21 | config.castxml_epic_version = 1 22 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 23 | global_ns = declarations.get_global_namespace(decls) 24 | global_ns.init_optimizer() 25 | return global_ns 26 | 27 | 28 | def test_is_elaborated_type(global_ns): 29 | """ 30 | Test for the is_elaborated function 31 | """ 32 | 33 | for specifier in ["class", "struct", "enum", "union"]: 34 | _test_impl_yes(specifier=specifier, global_ns=global_ns) 35 | _test_impl_no(specifier=specifier, global_ns=global_ns) 36 | _test_arg_impl(specifier=specifier, global_ns=global_ns) 37 | 38 | 39 | def _test_impl_yes(specifier, global_ns): 40 | yes = global_ns.namespace(name="::elaborated_t::yes_" + specifier) 41 | for decl in yes.declarations: 42 | assert declarations.is_elaborated(decl.decl_type) is True 43 | 44 | 45 | def _test_impl_no(specifier, global_ns): 46 | no = global_ns.namespace(name="::elaborated_t::no_" + specifier) 47 | for decl in no.declarations: 48 | assert declarations.is_elaborated(decl.decl_type) is False 49 | 50 | 51 | def _test_arg_impl(specifier, global_ns): 52 | decls = global_ns.namespace( 53 | name="::elaborated_t::arguments_" + specifier) 54 | for decl in decls.declarations: 55 | # The first argument is not elaborated 56 | no = decl.arguments[0].decl_type 57 | # The second argument is always elaborated 58 | yes = decl.arguments[1].decl_type 59 | assert declarations.is_elaborated(yes) is True 60 | assert declarations.is_elaborated(no) is False 61 | -------------------------------------------------------------------------------- /tests/test_example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import os 7 | import fnmatch 8 | import subprocess 9 | 10 | 11 | def test_example(): 12 | """Runs the example in the docs directory""" 13 | 14 | env = os.environ.copy() 15 | 16 | # Get the path to current directory 17 | path = os.path.dirname(os.path.realpath(__file__)) 18 | # Set the COVERAGE_PROCESS_START env. variable. 19 | # Allows to cover files run in a subprocess 20 | # http://nedbatchelder.com/code/coverage/subprocess.html 21 | env["COVERAGE_PROCESS_START"] = path + "/../.coveragerc" 22 | 23 | # Find all the examples files 24 | file_paths = [] 25 | for root, _, filenames in os.walk(path + "/../docs/examples"): 26 | for file_path in fnmatch.filter(filenames, '*.py'): 27 | file_paths.append(os.path.join(root, file_path)) 28 | 29 | for file_path in file_paths: 30 | return_code = subprocess.call( 31 | ["python", path + "/example_tester_wrap.py", file_path], 32 | env=env) 33 | assert return_code == 0 34 | -------------------------------------------------------------------------------- /tests/test_find_noncopyable_vars.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = ['find_noncopyable_vars.hpp'] 15 | 16 | 17 | @pytest.fixture 18 | def global_ns(): 19 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 20 | config = autoconfig.cxx_parsers_cfg.config.clone() 21 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 22 | global_ns = declarations.get_global_namespace(decls) 23 | global_ns.init_optimizer() 24 | return global_ns 25 | 26 | 27 | def test_find_noncopyable_vars(global_ns): 28 | """ 29 | Test the find_noncopyable_vars function 30 | 31 | """ 32 | 33 | # The ptr1 variable in the holder struct can be copied, 34 | # but not the ptr2 variable 35 | holder = global_ns.class_("holder") 36 | nc_vars = declarations.find_noncopyable_vars(holder) 37 | assert len(nc_vars) == 1 38 | assert nc_vars[0].name == "ptr2" 39 | assert declarations.is_pointer(nc_vars[0].decl_type) is True 40 | assert declarations.is_const(nc_vars[0].decl_type) is True 41 | -------------------------------------------------------------------------------- /tests/test_free_operators.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = ['free_operators.hpp'] 15 | 16 | 17 | @pytest.fixture 18 | def global_ns(): 19 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 20 | config = autoconfig.cxx_parsers_cfg.config.clone() 21 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 22 | global_ns = declarations.get_global_namespace(decls) 23 | global_ns.init_optimizer() 24 | return global_ns 25 | 26 | 27 | def test_free_operators(global_ns): 28 | fo = global_ns.namespace('free_operators') 29 | number = fo.class_('number') 30 | rational = fo.class_('rational') 31 | for oper in fo.free_operators(): 32 | if number.name in str(oper): 33 | assert number in oper.class_types 34 | if rational.name in str(oper): 35 | assert rational in oper.class_types 36 | -------------------------------------------------------------------------------- /tests/test_function_traits.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = ['covariant_returns.hpp'] 14 | 15 | 16 | @pytest.fixture 17 | def global_ns(): 18 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 19 | config = autoconfig.cxx_parsers_cfg.config.clone() 20 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 21 | global_ns = declarations.get_global_namespace(decls) 22 | global_ns.init_optimizer() 23 | return global_ns 24 | 25 | 26 | def test_is_same_function(global_ns): 27 | d = global_ns.class_('better_algorithm_t') 28 | b = global_ns.class_('algorithm_t') 29 | 30 | df = d.member_function('f') 31 | bf = b.member_function('f') 32 | 33 | assert id(df) != id(bf) 34 | assert declarations.is_same_function(df, bf) is True 35 | -------------------------------------------------------------------------------- /tests/test_gccxml10184.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from . import autoconfig 7 | 8 | from pygccxml import parser 9 | from pygccxml import declarations 10 | 11 | code = \ 12 | """ 13 | class A { 14 | public: 15 | virtual ~A() = 0; 16 | unsigned int a : 1; 17 | unsigned int unused : 31; 18 | }; 19 | """ 20 | 21 | 22 | def test_gccxml_10184(): 23 | config = autoconfig.cxx_parsers_cfg.config.clone() 24 | decls = parser.parse_string(code, config) 25 | global_ns = declarations.get_global_namespace(decls) 26 | assert global_ns.variable('a').bits == 1 27 | assert global_ns.variable('unused').bits == 31 28 | -------------------------------------------------------------------------------- /tests/test_gccxml10185.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | code = \ 14 | """ 15 | template struct A {}; 16 | template struct A 17 | { static int size(const char[N]) { return N - 1; } }; 18 | """ 19 | 20 | 21 | def test_partial_template(): 22 | """ 23 | The purpose of this test was to check if changes to GCCXML 24 | would lead to changes in the outputted xml file (Meaning 25 | the bug was fixed). 26 | 27 | GCCXML wrongly outputted partial template specialization. 28 | CastXML does not have this bug. In this case we check if 29 | the template specialization can not be found; which is the 30 | expected/wanted behaviour. 31 | 32 | https://github.com/CastXML/CastXML/issues/20 33 | 34 | """ 35 | 36 | config = autoconfig.cxx_parsers_cfg.config.clone() 37 | decls = parser.parse_string(code, config) 38 | global_ns = declarations.get_global_namespace(decls) 39 | with pytest.raises(declarations.declaration_not_found_t): 40 | global_ns.class_('A') 41 | -------------------------------------------------------------------------------- /tests/test_has_binary_operator_traits.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = ["has_public_binary_operator_traits.hpp"] 14 | 15 | 16 | @pytest.fixture 17 | def global_ns(): 18 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 19 | config = autoconfig.cxx_parsers_cfg.config.clone() 20 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 21 | global_ns = declarations.get_global_namespace(decls) 22 | global_ns.init_optimizer() 23 | return global_ns 24 | 25 | 26 | def test_yes_equal(global_ns): 27 | yes_ns = global_ns.namespace('yesequal') 28 | for typedef in yes_ns.typedefs(): 29 | assert declarations.has_public_equal(typedef) is True 30 | 31 | 32 | def test_no_equal(global_ns): 33 | no_ns = global_ns.namespace('noequal') 34 | for typedef in no_ns.typedefs(): 35 | assert declarations.has_public_equal(typedef) is False 36 | 37 | 38 | def test_yes_less(global_ns): 39 | yes_ns = global_ns.namespace('yesless') 40 | for typedef in yes_ns.typedefs(): 41 | assert declarations.has_public_less(typedef) 42 | 43 | 44 | def test_no_less(global_ns): 45 | no_ns = global_ns.namespace('noless') 46 | for typedef in no_ns.typedefs(): 47 | assert declarations.has_public_less(typedef) is False 48 | -------------------------------------------------------------------------------- /tests/test_inline_specifier.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = ["inline_specifier.hpp"] 14 | 15 | 16 | @pytest.fixture 17 | def global_ns(): 18 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 19 | config = autoconfig.cxx_parsers_cfg.config.clone() 20 | config.cflags = "-std=c++11" 21 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 22 | global_ns = declarations.get_global_namespace(decls) 23 | global_ns.init_optimizer() 24 | return global_ns 25 | 26 | 27 | def test_inline_specifier(global_ns): 28 | inlined_funcs = global_ns.calldefs('inlined') 29 | assert len(inlined_funcs) != 0 30 | for f in inlined_funcs: 31 | assert f.has_inline is True 32 | 33 | not_inlined_funcs = global_ns.calldefs('not_inlined') 34 | assert len(not_inlined_funcs) != 0 35 | for f in not_inlined_funcs: 36 | assert f.has_inline is False 37 | -------------------------------------------------------------------------------- /tests/test_map_gcc5.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import platform 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = ["test_map_gcc5.hpp"] 14 | 15 | 16 | def test_map_gcc5(): 17 | """ 18 | The code in test_map_gcc5.hpp was breaking pygccxml. 19 | 20 | Test that case (gcc5 + castxml + c++11). 21 | 22 | See issue #45 and #55 23 | 24 | """ 25 | 26 | config = autoconfig.cxx_parsers_cfg.config.clone() 27 | if platform.system() == "Darwin": 28 | config.cflags = "-std=c++11 -Dat_quick_exit=atexit -Dquick_exit=exit" 29 | # https://fr.mathworks.com/matlabcentral/answers/2013982-clibgen-generatelibrarydefinition-error-the-global-scope-has-no-quick_exit-on-mac-m2#answer_1439856 30 | # https://github.com/jetbrains/kotlin/commit/d50f585911dedec5723213da8835707ac95e1c01 31 | else: 32 | config.cflags = "-std=c++11" 33 | 34 | decls = parser.parse(TEST_FILES, config) 35 | global_ns = declarations.get_global_namespace(decls) 36 | 37 | # This calldef is defined with gcc > 4.9 (maybe earlier, not tested) 38 | # and -std=c++11. Calling create_decl_string is failing with gcc. 39 | # With clang the calldef does not exist so the matcher 40 | # will just return an empty list, letting the test pass. 41 | # See the test_argument_without_name.py for an equivalent test, 42 | # which is not depending on the presence of the _M_clone_node 43 | # method in the stl_tree.h file. 44 | criteria = declarations.calldef_matcher(name="_M_clone_node") 45 | free_funcs = declarations.matcher.find(criteria, global_ns) 46 | for free_funcs in free_funcs: 47 | free_funcs.create_decl_string(with_defaults=False) 48 | -------------------------------------------------------------------------------- /tests/test_namespace_matcher.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from . import autoconfig 7 | 8 | from pygccxml import parser 9 | from pygccxml import declarations 10 | 11 | TEST_FILES1 = ["bit_fields.hpp"] 12 | TEST_FILES2 = ["unnamed_ns_bug.hpp"] 13 | 14 | 15 | def test_namespace_matcher_get_single(): 16 | config = autoconfig.cxx_parsers_cfg.config.clone() 17 | decls = parser.parse(TEST_FILES1, config) 18 | criteria = declarations.namespace_matcher_t(name='bit_fields') 19 | declarations.matcher.get_single(criteria, decls) 20 | assert str(criteria) == '(decl type==namespace_t) and (name==bit_fields)' 21 | 22 | 23 | def test_namespace_matcher_allow_empty(): 24 | config = autoconfig.cxx_parsers_cfg.config.clone() 25 | decls = parser.parse(TEST_FILES1, config) 26 | global_ns = declarations.get_global_namespace(decls) 27 | assert 0 == len(global_ns.namespaces('does not exist', allow_empty=True)) 28 | 29 | 30 | def test_namespace_matcher_upper(): 31 | config = autoconfig.cxx_parsers_cfg.config.clone() 32 | decls = parser.parse(TEST_FILES2, config) 33 | declarations.matcher.get_single( 34 | declarations.namespace_matcher_t(name='::'), decls) 35 | -------------------------------------------------------------------------------- /tests/test_non_copyable_classes.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = ["non_copyable_classes.hpp"] 14 | 15 | 16 | @pytest.fixture 17 | def global_ns(): 18 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 19 | config = autoconfig.cxx_parsers_cfg.config.clone() 20 | config.cflags = "-std=c++11" 21 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 22 | global_ns = declarations.get_global_namespace(decls) 23 | global_ns.init_optimizer() 24 | return global_ns 25 | 26 | 27 | def test(global_ns): 28 | """ 29 | Search for classes which can not be copied. 30 | 31 | See bug #13 32 | 33 | 1) non copyable class 34 | 2) non copyable const variable (fundamental type) 35 | 3) non copyable const variable (class type) 36 | 4) non copyable const variable (array type) 37 | 5) non copyable const variable (class type) 38 | 39 | """ 40 | 41 | main_foo_1 = global_ns.class_('MainFoo1') 42 | assert declarations.is_noncopyable(main_foo_1) is True 43 | 44 | main_foo_2 = global_ns.class_('MainFoo2') 45 | assert declarations.is_noncopyable(main_foo_2) is True 46 | 47 | main_foo_3 = global_ns.class_('MainFoo3') 48 | assert declarations.is_noncopyable(main_foo_3) is True 49 | 50 | main_foo_4 = global_ns.class_('MainFoo4') 51 | assert declarations.is_noncopyable(main_foo_4) is True 52 | 53 | main_foo_5 = global_ns.class_('MainFoo5') 54 | assert declarations.is_noncopyable(main_foo_5) is True 55 | 56 | main_foo_6 = global_ns.class_('MainFoo6') 57 | assert declarations.is_noncopyable(main_foo_6) is False 58 | -------------------------------------------------------------------------------- /tests/test_null_comparison.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from . import autoconfig 7 | 8 | from pygccxml import parser 9 | from pygccxml import declarations 10 | 11 | TEST_FILES = [ 12 | "null_comparison.hpp", 13 | ] 14 | 15 | 16 | def test_argument_null_comparison(): 17 | """ 18 | Test for None comparisons with default arguments 19 | """ 20 | 21 | config = autoconfig.cxx_parsers_cfg.config.clone() 22 | decls = parser.parse(TEST_FILES, config) 23 | global_ns = declarations.get_global_namespace(decls) 24 | 25 | ns = global_ns.namespace("ns") 26 | 27 | func = ns.free_function(name="TestFunction1") 28 | assert (func.arguments[0] > func.arguments[1]) is False 29 | 30 | func = ns.free_function(name="TestFunction2") 31 | assert (func.arguments[0] > func.arguments[1]) is False 32 | -------------------------------------------------------------------------------- /tests/test_overrides.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2020 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | import platform 8 | 9 | from . import autoconfig 10 | 11 | from pygccxml import parser 12 | from pygccxml import declarations 13 | 14 | 15 | @pytest.fixture 16 | def global_ns_fixture(): 17 | config = autoconfig.cxx_parsers_cfg.config.clone() 18 | config.castxml_epic_version = 1 19 | if platform.system() == "Darwin": 20 | config.cflags = "-std=c++11 -Dat_quick_exit=atexit -Dquick_exit=exit" 21 | # https://fr.mathworks.com/matlabcentral/answers/2013982-clibgen-generatelibrarydefinition-error-the-global-scope-has-no-quick_exit-on-mac-m2#answer_1439856 22 | # https://github.com/jetbrains/kotlin/commit/d50f585911dedec5723213da8835707ac95e1c01 23 | else: 24 | config.cflags = "-std=c++11" 25 | decls = parser.parse(["test_overrides.hpp"], config) 26 | global_ns = declarations.get_global_namespace(decls) 27 | return global_ns 28 | 29 | 30 | def test_overrides(global_ns_fixture): 31 | """ 32 | Check that the override information is populated for the 33 | simple::goodbye function. It should contain the decl for the 34 | base::goodbye function. Base::goodbye has no override so it 35 | will be none 36 | """ 37 | base = global_ns_fixture.class_("base").member_function("goodbye") 38 | override_decl = global_ns_fixture.class_("simple")\ 39 | .member_function("goodbye") 40 | 41 | assert base.overrides is None 42 | assert override_decl.overrides is not None 43 | assert override_decl.overrides == base 44 | -------------------------------------------------------------------------------- /tests/test_parser_raise.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import os 7 | import pytest 8 | 9 | from . import autoconfig 10 | 11 | from pygccxml import parser 12 | 13 | 14 | def test_raise(): 15 | config = autoconfig.cxx_parsers_cfg.config.clone() 16 | content = "abra cadabra " + os.linesep 17 | with pytest.raises(RuntimeError) as _: 18 | parser.parse_string(content, config) 19 | -------------------------------------------------------------------------------- /tests/test_plain_c.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILES = [ 14 | 'plain_c.c' 15 | ] 16 | 17 | 18 | @pytest.fixture 19 | def global_ns(): 20 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 21 | config = autoconfig.cxx_parsers_cfg.config.clone() 22 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 23 | global_ns = declarations.get_global_namespace(decls) 24 | global_ns.init_optimizer() 25 | return global_ns 26 | 27 | 28 | def test_plain_c(global_ns): 29 | global_ns.free_function('hello_sum') 30 | global_ns.free_function('hello_print') 31 | f = global_ns.free_function('do_smth') 32 | for arg in f.arguments: 33 | assert arg.decl_type.decl_string is not None 34 | -------------------------------------------------------------------------------- /tests/test_source_reader.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import platform 7 | 8 | import pytest 9 | 10 | from . import autoconfig 11 | 12 | from pygccxml import parser 13 | from pygccxml import declarations 14 | 15 | TEST_FILES = [ 16 | 'declarations_calldef.hpp' 17 | ] 18 | 19 | 20 | @pytest.fixture 21 | def global_ns(): 22 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 23 | config = autoconfig.cxx_parsers_cfg.config.clone() 24 | if platform.system() == "Darwin": 25 | config.cflags = "-Dat_quick_exit=atexit -Dquick_exit=exit" 26 | # https://fr.mathworks.com/matlabcentral/answers/2013982-clibgen-generatelibrarydefinition-error-the-global-scope-has-no-quick_exit-on-mac-m2#answer_1439856 27 | # https://github.com/jetbrains/kotlin/commit/d50f585911dedec5723213da8835707ac95e1c01 28 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 29 | global_ns = declarations.get_global_namespace(decls) 30 | global_ns.init_optimizer() 31 | return global_ns 32 | 33 | 34 | def test_compound_argument_type(global_ns): 35 | do_smth = global_ns.calldefs('do_smth') 36 | assert do_smth is not None 37 | do_smth.function_type() 38 | -------------------------------------------------------------------------------- /tests/test_start_with_declarations.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | 11 | from pygccxml import parser 12 | from pygccxml import declarations 13 | 14 | TEST_FILES = "core_ns_join_1.hpp" 15 | 16 | 17 | def __check_result(decls): 18 | E11 = declarations.find_declaration(decls, fullname='::E11') 19 | assert E11 is not None 20 | ns12 = declarations.find_declaration(decls, fullname='::ns::ns12') 21 | assert ns12 is not None 22 | E13 = declarations.find_declaration(ns12.declarations, name='E13') 23 | assert E13 is not None 24 | E14 = declarations.find_declaration(decls, name='E14') 25 | assert E14 is None 26 | 27 | 28 | def test_simple_start_with_declarations(): 29 | config = autoconfig.cxx_parsers_cfg.config.clone() 30 | config.start_with_declarations.extend(['E11', 'ns::ns12::E13']) 31 | decls = parser.parse([TEST_FILES], config) 32 | __check_result(decls) 33 | 34 | 35 | def test_project_reader_file_by_file_start_with_declarations(): 36 | config = autoconfig.cxx_parsers_cfg.config.clone() 37 | config.start_with_declarations.extend(['E11', 'ns::ns12::E13']) 38 | reader = parser.project_reader_t(config) 39 | decls = reader.read_files( 40 | [parser.file_configuration_t( 41 | TEST_FILES, config.start_with_declarations)], 42 | parser.COMPILATION_MODE.FILE_BY_FILE) 43 | __check_result(decls) 44 | 45 | 46 | def test_project_reader_all_at_once_start_with_declarations(): 47 | config = autoconfig.cxx_parsers_cfg.config.clone() 48 | config.start_with_declarations.extend(['E11', 'ns::ns12::E13']) 49 | reader = parser.project_reader_t(config) 50 | decls = reader.read_files( 51 | [parser.file_configuration_t( 52 | TEST_FILES, config.start_with_declarations)], 53 | parser.COMPILATION_MODE.ALL_AT_ONCE) 54 | __check_result(decls) 55 | -------------------------------------------------------------------------------- /tests/test_string_traits.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = [ 15 | "string_traits.hpp", 16 | ] 17 | 18 | 19 | @pytest.fixture 20 | def global_ns(): 21 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 22 | config = autoconfig.cxx_parsers_cfg.config.clone() 23 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 24 | global_ns = declarations.get_global_namespace(decls) 25 | global_ns.init_optimizer() 26 | return global_ns 27 | 28 | 29 | def validate_yes(ns, controller): 30 | for typedef in ns.typedefs(): 31 | assert controller(typedef.decl_type) is True 32 | 33 | 34 | def validate_no(ns, controller): 35 | for typedef in ns.typedefs(): 36 | assert controller(typedef.decl_type) is False 37 | 38 | 39 | def test_string(global_ns): 40 | string_traits = global_ns.namespace('string_traits') 41 | validate_yes( 42 | string_traits.namespace('yes'), 43 | declarations.is_std_string) 44 | validate_no( 45 | string_traits.namespace('no'), 46 | declarations.is_std_string) 47 | 48 | 49 | def test_wstring(global_ns): 50 | wstring_traits = global_ns.namespace('wstring_traits') 51 | validate_yes( 52 | wstring_traits.namespace('yes'), 53 | declarations.is_std_wstring) 54 | validate_no( 55 | wstring_traits.namespace('no'), 56 | declarations.is_std_wstring) 57 | -------------------------------------------------------------------------------- /tests/test_text_reader.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from . import autoconfig 7 | 8 | from pygccxml import parser 9 | from pygccxml import declarations 10 | 11 | 12 | def test_text_reader(): 13 | config = autoconfig.cxx_parsers_cfg.config.clone() 14 | 15 | fconfig = parser.file_configuration_t( 16 | data='int i;', 17 | start_with_declarations=None, 18 | content_type=parser.file_configuration_t.CONTENT_TYPE.TEXT) 19 | 20 | prj_reader = parser.project_reader_t(config) 21 | decls = prj_reader.read_files( 22 | [fconfig], 23 | compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE) 24 | 25 | var_i = declarations.find_declaration( 26 | decls, decl_type=declarations.variable_t, name='i') 27 | assert var_i is not None 28 | -------------------------------------------------------------------------------- /tests/test_type_as_exception_bug.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES = [ 15 | "type_as_exception_bug.h", 16 | ] 17 | 18 | 19 | @pytest.fixture 20 | def global_ns(): 21 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 22 | config = autoconfig.cxx_parsers_cfg.config.clone() 23 | # This test does not work with c++17 and above 24 | # See https://developers.redhat.com/articles/2021/08/06/porting-your-code-c17-gcc-11#exception_specification_changes # noqa 25 | # This test is thus excpected to use -std=c++14 forever 26 | config.cflags = "-std=c++14" 27 | decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) 28 | global_ns = declarations.get_global_namespace(decls) 29 | return global_ns 30 | 31 | 32 | def test_type_as_exception(global_ns): 33 | buggy = global_ns.member_function('buggy') 34 | expression_error = global_ns.class_('ExpressionError') 35 | assert len(buggy.exceptions) == 1 36 | err = buggy.exceptions[0] 37 | assert declarations.is_reference(err) 38 | err = declarations.remove_declarated( 39 | declarations.remove_reference(err)) 40 | assert err is expression_error 41 | -------------------------------------------------------------------------------- /tests/test_typedefs.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | from . import autoconfig 7 | 8 | from pygccxml import parser 9 | from pygccxml import declarations 10 | 11 | 12 | def test_typedefs_src_reader(): 13 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 14 | header = 'typedefs_base.hpp' 15 | config = autoconfig.cxx_parsers_cfg.config.clone() 16 | decls = parser.parse([header], config) 17 | global_ns = declarations.find_declaration( 18 | decls, 19 | decl_type=declarations.namespace_t, 20 | name='::') 21 | global_ns.init_optimizer() 22 | 23 | item_cls = global_ns.class_(name='item_t') 24 | assert item_cls is not None 25 | assert len(item_cls.aliases) == 1 26 | assert item_cls.aliases[0].name == 'Item' 27 | 28 | 29 | def test_typedefs_source_reader(): 30 | COMPILATION_MODE = parser.COMPILATION_MODE.FILE_BY_FILE 31 | config = autoconfig.cxx_parsers_cfg.config.clone() 32 | 33 | decls = parser.parse( 34 | ['typedefs1.hpp', 'typedefs2.hpp'], 35 | config, 36 | COMPILATION_MODE 37 | ) 38 | item_cls = declarations.find_declaration( 39 | decls, 40 | decl_type=declarations.class_t, 41 | name='item_t') 42 | assert item_cls is not None 43 | assert len(item_cls.aliases) == 3 44 | expected_aliases = {'Item', 'Item1', 'Item2'} 45 | real_aliases = set([typedef.name for typedef in item_cls.aliases]) 46 | assert real_aliases == expected_aliases 47 | -------------------------------------------------------------------------------- /tests/test_unnamed_enums_bug.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | 7 | from . import autoconfig 8 | 9 | from pygccxml import parser 10 | from pygccxml import declarations 11 | 12 | 13 | def test_source_reader_enums(): 14 | config = autoconfig.cxx_parsers_cfg.config.clone() 15 | reader = parser.source_reader_t(config) 16 | decls = reader.read_file("unnamed_enums_bug1.hpp") 17 | global_ns = declarations.get_global_namespace(decls) 18 | global_ns.init_optimizer() 19 | names = [] 20 | enums = global_ns.enumerations() 21 | for enum in enums: 22 | names.extend(list(enum.get_name2value_dict().keys())) 23 | assert len(names) == 4 24 | assert 'x1' in names 25 | assert 'x2' in names 26 | assert 'y1' in names 27 | assert 'y2' in names 28 | 29 | 30 | def test_project_reader_enums(): 31 | config = autoconfig.cxx_parsers_cfg.config.clone() 32 | decls = parser.parse(["unnamed_enums_bug1.hpp"], config) 33 | global_ns = declarations.get_global_namespace(decls) 34 | global_ns.init_optimizer() 35 | 36 | names = [] 37 | for enum in global_ns.enumerations(): 38 | names.extend(list(enum.get_name2value_dict().keys())) 39 | assert len(names) == 4 40 | assert 'x1' in names 41 | assert 'x2' in names 42 | assert 'y1' in names 43 | assert 'y2' in names 44 | 45 | 46 | def test_multiple_files_enums(): 47 | config = autoconfig.cxx_parsers_cfg.config.clone() 48 | decls = parser.parse( 49 | [ 50 | 'unnamed_enums_bug1.hpp', 51 | 'unnamed_enums_bug2.hpp', 52 | 'unnamed_enums_bug1.hpp' 53 | ], config 54 | ) 55 | global_ns = declarations.get_global_namespace(decls) 56 | global_ns.init_optimizer() 57 | names = [] 58 | enums = global_ns.enumerations() 59 | list(map( 60 | lambda enum: names.extend(list(enum.get_name2value_dict().keys())), 61 | enums)) 62 | assert len(names) == 6 63 | assert 'x1' in names 64 | assert 'x2' in names 65 | assert 'y1' in names 66 | assert 'y2' in names 67 | assert 'z1' in names 68 | assert 'z2' in names 69 | -------------------------------------------------------------------------------- /tests/test_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import os 7 | import warnings 8 | 9 | from pygccxml import utils 10 | 11 | 12 | def test_contains_parent_dir(): 13 | path = os.path.normpath("/mypath/folder1/folder2/folder3") 14 | dirs = [ 15 | os.path.normpath("/mypath/folder1/folder2/"), 16 | os.path.normpath("/mypath3/folder1/folder2/folder3"), 17 | os.path.normpath("home"), 18 | os.path.normpath("/test/test1/mypath")] 19 | 20 | assert utils.utils.contains_parent_dir(path, dirs) is True 21 | 22 | dirs = [os.path.normpath("/home"), os.path.normpath("/mypath/test/")] 23 | 24 | assert utils.utils.contains_parent_dir(path, dirs) is False 25 | 26 | 27 | def test_deprecation_wrapper(): 28 | """ 29 | The DeprecationWrapper is not part of the public API 30 | 31 | We still need to test it. 32 | """ 33 | 34 | a = utils.utils.DeprecationWrapper( 35 | DeprecatedClass, 36 | "DeprecatedClass", 37 | "NewClass", 38 | "1.9.0") 39 | with warnings.catch_warnings(record=True) as w: 40 | warnings.simplefilter("always") 41 | a() 42 | assert len(w) == 1 43 | assert issubclass(w[-1].category, DeprecationWarning) 44 | assert "deprecated" in str(w[-1].message) 45 | 46 | 47 | class DeprecatedClass(object): 48 | """ 49 | An empty class used for testing purposes. 50 | """ 51 | pass 52 | -------------------------------------------------------------------------------- /tests/test_variable_matcher.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import os 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | 14 | TEST_FILES1 = [ 15 | "bit_fields.hpp", 16 | ] 17 | 18 | TEST_FILES2 = [ 19 | "vector_traits.hpp", 20 | ] 21 | 22 | 23 | def test_bit_fields(): 24 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 25 | config = autoconfig.cxx_parsers_cfg.config.clone() 26 | decls = parser.parse(TEST_FILES1, config, COMPILATION_MODE) 27 | 28 | criteria = declarations.variable_matcher_t( 29 | name='x', 30 | decl_type='unsigned int') 31 | x = declarations.matcher.get_single(criteria, decls) 32 | 33 | comp_str = ( 34 | '(decl type==variable_t) and (name==x) and ' + 35 | '(value type==unsigned int)') 36 | assert str(criteria) == comp_str 37 | 38 | criteria = declarations.variable_matcher_t( 39 | name='::bit_fields::fields_t::x', 40 | decl_type=declarations.unsigned_int_t(), 41 | header_dir=os.path.dirname( 42 | x.location.file_name), 43 | header_file=x.location.file_name) 44 | 45 | x = declarations.matcher.get_single(criteria, decls) 46 | assert x is not None 47 | assert 'public' == x.access_type 48 | 49 | 50 | def test_no_defaults(): 51 | COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 52 | config = autoconfig.cxx_parsers_cfg.config.clone() 53 | decls = parser.parse(TEST_FILES2, config, COMPILATION_MODE) 54 | global_ns = declarations.get_global_namespace(decls) 55 | 56 | global_ns.decls(lambda decl: 'vector<' in decl.name) 57 | global_ns.decl('vector<_0_>') 58 | global_ns.class_('vector>') 59 | global_ns.class_('vector') 60 | global_ns.decl('vector') 61 | -------------------------------------------------------------------------------- /tests/test_warn_missing_include_dirs.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import os 7 | 8 | import pytest 9 | 10 | from pygccxml import parser 11 | from pygccxml import utils 12 | 13 | 14 | def test_config_warn(): 15 | """ 16 | Test that a missing include directory is printing a warning, 17 | not raising an error 18 | """ 19 | 20 | # Some code to parse for the example 21 | code = "int a;" 22 | 23 | # Find the location of the xml generator (castxml or gccxml) 24 | generator_path, name = utils.find_xml_generator() 25 | 26 | # Path given as include director doesn't exist 27 | config = parser.xml_generator_configuration_t( 28 | xml_generator_path=generator_path, 29 | xml_generator=name, 30 | include_paths=["doesnt/exist", os.getcwd()]) 31 | with pytest.warns(RuntimeWarning): 32 | parser.parse_string(code, config) 33 | -------------------------------------------------------------------------------- /tests/test_xml_generators.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import pytest 7 | 8 | import logging 9 | 10 | from pygccxml import utils 11 | 12 | 13 | mock_logger = logging.getLogger("Test") 14 | 15 | 16 | def test_old_xml_generators(): 17 | """ 18 | Tests for the xml_generators class. 19 | 20 | This is for gccxml and for castxml using the gccxml xml file format 21 | """ 22 | _test_impl("0.6", False, "is_gccxml_06") 23 | _test_impl("1.114", False, "is_gccxml_07") 24 | _test_impl("1.115", False, "is_gccxml_09_buggy") 25 | _test_impl("1.126", False, "is_gccxml_09_buggy") 26 | _test_impl("1.127", False, "is_gccxml_09") 27 | _test_impl("1.136", True, "is_castxml") 28 | 29 | 30 | def test_casxtml_epic_version_1(): 31 | """ 32 | Test with the castxml epic version set to 1 33 | """ 34 | gen = utils.xml_generators( 35 | mock_logger, castxml_format="1.1.0") 36 | assert gen.is_gccxml is False 37 | assert gen.is_castxml is True 38 | assert gen.is_castxml1 is True 39 | assert gen.xml_output_version == "1.1.0" 40 | 41 | with pytest.raises(RuntimeError): 42 | utils.xml_generators(mock_logger, "1.136", "1.1.0") 43 | 44 | with pytest.raises(RuntimeError): 45 | utils.xml_generators(mock_logger, None, None) 46 | 47 | 48 | def _test_impl( 49 | gccxml_cvs_revision, is_castxml, 50 | expected_gccxml_cvs_revision): 51 | """ 52 | Implementation detail for the test 53 | 54 | Args: 55 | gccxml_cvs_revision (str|None) : a known cvs revision 56 | is_castxml (bool): check for castxml 57 | expected_gccxml_cvs_revision (str): will be used to check if the 58 | attribute is set to True. 59 | """ 60 | gen = utils.xml_generators( 61 | mock_logger, gccxml_cvs_revision) 62 | if is_castxml: 63 | assert gen.is_gccxml is False 64 | assert gen.is_castxml is True 65 | else: 66 | assert gen.is_gccxml is True 67 | assert gen.is_castxml is False 68 | assert getattr(gen, expected_gccxml_cvs_revision) is True 69 | assert gen.xml_output_version == gccxml_cvs_revision 70 | -------------------------------------------------------------------------------- /tests/test_xmlfile_reader.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2017 Insight Software Consortium. 2 | # Copyright 2004-2009 Roman Yakovenko. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | import os 7 | 8 | from . import autoconfig 9 | 10 | from pygccxml import parser 11 | from pygccxml import declarations 12 | 13 | TEST_FILE = "core_types.hpp" 14 | 15 | 16 | def test_read_xml_file(): 17 | config = autoconfig.cxx_parsers_cfg.config.clone() 18 | 19 | src_reader = parser.source_reader_t(config) 20 | src_decls = src_reader.read_file(TEST_FILE) 21 | 22 | xmlfile = src_reader.create_xml_file(TEST_FILE) 23 | 24 | conf_t = parser.file_configuration_t 25 | fconfig = conf_t( 26 | data=xmlfile, 27 | start_with_declarations=None, 28 | content_type=conf_t.CONTENT_TYPE.GCCXML_GENERATED_FILE) 29 | 30 | prj_reader = parser.project_reader_t(config) 31 | prj_decls = prj_reader.read_files( 32 | [fconfig], 33 | compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE) 34 | 35 | declarations.dump_declarations( 36 | src_decls, 37 | os.path.join( 38 | autoconfig.build_directory, 39 | 'xmlfile_reader.src.txt')) 40 | declarations.dump_declarations( 41 | prj_decls, 42 | os.path.join( 43 | autoconfig.build_directory, 44 | 'xmlfile_reader.prj.txt')) 45 | 46 | assert src_decls == prj_decls 47 | -------------------------------------------------------------------------------- /tests/xml_generator.cfg: -------------------------------------------------------------------------------- 1 | [xml_generator] 2 | # Specify which xml generator you want to use "castxml" or "gccxml" 3 | # "castxml is the default" 4 | xml_generator= 5 | # Path to castxml or gccxml executable file 6 | xml_generator_path= 7 | # Set the path to the compiler (for example "/usr/bin/gcc") for CastXML 8 | compiler_path= 9 | # Gccxml working directory - optional, could be set to your source code directory 10 | working_directory= 11 | # Additional include directories, as list of paths ["path1/file1.h", "path2/file2.h", ...] 12 | include_paths= 13 | # You can explicitly set what compiler it should emulate (for GCCXML) 14 | # Valid options are: g++, msvc6, msvc7, msvc71, msvc8, cl. 15 | compiler= 16 | # Keep xml files after errors (useful for debugging) 17 | keep_xml= 18 | --------------------------------------------------------------------------------