aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Yakimowich-Payne <jyapayne@gmail.com>2020-05-13 22:19:37 -0600
committergenotrance <dev@genotrance.com>2020-05-15 11:20:00 -0500
commit2098f6a471784b5c87c678ec9d79faf2cc467199 (patch)
tree44e044e516a9ccbe2b1cc68639c1ec6781e3cda4
parent1a7860d8f4ac5d2d2d453e75e05200cb34849954 (diff)
downloadnimterop-2098f6a471784b5c87c678ec9d79faf2cc467199.tar.gz
nimterop-2098f6a471784b5c87c678ec9d79faf2cc467199.zip
Preserve type array ast
-rw-r--r--nimterop/ast2.nim5
-rw-r--r--nimterop/exprparser.nim14
-rw-r--r--nimterop/globals.nim3
3 files changed, 12 insertions, 10 deletions
diff --git a/nimterop/ast2.nim b/nimterop/ast2.nim
index 0d0883c..389d371 100644
--- a/nimterop/ast2.nim
+++ b/nimterop/ast2.nim
@@ -952,10 +952,7 @@ proc getTypeArray(gState: State, node: TSNode, tident: PNode, name: string): PNo
var size: PNode
let cnodeVal = gState.getNodeVal(cnode[1])
# Size of array could be a Nim expression
- size = gState.parseCExpression(cnodeVal)
- if size.kind == nkNone:
- # If the size could not be parsed, leave it alone
- size = gState.getIdent(cnodeVal)
+ size = gState.parseCExpression(cnodeVal, skipIdentValidation = true)
result = gState.newArrayTree(cnode, result, size)
cnode = cnode[0]
diff --git a/nimterop/exprparser.nim b/nimterop/exprparser.nim
index b0c34c1..e5e2150 100644
--- a/nimterop/exprparser.nim
+++ b/nimterop/exprparser.nim
@@ -45,14 +45,14 @@ proc getExprIdent*(gState: State, identName: string, kind = nskConst, parent = "
##
## Returns PNode(nkNone) if the identifier is blank
result = newNode(nkNone)
- if identName notin gState.skippedSyms:
+ if gState.currentExprSkipIdentValidation or identName notin gState.skippedSyms:
var ident = identName
if ident != "_":
# Process the identifier through cPlugin
ident = gState.getIdentifier(ident, kind, parent)
if kind == nskType:
result = gState.getIdent(ident)
- elif ident.nBl and ident in gState.constIdentifiers:
+ elif gState.currentExprSkipIdentValidation or ident.nBl and ident in gState.constIdentifiers:
if gState.currentTyCastName.nBl:
ident = ident & "." & gState.currentTyCastName
result = gState.getIdent(ident)
@@ -591,7 +591,7 @@ proc processTSNode(gState: State, node: TSNode, typeofNode: var PNode): PNode =
decho "NODE RESULT: ", result
-proc parseCExpression*(gState: State, codeRoot: TSNode, name = ""): PNode =
+proc parseCExpression*(gState: State, codeRoot: TSNode): PNode =
## Parse a c expression from a root ts node
# This var is used for keeping track of the type of the first
@@ -607,14 +607,16 @@ proc parseCExpression*(gState: State, codeRoot: TSNode, name = ""): PNode =
decho "UNEXPECTED EXCEPTION: ", e.msg
result = newNode(nkNone)
-proc parseCExpression*(gState: State, code: string, name = ""): PNode =
+proc parseCExpression*(gState: State, code: string, name = "", skipIdentValidation = false): PNode =
## Convert the C string to a nim PNode tree
gState.currentExpr = code
gState.currentTyCastName = name
+ gState.currentExprSkipIdentValidation = skipIdentValidation
withCodeAst(gState.currentExpr, gState.mode):
- result = gState.parseCExpression(root, name)
+ result = gState.parseCExpression(root)
# Clear the state
gState.currentExpr = ""
- gState.currentTyCastName = "" \ No newline at end of file
+ gState.currentTyCastName = ""
+ gState.currentExprSkipIdentValidation = false \ No newline at end of file
diff --git a/nimterop/globals.nim b/nimterop/globals.nim
index 46203ea..039dd3c 100644
--- a/nimterop/globals.nim
+++ b/nimterop/globals.nim
@@ -114,6 +114,9 @@ type
# Used for the exprparser.nim module
currentExpr*, currentTyCastName*: string
+ # Controls whether or not the current expression
+ # should validate idents against currently defined idents
+ currentExprSkipIdentValidation*: bool
# Legacy AST fields, remove when ast2 becomes default
constStr*, enumStr*, procStr*, typeStr*: string