Address some PR comments
This commit is contained in:
parent
d11fd7407d
commit
e059b86719
3 changed files with 16 additions and 14 deletions
|
|
@ -4,7 +4,7 @@ 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, c, cpp]
|
import "."/treesitter/api
|
||||||
|
|
||||||
import "."/[globals, getters, exprparser, comphelp, tshelp]
|
import "."/[globals, getters, exprparser, comphelp, tshelp]
|
||||||
|
|
||||||
|
|
@ -1391,7 +1391,9 @@ proc addEnum(gState: State, node: TSNode) =
|
||||||
# Create const for fields
|
# Create const for fields
|
||||||
var
|
var
|
||||||
fnames: HashSet[string]
|
fnames: HashSet[string]
|
||||||
fvalSections: seq[tuple[fname: string, fval: string, cexpr: Option[TSNode]]]
|
# Hold all of field information so that we can add all of them
|
||||||
|
# after the const identifiers has been updated
|
||||||
|
fieldDeclarations: seq[tuple[fname: string, fval: string, cexpr: Option[TSNode]]]
|
||||||
for i in 0 .. enumlist.len - 1:
|
for i in 0 .. enumlist.len - 1:
|
||||||
let
|
let
|
||||||
en = enumlist[i]
|
en = enumlist[i]
|
||||||
|
|
@ -1410,9 +1412,9 @@ proc addEnum(gState: State, node: TSNode) =
|
||||||
fval = &"({prev} + 1).{name}"
|
fval = &"({prev} + 1).{name}"
|
||||||
|
|
||||||
if en.len > 1 and en[1].getName() in gEnumVals:
|
if en.len > 1 and en[1].getName() in gEnumVals:
|
||||||
fvalSections.add((fname, "", some(en[1])))
|
fieldDeclarations.add((fname, "", some(en[1])))
|
||||||
else:
|
else:
|
||||||
fvalSections.add((fname, fval, none(TSNode)))
|
fieldDeclarations.add((fname, fval, none(TSNode)))
|
||||||
|
|
||||||
fnames.incl fname
|
fnames.incl fname
|
||||||
prev = fname
|
prev = fname
|
||||||
|
|
@ -1422,7 +1424,7 @@ proc addEnum(gState: State, node: TSNode) =
|
||||||
gState.constIdentifiers.incl fnames
|
gState.constIdentifiers.incl fnames
|
||||||
|
|
||||||
# parseCExpression requires all const identifiers to be present for the enum
|
# parseCExpression requires all const identifiers to be present for the enum
|
||||||
for (fname, fval, cexprNode) in fvalSections:
|
for (fname, fval, cexprNode) in fieldDeclarations:
|
||||||
var fval = fval
|
var fval = fval
|
||||||
if cexprNode.isSome:
|
if cexprNode.isSome:
|
||||||
fval = "(" & $gState.parseCExpression(gState.getNodeVal(cexprNode.get()), name) & ")." & name
|
fval = "(" & $gState.parseCExpression(gState.getNodeVal(cexprNode.get()), name) & ")." & name
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,9 @@ type
|
||||||
# All const names for enum casting
|
# All const names for enum casting
|
||||||
constIdentifiers*: HashSet[string]
|
constIdentifiers*: HashSet[string]
|
||||||
|
|
||||||
# All symbols that have been skipped
|
# All symbols that have been skipped due to
|
||||||
|
# being unwrappable or the user provided
|
||||||
|
# override is blank
|
||||||
skippedSyms*: HashSet[string]
|
skippedSyms*: HashSet[string]
|
||||||
|
|
||||||
# Legacy ast fields, remove when ast2 becomes default
|
# Legacy ast fields, remove when ast2 becomes default
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
template withCodeAst*(inputCode: string, inputMode: string, body: untyped): untyped =
|
import "."/treesitter/[c, cpp]
|
||||||
## A simple template to inject the TSNode into a body of code
|
|
||||||
|
|
||||||
# This section is needed to be able to reference
|
template withCodeAst*(code: string, mode: string, body: untyped): untyped =
|
||||||
# mode in strformat calls
|
## A simple template to inject the TSNode into a body of code
|
||||||
let
|
mixin treeSitterC
|
||||||
code = inputCode
|
mixin treeSitterCpp
|
||||||
mode {.inject.} = inputMode
|
|
||||||
|
|
||||||
var parser = tsParserNew()
|
var parser = tsParserNew()
|
||||||
defer:
|
defer:
|
||||||
|
|
@ -18,7 +16,7 @@ template withCodeAst*(inputCode: string, inputMode: string, body: untyped): unty
|
||||||
elif mode == "cpp":
|
elif mode == "cpp":
|
||||||
doAssert parser.tsParserSetLanguage(treeSitterCpp()), "Failed to load C++ parser"
|
doAssert parser.tsParserSetLanguage(treeSitterCpp()), "Failed to load C++ parser"
|
||||||
else:
|
else:
|
||||||
doAssert false, &"Invalid parser {mode}"
|
doAssert false, "Invalid parser " & mode
|
||||||
|
|
||||||
var
|
var
|
||||||
tree = parser.tsParserParseString(nil, code.cstring, code.len.uint32)
|
tree = parser.tsParserParseString(nil, code.cstring, code.len.uint32)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue