mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 17:34:43 +00:00
made compiler more robust for idetools support
This commit is contained in:
@@ -208,9 +208,10 @@ proc getModule(s: PSym): PSym =
|
||||
|
||||
proc getSymFromList(list: PNode, ident: PIdent, start: int = 0): PSym =
|
||||
for i in countup(start, sonsLen(list) - 1):
|
||||
if list.sons[i].kind != nkSym: InternalError(list.info, "getSymFromList")
|
||||
result = list.sons[i].sym
|
||||
if result.name.id == ident.id: return
|
||||
if list.sons[i].kind == nkSym:
|
||||
result = list.sons[i].sym
|
||||
if result.name.id == ident.id: return
|
||||
else: InternalError(list.info, "getSymFromList")
|
||||
result = nil
|
||||
|
||||
proc hashNode(p: PObject): THash =
|
||||
@@ -576,7 +577,9 @@ proc StrTableContains(t: TStrTable, n: PSym): bool =
|
||||
proc StrTableRawInsert(data: var TSymSeq, n: PSym) =
|
||||
var h: THash = n.name.h and high(data)
|
||||
while data[h] != nil:
|
||||
if data[h] == n: InternalError(n.info, "StrTableRawInsert: " & n.name.s)
|
||||
if data[h] == n:
|
||||
InternalError(n.info, "StrTableRawInsert: " & n.name.s)
|
||||
return
|
||||
h = nextTry(h, high(data))
|
||||
assert(data[h] == nil)
|
||||
data[h] = n
|
||||
|
||||
@@ -70,9 +70,9 @@ proc pushStackFrame*(c: PEvalContext, t: PStackFrame) {.inline.} =
|
||||
t.next = c.tos
|
||||
c.tos = t
|
||||
|
||||
proc popStackFrame*(c: PEvalContext) {.inline.} =
|
||||
if c.tos == nil: InternalError("popStackFrame")
|
||||
c.tos = c.tos.next
|
||||
proc popStackFrame*(c: PEvalContext) {.inline.} =
|
||||
if c.tos != nil: c.tos = c.tos.next
|
||||
else: InternalError("popStackFrame")
|
||||
|
||||
proc evalMacroCall*(c: PEvalContext, n: PNode, sym: PSym): PNode
|
||||
proc evalAux(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode
|
||||
@@ -315,11 +315,13 @@ proc evalCall(c: PEvalContext, n: PNode): PNode =
|
||||
if isSpecial(result): return
|
||||
prc = result
|
||||
# bind the actual params to the local parameter of a new binding
|
||||
if prc.kind != nkSym: InternalError(n.info, "evalCall " & n.renderTree)
|
||||
if prc.kind != nkSym:
|
||||
InternalError(n.info, "evalCall " & n.renderTree)
|
||||
return
|
||||
d.prc = prc.sym
|
||||
if prc.sym.kind notin {skProc, skConverter, skMacro}:
|
||||
InternalError(n.info, "evalCall")
|
||||
|
||||
return
|
||||
for i in countup(1, sonsLen(n) - 1):
|
||||
result = evalAux(c, n.sons[i], {})
|
||||
if isSpecial(result): return
|
||||
@@ -551,13 +553,13 @@ proc evalOr(c: PEvalContext, n: PNode): PNode =
|
||||
result = evalAux(c, n.sons[1], {})
|
||||
if isSpecial(result): return
|
||||
if result.kind != nkIntLit: InternalError(n.info, "evalOr")
|
||||
if result.intVal == 0: result = evalAux(c, n.sons[2], {})
|
||||
elif result.intVal == 0: result = evalAux(c, n.sons[2], {})
|
||||
|
||||
proc evalAnd(c: PEvalContext, n: PNode): PNode =
|
||||
result = evalAux(c, n.sons[1], {})
|
||||
if isSpecial(result): return
|
||||
if result.kind != nkIntLit: InternalError(n.info, "evalAnd")
|
||||
if result.intVal != 0: result = evalAux(c, n.sons[2], {})
|
||||
elif result.intVal != 0: result = evalAux(c, n.sons[2], {})
|
||||
|
||||
proc evalNew(c: PEvalContext, n: PNode): PNode =
|
||||
#if c.mode == emOptimize: return raiseCannotEval(c, n.info)
|
||||
@@ -720,7 +722,9 @@ proc evalSetLengthSeq(c: PEvalContext, n: PNode): PNode =
|
||||
result = evalAux(c, n.sons[2], {})
|
||||
if isSpecial(result): return
|
||||
var b = result
|
||||
if a.kind != nkBracket: InternalError(n.info, "evalSetLengthSeq")
|
||||
if a.kind != nkBracket:
|
||||
InternalError(n.info, "evalSetLengthSeq")
|
||||
return
|
||||
var newLen = int(getOrdValue(b))
|
||||
var oldLen = sonsLen(a)
|
||||
setlen(a.sons, newLen)
|
||||
@@ -970,6 +974,7 @@ proc evalExpandToAst(c: PEvalContext, original: PNode): PNode =
|
||||
else:
|
||||
InternalError(macroCall.info,
|
||||
"ExpandToAst: expanded symbol is no macro or template")
|
||||
result = emptyNode
|
||||
|
||||
proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
|
||||
var m = getMagic(n)
|
||||
@@ -1080,7 +1085,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
|
||||
result = newNodeIT(nkIntLit, n.info, n.typ)
|
||||
case a.kind
|
||||
of nkCharLit..nkInt64Lit: result.intVal = a.intVal
|
||||
else: InternalError(n.info, "no int value")
|
||||
else: stackTrace(c, n, errFieldXNotFound, "intVal")
|
||||
of mNFloatVal:
|
||||
result = evalAux(c, n.sons[1], {})
|
||||
if isSpecial(result): return
|
||||
@@ -1088,15 +1093,15 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
|
||||
result = newNodeIT(nkFloatLit, n.info, n.typ)
|
||||
case a.kind
|
||||
of nkFloatLit..nkFloat64Lit: result.floatVal = a.floatVal
|
||||
else: InternalError(n.info, "no float value")
|
||||
else: stackTrace(c, n, errFieldXNotFound, "floatVal")
|
||||
of mNSymbol:
|
||||
result = evalAux(c, n.sons[1], {efLValue})
|
||||
if isSpecial(result): return
|
||||
if result.kind != nkSym: InternalError(n.info, "no symbol")
|
||||
if result.kind != nkSym: stackTrace(c, n, errFieldXNotFound, "symbol")
|
||||
of mNIdent:
|
||||
result = evalAux(c, n.sons[1], {})
|
||||
if isSpecial(result): return
|
||||
if result.kind != nkIdent: InternalError(n.info, "no symbol")
|
||||
if result.kind != nkIdent: stackTrace(c, n, errFieldXNotFound, "ident")
|
||||
of mNGetType: result = evalAux(c, n.sons[1], {})
|
||||
of mNStrVal:
|
||||
result = evalAux(c, n.sons[1], {})
|
||||
@@ -1105,14 +1110,18 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
|
||||
result = newNodeIT(nkStrLit, n.info, n.typ)
|
||||
case a.kind
|
||||
of nkStrLit..nkTripleStrLit: result.strVal = a.strVal
|
||||
else: InternalError(n.info, "no string value")
|
||||
else: stackTrace(c, n, errFieldXNotFound, "strVal")
|
||||
of mNSetIntVal:
|
||||
result = evalAux(c, n.sons[1], {efLValue})
|
||||
if isSpecial(result): return
|
||||
var a = result
|
||||
result = evalAux(c, n.sons[2], {})
|
||||
if isSpecial(result): return
|
||||
a.intVal = result.intVal # XXX: exception handling?
|
||||
if isSpecial(result): return
|
||||
if a.kind in {nkCharLit..nkInt64Lit} and
|
||||
result.kind in {nkCharLit..nkInt64Lit}:
|
||||
a.intVal = result.intVal
|
||||
else:
|
||||
stackTrace(c, n, errFieldXNotFound, "intVal")
|
||||
result = emptyNode
|
||||
of mNSetFloatVal:
|
||||
result = evalAux(c, n.sons[1], {efLValue})
|
||||
@@ -1120,7 +1129,11 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
|
||||
var a = result
|
||||
result = evalAux(c, n.sons[2], {})
|
||||
if isSpecial(result): return
|
||||
a.floatVal = result.floatVal # XXX: exception handling?
|
||||
if a.kind in {nkFloatLit..nkFloat64Lit} and
|
||||
result.kind in {nkFloatLit..nkFloat64Lit}:
|
||||
a.floatVal = result.floatVal
|
||||
else:
|
||||
stackTrace(c, n, errFieldXNotFound, "floatVal")
|
||||
result = emptyNode
|
||||
of mNSetSymbol:
|
||||
result = evalAux(c, n.sons[1], {efLValue})
|
||||
@@ -1128,7 +1141,10 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
|
||||
var a = result
|
||||
result = evalAux(c, n.sons[2], {efLValue})
|
||||
if isSpecial(result): return
|
||||
a.sym = result.sym # XXX: exception handling?
|
||||
if a.kind == nkSym and result.kind == nkSym:
|
||||
a.sym = result.sym
|
||||
else:
|
||||
stackTrace(c, n, errFieldXNotFound, "symbol")
|
||||
result = emptyNode
|
||||
of mNSetIdent:
|
||||
result = evalAux(c, n.sons[1], {efLValue})
|
||||
@@ -1136,7 +1152,10 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
|
||||
var a = result
|
||||
result = evalAux(c, n.sons[2], {efLValue})
|
||||
if isSpecial(result): return
|
||||
a.ident = result.ident # XXX: exception handling?
|
||||
if a.kind == nkIdent and result.kind == nkIdent:
|
||||
a.ident = result.ident
|
||||
else:
|
||||
stackTrace(c, n, errFieldXNotFound, "ident")
|
||||
result = emptyNode
|
||||
of mNSetType:
|
||||
result = evalAux(c, n.sons[1], {efLValue})
|
||||
@@ -1146,13 +1165,17 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
|
||||
if isSpecial(result): return
|
||||
a.typ = result.typ # XXX: exception handling?
|
||||
result = emptyNode
|
||||
of mNSetStrVal:
|
||||
of mNSetStrVal:
|
||||
result = evalAux(c, n.sons[1], {efLValue})
|
||||
if isSpecial(result): return
|
||||
var a = result
|
||||
result = evalAux(c, n.sons[2], {})
|
||||
if isSpecial(result): return
|
||||
a.strVal = result.strVal # XXX: exception handling?
|
||||
if isSpecial(result): return
|
||||
|
||||
if a.kind in {nkStrLit..nkTripleStrLit} and
|
||||
result.kind in {nkStrLit..nkTripleStrLit}:
|
||||
a.strVal = result.strVal
|
||||
else: stackTrace(c, n, errFieldXNotFound, "strVal")
|
||||
result = emptyNode
|
||||
of mNNewNimNode:
|
||||
result = evalAux(c, n.sons[1], {})
|
||||
@@ -1177,7 +1200,8 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
|
||||
result = evalAux(c, n.sons[1], {})
|
||||
if isSpecial(result): return
|
||||
if not (result.kind in {nkStrLit..nkTripleStrLit}):
|
||||
InternalError(n.info, "no string node")
|
||||
stackTrace(c, n, errFieldXNotFound, "strVal")
|
||||
return
|
||||
var a = result
|
||||
result = newNodeIT(nkIdent, n.info, n.typ)
|
||||
result.ident = getIdent(a.strVal)
|
||||
|
||||
@@ -60,7 +60,9 @@ proc getSymRepr*(s: PSym): string =
|
||||
|
||||
proc CloseScope*(tab: var TSymTab) =
|
||||
# check if all symbols have been used and defined:
|
||||
if tab.tos > len(tab.stack): InternalError("CloseScope")
|
||||
if tab.tos > len(tab.stack):
|
||||
InternalError("CloseScope")
|
||||
return
|
||||
var it: TTabIter
|
||||
var s = InitTabIter(it, tab.stack[tab.tos-1])
|
||||
var missingImpls = 0
|
||||
@@ -95,8 +97,8 @@ proc addDeclAt*(c: PContext, sym: PSym, at: Natural) =
|
||||
proc AddInterfaceDeclAux(c: PContext, sym: PSym) =
|
||||
if sfExported in sym.flags:
|
||||
# add to interface:
|
||||
if c.module == nil: InternalError(sym.info, "AddInterfaceDeclAux")
|
||||
StrTableAdd(c.module.tab, sym)
|
||||
if c.module != nil: StrTableAdd(c.module.tab, sym)
|
||||
else: InternalError(sym.info, "AddInterfaceDeclAux")
|
||||
#if getCurrOwner().kind == skModule: incl(sym.flags, sfGlobal)
|
||||
|
||||
proc addInterfaceDeclAt*(c: PContext, sym: PSym, at: Natural) =
|
||||
@@ -106,6 +108,7 @@ proc addInterfaceDeclAt*(c: PContext, sym: PSym, at: Natural) =
|
||||
proc addOverloadableSymAt*(c: PContext, fn: PSym, at: Natural) =
|
||||
if fn.kind notin OverloadableSyms:
|
||||
InternalError(fn.info, "addOverloadableSymAt")
|
||||
return
|
||||
var check = StrTableGet(c.tab.stack[at], fn.name)
|
||||
if check != nil and check.Kind notin OverloadableSyms:
|
||||
LocalError(fn.info, errAttemptToRedefine, fn.Name.s)
|
||||
@@ -138,7 +141,9 @@ proc lookUp*(c: PContext, n: PNode): PSym =
|
||||
if result == nil:
|
||||
LocalError(n.info, errUndeclaredIdentifier, ident.s)
|
||||
result = errorSym(n)
|
||||
else: InternalError(n.info, "lookUp")
|
||||
else:
|
||||
InternalError(n.info, "lookUp")
|
||||
return
|
||||
if Contains(c.AmbiguousSymbols, result.id):
|
||||
LocalError(n.info, errUseQualifier, result.name.s)
|
||||
if result.kind == skStub: loadStub(result)
|
||||
|
||||
@@ -78,7 +78,8 @@ proc CompileModule(filename: string, flags: TSymFlags): PSym =
|
||||
rd = handleSymbolFile(result, f)
|
||||
if result.id < 0:
|
||||
InternalError("handleSymbolFile should have set the module\'s ID")
|
||||
else:
|
||||
return
|
||||
else:
|
||||
result.id = getID()
|
||||
processModule(result, f, nil, rd)
|
||||
|
||||
|
||||
@@ -30,8 +30,10 @@ proc equalGenericParams(procA, procB: PNode): bool =
|
||||
for i in countup(0, sonsLen(procA) - 1):
|
||||
if procA.sons[i].kind != nkSym:
|
||||
InternalError(procA.info, "equalGenericParams")
|
||||
return
|
||||
if procB.sons[i].kind != nkSym:
|
||||
InternalError(procB.info, "equalGenericParams")
|
||||
return
|
||||
a = procA.sons[i].sym
|
||||
b = procB.sons[i].sym
|
||||
if (a.name.id != b.name.id) or not sameTypeOrNil(a.typ, b.typ): return
|
||||
|
||||
@@ -237,7 +237,8 @@ proc ropef(frmt: TFormatStr, args: openarray[PRope]): PRope =
|
||||
num = j
|
||||
if j > high(args) + 1:
|
||||
internalError("ropes: invalid format string $" & $(j))
|
||||
app(result, args[j - 1])
|
||||
else:
|
||||
app(result, args[j - 1])
|
||||
of 'n':
|
||||
if optLineDir notin gOptions: app(result, tnl)
|
||||
inc i
|
||||
@@ -263,6 +264,7 @@ proc auxRopeEqualsFile(r: PRope, bin: var tfile, buf: Pointer): bool =
|
||||
if r.data != nil:
|
||||
if r.length > bufSize:
|
||||
internalError("ropes: token too long")
|
||||
return
|
||||
var readBytes = readBuffer(bin, buf, r.length)
|
||||
result = readBytes == r.length and
|
||||
equalMem(buf, addr(r.data[0]), r.length) # BUGFIX
|
||||
|
||||
@@ -152,7 +152,8 @@ proc addCodeForGenerics(c: PContext, n: PNode) =
|
||||
if prc.kind in {skProc, skMethod, skConverter} and prc.magic == mNone:
|
||||
if prc.ast == nil or prc.ast.sons[bodyPos] == nil:
|
||||
InternalError(prc.info, "no code for " & prc.name.s)
|
||||
addSon(n, prc.ast)
|
||||
else:
|
||||
addSon(n, prc.ast)
|
||||
c.generics.lastGenericIdx = Len(c.generics.generics)
|
||||
|
||||
proc semExprNoFlags(c: PContext, n: PNode): PNode {.procvar.} =
|
||||
@@ -160,7 +161,7 @@ proc semExprNoFlags(c: PContext, n: PNode): PNode {.procvar.} =
|
||||
|
||||
proc myOpen(module: PSym, filename: string): PPassContext =
|
||||
var c = newContext(module, filename)
|
||||
if (c.p != nil): InternalError(module.info, "sem.myOpen")
|
||||
if c.p != nil: InternalError(module.info, "sem.myOpen")
|
||||
c.semConstExpr = semConstExpr
|
||||
c.semExpr = semExprNoFlags
|
||||
c.semConstBoolExpr = semConstBoolExpr
|
||||
@@ -224,9 +225,8 @@ proc myClose(context: PPassContext, n: PNode): PNode =
|
||||
var c = PContext(context)
|
||||
closeScope(c.tab) # close module's scope
|
||||
rawCloseScope(c.tab) # imported symbols; don't check for unused ones!
|
||||
if n == nil:
|
||||
result = newNode(nkStmtList)
|
||||
else:
|
||||
result = newNode(nkStmtList)
|
||||
if n != nil:
|
||||
InternalError(n.info, "n is not nil") #result := n;
|
||||
addCodeForGenerics(c, result)
|
||||
if c.module.ast != nil:
|
||||
|
||||
@@ -368,6 +368,7 @@ proc semRecordCase(c: PContext, n: PNode, check: var TIntSet, pos: var int,
|
||||
semRecordNodeAux(c, n.sons[0], check, pos, a, rectype)
|
||||
if a.sons[0].kind != nkSym:
|
||||
internalError("semRecordCase: dicriminant is no symbol")
|
||||
return
|
||||
incl(a.sons[0].sym.flags, sfDiscriminant)
|
||||
var covered: biggestInt = 0
|
||||
var typ = skipTypes(a.sons[0].Typ, abstractVar)
|
||||
|
||||
@@ -56,8 +56,9 @@ template wholeSymTab(cond, section: expr) {.immediate.} =
|
||||
|
||||
proc suggestSymList(list: PNode, outputs: var int) =
|
||||
for i in countup(0, sonsLen(list) - 1):
|
||||
if list.sons[i].kind != nkSym: InternalError(list.info, "getSymFromList")
|
||||
suggestField(list.sons[i].sym, outputs)
|
||||
if list.sons[i].kind == nkSym:
|
||||
suggestField(list.sons[i].sym, outputs)
|
||||
#else: InternalError(list.info, "getSymFromList")
|
||||
|
||||
proc suggestObject(n: PNode, outputs: var int) =
|
||||
case n.kind
|
||||
|
||||
@@ -88,7 +88,7 @@ proc getOpSym*(op: PNode): PSym =
|
||||
result = nil
|
||||
else:
|
||||
if (sonsLen(op) <= 0): InternalError(op.info, "getOpSym")
|
||||
if op.sons[0].Kind == nkSym: result = op.sons[0].sym
|
||||
elif op.sons[0].Kind == nkSym: result = op.sons[0].sym
|
||||
else: result = nil
|
||||
|
||||
proc getMagic*(op: PNode): TMagic =
|
||||
|
||||
@@ -121,11 +121,13 @@ proc getProcHeader(sym: PSym): string =
|
||||
var n = sym.typ.n
|
||||
for i in countup(1, sonsLen(n) - 1):
|
||||
var p = n.sons[i]
|
||||
if p.kind != nkSym: InternalError("getProcHeader")
|
||||
add(result, p.sym.name.s)
|
||||
add(result, ": ")
|
||||
add(result, typeToString(p.sym.typ))
|
||||
if i != sonsLen(n)-1: add(result, ", ")
|
||||
if p.kind == nkSym:
|
||||
add(result, p.sym.name.s)
|
||||
add(result, ": ")
|
||||
add(result, typeToString(p.sym.typ))
|
||||
if i != sonsLen(n)-1: add(result, ", ")
|
||||
else:
|
||||
InternalError("getProcHeader")
|
||||
add(result, ')')
|
||||
if n.sons[0].typ != nil: result.add(": " & typeToString(n.sons[0].typ))
|
||||
|
||||
@@ -680,13 +682,13 @@ proc sameTuple(a, b: PType, c: var TSameTypeClosure): bool =
|
||||
if a.n != nil and b.n != nil and not c.ignoreTupleFields:
|
||||
for i in countup(0, sonsLen(a.n) - 1):
|
||||
# check field names:
|
||||
if a.n.sons[i].kind != nkSym: InternalError(a.n.info, "sameTuple")
|
||||
if b.n.sons[i].kind != nkSym: InternalError(b.n.info, "sameTuple")
|
||||
var x = a.n.sons[i].sym
|
||||
var y = b.n.sons[i].sym
|
||||
result = x.name.id == y.name.id
|
||||
if not result: break
|
||||
else:
|
||||
if a.n.sons[i].kind == nkSym and b.n.sons[i].kind == nkSym:
|
||||
var x = a.n.sons[i].sym
|
||||
var y = b.n.sons[i].sym
|
||||
result = x.name.id == y.name.id
|
||||
if not result: break
|
||||
else: InternalError(a.n.info, "sameTuple")
|
||||
else:
|
||||
result = false
|
||||
|
||||
template IfFastObjectTypeCheckFailed(a, b: PType, body: stmt) =
|
||||
@@ -1094,7 +1096,7 @@ proc getReturnType*(s: PSym): PType =
|
||||
|
||||
proc getSize(typ: PType): biggestInt =
|
||||
result = computeSize(typ)
|
||||
if result < 0: InternalError("getSize(" & $typ.kind & ')')
|
||||
if result < 0: InternalError("getSize: " & $typ.kind)
|
||||
|
||||
|
||||
proc containsGenericTypeIter(t: PType, closure: PObject): bool =
|
||||
|
||||
Reference in New Issue
Block a user