Thread: [Nice-commit] Nice/src/bossa/util UserError.java,1.7,1.8 Location.java,1.23,1.24
Brought to you by:
bonniot
From: <bo...@us...> - 2003-06-24 15:28:24
|
Update of /cvsroot/nice/Nice/src/bossa/util In directory sc8-pr-cvs1:/tmp/cvs-serv20812/src/bossa/util Modified Files: UserError.java Location.java Log Message: Refactored bossa.util.Location, to provide a higher-level view on locations, using several subclasses for the different cases. Index: UserError.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/util/UserError.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** UserError.java 7 Apr 2003 20:35:33 -0000 1.7 --- UserError.java 24 Jun 2003 15:28:19 -0000 1.8 *************** *** 36,41 **** public UserError(gnu.expr.Expression responsible, String message) { ! this(new Location(responsible.getFile(), responsible.getLine(), ! responsible.getColumn()), message); } --- 36,41 ---- public UserError(gnu.expr.Expression responsible, String message) { ! this(Location.make(new java.io.File(responsible.getFile()), ! responsible.getLine(), responsible.getColumn()), message); } Index: Location.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/util/Location.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Location.java 20 Feb 2003 14:58:39 -0000 1.23 --- Location.java 24 Jun 2003 15:28:19 -0000 1.24 *************** *** 1,6 **** /**************************************************************************/ ! /* B O S S A */ ! /* A simple imperative object-oriented research language */ ! /* (c) Daniel Bonniot 1999 */ /* */ /* This program is free software; you can redistribute it and/or modify */ --- 1,6 ---- /**************************************************************************/ ! /* N I C E */ ! /* A high-level object-oriented research language */ ! /* (c) Daniel Bonniot 2003 */ /* */ /* This program is free software; you can redistribute it and/or modify */ *************** *** 11,18 **** /**************************************************************************/ - // File : Location.java - // Created : Tue Jul 13 11:55:08 1999 by bonniot - //$Modified: Tue Oct 03 12:02:39 2000 by Daniel Bonniot $ - package bossa.util; --- 11,14 ---- *************** *** 22,189 **** /** ! * Represents a portion of the input file. ! * Used to report errors to the user. ! * ! * @see Located */ ! public class Location implements Located { ! /** ! * The file beeing parsed. ! * Enables to set the file name just once, ! * not at each Location construction. ! */ ! public static void setCurrentFile(String file) { ! currentFile = nice.tools.util.System.prettyPrintFile(file); } - private static String currentFile = null; ! public static Location current = null; ! ! public Location(String file, ! int startLine, int startColumn, ! int endLine, int endColumn) { ! this.fileName = file; ! this.startLine = startLine; ! this.startColumn = startColumn; ! this.endLine = endLine; ! this.endColumn = endColumn; } ! public Location( ! int startLine, int startColumn, ! int endLine, int endColumn) { ! this(currentFile, startLine, startColumn, endLine, endColumn); } ! public Location(String fileName, int startLine, int startColumn) { ! this(fileName, startLine, startColumn, -1, -1); } ! public Location(String fileName) { ! this(fileName, -1, -1); } ! public Location(String abstractLocation, boolean dummy) { ! this.abstractLocation = abstractLocation; } ! public Location(Token t) { ! this(t.beginLine,t.beginColumn,t.endLine,t.endColumn); } /** ! Return a location that goes from start to end. ! */ ! public Location(Token start, Token end) { ! this(start.beginLine, start.beginColumn, end.endLine, end.endColumn); } ! /** returns the "invalid" location */ ! public static Location nowhere() { - return new Location(-1,-1,-1,-1); } ! public static Location nowhereAtAll() { - return new Location(null, -1,-1,-1,-1); } ! public String toString() { ! if (abstractLocation != null) ! return "[" + abstractLocation + "]"; ! String res; ! if (fileName != null) ! res = fileName; ! else ! res = ""; ! if (!isValid()) ! if (Debug.powerUser) ! return "[no location]: " + res; ! else ! return res; ! if (editorMode) ! return ! (res.length()>0 ? (res + ":") : "") + ! startLine + ":" + startColumn; ! else ! return ! (res.length()>0 ? (res + ": ") : "") + ! "line "+startLine+", column "+startColumn; ! } ! public boolean isValid() ! { ! return abstractLocation!=null || startLine>=0; ! } ! ! public Location englobe(Location loc) ! { ! return new Location(fileName, ! startLine, startColumn, loc.endLine, loc.endColumn); ! } ! public Location englobe(Collection /* of Located */ locs) ! { ! List llocs = (List) locs; ! return englobe(((Located)llocs.get(llocs.size()-1)).location()); ! } ! public Location location() ! { ! return this; } - public int getLine() - { - return startLine; - } - - public int getColumn() - { - return startColumn; - } - - public String getFile() - { - return fileName; - } - /**************************************************************** ! * Setting source location in the generated bytecode. ****************************************************************/ ! public void write(gnu.expr.Expression exp) { ! exp.setFile(getFile()); ! exp.setLine(getLine(), getColumn()); ! } ! /**************************************************************** ! * Private state. ! ****************************************************************/ ! private int startLine,startColumn,endLine,endColumn; ! private String fileName; ! private String abstractLocation = null; // if non-null, overseeds everyting /**************************************************************** ! * Different behaviour wether compiler is invoked by an editor. ****************************************************************/ ! public static boolean editorMode = false; } --- 18,228 ---- /** ! Represents a portion of the input file. ! Used to report errors to the user. ! ! @see Located ! ! @author Daniel Bonniot (bo...@us...) */ ! public abstract class Location implements Located { ! public static Location make ! (java.io.File file, ! int startLine, int startColumn, ! int endLine, int endColumn) { ! return new Source(file, startLine, startColumn, endLine, endColumn); } ! public static Location make ! (java.io.File file, ! int startLine, int startColumn) { ! return make(file, startLine, startColumn, -1, -1); } ! public static Location make ! (int startLine, int startColumn, ! int endLine, int endColumn) { ! return make(currentFile, startLine, startColumn, endLine, endColumn); } ! public static Location make (Token t) { ! return make(t.beginLine, t.beginColumn, t.endLine, t.endColumn); } ! /** ! Return a location that goes from start to end. ! */ ! public static Location make (Token start, Token end) { ! return make(start.beginLine, start.beginColumn, end.endLine, end.endColumn); } ! /** ! * The file beeing parsed. ! * Enables to set the file name just once, ! * not at each Location construction. ! */ ! public static void setCurrentFile(java.io.File file) { ! currentFile = file; } + private static java.io.File currentFile = null; ! public static final Location option = new Option(); ! ! public static Location nowhere() ! { ! return new Location.File(currentFile); ! } ! ! public Location location() { ! return this; } /** ! Return an identifier, which is guaranteed to be different for ! different locations. ! */ ! public String uniqueIdentifier(String root) { ! StringBuffer uniq = new StringBuffer(super.toString()); ! // Replace the '@' in bossa.util.Location@12345 with '_' ! uniq.setCharAt("bossa.util.Location".length(), '_'); ! ! return root + uniq.toString(); } ! /**************************************************************** ! * Setting source location in the generated bytecode. ! ****************************************************************/ ! ! public void write(gnu.expr.Expression exp) { } ! public void write(gnu.expr.Declaration decl) { } ! /**************************************************************** ! * Different behaviour wether compiler is invoked by an editor. ! ****************************************************************/ ! ! public static boolean editorMode = false; ! ! /**************************************************************** ! * File location ! ****************************************************************/ ! ! public static class File extends Location { ! private File(java.io.File file) ! { ! this.file = file; ! } ! private java.io.File file; ! public java.io.File getFile() { return file; } ! public String toString() ! { ! return nice.tools.util.System.prettyPrint(file); ! } ! public void write(gnu.expr.Expression exp) ! { ! if (file == null) ! return; ! // In the bytecode, the fully qualified name is not wanted. ! exp.setFile(file.getName()); ! } ! public void write(gnu.expr.Declaration decl) ! { ! if (file == null) ! return; ! // In the bytecode, the fully qualified name is not wanted. ! decl.setFile(file.getName()); ! } } /**************************************************************** ! * Source location ****************************************************************/ ! public static class Source extends File { ! private Source(java.io.File file, ! int startLine, int startColumn, ! int endLine, int endColumn) ! { ! super(file); ! this.startLine = startLine; ! this.startColumn = startColumn; ! this.endLine = endLine; ! this.endColumn = endColumn; ! } ! private int startLine,startColumn,endLine,endColumn; ! ! public int getLine() ! { ! return startLine; ! } ! public int getColumn() ! { ! return startColumn; ! } ! ! public String toString() ! { ! String res = super.toString(); ! if (editorMode) ! return ! (res.length()>0 ? (res + ":") : "") + ! startLine + ":" + startColumn; ! else ! return ! (res.length()>0 ? (res + ": ") : "") + ! "line "+startLine+", column "+startColumn; ! } ! ! public String uniqueIdentifier(String root) ! { ! return root + startLine + "_" + startColumn; ! } ! ! public void write(gnu.expr.Expression exp) ! { ! super.write(exp); ! exp.setLine(getLine(), getColumn()); ! } + public void write(gnu.expr.Declaration decl) + { + super.write(decl); + decl.setLine(getLine(), getColumn()); + } + } + /**************************************************************** ! * A compilation option ****************************************************************/ ! public static class Option extends Location ! { ! public String toString() ! { ! return "Command line"; ! } ! } } |