Skip to content

Commit

Permalink
Revise the generation of GFlags types
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Sep 29, 2023
1 parent 0966dc3 commit d024c3d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
15 changes: 12 additions & 3 deletions build/gen_cpp_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,20 @@ def add_enum(gtype, a, b):

return ffi.NULL

# Enums
def add_flag(gtype, a, b):
nickname = type_name(gtype)
all_flags.append(nickname)

type_map(gtype, add_flag)

return ffi.NULL

type_map(type_from_name('GEnum'), add_enum)
type_map(type_from_name('GFlags'), add_flag)

# Flags
all_flags.append('VipsForeignPngFilter')
# Filter internal flags
filter_flags = ['VipsForeignFlags']
all_flags = [name for name in all_flags if name not in filter_flags]

print(f'Generating {file}...')

Expand Down
22 changes: 15 additions & 7 deletions build/gen_type_declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,21 @@ def add_enum(gtype, a, b):

return ffi.NULL

# Enums
def add_flag(gtype, a, b):
nickname = type_name(gtype)
all_nicknames.append(nickname)
gtype_to_js_param[gtype] = f'{remove_prefix(nickname)} | Flag'

type_map(gtype, add_flag)

return ffi.NULL

type_map(type_from_name('GEnum'), add_enum)
type_map(type_from_name('GFlags'), add_flag)

# Flags
all_nicknames.append('VipsForeignPngFilter')
gtype_to_js_param[type_from_name('VipsForeignPngFilter')] = f'{remove_prefix("VipsForeignPngFilter")} | Flag'
# Filter internal flags
filter = ['VipsForeignFlags']
all_nicknames = [name for name in all_nicknames if name not in filter]

with open('preamble_vips.d.ts', 'r') as f:
preamble = f.read()
Expand All @@ -261,11 +270,11 @@ def add_enum(gtype, a, b):
gtype = type_from_name(name)
name = remove_prefix(name)
if name in xml_enums:
is_enum = True
node = xml_enums[name]
values = values_for_enum(gtype)
elif name in xml_flags:
is_enum = False
node = xml_flags[name]
values = values_for_flag(gtype)
else:
continue

Expand All @@ -280,7 +289,6 @@ def add_enum(gtype, a, b):

f.write(f'{indent}enum {name} {{\n')

values = values_for_enum(gtype) if is_enum else values_for_flag(gtype)
for i, value in enumerate(values):
js_value = value.replace('-', '_')
if i == 0 and (js_value == 'error' or js_value == 'notset'):
Expand Down

0 comments on commit d024c3d

Please sign in to comment.