From 48a62af3b13015cc7eda194b9f6ec7e194456e74 Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 11 Nov 2012 22:03:41 +0100 Subject: implemented 'tags' pragma --- compiler/pragmas.nim | 15 +++-- compiler/sempass2.nim | 156 ++++++++++++++++++++++++++++----------------- compiler/types.nim | 41 ++++++++---- compiler/wordrecg.nim | 6 +- doc/manual.txt | 6 +- lib/system.nim | 10 +++ tests/reject/teffects3.nim | 19 ++++++ tests/reject/teffects4.nim | 24 +++++++ web/news.txt | 4 +- 9 files changed, 193 insertions(+), 88 deletions(-) create mode 100644 tests/reject/teffects3.nim create mode 100644 tests/reject/teffects4.nim diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 65574e80e..f874a0acf 100755 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -24,7 +24,7 @@ const wCompilerProc, wProcVar, wDeprecated, wVarargs, wCompileTime, wMerge, wBorrow, wExtern, wImportCompilerProc, wThread, wImportCpp, wImportObjC, wNoStackFrame, wError, wDiscardable, wNoInit, wDestructor, wHoist, - wGenSym, wInject, wRaises} + wGenSym, wInject, wRaises, wTags} converterPragmas* = procPragmas methodPragmas* = procPragmas templatePragmas* = {wImmediate, wDeprecated, wError, wGenSym, wInject, wDirty} @@ -33,7 +33,8 @@ const wImportcpp, wImportobjc, wError, wDiscardable, wGenSym, wInject} iteratorPragmas* = {FirstCallConv..LastCallConv, wNosideEffect, wSideEffect, wImportc, wExportc, wNodecl, wMagic, wDeprecated, wBorrow, wExtern, - wImportcpp, wImportobjc, wError, wDiscardable, wGenSym, wInject, wRaises} + wImportcpp, wImportobjc, wError, wDiscardable, wGenSym, wInject, wRaises, + wTags} exprPragmas* = {wLine} stmtPragmas* = {wChecks, wObjChecks, wFieldChecks, wRangechecks, wBoundchecks, wOverflowchecks, wNilchecks, wAssertions, wWarnings, wHints, @@ -45,7 +46,7 @@ const lambdaPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc, wNodecl, wNosideEffect, wSideEffect, wNoreturn, wDynLib, wHeader, wDeprecated, wExtern, wThread, wImportcpp, wImportobjc, wNoStackFrame, - wRaises} + wRaises, wTags} typePragmas* = {wImportc, wExportc, wDeprecated, wMagic, wAcyclic, wNodecl, wPure, wHeader, wCompilerProc, wFinal, wSize, wExtern, wShallow, wImportcpp, wImportobjc, wError, wIncompleteStruct, wByCopy, wByRef, @@ -60,7 +61,7 @@ const wExtern, wImportcpp, wImportobjc, wError, wGenSym, wInject} letPragmas* = varPragmas procTypePragmas* = {FirstCallConv..LastCallConv, wVarargs, wNosideEffect, - wThread, wRaises} + wThread, wRaises, wTags} allRoutinePragmas* = procPragmas + iteratorPragmas + lambdaPragmas proc pragma*(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) @@ -464,11 +465,11 @@ proc processPragma(c: PContext, n: PNode, i: int) = userPragma.ast = body StrTableAdd(c.userPragmas, userPragma) -proc pragmaRaises(c: PContext, n: PNode) = +proc pragmaRaisesOrTags(c: PContext, n: PNode) = proc processExc(c: PContext, x: PNode) = var t = skipTypes(c.semTypeNode(c, x, nil), skipPtrs) if t.kind != tyObject: - localError(x.info, errGenerated, "invalid exception type") + localError(x.info, errGenerated, "invalid type for raises/tags list") x.typ = t if n.kind == nkExprColonExpr: @@ -696,7 +697,7 @@ proc pragma(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) = noVal(it) if sym == nil: invalidPragma(it) of wLine: PragmaLine(c, it) - of wRaises: pragmaRaises(c, it) + of wRaises, wTags: pragmaRaisesOrTags(c, it) else: invalidPragma(it) else: invalidPragma(it) else: processNote(c, it) diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 422eb4475..59ae26385 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -53,7 +53,7 @@ when false: assert n.kind == nkSym -# ------------------------ exception tracking ------------------------------- +# ------------------------ exception and tag tracking ------------------------- discard """ exception tracking: @@ -79,15 +79,15 @@ discard """ type TEffects = object exc: PNode # stack of exceptions + tags: PNode # list of tags bottom: int PEffects = var TEffects -proc throws(tracked: PEffects, n: PNode) = - if n.typ == nil or n.typ.kind != tyError: tracked.exc.add n +proc throws(tracked, n: PNode) = + if n.typ == nil or n.typ.kind != tyError: tracked.add n proc excType(n: PNode): PType = - assert n.kind != nkRaiseStmt # reraise is like raising E_Base: let t = if n.kind == nkEmpty: sysTypeFromName"E_Base" else: n.typ result = skipTypes(t, skipPtrs) @@ -99,15 +99,25 @@ proc addEffect(a: PEffects, e: PNode, useLineInfo=true) = if sameType(aa[i].excType, e.excType): if not useLineInfo: return elif aa[i].info == e.info: return - throws(a, e) + throws(a.exc, e) -proc mergeEffects(a: PEffects, b: PNode, useLineInfo) = +proc mergeEffects(a: PEffects, b: PNode, useLineInfo: bool) = for effect in items(b): addEffect(a, effect, useLineInfo) +proc addTag(a: PEffects, e: PNode, useLineInfo=true) = + var aa = a.tags + for i in 0 .. `_. - Summary ------- -- cgit 1.4.1-2-gfad0