diff options
author | Martin Odersky <odersky@gmail.com> | 2003-02-13 14:41:36 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2003-02-13 14:41:36 +0000 |
commit | 4177daab2f54bdb20c71f623296a8bb32616fd12 (patch) | |
tree | 23f08b43f3758e825d5965b336030603a65bbcf7 /sources/scalac/util/Position.java | |
parent | 33d6e170c97ca7b2f991896a0729941a7240b6d6 (diff) | |
download | scala-4177daab2f54bdb20c71f623296a8bb32616fd12.tar.gz scala-4177daab2f54bdb20c71f623296a8bb32616fd12.tar.bz2 scala-4177daab2f54bdb20c71f623296a8bb32616fd12.zip |
Initial version.
Diffstat (limited to 'sources/scalac/util/Position.java')
-rw-r--r-- | sources/scalac/util/Position.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/sources/scalac/util/Position.java b/sources/scalac/util/Position.java new file mode 100644 index 0000000000..c2cd7f72d3 --- /dev/null +++ b/sources/scalac/util/Position.java @@ -0,0 +1,54 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ 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; + } +} |