Exemplo n.º 1
0
    def genGroup(self, groupinfo, groupName, alias=None):
        """Generate groups (e.g. C "enum" type).

        These are concatenated together with other types.

        If alias is not None, it is the name of another group type
        which aliases this type; just generate that alias."""
        OutputGenerator.genGroup(self, groupinfo, groupName, alias)
        groupElem = groupinfo.elem

        # After either enumerated type or alias paths, add the declaration
        # to the appropriate section for the group being defined.
        if groupElem.get('type') == 'bitmask':
            section = 'bitmask'
        else:
            section = 'group'

        if alias:
            # If the group name is aliased, just emit a typedef declaration
            # for the alias.
            body = 'typedef ' + alias + ' ' + groupName + ';\n'
            self.appendSection(section, body)
        else:
            if self.genOpts is None:
                raise MissingGeneratorOptionsError()
            (section,
             body) = self.buildEnumCDecl(self.genOpts.genEnumBeginEndRange,
                                         groupinfo, groupName)
            self.appendSection(section, "\n" + body)
Exemplo n.º 2
0
    def beginFile(self, genOpts):
        OutputGenerator.beginFile(self, genOpts)
        if self.genOpts is None:
            raise MissingGeneratorOptionsError()
        # C-specific
        #
        # Multiple inclusion protection & C++ wrappers.
        if self.genOpts.protectFile and self.genOpts.filename:
            headerSym = re.sub(r'\.h', '_h_',
                               os.path.basename(
                                   self.genOpts.filename)).upper()
            write('#ifndef', headerSym, file=self.outFile)
            write('#define', headerSym, '1', file=self.outFile)
            self.newline()

        # User-supplied prefix text, if any (list of strings)
        if genOpts.prefixText:
            for s in genOpts.prefixText:
                write(s, file=self.outFile)

        # C++ extern wrapper - after prefix lines so they can add includes.
        self.newline()
        write('#ifdef __cplusplus', file=self.outFile)
        write('extern "C" {', file=self.outFile)
        write('#endif', file=self.outFile)
        self.newline()
Exemplo n.º 3
0
 def endFile(self):
     # C-specific
     # Finish C++ wrapper and multiple inclusion protection
     if self.genOpts is None:
         raise MissingGeneratorOptionsError()
     self.newline()
     write('#ifdef __cplusplus', file=self.outFile)
     write('}', file=self.outFile)
     write('#endif', file=self.outFile)
     if self.genOpts.protectFile and self.genOpts.filename:
         self.newline()
         write('#endif', file=self.outFile)
     # Finish processing in superclass
     OutputGenerator.endFile(self)
Exemplo n.º 4
0
    def genCmd(self, cmdinfo, name, alias):
        "Command generation"
        OutputGenerator.genCmd(self, cmdinfo, name, alias)

        # if alias:
        #     prefix = '// ' + name + ' is an alias of command ' + alias + '\n'
        # else:
        #     prefix = ''
        if self.genOpts is None:
            raise MissingGeneratorOptionsError()

        prefix = ''
        decls = self.makeCDecls(cmdinfo.elem)
        self.appendSection('command', prefix + decls[0] + '\n')
        if self.genOpts.genFuncPointers:
            self.appendSection('commandPointer', decls[1])
Exemplo n.º 5
0
    def genType(self, typeinfo, name, alias):
        "Generate type."
        OutputGenerator.genType(self, typeinfo, name, alias)
        typeElem = typeinfo.elem

        # Vulkan:
        # Determine the category of the type, and the type section to add
        # its definition to.
        # 'funcpointer' is added to the 'struct' section as a workaround for
        # internal issue #877, since structures and function pointer types
        # can have cross-dependencies.
        category = typeElem.get('category')
        if category == 'funcpointer':
            section = 'struct'
        else:
            section = category

        if category in ('struct', 'union'):
            # If the type is a struct type, generate it using the
            # special-purpose generator.
            self.genStruct(typeinfo, name, alias)
        else:
            if self.genOpts is None:
                raise MissingGeneratorOptionsError()
            # OpenXR: this section was not under 'else:' previously, just fell through
            if alias:
                # If the type is an alias, just emit a typedef declaration
                body = 'typedef ' + alias + ' ' + name + ';\n'
            else:
                # Replace <apientry /> tags with an APIENTRY-style string
                # (from self.genOpts). Copy other text through unchanged.
                # If the resulting text is an empty string, don't emit it.
                body = noneStr(typeElem.text)
                for elem in typeElem:
                    if elem.tag == 'apientry':
                        body += self.genOpts.apientry + noneStr(elem.tail)
                    else:
                        body += noneStr(elem.text) + noneStr(elem.tail)
            if body:
                # Add extra newline after multi-line entries.
                if '\n' in body[0:-1]:
                    body += '\n'
                self.appendSection(section, body)
Exemplo n.º 6
0
 def endFeature(self):
     "Actually write the interface to the output file."
     # C-specific
     if self.emit:
         if self.feature_not_empty:
             if self.genOpts is None:
                 raise MissingGeneratorOptionsError()
             if self.genOpts.conventions is None:
                 raise MissingGeneratorOptionsConventionsError()
             is_core = self.featureName and self.featureName.startswith(
                 self.conventions.api_prefix + "VERSION_")
             if self.genOpts.conventions.writeFeature(
                     self.featureExtraProtect, self.genOpts.filename):
                 self.newline()
                 if self.genOpts.protectFeature:
                     write('#ifndef', self.featureName, file=self.outFile)
                 # If type declarations are needed by other features based on
                 # this one, it may be necessary to suppress the ExtraProtect,
                 # or move it below the 'for section...' loop.
                 if self.featureExtraProtect is not None:
                     write('#ifdef',
                           self.featureExtraProtect,
                           file=self.outFile)
                 self.newline()
                 write('#define', self.featureName, '1', file=self.outFile)
                 for section in self.TYPE_SECTIONS:
                     contents = self.sections[section]
                     if contents:
                         write('\n'.join(contents), file=self.outFile)
                 if self.genOpts.genFuncPointers and self.sections[
                         'commandPointer']:
                     write('\n'.join(self.sections['commandPointer']),
                           file=self.outFile)
                     self.newline()
                 if self.sections['command']:
                     if self.genOpts.protectProto:
                         write(self.genOpts.protectProto,
                               self.genOpts.protectProtoStr,
                               file=self.outFile)
                     if self.genOpts.protectExtensionProto and not is_core:
                         write(self.genOpts.protectExtensionProto,
                               self.genOpts.protectExtensionProtoStr,
                               file=self.outFile)
                     write('\n'.join(self.sections['command']),
                           end='',
                           file=self.outFile)
                     if self.genOpts.protectExtensionProto and not is_core:
                         write('#endif',
                               self._endProtectComment(
                                   protect_directive=self.genOpts.
                                   protectExtensionProto,
                                   protect_str=self.genOpts.
                                   protectExtensionProtoStr),
                               file=self.outFile)
                     if self.genOpts.protectProto:
                         write(
                             '#endif',
                             self._endProtectComment(
                                 protect_directive=self.genOpts.
                                 protectProto,
                                 protect_str=self.genOpts.protectProtoStr),
                             file=self.outFile)
                     else:
                         self.newline()
                 if self.featureExtraProtect is not None:
                     write('#endif',
                           self._endProtectComment(
                               protect_str=self.featureExtraProtect),
                           file=self.outFile)
                 if self.genOpts.protectFeature:
                     write('#endif',
                           self._endProtectComment(
                               protect_str=self.featureName),
                           file=self.outFile)
     # Finish processing in superclass
     OutputGenerator.endFeature(self)