[m-rev.] diff: disable warnings from C# compiler

Peter Wang novalazy at gmail.com
Tue Nov 9 14:47:02 AEDT 2010


Branches: main

compiler/mlds_to_cs.m:
        Output #pragmas to disable warnings for C# we generate.
        Restore warnings for handwritten code.

library/Mmakefile:
        Delete an unnecessary line.

library/array.m:
library/dir.m:
library/io.m:
library/thread.m:
library/version_array.m:
ssdb/ssdb.m:
        Make some of the remaining warnings from the C# compiler go away.

diff --git a/compiler/mlds_to_cs.m b/compiler/mlds_to_cs.m
index ab3d60a..3848de2 100644
--- a/compiler/mlds_to_cs.m
+++ b/compiler/mlds_to_cs.m
@@ -171,6 +171,8 @@ output_csharp_src_file(ModuleInfo, Indent, MLDS, !IO) :-
     io.write_list(ForeignBodyCode, "\n", output_csharp_body_code(Info, Indent),
         !IO),
 
+    output_pragma_warning_disable(!IO),
+
     list.filter(defn_is_rtti_data, Defns, RttiDefns, NonRttiDefns),
 
     io.write_string("\n// RttiDefns\n", !IO),
@@ -760,8 +762,6 @@ output_src_start(Globals, Info, Indent, MercuryModuleName, _Imports,
     io.write_string(ClassName, !IO),
     io.write_string(" {\n", !IO),
 
-    % output_debug_class_init(MercuryModuleName, "start", !IO),
-
     % Check if this module contains a `main' predicate and if it does insert
     % a `main' method in the resulting source file that calls the `main'
     % predicate.
@@ -3147,7 +3147,9 @@ output_atomic_stmt(Info, Indent, AtomicStmt, _Context, !IO) :-
         AtomicStmt = inline_target_code(TargetLang, Components),
         (
             TargetLang = ml_target_csharp,
-            list.foldl(output_target_code_component(Info), Components, !IO)
+            output_pragma_warning_restore(!IO),
+            list.foldl(output_target_code_component(Info), Components, !IO),
+            output_pragma_warning_disable(!IO)
         ;
             ( TargetLang = ml_target_c
             ; TargetLang = ml_target_gnu_c
@@ -3807,6 +3809,21 @@ indent_line(N, !IO) :-
         indent_line(N - 1, !IO)
     ).
 
+:- pred output_pragma_warning_disable(io::di, io::uo) is det.
+
+output_pragma_warning_disable(!IO) :-
+    % CS0162: Unreachable code detected
+    % CS0168: The variable `foo' is declared but never used
+    % CS0169: The private method `foo' is never used
+    % CS0219: The variable `foo' is assigned but its value is never used
+    % CS1717: Assignment made to same variable
+    io.write_string("#pragma warning disable 162, 168, 169, 219, 1717\n", !IO).
+
+:- pred output_pragma_warning_restore(io::di, io::uo) is det.
+
+output_pragma_warning_restore(!IO) :-
+    io.write_string("#pragma warning restore\n", !IO).
+
 %-----------------------------------------------------------------------------%
 
 :- type csharp_out_info
diff --git a/library/Mmakefile b/library/Mmakefile
index b705458..b9d6ca5 100644
--- a/library/Mmakefile
+++ b/library/Mmakefile
@@ -359,9 +359,6 @@ endif
 ifneq ("$(filter csharp%,$(GRADE))","")
 LINK_LIB_OPTS :=
 MLOBJS += ../runtime/mercury_dotnet.cs
-
-# Suppress warnings about unused variables.
-CSCFLAGS += /nowarn:0219
 endif
 
 #-----------------------------------------------------------------------------#
diff --git a/library/array.m b/library/array.m
index 320b9e4..a16dd6b 100644
--- a/library/array.m
+++ b/library/array.m
@@ -973,7 +973,7 @@ array.init(Size, Item, Array) :-
 ").
 
 :- pragma foreign_proc("C#",
-    array.min(Array::in, Min::out),
+    array.min(_Array::in, Min::out),
     [will_not_call_mercury, promise_pure, thread_safe],
 "
     /* Array not used */
diff --git a/library/dir.m b/library/dir.m
index bf23ee2..640f4c5 100644
--- a/library/dir.m
+++ b/library/dir.m
@@ -493,7 +493,7 @@ dir.split_name_dotnet(_, "", "") :- semidet_fail.
             BaseName = System.IO.Path.GetFileName(FileName);
             SUCCESS_INDICATOR = (BaseName != null);
         }
-    } catch (System.Exception e) {
+    } catch (System.Exception) {
         BaseName = null;
         DirName = null;
         SUCCESS_INDICATOR = false;
@@ -698,7 +698,7 @@ is_dotnet_root_directory_2(_) :-
     try {
         SUCCESS_INDICATOR =
             (System.IO.Path.GetDirectoryName(FileName) == null);
-    } catch (System.Exception e) {
+    } catch (System.Exception) {
         SUCCESS_INDICATOR = false;
     }
 }").
@@ -759,7 +759,7 @@ dir.dotnet_path_name_is_absolute_2(_) :-
 "
     try {
         SUCCESS_INDICATOR = System.IO.Path.IsPathRooted(FileName);
-    } catch (System.Exception e) {
+    } catch (System.Exception) {
         SUCCESS_INDICATOR = false;
     }
 ").
diff --git a/library/io.m b/library/io.m
index a313676..c90613e 100644
--- a/library/io.m
+++ b/library/io.m
@@ -10044,7 +10044,7 @@ io.make_temp(Dir, Prefix, Name, !IO) :-
 }").
 
 :- pragma foreign_proc("C#",
-    io.do_make_temp(Dir::in, Prefix::in, _Sep::in, FileName::out,
+    io.do_make_temp(_Dir::in, _Prefix::in, _Sep::in, FileName::out,
         Error::out, ErrorMessage::out, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "{
diff --git a/library/thread.m b/library/thread.m
index d238764..c01f5ad 100644
--- a/library/thread.m
+++ b/library/thread.m
@@ -200,13 +200,12 @@
 ").
 
 :- pragma foreign_proc("C#",
-    yield(IO0::di, IO::uo),
+    yield(_IO0::di, _IO::uo),
     [promise_pure, will_not_call_mercury, thread_safe, tabled_for_io,
         may_not_duplicate],
 "
     // Only available in .NET 4.0.
     // System.Threading.Yield();
-    IO = IO0;
 ").
 
 :- pragma foreign_proc("Java",
diff --git a/library/version_array.m b/library/version_array.m
index 9368ec1..acad612 100644
--- a/library/version_array.m
+++ b/library/version_array.m
@@ -1245,10 +1245,8 @@ public class ML_uva : ML_va {
         ML_uva  VA0 = this;
         ML_uva  latest;
         ML_uva  VA;
-        int     N;
 
         latest = VA0.latest();
-        N = latest.size();
 
         VA = new ML_uva();
         VA.index = -1;
@@ -1521,10 +1519,8 @@ public static class ML_uva implements ML_va, java.io.Serializable {
         ML_uva  VA0 = this;
         ML_uva  latest;
         ML_uva  VA;
-        int     N;
 
         latest = VA0.latest();
-        N = latest.size();
 
         VA = new ML_uva();
         VA.index = -1;
diff --git a/ssdb/ssdb.m b/ssdb/ssdb.m
index ba42a5f..7a6287e 100755
--- a/ssdb/ssdb.m
+++ b/ssdb/ssdb.m
@@ -471,14 +471,13 @@ static void MR_ssdb_sigint_handler(void)
 ").
 
 :- pragma foreign_proc("C#",
-    install_sigint_handler(IO0::di, IO::uo),
+    install_sigint_handler(_IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, thread_safe, may_not_duplicate],
 "
     System.Console.TreatControlCAsInput = false;
     System.Console.CancelKeyPress += new System.ConsoleCancelEventHandler(
         ssdb.sigint_handler
     );
-    IO = IO0;
 ").
 
 :- pragma foreign_code("C#",

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list