def __parse_declarations( self, files, gccxml_config, compilation_mode, cache, indexing_suite_version ):
        if None is gccxml_config:
            gccxml_config = parser.gccxml_configuration_t()
        if None is compilation_mode:
            compilation_mode = parser.COMPILATION_MODE.FILE_BY_FILE
        start_time = time.clock()
        self.logger.debug( 'parsing files - started' )
        reader = parser.project_reader_t( gccxml_config, cache, decl_wrappers.dwfactory_t() )
        decls = reader.read_files( files, compilation_mode )

        self.logger.debug( 'parsing files - done( %f seconds )' % ( time.clock() - start_time ) )
        self.logger.debug( 'settings declarations defaults - started' )

        global_ns = decls_package.matcher.get_single(
                decls_package.namespace_matcher_t( name='::' )
                , decls )
        if indexing_suite_version != 1:
            for cls in global_ns.classes():
                cls.indexing_suite_version = indexing_suite_version
            for cls in global_ns.decls(decl_type=decls_package.class_declaration_t):
                cls.indexing_suite_version = indexing_suite_version

        start_time = time.clock()
        self.__apply_decls_defaults(decls)
        self.logger.debug( 'settings declarations defaults - done( %f seconds )'
                           % ( time.clock() - start_time ) )
        return global_ns
Ejemplo n.º 2
0
    def __parse_declarations( self, files, gccxml_config, compilation_mode=None, cache=None ):
        if None is gccxml_config:
            gccxml_config = parser.gccxml_configuration_t()
        if None is compilation_mode:
            compilation_mode = parser.COMPILATION_MODE.FILE_BY_FILE
        start_time = time.clock()
        self.logger.debug( 'parsing files - started' )
        reader = parser.project_reader_t( gccxml_config, cache, decl_wrappers.dwfactory_t() )
        decls = reader.read_files( files, compilation_mode )

        self.logger.debug( 'parsing files - done( %f seconds )' % ( time.clock() - start_time ) )

        return decls_package.matcher.get_single( decls_package.namespace_matcher_t( name='::' )
                                                 , decls )
    def __parse_declarations(self,
                             files,
                             gccxml_config,
                             compilation_mode=None,
                             cache=None):
        if None is gccxml_config:
            gccxml_config = parser.gccxml_configuration_t()
        if None is compilation_mode:
            compilation_mode = parser.COMPILATION_MODE.FILE_BY_FILE
        start_time = time.clock()
        self.logger.debug('parsing files - started')
        reader = parser.project_reader_t(gccxml_config, cache,
                                         decl_wrappers.dwfactory_t())
        decls = reader.read_files(files, compilation_mode)

        self.logger.debug('parsing files - done( %f seconds )' %
                          (time.clock() - start_time))

        return decls_package.matcher.get_single(
            decls_package.namespace_matcher_t(name='::'), decls)
    def __init__( self
                  , files
                  , gccxml_path=''
                  , working_directory='.'
                  , include_paths=None
                  , define_symbols=None
                  , undefine_symbols=None
                  , start_with_declarations=None
                  , compilation_mode=None
                  , cache=None
                  , optimize_queries=True
                  , ignore_gccxml_output=False
                  , indexing_suite_version=1
                  , cflags=""
                  , encoding='ascii'
                  , compiler=None
                  , gccxml_config=None):
        """
        :param files: list of files, declarations from them you want to export
        :type files: list of strings or :class:`parser.file_configuration_t` instances

        :param gccxml_path: path to gccxml binary. If you don't pass this argument,
                            pygccxml parser will try to locate it using you environment PATH variable
        :type gccxml_path: str

        :param include_paths: additional header files location. You don't have to
                              specify system and standard directories.
        :type include_paths: list of strings

        :param define_symbols: list of symbols to be defined for preprocessor.
        :param define_symbols: list of strings

        :param undefine_symbols: list of symbols to be undefined for preprocessor.
        :param undefine_symbols: list of strings

        :param cflags: Raw string to be added to gccxml command line.

        :param gccxml_config: instance of pygccxml.parser.gccxml_configuration_t class, holds
                              gccxml( compiler ) configuration. You can use this
                              argument instead of passing the compiler configuration separately.
        """
        module_builder.module_builder_t.__init__( self, global_ns=None, encoding=encoding )

        if not gccxml_config:
            gccxml_config = parser.gccxml_configuration_t( gccxml_path=gccxml_path
                                             , working_directory=working_directory
                                             , include_paths=include_paths
                                             , define_symbols=define_symbols
                                             , undefine_symbols=undefine_symbols
                                             , start_with_declarations=start_with_declarations
                                             , ignore_gccxml_output=ignore_gccxml_output
                                             , cflags=cflags
                                             , compiler=compiler)

        #may be in future I will add those directories to user_defined_directories to self.__code_creator.
        self.__parsed_files = list(map( pygccxml_utils.normalize_path
                                   , parser.project_reader_t.get_os_file_names( files ) ))
        tmp = [os.path.split( file_ )[0] for file_ in self.__parsed_files]
        self.__parsed_dirs = [_f for _f in tmp if _f]

        self.global_ns = self.__parse_declarations( files
                                                    , gccxml_config
                                                    , compilation_mode
                                                    , cache
                                                    , indexing_suite_version)
        self.global_ns.decls(recursive=True, allow_empty=True)._code_generator = decl_wrappers.CODE_GENERATOR_TYPES.CTYPES

        self.__code_creator = None
        if optimize_queries:
            self.run_query_optimizer()

        self.__declarations_code_head = []
        self.__declarations_code_tail = []

        self.__registrations_code_head = []
        self.__registrations_code_tail = []
Ejemplo n.º 5
0
import os
import sys

import project_env

from pygccxml import utils
from pygccxml import parser
from pygccxml import declarations
from pyplusplus.module_builder import ctypes_module_builder_t

gccxml_cfg = parser.gccxml_configuration_t(
    gccxml_path=project_env.settings.gccxml_path)

mb = ctypes_module_builder_t([project_env.gmp.header_file],
                             project_env.gmp.symbols_file, gccxml_cfg)

#there is a bug in the code generator
has_varargs = lambda f: f.arguments \
                        and isinstance( f.arguments[-1].type, declarations.ellipsis_t )

mb.calldefs(has_varargs).exclude()

#gmp uses strange convention: every function name starts with __gmp and than, it
#introduces define, which aliass __gmpy to gmpy
for f in mb.calldefs(lambda x: x.name.startswith('__gmp')):
    f.alias = f.name[2:]

for v in mb.vars(lambda x: x.name.startswith('__gmp')):
    v.alias = v.name[2:]

#those structs are private implementation of FILE
Ejemplo n.º 6
0
 def __init__(self, filename):
     self.filename = filename
     self.ns = parser.parse([filename], parser.gccxml_configuration_t())[0]
Ejemplo n.º 7
0
import os
import sys

import project_env

from pygccxml import utils
from pygccxml import parser
from pygccxml import declarations
from pyplusplus.module_builder import ctypes_module_builder_t

gccxml_cfg = parser.gccxml_configuration_t(
    gccxml_path=project_env.settings.gccxml_path,
    include_paths=project_env.libmemcached.include_paths)

mb = ctypes_module_builder_t([project_env.libmemcached.header_file],
                             project_env.libmemcached.symbols_file, gccxml_cfg)

#there is a bug in the code generator
has_varargs = lambda f: f.arguments \
                        and isinstance( f.arguments[-1].type, declarations.ellipsis_t )

mb.calldefs(has_varargs).exclude()

#libmemcached uses strange convention: every function name starts with __gmp and than, it
#introduces define, which aliass __gmpy to gmpy
#for f in mb.calldefs( lambda x: x.name.startswith('__gmp') ):
#    f.alias = f.name[2:]

#for v in mb.vars( lambda x: x.name.startswith( '__gmp' ) ):
#    v.alias = v.name[2:]
Ejemplo n.º 8
0
import os
import sys

import project_env

from pygccxml import utils
from pygccxml import parser
from pygccxml import declarations
from pyplusplus.module_builder import ctypes_module_builder_t


gccxml_cfg = parser.gccxml_configuration_t( gccxml_path=project_env.settings.gccxml_path
                                            , include_paths=project_env.libmemcached.include_paths)

mb = ctypes_module_builder_t( [project_env.libmemcached.header_file]
                              , project_env.libmemcached.symbols_file, gccxml_cfg )

#there is a bug in the code generator
has_varargs = lambda f: f.arguments \
                        and isinstance( f.arguments[-1].type, declarations.ellipsis_t )

mb.calldefs( has_varargs ).exclude()

#libmemcached uses strange convention: every function name starts with __gmp and than, it
#introduces define, which aliass __gmpy to gmpy
#for f in mb.calldefs( lambda x: x.name.startswith('__gmp') ):
#    f.alias = f.name[2:]

#for v in mb.vars( lambda x: x.name.startswith( '__gmp' ) ):
#    v.alias = v.name[2:]
Ejemplo n.º 9
0
import os
import sys

import project_env

from pygccxml import utils
from pygccxml import parser
from pygccxml import declarations
from pyplusplus.module_builder import ctypes_module_builder_t


gccxml_cfg = parser.gccxml_configuration_t( gccxml_path=project_env.settings.gccxml_path )

mb = ctypes_module_builder_t( [project_env.gmp.header_file], project_env.gmp.symbols_file, gccxml_cfg )

#there is a bug in the code generator
has_varargs = lambda f: f.arguments \
                        and isinstance( f.arguments[-1].type, declarations.ellipsis_t )

mb.calldefs( has_varargs ).exclude()

#gmp uses strange convention: every function name starts with __gmp and than, it
#introduces define, which aliass __gmpy to gmpy
for f in mb.calldefs( lambda x: x.name.startswith('__gmp') ):
    f.alias = f.name[2:]

for v in mb.vars( lambda x: x.name.startswith( '__gmp' ) ):
    v.alias = v.name[2:]

#those structs are private implementation of FILE
mb.class_( '_IO_FILE' ).opaque = True
Ejemplo n.º 10
0
# 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 gccxml location
gccxml_09_path = os.path.join(
    this_module_dir_path, '..', '..', '..',
    'gccxml_bin', 'v09', sys.platform, 'bin')
# Add pygccxml package to Python path
sys.path.append(os.path.join(this_module_dir_path, '..', '..'))


from pygccxml import parser
from pygccxml import declarations

# Configure GCC-XML parser
config = parser.gccxml_configuration_t(
    gccxml_path=gccxml_09_path, compiler='gcc')

# Parsing source file
decls = parser.parse([this_module_dir_path + '/example.hpp'], config)
global_ns = declarations.get_global_namespace(decls)

# Get object that describes unittests namespace
unittests = global_ns.namespace('unittests')

print('"unittests" declarations: \n')
declarations.print_declarations(unittests)

# Print all base and derived class names
for class_ in unittests.classes():
    print('class "%s" hierarchy information:' % class_.name)
    print('\tbase classes   : ', repr([