fixes #250
This commit is contained in:
parent
db80038c37
commit
14fc0631d7
11 changed files with 62 additions and 22 deletions
|
|
@ -726,7 +726,7 @@ const
|
||||||
nkSymChoices* = {nkClosedSymChoice, nkOpenSymChoice}
|
nkSymChoices* = {nkClosedSymChoice, nkOpenSymChoice}
|
||||||
nkStrKinds* = {nkStrLit..nkTripleStrLit}
|
nkStrKinds* = {nkStrLit..nkTripleStrLit}
|
||||||
|
|
||||||
skLocalVars* = {skVar, skLet, skForVar, skParam}
|
skLocalVars* = {skVar, skLet, skForVar, skParam, skResult}
|
||||||
|
|
||||||
|
|
||||||
# creator procs:
|
# creator procs:
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ type
|
||||||
warnUnknownSubstitutionX, warnLanguageXNotSupported, warnCommentXIgnored,
|
warnUnknownSubstitutionX, warnLanguageXNotSupported, warnCommentXIgnored,
|
||||||
warnNilStatement, warnAnalysisLoophole,
|
warnNilStatement, warnAnalysisLoophole,
|
||||||
warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitClosure,
|
warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitClosure,
|
||||||
warnEachIdentIsTuple, warnUser,
|
warnEachIdentIsTuple, warnShadowIdent, warnUser,
|
||||||
hintSuccess, hintSuccessX,
|
hintSuccess, hintSuccessX,
|
||||||
hintLineTooLong, hintXDeclaredButNotUsed, hintConvToBaseNotNeeded,
|
hintLineTooLong, hintXDeclaredButNotUsed, hintConvToBaseNotNeeded,
|
||||||
hintConvFromXtoItselfNotNeeded, hintExprAlwaysX, hintQuitCalled,
|
hintConvFromXtoItselfNotNeeded, hintExprAlwaysX, hintQuitCalled,
|
||||||
|
|
@ -351,6 +351,7 @@ const
|
||||||
warnWriteToForeignHeap: "write to foreign heap [WriteToForeignHeap]",
|
warnWriteToForeignHeap: "write to foreign heap [WriteToForeignHeap]",
|
||||||
warnImplicitClosure: "implicit closure convention: '$1' [ImplicitClosure]",
|
warnImplicitClosure: "implicit closure convention: '$1' [ImplicitClosure]",
|
||||||
warnEachIdentIsTuple: "each identifier is a tuple [EachIdentIsTuple]",
|
warnEachIdentIsTuple: "each identifier is a tuple [EachIdentIsTuple]",
|
||||||
|
warnShadowIdent: "shadowed identifier: '$1' [ShadowIdent]",
|
||||||
warnUser: "$1 [User]",
|
warnUser: "$1 [User]",
|
||||||
hintSuccess: "operation successful [Success]",
|
hintSuccess: "operation successful [Success]",
|
||||||
hintSuccessX: "operation successful ($# lines compiled; $# sec total; $#) [SuccessX]",
|
hintSuccessX: "operation successful ($# lines compiled; $# sec total; $#) [SuccessX]",
|
||||||
|
|
@ -370,14 +371,14 @@ const
|
||||||
hintUser: "$1 [User]"]
|
hintUser: "$1 [User]"]
|
||||||
|
|
||||||
const
|
const
|
||||||
WarningsToStr*: array[0..18, string] = ["CannotOpenFile", "OctalEscape",
|
WarningsToStr*: array[0..19, string] = ["CannotOpenFile", "OctalEscape",
|
||||||
"XIsNeverRead", "XmightNotBeenInit",
|
"XIsNeverRead", "XmightNotBeenInit",
|
||||||
"Deprecated", "ConfigDeprecated",
|
"Deprecated", "ConfigDeprecated",
|
||||||
"SmallLshouldNotBeUsed", "UnknownMagic",
|
"SmallLshouldNotBeUsed", "UnknownMagic",
|
||||||
"RedefinitionOfLabel", "UnknownSubstitutionX", "LanguageXNotSupported",
|
"RedefinitionOfLabel", "UnknownSubstitutionX", "LanguageXNotSupported",
|
||||||
"CommentXIgnored", "NilStmt",
|
"CommentXIgnored", "NilStmt",
|
||||||
"AnalysisLoophole", "DifferentHeaps", "WriteToForeignHeap",
|
"AnalysisLoophole", "DifferentHeaps", "WriteToForeignHeap",
|
||||||
"ImplicitClosure", "EachIdentIsTuple", "User"]
|
"ImplicitClosure", "EachIdentIsTuple", "ShadowIdent", "User"]
|
||||||
|
|
||||||
HintsToStr*: array[0..15, string] = ["Success", "SuccessX", "LineTooLong",
|
HintsToStr*: array[0..15, string] = ["Success", "SuccessX", "LineTooLong",
|
||||||
"XDeclaredButNotUsed", "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded",
|
"XDeclaredButNotUsed", "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded",
|
||||||
|
|
@ -464,7 +465,7 @@ proc raiseRecoverableError*(msg: string) {.noinline, noreturn.} =
|
||||||
raise newException(ERecoverableError, msg)
|
raise newException(ERecoverableError, msg)
|
||||||
|
|
||||||
var
|
var
|
||||||
gNotes*: TNoteKinds = {low(TNoteKind)..high(TNoteKind)}
|
gNotes*: TNoteKinds = {low(TNoteKind)..high(TNoteKind)} - {warnShadowIdent}
|
||||||
gErrorCounter*: int = 0 # counts the number of errors
|
gErrorCounter*: int = 0 # counts the number of errors
|
||||||
gHintCounter*: int = 0
|
gHintCounter*: int = 0
|
||||||
gWarnCounter*: int = 0
|
gWarnCounter*: int = 0
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,9 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
||||||
if c.InUnrolledContext > 0: v.flags.incl(sfShadowed)
|
if c.InUnrolledContext > 0: v.flags.incl(sfShadowed)
|
||||||
else:
|
else:
|
||||||
let shadowed = findShadowedVar(c, v)
|
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:
|
if def != nil and def.kind != nkEmpty:
|
||||||
# this is only needed for the evaluation pass:
|
# this is only needed for the evaluation pass:
|
||||||
v.ast = def
|
v.ast = def
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,38 @@ Advanced command line switches are:
|
||||||
.. include:: advopt.txt
|
.. 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
|
Configuration files
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ type
|
||||||
TDbConn* = TMongo ## a database connection; alias for ``TMongo``
|
TDbConn* = TMongo ## a database connection; alias for ``TMongo``
|
||||||
|
|
||||||
FDb* = object of FIO ## effect that denotes a database operation
|
FDb* = object of FIO ## effect that denotes a database operation
|
||||||
FReadDb* = object of FReadIO ## effect that denotes a read operation
|
FReadDb* = object of FDB ## effect that denotes a read operation
|
||||||
FWriteDb* = object of FWriteIO ## effect that denotes a write operation
|
FWriteDb* = object of FDB ## effect that denotes a write operation
|
||||||
|
|
||||||
proc dbError*(db: TDbConn, msg: string) {.noreturn.} =
|
proc dbError*(db: TDbConn, msg: string) {.noreturn.} =
|
||||||
## raises an EDb exception with message `msg`.
|
## raises an EDb exception with message `msg`.
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ type
|
||||||
TSqlQuery* = distinct string ## an SQL query string
|
TSqlQuery* = distinct string ## an SQL query string
|
||||||
|
|
||||||
FDb* = object of FIO ## effect that denotes a database operation
|
FDb* = object of FIO ## effect that denotes a database operation
|
||||||
FReadDb* = object of FReadIO ## effect that denotes a read operation
|
FReadDb* = object of FDb ## effect that denotes a read operation
|
||||||
FWriteDb* = object of FWriteIO ## effect that denotes a write operation
|
FWriteDb* = object of FDb ## effect that denotes a write operation
|
||||||
|
|
||||||
proc dbError(db: TDbConn) {.noreturn.} =
|
proc dbError(db: TDbConn) {.noreturn.} =
|
||||||
## raises an EDb exception.
|
## raises an EDb exception.
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ type
|
||||||
TSqlQuery* = distinct string ## an SQL query string
|
TSqlQuery* = distinct string ## an SQL query string
|
||||||
|
|
||||||
FDb* = object of FIO ## effect that denotes a database operation
|
FDb* = object of FIO ## effect that denotes a database operation
|
||||||
FReadDb* = object of FReadIO ## effect that denotes a read operation
|
FReadDb* = object of FDB ## effect that denotes a read operation
|
||||||
FWriteDb* = object of FWriteIO ## effect that denotes a write operation
|
FWriteDb* = object of FDB ## effect that denotes a write operation
|
||||||
|
|
||||||
proc sql*(query: string): TSqlQuery {.noSideEffect, inline.} =
|
proc sql*(query: string): TSqlQuery {.noSideEffect, inline.} =
|
||||||
## constructs a TSqlQuery from the string `query`. This is supposed to be
|
## constructs a TSqlQuery from the string `query`. This is supposed to be
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ type
|
||||||
TSqlQuery* = distinct string ## an SQL query string
|
TSqlQuery* = distinct string ## an SQL query string
|
||||||
|
|
||||||
FDb* = object of FIO ## effect that denotes a database operation
|
FDb* = object of FIO ## effect that denotes a database operation
|
||||||
FReadDb* = object of FReadIO ## effect that denotes a read operation
|
FReadDb* = object of FDB ## effect that denotes a read operation
|
||||||
FWriteDb* = object of FWriteIO ## effect that denotes a write operation
|
FWriteDb* = object of FDB ## effect that denotes a write operation
|
||||||
|
|
||||||
proc sql*(query: string): TSqlQuery {.noSideEffect, inline.} =
|
proc sql*(query: string): TSqlQuery {.noSideEffect, inline.} =
|
||||||
## constructs a TSqlQuery from the string `query`. This is supposed to be
|
## constructs a TSqlQuery from the string `query`. This is supposed to be
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ var
|
||||||
c_stderr {.importc: "stderr", noDecl.}: C_TextFileStar
|
c_stderr {.importc: "stderr", noDecl.}: C_TextFileStar
|
||||||
|
|
||||||
# constants faked as variables:
|
# constants faked as variables:
|
||||||
|
when not defined(SIGINT):
|
||||||
var
|
var
|
||||||
SIGINT {.importc: "SIGINT", nodecl.}: cint
|
SIGINT {.importc: "SIGINT", nodecl.}: cint
|
||||||
SIGSEGV {.importc: "SIGSEGV", nodecl.}: cint
|
SIGSEGV {.importc: "SIGSEGV", nodecl.}: cint
|
||||||
|
|
@ -95,6 +96,7 @@ proc c_malloc(size: int): pointer {.importc: "malloc", nodecl.}
|
||||||
proc c_free(p: pointer) {.importc: "free", nodecl.}
|
proc c_free(p: pointer) {.importc: "free", nodecl.}
|
||||||
proc c_realloc(p: pointer, newsize: int): pointer {.importc: "realloc", nodecl.}
|
proc c_realloc(p: pointer, newsize: int): pointer {.importc: "realloc", nodecl.}
|
||||||
|
|
||||||
|
when not defined(errno):
|
||||||
var errno {.importc, header: "<errno.h>".}: cint ## error variable
|
var errno {.importc, header: "<errno.h>".}: cint ## error variable
|
||||||
proc strerror(errnum: cint): cstring {.importc, header: "<string.h>".}
|
proc strerror(errnum: cint): cstring {.importc, header: "<string.h>".}
|
||||||
|
|
||||||
|
|
|
||||||
3
todo.txt
3
todo.txt
|
|
@ -152,7 +152,8 @@ Version 2 and beyond
|
||||||
"stop the world". However, it may be worthwhile to generate explicit
|
"stop the world". However, it may be worthwhile to generate explicit
|
||||||
(or implicit) syncGC() calls in loops. Automatic loop injection seems
|
(or implicit) syncGC() calls in loops. Automatic loop injection seems
|
||||||
troublesome, but maybe we can come up with a simple heuristic. (All procs
|
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;
|
- const ptr/ref --> pointless because of aliasing;
|
||||||
much better: 'writes: []' effect
|
much better: 'writes: []' effect
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ Changes affecting backwards compatibility
|
||||||
Compiler Additions
|
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
|
Language Additions
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue