Preserve type array ast

This commit is contained in:
Joey Yakimowich-Payne 2020-05-13 22:19:37 -06:00 • committed by genotrance
commit 2098f6a471
3 changed files with 12 additions and 10 deletions

View file

@ -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]

View file

@ -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 = ""
gState.currentTyCastName = ""
gState.currentExprSkipIdentValidation = false

View file

@ -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