mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-10 21:03:51 +01:00
Merge branch 'wip/mak/mkenums-priv-trigraph' into 'master'
mkenums: Support public/private trigraph again See merge request GNOME/glib!1870
This commit is contained in:
commit
e54cfb82f2
@ -131,17 +131,18 @@ option_lowercase_name = '' # DEPRECATED. A lower case name to use as part
|
|||||||
# uses abnormal capitalization and we can not
|
# uses abnormal capitalization and we can not
|
||||||
# guess where to put the underscores.
|
# guess where to put the underscores.
|
||||||
option_since = '' # User provided version info for the enum.
|
option_since = '' # User provided version info for the enum.
|
||||||
seenbitshift = 0 # Have we seen bitshift operators?
|
seenbitshift = 0 # Have we seen bitshift operators?
|
||||||
enum_prefix = None # Prefix for this enumeration
|
seenprivate = False # Have we seen a private option?
|
||||||
enumname = '' # Name for this enumeration
|
enum_prefix = None # Prefix for this enumeration
|
||||||
enumshort = '' # $enumname without prefix
|
enumname = '' # Name for this enumeration
|
||||||
enumname_prefix = '' # prefix of $enumname
|
enumshort = '' # $enumname without prefix
|
||||||
enumindex = 0 # Global enum counter
|
enumname_prefix = '' # prefix of $enumname
|
||||||
firstenum = 1 # Is this the first enumeration per file?
|
enumindex = 0 # Global enum counter
|
||||||
entries = [] # [ name, val ] for each entry
|
firstenum = 1 # Is this the first enumeration per file?
|
||||||
sandbox = None # sandbox for safe evaluation of expressions
|
entries = [] # [ name, val ] for each entry
|
||||||
|
sandbox = None # sandbox for safe evaluation of expressions
|
||||||
|
|
||||||
output = '' # Filename to write result into
|
output = '' # Filename to write result into
|
||||||
|
|
||||||
def parse_trigraph(opts):
|
def parse_trigraph(opts):
|
||||||
result = {}
|
result = {}
|
||||||
@ -161,7 +162,7 @@ def parse_trigraph(opts):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def parse_entries(file, file_name):
|
def parse_entries(file, file_name):
|
||||||
global entries, enumindex, enumname, seenbitshift, flags
|
global entries, enumindex, enumname, seenbitshift, seenprivate, flags
|
||||||
looking_for_name = False
|
looking_for_name = False
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -239,16 +240,33 @@ 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, options.get('nick')))
|
||||||
else:
|
else:
|
||||||
entries.append((name, value))
|
entries.append((name, value))
|
||||||
elif re.match(r's*\#', line):
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
print_warning('Failed to parse "{}" in {}'.format(line, file_name))
|
m = re.match(r'''\s*
|
||||||
|
/\*< (([^*]|\*(?!/))*) >\s*\*/
|
||||||
|
\s*$''', line, flags=re.X)
|
||||||
|
if m:
|
||||||
|
options = m.groups()[0]
|
||||||
|
if options is not None:
|
||||||
|
options = parse_trigraph(options)
|
||||||
|
if 'private' in options:
|
||||||
|
seenprivate = True
|
||||||
|
continue
|
||||||
|
if 'public' in options:
|
||||||
|
seenprivate = False
|
||||||
|
continue
|
||||||
|
if re.match(r's*\#', line):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print_warning('Failed to parse "{}" in {}'.format(line, file_name))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
help_epilog = '''Production text substitutions:
|
help_epilog = '''Production text substitutions:
|
||||||
@ -464,7 +482,7 @@ if len(fhead) > 0:
|
|||||||
write_output(prod)
|
write_output(prod)
|
||||||
|
|
||||||
def process_file(curfilename):
|
def process_file(curfilename):
|
||||||
global entries, flags, seenbitshift, enum_prefix
|
global entries, flags, seenbitshift, seenprivate, enum_prefix
|
||||||
firstenum = True
|
firstenum = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -542,6 +560,7 @@ def process_file(curfilename):
|
|||||||
break
|
break
|
||||||
|
|
||||||
seenbitshift = 0
|
seenbitshift = 0
|
||||||
|
seenprivate = False
|
||||||
entries = []
|
entries = []
|
||||||
|
|
||||||
# Now parse the entries
|
# Now parse the entries
|
||||||
|
@ -595,6 +595,61 @@ comment: {standard_bottom_comment}
|
|||||||
"0",
|
"0",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_enum_private_public(self):
|
||||||
|
"""Test private/public enums. Bug #782162."""
|
||||||
|
h_contents1 = """
|
||||||
|
typedef enum {
|
||||||
|
ENUM_VALUE_PUBLIC1,
|
||||||
|
/*< private >*/
|
||||||
|
ENUM_VALUE_PRIVATE,
|
||||||
|
} SomeEnumA
|
||||||
|
"""
|
||||||
|
|
||||||
|
h_contents2 = """
|
||||||
|
typedef enum {
|
||||||
|
/*< private >*/
|
||||||
|
ENUM_VALUE_PRIVATE,
|
||||||
|
/*< public >*/
|
||||||
|
ENUM_VALUE_PUBLIC2,
|
||||||
|
} SomeEnumB;
|
||||||
|
"""
|
||||||
|
|
||||||
|
result = self.runMkenumsWithHeader(h_contents1)
|
||||||
|
self.maxDiff = None
|
||||||
|
self.assertEqual("", result.err)
|
||||||
|
self.assertSingleEnum(
|
||||||
|
result,
|
||||||
|
"SomeEnumA",
|
||||||
|
"some_enum_a",
|
||||||
|
"SOME_ENUM_A",
|
||||||
|
"ENUM_A",
|
||||||
|
"SOME",
|
||||||
|
"",
|
||||||
|
"enum",
|
||||||
|
"Enum",
|
||||||
|
"ENUM",
|
||||||
|
"ENUM_VALUE_PUBLIC1",
|
||||||
|
"public1",
|
||||||
|
"0",
|
||||||
|
)
|
||||||
|
result = self.runMkenumsWithHeader(h_contents2)
|
||||||
|
self.assertEqual("", result.err)
|
||||||
|
self.assertSingleEnum(
|
||||||
|
result,
|
||||||
|
"SomeEnumB",
|
||||||
|
"some_enum_b",
|
||||||
|
"SOME_ENUM_B",
|
||||||
|
"ENUM_B",
|
||||||
|
"SOME",
|
||||||
|
"",
|
||||||
|
"enum",
|
||||||
|
"Enum",
|
||||||
|
"ENUM",
|
||||||
|
"ENUM_VALUE_PUBLIC2",
|
||||||
|
"public2",
|
||||||
|
"0",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestRspMkenums(TestMkenums):
|
class TestRspMkenums(TestMkenums):
|
||||||
"""Run all tests again in @rspfile mode"""
|
"""Run all tests again in @rspfile mode"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user