diff options
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/ast.nim | 2 | ||||
-rwxr-xr-x | compiler/evals.nim | 11 | ||||
-rwxr-xr-x | compiler/msgs.nim | 6 | ||||
-rwxr-xr-x | compiler/semstmts.nim | 14 |
4 files changed, 24 insertions, 9 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index b33d99554..e60a52fc6 100755 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -369,7 +369,7 @@ type mCompileOption, mCompileOptionArg, mNLen, mNChild, mNSetChild, mNAdd, mNAddMultiple, mNDel, mNKind, mNIntVal, mNFloatVal, mNSymbol, mNIdent, mNGetType, mNStrVal, mNSetIntVal, - mNSetFloatVal, mNSetSymbol, mNSetIdent, mNSetType, mNSetStrVal, + mNSetFloatVal, mNSetSymbol, mNSetIdent, mNSetType, mNSetStrVal, mNLineInfo, mNNewNimNode, mNCopyNimNode, mNCopyNimTree, mStrToIdent, mIdentToStr, mEqIdent, mEqNimrodNode, mNHint, mNWarning, mNError, mGetTypeInfo diff --git a/compiler/evals.nim b/compiler/evals.nim index b7b3746a5..db15b0370 100755 --- a/compiler/evals.nim +++ b/compiler/evals.nim @@ -798,8 +798,9 @@ proc evalMacroCall*(c: PEvalContext, n: PNode, sym: PSym): PNode = import semdata, sem -proc evalExpandToAst(c: PEvalContext, n: PNode): PNode = - var +proc evalExpandToAst(c: PEvalContext, original: PNode): PNode = + var + n = original.copyTree macroCall = n.sons[1] expandedSym = macroCall.sons[0].sym @@ -854,7 +855,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode = of mParseExprToAst: result = evalParseExpr(c, n) of mParseStmtToAst: result = evalParseStmt(c, n) of mExpandMacroToAst: result = evalExpandToAst(c, n) - of mNLen: + of mNLen: result = evalAux(c, n.sons[1], {efLValue}) if isSpecial(result): return var a = result @@ -1060,6 +1061,10 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode = if (a == b) or (b.kind in {nkNilLit, nkEmpty}) and (a.kind in {nkNilLit, nkEmpty}): result.intVal = 1 + of mNLineInfo: + result = evalAux(c, n.sons[1], {}) + if isSpecial(result): return + result = newStrNodeT(result.info.toFileLineCol, n) of mAstToYaml: var ast = evalAux(c, n.sons[1], {efLValue}) result = newStrNode(nkStrLit, ast.treeToYaml.ropeToStr) diff --git a/compiler/msgs.nim b/compiler/msgs.nim index d34c6b410..4f8a21f54 100755 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -456,6 +456,12 @@ proc ToLinenumber*(info: TLineInfo): int {.inline.} = proc toColumn*(info: TLineInfo): int {.inline.} = result = info.col +proc toFileLine*(info: TLineInfo): string {.inline.} = + result = info.toFilename & ":" & $info.line + +proc toFileLineCol*(info: TLineInfo): string {.inline.} = + result = info.toFilename & "(" & $info.line & "," & $info.col & ")" + var checkPoints: seq[TLineInfo] = @[] proc addCheckpoint*(info: TLineInfo) = diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index c00b68bb5..057c99e94 100755 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -428,7 +428,7 @@ proc semRaise(c: PContext, n: PNode): PNode = var typ = n.sons[0].typ if typ.kind != tyRef or typ.sons[0].kind != tyObject: localError(n.info, errExprCannotBeRaised) - + proc semTry(c: PContext, n: PNode): PNode = result = n checkMinSonsLen(n, 2) @@ -438,15 +438,19 @@ proc semTry(c: PContext, n: PNode): PNode = var a = n.sons[i] checkMinSonsLen(a, 1) var length = sonsLen(a) - if a.kind == nkExceptBranch: - for j in countup(0, length - 2): + if a.kind == nkExceptBranch: + if length == 2 and a.sons[0].kind == nkBracket: + a.sons.splice(0, 1, a.sons[0].sons) + length = a.sonsLen + + for j in countup(0, length - 2): var typ = semTypeNode(c, a.sons[j], nil) if typ.kind == tyRef: typ = typ.sons[0] - if typ.kind != tyObject: + if typ.kind != tyObject: GlobalError(a.sons[j].info, errExprCannotBeRaised) a.sons[j] = newNodeI(nkType, a.sons[j].info) a.sons[j].typ = typ - if ContainsOrIncl(check, typ.id): + if ContainsOrIncl(check, typ.id): localError(a.sons[j].info, errExceptionAlreadyHandled) elif a.kind != nkFinally: illFormedAst(n) |