ast2 improve override/skip, duplicates

This commit is contained in:
Ganesh Viswanathan 2020-03-20 01:31:54 -05:00
commit f01c7ea60d
4 changed files with 304 additions and 206 deletions

View file

@ -8,8 +8,6 @@ import "."/treesitter/api
import "."/[globals, getters] import "."/[globals, getters]
# Move to getters after ast2 becomes default
proc getPtrType*(str: string): string = proc getPtrType*(str: string): string =
result = case str: result = case str:
of "cchar": of "cchar":
@ -20,6 +18,7 @@ proc getPtrType*(str: string): string =
str str
proc parseString(nimState: NimState, str: string): PNode = proc parseString(nimState: NimState, str: string): PNode =
# Parse a string into Nim AST
result = parseString(str, nimState.identCache, nimState.config) result = parseString(str, nimState.identCache, nimState.config)
proc getLit*(nimState: NimState, str: string): PNode = proc getLit*(nimState: NimState, str: string): PNode =
@ -51,70 +50,86 @@ proc getLit*(nimState: NimState, str: string): PNode =
result = newNode(nkNilLit) result = newNode(nkNilLit)
proc getOverrideOrSkip(nimState: NimState, node: TSNode, origname: string, kind: NimSymKind): PNode = proc getOverrideOrSkip(nimState: NimState, node: TSNode, origname: string, kind: NimSymKind): PNode =
# Check if symbol `origname` of `kind` and `origname` has any cOverride defined
# and use that if present
#
# If not, symbol needs to be skipped - only get here if `name` is blank
let let
# Get cleaned name for symbol, set parent so that cOverride is ignored
name = nimState.getIdentifier(origname, kind, parent = "override")
override = nimState.getOverride(origname, kind) override = nimState.getOverride(origname, kind)
def =
if kind == nskConst:
nkConstDef
elif kind == nskType:
nkTypeDef
else:
nkEmpty
skind = skind =
if kind == nskConst: if kind == nskConst:
"const " "const "
elif kind == nskType: elif kind == nskType:
"type " "type "
elif kind == nskProc:
"proc "
else: else:
"" ""
if override.nBl: if override.nBl:
result = newNode(def) result = nimState.parseString(skind & override.replace(origname, name))[0][0]
result.add nimState.parseString(nimState.getComments())
result.add nimState.parseString(skind & override)[0]
else: else:
result = nimState.parseString(nimState.getComments()) necho &"\n# $1'{origname}' skipped" % skind
result.add nimState.parseString(&" # $1'{origname}' skipped" % skind)
if nimState.gState.debug: if nimState.gState.debug:
nimState.skipStr &= &"\n{nimState.getNodeVal(node)}" nimState.skipStr &= &"\n{nimState.getNodeVal(node)}"
proc newConstDef(nimState: NimState, node: TSNode, fname = "", fval = ""): PNode = proc newConstDef(nimState: NimState, node: TSNode, fname = "", fval = ""): PNode =
# Create an nkConstDef PNode
#
# If `fname` or `fval` are set, use them as name and val
let let
# node[0] = identifier = const name # node[0] = identifier = const name
(name, origname, info) = nimState.getNameInfo(node.getAtom(), nskConst) (cname, origname, info) = nimState.getNameInfo(node.getAtom(), nskConst)
ident = name =
if fname.nBl: if fname.nBl:
nimState.getIdent(fname, info) fname
else: else:
nimState.getIdent(name, info) cname
ident = nimState.getIdent(name, info)
# node[1] = preproc_arg = value # node[1] = preproc_arg = value
val = val =
if fval.nBl:
fval
else:
nimState.getNodeVal(node[1])
valident =
if fval.nBl: if fval.nBl:
newStrNode(nkStrLit, fval) newStrNode(nkStrLit, fval)
else: else:
nimState.getLit(nimState.getNodeVal(node[1])) nimState.getLit(val)
if name.Bl and fname.Bl: if name.Bl:
# Name skipped or overridden since blank # Name skipped or overridden since blank
result = nimState.getOverrideOrSkip(node, origname, nskConst) result = nimState.getOverrideOrSkip(node, origname, nskConst)
elif val.kind != nkNilLit and nimState.addNewIdentifer(name): elif valident.kind != nkNilLit:
# const X* = Y if nimState.addNewIdentifer(name):
# # const X* = Y
# nkConstDef( #
# nkPostfix( # nkConstDef(
# nkIdent("*"), # nkPostfix(
# nkIdent("X") # nkIdent("*"),
# ), # nkIdent("X")
# nkEmpty(), # ),
# nkXLit(Y) # nkEmpty(),
# ) # nkXLit(Y)
result = newNode(nkConstDef) # )
result.add ident result = newNode(nkConstDef)
result.add newNode(nkEmpty) result.add ident
result.add val result.add newNode(nkEmpty)
result.add valident
else:
necho &"# const '{origname}' is duplicate, skipped"
else:
necho &"# const '{origname}' has invalid value '{val}'"
proc addConst(nimState: NimState, node: TSNode) = proc addConst(nimState: NimState, node: TSNode) =
# Add a const to the AST
#
# #define X Y # #define X Y
# #
# (preproc_def # (preproc_def
@ -195,7 +210,7 @@ proc newPragmaExpr(nimState: NimState, node: TSNode, ident: PNode, name: string,
result.add ident result.add ident
result.add nimState.newPragma(node, name, value) result.add nimState.newPragma(node, name, value)
proc newPragmaExpr(nimState: NimState, node: TSNode, ident: PNode, pragmas: OrderedTable[string, PNode]): PNode = proc newPragmaExpr(nimState: NimState, node: TSNode, ident: PNode, pragmas: OrderedTable[string, PNode]): PNode {.used.} =
# Create nkPragmaExpr tree for multiple name:value # Create nkPragmaExpr tree for multiple name:value
result = newNode(nkPragmaExpr) result = newNode(nkPragmaExpr)
result.add ident result.add ident
@ -206,13 +221,14 @@ proc newTypeIdent(nimState: NimState, node: TSNode, fname = "", union = false):
# #
# If `fname`, use it instead of node.getAtom() for name # If `fname`, use it instead of node.getAtom() for name
let let
(name, origname, info) = nimState.getNameInfo(node.getAtom(), nskType) (tname, origname, info) = nimState.getNameInfo(node.getAtom(), nskType)
ident = name =
if fname.nBl: if fname.nBl:
nimState.getIdent(fname, info) fname
else: else:
nimState.getIdent(name, info) tname
ident = nimState.getIdent(name, info)
prident = prident =
if union: if union:
@ -220,10 +236,10 @@ proc newTypeIdent(nimState: NimState, node: TSNode, fname = "", union = false):
else: else:
ident ident
if name.Bl and fname.Bl: if name.Bl:
# Name skipped or overridden since blank # Name skipped or overridden since blank
result = nimState.getOverrideOrSkip(node, origname, nskType) result = nimState.getOverrideOrSkip(node, origname, nskType)
else: elif nimState.addNewIdentifer(name):
# type name* = # type name* =
# #
# nkTypeDef( # nkTypeDef(
@ -236,6 +252,8 @@ proc newTypeIdent(nimState: NimState, node: TSNode, fname = "", union = false):
result = newNode(nkTypeDef) result = newNode(nkTypeDef)
result.add prident result.add prident
result.add newNode(nkEmpty) result.add newNode(nkEmpty)
else:
necho &"# type '{origname}' is duplicate, skipped"
proc newPtrTree(nimState: NimState, count: int, typ: PNode): PNode = proc newPtrTree(nimState: NimState, count: int, typ: PNode): PNode =
# Create nkPtrTy tree depending on count # Create nkPtrTy tree depending on count
@ -295,7 +313,7 @@ proc newArrayTree(nimState: NimState, node: TSNode, typ, size: PNode): PNode =
result.add size result.add size
result.add typ result.add typ
proc getTypeArray(nimState: NimState, node: TSNode): PNode proc getTypeArray(nimState: NimState, node: TSNode, name: string): PNode
proc getTypeProc(nimState: NimState, name: string, node: TSNode): PNode proc getTypeProc(nimState: NimState, name: string, node: TSNode): PNode
proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeInteger, exported = false): PNode = proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeInteger, exported = false): PNode =
@ -387,7 +405,7 @@ proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeIn
(pname, _, pinfo) = nimState.getNameInfo(node[start+1].getAtom(), nskField, parent = name) (pname, _, pinfo) = nimState.getNameInfo(node[start+1].getAtom(), nskField, parent = name)
pident = nimState.getIdent(pname, pinfo, exported) pident = nimState.getIdent(pname, pinfo, exported)
result.add pident result.add pident
result.add nimState.getTypeArray(node) result.add nimState.getTypeArray(node, name)
result.add newNode(nkEmpty) result.add newNode(nkEmpty)
else: else:
result = nil result = nil
@ -454,17 +472,20 @@ proc newRecListTree(nimState: NimState, name: string, node: TSNode): PNode =
if not field.isNil: if not field.isNil:
result.add field result.add field
proc addTypeObject(nimState: NimState, node: TSNode, fname = "", duplicate = "", union = false) = proc addTypeObject(nimState: NimState, node: TSNode, typeDef: PNode = nil, fname = "", union = false) =
# Add a type of object # Add a type of object
# #
# If `fname` is set, use it as the name # If `typeDef` is set, use it instead of creating new PNode
# If `duplicate` is set, don't add the same name # If `fname` is set, use it as the name when creating new PNode
decho("addTypeObject()") decho("addTypeObject()")
let let
typeDef = nimState.newTypeIdent(node, fname, union = union) typeDef =
name = $typeDef[0][1] if typeDef.isNil:
nimState.newTypeIdent(node, fname, union = union)
else:
typeDef
if name != duplicate: if not typeDef.isNil:
# type X* = object # type X* = object
# #
# nkTypeDef( # nkTypeDef(
@ -480,6 +501,7 @@ proc addTypeObject(nimState: NimState, node: TSNode, fname = "", duplicate = "",
# ) # )
# ) # )
let let
name = $typeDef[0][1]
obj = newNode(nkObjectTy) obj = newNode(nkObjectTy)
obj.add newNode(nkEmpty) obj.add newNode(nkEmpty)
obj.add newNode(nkEmpty) obj.add newNode(nkEmpty)
@ -499,72 +521,75 @@ proc addTypeObject(nimState: NimState, node: TSNode, fname = "", duplicate = "",
nimState.printDebug(typeDef) nimState.printDebug(typeDef)
proc addTypeTyped(nimState: NimState, node: TSNode, ftname = "", duplicate = "") = proc addTypeTyped(nimState: NimState, node: TSNode, ftname = "", offset = 0) =
# Add a type of a specified type # Add a type of a specified type
# #
# If `ftname` is set, use it as the type name # If `ftname` is set, use it as the type name
# If `duplicate` is set, don't add the same name # If `offset` is set, skip `offset` names, since created already
decho("addTypeTyped()") decho("addTypeTyped()")
let let
start = getStartAtom(node) start = getStartAtom(node)
for i in start+1 ..< node.len: for i in start+1+offset ..< node.len:
# Add a type of a specific type # Add a type of a specific type
let let
# node[i] = identifer = name # node[i] = identifer = name
typeDef = nimState.newTypeIdent(node[i]) typeDef = nimState.newTypeIdent(node[i])
name = $typeDef[0][1]
if not typeDef.isNil:
let
name = $typeDef[0][1]
# node[start] = identifier = type name # node[start] = identifier = type name
(tname0, _, tinfo) = nimState.getNameInfo(node[start].getAtom(), nskType, parent = name) (tname0, _, tinfo) = nimState.getNameInfo(node[start].getAtom(), nskType, parent = name)
# Override type name # Override type name
tname = tname =
if ftname.nBl: if ftname.nBl:
ftname ftname
else:
tname0
ident = nimState.getIdent(tname, tinfo, exported = false)
# node[i] could have nested pointers
count = node[i].getPtrCount()
# Skip typedef X X;
if $typeDef[0][1] != tname:
if count > 0:
# If pointers
typeDef.add nimState.newPtrTree(count, ident)
else: else:
tname0 typeDef.add ident
ident = nimState.getIdent(tname, tinfo, exported = false) # type X* = [ptr ..] Y
#
# nkTypeDef(
# nkPostfix(
# nkIdent("*"),
# nkIdent("X")
# ),
# nkEmpty(),
# nkPtrTy( # optional, nested
# nkIdent("Y")
# )
# )
# node[i] could have nested pointers # nkTypeSection.add
count = node[i].getPtrCount() nimState.typeSection.add typeDef
# Skip typedef X X; nimState.printDebug(typeDef)
if $typeDef[0][1] != tname:
if count > 0:
# If pointers
typeDef.add nimState.newPtrTree(count, ident)
else: else:
typeDef.add ident nimState.addTypeObject(node, typeDef = typeDef)
# type X* = [ptr ..] Y proc getTypeArray(nimState: NimState, node: TSNode, name: string): PNode =
#
# nkTypeDef(
# nkPostfix(
# nkIdent("*"),
# nkIdent("X")
# ),
# nkEmpty(),
# nkPtrTy( # optional, nested
# nkIdent("Y")
# )
# )
# nkTypeSection.add
nimState.typeSection.add typeDef
nimState.printDebug(typeDef)
else:
nimState.addTypeObject(node, duplicate = duplicate)
proc getTypeArray(nimState: NimState, node: TSNode): PNode =
# Create array type tree # Create array type tree
let let
start = getStartAtom(node) start = getStartAtom(node)
# node[start] = identifier = type name # node[start] = identifier = type name
(name, origname, info) = nimState.getNameInfo(node[start].getAtom(), nskType) (tname, _, info) = nimState.getNameInfo(node[start].getAtom(), nskType, parent = name)
ident = nimState.getIdent(name, info, exported = false) ident = nimState.getIdent(tname, info, exported = false)
# Top-most array declarator # Top-most array declarator
adecl = node[start+1].firstChildInTree("array_declarator") adecl = node[start+1].firstChildInTree("array_declarator")
@ -616,33 +641,36 @@ proc addTypeArray(nimState: NimState, node: TSNode) =
# node[1] = identifer = name # node[1] = identifer = name
typeDef = nimState.newTypeIdent(node[1]) typeDef = nimState.newTypeIdent(node[1])
typ = nimState.getTypeArray(node) if not typeDef.isNil:
let
name = $typeDef[0][1]
typ = nimState.getTypeArray(node, name)
typeDef.add typ typeDef.add typ
# type X* = [ptr] array[x, [ptr] Y] # type X* = [ptr] array[x, [ptr] Y]
# #
# nkTypeDef( # nkTypeDef(
# nkPostfix( # nkPostfix(
# nkIdent("*"), # nkIdent("*"),
# nkIdent("X") # nkIdent("X")
# ), # ),
# nkEmpty(), # nkEmpty(),
# nkPtrTy( # optional, nested # nkPtrTy( # optional, nested
# nkBracketExpr( # nkBracketExpr(
# nkIdent("array") # nkIdent("array")
# nkXLit(x), # nkXLit(x),
# nkPtrTy( # optional, nested # nkPtrTy( # optional, nested
# nkIdent("Y") # nkIdent("Y")
# ) # )
# ) # )
# ) # )
# ) # )
# nkTypeSection.add # nkTypeSection.add
nimState.typeSection.add typeDef nimState.typeSection.add typeDef
nimState.printDebug(typeDef) nimState.printDebug(typeDef)
proc getTypeProc(nimState: NimState, name: string, node: TSNode): PNode = proc getTypeProc(nimState: NimState, name: string, node: TSNode): PNode =
# Create proc type tree # Create proc type tree
@ -688,44 +716,47 @@ proc addTypeProc(nimState: NimState, node: TSNode) =
let let
# node[1] = identifier = name # node[1] = identifier = name
typeDef = nimState.newTypeIdent(node[1]) typeDef = nimState.newTypeIdent(node[1])
name = $typeDef[0][1]
procTy = nimState.getTypeProc(name, node) if not typeDef.isNil:
let
name = $typeDef[0][1]
typeDef.add procTy procTy = nimState.getTypeProc(name, node)
# type X* = proc(a1: Y, a2: Z): P typeDef.add procTy
#
# nkTypeDef(
# nkPostfix(
# nkIdent("*"),
# nkIdent("X")
# ),
# nkEmpty(),
# nkPtrTy( # optional, nested
# nkProcTy(
# nkFormalParams(
# nkPtrTy( # optional, nested
# nkIdent(retType)
# ),
# nkIdentDefs(
# nkIdent(param),
# nkPtrTy(
# nkIdent(ptype)
# ),
# nkEmpty()
# ),
# ...
# ),
# nkEmpty()
# )
# )
# )
# nkTypeSection.add # type X* = proc(a1: Y, a2: Z): P
nimState.typeSection.add typeDef #
# nkTypeDef(
# nkPostfix(
# nkIdent("*"),
# nkIdent("X")
# ),
# nkEmpty(),
# nkPtrTy( # optional, nested
# nkProcTy(
# nkFormalParams(
# nkPtrTy( # optional, nested
# nkIdent(retType)
# ),
# nkIdentDefs(
# nkIdent(param),
# nkPtrTy(
# nkIdent(ptype)
# ),
# nkEmpty()
# ),
# ...
# ),
# nkEmpty()
# )
# )
# )
nimState.printDebug(typeDef) # nkTypeSection.add
nimState.typeSection.add typeDef
nimState.printDebug(typeDef)
proc addType(nimState: NimState, node: TSNode, union = false) = proc addType(nimState: NimState, node: TSNode, union = false) =
decho("addType()") decho("addType()")
@ -897,7 +928,7 @@ proc addType(nimState: NimState, node: TSNode, union = false) =
if node.len > 1 and nimState.getNodeVal(node[1]) != "": if node.len > 1 and nimState.getNodeVal(node[1]) != "":
# Add any additional names # Add any additional names
nimState.addTypeTyped(node, duplicate = nimState.getNodeVal(node[0].getAtom())) nimState.addTypeTyped(node)
else: else:
# Same as above except unnamed struct # Same as above except unnamed struct
# #
@ -919,8 +950,8 @@ proc addType(nimState: NimState, node: TSNode, union = false) =
nimState.addTypeObject(node[0], fname = name, union = union) nimState.addTypeObject(node[0], fname = name, union = union)
if name.nBl: if name.nBl:
# Add any additional names except duplicate # Add any additional names
nimState.addTypeTyped(node, ftname = name, duplicate = name) nimState.addTypeTyped(node, ftname = name, offset = 1)
proc addEnum(nimState: NimState, node: TSNode) = proc addEnum(nimState: NimState, node: TSNode) =
decho("addEnum()") decho("addEnum()")
@ -935,67 +966,72 @@ proc addProc(nimState: NimState, node: TSNode) =
start = getStartAtom(node) start = getStartAtom(node)
# node[start+1] = identifier = name # node[start+1] = identifier = name
ident = nimState.newTypeIdent(node[start+1]) tident = nimState.newTypeIdent(node[start+1])
name = $ident[0][1]
if not tident.isNil:
let
# Only need the ident tree, not nkTypeDef parent
ident = tident[0]
name = $tident[0][1]
# node[start+1] could have nested pointers # node[start+1] could have nested pointers
tcount = node[start+1].getPtrCount() tcount = node[start+1].getPtrCount()
# node[start] = identifier = return type name # node[start] = identifier = return type name
(rname, _, rinfo) = nimState.getNameInfo(node[start].getAtom(), nskType, parent = name) (rname, _, rinfo) = nimState.getNameInfo(node[start].getAtom(), nskType, parent = name)
# Parameter list # Parameter list
plist = node[start+1].anyChildInTree("parameter_list") plist = node[start+1].anyChildInTree("parameter_list")
procDef = newNode(nkProcDef) procDef = newNode(nkProcDef)
# proc X(a1: Y, a2: Z): P {.pragma.} # proc X(a1: Y, a2: Z): P {.pragma.}
# #
# nkProcDef( # nkProcDef(
# nkPostfix( # nkPostfix(
# nkIdent("*"), # nkIdent("*"),
# nkIdent("X") # nkIdent("X")
# ), # ),
# nkEmpty(), # nkEmpty(),
# nkEmpty(), # nkEmpty(),
# nkFormalParams( # nkFormalParams(
# nkPtrTy( # optional, nested # nkPtrTy( # optional, nested
# nkIdent(retType) # nkIdent(retType)
# ), # ),
# nkIdentDefs( # nkIdentDefs(
# nkIdent(param), # nkIdent(param),
# nkPtrTy( # nkPtrTy(
# nkIdent(ptype) # nkIdent(ptype)
# ), # ),
# nkEmpty() # nkEmpty()
# ), # ),
# ... # ...
# ), # ),
# nkPragma(...), # nkPragma(...),
# nkEmpty(), # nkEmpty(),
# nkEmpty() # nkEmpty()
# ) # )
procDef.add ident procDef.add ident
procDef.add newNode(nkEmpty) procDef.add newNode(nkEmpty)
procDef.add newNode(nkEmpty) procDef.add newNode(nkEmpty)
# Return type # Return type
var var
retType = nimState.getIdent(rname, rinfo, exported = false) retType = nimState.getIdent(rname, rinfo, exported = false)
if tcount > 0: if tcount > 0:
retType = nimState.newPtrTree(tcount, retType) retType = nimState.newPtrTree(tcount, retType)
# Proc with return type and params # Proc with return type and params
procDef.add nimState.newFormalParams(name, plist, retType) procDef.add nimState.newFormalParams(name, plist, retType)
procDef.add newNode(nkEmpty) # Pragmas procDef.add newNode(nkEmpty) # Pragmas
procDef.add newNode(nkEmpty) procDef.add newNode(nkEmpty)
procDef.add newNode(nkEmpty) procDef.add newNode(nkEmpty)
# nkProcSection.add # nkProcSection.add
nimState.procSection.add procDef nimState.procSection.add procDef
nimState.printDebug(procDef) nimState.printDebug(procDef)
proc processNode(nimState: NimState, node: TSNode): bool = proc processNode(nimState: NimState, node: TSNode): bool =
result = true result = true

View file

@ -120,7 +120,8 @@ when not declared(CIMPORT):
gState.outputHandle.writeLine(args) gState.outputHandle.writeLine(args)
template necho*(args: string) {.dirty.} = template necho*(args: string) {.dirty.} =
let gState = nimState.gState when not declared(gState):
let gState = nimState.gState
gecho args gecho args
template decho*(str: untyped): untyped = template decho*(str: untyped): untyped =

View file

@ -1,3 +1,55 @@
#define A 1
#define B 1.0
#define C 0x10
#define D "hello"
#define E 'c'
struct A0;
struct A1 {};
typedef struct A2;
typedef struct A3 {};
typedef struct A4 A4, *A4p;
typedef const int A5;
typedef int *A6;
typedef A0 **A7;
typedef void *A8;
typedef char *A9p[3]; //, A9[4];
typedef char *A10[3][6];
typedef char *(*A11)[3];
typedef struct A1 *A111[12];
typedef int **(*A12)(int, int b, int *c, int *, int *count[4], int (*func)(int, int));
typedef int A13(int, int);
struct A14 { volatile char a1; };
struct A15 { char *a1; const int *a2[1]; };
typedef struct A16 { char f1; };
typedef struct A17 { char *a1; int *a2[1]; } A18, *A18p;
typedef struct { char *a1; int *a2[1]; } A19, *A19p;
typedef struct A20 { char a1; } A20, A21, *A21p;
//Expression
typedef struct A22 { int **f1; int *f2[123+132]; } A22;
//Unions
union U1 {int f1; float f2; };
typedef union U2 { int **f1; int abc[123+132]; } U2;
// Anonymous
//typedef struct { char a1; };
//struct A2 test_proc1(struct A0 a);
// DUPLICATES
#define A 1 #define A 1
#define B 1.0 #define B 1.0
@ -18,6 +70,7 @@ typedef void *A8;
typedef char *A9p[3]; //, A9[4]; typedef char *A9p[3]; //, A9[4];
typedef char *A10[3][6]; typedef char *A10[3][6];
typedef char *(*A11)[3]; typedef char *(*A11)[3];
typedef struct A1 *A111[12];
typedef int **(*A12)(int, int b, int *c, int *, int *count[4], int (*func)(int, int)); typedef int **(*A12)(int, int b, int *c, int *, int *count[4], int (*func)(int, int));
typedef int A13(int, int); typedef int A13(int, int);

View file

@ -5,6 +5,13 @@ import nimterop/[cimport]
static: static:
cDebug() cDebug()
cOverride:
const
A* = 2
type
A1* = A0
cImport("include/tast2.h", flags="-d -f:ast2") cImport("include/tast2.h", flags="-d -f:ast2")
proc testFields(t: typedesc, fields: Table[string, string] = initTable[string, string]()) = proc testFields(t: typedesc, fields: Table[string, string] = initTable[string, string]()) =
@ -18,7 +25,7 @@ proc testFields(t: typedesc, fields: Table[string, string] = initTable[string, s
"typeof(" & $t & ":" & name & ") != " & fields[name] & ", is " & $typeof(value) "typeof(" & $t & ":" & name & ") != " & fields[name] & ", is " & $typeof(value)
assert count == fields.len, "Failed for " & $t assert count == fields.len, "Failed for " & $t
assert A == 1 assert A == 2
assert B == 1.0 assert B == 1.0
assert C == 0x10 assert C == 0x10
assert D == "hello" assert D == "hello"
@ -26,7 +33,7 @@ assert E == 'c'
assert A0 is object assert A0 is object
testFields(A0) testFields(A0)
assert A1 is object assert A1 is A0
testFields(A1) testFields(A1)
assert A2 is object assert A2 is object
testFields(A2) testFields(A2)
@ -44,6 +51,7 @@ assert A9p is array[3, cstring]
#assert A9 is array[4, cchar] #assert A9 is array[4, cchar]
assert A10 is array[3, array[6, cstring]] assert A10 is array[3, array[6, cstring]]
assert A11 is ptr array[3, cstring] assert A11 is ptr array[3, cstring]
assert A111 is array[12, ptr A1]
assert A12 is proc(a1: cint, b: cint, c: ptr cint, a4: ptr cint, count: array[4, ptr cint], `func`: proc(a1: cint, a2: cint): cint): ptr ptr cint assert A12 is proc(a1: cint, b: cint, c: ptr cint, a4: ptr cint, count: array[4, ptr cint], `func`: proc(a1: cint, a2: cint): cint): ptr ptr cint
assert A13 is proc(a1: cint, a2: cint): cint assert A13 is proc(a1: cint, a2: cint): cint