Пример #1
0
    def GenerateHead(self, out, filenode, releases, options):
        __pychecker__ = 'unusednames=options'

        proto = ProtoResolver()
        proto.Visit(filenode, None)

        cgen = CGen()
        gpath = GetOption('guard')
        def_guard = GetHeaderFromNode(filenode, relpath=gpath)
        def_guard = def_guard.replace(os.sep, '_').replace('.',
                                                           '_').upper() + '_'

        cright_node = filenode.GetChildren()[0]
        assert (cright_node.IsA('Copyright'))
        fileinfo = filenode.GetChildren()[1]
        assert (fileinfo.IsA('Comment'))

        out.Write('%s\n' % cgen.Copyright(cright_node))

        # Wrap the From ... modified ... comment if it would be >80 characters.
        from_text = 'From %s' % GetPathFromNode(filenode).replace(os.sep, '/')
        modified_text = 'modified %s.' % (filenode.GetProperty('DATETIME'))
        if len(from_text) + len(modified_text) < 74:
            out.Write('/* %s %s */\n\n' % (from_text, modified_text))
        else:
            out.Write('/* %s,\n *   %s\n */\n\n' % (from_text, modified_text))

        out.Write('#ifndef %s\n#define %s\n\n' % (def_guard, def_guard))
        # Generate set of includes

        deps = set()
        for release in releases:
            deps |= filenode.GetDeps(release)

        includes = set([])
        for dep in deps:
            depfile = dep.GetProperty('FILE')
            if depfile:
                includes.add(depfile)
        includes = [
            GetHeaderFromNode(include, relpath=gpath).replace(os.sep, '/')
            for include in includes
        ]
        includes.append('ppapi/c/pp_macros.h')

        # Assume we need stdint if we "include" C or C++ code
        if filenode.GetListOf('Include'):
            includes.append('ppapi/c/pp_stdint.h')

        includes = sorted(set(includes))
        cur_include = GetHeaderFromNode(filenode,
                                        relpath=gpath).replace(os.sep, '/')
        for include in includes:
            if include == cur_include: continue
            out.Write('#include "%s"\n' % include)

        # Generate Prototypes
        if proto.struct_map:
            out.Write('\n/* Struct prototypes */\n')
            for struct in proto.struct_map:
                out.Write('struct %s;\n' % struct)

        # Create a macro for the highest available release number.
        if filenode.GetProperty('NAME').endswith('pp_macros.idl'):
            releasestr = ' '.join(releases)
            if releasestr:
                release_numbers = re.findall('[\d\_]+', releasestr)
                release = re.findall('\d+', release_numbers[-1])[0]
                if release:
                    out.Write('\n#define PPAPI_RELEASE %s\n' % release)

        # Generate all interface defines
        out.Write('\n')
        for node in filenode.GetListOf('Interface'):
            idefs = ''
            macro = cgen.GetInterfaceMacro(node)
            unique = node.GetUniqueReleases(releases)

            # Skip this interface if there are no matching versions
            if not unique: continue

            for rel in unique:
                version = node.GetVersion(rel)
                name = cgen.GetInterfaceString(node, version)
                strver = str(version).replace('.', '_')
                idefs += cgen.GetDefine('%s_%s' % (macro, strver),
                                        '"%s"' % name)
            idefs += cgen.GetDefine(macro, '%s_%s' % (macro, strver)) + '\n'
            out.Write(idefs)

        # Generate the @file comment
        out.Write('%s\n' % Comment(fileinfo, prefix='*\n @file'))
Пример #2
0
    def GenerateHead(self, out, filenode, releases, options):
        __pychecker__ = 'unusednames=options'
        cgen = CGen()
        gpath = GetOption('guard')
        def_guard = GetOutFileName(filenode, relpath=gpath)
        def_guard = def_guard.replace(os.sep, '_').replace('.',
                                                           '_').upper() + '_'

        cright_node = filenode.GetChildren()[0]
        assert (cright_node.IsA('Copyright'))
        fileinfo = filenode.GetChildren()[1]
        assert (fileinfo.IsA('Comment'))

        out.Write('%s\n' % cgen.Copyright(cright_node))

        # Wrap the From ... modified ... comment if it would be >80 characters.
        from_text = 'From %s' % (filenode.GetProperty('NAME').replace(
            os.sep, '/'))
        modified_text = 'modified %s.' % (filenode.GetProperty('DATETIME'))
        if len(from_text) + len(modified_text) < 74:
            out.Write('/* %s %s */\n\n' % (from_text, modified_text))
        else:
            out.Write('/* %s,\n *   %s\n */\n\n' % (from_text, modified_text))

        out.Write('#ifndef %s\n#define %s\n\n' % (def_guard, def_guard))
        # Generate set of includes

        deps = set()
        for release in releases:
            deps |= filenode.GetDeps(release)

        includes = set([])
        for dep in deps:
            depfile = dep.GetProperty('FILE')
            if depfile:
                includes.add(depfile)
        includes = [
            GetOutFileName(include, relpath=gpath).replace(os.sep, '/')
            for include in includes
        ]
        includes.append('ppapi/c/pp_macros.h')

        # Assume we need stdint if we "include" C or C++ code
        if filenode.GetListOf('Include'):
            includes.append('ppapi/c/pp_stdint.h')

        includes = sorted(set(includes))
        cur_include = GetOutFileName(filenode,
                                     relpath=gpath).replace(os.sep, '/')
        for include in includes:
            if include == cur_include: continue
            out.Write('#include "%s"\n' % include)

        # Generate all interface defines
        out.Write('\n')
        for node in filenode.GetListOf('Interface'):
            idefs = ''
            macro = cgen.GetInterfaceMacro(node)
            unique = node.GetUniqueReleases(releases)

            # Skip this interface if there are no matching versions
            if not unique: continue

            for rel in unique:
                version = node.GetVersion(rel)
                name = cgen.GetInterfaceString(node, version)
                strver = str(version).replace('.', '_')
                idefs += cgen.GetDefine('%s_%s' % (macro, strver),
                                        '"%s"' % name)
            idefs += cgen.GetDefine(macro, '%s_%s' % (macro, strver)) + '\n'
            out.Write(idefs)

        # Generate the @file comment
        out.Write('%s\n' % Comment(fileinfo, prefix='*\n @file'))