diff options
author | Clyybber <darkmine956@gmail.com> | 2020-09-05 22:01:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-05 22:01:47 +0200 |
commit | 35ff17410f303ce0434ef149f3e372d7243f41ab (patch) | |
tree | 9579d1f87b999641672bc01d39623f90397f7276 /compiler/ast.nim | |
parent | 70d62387568d55cd276472f28ce22ab8bafadf1c (diff) | |
download | Nim-35ff17410f303ce0434ef149f3e372d7243f41ab.tar.gz |
Expand hoisted default params in sem (#15270)
* Expand hoisted default params in sem Introduce ast.newTree{I,IT} Add test for default params in procs * Cleanup * Simplify hoist transformation and expand test
Diffstat (limited to 'compiler/ast.nim')
-rw-r--r-- | compiler/ast.nim | 78 |
1 files changed, 37 insertions, 41 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 23b564af3..b1a3a4a7b 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -312,10 +312,6 @@ const # the compiler will avoid printing such names # in user messages. - sfHoisted* = sfForward - # an expression was hoised to an anonymous variable. - # the flag is applied to the var/let symbol - sfNoForward* = sfRegister # forward declarations are not required (per module) sfReorder* = sfForward @@ -1121,12 +1117,49 @@ proc newNode*(kind: TNodeKind): PNode = writeStackTrace() inc gNodeId +proc newNodeI*(kind: TNodeKind, info: TLineInfo): PNode = + result = PNode(kind: kind, info: info) + when defined(useNodeIds): + result.id = gNodeId + if result.id == nodeIdToDebug: + echo "KIND ", result.kind + writeStackTrace() + inc gNodeId + +proc newNodeI*(kind: TNodeKind, info: TLineInfo, children: int): PNode = + result = PNode(kind: kind, info: info) + if children > 0: + newSeq(result.sons, children) + when defined(useNodeIds): + result.id = gNodeId + if result.id == nodeIdToDebug: + echo "KIND ", result.kind + writeStackTrace() + inc gNodeId + +proc newNodeIT*(kind: TNodeKind, info: TLineInfo, typ: PType): PNode = + result = newNode(kind) + result.info = info + result.typ = typ + proc newTree*(kind: TNodeKind; children: varargs[PNode]): PNode = result = newNode(kind) if children.len > 0: result.info = children[0].info result.sons = @children +proc newTreeI*(kind: TNodeKind; info: TLineInfo; children: varargs[PNode]): PNode = + result = newNodeI(kind, info) + if children.len > 0: + result.info = children[0].info + result.sons = @children + +proc newTreeIT*(kind: TNodeKind; info: TLineInfo; typ: PType; children: varargs[PNode]): PNode = + result = newNodeIT(kind, info, typ) + if children.len > 0: + result.info = children[0].info + result.sons = @children + template previouslyInferred*(t: PType): PType = if t.sons.len > 1: t.lastSon else: nil @@ -1227,43 +1260,6 @@ proc newSymNode*(sym: PSym, info: TLineInfo): PNode = result.typ = sym.typ result.info = info -proc newNodeI*(kind: TNodeKind, info: TLineInfo): PNode = - result = PNode(kind: kind, info: info) - when defined(useNodeIds): - result.id = gNodeId - if result.id == nodeIdToDebug: - echo "KIND ", result.kind - writeStackTrace() - inc gNodeId - -proc newNodeI*(kind: TNodeKind, info: TLineInfo, children: int): PNode = - result = PNode(kind: kind, info: info) - if children > 0: - newSeq(result.sons, children) - when defined(useNodeIds): - result.id = gNodeId - if result.id == nodeIdToDebug: - echo "KIND ", result.kind - writeStackTrace() - inc gNodeId - -proc newNode*(kind: TNodeKind, info: TLineInfo, sons: TNodeSeq = @[], - typ: PType = nil): PNode = - # XXX use shallowCopy here for ownership transfer: - result = PNode(kind: kind, info: info, typ: typ) - result.sons = sons - when defined(useNodeIds): - result.id = gNodeId - if result.id == nodeIdToDebug: - echo "KIND ", result.kind - writeStackTrace() - inc gNodeId - -proc newNodeIT*(kind: TNodeKind, info: TLineInfo, typ: PType): PNode = - result = newNode(kind) - result.info = info - result.typ = typ - proc newIntNode*(kind: TNodeKind, intVal: BiggestInt): PNode = result = newNode(kind) result.intVal = intVal |