mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-31 21:34:12 +02:00
glib-mkenums: allow optional 'since' tag
The glib-mkenums program allows generating code to handle enums/flags with very different purposes. One of its purposes could be generating per-enum/flag methods to be exposed in a library API, and while doing that, it would be nice to have a way to specify in which API version the enum/flag was introduced, so that the same version could be shown in the generated API methods. E.g. From the following code: /** * QmiWmsMessageProtocol: * @QMI_WMS_MESSAGE_PROTOCOL_CDMA: CDMA. * @QMI_WMS_MESSAGE_PROTOCOL_WCDMA: WCDMA. * * Type of message protocol. * * Since: 1.0 */ typedef enum { /*< since=1.0 >*/ QMI_WMS_MESSAGE_PROTOCOL_CDMA = 0x00, QMI_WMS_MESSAGE_PROTOCOL_WCDMA = 0x01 } QmiWmsMessageProtocol; The template would allow us to generate a method documented like this, including the Since tag with the value given in the mkenums 'since' tag. /** * qmi_wms_message_protocol_get_string: * @val: a QmiWmsMessageProtocol. * * Gets the nickname string for the #QmiWmsMessageProtocol specified at @val. * * Returns: (transfer none): a string with the nickname, or %NULL if not found. Do not free the returned value. * Since: 1.0 */ const gchar *qmi_wms_message_protocol_get_string (QmiWmsMessageProtocol val); Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
This commit is contained in:
@@ -130,6 +130,7 @@ option_lowercase_name = '' # DEPRECATED. A lower case name to use as part
|
||||
# one that we guess. For instance, when an enum
|
||||
# uses abnormal capitalization and we can not
|
||||
# guess where to put the underscores.
|
||||
option_since = '' # User provided version info for the enum.
|
||||
seenbitshift = 0 # Have we seen bitshift operators?
|
||||
enum_prefix = None # Prefix for this enumeration
|
||||
enumname = '' # Name for this enumeration
|
||||
@@ -256,6 +257,7 @@ help_epilog = '''Production text substitutions:
|
||||
\u0040ENUMNAME\u0040 PREFIX_THE_XENUM
|
||||
\u0040ENUMSHORT\u0040 THE_XENUM
|
||||
\u0040ENUMPREFIX\u0040 PREFIX
|
||||
\u0040enumsince\u0040 the user-provided since value given
|
||||
\u0040VALUENAME\u0040 PREFIX_THE_XVALUE
|
||||
\u0040valuenick\u0040 the-xvalue
|
||||
\u0040valuenum\u0040 the integer value (limited support, Since: 2.26)
|
||||
@@ -515,11 +517,13 @@ def process_file(curfilename):
|
||||
flags = int(flags)
|
||||
option_lowercase_name = options.get('lowercase_name', None)
|
||||
option_underscore_name = options.get('underscore_name', None)
|
||||
option_since = options.get('since', None)
|
||||
else:
|
||||
enum_prefix = None
|
||||
flags = None
|
||||
option_lowercase_name = None
|
||||
option_underscore_name = None
|
||||
option_since = None
|
||||
|
||||
if option_lowercase_name is not None:
|
||||
if option_underscore_name is not None:
|
||||
@@ -620,6 +624,11 @@ def process_file(curfilename):
|
||||
enumlong = enumname_prefix + "_" + enumshort
|
||||
enumsym = enumlong.lower()
|
||||
|
||||
if option_since is not None:
|
||||
enumsince = option_since
|
||||
else:
|
||||
enumsince = ""
|
||||
|
||||
if firstenum:
|
||||
firstenum = False
|
||||
|
||||
@@ -641,6 +650,7 @@ def process_file(curfilename):
|
||||
prod = prod.replace('\u0040ENUMSHORT\u0040', enumshort)
|
||||
prod = prod.replace('\u0040ENUMNAME\u0040', enumlong)
|
||||
prod = prod.replace('\u0040ENUMPREFIX\u0040', enumname_prefix)
|
||||
prod = prod.replace('\u0040enumsince\u0040', enumsince)
|
||||
if flags:
|
||||
prod = prod.replace('\u0040type\u0040', 'flags')
|
||||
else:
|
||||
@@ -663,6 +673,7 @@ def process_file(curfilename):
|
||||
prod = prod.replace('\u0040ENUMSHORT\u0040', enumshort)
|
||||
prod = prod.replace('\u0040ENUMNAME\u0040', enumlong)
|
||||
prod = prod.replace('\u0040ENUMPREFIX\u0040', enumname_prefix)
|
||||
prod = prod.replace('\u0040enumsince\u0040', enumsince)
|
||||
if flags:
|
||||
prod = prod.replace('\u0040type\u0040', 'flags')
|
||||
else:
|
||||
@@ -729,6 +740,7 @@ def process_file(curfilename):
|
||||
prod = prod.replace('\u0040ENUMSHORT\u0040', enumshort)
|
||||
prod = prod.replace('\u0040ENUMNAME\u0040', enumlong)
|
||||
prod = prod.replace('\u0040ENUMPREFIX\u0040', enumname_prefix)
|
||||
prod = prod.replace('\u0040enumsince\u0040', enumsince)
|
||||
if flags:
|
||||
prod = prod.replace('\u0040type\u0040', 'flags')
|
||||
else:
|
||||
|
Reference in New Issue
Block a user