Exemplo n.º 1
0
  def WriteHead(self, out, filenode, releases, options, meta):
    __pychecker__ = 'unusednames=options'
    cgen = CGen()

    cright_node = filenode.GetChildren()[0]
    assert(cright_node.IsA('Copyright'))
    out.Write('%s\n' % cgen.Copyright(cright_node, cpp_style=True))

    # 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' % (from_text, modified_text))

    if meta.BuiltinIncludes():
      for include in sorted(meta.BuiltinIncludes()):
        out.Write('#include <%s>\n' % include)
      out.Write('\n')

    # TODO(teravest): Don't emit includes we don't need.
    includes = ['ppapi/c/pp_errors.h',
                'ppapi/shared_impl/tracked_callback.h',
                'ppapi/thunk/enter.h',
                'ppapi/thunk/ppb_instance_api.h',
                'ppapi/thunk/resource_creation_api.h',
                'ppapi/thunk/thunk.h']
    includes.append(_GetHeaderFileName(filenode))
    for api in meta.Apis():
      includes.append('ppapi/thunk/%s.h' % api.lower())
    for i in meta.Includes():
      includes.append(i)
    for include in sorted(includes):
      out.Write('#include "%s"\n' % include)
    out.Write('\n')
    out.Write('namespace ppapi {\n')
    out.Write('namespace thunk {\n')
    out.Write('\n')
    out.Write('namespace {\n')
    out.Write('\n')
Exemplo n.º 2
0
  def WriteHead(self, out, filenode, releases, options, meta):
    __pychecker__ = 'unusednames=options'
    cgen = CGen()

    cright_node = filenode.GetChildren()[0]
    assert(cright_node.IsA('Copyright'))
    out.Write('%s\n' % cgen.Copyright(cright_node, cpp_style=True))

    from_text = 'From %s' % (
        filenode.GetProperty('NAME').replace(os.sep,'/'))
    modified_text = 'modified %s.' % (
        filenode.GetProperty('DATETIME'))
    out.Write('// %s %s\n\n' % (from_text, modified_text))

    meta.AddBuiltinInclude('stdint.h')
    if meta.BuiltinIncludes():
      for include in sorted(meta.BuiltinIncludes()):
        out.Write('#include <%s>\n' % include)
      out.Write('\n')

    # TODO(teravest): Don't emit includes we don't need.
    includes = ['ppapi/c/pp_errors.h',
                'ppapi/shared_impl/tracked_callback.h',
                'ppapi/thunk/enter.h',
                'ppapi/thunk/ppapi_thunk_export.h']
    includes.append(_GetHeaderFileName(filenode))
    for api in meta.Apis():
      includes.append('%s' % api.lower())
    for i in meta.Includes():
      includes.append(i)
    for include in sorted(includes):
      out.Write('#include "%s"\n' % include)
    out.Write('\n')
    out.Write('namespace ppapi {\n')
    out.Write('namespace thunk {\n')
    out.Write('\n')
    out.Write('namespace {\n')
    out.Write('\n')
Exemplo n.º 3
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'))
Exemplo n.º 4
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'))
Exemplo n.º 5
0
    def GenerateHead(self, out, filenode, releases, options):
        cgen = CGen()
        gpath = GetOption('guard')
        release = releases[0]
        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))
        out.Write('/* From %s modified %s. */\n\n' %
                  (filenode.GetProperty('NAME').replace(
                      os.sep, '/'), filenode.GetProperty('DATETIME')))
        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 = ''
            name = self.GetVersionString(node)
            macro = node.GetProperty('macro')
            if not macro:
                macro = self.GetMacro(node)

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

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