Bug 27204 - Codegen erroneously uses enums' value-prefix as the name for the C++ enum
Summary: Codegen erroneously uses enums' value-prefix as the name for the C++ enum
Status: RESOLVED FIXED
Alias: None
Product: Telepathy
Classification: Unclassified
Component: tp-qt (show other bugs)
Version: git master
Hardware: Other All
: medium normal
Assignee: Telepathy bugs list
QA Contact: Telepathy bugs list
URL:
Whiteboard: [api break]
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-19 12:08 UTC by Will Thompson
Modified: 2010-11-16 07:01 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Will Thompson 2010-03-19 12:08:47 UTC
So, I'm designing types to represent affiliations to PubSub nodes. This is what I want in half-C++-half-DBus:

struct Affiliation {
  QString jid;
  AffiliationType affiliation;
};

enum AffiliationType {
  AffiliationOwner,
  AffiliationPublisher,
  AffiliationPublishOnly,
  ...
};

So I wrote this spec. XML:

    <tp:struct name="Affiliation">
      <tp:member name="JID" type="s"/>
      <tp:member name="Type" type="u" tp:type="Affiliation_Type"/>
    </tp:struct>

    <tp:enum name="Affiliation_Type"
             type="u"
             value-prefix="Affiliation">
      <tp:enumvalue suffix="Owner" value="0"/>
      <tp:enumvalue suffix="Publisher" value="1"/>
      <tp:enumvalue suffix="Publish_Only" value="2"/>
      <!-- ... -->
    </tp:enum>

and was horrified to discover that the code generator named the C++ enum 'Affiliation', which of course collides with the name of the struct.

This turns out to be because tpqt4-constants-gen.py does this:

    def do_enum(self, enum):
        singular = enum.getAttribute('singular') or \
                   enum.getAttribute('value-prefix') or \
                   enum.getAttribute('name')

I'm pretty sure that the use of value-prefix here shouldn't be there, given that the whole point of it is to be able to use a different prefix for values than the name of the type. Sadly we can't fix this without breaking the tp-qt4 API, so I guess I'm about to become the first person to use this newly-discovered 'singular' attribute.
Comment 1 Will Thompson 2010-03-19 12:14:15 UTC
The corresponding tp-glib codegen (which looks remarkably similar) does something more like what I would have expected, separating the name from the value prefix:

    def do_enum(self, enum):
        name = enum.getAttribute('singular') or enum.getAttribute('name')
        value_prefix = enum.getAttribute('singular') or \
                       enum.getAttribute('value-prefix') or \
                       enum.getAttribute('name')
        name_plural = enum.getAttribute('plural') or \
                      enum.getAttribute('name') + 's'
Comment 2 Olli Salli 2010-11-16 07:01:09 UTC
Fix merged to master. Will be in 0.5.0.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.