Beispiel #1
0
def generateStubs(cppFlag, module, excludes=[], typeValMap={}):
    """
    Generate C++ stubs for all items in the module, except those that are
    in the optional excludes list.
    """
    # First add a define for the cppFlag (like wxUSE_SOME_FEATURE) so the user
    # code has a way to check if an optional classis available before using it
    # and getting an exception.
    assert isinstance(module, extractors.ModuleDef)
    if not module.findItem(cppFlag):
        module.addItem(extractors.DefineDef(name=cppFlag, value='0'))
        excludes.append(cppFlag)

    # Copy incoming typeValMap so it can be updated with some stock types
    import copy
    typeValMap = copy.copy(typeValMap)
    typeValMap.update({
        'int': '0',
        'bool': 'false',
        'double': '0.0',
        'wxString': 'wxEmptyString',
        'const wxString &': 'wxEmptyString',
        'wxString &': 'wxEmptyString',
        'wxSize': 'wxDefaultSize',
        'wxPoint': 'wxDefaultPosition',
        'wxFileOffset': '0',
    })

    code = _StubCodeHolder(cppFlag)

    # Next add forward declarations of all classes in case they refer to
    # each other.
    for item in module:
        if isinstance(item, extractors.ClassDef):
            code.hdr.append('class {};'.format(item.name))

    # Now write code for all the items in the module.
    for item in module:
        if item.name in excludes:
            continue

        dispatchMap = {
            extractors.DefineDef: _generateDefineStub,
            extractors.GlobalVarDef: _generateGlobalStub,
            extractors.EnumDef: _generateEnumStub,
            extractors.ClassDef: _generateClassStub,
            extractors.PyCodeDef: _ignore,
        }
        func = dispatchMap.get(type(item), None)
        if func is None:
            print('WARNING: Unable to generate stub for {}, type {}'.format(
                item.name, type(item)))
        else:
            func(code, item, typeValMap)

    # Add the code to the module header
    module.addHeaderCode(code.renderHdr())
    if code.cpp:
        # and possibly the module's C++ file
        module.addCppCode(code.renderCpp())
Beispiel #2
0
def run():
    # Parse the XML file(s) building a collection of Extractor objects
    module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING, check4unittest=False)
    etgtools.parseDoxyXML(module, ITEMS)

    #-----------------------------------------------------------------
    # Tweak the parsed meta objects in the module object as needed for
    # customizing the generated code and docstrings.

    #c = module.find('')
    #assert isinstance(c, etgtools.ClassDef)

    module.addItem(etgtools.DefineDef(name='INT_MAX', value='11111'))

    #-----------------------------------------------------------------
    tools.doCommonTweaks(module)
    tools.runGenerators(module)
Beispiel #3
0
def run():
    # Parse the XML file(s) building a collection of Extractor objects
    module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING, False)
    etgtools.parseDoxyXML(module, ITEMS)

    #-----------------------------------------------------------------
    # Tweak the parsed meta objects in the module object as needed for
    # customizing the generated code and docstrings.

    c = module.find('wxWithImages')
    c.addPrivateCopyCtor()
    c.addPrivateAssignOp()

    c.find('AssignImageList.imageList').transfer = True

    module.addItem(etgtools.DefineDef(name='NO_IMAGE', value='-1'))
    module.addCppCode("#define NO_IMAGE wxWithImages::NO_IMAGE")

    #-----------------------------------------------------------------
    tools.doCommonTweaks(module)
    tools.runGenerators(module)
