How to use the pygccxml.utils function in pygccxml

To help you get started, we’ve selected a few pygccxml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gccxml / pygccxml / unittests / attributes_tester.py View on Github external
def test(self):

        numeric = self.global_ns.class_('numeric_t')
        do_nothing = numeric.mem_fun('do_nothing')
        arg = do_nothing.arguments[0]

        if "CastXML" in utils.xml_generator:
            if utils.xml_output_version >= 1.137:
                # This works since:
                # https://github.com/CastXML/CastXML/issues/25
                # https://github.com/CastXML/CastXML/pull/26
                # https://github.com/CastXML/CastXML/pull/27
                # The version bump to 1.137 came way later but this is the
                # only way to make sure the test is running correctly
                self.assertTrue("annotate(sealed)" == numeric.attributes)
                self.assertTrue("annotate(no throw)" == do_nothing.attributes)
                self.assertTrue("annotate(out)" == arg.attributes)
        else:
            self.assertTrue("gccxml(no throw)" == do_nothing.attributes)
            self.assertTrue("gccxml(out)" == arg.attributes)
github gccxml / pygccxml / unittests / reopen_cache_tester.py View on Github external
"""

    if "__pypy__" in sys.builtin_module_names:
        # This test is broken on travis with pypy3.3-5.2-alpha1
        # It is annoying but only the alpha version is working without
        # segfaulting, and it is quite old now. Also; this test is due for
        # removal because the utils.xml_generator mechanism is being
        # deprecated. So this test can just be skipped until it is completely
        # removed
        return

    data = autoconfig.data_directory

    # xml_generator has not been set
    if utils.xml_generator is not "":
        raise Exception

    # Try to reopen an old cache file and check if there is an exception
    # These old files do not know about the xml generator; a RuntimeError
    # should be thrown, asking to regenerate the cache file.
    c_file = os.path.join(data, 'old_cache.cache')
    error = False
    try:
        parser.file_cache_t(c_file)
    except RuntimeError:
        error = True
    if error is False:
        raise Exception

    # This cache file knows about the xml generator, and was generated
    # with CastXML. Loading the cache should set the utils.xml_generator.
github gccxml / pygccxml / pygccxml / bparsers / config.py View on Github external
def get_msvcr_path( self ):
        vss_installed = self.__get_installed_vs_dirs()
        for f in utils.files_walker( vss_installed, ["*.dll"], ):
            f_path, f_name = os.path.split( f.upper() )
            if f_name.startswith( 'MSVCR' ):
                return f
        else:
            raise RuntimeError( 'Unable to find msvcrXX.dll. Search path is: %s' % vss_installed  )
github michellab / Sire / wrapper / AutoGenerate / create_wrappers.py View on Github external
gsl_include_dirs = [ gsldir ]

    generator_path, generator_name = pygccxml.utils.find_xml_generator()

    print("Using %s from %s" % (generator_name, generator_path))

    if openmm_include_dir is not None:
        if os.path.exists("%s/OpenMM.h" % openmm_include_dir):
            print("Generating wrappers including OpenMM from %s" % openmm_include_dir)
            openmm_include_dirs = [openmm_include_dir]
        else:
            print("Cannot find %s/OpenMM.h - disabling generation of OpenMM wrappers." % openmm_include_dir)
            openmm_include_dirs = None

    if os.getenv("VERBOSE"):
        pygccxml.utils.loggers.cxx_parser.setLevel(logging.DEBUG)

    if openmm_include_dirs is None:
        #construct a module builder that will build all of the wrappers for this module
        xml_generator_config = pygccxml.parser.xml_generator_configuration_t(
                                xml_generator_path=generator_path,
                                xml_generator=generator_name,
                                compiler="gcc",
                                cflags = "-m64 -fPIC -std=c++14",
                                include_paths = sire_include_dirs + qt_include_dirs +
                                           boost_include_dirs + gsl_include_dirs,
                                define_symbols = ["GCCXML_PARSE", "__PIC__",
                                                  "SIRE_SKIP_INLINE_FUNCTIONS",
                                                  "SIREN_SKIP_INLINE_FUNCTIONS",
                                                  "SIRE_INSTANTIATE_TEMPLATES",
                                                  "SIREN_INSTANTIATE_TEMPLATES"]
                         )
github cpc / tce / tce / Python-bindings / tools / pygccxml / pygccxml / parser / source_reader.py View on Github external
for "header" file. If destination_file_path is not None, then this file
        path will be used and returned.

        @param header: path to source file, that should be parsed
        @type header: str

        @param destination: if given, will be used as target file/path for
                            GCC-XML generated file.
        @type destination: str

        @return: path to GCC-XML generated file
        """
        gccxml_file = destination
        # If file specified, remove it to start else create new file name
        if gccxml_file:
            pygccxml.utils.remove_file_no_raise( gccxml_file )
        else:
            gccxml_file = pygccxml.utils.create_temp_file_name( suffix='.xml' )
        try:
            ffname = header
            if not os.path.isabs( ffname ):
                  ffname = self.__file_full_name(header)
            command_line = self.__create_command_line( ffname, gccxml_file )
            input_, output = os.popen4( command_line )
            input_.close()
            gccxml_reports = []
            while True:
                  data = output.readline()
                  gccxml_reports.append( data )
                  if not data:
                       break
            exit_status = output.close()
github gccxml / pygccxml / docs / examples / templates / example.py View on Github external
# See http://www.boost.org/LICENSE_1_0.txt

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

import os
import sys
import warnings
warnings.simplefilter("error", Warning)
# Find out the file location within the sources tree
this_module_dir_path = os.path.abspath(
    os.path.dirname(sys.modules[__name__].__file__))

# Find out the c++ parser
generator_path, generator_name = utils.find_xml_generator()

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

# The c++ file we want to parse
filename = "example.hpp"
filename = this_module_dir_path + "/" + filename

decls = parser.parse([filename], xml_generator_config)
global_namespace = declarations.get_global_namespace(decls)
ns = global_namespace.namespace("ns")

class_t_decl = []
for d in ns.declarations:
github gccxml / pygccxml / pygccxml / bparsers / bsc / c_wrapper.py View on Github external
InitBSCQuery = _libraries['msbsc70.dll'].InitBSCQuery
InitBSCQuery.restype = BOOL
InitBSCQuery.argtypes = [QY, BOB]
BobNext = _libraries['msbsc70.dll'].BobNext
BobNext.restype = BOB
BobNext.argtypes = []
BobFrName = _libraries['msbsc70.dll'].BobFrName
BobFrName.restype = BOB
BobFrName.argtypes = [SZ]
LszNameFrBob = _libraries['msbsc70.dll'].LszNameFrBob
LszNameFrBob.restype = SZ
LszNameFrBob.argtypes = [BOB]
CLS = USHORT

class enums:
    class MBF(utils.enum):
        NIL       = 0x000
        VARS      = 0x001
        FUNCS     = 0x002
        MACROS    = 0x004
        TYPES     = 0x008
        CLASS     = 0x010
        INCL      = 0x020
        MSGMAP    = 0x040
        DIALOGID  = 0x080
        LIBRARY   = 0x100
        IMPORT    = 0x200
        TEMPLATE  = 0x400
        NAMESPACE = 0x800
        ALL       = 0xFFF

    class TYPES(utils.enum):
github gccxml / pygccxml / pygccxml / parser / declarations_cache.py View on Github external
if isinstance(config, cxx_parsers_cfg.xml_generator_configuration_t):
        sig.update(str(config.xml_generator_path).encode())
    sig.update(str(config.working_directory).encode('utf-8'))
    if isinstance(config, cxx_parsers_cfg.xml_generator_configuration_t):
        sig.update(str(config.cflags).encode('utf-8'))
    for p in config.include_paths:
        sig.update(str(p).encode('utf-8'))
    for s in config.define_symbols:
        sig.update(str(s).encode('utf-8'))
    for u in config.undefine_symbols:
        sig.update(str(u).encode('utf-8'))
    return sig.hexdigest()


class cache_base_t(object):
    logger = utils.loggers.declarations_cache

    def __init__(self):
        object.__init__(self)

    def flush(self):
        """ Flush (write out) the cache to disk if needed. """

        raise NotImplementedError()

    def update(self, source_file, configuration, declarations, included_files):
        """
        update cache entry

        :param source_file: path to the C++ source file being parsed
        :param configuration: configuration used in
               parsing :class:`xml_generator_configuration_t`
github gccxml / pygccxml / pygccxml / parser / source_reader.py View on Github external
"""
        :param configuration:
                       Instance of :class:`xml_generator_configuration_t`
                       class, that contains CastXML configuration.

        :param cache: Reference to cache object, that will be updated after a
                      file has been parsed.
        :type cache: Instance of :class:`cache_base_t` class

        :param decl_factory: Declarations factory, if not given default
                             declarations factory( :class:`decl_factory_t` )
                             will be used.

        """

        self.logger = utils.loggers.cxx_parser
        self.__search_directories = []
        self.__config = configuration
        self.__cxx_std = utils.cxx_standard(configuration.cflags)
        self.__search_directories.append(configuration.working_directory)
        self.__search_directories.extend(configuration.include_paths)
        if not cache:
            cache = declarations_cache.dummy_cache_t()
        self.__dcache = cache
        self.__config.raise_on_wrong_settings()
        self.__decl_factory = decl_factory
        if not decl_factory:
            self.__decl_factory = declarations.decl_factory_t()
        self.__xml_generator_from_xml_file = None
github gccxml / pygccxml / docs / examples / parsing-string / example.py View on Github external
# Copyright 2014-2016 Insight Software Consortium.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

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

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

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

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

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

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