def parseExtensions(src, allFunctions, allCompositeTypes, allEnums, allBitfields, allHandles, allDefinitions):

    def getCoreVersion(extensionTuple):
        if (not extensionTuple[0]):
            return None
        ptrn = (('\\/\\/\\s*' + extensionTuple[0]) + '\\s+(DEVICE|INSTANCE)\\s+([0-9_]+)')
        coreVersion = re.search(ptrn, extensionTuple[1], re.I)
        if (coreVersion != None):
            return ([coreVersion.group(1)] + [int(number) for number in coreVersion.group(2).split('_')[:3]])
        return None
    splitSrc = splitByExtension(src)
    extensions = []
    functionsByName = {function.name: function for function in allFunctions}
    compositeTypesByName = {compType.name: compType for compType in allCompositeTypes}
    enumsByName = {enum.name: enum for enum in allEnums}
    bitfieldsByName = {bitfield.name: bitfield for bitfield in allBitfields}
    handlesByName = {handle.name: handle for handle in allHandles}
    definitionsByName = {definition.name: definition for definition in allDefinitions}
    for (extensionName, extensionSrc) in splitSrc:
        definitions = [Definition(type, name, parsePreprocDefinedValueOptional(extensionSrc, name)) for (name, type) in DEFINITIONS]
        definitions = [definition for definition in definitions if (definition.value != None)]
        additionalDefinitions = parseDefinitions(extensionName, extensionSrc)
        handles = parseHandles(extensionSrc)
        functions = parseFunctions(extensionSrc)
        compositeTypes = parseCompositeTypes(extensionSrc)
        rawEnums = parseEnums(extensionSrc)
        bitfieldNames = parseBitfieldNames(extensionSrc)
        enumBitfieldNames = [getBitEnumNameForBitfield(name) for name in bitfieldNames]
        enums = [enum for enum in rawEnums if (enum.name not in enumBitfieldNames)]
        extCoreVersion = getCoreVersion((extensionName, extensionSrc))
        extFunctions = [functionsByName[function.name] for function in functions]
        extCompositeTypes = [compositeTypesByName[compositeType.name] for compositeType in compositeTypes]
        extEnums = [enumsByName[enum.name] for enum in enums]
        extBitfields = [bitfieldsByName[bitfieldName] for bitfieldName in bitfieldNames]
        extHandles = [handlesByName[handle.name] for handle in handles]
        extDefinitions = [definitionsByName[definition.name] for definition in definitions]
        extensions.append(Extension(extensionName, extHandles, extEnums, extBitfields, extCompositeTypes, extFunctions, extDefinitions, additionalDefinitions, extCoreVersion))
    return extensions
def parseExtensions(src, allFunctions, allCompositeTypes, allEnums, allBitfields, allHandles, allDefinitions):

    def getCoreVersion(extensionTuple):
        if (not extensionTuple[0]):
            return None
        ptrn = (('\\/\\/\\s*' + extensionTuple[0]) + '\\s+(DEVICE|INSTANCE)\\s+([0-9_]+)')
        coreVersion = re.search(ptrn, extensionTuple[1], re.I)
        if (coreVersion != None):
            return ([coreVersion.group(1)] + [int(number) for number in coreVersion.group(2).split('_')[:3]])
        return None
    splitSrc = splitByExtension(src)
    extensions = []
    functionsByName = {function.name: function for function in allFunctions}
    compositeTypesByName = {compType.name: compType for compType in allCompositeTypes}
    enumsByName = {enum.name: enum for enum in allEnums}
    bitfieldsByName = {bitfield.name: bitfield for bitfield in allBitfields}
    handlesByName = {handle.name: handle for handle in allHandles}
    definitionsByName = {definition.name: definition for definition in allDefinitions}
    for (extensionName, extensionSrc) in splitSrc:
        definitions = [Definition(type, name, parsePreprocDefinedValueOptional(extensionSrc, name)) for (name, type) in DEFINITIONS]
        definitions = [definition for definition in definitions if (definition.value != None)]
        additionalDefinitions = parseDefinitions(extensionName, extensionSrc)
        handles = parseHandles(extensionSrc)
        functions = parseFunctions(extensionSrc)
        compositeTypes = parseCompositeTypes(extensionSrc)
        rawEnums = parseEnums(extensionSrc)
        bitfieldNames = parseBitfieldNames(extensionSrc)
        enumBitfieldNames = [getBitEnumNameForBitfield(name) for name in bitfieldNames]
        enums = [enum for enum in rawEnums if (enum.name not in enumBitfieldNames)]
        extCoreVersion = getCoreVersion((extensionName, extensionSrc))
        extFunctions = [functionsByName[function.name] for function in functions]
        extCompositeTypes = [compositeTypesByName[compositeType.name] for compositeType in compositeTypes]
        extEnums = [enumsByName[enum.name] for enum in enums]
        extBitfields = [bitfieldsByName[bitfieldName] for bitfieldName in bitfieldNames]
        extHandles = [handlesByName[handle.name] for handle in handles]
        extDefinitions = [definitionsByName[definition.name] for definition in definitions]
        extensions.append(Extension(extensionName, extHandles, extEnums, extBitfields, extCompositeTypes, extFunctions, extDefinitions, additionalDefinitions, extCoreVersion))
    return extensions