Skip to content

Commit

Permalink
[WIP] TS read class/signal/slot
Browse files Browse the repository at this point in the history
- ADDED ::
  - Support for reading Qt signals, slots
  - General C++ method, constructor handling
- NEXT ::
  - Make a simplified test for Qt wrapper generator before going into
    wrapping whole Qt library.
  - #25
  • Loading branch information
haxscramper committed Nov 2, 2021
1 parent 5b80667 commit a5d4d7a
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 82 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ wrap-examples.rst

# End of https://www.toptal.com/developers/gitignore/api/c++

**/.gdb_history
**/.gdb_history
*.code-workspace
8 changes: 7 additions & 1 deletion hcparse.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"folders": [
{
"path": "."
},
{
"path": "/mnt/workspace/github/hlibgit2"
},
{
"path": "/mnt/workspace/github/hlibssh2"
}
],
"settings": {}
}
}
5 changes: 4 additions & 1 deletion nim.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
--showAllMismatches:on
# added by nimph:
# added by nimph:
--path="/mnt/workspace/github/deps/pkgs/unicodedb-#master/src/"
# added by nimph:
--path="/mnt/workspace/github/deps/pkgs/fusion-#master/src/"
# added by nimph:
--path="/mnt/workspace/github/deps/pkgs/unicodedb-0.10.0/src/"
71 changes: 53 additions & 18 deletions src/hcparse/hc_codegen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type

nameStyle*: IdentStyle



