Skip to content

Commit

Permalink
Merge #390
Browse files Browse the repository at this point in the history
390: internals: sigmatch comments and code style r=saem a=saem

## Summary
No behaviour changes, a few things should be more clear.

## Details
Added some `ast.newSymNode` overloads for convenience.


Co-authored-by: saem <saemghani+github@gmail.com>
  • Loading branch information
bors[bot] and saem authored Jul 31, 2022
2 parents 4b04405 + c757e69 commit 980b073
Show file tree
Hide file tree
Showing 3 changed files with 543 additions and 274 deletions.
19 changes: 10 additions & 9 deletions compiler/ast/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,18 @@ proc newSymNode2*(sym: PSym, info: TLineInfo): PNode =
result.typ = sym.typ
result.info = info

proc newSymNode*(sym: PSym): PNode =
result = newNode(nkSym)
proc newSymNodeIT*(sym: PSym, info: TLineInfo, typ: PType): PNode =
## create a new sym node with the supplied `info` and `typ`
result = newNodeIT(nkSym, info, typ)
result.sym = sym
result.typ = sym.typ
result.info = sym.info

proc newSymNode*(sym: PSym, info: TLineInfo): PNode =
result = newNode(nkSym)
result.sym = sym
result.typ = sym.typ
result.info = info
proc newSymNode*(sym: PSym, info: TLineInfo): PNode {.inline.} =
## create a new sym node from `sym` with its type and supplied `info`
result = newSymNodeIT(sym, info, sym.typ)

proc newSymNode*(sym: PSym): PNode {.inline.} =
## create a new sym node from `sym` with its info and type
result = newSymNode(sym, sym.info)

proc newIntNode*(kind: TNodeKind, intVal: BiggestInt): PNode =
result = newNode(kind)
Expand Down
17 changes: 12 additions & 5 deletions compiler/ast/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1163,13 +1163,20 @@ proc skipConvTakeType*(n: PNode): PNode =
result.typ = n.typ

proc isEmptyContainer*(t: PType): bool =
## true if the type is considered a container and is empty, otherwise false.
## container types are untyped, nil, `array/seq/set/etc[T]` with an emtpy
## type for `T`.
case t.kind
of tyUntyped, tyNil: result = true
of tyArray: result = t[1].kind == tyEmpty
of tyUntyped, tyNil:
true
of tyArray:
t[1].kind == tyEmpty
of tySet, tySequence, tyOpenArray, tyVarargs:
result = t[0].kind == tyEmpty
of tyGenericInst, tyAlias, tySink: result = isEmptyContainer(t.lastSon)
else: result = false
t[0].kind == tyEmpty
of tyGenericInst, tyAlias, tySink:
isEmptyContainer(t.lastSon)
else:
false

proc takeType*(formal, arg: PType; g: ModuleGraph; idgen: IdGenerator): PType =
# param: openArray[string] = []
Expand Down
Loading

0 comments on commit 980b073

Please sign in to comment.