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 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 =
|
proc getPtrType*(str: string): string =
|
||||||
result = case str:
|
result = case str:
|
||||||
|
|
@ -99,8 +99,30 @@ proc newConstDef(gState: State, node: TSNode, fname = "", fval = ""): PNode =
|
||||||
fval
|
fval
|
||||||
else:
|
else:
|
||||||
gState.getNodeVal(node[1])
|
gState.getNodeVal(node[1])
|
||||||
valident =
|
var valident = newNode(nkNone)
|
||||||
gState.parseCExpression(val)
|
|
||||||
|
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:
|
if name.Bl:
|
||||||
# Name skipped or overridden since blank
|
# Name skipped or overridden since blank
|
||||||
|
|
|
||||||
|
|
@ -547,18 +547,15 @@ proc processTSNode(gState: State, node: TSNode, typeofNode: var PNode): PNode =
|
||||||
|
|
||||||
decho "NODE RESULT: ", result
|
decho "NODE RESULT: ", result
|
||||||
|
|
||||||
proc parseCExpression*(gState: State, code: string, name = ""): PNode =
|
proc parseCExpression*(gState: State, codeRoot: TSNode, name = ""): PNode =
|
||||||
## Convert the C string to a nim PNode tree
|
## Parse a c expression from a root ts node
|
||||||
gState.currentExpr = code
|
|
||||||
gState.currentTyCastName = name
|
|
||||||
|
|
||||||
result = newNode(nkNone)
|
# This var is used for keeping track of the type of the first
|
||||||
# This is used for keeping track of the type of the first
|
|
||||||
# symbol used for type casting
|
# symbol used for type casting
|
||||||
var tnode: PNode = nil
|
var tnode: PNode = nil
|
||||||
|
result = newNode(nkNone)
|
||||||
try:
|
try:
|
||||||
withCodeAst(gState.currentExpr, gState.mode):
|
result = gState.processTSNode(codeRoot, tnode)
|
||||||
result = gState.processTSNode(root, tnode)
|
|
||||||
except ExprParseError as e:
|
except ExprParseError as e:
|
||||||
decho e.msg
|
decho e.msg
|
||||||
result = newNode(nkNone)
|
result = newNode(nkNone)
|
||||||
|
|
@ -566,6 +563,14 @@ proc parseCExpression*(gState: State, code: string, name = ""): PNode =
|
||||||
decho "UNEXPECTED EXCEPTION: ", e.msg
|
decho "UNEXPECTED EXCEPTION: ", e.msg
|
||||||
result = newNode(nkNone)
|
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
|
# Clear the state
|
||||||
gState.currentExpr = ""
|
gState.currentExpr = ""
|
||||||
gState.currentTyCastName = ""
|
gState.currentTyCastName = ""
|
||||||
Loading…
Add table
Add a link
Reference in a new issue