bugfix: preliminary symbol declaration in first pass of generics
This commit is contained in:
parent
5e5ed192e5
commit
e9d6f5a647
3 changed files with 17 additions and 10 deletions
|
|
@ -68,7 +68,10 @@ proc AddSym*(t: var TStrTable, n: PSym) =
|
||||||
proc addDecl*(c: PContext, sym: PSym) =
|
proc addDecl*(c: PContext, sym: PSym) =
|
||||||
if SymTabAddUnique(c.tab, sym) == Failure:
|
if SymTabAddUnique(c.tab, sym) == Failure:
|
||||||
LocalError(sym.info, errAttemptToRedefine, sym.Name.s)
|
LocalError(sym.info, errAttemptToRedefine, sym.Name.s)
|
||||||
|
|
||||||
|
proc addPrelimDecl*(c: PContext, sym: PSym) =
|
||||||
|
discard SymTabAddUnique(c.tab, sym)
|
||||||
|
|
||||||
proc addDeclAt*(c: PContext, sym: PSym, at: Natural) =
|
proc addDeclAt*(c: PContext, sym: PSym, at: Natural) =
|
||||||
if SymTabAddUniqueAt(c.tab, sym, at) == Failure:
|
if SymTabAddUniqueAt(c.tab, sym, at) == Failure:
|
||||||
LocalError(sym.info, errAttemptToRedefine, sym.Name.s)
|
LocalError(sym.info, errAttemptToRedefine, sym.Name.s)
|
||||||
|
|
|
||||||
|
|
@ -549,12 +549,14 @@ proc handleError(msg: TMsgKind, eh: TErrorHandling) =
|
||||||
assert(false) # we want a stack trace here
|
assert(false) # we want a stack trace here
|
||||||
if (msg >= fatalMin) and (msg <= fatalMax):
|
if (msg >= fatalMin) and (msg <= fatalMax):
|
||||||
if gVerbosity >= 3: assert(false)
|
if gVerbosity >= 3: assert(false)
|
||||||
|
assert false
|
||||||
quit(1)
|
quit(1)
|
||||||
if (msg >= errMin) and (msg <= errMax):
|
if (msg >= errMin) and (msg <= errMax):
|
||||||
inc(gErrorCounter)
|
inc(gErrorCounter)
|
||||||
options.gExitcode = 1'i8
|
options.gExitcode = 1'i8
|
||||||
if gErrorCounter >= gErrorMax or eh == doAbort:
|
if gErrorCounter >= gErrorMax or eh == doAbort:
|
||||||
if gVerbosity >= 3: assert(false)
|
if gVerbosity >= 3: assert(false)
|
||||||
|
assert false
|
||||||
quit(1) # one error stops the compiler
|
quit(1) # one error stops the compiler
|
||||||
elif eh == doRaise:
|
elif eh == doRaise:
|
||||||
raiseRecoverableError()
|
raiseRecoverableError()
|
||||||
|
|
|
||||||
|
|
@ -144,13 +144,15 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
var L = sonsLen(n)
|
var L = sonsLen(n)
|
||||||
openScope(c.tab)
|
openScope(c.tab)
|
||||||
n.sons[L - 2] = semGenericStmt(c, n.sons[L-2], flags, toBind)
|
n.sons[L - 2] = semGenericStmt(c, n.sons[L-2], flags, toBind)
|
||||||
for i in countup(0, L - 3): addDecl(c, newSymS(skUnknown, n.sons[i], c))
|
for i in countup(0, L - 3):
|
||||||
|
addPrelimDecl(c, newSymS(skUnknown, n.sons[i], c))
|
||||||
n.sons[L - 1] = semGenericStmt(c, n.sons[L-1], flags, toBind)
|
n.sons[L - 1] = semGenericStmt(c, n.sons[L-1], flags, toBind)
|
||||||
closeScope(c.tab)
|
closeScope(c.tab)
|
||||||
of nkBlockStmt, nkBlockExpr, nkBlockType:
|
of nkBlockStmt, nkBlockExpr, nkBlockType:
|
||||||
checkSonsLen(n, 2)
|
checkSonsLen(n, 2)
|
||||||
openScope(c.tab)
|
openScope(c.tab)
|
||||||
if n.sons[0].kind != nkEmpty: addDecl(c, newSymS(skUnknown, n.sons[0], c))
|
if n.sons[0].kind != nkEmpty:
|
||||||
|
addPrelimDecl(c, newSymS(skUnknown, n.sons[0], c))
|
||||||
n.sons[1] = semGenericStmt(c, n.sons[1], flags, toBind)
|
n.sons[1] = semGenericStmt(c, n.sons[1], flags, toBind)
|
||||||
closeScope(c.tab)
|
closeScope(c.tab)
|
||||||
of nkTryStmt:
|
of nkTryStmt:
|
||||||
|
|
@ -174,7 +176,7 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
toBind)
|
toBind)
|
||||||
a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, toBind)
|
a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, toBind)
|
||||||
for j in countup(0, L-3):
|
for j in countup(0, L-3):
|
||||||
addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c))
|
addPrelimDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c))
|
||||||
of nkGenericParams:
|
of nkGenericParams:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
var a = n.sons[i]
|
var a = n.sons[i]
|
||||||
|
|
@ -185,14 +187,14 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
toBind)
|
toBind)
|
||||||
# do not perform symbol lookup for default expressions
|
# do not perform symbol lookup for default expressions
|
||||||
for j in countup(0, L-3):
|
for j in countup(0, L-3):
|
||||||
addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c))
|
addPrelimDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c))
|
||||||
of nkConstSection:
|
of nkConstSection:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
var a = n.sons[i]
|
var a = n.sons[i]
|
||||||
if a.kind == nkCommentStmt: continue
|
if a.kind == nkCommentStmt: continue
|
||||||
if (a.kind != nkConstDef): IllFormedAst(a)
|
if (a.kind != nkConstDef): IllFormedAst(a)
|
||||||
checkSonsLen(a, 3)
|
checkSonsLen(a, 3)
|
||||||
addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[0]), c))
|
addPrelimDecl(c, newSymS(skUnknown, getIdentNode(a.sons[0]), c))
|
||||||
a.sons[1] = semGenericStmt(c, a.sons[1], flags+{withinTypeDesc}, toBind)
|
a.sons[1] = semGenericStmt(c, a.sons[1], flags+{withinTypeDesc}, toBind)
|
||||||
a.sons[2] = semGenericStmt(c, a.sons[2], flags, toBind)
|
a.sons[2] = semGenericStmt(c, a.sons[2], flags, toBind)
|
||||||
of nkTypeSection:
|
of nkTypeSection:
|
||||||
|
|
@ -201,7 +203,7 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
if a.kind == nkCommentStmt: continue
|
if a.kind == nkCommentStmt: continue
|
||||||
if (a.kind != nkTypeDef): IllFormedAst(a)
|
if (a.kind != nkTypeDef): IllFormedAst(a)
|
||||||
checkSonsLen(a, 3)
|
checkSonsLen(a, 3)
|
||||||
addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[0]), c))
|
addPrelimDecl(c, newSymS(skUnknown, getIdentNode(a.sons[0]), c))
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
var a = n.sons[i]
|
var a = n.sons[i]
|
||||||
if a.kind == nkCommentStmt: continue
|
if a.kind == nkCommentStmt: continue
|
||||||
|
|
@ -240,17 +242,17 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
toBind)
|
toBind)
|
||||||
a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, toBind)
|
a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, toBind)
|
||||||
for j in countup(0, L-3):
|
for j in countup(0, L-3):
|
||||||
addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c))
|
addPrelimDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c))
|
||||||
of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef,
|
of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef,
|
||||||
nkIteratorDef, nkLambda:
|
nkIteratorDef, nkLambda:
|
||||||
checkSonsLen(n, bodyPos + 1)
|
checkSonsLen(n, bodyPos + 1)
|
||||||
addDecl(c, newSymS(skUnknown, getIdentNode(n.sons[0]), c))
|
addPrelimDecl(c, newSymS(skUnknown, getIdentNode(n.sons[0]), c))
|
||||||
openScope(c.tab)
|
openScope(c.tab)
|
||||||
n.sons[genericParamsPos] = semGenericStmt(c, n.sons[genericParamsPos],
|
n.sons[genericParamsPos] = semGenericStmt(c, n.sons[genericParamsPos],
|
||||||
flags, toBind)
|
flags, toBind)
|
||||||
if n.sons[paramsPos].kind != nkEmpty:
|
if n.sons[paramsPos].kind != nkEmpty:
|
||||||
if n.sons[paramsPos].sons[0].kind != nkEmpty:
|
if n.sons[paramsPos].sons[0].kind != nkEmpty:
|
||||||
addDecl(c, newSym(skUnknown, getIdent("result"), nil))
|
addPrelimDecl(c, newSym(skUnknown, getIdent("result"), nil))
|
||||||
n.sons[paramsPos] = semGenericStmt(c, n.sons[paramsPos], flags, toBind)
|
n.sons[paramsPos] = semGenericStmt(c, n.sons[paramsPos], flags, toBind)
|
||||||
n.sons[pragmasPos] = semGenericStmt(c, n.sons[pragmasPos], flags, toBind)
|
n.sons[pragmasPos] = semGenericStmt(c, n.sons[pragmasPos], flags, toBind)
|
||||||
var body: PNode
|
var body: PNode
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue