2008-07-14 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / report.cs
index c329d03f84c1b83ed449bed35555051b32c173fb..16a813e67c77206aa4b4651a21809a6dcc103606 100644 (file)
@@ -4,7 +4,7 @@
 // Author: Miguel de Icaza (miguel@ximian.com)
 //         Marek Safar (marek.safar@seznam.cz)         
 //
-// (C) 2001 Ximian, Inc. (http://www.ximian.com)
+// Copyright 2001 Ximian, Inc. (http://www.ximian.com)
 //
 
 using System;
@@ -101,7 +101,7 @@ namespace Mono.CSharp {
                        2002, 2023, 2029,
                        3005, 3012, 3018, 3019, 3021, 3022, 3023, 3026, 3027,
 #if GMCS_SOURCE
-                       402, 414, 693, 1058, 1700, 3024
+                       402, 414, 458, 464, 693, 1058, 1700, 3024
 #endif
                };
 
@@ -118,6 +118,7 @@ namespace Mono.CSharp {
                        warning_ignore_table = null;
                        warning_regions_table = null;
                        reporting_disabled = false;
+                       error_stack = warning_stack = null;
                }
 
                public static void DisableReporting ()
@@ -137,8 +138,10 @@ namespace Mono.CSharp {
 
                public static void EnableReporting ()
                {
-                       if (warning_stack != null)
+                       if (warning_stack != null && warning_stack.Count > 0)
                                Warnings = (int) warning_stack.Pop ();
+                       else
+                               Warnings = 0;
 
                        Errors = (int) error_stack.Pop ();
                        if (error_stack.Count == 0) {
@@ -157,6 +160,7 @@ namespace Mono.CSharp {
 
                public interface IMessageRecorder
                {
+                       bool IsEmpty { get; }
                        void EndSession ();
                        void AddMessage (AbstractMessage msg);
                        bool PrintMessages ();
@@ -238,6 +242,12 @@ namespace Mono.CSharp {
                                session_messages.Add (msg);
                        }
 
+                       public bool IsEmpty {
+                               get {
+                                       return merged_messages == null && common_messages == null;
+                               }
+                       }
+
                        //
                        // Prints collected messages, common messages have a priority
                        //
@@ -355,7 +365,7 @@ namespace Mono.CSharp {
                                Check (code);
                        }
 
-                       public virtual string ColorFormat (string s)
+                       protected virtual string ColorFormat (string s)
                        {
                                return s;
                        }
@@ -465,6 +475,18 @@ namespace Mono.CSharp {
                sealed class ErrorMessage : AbstractMessage
                {
                        static string prefix, postfix;
+
+                       [System.Runtime.InteropServices.DllImport ("libc", EntryPoint="isatty")]
+                       extern static int _isatty (int fd);
+                       
+                       static bool isatty (int fd)
+                       {
+                               try {
+                                       return _isatty (fd) == 1;
+                               } catch {
+                                       return false;
+                               }
+                       }
                        
                        static ErrorMessage ()
                        {
@@ -484,6 +506,12 @@ namespace Mono.CSharp {
                                        xterm_colors = true;
                                        break;
                                }
+                               if (!xterm_colors)
+                                       return;
+
+                               if (!(isatty (1) && isatty (2)))
+                                       return;
+                               
                                string config = Environment.GetEnvironmentVariable ("MCS_COLORS");
                                if (config == null){
                                        config = "errors=red";
@@ -498,9 +526,6 @@ namespace Mono.CSharp {
 
                                config = config.Substring (7);
                                
-                               if (!xterm_colors)
-                                       return;
-
                                int p = config.IndexOf (",");
                                if (p == -1)
                                        prefix = GetForeground (config);
@@ -519,7 +544,7 @@ namespace Mono.CSharp {
                        {
                        }
 
-                       public override string ColorFormat (string s)
+                       protected override string ColorFormat (string s)
                        {
                                if (prefix != null)
                                        return prefix + s + postfix;
@@ -554,7 +579,7 @@ namespace Mono.CSharp {
                                version = "2.0";
                                break;
                        case LanguageVersion.Default_MCS:
-                               Report.Error (1644, loc, "Feature `{0}' is not available in Mono mcs compiler. Consider using Mono gmcs compiler instead",
+                               Report.Error (1644, loc, "Feature `{0}' is not available in Mono mcs1 compiler. Consider using the `gmcs' compiler instead",
                                              feature);
                                return;
                        default:
@@ -682,7 +707,7 @@ namespace Mono.CSharp {
                        if (type is TypeBuilder) {
                                DeclSpace temp_ds = TypeManager.LookupDeclSpace (type);
                                SymbolRelatedToPreviousError (temp_ds.Location, TypeManager.CSharpName (type));
-                       } else if (type.HasElementType) {
+                       } else if (TypeManager.HasElementType (type)) {
                                SymbolRelatedToPreviousError (type.GetElementType ());
                        } else {
                                SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));