Skip to content

Commit

Permalink
gencpp: clean code; move more things to preset
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Dec 20, 2024
1 parent b17f0a0 commit 490753a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
11 changes: 9 additions & 2 deletions cmd/codegen/cimgui-go-preset.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@
"TextEditor_GetText": "TextEditor_GetText_alloc"
},
"DefaultArgReplace": {
"FLT_MIN": "igGET_FLT_MIN()",
"FLT_MAX": "igGET_FLT_MAX()"
"FLT_MIN": "igGET_FLT_MIN()",
"FLT_MAX": "igGET_FLT_MAX()",
"nullptr": "0",
"NULL": "0",
"((void*)0)": "0"
},
"DefaultArgArbitraryValue": {
"text_end": 0,
"text_end_": "0"
},
"ExtraCGOPreamble": [
"#include \"../imgui/extra_types.h\""
Expand Down
12 changes: 2 additions & 10 deletions cmd/codegen/gencpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,8 @@ extern "C" {
v = string(r)
}

if v == "((void*)0)" {
v = "NULL"
}

if v == "nullptr" || v == "NULL" {
v = "0"
}

if k == "text_end" || k == "text_end_" {
v = "0"
if r, ok := ctx.preset.DefaultArgArbitraryValue[CIdentifier(k)]; ok {
v = string(r)
}

if strings.Contains(invocationStmt, ","+k) {
Expand Down
4 changes: 4 additions & 0 deletions cmd/codegen/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type Preset struct {
// cimgui-go uses this to change FLT_MIN with igGet_FLT_MIN()
// NOTE: Iterated randomly!
DefaultArgReplace map[CIdentifier]CIdentifier
// DefaultArgArbitraryValue is similar to the above DefaultArgReplace, but
// associates default arg name with any arbitrary value.
// cimgui-go uses this to set text_end to 0
DefaultArgArbitraryValue map[CIdentifier]CIdentifier
// ExtraCGOPreamble allows to specify additional C code elements in Go files.
// For example could be used to include extra files.
// For ease of use, its in form of []string. These lines will be merged and prefixed (if appliable) with '//'
Expand Down

0 comments on commit 490753a

Please sign in to comment.