summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-06-16 12:38:45 +0000
committerpaltherr <paltherr@epfl.ch>2003-06-16 12:38:45 +0000
commitba5d59e9f697fc307140a67d37edbfeb2dc4d795 (patch)
tree6a1a04c1dc80978708b5dcf35beb89442fc154c6
parent9c9dfb24a48f11e175d8f82417e7b9c7ab78f7c7 (diff)
downloadscala-ba5d59e9f697fc307140a67d37edbfeb2dc4d795.tar.gz
scala-ba5d59e9f697fc307140a67d37edbfeb2dc4d795.tar.bz2
scala-ba5d59e9f697fc307140a67d37edbfeb2dc4d795.zip
- Removed scalac.util.Position
- Removed scalac.ast.parser.Sourcefile
-rw-r--r--sources/scalac/ast/parser/Sourcefile.java300
-rw-r--r--sources/scalac/util/Position.java54
2 files changed, 0 insertions, 354 deletions
diff --git a/sources/scalac/ast/parser/Sourcefile.java b/sources/scalac/ast/parser/Sourcefile.java
deleted file mode 100644
index 3ac0a9d4bd..0000000000
--- a/sources/scalac/ast/parser/Sourcefile.java
+++ /dev/null
@@ -1,300 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-** **
-** $Id$
-\* */
-
-package scalac.ast.parser;
-
-import java.io.*;
-import java.util.Hashtable;
-import scalac.util.AbstractFile;
-import scalac.util.Name;
-import scalac.util.Position;
-
-
-/** This class represents a single scala source file. It provides
- * functionality to read the file and to output error messages on
- * a given line and column. Error messages are logged to
- * decouple the time where an error message is issued from the
- * time where the error messages are displayed.
- *
- * @author Matthias Zenger
- * @version 1.0
- */
-public class Sourcefile {
-
- /** the id management
- */
- public static int numIds = 1;
- public static String[] files = new String[]{"console", null, null, null};
- public static Sourcefile[] sources = new Sourcefile[]{null, null, null, null};
- public int id;
-
- /** the filename
- */
- public String filename;
- public String shortname;
- public String pathname;
-
- /** the encoding of the file
- */
- protected String encoding;
-
- /** a log of all errors generated so far; used to avoid printing an
- * error message more than once
- */
- protected Hashtable recorded = new Hashtable();
-
- /** the buffer containing the file that is currently translated
- */
- protected byte[] buf = null;
-
- /** the last error position
- */
- protected int lastLine = 0;
- protected int lastPos = 0;
- protected int lineEnd = 0;
- protected int newPos = 0;
-
- /** constants used for source parsing
- */
- final static byte LF = 0xA;
- final static byte FF = 0xC;
- final static byte CR = 0xD;
- final static byte SU = 0x1A;
-
- /** set col to NO_COLUMN, if the printLine method should not mark
- * the column
- */
- final static int NO_COLUMN = -1;
-
- /** number of lines and bytes (not used internally)
- */
- public int lines; // set externally
- public int bytes;
-
- /** prompt after error?
- */
- public boolean prompt;
-
- /** constructors
- */
- public Sourcefile(String filename) throws IOException, FileNotFoundException {
- if (filename == null) {
- this.filename = "(sourcefile not available)";
- this.shortname = "?";
- this.pathname = "?";
- buf = new byte[]{SU};
- } else {
- File f = new File(filename);
- this.filename = filename;
- this.shortname = f.getName();
- this.pathname = f.getAbsoluteFile().getParentFile().
- getCanonicalPath();
- fillBuffer(new FileInputStream(f));
- }
- if (numIds == files.length) {
- String[] newfiles = new String[numIds * 2];
- System.arraycopy(files, 0, newfiles, 0, numIds);
- files = newfiles;
- Sourcefile[] newsources = new Sourcefile[numIds * 2];
- System.arraycopy(sources, 0, newsources, 0, numIds);
- sources = newsources;
- }
- sources[numIds] = this;
- files[id = numIds++] = shortname;
- }
-
- public Sourcefile(AbstractFile abs) throws IOException, FileNotFoundException {
- if (filename == null) {
- this.filename = "(sourcefile not available)";
- this.shortname = "?";
- this.pathname = "?";
- buf = new byte[]{SU};
- } else {
- this.filename = abs.getPath();
- this.shortname = abs.getName();
- this.pathname = abs.getPath();
- fillBuffer(abs.getInputStream());
- }
- if (numIds == files.length) {
- String[] newfiles = new String[numIds * 2];
- System.arraycopy(files, 0, newfiles, 0, numIds);
- files = newfiles;
- Sourcefile[] newsources = new Sourcefile[numIds * 2];
- System.arraycopy(sources, 0, newsources, 0, numIds);
- sources = newsources;
- }
- sources[numIds] = this;
- files[id = numIds++] = shortname;
- }
-
- public Sourcefile(byte[] input) {
- if (input == null) {
- this.filename = "(sourcefile not available)";
- this.shortname = "?";
- this.pathname = "?";
- buf = new byte[]{SU};
- } else {
- this.filename = "console";
- this.shortname = "console";
- this.pathname = "console";
- buf = new byte[input.length + 2];
- System.arraycopy(input, 0, buf, 0, input.length);
- buf[input.length] = Scanner.LF;
- buf[input.length + 1] = SU;
- }
- sources[0] = this;
- id = 0;
- }
-
- /** fill the buffer using the InputStream
- */
- private void fillBuffer(InputStream in) throws IOException {
- try {
- buf = new byte[(bytes = in.available()) + 1];
- if (in.read(buf) != (buf.length - 1))
- throw new IOException();
- in.close();
- buf[buf.length - 1] = SU;
- } catch (IOException e) {
- throw new IOException("cannot read '" + filename + "'");
- }
- }
-
- /** return filename as a string
- */
- public String toString() {
- return filename;
- }
-
- /** return filename as a name
- */
- public Name getName() {
- return Name.fromString(filename);
- }
-
- /** return the shortname without the suffix
- */
- public String getShortnameWithoutSuffix() {
- int idx = shortname.lastIndexOf('.');
- if (idx < 0)
- return shortname;
- else
- return shortname.substring(0, idx);
- }
-
- /** return the source buffer of this file
- */
- public byte[] getBuffer() {
- return buf;
- }
-
- /** number of logged entries
- */
- public int logged() {
- return recorded.size();
- }
-
- /** is there already an entry at position 'pos'
- */
- public boolean isLogged(int pos) {
- return (recorded.get(new Integer(pos)) != null);
- }
-
- /** enter entry into log table
- */
- public void log(int pos, String message) {
- recorded.put(new Integer(pos), message);
- }
-
- /** set encoding of the file
- */
- public void setEncoding(String encoding) {
- this.encoding = encoding;
- }
-
- /** return true if there is an entry for this position,
- * otherwise return false and enter message into log
- */
- public boolean testAndSetLog(int pos, String message) {
- if (!isLogged(pos)) {
- log(pos, message);
- return false;
- }
- return true;
- }
-
- /** get error message with line from sourcefile
- */
- public String getMessage(int pos, String message) {
- if (pos == Position.NOPOS)
- return filename + ": " + message;
- else {
- int fileId = Position.file(pos);
- String filename = files[fileId];
- int line = Position.line(pos);
- int col = Position.column(pos);
- String main = filename + ":" + line + ": " + message;
- if ((fileId > 0) &&
- (fileId < numIds) &&
- (sources[fileId] != null))
- return main + '\n' + sources[fileId].getLine(line, col);
- else
- return main;
- //else
- // System.out.println("(source file not available anymore)");
- }
- }
-
- /** get source line
- */
- public String getLine(int line, int col) {
- int pos = 0;
- if (lastLine > line)
- lastLine = 0;
- else
- pos = newPos;
- while ((pos < buf.length) && (lastLine < line))
- {
- lastPos = pos;
- while ((pos < buf.length) && (buf[pos] != CR) &&
- (buf[pos] != LF) && (buf[pos] != FF))
- pos++;
- lineEnd = pos;
- if (pos < buf.length)
- pos++;
- if ((pos < buf.length) && (buf[pos-1] == CR) && (buf[pos] == LF))
- pos++;
- lastLine++;
- }
- newPos = pos;
- try
- {
- String errline = (encoding != null) ?
- new String(buf, lastPos, lineEnd - lastPos, encoding) :
- new String(buf, lastPos, lineEnd - lastPos);
- if (col != NO_COLUMN)
- {
- byte[] ptr = new byte[col];
- for (int i = col - 2; i >= 0; i--)
- ptr[i] = (byte)' ';
- ptr[col - 1] = (byte)'^';
- return errline + '\n' + new String(ptr);
- } else
- return errline;
- } catch (UnsupportedEncodingException e) {
- throw new InternalError(e.getMessage());
- }
- }
-
- /** release all sourcefile objects
- */
- public static void flushSources() {
- for (int i = 0; i < sources.length; i++)
- sources[i] = null;
- }
-}
diff --git a/sources/scalac/util/Position.java b/sources/scalac/util/Position.java
deleted file mode 100644
index c2cd7f72d3..0000000000
--- a/sources/scalac/util/Position.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-** **
-** $Id$
-\* */
-
-package scalac.util;
-
-
-public final class Position {
-
-/** source file positions are integers in the format:
- * line-number << LINESHIFT + column-number
- * NOPOS represents an undefined position.
- */
- public static final int LINESHIFT = 10;
- public static final int FILESHIFT = 26;
- public static final int COLUMNMASK = 1023;
- public static final int LINEMASK = 0xffff;
-
-/** predefined positions
- */
- public static final int NOPOS = 0;
-
-/** first position in a source file
- */
- public static final int FIRSTPOS = (1 << LINESHIFT) + 1;
-
-/** encode a line and column number into a single int
- */
- public static int encode(int line, int col, int file) {
- return (file << FILESHIFT) | (line << LINESHIFT) | col;
- }
-
-/** get the file id of an encoded position
- */
- public static int file(int pos) {
- return pos >>> FILESHIFT;
- }
-
-/** get the line number out of an encoded position
- */
- public static int line(int pos) {
- return (pos >>> LINESHIFT) & LINEMASK;
- }
-
-/** return the column number of an encoded position
- */
- public static int column(int pos) {
- return pos & COLUMNMASK;
- }
-}