Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uses cbuilder for tuples #24127

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions compiler/cbuilder.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
type
Snippet = string
Builder = string

template newBuilder(s: string): Builder =
s

proc addField(obj: var Builder; field: Snippet;) =
obj.add field
obj.add ";\n"


template withStruct(obj: var Builder; structOrUnion: string; name: string; inheritance: string; body: typed) =
if inheritance.len > 0:
obj.add "$1 $2 : public $1 {$n" % [structOrUnion, name, inheritance]
else:
obj.add "$1 $2 {$n" % [structOrUnion, name]
body
obj.add("};\n")
15 changes: 7 additions & 8 deletions compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -868,14 +868,13 @@ proc getRecordDesc(m: BModule; typ: PType, name: Rope,

proc getTupleDesc(m: BModule; typ: PType, name: Rope,
check: var IntSet): Rope =
result = "$1 $2 {$n" % [structOrUnion(typ), name]
var desc: Rope = ""
for i, a in typ.ikids:
desc.addf("$1 Field$2;$n",
[getTypeDescAux(m, a, check, dkField), rope(i)])
if desc == "": result.add("char dummy;\L")
else: result.add(desc)
result.add("};\L")
result = newBuilder("")
withStruct(result, structOrUnion(typ), name, ""):
if kidsLen(typ) > 0:
for i, a in typ.ikids:
result.addField "$1 Field$2" % [getTypeDescAux(m, a, check, dkField), rope(i)]
else:
result.addField "char dummy"

proc scanCppGenericSlot(pat: string, cursor, outIdx, outStars: var int): bool =
# A helper proc for handling cppimport patterns, involving numeric
Expand Down
1 change: 1 addition & 0 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ proc dataField(p: BProc): Rope =

proc genProcPrototype(m: BModule, sym: PSym)

include cbuilder
include ccgliterals
include ccgtypes

Expand Down