VirtualBox

Changeset 72973 in vbox for trunk/src/VBox/Main/idl


Ignore:
Timestamp:
Jul 8, 2018 1:23:58 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
123525
Message:

Main: Some early sketches on how to get proper C++ enums with xpidl.

Location:
trunk/src/VBox/Main/idl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/comimpl.xsl

    r60977 r72973  
    303303    <xsl:choose>
    304304      <xsl:when test="@safearray='yes'">
    305          <xsl:variable name="elemtype">
    306            <xsl:call-template name="typeIdl2Back">
    307              <xsl:with-param name="type" select="@type" />
    308              <xsl:with-param name="safearray" select="''" />
    309              <xsl:with-param name="dir" select="'in'" />
    310            </xsl:call-template>
    311          </xsl:variable>
    312          <xsl:value-of select="       '#ifdef RT_OS_WINDOWS&#10;'"/>
    313          <xsl:value-of select="concat('              SAFEARRAY *aPtr_', @name, ' = va_arg(args, SAFEARRAY *);&#10;')"/>
    314          <xsl:value-of select="concat('              com::SafeArray&lt;', $elemtype,'&gt;   aArr_', @name, '(aPtr_', @name, ');&#10;')"/>
    315          <xsl:value-of select="       '#else&#10;'"/>
    316          <xsl:value-of select="concat('              PRUint32 aArrSize_', @name, ' = va_arg(args, PRUint32);&#10;')"/>
    317          <xsl:value-of select="concat('              void*    aPtr_', @name, ' = va_arg(args, void*);&#10;')"/>
    318          <xsl:value-of select="concat('              com::SafeArray&lt;', $elemtype,'&gt;   aArr_', @name, '(aArrSize_', @name, ', (', $elemtype,'*)aPtr_', @name, ');&#10;')"/>
    319          <xsl:value-of select="       '#endif&#10;'"/>
    320          <xsl:value-of select="concat('              ',$obj, '->set_', @name, '(ComSafeArrayAsInParam(aArr_', @name, '));&#10;')"/>
     305        <xsl:variable name="elemtype">
     306          <xsl:call-template name="typeIdl2Back">
     307            <xsl:with-param name="type" select="@type" />
     308            <xsl:with-param name="safearray" select="''" />
     309            <xsl:with-param name="dir" select="'in'" />
     310          </xsl:call-template>
     311        </xsl:variable>
     312        <xsl:value-of select="       '#ifdef RT_OS_WINDOWS&#10;'"/>
     313        <xsl:value-of select="concat('              SAFEARRAY *aPtr_', @name, ' = va_arg(args, SAFEARRAY *);&#10;')"/>
     314        <xsl:value-of select="concat('              com::SafeArray&lt;', $elemtype,'&gt;   aArr_', @name, '(aPtr_', @name, ');&#10;')"/>
     315        <xsl:value-of select="       '#else&#10;'"/>
     316        <xsl:value-of select="concat('              PRUint32 aArrSize_', @name, ' = va_arg(args, PRUint32);&#10;')"/>
     317        <xsl:value-of select="concat('              void*    aPtr_', @name, ' = va_arg(args, void*);&#10;')"/>
     318        <xsl:value-of select="concat('              com::SafeArray&lt;', $elemtype,'&gt;   aArr_', @name, '(aArrSize_', @name, ', (', $elemtype,'*)aPtr_', @name, ');&#10;')"/>
     319        <xsl:value-of select="       '#endif&#10;'"/>
     320        <xsl:value-of select="concat('              ',$obj, '->set_', @name, '(ComSafeArrayAsInParam(aArr_', @name, '));&#10;')"/>
     321      </xsl:when>
     322      <xsl:when test="substring($aType, string-length($aType) - 1) = '_T'"> <!-- To avoid pedantic gcc warnings/errors. -->
     323        <xsl:value-of select="       '#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK&#10;'"/>
     324        <xsl:value-of select="concat('              ',$aTypeName, ' = (',$aType,')va_arg(args, int);&#10;')"/>
     325        <xsl:value-of select="       '#else&#10;'"/>
     326        <xsl:value-of select="concat('              ',$aTypeName, ' = va_arg(args, ',$aType,');&#10;')"/>
     327        <xsl:value-of select="       '#endif&#10;'"/>
     328        <xsl:value-of select="concat('              ',$obj, '->set_', @name, '(',$aName, ');&#10;')"/>
    321329      </xsl:when>
    322330      <xsl:otherwise>
  • trunk/src/VBox/Main/idl/xpidl.xsl

    r69379 r72973  
    2323
    2424<xsl:include href="typemap-shared.inc.xsl"/>
     25
     26
     27<!-- - - - - - - - - - - - - - - - - - - - - - -
     28   XSLT parameters
     29 - - - - - - - - - - - - - - - - - - - - - - -->
     30
     31<!-- xpidl doesn't support enums. This parameter performs certain hacks that helps
     32     us bridge the gap and get similar behaviour as msidl.
     33
     34     The https://bugzilla.mozilla.org/show_bug.cgi?id=8781 bug discusses why xpidl
     35     doesn't do enums.  It boils down to the gcc short-enum option and similar
     36     portability concerns.
     37 -->
     38<xsl:param name="g_fHackEnumsOntoCppEnums" select="'no'"/>
     39
    2540
    2641<!--
     
    701716  </xsl:for-each>
    702717  <xsl:text>};&#x0A;&#x0A;</xsl:text>
    703   <!-- -->
    704   <xsl:value-of select="concat('/* cross-platform type name for ', @name, ' */&#x0A;')"/>
    705   <xsl:text>%{C++&#x0A;</xsl:text>
    706   <xsl:value-of select="concat('#define ', @name, '_T', ' ',
    707                                'PRUint32&#x0A;')"/>
    708   <xsl:text>%}&#x0A;&#x0A;</xsl:text>
    709   <!-- -->
    710   <xsl:value-of select="concat('/* cross-platform constants for ', @name, ' */&#x0A;')"/>
    711   <xsl:text>%{C++&#x0A;</xsl:text>
    712   <xsl:for-each select="const">
    713     <xsl:value-of select="concat('#define ', ../@name, '_', @name, ' ',
    714                                  ../@name, '::', @name, '&#x0A;')"/>
    715   </xsl:for-each>
    716   <xsl:text>%}&#x0A;&#x0A;</xsl:text>
     718  <xsl:choose>
     719    <xsl:when test="$g_fHackEnumsOntoCppEnums = 'yes'">
     720      <xsl:text>
     721/* IDL typedef for enum ', @name, ' */
     722typedef PRUint32 </xsl:text><xsl:value-of select="concat(@name, '_EnumT')" /><xsl:text>;
     723
     724/* C++ enum type name for ', @name, ' */
     725%{C++
     726typedef enum </xsl:text>
     727      <xsl:value-of select="concat(@name, '_T')" />
     728      <xsl:text> {
     729</xsl:text>
     730      <xsl:for-each select="const">
     731        <xsl:value-of select="concat('    ', ../@name, '_', @name, ' = ', ../@name, '::', @name, ',&#x0A;')"/>
     732      </xsl:for-each>
     733      <xsl:value-of select="concat('    ', @name, '_32BitHack = 0x7fffffff', '&#x0A;')"/>
     734      <xsl:text>} </xsl:text><xsl:value-of select="concat(@name, '_T')"/><xsl:text>;
     735#ifdef AssertCompileSize
     736AssertCompileSize(</xsl:text><xsl:value-of select="concat(@name, '_T')"/><xsl:text>, sizeof(PRUint32));
     737#endif
     738/* Use the preprocessor to replace the IDL enum typedef with our C++ enum so it will
     739   behave just like we had real enum support in xpidl or if were using msidl. */
     740#define </xsl:text><xsl:value-of select="concat(@name, '_EnumT ', @name, '_T')" /><xsl:text>
     741#ifndef VBOX_WITH_XPCOM_CPP_ENUM_HACK
     742# define VBOX_WITH_XPCOM_CPP_ENUM_HACK 1
     743#endif
     744%}
     745
     746</xsl:text>
     747    </xsl:when>
     748
     749    <xsl:otherwise>
     750      <!-- -->
     751      <xsl:value-of select="concat('/* cross-platform type name for ', @name, ' */&#x0A;')"/>
     752      <xsl:text>%{C++&#x0A;</xsl:text>
     753      <xsl:value-of select="concat('#define ', @name, '_T', ' ',
     754                                   'PRUint32&#x0A;')"/>
     755      <xsl:text>%}&#x0A;&#x0A;</xsl:text>
     756      <!-- -->
     757      <xsl:value-of select="concat('/* cross-platform constants for ', @name, ' */&#x0A;')"/>
     758      <xsl:text>%{C++&#x0A;</xsl:text>
     759      <xsl:for-each select="const">
     760        <xsl:value-of select="concat('#define ', ../@name, '_', @name, ' ',
     761                                     ../@name, '::', @name, '&#x0A;')"/>
     762      </xsl:for-each>
     763      <xsl:text>%}&#x0A;&#x0A;</xsl:text>
     764    </xsl:otherwise>
     765  </xsl:choose>
    717766</xsl:template>
    718767
     
    902951              (ancestor::library/application/if[@target=$self_target]/enum[@name=current()])
    903952            ">
    904               <xsl:text>PRUint32</xsl:text>
     953              <xsl:choose>
     954                <xsl:when test="$g_fHackEnumsOntoCppEnums = 'yes'">
     955                  <xsl:value-of select="concat(., '_EnumT')" />
     956                </xsl:when>
     957                <xsl:otherwise>
     958                  <xsl:text>PRUint32</xsl:text>
     959                </xsl:otherwise>
     960              </xsl:choose>
    905961            </xsl:when>
    906962            <!-- custom interface types -->
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette