def writeStrUtilImpl(api, filename):

    def makeStrUtilImpl():
        for line in indentLines([('template<> const char*\tgetTypeName<%s>\t(void) { return "%s";\t}' % (handle.name, handle.name)) for handle in api.handles if (not handle.isAlias)]):
            (yield line)
        (yield '')
        (yield ('namespace %s' % PLATFORM_TYPE_NAMESPACE))
        (yield '{')
        for line in indentLines((('std::ostream& operator<< (std::ostream& s, %s\tv) { return s << tcu::toHex(v.internal); }' % ''.join(s)) for (n, s, c) in PLATFORM_TYPES)):
            (yield line)
        (yield '}')
        for enum in api.enums:
            if enum.isAlias:
                continue
            (yield '')
            (yield ('const char* get%sName (%s value)' % (enum.name[2:], enum.name)))
            (yield '{')
            (yield '\tswitch (value)')
            (yield '\t{')
            for line in indentLines(([('\t\tcase %s:\treturn "%s";' % (n, n)) for (n, v) in enum.values] + ['\t\tdefault:\treturn DE_NULL;'])):
                (yield line)
            (yield '\t}')
            (yield '}')
        for bitfield in api.bitfields:
            if bitfield.isAlias:
                continue
            (yield '')
            (yield ('tcu::Format::Bitfield<32> get%sStr (%s value)' % (bitfield.name[2:], bitfield.name)))
            (yield '{')
            if (len(bitfield.values) > 0):
                (yield '\tstatic const tcu::Format::BitDesc s_desc[] =')
                (yield '\t{')
                for line in indentLines([('\t\ttcu::Format::BitDesc(%s,\t"%s"),' % (n, n)) for (n, v) in bitfield.values]):
                    (yield line)
                (yield '\t};')
                (yield '\treturn tcu::Format::Bitfield<32>(value, DE_ARRAY_BEGIN(s_desc), DE_ARRAY_END(s_desc));')
            else:
                (yield '\treturn tcu::Format::Bitfield<32>(value, DE_NULL, DE_NULL);')
            (yield '}')
        bitfieldTypeNames = set([bitfield.name for bitfield in api.bitfields])
        for type in api.compositeTypes:
            if (not type.isAlias):
                (yield '')
                (yield ('std::ostream& operator<< (std::ostream& s, const %s& value)' % type.name))
                (yield '{')
                (yield ('\ts << "%s = {\\n";' % type.name))
                for member in type.members:
                    memberName = member.name
                    valFmt = None
                    newLine = ''
                    if (member.getType() in bitfieldTypeNames):
                        valFmt = ('get%sStr(value.%s)' % (member.getType()[2:], member.name))
                    elif ((member.getType() == 'const char*') or (member.getType() == 'char*')):
                        valFmt = ('getCharPtrStr(value.%s)' % member.name)
                    elif (member.arraySize != ''):
                        if (member.name in ['extensionName', 'deviceName', 'layerName', 'description']):
                            valFmt = ('(const char*)value.%s' % member.name)
                        elif ((member.getType() == 'char') or (member.getType() == 'deUint8')):
                            newLine = "'\\n' << "
                            valFmt = ('tcu::formatArray(tcu::Format::HexIterator<%s>(DE_ARRAY_BEGIN(value.%s)), tcu::Format::HexIterator<%s>(DE_ARRAY_END(value.%s)))' % (member.getType(), member.name, member.getType(), member.name))
                        else:
                            if ((member.name == 'memoryTypes') or (member.name == 'memoryHeaps')):
                                endIter = ('DE_ARRAY_BEGIN(value.%s) + value.%sCount' % (member.name, member.name[:(- 1)]))
                            else:
                                endIter = ('DE_ARRAY_END(value.%s)' % member.name)
                            newLine = "'\\n' << "
                            valFmt = ('tcu::formatArray(DE_ARRAY_BEGIN(value.%s), %s)' % (member.name, endIter))
                        memberName = member.name
                    else:
                        valFmt = ('value.%s' % member.name)
                    (yield (((('\ts << "\\t%s = " << ' % memberName) + newLine) + valFmt) + " << '\\n';"))
                (yield "\ts << '}';")
                (yield '\treturn s;')
                (yield '}')
    writeInlFile(filename, INL_HEADER, makeStrUtilImpl())
def writeStrUtilImpl(api, filename):

    def makeStrUtilImpl():
        for line in indentLines([('template<> const char*\tgetTypeName<%s>\t(void) { return "%s";\t}' % (handle.name, handle.name)) for handle in api.handles if (not handle.isAlias)]):
            (yield line)
        (yield )
        (yield ('namespace %s' % PLATFORM_TYPE_NAMESPACE))
        (yield '{')
        for line in indentLines((('std::ostream& operator<< (std::ostream& s, %s\tv) { return s << tcu::toHex(v.internal); }' % .join(s)) for (n, s, c) in PLATFORM_TYPES)):
            (yield line)
        (yield '}')
        for enum in api.enums:
            if enum.isAlias:
                continue
            (yield )
            (yield ('const char* get%sName (%s value)' % (enum.name[2:], enum.name)))
            (yield '{')
            (yield '\tswitch (value)')
            (yield '\t{')
            for line in indentLines(([('\t\tcase %s:\treturn "%s";' % (n, n)) for (n, v) in enum.values] + ['\t\tdefault:\treturn DE_NULL;'])):
                (yield line)
            (yield '\t}')
            (yield '}')
        for bitfield in api.bitfields:
            if bitfield.isAlias:
                continue
            (yield )
            (yield ('tcu::Format::Bitfield<32> get%sStr (%s value)' % (bitfield.name[2:], bitfield.name)))
            (yield '{')
            if (len(bitfield.values) > 0):
                (yield '\tstatic const tcu::Format::BitDesc s_desc[] =')
                (yield '\t{')
                for line in indentLines([('\t\ttcu::Format::BitDesc(%s,\t"%s"),' % (n, n)) for (n, v) in bitfield.values]):
                    (yield line)
                (yield '\t};')
                (yield '\treturn tcu::Format::Bitfield<32>(value, DE_ARRAY_BEGIN(s_desc), DE_ARRAY_END(s_desc));')
            else:
                (yield '\treturn tcu::Format::Bitfield<32>(value, DE_NULL, DE_NULL);')
            (yield '}')
        bitfieldTypeNames = set([bitfield.name for bitfield in api.bitfields])
        for type in api.compositeTypes:
            if (not type.isAlias):
                (yield )
                (yield ('std::ostream& operator<< (std::ostream& s, const %s& value)' % type.name))
                (yield '{')
                (yield ('\ts << "%s = {\\n";' % type.name))
                for member in type.members:
                    memberName = member.name
                    valFmt = None
                    newLine = 
                    if (member.getType() in bitfieldTypeNames):
                        valFmt = ('get%sStr(value.%s)' % (member.getType()[2:], member.name))
                    elif ((member.getType() == 'const char*') or (member.getType() == 'char*')):
                        valFmt = ('getCharPtrStr(value.%s)' % member.name)
                    elif (member.arraySize != ):
                        if (member.name in ['extensionName', 'deviceName', 'layerName', 'description']):
                            valFmt = ('(const char*)value.%s' % member.name)
                        elif ((member.getType() == 'char') or (member.getType() == 'deUint8')):
                            newLine = "'\\n' << "
                            valFmt = ('tcu::formatArray(tcu::Format::HexIterator<%s>(DE_ARRAY_BEGIN(value.%s)), tcu::Format::HexIterator<%s>(DE_ARRAY_END(value.%s)))' % (member.getType(), member.name, member.getType(), member.name))
                        else:
                            if ((member.name == 'memoryTypes') or (member.name == 'memoryHeaps')):
                                endIter = ('DE_ARRAY_BEGIN(value.%s) + value.%sCount' % (member.name, member.name[:(- 1)]))
                            else:
                                endIter = ('DE_ARRAY_END(value.%s)' % member.name)
                            newLine = "'\\n' << "
                            valFmt = ('tcu::formatArray(DE_ARRAY_BEGIN(value.%s), %s)' % (member.name, endIter))
                        memberName = member.name
                    else:
                        valFmt = ('value.%s' % member.name)
                    (yield (((('\ts << "\\t%s = " << ' % memberName) + newLine) + valFmt) + " << '\\n';"))
                (yield "\ts << '}';")
                (yield '\treturn s;')
                (yield '}')
    writeInlFile(filename, INL_HEADER, makeStrUtilImpl())