semTemplateDef and t17433 clean-ups (#17448)
- use `doAssert` in t17433 - use setGenericParamsMisc in semTemplateDef akin to semProcAux - pragma handling in semTemplateDef inline with semProcAux
This commit is contained in:
parent
c8dda867f2
commit
e5873b3a93
4 changed files with 43 additions and 41 deletions
|
|
@ -595,12 +595,14 @@ proc semTemplBodyDirty(c: var TemplCtx, n: PNode): PNode =
|
|||
result[i] = semTemplBodyDirty(c, n[i])
|
||||
|
||||
proc semTemplateDef(c: PContext, n: PNode): PNode =
|
||||
result = n
|
||||
var s: PSym
|
||||
if isTopLevel(c):
|
||||
s = semIdentVis(c, skTemplate, n[0], {sfExported})
|
||||
s = semIdentVis(c, skTemplate, n[namePos], {sfExported})
|
||||
incl(s.flags, sfGlobal)
|
||||
else:
|
||||
s = semIdentVis(c, skTemplate, n[0], {})
|
||||
s = semIdentVis(c, skTemplate, n[namePos], {})
|
||||
assert s.kind == skTemplate
|
||||
|
||||
if s.owner != nil:
|
||||
const names = ["!=", ">=", ">", "incl", "excl", "in", "notin", "isnot"]
|
||||
|
|
@ -608,26 +610,23 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
|
|||
s.owner.name.s == "vm" and s.name.s == "stackTrace":
|
||||
incl(s.flags, sfCallsite)
|
||||
|
||||
s.ast = n
|
||||
|
||||
styleCheckDef(c.config, s)
|
||||
onDef(n[0].info, s)
|
||||
onDef(n[namePos].info, s)
|
||||
# check parameter list:
|
||||
#s.scope = c.currentScope
|
||||
pushOwner(c, s)
|
||||
openScope(c)
|
||||
n[namePos] = newSymNode(s, n[namePos].info)
|
||||
if n[pragmasPos].kind != nkEmpty:
|
||||
pragma(c, s, n[pragmasPos], templatePragmas)
|
||||
n[namePos] = newSymNode(s)
|
||||
pragmaCallable(c, s, n, templatePragmas)
|
||||
implicitPragmas(c, s, n.info, templatePragmas)
|
||||
|
||||
var gp: PNode
|
||||
if n[genericParamsPos].kind != nkEmpty:
|
||||
n[genericParamsPos] = semGenericParamList(c, n[genericParamsPos])
|
||||
gp = n[genericParamsPos]
|
||||
else:
|
||||
gp = newNodeI(nkGenericParams, n.info)
|
||||
setGenericParamsMisc(c, n)
|
||||
# process parameters:
|
||||
var allUntyped = true
|
||||
if n[paramsPos].kind != nkEmpty:
|
||||
semParamList(c, n[paramsPos], gp, s)
|
||||
semParamList(c, n[paramsPos], n[genericParamsPos], s)
|
||||
# a template's parameters are not gensym'ed even if that was originally the
|
||||
# case as we determine whether it's a template parameter in the template
|
||||
# body by the absence of the sfGenSym flag:
|
||||
|
|
@ -636,18 +635,21 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
|
|||
param.flags.incl sfTemplateParam
|
||||
param.flags.excl sfGenSym
|
||||
if param.typ.kind != tyUntyped: allUntyped = false
|
||||
if gp.len > 0 and n[genericParamsPos].kind == nkEmpty:
|
||||
# we have a list of implicit type parameters:
|
||||
n[genericParamsPos] = gp
|
||||
else:
|
||||
s.typ = newTypeS(tyProc, c)
|
||||
# XXX why do we need tyTyped as a return type again?
|
||||
s.typ.n = newNodeI(nkFormalParams, n.info)
|
||||
rawAddSon(s.typ, newTypeS(tyTyped, c))
|
||||
s.typ.n.add newNodeIT(nkType, n.info, s.typ[0])
|
||||
if n[genericParamsPos].safeLen == 0:
|
||||
# restore original generic type params as no explicit or implicit were found
|
||||
n[genericParamsPos] = n[miscPos][1]
|
||||
n[miscPos] = c.graph.emptyNode
|
||||
if allUntyped: incl(s.flags, sfAllUntyped)
|
||||
|
||||
if n[patternPos].kind != nkEmpty:
|
||||
n[patternPos] = semPattern(c, n[patternPos])
|
||||
|
||||
var ctx: TemplCtx
|
||||
ctx.toBind = initIntSet()
|
||||
ctx.toMixin = initIntSet()
|
||||
|
|
@ -662,8 +664,6 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
|
|||
semIdeForTemplateOrGeneric(c, n[bodyPos], ctx.cursorInBody)
|
||||
closeScope(c)
|
||||
popOwner(c)
|
||||
s.ast = n
|
||||
result = n
|
||||
if sfCustomPragma in s.flags:
|
||||
if n[bodyPos].kind != nkEmpty:
|
||||
localError(c.config, n[bodyPos].info, errImplOfXNotAllowed % s.name.s)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue