scale.frontend.c
Class CReader

java.lang.Object
  extended by java.io.Reader
      extended by scale.frontend.c.CReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable

public class CReader
extends java.io.Reader

This class reads a C file and transforms it by translating special character sequences and catenating "continued" lines.

$Id: CReader.java,v 1.10 2006-05-15 19:37:06 burrill Exp $

Copyright 2005 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.


Field Summary
static boolean classTrace
          True if traces are to be performed.
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
CReader(java.lang.String filename)
           
 
Method Summary
 void close()
           
 boolean fillLine()
          Fill the line buffer.
 java.lang.String getFilename()
          Return the file name associated with this reader.
 boolean getLineArray(char[] text, int position)
           
 int getLineLength()
          Return the length of the current line.
 int getLineNumber()
          Return the line number of the next line to be read.
 int getLinePosition()
          Return the current position in the current line.
 void mark(int readAheadLimit)
          Mark the present position in the stream.
 boolean markSupported()
          Marking is not supported by this Reader.
 int read()
          Read a single character.
 int read(char[] cbuf, int off, int len)
          Read characters into a portion of an array.
 java.lang.String readLine()
          Read a line of text.
 void reset()
          Reset the stream to the most recent mark.
 void setFilename(java.lang.String filename)
          Set the file name associated with this reader.
 void setLineNumber(int lineNumber)
          Set the line number of the next line to be read.
 long skip(long n)
          Skip characters.
 
Methods inherited from class java.io.Reader
read, read, ready
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classTrace

public static boolean classTrace
True if traces are to be performed.

Constructor Detail

CReader

public CReader(java.lang.String filename)
        throws java.io.IOException
Throws:
java.io.IOException
Method Detail

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Reader
Throws:
java.io.IOException

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Read characters into a portion of an array.

Specified by:
read in class java.io.Reader
Parameters:
cbuf - - destination buffer
off - - offset at which to start storing characters
len - - maximum number of characters to read
Returns:
the number of bytes read, or -1 if the end of the stream has already been reached
Throws:
java.io.IOException

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.

Returns:
a String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
Throws:
java.io.IOException

getLineArray

public final boolean getLineArray(char[] text,
                                  int position)

getLinePosition

public final int getLinePosition()
Return the current position in the current line.


getLineLength

public final int getLineLength()
Return the length of the current line.


fillLine

public boolean fillLine()
                 throws java.io.IOException
Fill the line buffer. Convert trigraphs. Converts '\r' to '\n' and all Unicode space characters to ' '. Keep track of the source file line number.

Returns:
true if at end-of-file
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Read a single character. Line terminators are compressed into single newline ('\n') characters.

Overrides:
read in class java.io.Reader
Returns:
the character read, or -1 if the end of the stream has been reached
Throws:
java.io.IOException

setLineNumber

public void setLineNumber(int lineNumber)
Set the line number of the next line to be read. The lines are numbered starting at 1.


getLineNumber

public int getLineNumber()
Return the line number of the next line to be read. The lines are numbered starting at 1.


setFilename

public void setFilename(java.lang.String filename)
Set the file name associated with this reader.


getFilename

public java.lang.String getFilename()
Return the file name associated with this reader.


skip

public long skip(long n)
          throws java.io.IOException
Skip characters.

Overrides:
skip in class java.io.Reader
Parameters:
n - - the number of characters to skip
Returns:
the number of characters actually skipped
Throws:
java.io.IOException

mark

public void mark(int readAheadLimit)
          throws java.io.IOException
Mark the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point, and will also reset the line number appropriately.

Overrides:
mark in class java.io.Reader
Throws:
java.io.IOException

markSupported

public boolean markSupported()
Marking is not supported by this Reader.

Overrides:
markSupported in class java.io.Reader

reset

public void reset()
           throws java.io.IOException
Reset the stream to the most recent mark.

Overrides:
reset in class java.io.Reader
Throws:
java.io.IOException