001    package AST;
002    
003    import java.util.HashSet;
004    import java.io.File;
005    import java.util.*;
006    import beaver.*;
007    import java.util.ArrayList;
008    import java.util.zip.*;
009    import java.io.*;
010    import java.io.FileNotFoundException;
011    import java.util.Collection;
012    /**
013      * @ast class
014     * 
015     */
016    public class Problem extends java.lang.Object implements Comparable {
017    
018        public int compareTo(Object o) {
019          if(o instanceof Problem) {
020            Problem other = (Problem)o;
021            if(!fileName.equals(other.fileName))
022              return fileName.compareTo(other.fileName);
023            if(line != other.line)
024              return line - other.line;
025            return message.compareTo(other.message);
026          }
027          return 0;
028        }
029    
030    
031        public static class Severity {
032          public static final Severity ERROR = new Severity();
033          public static final Severity WARNING = new Severity();
034          private Severity() { }
035        }
036    
037    
038        public static class Kind {
039          public static final Kind OTHER = new Kind();
040          public static final Kind LEXICAL = new Kind();
041          public static final Kind SYNTACTIC = new Kind();
042          public static final Kind SEMANTIC = new Kind();
043          private Kind() { }
044        }
045    
046    
047        protected int line = -1;
048    
049    
050        public int line() { return line; }
051    
052    
053        protected int column = -1;
054    
055    
056        public int column() { return column; }
057    
058    
059        protected int endLine = -1;
060    
061    
062        public int endLine() { return endLine; }
063    
064    
065        protected int endColumn = -1;
066    
067    
068        public int endColumn() { return endColumn; }
069    
070    
071        protected String fileName;
072    
073    
074        public String fileName() { return fileName; }
075    
076    
077        public void setFileName(String fileName) { this.fileName = fileName; }
078    
079    
080        protected String message;
081    
082    
083        public String message() { return message; }
084    
085    
086        protected Severity severity = Severity.ERROR;
087    
088    
089        public Severity severity() { return severity; }
090    
091    
092        protected Kind kind = Kind.OTHER;
093    
094    
095        public Kind kind() { return kind; }
096    
097    
098        public Problem(String fileName, String message) {
099          this.fileName = fileName;
100          this.message = message;
101        }
102    
103    
104        public Problem(String fileName, String message, int line) {
105          this(fileName, message);
106          this.line = line;
107        }
108    
109    
110        public Problem(String fileName, String message, int line, Severity severity) {
111          this(fileName, message);
112          this.line = line;
113          this.severity = severity;
114        }
115    
116    
117        public Problem(String fileName, String message, int line, int column, Severity severity) {
118          this(fileName, message);
119          this.line = line;
120          this.column = column;
121          this.severity = severity;
122        }
123    
124    
125        public Problem(String fileName, String message, int line, Severity severity, Kind kind) {
126          this(fileName, message);
127          this.line = line;
128          this.kind = kind;
129          this.severity = severity;
130        }
131    
132    
133        public Problem(String fileName, String message, int line, int column, Severity severity, Kind kind) {
134          this(fileName, message);
135          this.line = line;
136          this.column = column;
137          this.kind = kind;
138          this.severity = severity;
139        }
140    
141    
142        public Problem(String fileName, String message, int line, int column, int endLine, int endColumn, Severity severity, Kind kind) {
143          this(fileName, message);
144          this.line = line;
145          this.column = column;
146          this.endLine = endLine;
147          this.endColumn = endColumn;
148          this.kind = kind;
149          this.severity = severity;
150        }
151    
152    
153        public String toString() {
154          String location = "";
155          if(line != -1 && column != -1)
156            location = line + "," + column + ":";
157          else if(line != -1)
158            location = line + ":";
159          String s = "";
160          if(this.kind == Kind.LEXICAL)
161            s = "Lexical Error: ";
162          else if(this.kind == Kind.SYNTACTIC)
163            s = "Syntactic Error: ";
164          else if(this.kind == Kind.SEMANTIC)
165            s = "Semantic Error: ";
166          return fileName + ":" + location + "\n" + "  " + s + message;
167        }
168    
169    
170    }