const
cxxCodegenConf* = CodegenConf(
isIcpp: true
Expand Down Expand Up @@ -103,6 +105,10 @@ proc toNNode*[N](
else:
result = newNType[N]("ptr", @[toNNode[N](t.wrapped, conf, anon)])

of ctkLVref:
# QUESTION how to map lvref properly?
result = toNNode[N](t.wrapped, conf, anon)

of ctkProc:
var pragma: Pragma[N]
if ctfNoCdeclProc notin t.flags:
Expand Down Expand Up @@ -260,7 +266,7 @@ proc toNNode*[N](
def: CxxProc,
conf: CodegenConf,
anon: var seq[NimDecl[N]],
onConstructor: CxxTypeKind = ctkIdent
onConstructor: NimConstructorTarget = nctRegular
): ProcDecl[N] =

result = newProcDecl[N](def.nimName)
Expand All @@ -270,28 +276,58 @@ proc toNNode*[N](
if cpfExportc in def.flags:
result.addPragma("exportc", newNLit[N, string](def.cxxName.cxxStr()))

if cpfVariadic in def.flags: result.addPragma("varargs")
if cpfSlot in def.flags: result.addPragma("qslot")
if cpfSignal in def.flags: result.addPragma("qsignal")

if def.isConstructor:
let name = conf.getSuffix(result.name)

var cbind = def.cbind
case onConstructor:
of nctRegular:
cbind.icpp.standaloneProc(def.getIcppName())
result.addPragma toNNode[N](cbind, conf, def.nimName)

result.addPragma("constructor")
result.name = "init" & name

of nctPtr:
cbind.icpp.standaloneProc("new " & def.getIcppName())
result.addPragma toNNode[N](cbind, conf, def.nimName)

result.name = "cnew" & name

of nctRef:
result.name = "new" & name

elif def.isMethod():
var ret = toNNode[N](def.methodOf.get(), conf, anon)
if not def.isConst():
ret = newNType[N]("var", @[ret])

result.addArgument("this", ret)
result.addPragma toNNode[N](def.getCbindAs(), conf, def.nimName)

else:
result.addPragma toNNode[N](
def.getCbindAs(ctkIdent), conf, def.nimName)
result.addPragma toNNode[N](def.getCbindAs(), conf, def.nimName)

if cpfVariadic in def.flags:
result.addPragma("varargs")

if def.isConstructor and onConstructor == ctkIdent:
result.addPragma("constructor")

let ret: NType[N] =
if def.isConstructor:
let base: NType[N] = toNNode[N](def.getConstructed(), conf, anon)
case onConstructor:
of nctRegular: base
of nctPtr: newNType[N]("ptr", @[base])
of nctRef: newNType[N]("ref", @[base])

let ret = def.getReturn(onConstructor)
if "git_object_t" in $def.getReturn(onConstructor):
echov ret
echov ret.flags
else:
toNNode[N](def.returnType, conf, anon)

# nim's overload-resolution-in-generics magic
proc_decl.`returnType=`(result, toNNode[N](ret, conf, anon))
proc_decl.`returnType=`(result, ret)

if def.methodOf.isSome():
result.addArgument(
"this", toNNode[N](def.methodOf.get(), conf, anon))

for arg in def.arguments:
result.addArgument toNNode[N](arg, conf, anon)
Expand Down Expand Up @@ -319,7 +355,7 @@ proc toNNode*[N](
result.add toNimDecl(res)

for meth in obj.methods:
result.add toNNode[N](meth, conf, anon, ctkPtr)
result.add toNNode[N](meth, conf, anon, nctPtr)

for n in obj.nested:
result.add toNNode[N](n, conf, anon)
Expand Down Expand Up @@ -500,8 +536,7 @@ proc toNNode*[N](
result.add toNNode[N](entry.cxxEnum, conf)

of cekProc:
result.add toNNode[N](
entry.cxxProc, conf, anon, ctkPtr).toNimDecl()
result.add toNNode[N](entry.cxxProc, conf, anon).toNimDecl()

of cekForward:
result.add toNNode[N](entry.cxxForward, conf)
Expand Down
5 changes: 5 additions & 0 deletions src/hcparse/hc_impls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ proc fixContextedName*(

cache.newRename(name.nim, result)

let l = "LIBSSH2_CHANNEL" in $name
if l:
echov name, " -> ", result



proc getBaseFile*(conf: WrapConf, wrapped: WrappedFile): AbsFile =
## Return base file for generated wrapped one. For generated grouped
Expand Down
33 changes: 29 additions & 4 deletions src/hcparse/hc_parsefront.nim
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,30 @@ proc postFixEntries*(
for item in mitems(entries):
setHeaderRec(item, conf)


proc postFixEntries*(
entries: sink seq[CxxEntry],
conf: CxxFixConf,
lib: CxxLibImport,
file: Option[AbsFile] = none AbsFile
): seq[CxxEntry] =
result = entries
conf.postFixEntries(result, lib, file)


iterator mentries*(files: var seq[CxxFile]): var CxxEntry =
for file in mitems(files):
for entry in mitems(file.entries):
yield entry

proc postFixEntries*(conf: CxxFixConf, files: var seq[CxxFile]) =
var store = conf.typeStore
var cache: StringNameCache

# Fix all identifier names in entry lists
for item in mentries(files):
fixIdentsRec(item, cache, conf)
for file in mitems(files):
var cache: StringNameCache
for item in mitems(file.entries):
fixIdentsRec(item, cache, conf)

# Set spelling location file for all entries in the list
for file in mitems(files):
Expand All @@ -230,6 +242,14 @@ proc postFixEntries*(conf: CxxFixConf, files: var seq[CxxFile]) =
for item in mentries(files):
setHeaderRec(item, conf)


proc postFixEntries*(
files: sink seq[CxxFile], conf: CxxFixConf): seq[CxxFile] =

result = files
conf.postFixEntries(result)


proc wrapViaTs*(
str: string,
conf: CxxFixConf,
Expand Down Expand Up @@ -487,7 +507,12 @@ proc wrapCSharedLibViaTsWave*(
proc validateGenerated*(files: GenFiles) =
for file in items(files.genNim):
try:
execShell shellCmd(nim, check, errormax = 3, $file)
execShell shellCmd(
nim,
check,
errormax = 3,
spellSuggest = 0,
$file)

except ShellError:
echo "> ", file
Expand Down
Loading

0 comments on commit a5d4d7a

Please sign in to comment.