bugfixes for semantic checking; thread implementation pushed the compiler
This commit is contained in:
parent
3260702a60
commit
5008b44467
8 changed files with 153 additions and 125 deletions
|
|
@ -20,9 +20,9 @@ type
|
|||
withinBind, withinTypeDesc
|
||||
TSemGenericFlags = set[TSemGenericFlag]
|
||||
|
||||
proc semGenericStmt(c: PContext, n: PNode, flags: TSemGenericFlags = {}): PNode
|
||||
proc semGenericStmt(c: PContext, n: PNode, flags: TSemGenericFlags): PNode
|
||||
proc semGenericStmtScope(c: PContext, n: PNode,
|
||||
flags: TSemGenericFlags = {}): PNode =
|
||||
flags: TSemGenericFlags): PNode =
|
||||
openScope(c.tab)
|
||||
result = semGenericStmt(c, n, flags)
|
||||
closeScope(c.tab)
|
||||
|
|
@ -60,7 +60,7 @@ proc getIdentNode(n: PNode): PNode =
|
|||
result = n
|
||||
|
||||
proc semGenericStmt(c: PContext, n: PNode,
|
||||
flags: TSemGenericFlags = {}): PNode =
|
||||
flags: TSemGenericFlags): PNode =
|
||||
result = n
|
||||
if gCmd == cmdIdeTools: suggestStmt(c, n)
|
||||
case n.kind
|
||||
|
|
@ -76,76 +76,88 @@ proc semGenericStmt(c: PContext, n: PNode,
|
|||
of nkDotExpr:
|
||||
var s = QualifiedLookUp(c, n, {})
|
||||
if s != nil: result = semGenericStmtSymbol(c, n, s)
|
||||
# XXX for example: ``result.add`` -- ``add`` needs to be looked up here...
|
||||
of nkEmpty, nkSym..nkNilLit:
|
||||
nil
|
||||
of nkBind:
|
||||
result = semGenericStmt(c, n.sons[0], {withinBind})
|
||||
result = semGenericStmt(c, n.sons[0], flags+{withinBind})
|
||||
of nkCall, nkHiddenCallConv, nkInfix, nkPrefix, nkCommand, nkCallStrLit:
|
||||
# check if it is an expression macro:
|
||||
checkMinSonsLen(n, 1)
|
||||
var s = qualifiedLookup(c, n.sons[0], {})
|
||||
var first = 0
|
||||
if s != nil:
|
||||
incl(s.flags, sfUsed)
|
||||
case s.kind
|
||||
of skMacro:
|
||||
return semMacroExpr(c, n, s, false)
|
||||
result = semMacroExpr(c, n, s, false)
|
||||
of skTemplate:
|
||||
return semTemplateExpr(c, n, s, false)
|
||||
result = semTemplateExpr(c, n, s, false)
|
||||
# BUGFIX: we must not return here, we need to do first phase of
|
||||
# symbol lookup ...
|
||||
of skUnknown, skParam:
|
||||
# Leave it as an identifier.
|
||||
of skProc, skMethod, skIterator, skConverter:
|
||||
n.sons[0] = symChoice(c, n.sons[0], s)
|
||||
result.sons[0] = symChoice(c, n.sons[0], s)
|
||||
first = 1
|
||||
of skGenericParam:
|
||||
n.sons[0] = newSymNode(s, n.sons[0].info)
|
||||
result.sons[0] = newSymNode(s, n.sons[0].info)
|
||||
first = 1
|
||||
of skType:
|
||||
# bad hack for generics:
|
||||
if (s.typ != nil) and (s.typ.kind != tyGenericParam):
|
||||
n.sons[0] = newSymNode(s, n.sons[0].info)
|
||||
else: n.sons[0] = newSymNode(s, n.sons[0].info)
|
||||
for i in countup(1, sonsLen(n) - 1):
|
||||
n.sons[i] = semGenericStmt(c, n.sons[i], flags)
|
||||
result.sons[0] = newSymNode(s, n.sons[0].info)
|
||||
first = 1
|
||||
else:
|
||||
result.sons[0] = newSymNode(s, n.sons[0].info)
|
||||
first = 1
|
||||
for i in countup(first, sonsLen(result) - 1):
|
||||
result.sons[i] = semGenericStmt(c, result.sons[i], flags)
|
||||
of nkMacroStmt:
|
||||
result = semMacroStmt(c, n, false)
|
||||
for i in countup(0, sonsLen(result)-1):
|
||||
result.sons[i] = semGenericStmt(c, result.sons[i], flags)
|
||||
of nkIfStmt:
|
||||
for i in countup(0, sonsLen(n)-1):
|
||||
n.sons[i] = semGenericStmtScope(c, n.sons[i])
|
||||
n.sons[i] = semGenericStmtScope(c, n.sons[i], flags)
|
||||
of nkWhileStmt:
|
||||
openScope(c.tab)
|
||||
for i in countup(0, sonsLen(n)-1): n.sons[i] = semGenericStmt(c, n.sons[i])
|
||||
for i in countup(0, sonsLen(n)-1):
|
||||
n.sons[i] = semGenericStmt(c, n.sons[i], flags)
|
||||
closeScope(c.tab)
|
||||
of nkCaseStmt:
|
||||
openScope(c.tab)
|
||||
n.sons[0] = semGenericStmt(c, n.sons[0])
|
||||
n.sons[0] = semGenericStmt(c, n.sons[0], flags)
|
||||
for i in countup(1, sonsLen(n)-1):
|
||||
var a = n.sons[i]
|
||||
checkMinSonsLen(a, 1)
|
||||
var L = sonsLen(a)
|
||||
for j in countup(0, L - 2): a.sons[j] = semGenericStmt(c, a.sons[j])
|
||||
a.sons[L - 1] = semGenericStmtScope(c, a.sons[L - 1])
|
||||
for j in countup(0, L-2): a.sons[j] = semGenericStmt(c, a.sons[j], flags)
|
||||
a.sons[L - 1] = semGenericStmtScope(c, a.sons[L-1], flags)
|
||||
closeScope(c.tab)
|
||||
of nkForStmt:
|
||||
var L = sonsLen(n)
|
||||
openScope(c.tab)
|
||||
n.sons[L - 2] = semGenericStmt(c, n.sons[L - 2])
|
||||
n.sons[L - 2] = semGenericStmt(c, n.sons[L-2], flags)
|
||||
for i in countup(0, L - 3): addDecl(c, newSymS(skUnknown, n.sons[i], c))
|
||||
n.sons[L - 1] = semGenericStmt(c, n.sons[L - 1])
|
||||
n.sons[L - 1] = semGenericStmt(c, n.sons[L-1], flags)
|
||||
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))
|
||||
n.sons[1] = semGenericStmt(c, n.sons[1])
|
||||
n.sons[1] = semGenericStmt(c, n.sons[1], flags)
|
||||
closeScope(c.tab)
|
||||
of nkTryStmt:
|
||||
checkMinSonsLen(n, 2)
|
||||
n.sons[0] = semGenericStmtScope(c, n.sons[0])
|
||||
for i in countup(1, sonsLen(n) - 1):
|
||||
n.sons[0] = semGenericStmtScope(c, n.sons[0], flags)
|
||||
for i in countup(1, sonsLen(n)-1):
|
||||
var a = n.sons[i]
|
||||
checkMinSonsLen(a, 1)
|
||||
var L = sonsLen(a)
|
||||
for j in countup(0, L - 2):
|
||||
a.sons[j] = semGenericStmt(c, a.sons[j], {withinTypeDesc})
|
||||
a.sons[L - 1] = semGenericStmtScope(c, a.sons[L - 1])
|
||||
for j in countup(0, L-2):
|
||||
a.sons[j] = semGenericStmt(c, a.sons[j], flags+{withinTypeDesc})
|
||||
a.sons[L-1] = semGenericStmtScope(c, a.sons[L-1], flags)
|
||||
of nkVarSection:
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
var a = n.sons[i]
|
||||
|
|
@ -153,8 +165,8 @@ proc semGenericStmt(c: PContext, n: PNode,
|
|||
if (a.kind != nkIdentDefs) and (a.kind != nkVarTuple): IllFormedAst(a)
|
||||
checkMinSonsLen(a, 3)
|
||||
var L = sonsLen(a)
|
||||
a.sons[L-2] = semGenericStmt(c, a.sons[L-2], {withinTypeDesc})
|
||||
a.sons[L-1] = semGenericStmt(c, a.sons[L-1])
|
||||
a.sons[L-2] = semGenericStmt(c, a.sons[L-2], flags+{withinTypeDesc})
|
||||
a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags)
|
||||
for j in countup(0, L-3):
|
||||
addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c))
|
||||
of nkGenericParams:
|
||||
|
|
@ -163,7 +175,7 @@ proc semGenericStmt(c: PContext, n: PNode,
|
|||
if (a.kind != nkIdentDefs): IllFormedAst(a)
|
||||
checkMinSonsLen(a, 3)
|
||||
var L = sonsLen(a)
|
||||
a.sons[L-2] = semGenericStmt(c, a.sons[L-2], {withinTypeDesc})
|
||||
a.sons[L-2] = semGenericStmt(c, a.sons[L-2], flags+{withinTypeDesc})
|
||||
# do not perform symbol lookup for default expressions
|
||||
for j in countup(0, L-3):
|
||||
addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c))
|
||||
|
|
@ -174,8 +186,8 @@ proc semGenericStmt(c: PContext, n: PNode,
|
|||
if (a.kind != nkConstDef): IllFormedAst(a)
|
||||
checkSonsLen(a, 3)
|
||||
addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[0]), c))
|
||||
a.sons[1] = semGenericStmt(c, a.sons[1], {withinTypeDesc})
|
||||
a.sons[2] = semGenericStmt(c, a.sons[2])
|
||||
a.sons[1] = semGenericStmt(c, a.sons[1], flags+{withinTypeDesc})
|
||||
a.sons[2] = semGenericStmt(c, a.sons[2], flags)
|
||||
of nkTypeSection:
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
var a = n.sons[i]
|
||||
|
|
@ -190,15 +202,15 @@ proc semGenericStmt(c: PContext, n: PNode,
|
|||
checkSonsLen(a, 3)
|
||||
if a.sons[1].kind != nkEmpty:
|
||||
openScope(c.tab)
|
||||
a.sons[1] = semGenericStmt(c, a.sons[1])
|
||||
a.sons[2] = semGenericStmt(c, a.sons[2], {withinTypeDesc})
|
||||
a.sons[1] = semGenericStmt(c, a.sons[1], flags)
|
||||
a.sons[2] = semGenericStmt(c, a.sons[2], flags+{withinTypeDesc})
|
||||
closeScope(c.tab)
|
||||
else:
|
||||
a.sons[2] = semGenericStmt(c, a.sons[2], {withinTypeDesc})
|
||||
a.sons[2] = semGenericStmt(c, a.sons[2], flags+{withinTypeDesc})
|
||||
of nkEnumTy:
|
||||
checkMinSonsLen(n, 1)
|
||||
if n.sons[0].kind != nkEmpty:
|
||||
n.sons[0] = semGenericStmt(c, n.sons[0], {withinTypeDesc})
|
||||
n.sons[0] = semGenericStmt(c, n.sons[0], flags+{withinTypeDesc})
|
||||
for i in countup(1, sonsLen(n) - 1):
|
||||
var a: PNode
|
||||
case n.sons[i].kind
|
||||
|
|
@ -211,14 +223,14 @@ proc semGenericStmt(c: PContext, n: PNode,
|
|||
of nkFormalParams:
|
||||
checkMinSonsLen(n, 1)
|
||||
if n.sons[0].kind != nkEmpty:
|
||||
n.sons[0] = semGenericStmt(c, n.sons[0], {withinTypeDesc})
|
||||
n.sons[0] = semGenericStmt(c, n.sons[0], flags+{withinTypeDesc})
|
||||
for i in countup(1, sonsLen(n) - 1):
|
||||
var a = n.sons[i]
|
||||
if (a.kind != nkIdentDefs): IllFormedAst(a)
|
||||
checkMinSonsLen(a, 3)
|
||||
var L = sonsLen(a)
|
||||
a.sons[L-2] = semGenericStmt(c, a.sons[L-2], {withinTypeDesc})
|
||||
a.sons[L-1] = semGenericStmt(c, a.sons[L-1])
|
||||
a.sons[L-2] = semGenericStmt(c, a.sons[L-2], flags+{withinTypeDesc})
|
||||
a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags)
|
||||
for j in countup(0, L-3):
|
||||
addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c))
|
||||
of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef,
|
||||
|
|
@ -226,13 +238,13 @@ proc semGenericStmt(c: PContext, n: PNode,
|
|||
checkSonsLen(n, codePos + 1)
|
||||
addDecl(c, newSymS(skUnknown, getIdentNode(n.sons[0]), c))
|
||||
openScope(c.tab)
|
||||
n.sons[genericParamsPos] = semGenericStmt(c, n.sons[genericParamsPos])
|
||||
n.sons[genericParamsPos] = semGenericStmt(c, n.sons[genericParamsPos], flags)
|
||||
if n.sons[paramsPos].kind != nkEmpty:
|
||||
if n.sons[paramsPos].sons[0].kind != nkEmpty:
|
||||
addDecl(c, newSym(skUnknown, getIdent("result"), nil))
|
||||
n.sons[paramsPos] = semGenericStmt(c, n.sons[paramsPos])
|
||||
n.sons[pragmasPos] = semGenericStmt(c, n.sons[pragmasPos])
|
||||
n.sons[codePos] = semGenericStmtScope(c, n.sons[codePos])
|
||||
n.sons[paramsPos] = semGenericStmt(c, n.sons[paramsPos], flags)
|
||||
n.sons[pragmasPos] = semGenericStmt(c, n.sons[pragmasPos], flags)
|
||||
n.sons[codePos] = semGenericStmtScope(c, n.sons[codePos], flags)
|
||||
closeScope(c.tab)
|
||||
else:
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
|
|
|
|||
|
|
@ -748,7 +748,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
|||
else:
|
||||
if s.typ.sons[0] != nil and kind != skIterator:
|
||||
addDecl(c, newSym(skUnknown, getIdent("result"), nil))
|
||||
n.sons[codePos] = semGenericStmtScope(c, n.sons[codePos])
|
||||
n.sons[codePos] = semGenericStmtScope(c, n.sons[codePos], {})
|
||||
if sfImportc in s.flags:
|
||||
# so we just ignore the body after semantic checking for importc:
|
||||
n.sons[codePos] = ast.emptyNode
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue