Skip to content

Commit fe5103b

Browse files
committed
Refactor the command/enum removal stuff a bit.
This removes the overly long and obtuse xpath strings, meaning there are some that're not in constants now, but it's a lot more specific as well. Mostly did this to make sure GL 4.4 was working right, since some commands disappeared from gl_commands.rb, but it looks like they maybe shouldn't have been there in the first place.
1 parent 8bb7976 commit fe5103b

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

gen_from_xml.rb

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@
8282

8383
SELECT_ENUMS_XPATH = 'registry/enums/enum[@name and @value and (not(@api) or not(starts-with(@api, "gles")))]'
8484
SELECT_COMMANDS_XPATH = 'registry/commands/command'
85-
SELECT_FEATURES_XPATH = 'registry/*[(self::feature or self::extension) and (not(starts-with(@api,"gles")) and not(starts-with(@supported, "gles")))]/require/*[self::command|self::enum]'
86-
SELECT_REMOVES_XPATH = 'registry/*[(self::feature or self::extension) and (not(starts-with(@api,"gles")) and not(starts-with(@supported, "gles")))]/remove[@profile="core"]/*[self::command|self::enum]'
8785
SELECT_TYPEDEFS_XPATH = 'registry/types/type[(not(@api) or not(starts-with(@api, "gles"))) and (not(@name) or not(starts-with(@name, "khr")))]'
8886
SELECT_TYPE_XPATH = 'ptype/text()|text()'
8987

@@ -147,39 +145,42 @@ def generate_binding_impl(document)
147145
gl_commands = get_commands(document)
148146
gl_enums = get_enums(document)
149147

150-
document.xpath(SELECT_FEATURES_XPATH).each {
151-
|feature|
148+
pull_feature = proc { |feature|
152149
feature_name = feature['name']
153150
feature_kind = feature.name
151+
154152
case feature_kind
155-
when 'enum'
156-
filtered_enums[feature_name] = gl_enums[feature_name]
153+
when 'enum' then filtered_enums[feature_name] = gl_enums[feature_name]
154+
when 'command' then filtered_commands[feature_name] = gl_commands[feature_name]
155+
else raise "Unrecognized feature kind"
156+
end
157+
}
157158

158-
when 'command'
159-
filtered_commands[feature_name] = gl_commands[feature_name]
159+
drop_feature = proc { |feature|
160+
feature_name = feature['name']
161+
feature_kind = feature.name
160162

161-
else
162-
Raise "Unrecognized feature kind"
163+
case feature_kind
164+
when 'enum' then filtered_enums.delete(feature_name)
165+
when 'command' then filtered_commands.delete(feature_name)
166+
else raise "Unrecognized feature kind"
163167
end
164168
}
165169

166-
if GEN_GL3_AND_UP
167-
document.xpath(SELECT_REMOVES_XPATH).each {
168-
|feature|
169-
feature_name = feature['name']
170-
feature_kind = feature.name
171-
case feature_kind
172-
when 'enum'
173-
filtered_enums.delete feature_name
174-
175-
when 'command'
176-
filtered_commands.delete feature_name
170+
extensions = document.xpath("registry/extensions/extension")
171+
core_exts = extensions.select { |ext| ext['supported'] =~ /\bglcore\b/ }
172+
core_exts.each { |ext|
173+
ext.xpath('extension/require/*[(self::command|self::enum)]').each(&pull_feature)
174+
}
177175

178-
else
179-
Raise "Unrecognized feature kind"
180-
end
181-
}
182-
end
176+
features = document.xpath('registry/feature')
177+
gl_features = features.select { |feature| feature['api'] =~ /\bgl\b/ }
178+
gl_features.each { |feature|
179+
feature.xpath('require/*[(self::command|self::enum)]').each(&pull_feature)
180+
if GEN_GL3_AND_UP
181+
feature.xpath('remove[@profile="core"]/*[(self::command|self::enum)]').each(&drop_feature)
182+
end
183+
}
183184
end
184185

185186
enum_name_length = filtered_enums.map { |k, enum| enum.name.length }.max

0 commit comments

Comments
 (0)