summaryrefslogtreecommitdiff
path: root/sources/scalac/Global.java
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2004-03-21 15:31:22 +0000
committerpaltherr <paltherr@epfl.ch>2004-03-21 15:31:22 +0000
commit7465e94917326f52367e8c8c294d50bff307ad1d (patch)
tree4e3e6e7df6fb05ee6f92be99ac0fd6eae0fe4711 /sources/scalac/Global.java
parent9cfde36da89989890b1c4123806578560ed0fe4c (diff)
downloadscala-7465e94917326f52367e8c8c294d50bff307ad1d.tar.gz
scala-7465e94917326f52367e8c8c294d50bff307ad1d.tar.bz2
scala-7465e94917326f52367e8c8c294d50bff307ad1d.zip
- Changed Scanner and SourceFile to work with c...
- Changed Scanner and SourceFile to work with chars instead of bytes
Diffstat (limited to 'sources/scalac/Global.java')
-rw-r--r--sources/scalac/Global.java42
1 files changed, 37 insertions, 5 deletions
diff --git a/sources/scalac/Global.java b/sources/scalac/Global.java
index c7b2001a33..088332e0f7 100644
--- a/sources/scalac/Global.java
+++ b/sources/scalac/Global.java
@@ -16,11 +16,16 @@ import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.UnsupportedCharsetException;
import java.util.*;
import scala.tools.util.AbstractFile;
import scala.tools.util.Position;
import scala.tools.util.SourceFile;
+import scala.tools.util.SourceReader;
import scalac.ast.*;
import scalac.ast.parser.*;
@@ -70,6 +75,18 @@ public abstract class Global {
*/
private final Stack startTimes = new Stack();
+ /** the source file charset
+ */
+ private final Charset charset;
+
+ /** the source file decoder
+ */
+ private final CharsetDecoder decoder;
+
+ /** the source file reader
+ */
+ private final SourceReader reader;
+
/** all compilation units
*/
public Unit[] units;
@@ -194,7 +211,23 @@ public abstract class Global {
this.printtokens = args.print.tokens;
this.classPath = args.classpath();
this.outpath = args.outpath();
- this.encoding = args.encoding.value;
+ String encoding = args.encoding.value;
+ Charset charset = null;
+ try {
+ charset = Charset.forName(encoding);
+ } catch (IllegalCharsetNameException exception) {
+ args.encoding.error("illegal charset name '" + encoding + "'");
+ } catch (UnsupportedCharsetException exception) {
+ args.encoding.error("unsupported charset '" + encoding + "'");
+ }
+ if (charset == null) {
+ encoding = "ISO-8859-1"; // A mandatory charset
+ charset = Charset.forName(encoding);
+ }
+ this.encoding = encoding;
+ this.charset = charset;
+ this.decoder = charset.newDecoder();
+ this.reader = new SourceReader(decoder);
this.target = interpret ? TARGET_INT : args.target.value.intern();
this.separate = args.separate.value.equals("yes") ||
args.separate.value.equals("default") && !this.target.equals(TARGET_INT);
@@ -259,7 +292,7 @@ public abstract class Global {
/** Creates a virtual source file with given name and content. */
public SourceFile getSourceFile(String sourcename, String content) {
- return new SourceFile(sourcename, content.getBytes());
+ return new SourceFile(sourcename, content.toCharArray());
}
/** Reads and returns the source file in file with given name. */
@@ -273,9 +306,8 @@ public abstract class Global {
/** Reads and returns the source file in given abstract file. */
public SourceFile getSourceFile(AbstractFile file) throws IOException {
if (!file.exists()) throw new FileNotFoundException(
- "source file '" + file.getPath() + "' could not be found");
- byte[] content = file.read();
- return new SourceFile(file, content);
+ "source file '" + file + "' could not be found");
+ return new SourceFile(file, reader.read(file));
}
/** Reads and returns the source file of given clasz. */