Beispiel #4
0
def run():
    # Parse the XML file(s) building a collection of Extractor objects
    module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING,
                                check4unittest=False)
    etgtools.parseDoxyXML(module, ITEMS)
    module.check4unittest = False
    
    #-----------------------------------------------------------------
    # Tweak the parsed meta objects in the module object as needed for
    # customizing the generated code and docstrings.
        
    # tweaks for defs.h to help SIP understand the types better
    module.find('wxInt16').type = 'short'
    module.find('wxInt64').type = 'long long'
    module.find('wxUint64').type = 'unsigned long long'
    
    # See src/wacky_ints.sip
    module.find('wxIntPtr').ignore()
    module.find('wxUIntPtr').ignore()
        
    # Correct the types for these as their values are outside the range of int
    module.find('wxUINT32_MAX').type = 'unsigned long'
    module.find('wxINT64_MIN').type = 'long long'
    module.find('wxINT64_MAX').type = 'long long'
    module.find('wxUINT64_MAX').type = 'unsigned long long'

    # Generate the code for these differently because they need to be
    # forcibly mashed into an int in the C code
    module.find('wxCANCEL_DEFAULT').forcedInt = True
    module.find('wxVSCROLL').forcedInt = True
    module.find('wxWINDOW_STYLE_MASK').forcedInt = True

    module.find('wxInt8').pyInt = True
    module.find('wxUint8').pyInt = True
    module.find('wxByte').pyInt = True
    
    module.find('wxDELETE').ignore()
    module.find('wxDELETEA').ignore()
    module.find('wxSwap').ignore()
    module.find('wxVaCopy').ignore()
    
    # Add some typedefs for basic wx types and others so the backend
    # generator knows what they are
    td = module.find('wxUIntPtr')
    module.insertItemAfter(td, etgtools.TypedefDef(type='wchar_t', name='wxUChar'))
    module.insertItemAfter(td, etgtools.TypedefDef(type='wchar_t', name='wxChar'))
    module.insertItemAfter(td, etgtools.TypedefDef(type='long', name='time_t'))
    module.insertItemAfter(td, etgtools.TypedefDef(type='long long', name='wxFileOffset'))
    module.insertItemAfter(td, etgtools.TypedefDef(type='SIP_SSIZE_T', name='ssize_t'))
    module.insertItemAfter(td, etgtools.TypedefDef(type='unsigned char', name='byte', pyInt=True))
    module.insertItemAfter(td, etgtools.TypedefDef(type='unsigned long', name='ulong'))
    

    
    # Forward declarations for classes that are referenced but not defined
    # yet. 
    # 
    # TODO: Remove these when the classes are added for real.
    # TODO: Add these classes for real :-)
    module.insertItem(0, etgtools.WigCode("""\
        // forward declarations
        class wxExecuteEnv;
        """))
    
   
    # Add some code for getting the version numbers
    module.addCppCode("""
        #include <wx/version.h>
        const int MAJOR_VERSION = wxMAJOR_VERSION;
        const int MINOR_VERSION = wxMINOR_VERSION;           
        const int RELEASE_NUMBER = wxRELEASE_NUMBER;     
        """)
    module.addItem(etgtools.WigCode("""
        const int MAJOR_VERSION;
        const int MINOR_VERSION;
        const int RELEASE_NUMBER;
        """))

    module.addPyCode("BG_STYLE_CUSTOM = BG_STYLE_PAINT")
    module.addItem(etgtools.DefineDef(name='wxADJUST_MINSIZE', value='0'))
    

    #-----------------------------------------------------------------
    tools.doCommonTweaks(module)
    tools.runGenerators(module)
Beispiel #5
0
def run():
    # Parse the XML file(s) building a collection of Extractor objects
    module = etgtools.ModuleDef(PACKAGE,
                                MODULE,
                                NAME,
                                DOCSTRING,
                                check4unittest=False)
    etgtools.parseDoxyXML(module, ITEMS)
    module.check4unittest = False

    #-----------------------------------------------------------------
    # Tweak the parsed meta objects in the module object as needed for
    # customizing the generated code and docstrings.

    # tweaks for defs.h
    module.find('wxInt16').type = 'short'
    module.find('wxInt64').type = 'long long'
    module.find('wxUint64').type = 'unsigned long long'
    module.find('wxIntPtr').type = 'long'  #'ssize_t'
    module.find('wxUIntPtr').type = 'unsigned long'  #'size_t'
    module.find('wxInt8').pyInt = True
    module.find('wxUint8').pyInt = True
    module.find('wxByte').pyInt = True

    module.find('wxDELETE').ignore()
    module.find('wxDELETEA').ignore()
    module.find('wxSwap').ignore()
    module.find('wxVaCopy').ignore()

    # Add some typedefs for basic wx types and others so the backend
    # generator knows what they are
    td = module.find('wxUIntPtr')
    module.insertItemAfter(td,
                           etgtools.TypedefDef(type='wchar_t', name='wxUChar'))
    module.insertItemAfter(td,
                           etgtools.TypedefDef(type='wchar_t', name='wxChar'))
    module.insertItemAfter(
        td, etgtools.TypedefDef(type='unsigned long', name='size_t'))
    module.insertItemAfter(td, etgtools.TypedefDef(type='long', name='time_t'))
    module.insertItemAfter(
        td, etgtools.TypedefDef(type='long long', name='wxFileOffset'))
    module.insertItemAfter(
        td, etgtools.TypedefDef(type='SIP_SSIZE_T', name='ssize_t'))
    module.insertItemAfter(
        td, etgtools.TypedefDef(type='unsigned char', name='byte', pyInt=True))

    # Forward declarations for classes that are referenced but not defined
    # yet.
    #
    # TODO: Remove these when the classes are added for real.
    # TODO: Add these classes for real :-)
    module.insertItem(
        0,
        etgtools.WigCode("""\
        // forward declarations
        class wxPalette;
        class wxExecuteEnv;
        """))

    # TBD: I've always disliked the WXK_* names. Should I rename all the items
    # in the wxKeyCode enum to be KEY_* names?

    # Add some code for getting the version numbers
    module.addCppCode("""
        #include <wx/version.h>
        const int MAJOR_VERSION = wxMAJOR_VERSION;
        const int MINOR_VERSION = wxMINOR_VERSION;           
        const int RELEASE_NUMBER = wxRELEASE_NUMBER;     
        const int SUBRELEASE_NUMBER = wxSUBRELEASE_NUMBER;
        """)
    module.addItem(
        etgtools.WigCode("""
        const int MAJOR_VERSION;
        const int MINOR_VERSION;
        const int RELEASE_NUMBER;
        const int SUBRELEASE_NUMBER;
        """))

    module.addPyCode("BG_STYLE_CUSTOM = BG_STYLE_PAINT")
    module.addItem(etgtools.DefineDef(name='wxADJUST_MINSIZE', value='0'))

    #-----------------------------------------------------------------
    tools.doCommonTweaks(module)
    tools.runGenerators(module)