diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2020-03-17 17:19:47 -0500 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2020-03-17 17:19:47 -0500 |
| commit | 795f607e96a3228b9daa6dd6384fa63dab35c14e (patch) | |
| tree | a9d24852d41d2adacb82b40a614be07564f9e88f | |
| parent | 9d2626bb5fd1603ed0f6db1757b0184d9e5b29e4 (diff) | |
| download | nimterop-795f607e96a3228b9daa6dd6384fa63dab35c14e.tar.gz nimterop-795f607e96a3228b9daa6dd6384fa63dab35c14e.zip | |
newConstDef for header
| -rw-r--r-- | nimterop/ast2.nim | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/nimterop/ast2.nim b/nimterop/ast2.nim index 8c2fc3f..536ef9b 100644 --- a/nimterop/ast2.nim +++ b/nimterop/ast2.nim @@ -50,6 +50,42 @@ proc getLit*(nimState: NimState, str: string): PNode = if result.isNil: result = newNode(nkNilLit) +proc newConstDef(nimState: NimState, node: TSNode, name = "", val = ""): PNode = + let + # node[0] = identifier = const name + (cname, info) = nimState.getNameInfo(node.getAtom(), nskConst) + + # TODO - check blank and override + ident = + if name.len != 0: + nimState.getIdent(name, info) + else: + nimState.getIdent(cname, info) + + # node[1] = preproc_arg = value + nval = + if val.len != 0: + newStrNode(nkStrLit, val) + else: + nimState.getLit(nimState.getNodeVal(node[1])) + + # If supported literal + if nval.kind != nkNilLit: + # const X* = Y + # + # nkConstDef( + # nkPostfix( + # nkIdent("*"), + # nkIdent("X") + # ), + # nkEmpty(), + # nkXLit(Y) + # ) + result = newNode(nkConstDef) + result.add ident + result.add newNode(nkEmpty) + result.add nval + proc addConst(nimState: NimState, node: TSNode) = # #define X Y # @@ -63,32 +99,9 @@ proc addConst(nimState: NimState, node: TSNode) = if node[0].getName() == "identifier" and node[1].getName() == "preproc_arg": let - constDef = newNode(nkConstDef) - - # node[0] = identifier = const name - (name, info) = nimState.getNameInfo(node.getAtom(), nskConst) - # TODO - check blank and override - ident = nimState.getIdent(name, info) - - # node[1] = preproc_arg = value - val = nimState.getLit(nimState.getNodeVal(node[1])) - - # If supported literal - if val.kind != nkNilLit: - # const X* = Y - # - # nkConstDef( - # nkPostfix( - # nkIdent("*"), - # nkIdent("X") - # ), - # nkEmpty(), - # nkXLit(Y) - # ) - constDef.add ident - constDef.add newNode(nkEmpty) - constDef.add val + constDef = nimState.newConstDef(node) + if not constDef.isNil: # nkConstSection.add nimState.constSection.add constDef @@ -1027,6 +1040,10 @@ proc printNim*(gState: State, fullpath: string, root: TSNode) = nimState.procSection = newNode(nkStmtList) nimState.typeSection = newNode(nkTypeSection) + if nimState.gState.dynlib.Bl and nimState.gState.includeHeader: + nimState.constSection.add nimState.newConstDef( + root, name = nimState.currentHeader, val = fp) + nimState.searchTree(root) var |
