glib-mkenums: evaluate private symbols too

This allows them to be referenced in other symbols value computation.

In addition, this fixes the automatically assigned value of a public
symbol that is preceded by a private one:

        typedef enum {
          /*< private >*/
          ENUM_VALUE_PRIVATE,
          /*< public >*/
          ENUM_VALUE_PUBLIC,                    <--- value is 1, not 0.
        } SomeExampleEnum;
This commit is contained in:
Patrick Monnerat 2022-11-01 15:46:13 +01:00
parent 0120cd772a
commit 96fa9752b2
2 changed files with 11 additions and 10 deletions

View File

@ -247,15 +247,12 @@ def parse_entries(file, file_name):
if flags is None and value is not None and '<<' in value: if flags is None and value is not None and '<<' in value:
seenbitshift = 1 seenbitshift = 1
if seenprivate:
continue
if options is not None: if options is not None:
options = parse_trigraph(options) options = parse_trigraph(options)
if 'skip' not in options: if 'skip' not in options:
entries.append((name, value, options.get('nick'))) entries.append((name, value, seenprivate, options.get('nick')))
else: else:
entries.append((name, value)) entries.append((name, value, seenprivate))
else: else:
m = re.match(r'''\s* m = re.match(r'''\s*
/\*< (([^*]|\*(?!/))*) >\s*\*/ /\*< (([^*]|\*(?!/))*) >\s*\*/
@ -580,7 +577,7 @@ def process_file(curfilename):
# Autogenerate a prefix # Autogenerate a prefix
if enum_prefix is None: if enum_prefix is None:
for entry in entries: for entry in entries:
if len(entry) < 3 or entry[2] is None: if not entry[2] and (len(entry) < 4 or entry[3] is None):
name = entry[0] name = entry[0]
if enum_prefix is not None: if enum_prefix is not None:
enum_prefix = os.path.commonprefix([name, enum_prefix]) enum_prefix = os.path.commonprefix([name, enum_prefix])
@ -601,10 +598,11 @@ def process_file(curfilename):
for e in entries: for e in entries:
name = e[0] name = e[0]
num = e[1] num = e[1]
if len(e) < 3 or e[2] is None: private = e[2]
if len(e) < 4 or e[3] is None:
nick = re.sub(r'^' + enum_prefix, '', name) nick = re.sub(r'^' + enum_prefix, '', name)
nick = nick.replace('_', '-').lower() nick = nick.replace('_', '-').lower()
e = (name, num, nick) e = (name, num, private, nick)
fixed_entries.append(e) fixed_entries.append(e)
entries = fixed_entries entries = fixed_entries
@ -720,7 +718,7 @@ def process_file(curfilename):
next_num = 0 next_num = 0
prod = replace_specials(prod) prod = replace_specials(prod)
for name, num, nick in entries: for name, num, private, nick in entries:
tmp_prod = prod tmp_prod = prod
if '\u0040valuenum\u0040' in prod: if '\u0040valuenum\u0040' in prod:
@ -742,6 +740,9 @@ def process_file(curfilename):
tmp_prod = tmp_prod.replace('\u0040valuenum\u0040', str(num)) tmp_prod = tmp_prod.replace('\u0040valuenum\u0040', str(num))
next_num = int(num) + 1 next_num = int(num) + 1
if private:
continue
tmp_prod = tmp_prod.replace('\u0040VALUENAME\u0040', name) tmp_prod = tmp_prod.replace('\u0040VALUENAME\u0040', name)
tmp_prod = tmp_prod.replace('\u0040valuenick\u0040', nick) tmp_prod = tmp_prod.replace('\u0040valuenick\u0040', nick)
if flags: if flags:

View File

@ -649,7 +649,7 @@ comment: {standard_bottom_comment}
"ENUM", "ENUM",
"ENUM_VALUE_PUBLIC2", "ENUM_VALUE_PUBLIC2",
"public2", "public2",
"0", "1",
) )
def test_available_in(self): def test_available_in(self):