aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2020-04-15 23:42:22 -0500
committerGanesh Viswanathan <dev@genotrance.com>2020-04-15 23:42:22 -0500
commit6a9a35db61e1e47652fa667ff557555e87a6edeb (patch)
tree59dd01c18e5b99a353848b9d382f633ab3467adc
parent6d08f6ed80ab1195b4d233a82f578d93c8611382 (diff)
downloadnimterop-6a9a35db61e1e47652fa667ff557555e87a6edeb.tar.gz
nimterop-6a9a35db61e1e47652fa667ff557555e87a6edeb.zip
ast2 varargs support
-rw-r--r--nimterop/ast2.nim11
-rw-r--r--nimterop/getters.nim14
2 files changed, 25 insertions, 0 deletions
diff --git a/nimterop/ast2.nim b/nimterop/ast2.nim
index 5bb33ae..554c507 100644
--- a/nimterop/ast2.nim
+++ b/nimterop/ast2.nim
@@ -686,6 +686,10 @@ proc newProcTy(nimState: NimState, name: string, node: TSNode, rtyp: PNode): PNo
result.add nimState.newFormalParams(name, node, rtyp)
result.add nimState.newPragma(node, nimState.gState.convention)
+ # Add varargs if ...
+ if node.getVarargs():
+ nimState.addPragma(node, result[^1], "varargs")
+
proc processNode(nimState: NimState, node: TSNode): bool
proc newRecListTree(nimState: NimState, name: string, node: TSNode): PNode =
# Create nkRecList tree for specified object
@@ -1582,6 +1586,9 @@ proc addProc(nimState: NimState, node, rnode: TSNode) =
# {.impnameC.} shortcut
nimState.newPragma(node, nimState.impShort & "C")
+ # Detect ... and add {.varargs.}
+ pvarargs = plist.getVarargs()
+
# Need {.convention.} and {.header.} if applicable
if name != origname:
if nimState.includeHeader():
@@ -1595,6 +1602,10 @@ proc addProc(nimState: NimState, node, rnode: TSNode) =
# {.dynlib.} for DLLs
nimState.addPragma(node, prident, "dynlib", nimState.getIdent(nimState.gState.dynlib))
+ if pvarargs:
+ # Add {.varargs.} for ...
+ nimState.addPragma(node, prident, "varargs")
+
procDef.add prident
procDef.add newNode(nkEmpty)
procDef.add newNode(nkEmpty)
diff --git a/nimterop/getters.nim b/nimterop/getters.nim
index aeefbd8..c971bfc 100644
--- a/nimterop/getters.nim
+++ b/nimterop/getters.nim
@@ -288,6 +288,20 @@ proc getDeclarator*(node: TSNode): TSNode =
elif node.len != 0:
return node[0].getDeclarator()
+proc getVarargs*(node: TSNode): bool =
+ # Detect ... and add {.varargs.}
+ #
+ # `node` is the param list
+ #
+ # ... is an unnamed node, second last node and ) is last node
+ let
+ nlen = node.tsNodeChildCount()
+ if nlen > 1:
+ let
+ nval = node.tsNodeChild(nlen - 2).getName()
+ if nval == "...":
+ result = true
+
proc firstChildInTree*(node: TSNode, ntype: string): TSNode =
# Search for node type in tree - first children
var