ast2 varargs support
This commit is contained in:
parent
6d08f6ed80
commit
6a9a35db61
2 changed files with 25 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue