summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-11-19 00:16:25 +0100
committerAraq <rumpf_a@web.de>2012-11-19 00:16:25 +0100
commit14fc0631d7cfa7436b9703fd8d08235b2b5929b7 (patch)
tree2bf9c695b6b442bc33aa6e2eebb436e8bd986f15
parentdb80038c378f4b63845cb1b035f2b3dfdd25c2fc (diff)
downloadNim-14fc0631d7cfa7436b9703fd8d08235b2b5929b7.tar.gz
fixes #250
-rwxr-xr-xcompiler/ast.nim2
-rwxr-xr-xcompiler/msgs.nim9
-rwxr-xr-xcompiler/semstmts.nim4
-rwxr-xr-xdoc/nimrodc.txt32
-rw-r--r--lib/impure/db_mongo.nim4
-rwxr-xr-xlib/impure/db_mysql.nim4
-rwxr-xr-xlib/impure/db_postgres.nim4
-rwxr-xr-xlib/impure/db_sqlite.nim4
-rwxr-xr-xlib/system/ansi_c.nim16
-rwxr-xr-xtodo.txt3
-rwxr-xr-xweb/news.txt2
11 files changed, 62 insertions, 22 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index cdca68c20..f4b0d00a0 100755
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -726,7 +726,7 @@ const
   nkSymChoices* = {nkClosedSymChoice, nkOpenSymChoice}
   nkStrKinds* = {nkStrLit..nkTripleStrLit}
 
-  skLocalVars* = {skVar, skLet, skForVar, skParam}
+  skLocalVars* = {skVar, skLet, skForVar, skParam, skResult}
 
 
 # creator procs:
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index 45075cba8..0f795c07d 100755
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -104,7 +104,7 @@ type
     warnUnknownSubstitutionX, warnLanguageXNotSupported, warnCommentXIgnored, 
     warnNilStatement, warnAnalysisLoophole,
     warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitClosure,
-    warnEachIdentIsTuple, warnUser,
+    warnEachIdentIsTuple, warnShadowIdent, warnUser,
     hintSuccess, hintSuccessX, 
     hintLineTooLong, hintXDeclaredButNotUsed, hintConvToBaseNotNeeded, 
     hintConvFromXtoItselfNotNeeded, hintExprAlwaysX, hintQuitCalled, 
@@ -351,6 +351,7 @@ const
     warnWriteToForeignHeap: "write to foreign heap [WriteToForeignHeap]",
     warnImplicitClosure: "implicit closure convention: '$1' [ImplicitClosure]",
     warnEachIdentIsTuple: "each identifier is a tuple [EachIdentIsTuple]",
+    warnShadowIdent: "shadowed identifier: '$1' [ShadowIdent]",
     warnUser: "$1 [User]", 
     hintSuccess: "operation successful [Success]", 
     hintSuccessX: "operation successful ($# lines compiled; $# sec total; $#) [SuccessX]", 
@@ -370,14 +371,14 @@ const
     hintUser: "$1 [User]"]
 
 const
-  WarningsToStr*: array[0..18, string] = ["CannotOpenFile", "OctalEscape", 
+  WarningsToStr*: array[0..19, string] = ["CannotOpenFile", "OctalEscape", 
     "XIsNeverRead", "XmightNotBeenInit",
     "Deprecated", "ConfigDeprecated",
     "SmallLshouldNotBeUsed", "UnknownMagic", 
     "RedefinitionOfLabel", "UnknownSubstitutionX", "LanguageXNotSupported", 
     "CommentXIgnored", "NilStmt",
     "AnalysisLoophole", "DifferentHeaps", "WriteToForeignHeap",
-    "ImplicitClosure", "EachIdentIsTuple", "User"]
+    "ImplicitClosure", "EachIdentIsTuple", "ShadowIdent", "User"]
 
   HintsToStr*: array[0..15, string] = ["Success", "SuccessX", "LineTooLong", 
     "XDeclaredButNotUsed", "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded", 
@@ -464,7 +465,7 @@ proc raiseRecoverableError*(msg: string) {.noinline, noreturn.} =
   raise newException(ERecoverableError, msg)
 
 var
-  gNotes*: TNoteKinds = {low(TNoteKind)..high(TNoteKind)}
+  gNotes*: TNoteKinds = {low(TNoteKind)..high(TNoteKind)} - {warnShadowIdent}
   gErrorCounter*: int = 0     # counts the number of errors
   gHintCounter*: int = 0
   gWarnCounter*: int = 0
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index b0cef2df7..e613f23af 100755
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -237,7 +237,9 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
         if c.InUnrolledContext > 0: v.flags.incl(sfShadowed)
         else:
           let shadowed = findShadowedVar(c, v)
-          if shadowed != nil: shadowed.flags.incl(sfShadowed)
+          if shadowed != nil:
+            shadowed.flags.incl(sfShadowed)
+            Message(a.info, warnShadowIdent, v.name.s)
       if def != nil and def.kind != nkEmpty:
         # this is only needed for the evaluation pass:
         v.ast = def
diff --git a/doc/nimrodc.txt b/doc/nimrodc.txt
index 8e43ce32c..06a0f4500 100755
--- a/doc/nimrodc.txt
+++ b/doc/nimrodc.txt
@@ -36,6 +36,38 @@ Advanced command line switches are:
 

 .. include:: advopt.txt

 

+
+
+List of warnings
+----------------
+
+Each warning can be activated individually with ``--warning[NAME]:on|off`` or
+in a ``push`` pragma. 
+
+==========================       ============================================
+Name                             Description
+==========================       ============================================
+CannotOpenFile                   Some file not essential for the compiler's
+                                 working could not be opened.
+OctalEscape                      The code contains an unsupported octal 
+                                 sequence.
+Deprecated                       The code uses a deprecated symbol.
+ConfigDeprecated                 The project makes use of a deprecated config
+                                 file.
+SmallLshouldNotBeUsed            The letter 'l' should not be used as an 
+                                 identifier.
+AnalysisLoophole                 The thread analysis was incomplete due to
+                                 an indirect call.
+DifferentHeaps                   The code mixes different local heaps in a
+                                 very dangerous way.
+WriteToForeignHeap               The code contains a threading error. 
+EachIdentIsTuple                 The code contains a confusing ``var`` 
+                                 declaration.
+ShadowIdent                      A local variable shadows another local 
+                                 variable of an outer scope.
+User                             Some user defined warning.
+==========================       ============================================
+
 

 Configuration files

 -------------------

diff --git a/lib/impure/db_mongo.nim b/lib/impure/db_mongo.nim
index b7fb325f9..b11db78f8 100644
--- a/lib/impure/db_mongo.nim
+++ b/lib/impure/db_mongo.nim
@@ -34,8 +34,8 @@ type
   TDbConn* = TMongo    ## a database connection; alias for ``TMongo``
 
   FDb* = object of FIO ## effect that denotes a database operation
-  FReadDb* = object of FReadIO   ## effect that denotes a read operation
-  FWriteDb* = object of FWriteIO ## effect that denotes a write operation
+  FReadDb* = object of FDB   ## effect that denotes a read operation
+  FWriteDb* = object of FDB  ## effect that denotes a write operation
 
 proc dbError*(db: TDbConn, msg: string) {.noreturn.} = 
   ## raises an EDb exception with message `msg`.
diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim
index 118ed39bb..5c71fc90d 100755
--- a/lib/impure/db_mysql.nim
+++ b/lib/impure/db_mysql.nim
@@ -20,8 +20,8 @@ type
   TSqlQuery* = distinct string ## an SQL query string
 
   FDb* = object of FIO ## effect that denotes a database operation
-  FReadDb* = object of FReadIO   ## effect that denotes a read operation
-  FWriteDb* = object of FWriteIO ## effect that denotes a write operation
+  FReadDb* = object of FDb   ## effect that denotes a read operation
+  FWriteDb* = object of FDb  ## effect that denotes a write operation
 
 proc dbError(db: TDbConn) {.noreturn.} = 
   ## raises an EDb exception.
diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim
index 2e2b09bc2..870960140 100755
--- a/lib/impure/db_postgres.nim
+++ b/lib/impure/db_postgres.nim
@@ -20,8 +20,8 @@ type
   TSqlQuery* = distinct string ## an SQL query string
 
   FDb* = object of FIO ## effect that denotes a database operation
-  FReadDb* = object of FReadIO   ## effect that denotes a read operation
-  FWriteDb* = object of FWriteIO ## effect that denotes a write operation
+  FReadDb* = object of FDB   ## effect that denotes a read operation
+  FWriteDb* = object of FDB  ## effect that denotes a write operation
   
 proc sql*(query: string): TSqlQuery {.noSideEffect, inline.} =  
   ## constructs a TSqlQuery from the string `query`. This is supposed to be 
diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim
index e9864c599..fbc097784 100755
--- a/lib/impure/db_sqlite.nim
+++ b/lib/impure/db_sqlite.nim
@@ -20,8 +20,8 @@ type
   TSqlQuery* = distinct string ## an SQL query string
   
   FDb* = object of FIO ## effect that denotes a database operation
-  FReadDb* = object of FReadIO   ## effect that denotes a read operation
-  FWriteDb* = object of FWriteIO ## effect that denotes a write operation
+  FReadDb* = object of FDB   ## effect that denotes a read operation
+  FWriteDb* = object of FDB  ## effect that denotes a write operation
   
 proc sql*(query: string): TSqlQuery {.noSideEffect, inline.} =  
   ## constructs a TSqlQuery from the string `query`. This is supposed to be 
diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim
index 486f5dd26..195bc2e60 100755
--- a/lib/system/ansi_c.nim
+++ b/lib/system/ansi_c.nim
@@ -35,12 +35,13 @@ var
   c_stderr {.importc: "stderr", noDecl.}: C_TextFileStar
 
 # constants faked as variables:
-var 
-  SIGINT {.importc: "SIGINT", nodecl.}: cint
-  SIGSEGV {.importc: "SIGSEGV", nodecl.}: cint
-  SIGABRT {.importc: "SIGABRT", nodecl.}: cint
-  SIGFPE {.importc: "SIGFPE", nodecl.}: cint
-  SIGILL {.importc: "SIGILL", nodecl.}: cint
+when not defined(SIGINT):
+  var 
+    SIGINT {.importc: "SIGINT", nodecl.}: cint
+    SIGSEGV {.importc: "SIGSEGV", nodecl.}: cint
+    SIGABRT {.importc: "SIGABRT", nodecl.}: cint
+    SIGFPE {.importc: "SIGFPE", nodecl.}: cint
+    SIGILL {.importc: "SIGILL", nodecl.}: cint
 
 when defined(macosx):
   var
@@ -95,7 +96,8 @@ proc c_malloc(size: int): pointer {.importc: "malloc", nodecl.}
 proc c_free(p: pointer) {.importc: "free", nodecl.}
 proc c_realloc(p: pointer, newsize: int): pointer {.importc: "realloc", nodecl.}
 
-var errno {.importc, header: "<errno.h>".}: cint ## error variable
+when not defined(errno):
+  var errno {.importc, header: "<errno.h>".}: cint ## error variable
 proc strerror(errnum: cint): cstring {.importc, header: "<string.h>".}
 
 proc c_remove(filename: CString): cint {.importc: "remove", noDecl.}
diff --git a/todo.txt b/todo.txt
index f31edfa39..a754bc650 100755
--- a/todo.txt
+++ b/todo.txt
@@ -152,7 +152,8 @@ Version 2 and beyond
   "stop the world". However, it may be worthwhile to generate explicit 
   (or implicit) syncGC() calls in loops. Automatic loop injection seems
   troublesome, but maybe we can come up with a simple heuristic. (All procs
-  that `new` shared memory are syncGC() candidates...)
+  that `new` shared memory are syncGC() candidates... But then 'new' itself
+  calls syncGC() so that's pointless.)
 
 - const ptr/ref  --> pointless because of aliasing; 
   much better: 'writes: []' effect
diff --git a/web/news.txt b/web/news.txt
index b73a32268..8474db4f9 100755
--- a/web/news.txt
+++ b/web/news.txt
@@ -27,6 +27,8 @@ Changes affecting backwards compatibility
 Compiler Additions
 ------------------
 
+- The compiler can now warn about shadowed local variables. However, this needs
+  to be turned on explicitly via ``--warning[ShadowIdent]:on``.
 
 
 Language Additions