Add hack for skipping types as root nodes
This commit is contained in:
parent
cb4a9d844f
commit
9ef3182d7a
2 changed files with 39 additions and 12 deletions
|
|
@ -4,9 +4,9 @@ import options as opts
|
|||
|
||||
import compiler/[ast, idents, lineinfos, modulegraphs, msgs, options, renderer]
|
||||
|
||||
import "."/treesitter/api
|
||||
import "."/treesitter/[api, c, cpp]
|
||||
|
||||
import "."/[globals, getters, exprparser, comphelp]
|
||||
import "."/[globals, getters, exprparser, comphelp, tshelp]
|
||||
|
||||
proc getPtrType*(str: string): string =
|
||||
result = case str:
|
||||
|
|
@ -99,8 +99,30 @@ proc newConstDef(gState: State, node: TSNode, fname = "", fval = ""): PNode =
|
|||
fval
|
||||
else:
|
||||
gState.getNodeVal(node[1])
|
||||
valident =
|
||||
gState.parseCExpression(val)
|
||||
var valident = newNode(nkNone)
|
||||
|
||||
withCodeAst(val, gState.mode):
|
||||
# This section is a hack for determining that the first
|
||||
# node is a type, which shouldn't be accepted by a const
|
||||
# def section. Need to replace this with some other mechanism
|
||||
# to handle type aliases
|
||||
var maybeTyNode: TSNode
|
||||
# Take the very first node, which may be 2 levels
|
||||
# down if there is an error node
|
||||
if root.len > 0 and root[0].getName() == "ERROR":
|
||||
maybeTyNode = root[0][0]
|
||||
elif root.len > 0:
|
||||
maybeTyNode = root[0]
|
||||
|
||||
if not maybeTyNode.isNil:
|
||||
let name = maybeTyNode.getName()
|
||||
case name
|
||||
of "type_descriptor", "sized_type_specifier":
|
||||
discard
|
||||
else:
|
||||
# Can't do gState.parseCExpression(root) here for some reason?
|
||||
# get a SEGFAULT if we use root
|
||||
valident = gState.parseCExpression(val)
|
||||
|
||||
if name.Bl:
|
||||
# Name skipped or overridden since blank
|
||||
|
|
|
|||
|
|
@ -547,18 +547,15 @@ proc processTSNode(gState: State, node: TSNode, typeofNode: var PNode): PNode =
|
|||
|
||||
decho "NODE RESULT: ", result
|
||||
|
||||
proc parseCExpression*(gState: State, code: string, name = ""): PNode =
|
||||
## Convert the C string to a nim PNode tree
|
||||
gState.currentExpr = code
|
||||
gState.currentTyCastName = name
|
||||
proc parseCExpression*(gState: State, codeRoot: TSNode, name = ""): PNode =
|
||||
## Parse a c expression from a root ts node
|
||||
|
||||
result = newNode(nkNone)
|
||||
# This is used for keeping track of the type of the first
|
||||
# This var is used for keeping track of the type of the first
|
||||
# symbol used for type casting
|
||||
var tnode: PNode = nil
|
||||
result = newNode(nkNone)
|
||||
try:
|
||||
withCodeAst(gState.currentExpr, gState.mode):
|
||||
result = gState.processTSNode(root, tnode)
|
||||
result = gState.processTSNode(codeRoot, tnode)
|
||||
except ExprParseError as e:
|
||||
decho e.msg
|
||||
result = newNode(nkNone)
|
||||
|
|
@ -566,6 +563,14 @@ proc parseCExpression*(gState: State, code: string, name = ""): PNode =
|
|||
decho "UNEXPECTED EXCEPTION: ", e.msg
|
||||
result = newNode(nkNone)
|
||||
|
||||
proc parseCExpression*(gState: State, code: string, name = ""): PNode =
|
||||
## Convert the C string to a nim PNode tree
|
||||
gState.currentExpr = code
|
||||
gState.currentTyCastName = name
|
||||
|
||||
withCodeAst(gState.currentExpr, gState.mode):
|
||||
result = gState.parseCExpression(root, name)
|
||||
|
||||
# Clear the state
|
||||
gState.currentExpr = ""
|
||||
gState.currentTyCastName = ""
|
||||
Loading…
Add table
Add a link
Reference in a new issue