Skip to content

Commit 4131dae

Browse files
committed
Sort generated declarations
This should make it easier to review changes in generated code between versions.
1 parent 3bf3932 commit 4131dae

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

tracing-generator.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def getWrappedCommands(self):
163163
handwritten = ["xrGetInstanceProcAddr", "xrCreateInstance"]
164164
skip = handwritten + self.no_trampoline_or_terminator
165165
all = self.core_commands + self.ext_commands
166+
all.sort(key=lambda command: command.name)
166167
return [command for command in all if command.name not in skip]
167168

168169
def outputGeneratedAuthorNote(self):
@@ -171,19 +172,19 @@ def outputGeneratedAuthorNote(self):
171172

172173
class MacroOutputGenerator(BoilerplateOutputGenerator):
173174
def genPlatformTypeMacros(self):
174-
names = {
175+
names = [
175176
"float",
176-
"int8_t",
177-
"uint8_t",
178177
"int16_t",
179-
"uint16_t",
180178
"int32_t",
181-
"uint32_t",
182179
"int64_t",
183-
"uint64_t",
180+
"int8_t",
184181
"size_t",
182+
"uint16_t",
183+
"uint32_t",
184+
"uint64_t",
185+
"uint8_t",
185186
"uintptr_t",
186-
}
187+
]
187188
macros = []
188189
for name in names:
189190
macros.append(
@@ -207,9 +208,9 @@ def genBaseTypeMacros(self):
207208
handwritten = {"XrAction", "XrActionSet", "XrSpace"}
208209

209210
ret = ""
210-
for xr_type in self.api_base_types:
211+
for xr_type in sorted(self.api_base_types, key=lambda xr_type: xr_type.name):
211212
ret += self.genBaseTypeMacro(xr_type) + "\n"
212-
for xr_type in self.api_handles:
213+
for xr_type in sorted(self.api_handles, key=lambda xr_type: xr_type.name):
213214
macro = (
214215
f"#define OXRTL_ARGS_{xr_type.name}(oxrtlIt, name) OXRTL_ARGS_HANDLE(oxrtlIt, name)"
215216
+ "\n"
@@ -218,13 +219,15 @@ def genBaseTypeMacros(self):
218219
ret += "// EXCLUDED - HANDWRITTEN:\n// " + macro
219220
else:
220221
ret += macro
221-
for xr_type in self.api_flags:
222+
for xr_type in sorted(self.api_flags, key=lambda xr_type: xr_type.name):
222223
ret += (
223224
f"#define OXRTL_ARGS_{xr_type.name}(oxrtlIt, name) OXRTL_ARGS_{xr_type.type}(oxrtlIt, name)"
224225
+ "\n"
225226
)
226227

227-
for xr_type in self.api_base_types + self.api_handles:
228+
for xr_type in sorted(
229+
self.api_base_types + self.api_handles, key=lambda xr_type: xr_type.name
230+
):
228231
ret += (
229232
f"""
230233
#define OXRTL_DUMP_{xr_type.name}(oxrtlActivity, oxrtlName, oxrtlValueName, oxrtlIt)
@@ -251,7 +254,7 @@ def genBaseTypeMacro(self, xr_type):
251254

252255
def genEnumMacros(self):
253256
ret = ""
254-
for xr_enum in self.api_enums:
257+
for xr_enum in sorted(self.api_enums, key=lambda xr_enum: xr_enum.name):
255258
ret += self.genEnumMacro(xr_enum) + "\n"
256259
return ret
257260

@@ -277,7 +280,7 @@ def genEnumMacro(self, xr_enum):
277280

278281
def genDumperAliases(self):
279282
ret = ""
280-
for type_name in self.aliases:
283+
for type_name in sorted(self.aliases):
281284
alias = self.aliases[type_name]
282285
if not self.isStruct(alias):
283286
continue
@@ -293,13 +296,17 @@ def genDumperAliases(self):
293296

294297
def genStructMacros(self):
295298
ret = ""
296-
for xr_struct in self.api_structures:
299+
for xr_struct in sorted(
300+
self.api_structures, key=lambda xr_struct: xr_struct.name
301+
):
297302
ret += self.genStructMacro(xr_struct) + "\n"
298303
return ret
299304

300305
def genStructNextDumpers(self):
301306
ret = ""
302-
for xr_struct in self.api_structures:
307+
for xr_struct in sorted(
308+
self.api_structures, key=lambda xr_struct: xr_struct.name
309+
):
303310
if self.hasNextDumper(xr_struct):
304311
ret += self.genStructNextDumper(xr_struct) + "\n"
305312
return ret
@@ -800,7 +807,9 @@ def genNextPFNDeclarations(self):
800807

801808
def genDumpingFunctionDeclarations(self):
802809
ret = ""
803-
for xr_struct in self.api_structures:
810+
for xr_struct in sorted(
811+
self.api_structures, key=lambda xr_struct: xr_struct.name
812+
):
804813
decl = self.getNextDumperDecl(xr_struct)
805814
if decl:
806815
ret += decl + ";\n"

0 commit comments

Comments
 (0)