Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
zilf
zilf
Commits
3b6f61e0998b
Commit
d157f4ae
authored
Jun 16, 2019
by
Jesse McGrew
Browse files
Added <SUPPRESS-WARNINGS?> to control warning suppression from source code. [
ZILF-195
]
parent
aa5d1b2e05cf
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/Zilf/Diagnostics/DiagnosticManager.cs
View file @
3b6f61e0
...
...
@@ -37,6 +37,8 @@ namespace Zilf.Diagnostics
[
NotNull
]
readonly
HashSet
<
string
>
suppressions
=
new
HashSet
<
string
>();
bool
suppressAllTheThings
=
false
;
[
NotNull
]
public
IReadOnlyCollection
<
Diagnostic
>
Diagnostics
=>
diagnostics
;
public
int
ErrorCount
=>
Diagnostics
.
Count
(
d
=>
d
.
Severity
==
Severity
.
Error
||
d
.
Severity
==
Severity
.
Fatal
);
...
...
@@ -58,9 +60,28 @@ namespace Zilf.Diagnostics
OutputWriter
=
outputWriter
??
Console
.
Error
;
}
public
void
AddSuppression
([
NotNull
]
string
code
)
public
void
Suppress
([
NotNull
]
string
code
)
{
if
(!
suppressAllTheThings
)
suppressions
.
Add
(
code
);
}
public
void
Suppress
([
NotNull
,
ItemNotNull
]
IEnumerable
<
string
>
codes
)
{
suppressions
.
Add
(
code
);
if
(!
suppressAllTheThings
)
suppressions
.
UnionWith
(
codes
);
}
public
void
SuppressAll
()
{
suppressAllTheThings
=
true
;
suppressions
.
Clear
();
}
public
void
SuppressNone
()
{
suppressAllTheThings
=
false
;
suppressions
.
Clear
();
}
public
void
Handle
([
NotNull
]
Diagnostic
diag
)
...
...
@@ -80,14 +101,22 @@ namespace Zilf.Diagnostics
}
}
if
(
diag
.
Severity
<
Severity
.
Error
&&
suppressions
.
Contains
(
diag
.
Code
))
if
(
IsSuppressed
(
diag
))
{
suppressedDiagnostics
.
Add
(
diag
);
}
else
{
{
OutputWriter
.
WriteLine
(
Formatter
.
Format
(
diag
));
}
}
private
bool
IsSuppressed
([
NotNull
]
Diagnostic
diag
)
{
if
(
diag
.
Severity
>=
Severity
.
Error
)
return
false
;
return
suppressAllTheThings
||
suppressions
.
Contains
(
diag
.
Code
);
}
}
}
src/Zilf/Interpreter/ArgDecoder.cs
View file @
3b6f61e0
...
...
@@ -722,7 +722,7 @@ namespace Zilf.Interpreter
}
else
{
throw
new
ArgumentOutOfRangeException
(
nameof
(
paramType
));
throw
new
ArgumentOutOfRangeException
(
nameof
(
paramType
)
,
$"Unhandled type '
{
paramType
}
'"
);
}
// modifiers
...
...
src/Zilf/Interpreter/Context.cs
View file @
3b6f61e0
...
...
@@ -103,7 +103,7 @@ namespace Zilf.Interpreter
}
[
NotNull
]
readonly
DiagnosticManager
d
iagnostic
s
;
public
DiagnosticManager
D
iagnostic
Manager
{
get
;
}
readonly
bool
ignoreCase
;
[
NotNull
]
...
...
@@ -154,8 +154,8 @@ namespace Zilf.Interpreter
{
this
.
ignoreCase
=
ignoreCase
;
d
iagnostic
s
=
new
DiagnosticManager
();
d
iagnostic
s
.
TooManyErrors
+=
(
sender
,
args
)
=>
this
.
D
iagnostic
Manager
=
new
DiagnosticManager
();
this
.
D
iagnostic
Manager
.
TooManyErrors
+=
(
sender
,
args
)
=>
{
if
(
RunMode
==
RunMode
.
Compiler
)
{
...
...
@@ -247,23 +247,18 @@ namespace Zilf.Interpreter
public
bool
WarningsAsErrors
{
get
=>
d
iagnostic
s
.
WarningsAsErrors
;
set
=>
d
iagnostic
s
.
WarningsAsErrors
=
value
;
get
=>
D
iagnostic
Manager
.
WarningsAsErrors
;
set
=>
D
iagnostic
Manager
.
WarningsAsErrors
=
value
;
}
public
void
SuppressDiagnostic
([
NotNull
]
string
code
)
{
diagnostics
.
AddSuppression
(
code
);
}
public
int
ErrorCount
=>
diagnostics
.
ErrorCount
;
public
int
ErrorCount
=>
DiagnosticManager
.
ErrorCount
;
public
int
WarningCount
=>
d
iagnostic
s
.
WarningCount
;
public
int
WarningCount
=>
D
iagnostic
Manager
.
WarningCount
;
public
int
SuppressedWarningCount
=>
d
iagnostic
s
.
SuppressedWarningCount
;
public
int
SuppressedWarningCount
=>
D
iagnostic
Manager
.
SuppressedWarningCount
;
[
NotNull
]
public
IReadOnlyCollection
<
Diagnostic
>
Diagnostics
=>
d
iagnostic
s
.
Diagnostics
;
public
IReadOnlyCollection
<
Diagnostic
>
Diagnostics
=>
D
iagnostic
Manager
.
Diagnostics
;
[
NotNull
]
public
ZEnvironment
ZEnvironment
=>
zenv
;
...
...
@@ -775,7 +770,7 @@ namespace Zilf.Interpreter
}
}
public
void
HandleError
([
NotNull
]
ZilErrorBase
ex
)
=>
d
iagnostic
s
.
Handle
(
ex
.
Diagnostic
);
public
void
HandleError
([
NotNull
]
ZilErrorBase
ex
)
=>
D
iagnostic
Manager
.
Handle
(
ex
.
Diagnostic
);
/// <exception cref="FileNotFoundException">The file wasn't found in any include path.</exception>
[
NotNull
]
...
...
src/Zilf/Interpreter/Subrs.Atoms.cs
View file @
3b6f61e0
...
...
@@ -95,7 +95,7 @@ namespace Zilf.Interpreter
[
NotNull
]
[
Subr
]
public
static
ZilObject
LOOKUP
(
Context
ctx
,
[
NotNull
]
string
str
,
[
NotNull
]
ObList
oblist
)
public
static
ZilObject
LOOKUP
(
[
NotNull
]
Context
ctx
,
[
NotNull
]
string
str
,
[
NotNull
]
ObList
oblist
)
{
return
oblist
.
Contains
(
str
)
?
oblist
[
str
]
:
ctx
.
FALSE
;
}
...
...
@@ -103,8 +103,8 @@ namespace Zilf.Interpreter
/// <exception cref="InterpreterError"><paramref name="oblist"/> already contains an atom named <paramref name="stringOrAtom"/>, or <paramref name="stringOrAtom"/> is an atom that is already on a different OBLIST.</exception>
[
NotNull
]
[
Subr
]
public
static
ZilObject
INSERT
(
Context
ctx
,
[
Either
(
typeof
(
string
),
typeof
(
ZilAtom
))]
object
stringOrAtom
,
public
static
ZilObject
INSERT
(
[
NotNull
]
Context
ctx
,
[
NotNull
,
Either
(
typeof
(
string
),
typeof
(
ZilAtom
))]
object
stringOrAtom
,
[
NotNull
]
ObList
oblist
)
{
switch
(
stringOrAtom
)
...
...
src/Zilf/Interpreter/Subrs.Meta.cs
View file @
3b6f61e0
...
...
@@ -384,6 +384,66 @@ namespace Zilf.Interpreter
return
ctx
.
TRUE
;
}
public
static
class
WarningParams
{
[
ZilSequenceParam
]
[
ParamDesc
(
"all-none-or-codes"
)]
public
struct
CodesOrWildcard
{
[
Either
(
typeof
(
Wildcard
),
typeof
(
AtomParams
.
StringOrAtom
[]))]
public
object
Content
;
public
StdAtom
?
GetWildcard
()
{
return
Content
is
Wildcard
w
?
w
.
Atom
.
StdAtom
:
(
StdAtom
?)
null
;
}
[
CanBeNull
]
public
string
[]
GetCodes
()
{
return
Content
is
AtomParams
.
StringOrAtom
[]
sas
?
sas
.
Select
(
sa
=>
sa
.
ToString
()).
ToArray
()
:
null
;
}
}
[
ZilSequenceParam
]
public
struct
Wildcard
{
[
Decl
(
"<OR 'ALL 'NONE>"
)]
public
ZilAtom
Atom
;
public
StdAtom
StdAtom
=>
Atom
.
StdAtom
;
}
}
[
NotNull
]
[
Subr
(
"SUPPRESS-WARNINGS?"
)]
public
static
ZilObject
SUPPRESS_WARNINGS_P
([
NotNull
]
Context
ctx
,
WarningParams
.
CodesOrWildcard
codesOrWildcard
)
{
switch
(
codesOrWildcard
.
GetWildcard
())
{
case
StdAtom
.
ALL
:
ctx
.
DiagnosticManager
.
SuppressAll
();
break
;
case
StdAtom
.
NONE
:
ctx
.
DiagnosticManager
.
SuppressNone
();
break
;
default
:
var
codes
=
codesOrWildcard
.
GetCodes
();
System
.
Diagnostics
.
Debug
.
Assert
(
codes
!=
null
);
foreach
(
var
code
in
codes
)
ctx
.
DiagnosticManager
.
Suppress
(
code
.
ToString
());
break
;
}
return
ctx
.
TRUE
;
}
#
region
IDE
Help
[
NotNull
]
...
...
src/Zilf/Language/StdAtom.cs
View file @
3b6f61e0
...
...
@@ -40,6 +40,7 @@ namespace Zilf.Language
ADECL
,
ADJ
,
ADJECTIVE
,
ALL
,
AND
,
ANY
,
APPLICABLE
,
...
...
src/Zilf/Program.cs
View file @
3b6f61e0
...
...
@@ -269,7 +269,7 @@ namespace Zilf
AddImplicitIncludePaths
(
ctx
.
IncludePaths
,
newInFile
,
mode
.
Value
);
foreach
(
var
code
in
suppressedDiagnosticCodes
)
ctx
.
Suppress
Diagnostic
(
code
);
ctx
.
Diagnostic
Manager
.
Suppress
(
code
);
inFile
=
newInFile
;
outFile
=
newOutFile
;
...
...
test/Zilf.Tests.Integration/AssertionHelper.cs
View file @
3b6f61e0
...
...
@@ -37,8 +37,8 @@ namespace Zilf.Tests.Integration
[
NotNull
]
protected
readonly
StringBuilder
input
=
new
StringBuilder
();
[
NotNull
]
protected
readonly
List
<(
Predicate
<
IReadOnlyCollection
<
Diagnostic
>
>,
string
message
)>
warningChecks
=
new
List
<(
Predicate
<
IReadOnlyCollection
<
Diagnostic
>
>,
string
message
)>();
protected
readonly
List
<(
Predicate
<
ZlrHelperRunResult
>,
string
message
)>
warningChecks
=
new
List
<(
Predicate
<
ZlrHelperRunResult
>,
string
message
)>();
protected
bool
wantCompileOutput
;
protected
bool
wantDebugInfo
;
...
...
@@ -108,7 +108,7 @@ namespace Zilf.Tests.Integration
[
NotNull
]
public
TThis
WithWarnings
()
{
warningChecks
.
Add
((
diag
s
=>
diag
s
.
Any
(
d
=>
d
.
Severity
==
Severity
.
Warning
),
warningChecks
.
Add
((
re
s
=>
res
.
Diagnostic
s
.
Any
(
d
=>
d
.
Severity
==
Severity
.
Warning
),
"Expected a nonzero number of warnings."
));
return
(
TThis
)
this
;
}
...
...
@@ -123,7 +123,7 @@ namespace Zilf.Tests.Integration
{
foreach
(
var
code
in
expectedWarningCodes
)
{
warningChecks
.
Add
((
diag
s
=>
diag
s
.
Any
(
d
=>
DiagnosticCodeMatches
(
d
,
code
)),
warningChecks
.
Add
((
re
s
=>
res
.
Diagnostic
s
.
Any
(
d
=>
DiagnosticCodeMatches
(
d
,
code
)),
$"Expected a diagnostic with code '
{
code
}
'."
));
}
return
(
TThis
)
this
;
...
...
@@ -132,17 +132,26 @@ namespace Zilf.Tests.Integration
[
NotNull
]
public
TThis
WithoutWarnings
()
{
warningChecks
.
Add
((
diag
s
=>
diag
s
.
All
(
d
=>
d
.
Severity
!=
Severity
.
Warning
),
warningChecks
.
Add
((
re
s
=>
res
.
Diagnostic
s
.
All
(
d
=>
d
.
Severity
!=
Severity
.
Warning
),
"Expected no warnings."
));
return
(
TThis
)
this
;
}
[
NotNull
]
public
TThis
WithoutUnsuppressedWarnings
()
{
warningChecks
.
Add
(
(
res
=>
res
.
Diagnostics
.
Count
(
d
=>
d
.
Severity
==
Severity
.
Warning
)
==
res
.
SuppressedWarningCount
,
"Expected all warnings to be suppressed."
));
return
(
TThis
)
this
;
}
[
NotNull
]
public
TThis
WithoutWarnings
(
params
string
[]
unexpectedWarningCodes
)
{
foreach
(
var
code
in
unexpectedWarningCodes
)
{
warningChecks
.
Add
((
diag
s
=>
!
diag
s
.
Any
(
d
=>
DiagnosticCodeMatches
(
d
,
code
)),
warningChecks
.
Add
((
re
s
=>
!
res
.
Diagnostic
s
.
Any
(
d
=>
DiagnosticCodeMatches
(
d
,
code
)),
$"Expected no diagnostic with code '
{
code
}
'."
));
}
return
(
TThis
)
this
;
...
...
@@ -183,7 +192,7 @@ namespace Zilf.Tests.Integration
protected
void
CheckWarnings
(
ZlrHelperRunResult
res
)
{
foreach
(
var
(
check
,
message
)
in
warningChecks
)
if
(!
check
(
res
.
Diagnostics
))
if
(!
check
(
res
))
Assert
.
Fail
(
message
);
}
}
...
...
@@ -375,6 +384,7 @@ namespace Zilf.Tests.Integration
{
WarningCount
=
helper
.
WarningCount
,
Diagnostics
=
helper
.
Diagnostics
,
SuppressedWarningCount
=
helper
.
SuppressedWarningCount
,
});
return
new
CodeMatchingResult
(
output
);
...
...
test/Zilf.Tests.Integration/MetaTests.cs
View file @
3b6f61e0
...
...
@@ -245,5 +245,28 @@ namespace Zilf.Tests.Integration
.
DoesNotCompile
(
"ZIL0204"
,
// no such {0} variable '{1}', using the {2} instead
diag
=>
diag
.
Severity
==
Severity
.
Error
);
}
[
TestMethod
]
public
void
Warnings_Can_Be_Suppressed
()
{
AssertRoutine
(
""
,
".X"
)
.
WithGlobal
(
"<GLOBAL X 5>"
)
.
WithGlobal
(
"<SUPPRESS-WARNINGS? \"ZIL0204\">"
)
.
WithoutUnsuppressedWarnings
()
.
GivesNumber
(
"5"
);
AssertRoutine
(
""
,
".X"
)
.
WithGlobal
(
"<GLOBAL X 5>"
)
.
WithGlobal
(
"<SUPPRESS-WARNINGS? ALL>"
)
.
WithoutUnsuppressedWarnings
()
.
GivesNumber
(
"5"
);
AssertRoutine
(
""
,
".X"
)
.
WithGlobal
(
"<GLOBAL X 5>"
)
.
WithGlobal
(
"<SUPPRESS-WARNINGS? \"ZIL0204\">"
)
.
WithGlobal
(
"<SUPPRESS-WARNINGS? NONE>"
)
.
WithWarnings
(
"ZIL0204"
)
.
GivesNumber
(
"5"
);
}
}
}
test/Zilf.Tests.Integration/ZlrHelper.cs
View file @
3b6f61e0
...
...
@@ -49,6 +49,7 @@ namespace Zilf.Tests.Integration
// ReSharper disable once NotAccessedField.Global
public
string
Output
;
public
int
WarningCount
;
public
int
SuppressedWarningCount
;
public
int
ErrorCount
;
public
IReadOnlyCollection
<
Diagnostic
>
Diagnostics
;
}
...
...
@@ -56,7 +57,7 @@ namespace Zilf.Tests.Integration
sealed
class
ZlrHelper
:
IDisposable
{
public
static
void
RunAndAssert
([
NotNull
]
string
code
,
string
input
,
[
NotNull
]
string
expectedOutput
,
IEnumerable
<(
Predicate
<
IReadOnlyCollection
<
Diagnostic
>
>,
string
message
)>
warningChecks
=
null
,
IEnumerable
<(
Predicate
<
ZlrHelperRunResult
>,
string
message
)>
warningChecks
=
null
,
bool
wantCompileOutput
=
false
)
{
var
helper
=
new
ZlrHelper
(
code
,
input
);
...
...
@@ -75,8 +76,16 @@ namespace Zilf.Tests.Integration
Assert
.
IsTrue
(
helper
.
Assemble
(),
"Failed to assemble"
);
if
(
warningChecks
!=
null
)
{
var
result
=
new
ZlrHelperRunResult
{
Diagnostics
=
helper
.
Diagnostics
,
ErrorCount
=
helper
.
ErrorCount
,
WarningCount
=
helper
.
WarningCount
,
Status
=
ZlrTestStatus
.
Finished
,
SuppressedWarningCount
=
helper
.
SuppressedWarningCount
,
};
foreach
(
var
(
check
,
message
)
in
warningChecks
)
if
(!
check
(
helper
.
Diagnostics
))
if
(!
check
(
result
))
Assert
.
Fail
(
message
);
}
string
actualOutput
=
compileOutput
+
helper
.
Execute
();
...
...
@@ -134,8 +143,9 @@ namespace Zilf.Tests.Integration
public
int
ErrorCount
{
get
;
private
set
;
}
public
int
WarningCount
{
get
;
private
set
;
}
public
int
SuppressedWarningCount
{
get
;
private
set
;
}
[
CanBeNull
]
public
IReadOnlyCollection
<
Diagnostic
>
Diagnostics
{
get
;
private
set
;
}
public
IReadOnlyCollection
<
Diagnostic
>
Diagnostics
{
get
;
private
set
;
}
// includes suppressed
public
ZlrHelper
([
NotNull
]
string
code
,
[
CanBeNull
]
string
input
)
{
...
...
@@ -217,6 +227,7 @@ namespace Zilf.Tests.Integration
ErrorCount
=
result
.
ErrorCount
;
WarningCount
=
result
.
WarningCount
;
Diagnostics
=
result
.
Diagnostics
;
SuppressedWarningCount
=
result
.
SuppressedWarningCount
;
if
(
result
.
Success
)
{
PrintZapCode
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment