diff --git a/compiler/ast.nim b/compiler/ast.nim index 2cdf40a8f24c..733f60090413 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1020,6 +1020,10 @@ const skProcKinds* = {skProc, skFunc, skTemplate, skMacro, skIterator, skMethod, skConverter} + defaultSize = -1 + defaultAlignment = -1 + defaultOffset = -1 + var ggDebug* {.deprecated.}: bool ## convenience switch for trying out things #var # gMainPackageId*: int @@ -1066,12 +1070,7 @@ when defined(useNodeIds): var gNodeId: int proc newNode*(kind: TNodeKind): PNode = - new(result) - result.kind = kind - #result.info = UnknownLineInfo() inlined: - result.info.fileIndex = InvalidFileIdx - result.info.col = int16(-1) - result.info.line = uint16(0) + result = PNode(kind: kind, info: unknownLineInfo) when defined(useNodeIds): result.id = gNodeId if result.id == nodeIdToDebug: @@ -1091,15 +1090,8 @@ template previouslyInferred*(t: PType): PType = proc newSym*(symKind: TSymKind, name: PIdent, owner: PSym, info: TLineInfo; options: TOptions = {}): PSym = # generates a symbol and initializes the hash field too - new(result) - result.name = name - result.kind = symKind - result.flags = {} - result.info = info - result.options = options - result.owner = owner - result.offset = -1 - result.id = getID() + result = PSym(name: name, kind: symKind, flags: {}, info: info, id: getID(), + options: options, owner: owner, offset: defaultOffset) when debugIds: registerId(result) @@ -1193,9 +1185,7 @@ proc newSymNode*(sym: PSym, info: TLineInfo): PNode = result.info = info proc newNodeI*(kind: TNodeKind, info: TLineInfo): PNode = - new(result) - result.kind = kind - result.info = info + result = PNode(kind: kind, info: info) when defined(useNodeIds): result.id = gNodeId if result.id == nodeIdToDebug: @@ -1204,9 +1194,7 @@ proc newNodeI*(kind: TNodeKind, info: TLineInfo): PNode = inc gNodeId proc newNodeI*(kind: TNodeKind, info: TLineInfo, children: int): PNode = - new(result) - result.kind = kind - result.info = info + result = PNode(kind: kind, info: info) if children > 0: newSeq(result.sons, children) when defined(useNodeIds): @@ -1217,12 +1205,9 @@ proc newNodeI*(kind: TNodeKind, info: TLineInfo, children: int): PNode = inc gNodeId proc newNode*(kind: TNodeKind, info: TLineInfo, sons: TNodeSeq = @[], - typ: PType = nil): PNode = - new(result) - result.kind = kind - result.info = info - result.typ = typ + 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 @@ -1321,14 +1306,10 @@ proc `$`*(s: PSym): string = result = "" proc newType*(kind: TTypeKind, owner: PSym): PType = - new(result) - result.kind = kind - result.owner = owner - result.size = -1 - result.align = -1 # default alignment - result.id = getID() - result.uniqueId = result.id - result.lockLevel = UnspecifiedLockLevel + let id = getID() + result = PType(kind: kind, owner: owner, size: defaultSize, + align: defaultAlignment, id: id, uniqueId: id, + lockLevel: UnspecifiedLockLevel) when debugIds: registerId(result) when false: @@ -1543,6 +1524,51 @@ proc copyNode*(src: PNode): PNode = of nkStrLit..nkTripleStrLit: result.strVal = src.strVal else: discard +template transitionNodeKindCommon(k: TNodeKind) = + let obj {.inject.} = n[] + n[] = TNode(kind: k, typ: obj.typ, info: obj.info, flags: obj.flags, + comment: obj.comment) + when defined(useNodeIds): + n.id = obj.id + +proc transitionSonsKind*(n: PNode, kind: range[nkComesFrom..nkTupleConstr]) = + transitionNodeKindCommon(kind) + n.sons = obj.sons + +proc transitionIntKind*(n: PNode, kind: range[nkCharLit..nkUInt64Lit]) = + transitionNodeKindCommon(kind) + n.intVal = obj.intVal + +proc transitionNoneToSym*(n: PNode) = + transitionNodeKindCommon(nkSym) + +template transitionSymKindCommon*(k: TSymKind) = + let obj {.inject.} = s[] + s[] = TSym(kind: k, id: obj.id, magic: obj.magic, typ: obj.typ, name: obj.name, + info: obj.info, owner: obj.owner, flags: obj.flags, ast: obj.ast, + options: obj.options, position: obj.position, offset: obj.offset, + loc: obj.loc, annex: obj.annex, constraint: obj.constraint) + when hasFFI: + s.cname = obj.cname + when defined(nimsuggest): + s.allUsages = obj.allUsages + +proc transitionGenericParamToType*(s: PSym) = + transitionSymKindCommon(skType) + s.typeInstCache = obj.typeInstCache + +proc transitionRoutineSymKind*(s: PSym, kind: range[skProc..skTemplate]) = + transitionSymKindCommon(kind) + s.procInstCache = obj.procInstCache + s.gcUnsafetyReason = obj.gcUnsafetyReason + s.transformedBody = obj.transformedBody + +proc transitionToLet*(s: PSym) = + transitionSymKindCommon(skLet) + s.guard = obj.guard + s.bitsize = obj.bitsize + s.alignment = obj.alignment + proc shallowCopy*(src: PNode): PNode = # does not copy its sons, but provides space for them: if src == nil: return nil diff --git a/compiler/canonicalizer.nim b/compiler/canonicalizer.nim index 76c2872f7e3c..de0d0f30e66e 100644 --- a/compiler/canonicalizer.nim +++ b/compiler/canonicalizer.nim @@ -282,7 +282,7 @@ proc encodeType(w: PRodWriter, t: PType, result: var string) = result.add('+') encodeVInt(t.id, result) if t.n != nil: - encodeNode(w, unknownLineInfo(), t.n, result) + encodeNode(w, unknownLineInfo, t.n, result) if t.flags != {}: result.add('$') encodeVInt(cast[int32](t.flags), result) @@ -364,7 +364,7 @@ proc encodeSym(w: PRodWriter, s: PSym, result: var string) = if s.annex != nil: encodeLib(w, s.annex, s.info, result) if s.constraint != nil: result.add('#') - encodeNode(w, unknownLineInfo(), s.constraint, result) + encodeNode(w, unknownLineInfo, s.constraint, result) # lazy loading will soon reload the ast lazily, so the ast needs to be # the last entry of a symbol: if s.ast != nil: diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index fb29a99076c2..87a936048ef1 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1457,7 +1457,7 @@ proc genArrToSeq(p: BProc, n: PNode, d: var TLoc) = genAssignment(p, elem, arr, {needToCopy}) else: var i: TLoc - getTemp(p, getSysType(p.module.g.graph, unknownLineInfo(), tyInt), i) + getTemp(p, getSysType(p.module.g.graph, unknownLineInfo, tyInt), i) linefmt(p, cpsStmts, "for ($1 = 0; $1 < $2; $1++) {$n", [i.r, L]) initLoc(elem, locExpr, lodeTyp elemType(skipTypes(n.typ, abstractInst)), OnHeap) elem.r = ropecg(p.module, "$1$3[$2]", [rdLoc(d), rdLoc(i), dataField(p)]) @@ -1847,10 +1847,10 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) = initLocExpr(p, e[1], a) putIntoDest(p, d, e, ropecg(p.module, "#cardSet($1, $2)", [rdCharLoc(a), size])) of mLtSet, mLeSet: - getTemp(p, getSysType(p.module.g.graph, unknownLineInfo(), tyInt), i) # our counter + getTemp(p, getSysType(p.module.g.graph, unknownLineInfo, tyInt), i) # our counter initLocExpr(p, e[1], a) initLocExpr(p, e[2], b) - if d.k == locNone: getTemp(p, getSysType(p.module.g.graph, unknownLineInfo(), tyBool), d) + if d.k == locNone: getTemp(p, getSysType(p.module.g.graph, unknownLineInfo, tyBool), d) if op == mLtSet: linefmt(p, cpsStmts, lookupOpr[mLtSet], [rdLoc(i), size, rdLoc(d), rdLoc(a), rdLoc(b)]) @@ -1866,7 +1866,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) = putIntoDest(p, d, e, ropecg(p.module, "(#nimCmpMem($1, $2, $3)==0)", [a.rdCharLoc, b.rdCharLoc, size])) of mMulSet, mPlusSet, mMinusSet, mSymDiffSet: # we inline the simple for loop for better code generation: - getTemp(p, getSysType(p.module.g.graph, unknownLineInfo(), tyInt), i) # our counter + getTemp(p, getSysType(p.module.g.graph, unknownLineInfo, tyInt), i) # our counter initLocExpr(p, e[1], a) initLocExpr(p, e[2], b) if d.k == locNone: getTemp(p, setType, d) @@ -2319,7 +2319,7 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) = [rdLoc(d), getTypeDesc(p.module, e.typ)]) for it in e.sons: if it.kind == nkRange: - getTemp(p, getSysType(p.module.g.graph, unknownLineInfo(), tyInt), idx) # our counter + getTemp(p, getSysType(p.module.g.graph, unknownLineInfo, tyInt), idx) # our counter initLocExpr(p, it[0], a) initLocExpr(p, it[1], b) lineF(p, cpsStmts, "for ($1 = $3; $1 <= $4; $1++) $n" & @@ -2335,7 +2335,7 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) = lineF(p, cpsStmts, "$1 = 0;$n", [rdLoc(d)]) for it in e.sons: if it.kind == nkRange: - getTemp(p, getSysType(p.module.g.graph, unknownLineInfo(), tyInt), idx) # our counter + getTemp(p, getSysType(p.module.g.graph, unknownLineInfo, tyInt), idx) # our counter initLocExpr(p, it[0], a) initLocExpr(p, it[1], b) lineF(p, cpsStmts, "for ($1 = $3; $1 <= $4; $1++) $n" & diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 30444e2aaa1a..ec13b991d277 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -558,7 +558,7 @@ proc genComputedGoto(p: BProc; n: PNode) = let it = n[j] if it.kind in {nkLetSection, nkVarSection}: let asgn = copyNode(it) - asgn.kind = nkAsgn + asgn.transitionSonsKind(nkAsgn) asgn.sons.setLen 2 for sym, value in it.fieldValuePairs: if value.kind != nkEmpty: diff --git a/compiler/ccgtrav.nim b/compiler/ccgtrav.nim index 510f81557791..63b1cb88a6df 100644 --- a/compiler/ccgtrav.nim +++ b/compiler/ccgtrav.nim @@ -75,7 +75,7 @@ proc genTraverseProc(c: TTraversalClosure, accessor: Rope, typ: PType) = of tyArray: let arraySize = lengthOrd(c.p.config, typ[0]) var i: TLoc - getTemp(p, getSysType(c.p.module.g.graph, unknownLineInfo(), tyInt), i) + getTemp(p, getSysType(c.p.module.g.graph, unknownLineInfo, tyInt), i) let oldCode = p.s(cpsStmts) linefmt(p, cpsStmts, "for ($1 = 0; $1 < $2; $1++) {$n", [i.r, arraySize]) @@ -119,7 +119,7 @@ proc genTraverseProcSeq(c: TTraversalClosure, accessor: Rope, typ: PType) = var p = c.p assert typ.kind == tySequence var i: TLoc - getTemp(p, getSysType(c.p.module.g.graph, unknownLineInfo(), tyInt), i) + getTemp(p, getSysType(c.p.module.g.graph, unknownLineInfo, tyInt), i) let oldCode = p.s(cpsStmts) var a: TLoc a.r = accessor diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 9a1f8cc46beb..56f227e37210 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -696,7 +696,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = var etB = et.skipTypes(abstractInst) if mapType(m.config, t) == ctPtrToArray: if etB.kind == tySet: - et = getSysType(m.g.graph, unknownLineInfo(), tyUInt8) + et = getSysType(m.g.graph, unknownLineInfo, tyUInt8) else: et = elemType(etB) etB = et.skipTypes(abstractInst) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index ee4634aad024..a36b6aa298ba 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -480,7 +480,7 @@ proc getIntTemp(p: BProc, result: var TLoc) = linefmt(p, cpsLocals, "NI $1;$n", [result.r]) result.k = locTemp result.storage = OnStack - result.lode = lodeTyp getSysType(p.module.g.graph, unknownLineInfo(), tyInt) + result.lode = lodeTyp getSysType(p.module.g.graph, unknownLineInfo, tyInt) result.flags = {} proc localVarDecl(p: BProc; n: PNode): Rope = diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim index f1fb1716a018..a71ac6ea7434 100644 --- a/compiler/cgmeth.nim +++ b/compiler/cgmeth.nim @@ -230,9 +230,9 @@ proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet): PS var paramLen = base.typ.len var nilchecks = newNodeI(nkStmtList, base.info) var disp = newNodeI(nkIfStmt, base.info) - var ands = getSysMagic(g, unknownLineInfo(), "and", mAnd) - var iss = getSysMagic(g, unknownLineInfo(), "of", mOf) - let boolType = getSysType(g, unknownLineInfo(), tyBool) + var ands = getSysMagic(g, unknownLineInfo, "and", mAnd) + var iss = getSysMagic(g, unknownLineInfo, "of", mOf) + let boolType = getSysType(g, unknownLineInfo, tyBool) for col in 1..=% conf.m.msgContext.len: result = unknownLineInfo() + if i >=% conf.m.msgContext.len: result = unknownLineInfo else: result = conf.m.msgContext[i].info const @@ -405,14 +405,14 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) = case msg of errMin..errMax: sev = Severity.Error - writeContext(conf, unknownLineInfo()) + writeContext(conf, unknownLineInfo) title = ErrorTitle color = ErrorColor of warnMin..warnMax: sev = Severity.Warning if optWarns notin conf.options: return if msg notin conf.notes: return - writeContext(conf, unknownLineInfo()) + writeContext(conf, unknownLineInfo) title = WarningTitle color = WarningColor kind = WarningsToStr[ord(msg) - ord(warnMin)] @@ -428,7 +428,7 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) = let s = msgKindToString(msg) % args if conf.structuredErrorHook != nil: - conf.structuredErrorHook(conf, unknownLineInfo(), + conf.structuredErrorHook(conf, unknownLineInfo, s & (if kind.len > 0: KindFormat % kind else: ""), sev) if not ignoreMsgBecauseOfIdeTools(conf, msg): @@ -561,7 +561,7 @@ proc internalError*(conf: ConfigRef; info: TLineInfo, errMsg: string) = proc internalError*(conf: ConfigRef; errMsg: string) = if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return - writeContext(conf, unknownLineInfo()) + writeContext(conf, unknownLineInfo) rawMessage(conf, errInternal, errMsg) template assertNotNil*(conf: ConfigRef; e): untyped = diff --git a/compiler/nim.cfg b/compiler/nim.cfg index 05f4ed5e9d40..f913e76a3b0e 100644 --- a/compiler/nim.cfg +++ b/compiler/nim.cfg @@ -15,7 +15,6 @@ define:nimcore @end define:useStdoutAsStdmsg -define:nimOldCaseObjects @if nimHasStyleChecks: styleCheck:error @@ -23,7 +22,3 @@ define:nimOldCaseObjects #define:useNodeIds #gc:markAndSweep - -@if nimHasWarningCaseTransition: -warning[CaseTransition]:off -@end diff --git a/compiler/nimblecmd.nim b/compiler/nimblecmd.nim index c84a0f3c28a3..fbc3fcee1916 100644 --- a/compiler/nimblecmd.nim +++ b/compiler/nimblecmd.nim @@ -147,16 +147,16 @@ when isMainModule: let conf = newConfigRef() var rr = newStringTable() - addPackage conf, rr, "irc-#a111", unknownLineInfo() - addPackage conf, rr, "irc-#head", unknownLineInfo() - addPackage conf, rr, "irc-0.1.0", unknownLineInfo() - #addPackage conf, rr, "irc", unknownLineInfo() - #addPackage conf, rr, "another", unknownLineInfo() - addPackage conf, rr, "another-0.1", unknownLineInfo() - - addPackage conf, rr, "ab-0.1.3", unknownLineInfo() - addPackage conf, rr, "ab-0.1", unknownLineInfo() - addPackage conf, rr, "justone-1.0", unknownLineInfo() + addPackage conf, rr, "irc-#a111", unknownLineInfo + addPackage conf, rr, "irc-#head", unknownLineInfo + addPackage conf, rr, "irc-0.1.0", unknownLineInfo + #addPackage conf, rr, "irc", unknownLineInfo + #addPackage conf, rr, "another", unknownLineInfo + addPackage conf, rr, "another-0.1", unknownLineInfo + + addPackage conf, rr, "ab-0.1.3", unknownLineInfo + addPackage conf, rr, "ab-0.1", unknownLineInfo + addPackage conf, rr, "justone-1.0", unknownLineInfo doAssert toSeq(rr.chosen) == @["irc-#head", "another-0.1", "ab-0.1.3", "justone-1.0"] diff --git a/compiler/parser.nim b/compiler/parser.nim index cf95eb26cf80..4ea751057161 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -427,7 +427,7 @@ proc exprColonEqExprListAux(p: var TParser, endTok: TTokType, result: PNode) = getTok(p) # (1,) produces a tuple expression if endTok == tkParRi and p.tok.tokType == tkParRi and result.kind == nkPar: - result.kind = nkTupleConstr + result.transitionSonsKind(nkTupleConstr) skipComment(p, a) optPar(p) eat(p, endTok) @@ -472,12 +472,12 @@ proc setOrTableConstr(p: var TParser): PNode = optInd(p, result) if p.tok.tokType == tkColon: getTok(p) # skip ':' - result.kind = nkTableConstr + result.transitionSonsKind(nkTableConstr) else: # progress guaranteed while p.tok.tokType notin {tkCurlyRi, tkEof}: var a = exprColonEqExpr(p) - if a.kind == nkExprColonExpr: result.kind = nkTableConstr + if a.kind == nkExprColonExpr: result.transitionSonsKind(nkTableConstr) result.add(a) if p.tok.tokType != tkComma: break getTok(p) @@ -534,7 +534,7 @@ proc semiStmtList(p: var TParser, result: PNode) = optInd(p, result) result.add(complexOrSimpleStmt(p)) dec p.inSemiStmtList - result.kind = nkStmtListExpr + result.transitionSonsKind(nkStmtListExpr) proc parsePar(p: var TParser): PNode = #| parKeyw = 'discard' | 'include' | 'if' | 'while' | 'case' | 'try' @@ -595,7 +595,7 @@ proc parsePar(p: var TParser): PNode = skipComment(p, a) # (1,) produces a tuple expression: if p.tok.tokType == tkParRi: - result.kind = nkTupleConstr + result.transitionSonsKind(nkTupleConstr) # progress guaranteed while p.tok.tokType != tkParRi and p.tok.tokType != tkEof: var a = exprColonEqExpr(p) @@ -778,7 +778,7 @@ proc primarySuffix(p: var TParser, r: PNode, break result = namedParams(p, result, nkCall, tkParRi) if result.len > 1 and result[1].kind == nkExprColonExpr: - result.kind = nkObjConstr + result.transitionSonsKind(nkObjConstr) of tkDot: # progress guaranteed result = dotExpr(p, result) @@ -1275,8 +1275,8 @@ proc primary(p: var TParser, mode: TPrimaryMode): PNode = of tkFunc: result = parseProcExpr(p, mode notin {pmTypeDesc, pmTypeDef}, nkFuncDef) of tkIterator: result = parseProcExpr(p, mode notin {pmTypeDesc, pmTypeDef}, nkLambda) - if result.kind == nkLambda: result.kind = nkIteratorDef - else: result.kind = nkIteratorTy + if result.kind == nkLambda: result.transitionSonsKind(nkIteratorDef) + else: result.transitionSonsKind(nkIteratorTy) of tkEnum: if mode == pmTypeDef: prettySection: @@ -1479,7 +1479,7 @@ proc parseImport(p: var TParser, kind: TNodeKind): PNode = result.add(a) if p.tok.tokType in {tkComma, tkExcept}: if p.tok.tokType == tkExcept: - result.kind = succ(kind) + result.transitionSonsKind(succ(kind)) getTok(p) optInd(p, result) while true: diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 0004fe94b024..ab0af80ea711 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -736,7 +736,7 @@ proc semCustomPragma(c: PContext, n: PNode): PNode = result = result[0] elif n.kind == nkExprColonExpr and r.len == 2: # pragma(arg) -> pragma: arg - result.kind = n.kind + result.transitionSonsKind(n.kind) proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, validPragmas: TSpecialWords, diff --git a/compiler/rodimpl.nim b/compiler/rodimpl.nim index d79dd1deb554..7a0f6fcef8d9 100644 --- a/compiler/rodimpl.nim +++ b/compiler/rodimpl.nim @@ -173,7 +173,7 @@ proc encodeLoc(g: ModuleGraph; loc: TLoc, result: var string) = encodeVInt(cast[int32](loc.flags), result) if loc.lode != nil: result.add('^') - encodeNode(g, unknownLineInfo(), loc.lode, result) + encodeNode(g, unknownLineInfo, loc.lode, result) if loc.r != nil: result.add('!') encodeStr($loc.r, result) @@ -200,7 +200,7 @@ proc encodeType(g: ModuleGraph, t: PType, result: var string) = result.add('+') encodeVInt(t.id, result) if t.n != nil: - encodeNode(g, unknownLineInfo(), t.n, result) + encodeNode(g, unknownLineInfo, t.n, result) if t.flags != {}: result.add('$') encodeVInt(cast[int32](t.flags), result) @@ -318,7 +318,7 @@ proc encodeSym(g: ModuleGraph, s: PSym, result: var string) = if s.annex != nil: encodeLib(g, s.annex, s.info, result) if s.constraint != nil: result.add('#') - encodeNode(g, unknownLineInfo(), s.constraint, result) + encodeNode(g, unknownLineInfo, s.constraint, result) case s.kind of skType, skGenericParam: for t in s.typeInstCache: @@ -605,7 +605,7 @@ proc loadType(g; id: int; info: TLineInfo): PType = result.id = result.uniqueId # here this also avoids endless recursion for recursive type g.incr.r.types.add(result.uniqueId, result) - if b.s[b.pos] == '(': result.n = decodeNode(g, b, unknownLineInfo()) + if b.s[b.pos] == '(': result.n = decodeNode(g, b, unknownLineInfo) if b.s[b.pos] == '$': inc(b.pos) result.flags = cast[TTypeFlags](int32(decodeVInt(b.s, b.pos))) @@ -752,7 +752,7 @@ proc loadSymFromBlob(g; b; info: TLineInfo): PSym = result.annex = decodeLib(g, b, info) if b.s[b.pos] == '#': inc(b.pos) - result.constraint = decodeNode(g, b, unknownLineInfo()) + result.constraint = decodeNode(g, b, unknownLineInfo) case result.kind of skType, skGenericParam: while b.s[b.pos] == '\14': diff --git a/compiler/sem.nim b/compiler/sem.nim index 7fdd83bdd92c..7cd0aa6f2079 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -416,7 +416,7 @@ proc semAfterMacroCall(c: PContext, call, macroResult: PNode, # More restrictive version. result = semExprWithType(c, result, flags) of tyTypeDesc: - if result.kind == nkStmtList: result.kind = nkStmtListType + if result.kind == nkStmtList: result.transitionSonsKind(nkStmtListType) var typ = semTypeNode(c, result, nil) if typ == nil: localError(c.config, result.info, "expression has no type: " & diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 3662b397c398..cbdb5ce77c9e 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -884,7 +884,7 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode = if n0.kind == nkDotCall: # it is a static call! result = n0 - result.kind = nkCall + result.transitionSonsKind(nkCall) result.flags.incl nfExplicitCall for i in 1.. lastOrd(c.config, desttyp): return true of tyUInt..tyUInt64: - if dest.kind != rkInt: - myreset(dest); dest.kind = rkInt + dest.ensureKind(rkInt) case skipTypes(srctyp, abstractRange).kind of tyFloat..tyFloat64: dest.intVal = int(src.floatVal) @@ -484,8 +464,7 @@ proc opConv(c: PCtx; dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType): value = (value shl destDist) shr destDist dest.intVal = cast[BiggestInt](value) of tyFloat..tyFloat64: - if dest.kind != rkFloat: - myreset(dest); dest.kind = rkFloat + dest.ensureKind(rkFloat) case skipTypes(srctyp, abstractRange).kind of tyInt..tyInt64, tyUInt..tyUInt64, tyEnum, tyBool, tyChar: dest.floatVal = toBiggestFloat(src.intVal) @@ -1206,8 +1185,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = var rcAddr = addr(regs[rc]) if rcAddr.kind == rkRegisterAddr: rcAddr = rcAddr.regAddr elif regs[rc].kind != rkFloat: - myreset(regs[rc]) - regs[rc].kind = rkFloat + regs[rc] = TFullReg(kind: rkFloat) regs[ra].intVal = parseBiggestFloat(regs[rb].node.strVal, rcAddr.floatVal, regs[rd].intVal.int) of opcRangeChck: @@ -1267,8 +1245,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = for i in 1..rc-1: newFrame.slots[i] = regs[rb+i] if isClosure: - newFrame.slots[rc].kind = rkNode - newFrame.slots[rc].node = regs[rb].node[1] + newFrame.slots[rc] = TFullReg(kind: rkNode, node: regs[rb].node[1]) tos = newFrame move(regs, newFrame.slots) # -1 for the following 'inc pc' @@ -1432,7 +1409,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = let rb = instr.regBx - wordExcess let cnst = c.constants[rb] if fitsRegister(cnst.typ): - myreset(regs[ra]) + reset(regs[ra]) putIntoReg(regs[ra], cnst) else: ensureKind(rkNode) @@ -2259,13 +2236,12 @@ proc setupMacroParam(x: PNode, typ: PType): TFullReg = of tyStatic: putIntoReg(result, prepareVMValue(x)) else: - result.kind = rkNode var n = x if n.kind in {nkHiddenSubConv, nkHiddenStdConv}: n = n[1] n = n.canonValue n.flags.incl nfIsRef n.typ = x.typ - result.node = n + result = TFullReg(kind: rkNode, node: n) iterator genericParamsInMacroCall*(macroSym: PSym, call: PNode): (PSym, PNode) = let gp = macroSym.ast[genericParamsPos] @@ -2317,8 +2293,7 @@ proc evalMacroCall*(module: PSym; g: ModuleGraph; #InternalAssert tos.slots.len >= L # return value: - tos.slots[0].kind = rkNode - tos.slots[0].node = newNodeI(nkEmpty, n.info) + tos.slots[0] = TFullReg(kind: rkNode, node: newNodeI(nkEmpty, n.info)) # setup parameters: for i in 1..= result.len: setLen(result.sons, pos + 1) let fieldNode = newNode(nkExprColonExpr) - fieldNode.add newSymNode(newSym(skField, ident, nil, unknownLineInfo())) + fieldNode.add newSymNode(newSym(skField, ident, nil, unknownLineInfo)) fieldNode.add loadAny(p, field.typ, tab, cache, conf) result[pos] = fieldNode if p.kind == jsonObjectEnd: next(p) diff --git a/nimpretty/nimpretty.nim.cfg b/nimpretty/nimpretty.nim.cfg index 138bce52e22f..25336d924e11 100644 --- a/nimpretty/nimpretty.nim.cfg +++ b/nimpretty/nimpretty.nim.cfg @@ -1,2 +1 @@ --define: nimpretty ---define: nimOldCaseObjects diff --git a/nimsuggest/nimsuggest.nim.cfg b/nimsuggest/nimsuggest.nim.cfg index 302c309654b8..394449740f89 100644 --- a/nimsuggest/nimsuggest.nim.cfg +++ b/nimsuggest/nimsuggest.nim.cfg @@ -22,4 +22,3 @@ define:nimcore #define:noDocgen --path:"$nim" --threads:on ---define:nimOldCaseObjects diff --git a/tests/compilerapi/tcompilerapi.nim.cfg b/tests/compilerapi/tcompilerapi.nim.cfg deleted file mode 100644 index 08e3312bec49..000000000000 --- a/tests/compilerapi/tcompilerapi.nim.cfg +++ /dev/null @@ -1 +0,0 @@ -define:nimOldCaseObjects