compiler almost free of deprecated expr/stmt names

This commit is contained in:
Andreas Rumpf 2016-07-30 16:28:58 +02:00
commit 39ebe2175b
22 changed files with 55 additions and 55 deletions

View file

@ -990,12 +990,12 @@ proc add*(father, son: PNode) =
proc `[]`*(n: PNode, i: int): PNode {.inline.} = proc `[]`*(n: PNode, i: int): PNode {.inline.} =
result = n.sons[i] result = n.sons[i]
template `-|`*(b, s: expr): expr = template `-|`*(b, s: untyped): untyped =
(if b >= 0: b else: s.len + b) (if b >= 0: b else: s.len + b)
# son access operators with support for negative indices # son access operators with support for negative indices
template `{}`*(n: PNode, i: int): expr = n[i -| n] template `{}`*(n: PNode, i: int): untyped = n[i -| n]
template `{}=`*(n: PNode, i: int, s: PNode): stmt = template `{}=`*(n: PNode, i: int, s: PNode) =
n.sons[i -| n] = s n.sons[i -| n] = s
when defined(useNodeIds): when defined(useNodeIds):

View file

@ -113,7 +113,7 @@ proc genMergeInfo*(m: BModule): Rope =
s.add("*/") s.add("*/")
result = s.rope result = s.rope
template `^`(pos: int): expr = L.buf[pos] template `^`(pos: int): untyped = L.buf[pos]
proc skipWhite(L: var TBaseLexer) = proc skipWhite(L: var TBaseLexer) =
var pos = L.bufpos var pos = L.bufpos

View file

@ -129,7 +129,7 @@ proc ropecg(m: BModule, frmt: FormatStr, args: varargs[Rope]): Rope =
if i - 1 >= start: if i - 1 >= start:
add(result, substr(frmt, start, i - 1)) add(result, substr(frmt, start, i - 1))
template rfmt(m: BModule, fmt: string, args: varargs[Rope]): expr = template rfmt(m: BModule, fmt: string, args: varargs[Rope]): untyped =
ropecg(m, fmt, args) ropecg(m, fmt, args)
proc appcg(m: BModule, c: var Rope, frmt: FormatStr, proc appcg(m: BModule, c: var Rope, frmt: FormatStr,
@ -215,7 +215,7 @@ proc accessThreadLocalVar(p: BProc, s: PSym)
proc emulatedThreadVars(): bool {.inline.} proc emulatedThreadVars(): bool {.inline.}
proc genProc(m: BModule, prc: PSym) proc genProc(m: BModule, prc: PSym)
template compileToCpp(m: BModule): expr = template compileToCpp(m: BModule): untyped =
gCmd == cmdCompileToCpp or sfCompileToCpp in m.module.flags gCmd == cmdCompileToCpp or sfCompileToCpp in m.module.flags
include "ccgtypes.nim" include "ccgtypes.nim"

View file

@ -728,12 +728,12 @@ proc simpleSlice*(a, b: PNode): BiggestInt =
result = -1 result = -1
template isMul(x): expr = x.getMagic in someMul template isMul(x): untyped = x.getMagic in someMul
template isDiv(x): expr = x.getMagic in someDiv template isDiv(x): untyped = x.getMagic in someDiv
template isAdd(x): expr = x.getMagic in someAdd template isAdd(x): untyped = x.getMagic in someAdd
template isSub(x): expr = x.getMagic in someSub template isSub(x): untyped = x.getMagic in someSub
template isVal(x): expr = x.kind in {nkCharLit..nkUInt64Lit} template isVal(x): untyped = x.kind in {nkCharLit..nkUInt64Lit}
template isIntVal(x, y): expr = x.intVal == y template isIntVal(x, y): untyped = x.intVal == y
import macros import macros
@ -776,8 +776,8 @@ proc isMinusOne(n: PNode): bool =
proc pleViaModel(model: TModel; aa, bb: PNode): TImplication proc pleViaModel(model: TModel; aa, bb: PNode): TImplication
proc ple(m: TModel; a, b: PNode): TImplication = proc ple(m: TModel; a, b: PNode): TImplication =
template `<=?`(a,b): expr = ple(m,a,b) == impYes template `<=?`(a,b): untyped = ple(m,a,b) == impYes
template `>=?`(a,b): expr = ple(m, nkIntLit.newIntNode(b), a) == impYes template `>=?`(a,b): untyped = ple(m, nkIntLit.newIntNode(b), a) == impYes
# 0 <= 3 # 0 <= 3
if a.isValue and b.isValue: if a.isValue and b.isValue:

View file

@ -138,7 +138,7 @@ proc getLineInfo*(L: TLexer, tok: TToken): TLineInfo {.inline.} =
proc isKeyword*(kind: TTokType): bool = proc isKeyword*(kind: TTokType): bool =
result = (kind >= tokKeywordLow) and (kind <= tokKeywordHigh) result = (kind >= tokKeywordLow) and (kind <= tokKeywordHigh)
template ones(n: expr): expr = ((1 shl n)-1) # for utf-8 conversion template ones(n): untyped = ((1 shl n)-1) # for utf-8 conversion
proc isNimIdentifier*(s: string): bool = proc isNimIdentifier*(s: string): bool =
if s[0] in SymStartChars: if s[0] in SymStartChars:
@ -893,10 +893,10 @@ proc scanComment(L: var TLexer, tok: var TToken) =
inc(indent) inc(indent)
when defined(nimfix): when defined(nimfix):
template doContinue(): expr = template doContinue(): untyped =
buf[pos] == '#' and (col == indent or lastBackslash > 0) buf[pos] == '#' and (col == indent or lastBackslash > 0)
else: else:
template doContinue(): expr = template doContinue(): untyped =
buf[pos] == '#' and buf[pos+1] == '#' buf[pos] == '#' and buf[pos+1] == '#'
if doContinue(): if doContinue():
tok.literal.add "\n" tok.literal.add "\n"
@ -942,9 +942,9 @@ proc skip(L: var TLexer, tok: var TToken) =
break break
tok.strongSpaceA = 0 tok.strongSpaceA = 0
when defined(nimfix): when defined(nimfix):
template doBreak(): expr = buf[pos] > ' ' template doBreak(): untyped = buf[pos] > ' '
else: else:
template doBreak(): expr = template doBreak(): untyped =
buf[pos] > ' ' and (buf[pos] != '#' or buf[pos+1] == '#') buf[pos] > ' ' and (buf[pos] != '#' or buf[pos+1] == '#')
if doBreak(): if doBreak():
tok.indent = indent tok.indent = indent

View file

@ -217,14 +217,14 @@ when defined(nimfix):
of 'a'..'z': result = getIdent(toLower(x.s[0]) & x.s.substr(1)) of 'a'..'z': result = getIdent(toLower(x.s[0]) & x.s.substr(1))
else: result = x else: result = x
template fixSpelling(n: PNode; ident: PIdent; op: expr) = template fixSpelling(n: PNode; ident: PIdent; op: untyped) =
let alt = ident.altSpelling let alt = ident.altSpelling
result = op(c, alt).skipAlias(n) result = op(c, alt).skipAlias(n)
if result != nil: if result != nil:
prettybase.replaceDeprecated(n.info, ident, alt) prettybase.replaceDeprecated(n.info, ident, alt)
return result return result
else: else:
template fixSpelling(n: PNode; ident: PIdent; op: expr) = discard template fixSpelling(n: PNode; ident: PIdent; op: untyped) = discard
proc errorUseQualifier*(c: PContext; info: TLineInfo; s: PSym) = proc errorUseQualifier*(c: PContext; info: TLineInfo; s: PSym) =
var err = "Error: ambiguous identifier: '" & s.name.s & "'" var err = "Error: ambiguous identifier: '" & s.name.s & "'"

View file

@ -38,7 +38,7 @@ proc getModule*(fileIdx: int32): PSym =
if fileIdx >= 0 and fileIdx < gCompiledModules.len: if fileIdx >= 0 and fileIdx < gCompiledModules.len:
result = gCompiledModules[fileIdx] result = gCompiledModules[fileIdx]
template hash(x: PSym): expr = template hash(x: PSym): untyped =
gMemCacheData[x.position].hash gMemCacheData[x.position].hash
proc hashChanged(fileIdx: int32): bool = proc hashChanged(fileIdx: int32): bool =

View file

@ -121,7 +121,7 @@ proc toTreeSet(s: TBitSet, settype: PType, info: TLineInfo): PNode =
e = b e = b
inc(e) inc(e)
template nodeSetOp(a, b: PNode, op: expr) {.dirty.} = template nodeSetOp(a, b: PNode, op: untyped) {.dirty.} =
var x, y: TBitSet var x, y: TBitSet
toBitSet(a, x) toBitSet(a, x)
toBitSet(b, y) toBitSet(b, y)

View file

@ -202,7 +202,7 @@ proc isRightAssociative(tok: TToken): bool {.inline.} =
proc getPrecedence(tok: TToken, strongSpaces: bool): int = proc getPrecedence(tok: TToken, strongSpaces: bool): int =
## Calculates the precedence of the given token. ## Calculates the precedence of the given token.
template considerStrongSpaces(x): expr = template considerStrongSpaces(x): untyped =
x + (if strongSpaces: 100 - tok.strongSpaceA.int*10 else: 0) x + (if strongSpaces: 100 - tok.strongSpaceA.int*10 else: 0)
case tok.tokType case tok.tokType
@ -214,7 +214,7 @@ proc getPrecedence(tok: TToken, strongSpaces: bool): int =
if L > 1 and tok.ident.s[L-1] == '>' and if L > 1 and tok.ident.s[L-1] == '>' and
tok.ident.s[L-2] in {'-', '~', '='}: return considerStrongSpaces(1) tok.ident.s[L-2] in {'-', '~', '='}: return considerStrongSpaces(1)
template considerAsgn(value: expr) = template considerAsgn(value: untyped) =
result = if tok.ident.s[L-1] == '=': 1 else: value result = if tok.ident.s[L-1] == '=': 1 else: value
case relevantChar case relevantChar

View file

@ -64,7 +64,7 @@ const
const const
vintDelta = 5 vintDelta = 5
template encodeIntImpl(self: expr) = template encodeIntImpl(self) =
var d: char var d: char
var v = x var v = x
var rem = v mod 190 var rem = v mod 190

View file

@ -87,7 +87,7 @@ proc destroyCase(c: PContext, n: PNode, holder: PNode): PNode =
result = nil result = nil
proc destroyFieldOrFields(c: PContext, field: PNode, holder: PNode): PNode = proc destroyFieldOrFields(c: PContext, field: PNode, holder: PNode): PNode =
template maybeAddLine(e: expr): stmt = template maybeAddLine(e) =
let stmt = e let stmt = e
if stmt != nil: if stmt != nil:
if result == nil: result = newNode(nkStmtList) if result == nil: result = newNode(nkStmtList)

View file

@ -1363,7 +1363,7 @@ proc asgnToResultVar(c: PContext, n, le, ri: PNode) {.inline.} =
n.sons[1] = takeImplicitAddr(c, ri) n.sons[1] = takeImplicitAddr(c, ri)
x.typ.flags.incl tfVarIsPtr x.typ.flags.incl tfVarIsPtr
template resultTypeIsInferrable(typ: PType): expr = template resultTypeIsInferrable(typ: PType): untyped =
typ.isMetaType and typ.kind != tyTypeDesc typ.isMetaType and typ.kind != tyTypeDesc
proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode = proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
@ -1888,7 +1888,7 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode =
# the correct branch. Otherwise the AST will be passed through semStmt. # the correct branch. Otherwise the AST will be passed through semStmt.
result = nil result = nil
template setResult(e: expr) = template setResult(e: untyped) =
if semCheck: result = semExpr(c, e) # do not open a new scope! if semCheck: result = semExpr(c, e) # do not open a new scope!
else: result = e else: result = e

View file

@ -47,10 +47,10 @@ proc semGenericStmtScope(c: PContext, n: PNode,
result = semGenericStmt(c, n, flags, ctx) result = semGenericStmt(c, n, flags, ctx)
closeScope(c) closeScope(c)
template macroToExpand(s: expr): expr = template macroToExpand(s): untyped =
s.kind in {skMacro, skTemplate} and (s.typ.len == 1 or sfAllUntyped in s.flags) s.kind in {skMacro, skTemplate} and (s.typ.len == 1 or sfAllUntyped in s.flags)
template macroToExpandSym(s: expr): expr = template macroToExpandSym(s): untyped =
s.kind in {skMacro, skTemplate} and (s.typ.len == 1) s.kind in {skMacro, skTemplate} and (s.typ.len == 1)
proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym,

View file

@ -121,7 +121,7 @@ proc checkLocal(c: AnalysisCtx; n: PNode) =
else: else:
for i in 0 .. <n.safeLen: checkLocal(c, n.sons[i]) for i in 0 .. <n.safeLen: checkLocal(c, n.sons[i])
template `?`(x): expr = x.renderTree template `?`(x): untyped = x.renderTree
proc checkLe(c: AnalysisCtx; a, b: PNode) = proc checkLe(c: AnalysisCtx; a, b: PNode) =
case proveLe(c.guards, a, b) case proveLe(c.guards, a, b)

View file

@ -151,7 +151,7 @@ proc guardDotAccess(a: PEffects; n: PNode) =
guardGlobal(a, n, g) guardGlobal(a, n, g)
proc makeVolatile(a: PEffects; s: PSym) {.inline.} = proc makeVolatile(a: PEffects; s: PSym) {.inline.} =
template compileToCpp(a): expr = template compileToCpp(a): untyped =
gCmd == cmdCompileToCpp or sfCompileToCpp in getModule(a.owner).flags gCmd == cmdCompileToCpp or sfCompileToCpp in getModule(a.owner).flags
if a.inTryStmt > 0 and not compileToCpp(a): if a.inTryStmt > 0 and not compileToCpp(a):
incl(s.flags, sfVolatile) incl(s.flags, sfVolatile)
@ -459,7 +459,7 @@ proc documentRaises*(n: PNode) =
if p4 != nil: n.sons[pragmasPos].add p4 if p4 != nil: n.sons[pragmasPos].add p4
if p5 != nil: n.sons[pragmasPos].add p5 if p5 != nil: n.sons[pragmasPos].add p5
template notGcSafe(t): expr = {tfGcSafe, tfNoSideEffect} * t.flags == {} template notGcSafe(t): untyped = {tfGcSafe, tfNoSideEffect} * t.flags == {}
proc importedFromC(n: PNode): bool = proc importedFromC(n: PNode): bool =
# when imported from C, we assume GC-safety. # when imported from C, we assume GC-safety.

View file

@ -632,7 +632,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
c.patterns.add(s) c.patterns.add(s)
proc semPatternBody(c: var TemplCtx, n: PNode): PNode = proc semPatternBody(c: var TemplCtx, n: PNode): PNode =
template templToExpand(s: expr): expr = template templToExpand(s: untyped): untyped =
s.kind == skTemplate and (s.typ.len == 1 or sfAllUntyped in s.flags) s.kind == skTemplate and (s.typ.len == 1 or sfAllUntyped in s.flags)
proc newParam(c: var TemplCtx, n: PNode, s: PSym): PNode = proc newParam(c: var TemplCtx, n: PNode, s: PSym): PNode =

View file

@ -754,18 +754,18 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
addDecl(c, s) addDecl(c, s)
# XXX: There are codegen errors if this is turned into a nested proc # XXX: There are codegen errors if this is turned into a nested proc
template liftingWalk(typ: PType, anonFlag = false): expr = template liftingWalk(typ: PType, anonFlag = false): untyped =
liftParamType(c, procKind, genericParams, typ, paramName, info, anonFlag) liftParamType(c, procKind, genericParams, typ, paramName, info, anonFlag)
#proc liftingWalk(paramType: PType, anon = false): PType = #proc liftingWalk(paramType: PType, anon = false): PType =
var paramTypId = if not anon and paramType.sym != nil: paramType.sym.name var paramTypId = if not anon and paramType.sym != nil: paramType.sym.name
else: nil else: nil
template maybeLift(typ: PType): expr = template maybeLift(typ: PType): untyped =
let lifted = liftingWalk(typ) let lifted = liftingWalk(typ)
(if lifted != nil: lifted else: typ) (if lifted != nil: lifted else: typ)
template addImplicitGeneric(e: expr): expr = template addImplicitGeneric(e): untyped =
addImplicitGenericImpl(e, paramTypId) addImplicitGenericImpl(e, paramTypId)
case paramType.kind: case paramType.kind:

View file

@ -511,6 +511,6 @@ proc generateTypeInstance*(p: PContext, pt: TIdTable, info: TLineInfo,
popInfoContext() popInfoContext()
template generateTypeInstance*(p: PContext, pt: TIdTable, arg: PNode, template generateTypeInstance*(p: PContext, pt: TIdTable, arg: PNode,
t: PType): expr = t: PType): untyped =
generateTypeInstance(p, pt, arg.info, t) generateTypeInstance(p, pt, arg.info, t)

View file

@ -575,7 +575,7 @@ proc matchUserTypeClass*(c: PContext, m: var TCandidate,
typ = ff.sons[i] typ = ff.sons[i]
param: PSym param: PSym
template paramSym(kind): expr = template paramSym(kind): untyped =
newSym(kind, typeParamName, body.sym, body.sym.info) newSym(kind, typeParamName, body.sym, body.sym.info)
case typ.kind case typ.kind
@ -1585,7 +1585,7 @@ proc incrIndexType(t: PType) =
assert t.kind == tyArrayConstr assert t.kind == tyArrayConstr
inc t.sons[0].n.sons[1].intVal inc t.sons[0].n.sons[1].intVal
template isVarargsUntyped(x): expr = template isVarargsUntyped(x): untyped =
x.kind == tyVarargs and x.sons[0].kind == tyExpr and x.kind == tyVarargs and x.sons[0].kind == tyExpr and
tfOldSchoolExprStmt notin x.sons[0].flags tfOldSchoolExprStmt notin x.sons[0].flags

View file

@ -115,7 +115,7 @@ template decodeBImm(k: untyped) {.dirty.} =
let imm = instr.regC - byteExcess let imm = instr.regC - byteExcess
ensureKind(k) ensureKind(k)
template decodeBx(k: expr) {.dirty.} = template decodeBx(k: untyped) {.dirty.} =
let rbx = instr.regBx - wordExcess let rbx = instr.regBx - wordExcess
ensureKind(k) ensureKind(k)
@ -162,7 +162,7 @@ proc moveConst(x: var TFullReg, y: TFullReg) =
# this seems to be the best way to model the reference semantics # this seems to be the best way to model the reference semantics
# of system.NimNode: # of system.NimNode:
template asgnRef(x, y: expr) = moveConst(x, y) template asgnRef(x, y: untyped) = moveConst(x, y)
proc copyValue(src: PNode): PNode = proc copyValue(src: PNode): PNode =
if src == nil or nfIsRef in src.flags: if src == nil or nfIsRef in src.flags:
@ -233,7 +233,7 @@ proc regToNode(x: TFullReg): PNode =
of rkRegisterAddr: result = regToNode(x.regAddr[]) of rkRegisterAddr: result = regToNode(x.regAddr[])
of rkNodeAddr: result = x.nodeAddr[] of rkNodeAddr: result = x.nodeAddr[]
template getstr(a: expr): expr = template getstr(a: untyped): untyped =
(if a.kind == rkNode: a.node.strVal else: $chr(int(a.intVal))) (if a.kind == rkNode: a.node.strVal else: $chr(int(a.intVal)))
proc pushSafePoint(f: PStackFrame; pc: int) = proc pushSafePoint(f: PStackFrame; pc: int) =

View file

@ -88,27 +88,27 @@ proc mapTypeToBracketX(name: string; m: TMagic; t: PType; info: TLineInfo;
proc mapTypeToAstX(t: PType; info: TLineInfo; proc mapTypeToAstX(t: PType; info: TLineInfo;
inst=false; allowRecursionX=false): PNode = inst=false; allowRecursionX=false): PNode =
var allowRecursion = allowRecursionX var allowRecursion = allowRecursionX
template atomicType(name, m): expr = atomicTypeX(name, m, t, info) template atomicType(name, m): untyped = atomicTypeX(name, m, t, info)
template mapTypeToAst(t,info): expr = mapTypeToAstX(t, info, inst) template mapTypeToAst(t,info): untyped = mapTypeToAstX(t, info, inst)
template mapTypeToAstR(t,info): expr = mapTypeToAstX(t, info, inst, true) template mapTypeToAstR(t,info): untyped = mapTypeToAstX(t, info, inst, true)
template mapTypeToAst(t,i,info): expr = template mapTypeToAst(t,i,info): untyped =
if i<t.len and t.sons[i]!=nil: mapTypeToAstX(t.sons[i], info, inst) if i<t.len and t.sons[i]!=nil: mapTypeToAstX(t.sons[i], info, inst)
else: ast.emptyNode else: ast.emptyNode
template mapTypeToBracket(name, m, t, info): expr = template mapTypeToBracket(name, m, t, info): untyped =
mapTypeToBracketX(name, m, t, info, inst) mapTypeToBracketX(name, m, t, info, inst)
template newNodeX(kind):expr = template newNodeX(kind): untyped =
newNodeIT(kind, if t.n.isNil: info else: t.n.info, t) newNodeIT(kind, if t.n.isNil: info else: t.n.info, t)
template newIdent(s):expr = template newIdent(s): untyped =
var r = newNodeX(nkIdent) var r = newNodeX(nkIdent)
r.add !s r.add !s
r r
template newIdentDefs(n,t):expr = template newIdentDefs(n,t): untyped =
var id = newNodeX(nkIdentDefs) var id = newNodeX(nkIdentDefs)
id.add n # name id.add n # name
id.add mapTypeToAst(t, info) # type id.add mapTypeToAst(t, info) # type
id.add ast.emptyNode # no assigned value id.add ast.emptyNode # no assigned value
id id
template newIdentDefs(s):expr = newIdentDefs(s, s.typ) template newIdentDefs(s): untyped = newIdentDefs(s, s.typ)
if inst: if inst:
if t.sym != nil: # if this node has a symbol if t.sym != nil: # if this node has a symbol

View file

@ -1266,7 +1266,7 @@ proc checkCanEval(c: PCtx; n: PNode) =
proc isTemp(c: PCtx; dest: TDest): bool = proc isTemp(c: PCtx; dest: TDest): bool =
result = dest >= 0 and c.prc.slots[dest].kind >= slotTempUnknown result = dest >= 0 and c.prc.slots[dest].kind >= slotTempUnknown
template needsAdditionalCopy(n): expr = template needsAdditionalCopy(n): untyped =
not c.isTemp(dest) and not fitsRegister(n.typ) not c.isTemp(dest) and not fitsRegister(n.typ)
proc skipDeref(n: PNode): PNode = proc skipDeref(n: PNode): PNode =
@ -1404,7 +1404,7 @@ proc genRdVar(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) =
# see tests/t99bott for an example that triggers it: # see tests/t99bott for an example that triggers it:
cannotEval(n) cannotEval(n)
template needsRegLoad(): expr = template needsRegLoad(): untyped =
gfAddrOf notin flags and fitsRegister(n.typ.skipTypes({tyVar})) gfAddrOf notin flags and fitsRegister(n.typ.skipTypes({tyVar}))
proc genArrAccess2(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode; proc genArrAccess2(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode;