bugfix: preliminary symbol declaration in first pass of generics

This commit is contained in:
Araq
2011-12-30 21:00:38 +01:00
parent 5e5ed192e5
commit e9d6f5a647
3 changed files with 17 additions and 10 deletions

View File

@@ -68,7 +68,10 @@ proc AddSym*(t: var TStrTable, n: PSym) =
proc addDecl*(c: PContext, sym: PSym) =
if SymTabAddUnique(c.tab, sym) == Failure:
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) =
if SymTabAddUniqueAt(c.tab, sym, at) == Failure:
LocalError(sym.info, errAttemptToRedefine, sym.Name.s)

View File

@@ -549,12 +549,14 @@ proc handleError(msg: TMsgKind, eh: TErrorHandling) =
assert(false) # we want a stack trace here
if (msg >= fatalMin) and (msg <= fatalMax):
if gVerbosity >= 3: assert(false)
assert false
quit(1)
if (msg >= errMin) and (msg <= errMax):
inc(gErrorCounter)
options.gExitcode = 1'i8
if gErrorCounter >= gErrorMax or eh == doAbort:
if gVerbosity >= 3: assert(false)
assert false
quit(1) # one error stops the compiler
elif eh == doRaise:
raiseRecoverableError()

View File

@@ -144,13 +144,15 @@ proc semGenericStmt(c: PContext, n: PNode,
var L = sonsLen(n)
openScope(c.tab)
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)
closeScope(c.tab)
of nkBlockStmt, nkBlockExpr, nkBlockType:
checkSonsLen(n, 2)
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)
closeScope(c.tab)
of nkTryStmt:
@@ -174,7 +176,7 @@ proc semGenericStmt(c: PContext, n: PNode,
toBind)
a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, toBind)
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:
for i in countup(0, sonsLen(n) - 1):
var a = n.sons[i]
@@ -185,14 +187,14 @@ proc semGenericStmt(c: PContext, n: PNode,
toBind)
# do not perform symbol lookup for default expressions
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:
for i in countup(0, sonsLen(n) - 1):
var a = n.sons[i]
if a.kind == nkCommentStmt: continue
if (a.kind != nkConstDef): IllFormedAst(a)
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[2] = semGenericStmt(c, a.sons[2], flags, toBind)
of nkTypeSection:
@@ -201,7 +203,7 @@ proc semGenericStmt(c: PContext, n: PNode,
if a.kind == nkCommentStmt: continue
if (a.kind != nkTypeDef): IllFormedAst(a)
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):
var a = n.sons[i]
if a.kind == nkCommentStmt: continue
@@ -240,17 +242,17 @@ proc semGenericStmt(c: PContext, n: PNode,
toBind)
a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, toBind)
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,
nkIteratorDef, nkLambda:
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)
n.sons[genericParamsPos] = semGenericStmt(c, n.sons[genericParamsPos],
flags, toBind)
if n.sons[paramsPos].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[pragmasPos] = semGenericStmt(c, n.sons[pragmasPos], flags, toBind)
var body: PNode