added metagen check for first class enum arrays

This commit is contained in:
Stefan Stefanov 2024-04-24 22:52:24 +03:00
parent 99194e943a
commit 043892cdd1

View file

@ -257,6 +257,9 @@ SourceCodeGeneratorMetadata :: struct {
top: string, top: string,
bottom: string, bottom: string,
}, },
lanugage_settings: struct {
first_class_enum_arrays: bool, // for languages that support creating arrays that contain for each enum value an entry in the enum_data.entry_line: .EnumCase = {array entry}
},
custom_data_type: struct { custom_data_type: struct {
name: string, name: string,
type_declaration: string, // contains one param: custom_data_type.name + the rest of the type declaration like braces of the syntax & the type members type_declaration: string, // contains one param: custom_data_type.name + the rest of the type declaration like braces of the syntax & the type members
@ -295,6 +298,7 @@ odin_source_generator_metadata := SourceCodeGeneratorMetadata {
entry_line = "\t.%v = {{ x = %v, y = %v, w = %v, h = %v }},\n", entry_line = "\t.%v = {{ x = %v, y = %v, w = %v, h = %v }},\n",
end_line = "}\n\n", end_line = "}\n\n",
}, },
lanugage_settings = {first_class_enum_arrays = true},
} }
@ -415,6 +419,7 @@ metadata_source_code_generate :: proc(
{ {
entry: string entry: string
for cell in metadata { for cell in metadata {
if codegen.lanugage_settings.first_class_enum_arrays {
entry = fmt.aprintf( entry = fmt.aprintf(
codegen.array_data.entry_line, // "\t.%v = {{ x = %v, y = %v, w = %v, h = %v }},\n", codegen.array_data.entry_line, // "\t.%v = {{ x = %v, y = %v, w = %v, h = %v }},\n",
cell.name, cell.name,
@ -423,6 +428,15 @@ metadata_source_code_generate :: proc(
cell.size.x, cell.size.x,
cell.size.y, cell.size.y,
) )
} else {
entry = fmt.aprintf(
codegen.array_data.entry_line, // "\t{{ x = %v, y = %v, w = %v, h = %v }},\n",
cell.location.x,
cell.location.y,
cell.size.x,
cell.size.y,
)
}
strings.write_string(&sb, entry) strings.write_string(&sb, entry)
} }
} }