瀏覽代碼

In ilasm/codegen:
* CodeGen.cs (CodeGen.AddDataDef): Use Report.Error for consistent error
reporting.
* MethodDef.cs (MethodDef.AddLabel): Likewise.

In ilasm:

* Report.cs (Report.Error): Add 2 new overloads.
(ILAsmException.ctor): Add 2 new overloads, with location and file_path
params.
(ILAsmException.Location):
(ILAsmException.FilePath): New properties.
(ILAsmException.ToString): Return formatted error message.
* Driver.cs (DriverMain.ProcessFile): Improve error message display.
(DriverMain.Run): Use ILAsmException.ToString ().

In ilasm/scanner:

* ILTokenizingExpcetion.cs (Location): Remove. Already inherited from
ILAsmException.

svn path=/trunk/mcs/; revision=60586

Ankit Jain 19 年之前
父節點
當前提交
ef0a5ce944

+ 11 - 0
mcs/ilasm/ChangeLog

@@ -1,3 +1,14 @@
+2006-05-11  Ankit Jain  <[email protected]>
+
+	* Report.cs (Report.Error): Add 2 new overloads.
+	(ILAsmException.ctor): Add 2 new overloads, with location and file_path
+	params.
+	(ILAsmException.Location):
+	(ILAsmException.FilePath): New properties.
+	(ILAsmException.ToString): Return formatted error message.
+	* Driver.cs (DriverMain.ProcessFile): Improve error message display.
+	(DriverMain.Run): Use ILAsmException.ToString (). 
+
 2006-05-09  Sebastien Pouliot  <[email protected]>
 
 	* Driver.cs: Move up the loading of the strongname key pair to allow

+ 12 - 9
mcs/ilasm/Driver.cs

@@ -93,10 +93,10 @@ namespace Mono.ILASM {
                                                 throw;
                                         }
                                 } catch (ILAsmException e) {
-                                        Error (e.Message);
+                                        Error (e.ToString ());
                                         return false;
                                 } catch (PEAPI.PEFileException pe) {
-                                        Error (pe.Message);
+                                        Error ("Error : " + pe.Message);
                                         return false;
                                 } 
 
@@ -114,7 +114,7 @@ namespace Mono.ILASM {
 
                         private void Error (string message)
                         {
-                                Console.WriteLine ("Error : " + message + "\n");
+                                Console.WriteLine (message + "\n");
                                 Console.WriteLine ("***** FAILURE *****\n");
                         }
 
@@ -180,12 +180,15 @@ namespace Mono.ILASM {
                                         else
                                                 parser.yyparse (new ScannerAdapter (scanner),  null);
                                 } catch (ILTokenizingException ilte) {
-                                        Report.Error (file_path + "(" + ilte.Location.line + ") : error : " +
-                                                        "syntax error at token '" + ilte.Token + "'.");
-                                } catch (Mono.ILASM.yyParser.yyException) {
-                                        Report.Error ("Error at: " + scanner.Reader.Location);
-                                } catch {
-                                        Console.WriteLine ("Error at: " + scanner.Reader.Location);
+                                        Report.Error (file_path, ilte.Location, "syntax error at token '" + ilte.Token + "'");
+                                } catch (Mono.ILASM.yyParser.yyException ye) {
+                                        Report.Error (file_path, scanner.Reader.Location, ye.Message);
+                                } catch (ILAsmException ie) {
+                                        ie.FilePath = file_path;
+                                        ie.Location = scanner.Reader.Location;
+                                        throw;
+                                } catch (Exception e){
+                                        Console.Write ("{0} ({1}, {2}): ",file_path, scanner.Reader.Location.line, scanner.Reader.Location.column);
                                         throw;
                                 } finally {
 					codegen.EndSourceFile ();

+ 40 - 3
mcs/ilasm/Report.cs

@@ -43,9 +43,19 @@ namespace Mono.ILASM {
                 }
 
                 public static void Error (string message)
+                {
+			Error (null, null, message);
+                }
+
+                public static void Error (Location location, string message)
+                {
+			Error (null, location, message);
+                }
+                
+                public static void Error (string file_path, Location location, string message)
                 {
                         error_count++;
-                        throw new ILAsmException (message);
+                        throw new ILAsmException (file_path, location, message);
                 }
 
                 public static void Message (string message)
@@ -67,23 +77,50 @@ namespace Mono.ILASM {
         public class ILAsmException : Exception {
 
                 string message;
+                string file_path;
                 Location location;
                 
-                public ILAsmException (Location location, string message)
+                public ILAsmException (string file_path, Location location, string message)
                 {
+                        this.file_path = file_path;
                         this.location = location;
                         this.message = message;
                 }
 
+                public ILAsmException (Location location, string message)
+                        : this (null, location, message)
+                {
+                }
+
                 public ILAsmException (string message)
+                        : this (null, null, message)
                 {
-                        this.message = message;
                 }
 
                 public override string Message {
                         get { return message; }
                 }
 
+                public Location Location {
+                        get { return location; }
+                        set { location = value; }
+                }
+
+                public string FilePath {
+                        get { return file_path; }
+                        set { file_path = value; }
+                }
+
+                public override string ToString ()
+                {
+                        string location_str = "";
+                        if (location != null)
+                                location_str = " (" + location.line + ", " + location.column + ") : ";
+
+                        return String.Format ("{0}{1}Error : {2}",
+                                (file_path != null ? file_path : ""), location_str, message);
+                }
+
         }
 
         public class InternalErrorException : Exception {

+ 6 - 0
mcs/ilasm/codegen/ChangeLog

@@ -1,3 +1,9 @@
+2006-05-11  Ankit Jain  <[email protected]>
+
+	* CodeGen.cs (CodeGen.AddDataDef): Use Report.Error for consistent error
+	reporting.
+	* MethodDef.cs (MethodDef.AddLabel): Likewise.
+
 2006-05-11  Ankit Jain  <[email protected]>
 
 	* MethodDef.cs (MethodDef.AddLabel): Fix exception message.

+ 1 - 1
mcs/ilasm/codegen/CodeGen.cs

@@ -356,7 +356,7 @@ namespace Mono.ILASM {
                 public void AddDataDef (DataDef datadef)
                 {
                         if (data_table [datadef.Name] != null)
-                                throw new ILAsmException (String.Format ("Duplicate global label '{0}'", datadef.Name));
+                                Report.Error ("Duplicate global label '" + datadef.Name + "'");
                         data_table [datadef.Name] = datadef;
                 }
 

+ 1 - 1
mcs/ilasm/codegen/MethodDef.cs

@@ -558,7 +558,7 @@ namespace Mono.ILASM {
                 {
                         LabelInfo label_info = (LabelInfo) label_table[name];
                         if (label_info != null)
-                                throw new ILAsmException ("Duplicate label '" + name + "'");
+                                Report.Error ("Duplicate label '" + name + "'");
 
                         label_info = new LabelInfo (name, inst_list.Count);
                         label_table [name] = label_info;

+ 5 - 0
mcs/ilasm/scanner/ChangeLog

@@ -1,3 +1,8 @@
+2006-05-11  Ankit Jain  <[email protected]>
+
+	* ILTokenizingExpcetion.cs (Location): Remove. Already inherited from
+	ILAsmException.
+
 2006-05-10  Ankit Jain  <[email protected]>
 
 	* ILTables.cs (keywords): Add 'property' for NET_2_0.

+ 0 - 2
mcs/ilasm/scanner/ILTokenizingException.cs

@@ -14,13 +14,11 @@ namespace Mono.ILASM {
 
         public class ILTokenizingException : ILAsmException {
 
-                public readonly Location Location;
                 public readonly string Token;
 
                 public ILTokenizingException (Location location, string token)
                         : base (location, token)
                 {
-                        Location = location;
                         Token = token;
                 }
         }