rename tyExpr/tyStmt to tyUntyped/tyTyped (#11227)

This commit is contained in:
Arne Döring 2019-05-11 10:11:08 +02:00 • committed by Andreas Rumpf
commit b92fd30282
22 changed files with 72 additions and 73 deletions

View file

@ -347,7 +347,7 @@ type
# (apparently something with bootstrapping) # (apparently something with bootstrapping)
# if you need to add a type, they can apparently be reused # if you need to add a type, they can apparently be reused
tyNone, tyBool, tyChar, tyNone, tyBool, tyChar,
tyEmpty, tyAlias, tyNil, tyExpr, tyStmt, tyTypeDesc, tyEmpty, tyAlias, tyNil, tyUntyped, tyTyped, tyTypeDesc,
tyGenericInvocation, # ``T[a, b]`` for types to invoke tyGenericInvocation, # ``T[a, b]`` for types to invoke
tyGenericBody, # ``T[a, b, body]`` last parameter is the body tyGenericBody, # ``T[a, b, body]`` last parameter is the body
tyGenericInst, # ``T[a, b, realInstance]`` instantiated generic type tyGenericInst, # ``T[a, b, realInstance]`` instantiated generic type
@ -448,7 +448,7 @@ const
tyUserTypeClass, tyUserTypeClassInst, tyUserTypeClass, tyUserTypeClassInst,
tyAnd, tyOr, tyNot, tyAnything} tyAnd, tyOr, tyNot, tyAnything}
tyMetaTypes* = {tyGenericParam, tyTypeDesc, tyExpr} + tyTypeClasses tyMetaTypes* = {tyGenericParam, tyTypeDesc, tyUntyped} + tyTypeClasses
tyUserTypeClasses* = {tyUserTypeClass, tyUserTypeClassInst} tyUserTypeClasses* = {tyUserTypeClass, tyUserTypeClassInst}
type type
@ -1713,7 +1713,7 @@ proc isAtom*(n: PNode): bool {.inline.} =
proc isEmptyType*(t: PType): bool {.inline.} = proc isEmptyType*(t: PType): bool {.inline.} =
## 'void' and 'stmt' types are often equivalent to 'nil' these days: ## 'void' and 'stmt' types are often equivalent to 'nil' these days:
result = t == nil or t.kind in {tyVoid, tyStmt} result = t == nil or t.kind in {tyVoid, tyTyped}
proc makeStmtList*(n: PNode): PNode = proc makeStmtList*(n: PNode): PNode =
if n.kind == nkStmtList: if n.kind == nkStmtList:

View file

@ -2720,8 +2720,8 @@ proc getDefaultValue(p: BProc; typ: PType; info: TLineInfo): Rope =
of tyBool: result = rope"NIM_FALSE" of tyBool: result = rope"NIM_FALSE"
of tyEnum, tyChar, tyInt..tyInt64, tyUInt..tyUInt64: result = rope"0" of tyEnum, tyChar, tyInt..tyInt64, tyUInt..tyUInt64: result = rope"0"
of tyFloat..tyFloat128: result = rope"0.0" of tyFloat..tyFloat128: result = rope"0.0"
of tyCString, tyString, tyVar, tyLent, tyPointer, tyPtr, tySequence, tyExpr, of tyCString, tyString, tyVar, tyLent, tyPointer, tyPtr, tySequence, tyUntyped,
tyStmt, tyTypeDesc, tyStatic, tyRef, tyNil: tyTyped, tyTypeDesc, tyStatic, tyRef, tyNil:
result = rope"NIM_NIL" result = rope"NIM_NIL"
of tyProc: of tyProc:
if t.callConv != ccClosure: if t.callConv != ccClosure:

View file

@ -152,7 +152,7 @@ proc mapSetType(conf: ConfigRef; typ: PType): TCTypeKind =
proc mapType(conf: ConfigRef; typ: PType): TCTypeKind = proc mapType(conf: ConfigRef; typ: PType): TCTypeKind =
## Maps a Nim type to a C type ## Maps a Nim type to a C type
case typ.kind case typ.kind
of tyNone, tyStmt: result = ctVoid of tyNone, tyTyped: result = ctVoid
of tyBool: result = ctBool of tyBool: result = ctBool
of tyChar: result = ctChar of tyChar: result = ctChar
of tySet: result = mapSetType(conf, typ) of tySet: result = mapSetType(conf, typ)

View file

@ -91,7 +91,7 @@ proc sameMethodBucket(a, b: PSym): MethodResult =
if result == Yes: if result == Yes:
# check for return type: # check for return type:
if not sameTypeOrNil(a.typ.sons[0], b.typ.sons[0]): if not sameTypeOrNil(a.typ.sons[0], b.typ.sons[0]):
if b.typ.sons[0] != nil and b.typ.sons[0].kind == tyExpr: if b.typ.sons[0] != nil and b.typ.sons[0].kind == tyUntyped:
# infer 'auto' from the base to make it consistent: # infer 'auto' from the base to make it consistent:
b.typ.sons[0] = a.typ.sons[0] b.typ.sons[0] = a.typ.sons[0]
else: else:

View file

@ -90,8 +90,8 @@ proc mapType(conf: ConfigRef, t: ast.PType): ptr libffi.TType =
else: result = nil else: result = nil
of tyFloat, tyFloat64: result = addr libffi.type_double of tyFloat, tyFloat64: result = addr libffi.type_double
of tyFloat32: result = addr libffi.type_float of tyFloat32: result = addr libffi.type_float
of tyVar, tyLent, tyPointer, tyPtr, tyRef, tyCString, tySequence, tyString, tyExpr, of tyVar, tyLent, tyPointer, tyPtr, tyRef, tyCString, tySequence, tyString, tyUntyped,
tyStmt, tyTypeDesc, tyProc, tyArray, tyStatic, tyNil: tyTyped, tyTypeDesc, tyProc, tyArray, tyStatic, tyNil:
result = addr libffi.type_pointer result = addr libffi.type_pointer
of tyDistinct, tyAlias, tySink: of tyDistinct, tyAlias, tySink:
result = mapType(conf, t.sons[0]) result = mapType(conf, t.sons[0])
@ -498,4 +498,3 @@ proc callForeignFunction*(conf: ConfigRef, fn: PNode, fntyp: PType,
let t = args[i+start].typ let t = args[i+start].typ
args[i+start] = unpack(conf, cargs[i], t, args[i+start]) args[i+start] = unpack(conf, cargs[i], t, args[i+start])
dealloc cargs[i] dealloc cargs[i]

View file

@ -190,7 +190,7 @@ proc mapType(typ: PType): TJSTypeKind =
of tyNil: result = etyNull of tyNil: result = etyNull
of tyGenericParam, tyGenericBody, tyGenericInvocation, of tyGenericParam, tyGenericBody, tyGenericInvocation,
tyNone, tyFromExpr, tyForward, tyEmpty, tyNone, tyFromExpr, tyForward, tyEmpty,
tyExpr, tyStmt, tyTypeDesc, tyBuiltInTypeClass, tyCompositeTypeClass, tyUntyped, tyTyped, tyTypeDesc, tyBuiltInTypeClass, tyCompositeTypeClass,
tyAnd, tyOr, tyNot, tyAnything, tyVoid: tyAnd, tyOr, tyNot, tyAnything, tyVoid:
result = etyNone result = etyNone
of tyGenericInst, tyInferred, tyAlias, tyUserTypeClass, tyUserTypeClassInst, of tyGenericInst, tyInferred, tyAlias, tyUserTypeClass, tyUserTypeClassInst,

View file

@ -487,7 +487,7 @@ proc fillBody(c: var TLiftCtx; t: PType; body, x, y: PNode) =
localError(c.graph.config, c.info, "cannot copy openArray") localError(c.graph.config, c.info, "cannot copy openArray")
of tyFromExpr, tyProxy, tyBuiltInTypeClass, tyUserTypeClass, of tyFromExpr, tyProxy, tyBuiltInTypeClass, tyUserTypeClass,
tyUserTypeClassInst, tyCompositeTypeClass, tyAnd, tyOr, tyNot, tyAnything, tyUserTypeClassInst, tyCompositeTypeClass, tyAnd, tyOr, tyNot, tyAnything,
tyGenericParam, tyGenericBody, tyNil, tyExpr, tyStmt, tyGenericParam, tyGenericBody, tyNil, tyUntyped, tyTyped,
tyTypeDesc, tyGenericInvocation, tyForward: tyTypeDesc, tyGenericInvocation, tyForward:
#internalError(c.graph.config, c.info, "assignment requested for type: " & typeToString(t)) #internalError(c.graph.config, c.info, "assignment requested for type: " & typeToString(t))
discard discard

View file

@ -204,7 +204,7 @@ proc addField*(obj: PType; s: PSym; cache: IdentCache) =
field.id = -s.id field.id = -s.id
let t = skipIntLit(s.typ) let t = skipIntLit(s.typ)
field.typ = t field.typ = t
assert t.kind != tyStmt assert t.kind != tyTyped
field.position = sonsLen(obj.n) field.position = sonsLen(obj.n)
addSon(obj.n, newSymNode(field)) addSon(obj.n, newSymNode(field))
@ -216,7 +216,7 @@ proc addUniqueField*(obj: PType; s: PSym; cache: IdentCache): PSym {.discardable
field.id = -s.id field.id = -s.id
let t = skipIntLit(s.typ) let t = skipIntLit(s.typ)
field.typ = t field.typ = t
assert t.kind != tyStmt assert t.kind != tyTyped
field.position = sonsLen(obj.n) field.position = sonsLen(obj.n)
addSon(obj.n, newSymNode(field)) addSon(obj.n, newSymNode(field))
result = field result = field

View file

@ -78,7 +78,7 @@ proc checkTypes(c: PPatternContext, p: PSym, n: PNode): bool =
result = matchNodeKinds(p.constraint, n) result = matchNodeKinds(p.constraint, n)
if not result: return if not result: return
if isNil(n.typ): if isNil(n.typ):
result = p.typ.kind in {tyVoid, tyStmt} result = p.typ.kind in {tyVoid, tyTyped}
else: else:
result = sigmatch.argtypeMatches(c.c, p.typ, n.typ, fromHlo = true) result = sigmatch.argtypeMatches(c.c, p.typ, n.typ, fromHlo = true)
@ -241,7 +241,7 @@ proc aliasAnalysisRequested(params: PNode): bool =
if whichAlias(param) != aqNone: return true if whichAlias(param) != aqNone: return true
proc addToArgList(result, n: PNode) = proc addToArgList(result, n: PNode) =
if n.typ != nil and n.typ.kind != tyStmt: if n.typ != nil and n.typ.kind != tyTyped:
if n.kind != nkArgList: result.add(n) if n.kind != nkArgList: result.add(n)
else: else:
for i in 0 ..< n.len: result.add(n.sons[i]) for i in 0 ..< n.len: result.add(n.sons[i])

View file

@ -26,7 +26,7 @@ proc semLocals*(c: PContext, n: PNode): PNode =
#if it.owner != c.p.owner: return result #if it.owner != c.p.owner: return result
if it.kind in skLocalVars and if it.kind in skLocalVars and
it.typ.skipTypes({tyGenericInst, tyVar}).kind notin it.typ.skipTypes({tyGenericInst, tyVar}).kind notin
{tyVarargs, tyOpenArray, tyTypeDesc, tyStatic, tyExpr, tyStmt, tyEmpty}: {tyVarargs, tyOpenArray, tyTypeDesc, tyStatic, tyUntyped, tyTyped, tyEmpty}:
var field = newSym(skField, it.name, getCurrOwner(c), n.info) var field = newSym(skField, it.name, getCurrOwner(c), n.info)
field.typ = it.typ.skipTypes({tyVar}) field.typ = it.typ.skipTypes({tyVar})

View file

@ -79,7 +79,7 @@ template semIdeForTemplateOrGeneric(c: PContext; n: PNode;
proc fitNodePostMatch(c: PContext, formal: PType, arg: PNode): PNode = proc fitNodePostMatch(c: PContext, formal: PType, arg: PNode): PNode =
result = arg result = arg
let x = result.skipConv let x = result.skipConv
if x.kind in {nkPar, nkTupleConstr, nkCurly} and formal.kind != tyExpr: if x.kind in {nkPar, nkTupleConstr, nkCurly} and formal.kind != tyUntyped:
changeType(c, x, formal, check=true) changeType(c, x, formal, check=true)
else: else:
result = skipHiddenSubConv(result) result = skipHiddenSubConv(result)
@ -106,7 +106,7 @@ proc fitNode(c: PContext, formal: PType, arg: PNode; info: TLineInfo): PNode =
proc inferWithMetatype(c: PContext, formal: PType, proc inferWithMetatype(c: PContext, formal: PType,
arg: PNode, coerceDistincts = false): PNode arg: PNode, coerceDistincts = false): PNode
template commonTypeBegin*(): PType = PType(kind: tyExpr) template commonTypeBegin*(): PType = PType(kind: tyUntyped)
proc commonType*(x, y: PType): PType = proc commonType*(x, y: PType): PType =
# new type relation that is used for array constructors, # new type relation that is used for array constructors,
@ -116,10 +116,10 @@ proc commonType*(x, y: PType): PType =
var a = skipTypes(x, {tyGenericInst, tyAlias, tySink}) var a = skipTypes(x, {tyGenericInst, tyAlias, tySink})
var b = skipTypes(y, {tyGenericInst, tyAlias, tySink}) var b = skipTypes(y, {tyGenericInst, tyAlias, tySink})
result = x result = x
if a.kind in {tyExpr, tyNil}: result = y if a.kind in {tyUntyped, tyNil}: result = y
elif b.kind in {tyExpr, tyNil}: result = x elif b.kind in {tyUntyped, tyNil}: result = x
elif a.kind == tyStmt: result = a elif a.kind == tyTyped: result = a
elif b.kind == tyStmt: result = b elif b.kind == tyTyped: result = b
elif a.kind == tyTypeDesc: elif a.kind == tyTypeDesc:
# turn any concrete typedesc into the abstract typedesc type # turn any concrete typedesc into the abstract typedesc type
if a.len == 0: result = a if a.len == 0: result = a
@ -290,7 +290,7 @@ proc fixupTypeAfterEval(c: PContext, evaluated, eOrig: PNode): PNode =
# recompute the types as 'eval' isn't guaranteed to construct types nor # recompute the types as 'eval' isn't guaranteed to construct types nor
# that the types are sound: # that the types are sound:
when true: when true:
if eOrig.typ.kind in {tyExpr, tyStmt, tyTypeDesc}: if eOrig.typ.kind in {tyUntyped, tyTyped, tyTypeDesc}:
result = semExprWithType(c, evaluated) result = semExprWithType(c, evaluated)
else: else:
result = evaluated result = evaluated
@ -406,12 +406,12 @@ proc semAfterMacroCall(c: PContext, call, macroResult: PNode,
result = semStmt(c, result, flags) result = semStmt(c, result, flags)
else: else:
case s.typ.sons[0].kind case s.typ.sons[0].kind
of tyExpr: of tyUntyped:
# BUGFIX: we cannot expect a type here, because module aliases would not # BUGFIX: we cannot expect a type here, because module aliases would not
# work then (see the ``tmodulealias`` test) # work then (see the ``tmodulealias`` test)
# semExprWithType(c, result) # semExprWithType(c, result)
result = semExpr(c, result, flags) result = semExpr(c, result, flags)
of tyStmt: of tyTyped:
result = semStmt(c, result, flags) result = semStmt(c, result, flags)
of tyTypeDesc: of tyTypeDesc:
if result.kind == nkStmtList: result.kind = nkStmtListType if result.kind == nkStmtList: result.kind = nkStmtListType

View file

@ -213,7 +213,7 @@ proc newOptionEntry*(conf: ConfigRef): POptionEntry =
proc newContext*(graph: ModuleGraph; module: PSym): PContext = proc newContext*(graph: ModuleGraph; module: PSym): PContext =
new(result) new(result)
result.enforceVoidContext = PType(kind: tyStmt) result.enforceVoidContext = PType(kind: tyTyped)
result.ambiguousSymbols = initIntSet() result.ambiguousSymbols = initIntSet()
result.optionStack = @[] result.optionStack = @[]
result.libs = @[] result.libs = @[]

View file

@ -573,7 +573,7 @@ proc fixAbstractType(c: PContext, n: PNode) =
if skipTypes(it.sons[1].typ, abstractVar).kind in if skipTypes(it.sons[1].typ, abstractVar).kind in
{tyNil, tyTuple, tySet} or it[1].isArrayConstr: {tyNil, tyTuple, tySet} or it[1].isArrayConstr:
var s = skipTypes(it.typ, abstractVar) var s = skipTypes(it.typ, abstractVar)
if s.kind != tyExpr: if s.kind != tyUntyped:
changeType(c, it.sons[1], s, check=true) changeType(c, it.sons[1], s, check=true)
n.sons[i] = it.sons[1] n.sons[i] = it.sons[1]
@ -1779,7 +1779,7 @@ proc semYield(c: PContext, n: PNode): PNode =
var iterType = c.p.owner.typ var iterType = c.p.owner.typ
let restype = iterType.sons[0] let restype = iterType.sons[0]
if restype != nil: if restype != nil:
if restype.kind != tyExpr: if restype.kind != tyUntyped:
n.sons[0] = fitNode(c, restype, n.sons[0], n.info) n.sons[0] = fitNode(c, restype, n.sons[0], n.info)
if n.sons[0].typ == nil: internalError(c.config, n.info, "semYield") if n.sons[0].typ == nil: internalError(c.config, n.info, "semYield")
@ -1878,7 +1878,7 @@ proc semExpandToAst(c: PContext, n: PNode): PNode =
if isCallExpr(macroCall): if isCallExpr(macroCall):
for i in 1 ..< macroCall.len: for i in 1 ..< macroCall.len:
#if macroCall.sons[0].typ.sons[i].kind != tyExpr: #if macroCall.sons[0].typ.sons[i].kind != tyUntyped:
macroCall.sons[i] = semExprWithType(c, macroCall[i], {}) macroCall.sons[i] = semExprWithType(c, macroCall[i], {})
# performing overloading resolution here produces too serious regressions: # performing overloading resolution here produces too serious regressions:
let headSymbol = macroCall[0] let headSymbol = macroCall[0]

View file

@ -133,7 +133,7 @@ proc fixNilType(c: PContext; n: PNode) =
proc discardCheck(c: PContext, result: PNode, flags: TExprFlags) = proc discardCheck(c: PContext, result: PNode, flags: TExprFlags) =
if c.matchedConcept != nil or efInTypeof in flags: return if c.matchedConcept != nil or efInTypeof in flags: return
if result.typ != nil and result.typ.kind notin {tyStmt, tyVoid}: if result.typ != nil and result.typ.kind notin {tyTyped, tyVoid}:
if implicitlyDiscardable(result): if implicitlyDiscardable(result):
var n = newNodeI(nkDiscardStmt, result.info, 1) var n = newNodeI(nkDiscardStmt, result.info, 1)
n[0] = result n[0] = result
@ -166,7 +166,7 @@ proc semIf(c: PContext, n: PNode; flags: TExprFlags): PNode =
it.sons[0] = semExprBranchScope(c, it.sons[0]) it.sons[0] = semExprBranchScope(c, it.sons[0])
typ = commonType(typ, it.sons[0]) typ = commonType(typ, it.sons[0])
else: illFormedAst(it, c.config) else: illFormedAst(it, c.config)
if isEmptyType(typ) or typ.kind in {tyNil, tyExpr} or if isEmptyType(typ) or typ.kind in {tyNil, tyUntyped} or
(not hasElse and efInTypeof notin flags): (not hasElse and efInTypeof notin flags):
for it in n: discardCheck(c, it.lastSon, flags) for it in n: discardCheck(c, it.lastSon, flags)
result.kind = nkIfStmt result.kind = nkIfStmt
@ -265,7 +265,7 @@ proc semTry(c: PContext, n: PNode; flags: TExprFlags): PNode =
closeScope(c) closeScope(c)
dec c.p.inTryStmt dec c.p.inTryStmt
if isEmptyType(typ) or typ.kind in {tyNil, tyExpr}: if isEmptyType(typ) or typ.kind in {tyNil, tyUntyped}:
discardCheck(c, n.sons[0], flags) discardCheck(c, n.sons[0], flags)
for i in 1..n.len-1: discardCheck(c, n.sons[i].lastSon, flags) for i in 1..n.len-1: discardCheck(c, n.sons[i].lastSon, flags)
if typ == c.enforceVoidContext: if typ == c.enforceVoidContext:
@ -919,7 +919,7 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags): PNode =
else: else:
localError(c.config, n.info, "not all cases are covered") localError(c.config, n.info, "not all cases are covered")
closeScope(c) closeScope(c)
if isEmptyType(typ) or typ.kind in {tyNil, tyExpr} or if isEmptyType(typ) or typ.kind in {tyNil, tyUntyped} or
(not hasElse and efInTypeof notin flags): (not hasElse and efInTypeof notin flags):
for i in 1..n.len-1: discardCheck(c, n.sons[i].lastSon, flags) for i in 1..n.len-1: discardCheck(c, n.sons[i].lastSon, flags)
# propagate any enforced VoidContext: # propagate any enforced VoidContext:
@ -1952,7 +1952,7 @@ proc semMethod(c: PContext, n: PNode): PNode =
# test case): # test case):
let disp = getDispatcher(s) let disp = getDispatcher(s)
# auto return type? # auto return type?
if disp != nil and disp.typ.sons[0] != nil and disp.typ.sons[0].kind == tyExpr: if disp != nil and disp.typ.sons[0] != nil and disp.typ.sons[0].kind == tyUntyped:
let ret = s.typ.sons[0] let ret = s.typ.sons[0]
disp.typ.sons[0] = ret disp.typ.sons[0] = ret
if disp.ast[resultPos].kind == nkSym: if disp.ast[resultPos].kind == nkSym:
@ -1989,7 +1989,7 @@ proc semMacroDef(c: PContext, n: PNode): PNode =
var allUntyped = true var allUntyped = true
for i in 1 .. t.n.len-1: for i in 1 .. t.n.len-1:
let param = t.n.sons[i].sym let param = t.n.sons[i].sym
if param.typ.kind != tyExpr: allUntyped = false if param.typ.kind != tyUntyped: allUntyped = false
if allUntyped: incl(s.flags, sfAllUntyped) if allUntyped: incl(s.flags, sfAllUntyped)
if t.sons[0] == nil: localError(c.config, n.info, "macro needs a return type") if t.sons[0] == nil: localError(c.config, n.info, "macro needs a return type")
if n.sons[bodyPos].kind == nkEmpty: if n.sons[bodyPos].kind == nkEmpty:

View file

@ -595,21 +595,21 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
for i in 1 .. s.typ.n.len-1: for i in 1 .. s.typ.n.len-1:
let param = s.typ.n.sons[i].sym let param = s.typ.n.sons[i].sym
param.flags.excl sfGenSym param.flags.excl sfGenSym
if param.typ.kind != tyExpr: allUntyped = false if param.typ.kind != tyUntyped: allUntyped = false
if sonsLen(gp) > 0: if sonsLen(gp) > 0:
if n.sons[genericParamsPos].kind == nkEmpty: if n.sons[genericParamsPos].kind == nkEmpty:
# we have a list of implicit type parameters: # we have a list of implicit type parameters:
n.sons[genericParamsPos] = gp n.sons[genericParamsPos] = gp
# no explicit return type? -> use tyStmt # no explicit return type? -> use tyTyped
if n.sons[paramsPos].sons[0].kind == nkEmpty: if n.sons[paramsPos].sons[0].kind == nkEmpty:
# use ``stmt`` as implicit result type # use ``stmt`` as implicit result type
s.typ.sons[0] = newTypeS(tyStmt, c) s.typ.sons[0] = newTypeS(tyTyped, c)
s.typ.n.sons[0] = newNodeIT(nkType, n.info, s.typ.sons[0]) s.typ.n.sons[0] = newNodeIT(nkType, n.info, s.typ.sons[0])
else: else:
s.typ = newTypeS(tyProc, c) s.typ = newTypeS(tyProc, c)
# XXX why do we need tyStmt as a return type again? # XXX why do we need tyTyped as a return type again?
s.typ.n = newNodeI(nkFormalParams, n.info) s.typ.n = newNodeI(nkFormalParams, n.info)
rawAddSon(s.typ, newTypeS(tyStmt, c)) rawAddSon(s.typ, newTypeS(tyTyped, c))
addSon(s.typ.n, newNodeIT(nkType, n.info, s.typ.sons[0])) addSon(s.typ.n, newNodeIT(nkType, n.info, s.typ.sons[0]))
if allUntyped: incl(s.flags, sfAllUntyped) if allUntyped: incl(s.flags, sfAllUntyped)
if n.sons[patternPos].kind != nkEmpty: if n.sons[patternPos].kind != nkEmpty:

View file

@ -1110,7 +1110,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
var owner = getCurrOwner(c).owner var owner = getCurrOwner(c).owner
# TODO: Disallow typed/untyped in procs in the compiler/stdlib # TODO: Disallow typed/untyped in procs in the compiler/stdlib
if (owner.kind != skModule or owner.owner.name.s != "stdlib") and if (owner.kind != skModule or owner.owner.name.s != "stdlib") and
kind == skProc and (typ.kind == tyStmt or typ.kind == tyExpr): kind == skProc and (typ.kind == tyTyped or typ.kind == tyUntyped):
localError(c.config, a.sons[length-2].info, "'" & typ.sym.name.s & "' is only allowed in templates and macros") localError(c.config, a.sons[length-2].info, "'" & typ.sym.name.s & "' is only allowed in templates and macros")
if hasDefault: if hasDefault:
@ -1155,7 +1155,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
if not hasType and not hasDefault: if not hasType and not hasDefault:
if isType: localError(c.config, a.info, "':' expected") if isType: localError(c.config, a.info, "':' expected")
if kind in {skTemplate, skMacro}: if kind in {skTemplate, skMacro}:
typ = newTypeS(tyExpr, c) typ = newTypeS(tyUntyped, c)
elif skipTypes(typ, {tyGenericInst, tyAlias, tySink}).kind == tyVoid: elif skipTypes(typ, {tyGenericInst, tyAlias, tySink}).kind == tyVoid:
continue continue
@ -1192,14 +1192,14 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
# turn explicit 'void' return type into 'nil' because the rest of the # turn explicit 'void' return type into 'nil' because the rest of the
# compiler only checks for 'nil': # compiler only checks for 'nil':
if skipTypes(r, {tyGenericInst, tyAlias, tySink}).kind != tyVoid: if skipTypes(r, {tyGenericInst, tyAlias, tySink}).kind != tyVoid:
if kind notin {skMacro, skTemplate} and r.kind in {tyStmt, tyExpr}: if kind notin {skMacro, skTemplate} and r.kind in {tyTyped, tyUntyped}:
localError(c.config, n.sons[0].info, "return type '" & typeToString(r) & localError(c.config, n.sons[0].info, "return type '" & typeToString(r) &
"' is only valid for macros and templates") "' is only valid for macros and templates")
# 'auto' as a return type does not imply a generic: # 'auto' as a return type does not imply a generic:
elif r.kind == tyAnything: elif r.kind == tyAnything:
# 'p(): auto' and 'p(): expr' are equivalent, but the rest of the # 'p(): auto' and 'p(): expr' are equivalent, but the rest of the
# compiler is hardly aware of 'auto': # compiler is hardly aware of 'auto':
r = newTypeS(tyExpr, c) r = newTypeS(tyUntyped, c)
else: else:
if r.sym == nil or sfAnon notin r.sym.flags: if r.sym == nil or sfAnon notin r.sym.flags:
let lifted = liftParamType(c, kind, genericParams, r, "result", let lifted = liftParamType(c, kind, genericParams, r, "result",
@ -1824,9 +1824,9 @@ proc processMagicType(c: PContext, m: PSym) =
if m.name.s == "auto": if m.name.s == "auto":
setMagicIntegral(c.config, m, tyAnything, 0) setMagicIntegral(c.config, m, tyAnything, 0)
else: else:
setMagicIntegral(c.config, m, tyExpr, 0) setMagicIntegral(c.config, m, tyUntyped, 0)
of mStmt: of mStmt:
setMagicIntegral(c.config, m, tyStmt, 0) setMagicIntegral(c.config, m, tyTyped, 0)
of mTypeDesc, mType: of mTypeDesc, mType:
setMagicIntegral(c.config, m, tyTypeDesc, 0) setMagicIntegral(c.config, m, tyTypeDesc, 0)
rawAddSon(m.typ, newTypeS(tyNone, c)) rawAddSon(m.typ, newTypeS(tyNone, c))

View file

@ -214,7 +214,7 @@ proc sumGeneric(t: PType): int =
break break
of tyStatic: of tyStatic:
return t.sons[0].sumGeneric + 1 return t.sons[0].sumGeneric + 1
of tyGenericParam, tyExpr, tyStmt: break of tyGenericParam, tyUntyped, tyTyped: break
of tyAlias, tySink: t = t.lastSon of tyAlias, tySink: t = t.lastSon
of tyBool, tyChar, tyEnum, tyObject, tyPointer, of tyBool, tyChar, tyEnum, tyObject, tyPointer,
tyString, tyCString, tyInt..tyInt64, tyFloat..tyFloat128, tyString, tyCString, tyInt..tyInt64, tyFloat..tyFloat128,
@ -988,7 +988,7 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
result = isNone result = isNone
assert(f != nil) assert(f != nil)
if f.kind == tyExpr: if f.kind == tyUntyped:
if aOrig != nil: put(c, f, aOrig) if aOrig != nil: put(c, f, aOrig)
return isGeneric return isGeneric
@ -1215,7 +1215,7 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
if f.kind == tyVarargs: if f.kind == tyVarargs:
if tfVarargs in a.flags: if tfVarargs in a.flags:
return typeRel(c, f.base, a.lastSon) return typeRel(c, f.base, a.lastSon)
if f.sons[0].kind == tyStmt: return if f.sons[0].kind == tyTyped: return
template matchArrayOrSeq(aBase: PType) = template matchArrayOrSeq(aBase: PType) =
let ff = f.base let ff = f.base
@ -1770,7 +1770,7 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
else: else:
result = isNone result = isNone
of tyStmt: of tyTyped:
if aOrig != nil: if aOrig != nil:
put(c, f, aOrig) put(c, f, aOrig)
result = isGeneric result = isGeneric
@ -1975,7 +1975,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
# XXX: duplicating this is ugly, but we cannot (!) move this # XXX: duplicating this is ugly, but we cannot (!) move this
# directly into typeRel using return-like templates # directly into typeRel using return-like templates
incMatches(m, r) incMatches(m, r)
if f.kind == tyStmt: if f.kind == tyTyped:
return arg return arg
elif f.kind == tyTypeDesc: elif f.kind == tyTypeDesc:
return arg return arg
@ -2173,9 +2173,9 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType,
if x.state != csMatch: if x.state != csMatch:
internalError(m.c.graph.config, arg.info, "x.state is not csMatch") internalError(m.c.graph.config, arg.info, "x.state is not csMatch")
# ambiguous: more than one symbol fits! # ambiguous: more than one symbol fits!
# See tsymchoice_for_expr as an example. 'f.kind == tyExpr' should match # See tsymchoice_for_expr as an example. 'f.kind == tyUntyped' should match
# anyway: # anyway:
if f.kind in {tyExpr, tyStmt}: result = arg if f.kind in {tyUntyped, tyTyped}: result = arg
else: result = nil else: result = nil
else: else:
# only one valid interpretation found: # only one valid interpretation found:
@ -2199,8 +2199,8 @@ proc setSon(father: PNode, at: int, son: PNode) =
# we are allowed to modify the calling node in the 'prepare*' procs: # we are allowed to modify the calling node in the 'prepare*' procs:
proc prepareOperand(c: PContext; formal: PType; a: PNode): PNode = proc prepareOperand(c: PContext; formal: PType; a: PNode): PNode =
if formal.kind == tyExpr and formal.len != 1: if formal.kind == tyUntyped and formal.len != 1:
# {tyTypeDesc, tyExpr, tyStmt, tyProxy}: # {tyTypeDesc, tyUntyped, tyTyped, tyProxy}:
# a.typ == nil is valid # a.typ == nil is valid
result = a result = a
elif a.typ.isNil: elif a.typ.isNil:
@ -2209,7 +2209,7 @@ proc prepareOperand(c: PContext; formal: PType; a: PNode): PNode =
let flags = {efDetermineType, efAllowStmt} let flags = {efDetermineType, efAllowStmt}
#if formal.kind == tyIter: {efDetermineType, efWantIterator} #if formal.kind == tyIter: {efDetermineType, efWantIterator}
#else: {efDetermineType, efAllowStmt} #else: {efDetermineType, efAllowStmt}
#elif formal.kind == tyStmt: {efDetermineType, efWantStmt} #elif formal.kind == tyTyped: {efDetermineType, efWantStmt}
#else: {efDetermineType} #else: {efDetermineType}
result = c.semOperand(c, a, flags) result = c.semOperand(c, a, flags)
else: else:
@ -2244,7 +2244,7 @@ proc incrIndexType(t: PType) =
inc t.sons[0].n.sons[1].intVal inc t.sons[0].n.sons[1].intVal
template isVarargsUntyped(x): untyped = template isVarargsUntyped(x): untyped =
x.kind == tyVarargs and x.sons[0].kind == tyExpr x.kind == tyVarargs and x.sons[0].kind == tyUntyped
proc matchesAux(c: PContext, n, nOrig: PNode, proc matchesAux(c: PContext, n, nOrig: PNode,
m: var TCandidate, marker: var IntSet) = m: var TCandidate, marker: var IntSet) =

View file

@ -258,7 +258,7 @@ proc getQuality(s: PSym): range[0..100] =
if s.typ != nil and s.typ.len > 1: if s.typ != nil and s.typ.len > 1:
var exp = s.typ.sons[1].skipTypes({tyGenericInst, tyVar, tyLent, tyAlias, tySink}) var exp = s.typ.sons[1].skipTypes({tyGenericInst, tyVar, tyLent, tyAlias, tySink})
if exp.kind == tyVarargs: exp = elemType(exp) if exp.kind == tyVarargs: exp = elemType(exp)
if exp.kind in {tyExpr, tyStmt, tyGenericParam, tyAnything}: return 50 if exp.kind in {tyUntyped, tyTyped, tyGenericParam, tyAnything}: return 50
return 100 return 100
template wholeSymTab(cond, section: untyped) = template wholeSymTab(cond, section: untyped) =
@ -319,7 +319,7 @@ proc suggestCall(c: PContext, n, nOrig: PNode, outputs: var Suggestions) =
proc typeFits(c: PContext, s: PSym, firstArg: PType): bool {.inline.} = proc typeFits(c: PContext, s: PSym, firstArg: PType): bool {.inline.} =
if s.typ != nil and sonsLen(s.typ) > 1 and s.typ.sons[1] != nil: if s.typ != nil and sonsLen(s.typ) > 1 and s.typ.sons[1] != nil:
# special rule: if system and some weird generic match via 'tyExpr' # special rule: if system and some weird generic match via 'tyUntyped'
# or 'tyGenericParam' we won't list it either to reduce the noise (nobody # or 'tyGenericParam' we won't list it either to reduce the noise (nobody
# wants 'system.`-|` as suggestion # wants 'system.`-|` as suggestion
let m = s.getModule() let m = s.getModule()
@ -327,7 +327,7 @@ proc typeFits(c: PContext, s: PSym, firstArg: PType): bool {.inline.} =
if s.kind == skType: return if s.kind == skType: return
var exp = s.typ.sons[1].skipTypes({tyGenericInst, tyVar, tyLent, tyAlias, tySink}) var exp = s.typ.sons[1].skipTypes({tyGenericInst, tyVar, tyLent, tyAlias, tySink})
if exp.kind == tyVarargs: exp = elemType(exp) if exp.kind == tyVarargs: exp = elemType(exp)
if exp.kind in {tyExpr, tyStmt, tyGenericParam, tyAnything}: return if exp.kind in {tyUntyped, tyTyped, tyGenericParam, tyAnything}: return
result = sigmatch.argtypeMatches(c, s.typ.sons[1], firstArg) result = sigmatch.argtypeMatches(c, s.typ.sons[1], firstArg)
proc suggestOperations(c: PContext, n, f: PNode, typ: PType, outputs: var Suggestions) = proc suggestOperations(c: PContext, n, f: PNode, typ: PType, outputs: var Suggestions) =

View file

@ -522,7 +522,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
result.add(" or ") result.add(" or ")
of tyNot: of tyNot:
result = "not " & typeToString(t.sons[0]) result = "not " & typeToString(t.sons[0])
of tyExpr: of tyUntyped:
#internalAssert t.len == 0 #internalAssert t.len == 0
result = "untyped" result = "untyped"
of tyFromExpr: of tyFromExpr:
@ -1033,7 +1033,7 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
case a.kind case a.kind
of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCString, of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCString,
tyInt..tyUInt64, tyStmt, tyExpr, tyVoid: tyInt..tyUInt64, tyTyped, tyUntyped, tyVoid:
result = sameFlags(a, b) result = sameFlags(a, b)
of tyStatic, tyFromExpr: of tyStatic, tyFromExpr:
result = exprStructuralEquivalent(a.n, b.n) and sameFlags(a, b) result = exprStructuralEquivalent(a.n, b.n) and sameFlags(a, b)
@ -1231,7 +1231,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
of tyTypeDesc: of tyTypeDesc:
# XXX: This is still a horrible idea... # XXX: This is still a horrible idea...
result = nil result = nil
of tyExpr, tyStmt, tyStatic: of tyUntyped, tyTyped, tyStatic:
if kind notin {skParam, skResult}: result = t if kind notin {skParam, skResult}: result = t
of tyVoid: of tyVoid:
if taField notin flags: result = t if taField notin flags: result = t
@ -1475,7 +1475,7 @@ proc skipConvTakeType*(n: PNode): PNode =
proc isEmptyContainer*(t: PType): bool = proc isEmptyContainer*(t: PType): bool =
case t.kind case t.kind
of tyExpr, tyNil: result = true of tyUntyped, tyNil: result = true
of tyArray: result = t.sons[1].kind == tyEmpty of tyArray: result = t.sons[1].kind == tyEmpty
of tySet, tySequence, tyOpenArray, tyVarargs: of tySet, tySequence, tyOpenArray, tyVarargs:
result = t.sons[0].kind == tyEmpty result = t.sons[0].kind == tyEmpty
@ -1506,7 +1506,7 @@ proc skipHiddenSubConv*(n: PNode): PNode =
result = n.sons[1] result = n.sons[1]
let arg = result.typ let arg = result.typ
let dest = takeType(formal, arg) let dest = takeType(formal, arg)
if dest == arg and formal.kind != tyExpr: if dest == arg and formal.kind != tyUntyped:
#echo n.info, " came here for ", formal.typeToString #echo n.info, " came here for ", formal.typeToString
result = n result = n
else: else:

View file

@ -91,8 +91,8 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
of tyBool: result = atomicType("bool", mBool) of tyBool: result = atomicType("bool", mBool)
of tyChar: result = atomicType("char", mChar) of tyChar: result = atomicType("char", mChar)
of tyNil: result = atomicType("nil", mNil) of tyNil: result = atomicType("nil", mNil)
of tyExpr: result = atomicType("expr", mExpr) of tyUntyped: result = atomicType("expr", mExpr)
of tyStmt: result = atomicType("stmt", mStmt) of tyTyped: result = atomicType("stmt", mStmt)
of tyVoid: result = atomicType("void", mVoid) of tyVoid: result = atomicType("void", mVoid)
of tyEmpty: result = atomicType("empty", mNone) of tyEmpty: result = atomicType("empty", mNone)
of tyUncheckedArray: of tyUncheckedArray:

View file

@ -1378,7 +1378,7 @@ proc genMarshalStore(c: PCtx, n: PNode, dest: var TDest) =
const const
atomicTypes = {tyBool, tyChar, atomicTypes = {tyBool, tyChar,
tyExpr, tyStmt, tyTypeDesc, tyStatic, tyUntyped, tyTyped, tyTypeDesc, tyStatic,
tyEnum, tyEnum,
tyOrdinal, tyOrdinal,
tyRange, tyRange,
@ -1766,8 +1766,8 @@ proc getNullValue(typ: PType, info: TLineInfo; conf: ConfigRef): PNode =
of tyCString, tyString: of tyCString, tyString:
result = newNodeIT(nkStrLit, info, t) result = newNodeIT(nkStrLit, info, t)
result.strVal = "" result.strVal = ""
of tyVar, tyLent, tyPointer, tyPtr, tyExpr, of tyVar, tyLent, tyPointer, tyPtr, tyUntyped,
tyStmt, tyTypeDesc, tyRef, tyNil: tyTyped, tyTypeDesc, tyRef, tyNil:
result = newNodeIT(nkNilLit, info, t) result = newNodeIT(nkNilLit, info, t)
of tyProc: of tyProc:
if t.callConv != ccClosure: if t.callConv != ccClosure:

View file

@ -17,8 +17,8 @@ type
tyEmpty, tyEmpty,
tyArrayConstr, tyArrayConstr,
tyNil, tyNil,
tyExpr, tyUntyped,
tyStmt, tyTyped,
tyTypeDesc, tyTypeDesc,
tyGenericInvocation, # ``T[a, b]`` for types to invoke tyGenericInvocation, # ``T[a, b]`` for types to invoke
tyGenericBody, # ``T[a, b, body]`` last parameter is the body tyGenericBody, # ``T[a, b, body]`` last parameter is the body