Partly fix issue #183, lineTrace:on
This commit is contained in:
parent
ecee58342e
commit
9cd39600d4
4 changed files with 109 additions and 73 deletions
|
|
@ -10,6 +10,7 @@ when defined(Windows):
|
||||||
|
|
||||||
# Retain stackTrace for clear errors
|
# Retain stackTrace for clear errors
|
||||||
switch("stackTrace", "on")
|
switch("stackTrace", "on")
|
||||||
|
switch("lineTrace", "on")
|
||||||
|
|
||||||
# Path to compiler
|
# Path to compiler
|
||||||
switch("path", "$nim")
|
switch("path", "$nim")
|
||||||
|
|
|
||||||
|
|
@ -495,7 +495,7 @@ proc newArrayTree(nimState: NimState, node: TSNode, typ, size: PNode = nil): PNo
|
||||||
proc getTypeArray(nimState: NimState, node, tnode: TSNode, name: string): PNode
|
proc getTypeArray(nimState: NimState, node, tnode: TSNode, name: string): PNode
|
||||||
proc getTypeProc(nimState: NimState, name: string, node, rnode: TSNode): PNode
|
proc getTypeProc(nimState: NimState, name: string, node, rnode: TSNode): PNode
|
||||||
|
|
||||||
proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeInteger, exported = false): PNode =
|
iterator newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeInteger, exported = false): PNode =
|
||||||
# Create nkIdentDefs tree for specified proc parameter or object field
|
# Create nkIdentDefs tree for specified proc parameter or object field
|
||||||
#
|
#
|
||||||
# For proc, param should not be exported
|
# For proc, param should not be exported
|
||||||
|
|
@ -520,8 +520,13 @@ proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeIn
|
||||||
# typ,
|
# typ,
|
||||||
# nkEmpty()
|
# nkEmpty()
|
||||||
# )
|
# )
|
||||||
result = newNode(nkIdentDefs)
|
#
|
||||||
|
# Iterator since structs can have multiple comma separated fields for the
|
||||||
|
# same type so can yield multiple results.
|
||||||
|
#
|
||||||
|
# struct ABC { int w, h; };
|
||||||
|
#
|
||||||
|
# This is not applicable for procs.
|
||||||
let
|
let
|
||||||
start = getStartAtom(node)
|
start = getStartAtom(node)
|
||||||
|
|
||||||
|
|
@ -533,6 +538,9 @@ proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeIn
|
||||||
# Only for proc with no named param - create a param name based on offset
|
# Only for proc with no named param - create a param name based on offset
|
||||||
#
|
#
|
||||||
# int func(char, int);
|
# int func(char, int);
|
||||||
|
var
|
||||||
|
result = newNode(nkIdentDefs)
|
||||||
|
|
||||||
if tname != "object":
|
if tname != "object":
|
||||||
let
|
let
|
||||||
pname = "a" & $(offset+1)
|
pname = "a" & $(offset+1)
|
||||||
|
|
@ -543,77 +551,88 @@ proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeIn
|
||||||
else:
|
else:
|
||||||
# int func(void)
|
# int func(void)
|
||||||
result = nil
|
result = nil
|
||||||
|
|
||||||
|
yield result
|
||||||
else:
|
else:
|
||||||
let
|
for i in start+1 ..< node.len:
|
||||||
fdecl = node[start+1].firstChildInTree("function_declarator")
|
if node[i].getName() == "bitfield_clause":
|
||||||
afdecl = node[start+1].firstChildInTree("abstract_function_declarator")
|
continue
|
||||||
adecl = node[start+1].firstChildInTree("array_declarator")
|
|
||||||
abst = node[start+1].getName() == "abstract_pointer_declarator"
|
var
|
||||||
if fdecl.isNil and afdecl.isNil and adecl.isNil:
|
result = newNode(nkIdentDefs)
|
||||||
if abst:
|
|
||||||
# Only for proc with no named param with pointer type
|
let
|
||||||
|
fdecl = node[i].firstChildInTree("function_declarator")
|
||||||
|
afdecl = node[i].firstChildInTree("abstract_function_declarator")
|
||||||
|
adecl = node[i].firstChildInTree("array_declarator")
|
||||||
|
abst = node[i].getName() == "abstract_pointer_declarator"
|
||||||
|
if fdecl.isNil and afdecl.isNil and adecl.isNil:
|
||||||
|
if abst:
|
||||||
|
# Only for proc with no named param with pointer type
|
||||||
|
# Create a param name based on offset
|
||||||
|
#
|
||||||
|
# int func(char *, int **);
|
||||||
|
let
|
||||||
|
pname = "a" & $(offset+1)
|
||||||
|
pident = nimState.getIdent(pname, tinfo, exported)
|
||||||
|
acount = node[i].getXCount("abstract_pointer_declarator")
|
||||||
|
result.add pident
|
||||||
|
result.add nimState.newPtrTree(acount, tident)
|
||||||
|
result.add newNode(nkEmpty)
|
||||||
|
else:
|
||||||
|
# Named param, simple type
|
||||||
|
let
|
||||||
|
(pname, _, pinfo) = nimState.getNameInfo(node[i].getAtom(), nskField, parent = name)
|
||||||
|
pident = nimState.getIdent(pname, pinfo, exported)
|
||||||
|
|
||||||
|
# Bitfield support - typedef struct { int field: 1; };
|
||||||
|
prident =
|
||||||
|
if node.len > i and node[i + 1].getName() == "bitfield_clause":
|
||||||
|
nimState.newPragmaExpr(node, pident, "bitsize",
|
||||||
|
newIntNode(nkIntLit, parseInt(nimState.getNodeVal(node[i + 1].getAtom()))))
|
||||||
|
else:
|
||||||
|
pident
|
||||||
|
|
||||||
|
count = node[i].getPtrCount()
|
||||||
|
|
||||||
|
result.add prident
|
||||||
|
if count > 0:
|
||||||
|
result.add nimState.newPtrTree(count, tident)
|
||||||
|
else:
|
||||||
|
result.add tident
|
||||||
|
result.add newNode(nkEmpty)
|
||||||
|
elif not fdecl.isNil:
|
||||||
|
# Named param, function pointer
|
||||||
|
let
|
||||||
|
(pname, _, pinfo) = nimState.getNameInfo(node[i].getAtom(), nskField, parent = name)
|
||||||
|
pident = nimState.getIdent(pname, pinfo, exported)
|
||||||
|
result.add pident
|
||||||
|
result.add nimState.getTypeProc(name, node[i], node[start])
|
||||||
|
result.add newNode(nkEmpty)
|
||||||
|
elif not afdecl.isNil:
|
||||||
|
# Only for proc with no named param with function pointer type
|
||||||
# Create a param name based on offset
|
# Create a param name based on offset
|
||||||
#
|
#
|
||||||
# int func(char *, int **);
|
# int func(int (*)(int *));
|
||||||
let
|
let
|
||||||
pname = "a" & $(offset+1)
|
pname = "a" & $(offset+1)
|
||||||
pident = nimState.getIdent(pname, tinfo, exported)
|
pident = nimState.getIdent(pname, tinfo, exported)
|
||||||
acount = node[start+1].getXCount("abstract_pointer_declarator")
|
procTy = nimState.getTypeProc(name, node[i], node[start])
|
||||||
result.add pident
|
result.add pident
|
||||||
result.add nimState.newPtrTree(acount, tident)
|
result.add procTy
|
||||||
|
result.add newNode(nkEmpty)
|
||||||
|
elif not adecl.isNil:
|
||||||
|
# Named param, array type
|
||||||
|
let
|
||||||
|
(pname, _, pinfo) = nimState.getNameInfo(node[i].getAtom(), nskField, parent = name)
|
||||||
|
pident = nimState.getIdent(pname, pinfo, exported)
|
||||||
|
result.add pident
|
||||||
|
result.add nimState.getTypeArray(node[i], node[start], name)
|
||||||
result.add newNode(nkEmpty)
|
result.add newNode(nkEmpty)
|
||||||
else:
|
else:
|
||||||
# Named param, simple type
|
result = nil
|
||||||
let
|
|
||||||
(pname, _, pinfo) = nimState.getNameInfo(node[start+1].getAtom(), nskField, parent = name)
|
|
||||||
pident = nimState.getIdent(pname, pinfo, exported)
|
|
||||||
|
|
||||||
# Bitfield support - typedef struct { int field: 1; };
|
yield result
|
||||||
prident =
|
|
||||||
if node.len > start+1 and node[start+2].getName() == "bitfield_clause":
|
|
||||||
nimState.newPragmaExpr(node, pident, "bitsize",
|
|
||||||
newIntNode(nkIntLit, parseInt(nimState.getNodeVal(node[start+2].getAtom()))))
|
|
||||||
else:
|
|
||||||
pident
|
|
||||||
|
|
||||||
count = node[start+1].getPtrCount()
|
|
||||||
|
|
||||||
result.add prident
|
|
||||||
if count > 0:
|
|
||||||
result.add nimState.newPtrTree(count, tident)
|
|
||||||
else:
|
|
||||||
result.add tident
|
|
||||||
result.add newNode(nkEmpty)
|
|
||||||
elif not fdecl.isNil:
|
|
||||||
# Named param, function pointer
|
|
||||||
let
|
|
||||||
(pname, _, pinfo) = nimState.getNameInfo(node[start+1].getAtom(), nskField, parent = name)
|
|
||||||
pident = nimState.getIdent(pname, pinfo, exported)
|
|
||||||
result.add pident
|
|
||||||
result.add nimState.getTypeProc(name, node[start+1], node[start])
|
|
||||||
result.add newNode(nkEmpty)
|
|
||||||
elif not afdecl.isNil:
|
|
||||||
# Only for proc with no named param with function pointer type
|
|
||||||
# Create a param name based on offset
|
|
||||||
#
|
|
||||||
# int func(int (*)(int *));
|
|
||||||
let
|
|
||||||
pname = "a" & $(offset+1)
|
|
||||||
pident = nimState.getIdent(pname, tinfo, exported)
|
|
||||||
procTy = nimState.getTypeProc(name, node[start+1], node[start])
|
|
||||||
result.add pident
|
|
||||||
result.add procTy
|
|
||||||
result.add newNode(nkEmpty)
|
|
||||||
elif not adecl.isNil:
|
|
||||||
# Named param, array type
|
|
||||||
let
|
|
||||||
(pname, _, pinfo) = nimState.getNameInfo(node[start+1].getAtom(), nskField, parent = name)
|
|
||||||
pident = nimState.getIdent(pname, pinfo, exported)
|
|
||||||
result.add pident
|
|
||||||
result.add nimState.getTypeArray(node[start+1], node[start], name)
|
|
||||||
result.add newNode(nkEmpty)
|
|
||||||
else:
|
|
||||||
result = nil
|
|
||||||
|
|
||||||
proc newFormalParams(nimState: NimState, name: string, node: TSNode, rtyp: PNode): PNode =
|
proc newFormalParams(nimState: NimState, name: string, node: TSNode, rtyp: PNode): PNode =
|
||||||
# Create nkFormalParams tree for specified params and return type
|
# Create nkFormalParams tree for specified params and return type
|
||||||
|
|
@ -635,10 +654,9 @@ proc newFormalParams(nimState: NimState, name: string, node: TSNode, rtyp: PNode
|
||||||
for i in 0 ..< node.len:
|
for i in 0 ..< node.len:
|
||||||
if node[i].getName() == "parameter_declaration":
|
if node[i].getName() == "parameter_declaration":
|
||||||
# Add nkIdentDefs for each param
|
# Add nkIdentDefs for each param
|
||||||
let
|
for param in nimState.newIdentDefs(name, node[i], i, exported = false):
|
||||||
param = nimState.newIdentDefs(name, node[i], i, exported = false)
|
if not param.isNil:
|
||||||
if not param.isNil:
|
result.add param
|
||||||
result.add param
|
|
||||||
|
|
||||||
proc newProcTy(nimState: NimState, name: string, node: TSNode, rtyp: PNode): PNode =
|
proc newProcTy(nimState: NimState, name: string, node: TSNode, rtyp: PNode): PNode =
|
||||||
# Create nkProcTy tree for specified proc type
|
# Create nkProcTy tree for specified proc type
|
||||||
|
|
@ -674,10 +692,9 @@ proc newRecListTree(nimState: NimState, name: string, node: TSNode): PNode =
|
||||||
for i in 0 ..< node.len:
|
for i in 0 ..< node.len:
|
||||||
if node[i].getName() == "field_declaration":
|
if node[i].getName() == "field_declaration":
|
||||||
# Add nkIdentDefs for each field
|
# Add nkIdentDefs for each field
|
||||||
let
|
for field in nimState.newIdentDefs(name, node[i], i, exported = true):
|
||||||
field = nimState.newIdentDefs(name, node[i], i, exported = true)
|
if not field.isNil:
|
||||||
if not field.isNil:
|
result.add field
|
||||||
result.add field
|
|
||||||
|
|
||||||
proc addTypeObject(nimState: NimState, node: TSNode, typeDef: PNode = nil, fname = "", istype = false, union = false) =
|
proc addTypeObject(nimState: NimState, node: TSNode, typeDef: PNode = nil, fname = "", istype = false, union = false) =
|
||||||
# Add a type of object
|
# Add a type of object
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,12 @@ typedef struct {
|
||||||
int flags;
|
int flags;
|
||||||
} BASS_DEVICEINFO;
|
} BASS_DEVICEINFO;
|
||||||
|
|
||||||
|
// Issue #183
|
||||||
|
struct GPU_Target
|
||||||
|
{
|
||||||
|
int w, *h;
|
||||||
|
char *x, y, **z;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -305,6 +311,13 @@ typedef struct {
|
||||||
int flags;
|
int flags;
|
||||||
} BASS_DEVICEINFO;
|
} BASS_DEVICEINFO;
|
||||||
|
|
||||||
|
// Issue #183
|
||||||
|
struct GPU_Target
|
||||||
|
{
|
||||||
|
int w, *h;
|
||||||
|
char *x, y, **z;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -356,4 +356,9 @@ assert func2 is proc (f1: cint; sfunc2: proc (f1: cint; ssfunc2: proc (f1: cint)
|
||||||
|
|
||||||
assert BASS_DEVICEINFO is object
|
assert BASS_DEVICEINFO is object
|
||||||
testFields(BASS_DEVICEINFO, "name|driver|flags!cstring|cstring|cint")
|
testFields(BASS_DEVICEINFO, "name|driver|flags!cstring|cstring|cint")
|
||||||
checkPragmas(BASS_DEVICEINFO, pHeaderImpBy)
|
checkPragmas(BASS_DEVICEINFO, pHeaderImpBy)
|
||||||
|
|
||||||
|
# Issue #183
|
||||||
|
assert GPU_Target is object
|
||||||
|
testFields(GPU_Target, "w|h|x|y|z!cint|ptr cint|cstring|cchar|ptr cstring")
|
||||||
|
checkPragmas(GPU_Target, pHeaderBy, istype = false)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue