gov.llnl.babel.backend.writers

Class LanguageWriterForMatlab

Implemented Interfaces:
CodeConstants, LineRedirector

public class LanguageWriterForMatlab
extends LanguageWriter
implements CodeConstants, LineRedirector

Class LanguageWriterForMatlab extends the generic language writer to provide additional capabilities for writing C code. This class manages writing comment blocks as well as include files and C++ external declaration guards.

Field Summary

protected LineCountingFilterWriter
d_lcfw
protected boolean
d_skipIncludeGuard

Fields inherited from class gov.llnl.babel.backend.writers.LanguageWriter

d_context

Fields inherited from interface gov.llnl.babel.backend.CodeConstants

C_AUTO_GEN_SPLICER, C_AUTO_GEN_WARNING, C_BACKSLASH, C_BEGIN_UNREFERENCED_METHODS, C_COMMENT_CLOSE, C_COMMENT_DOC_OPEN, C_COMMENT_F77, C_COMMENT_F90, C_COMMENT_HASH, C_COMMENT_OPEN, C_COMMENT_SLASH, C_COMMENT_SUBSEQUENT, C_DEFINE, C_DESC_CJNI_PREFIX, C_DESC_HEADER_PREFIX, C_DESC_IMPL_PREFIX, C_DESC_IOR_PREFIX, C_DESC_SJNI_PREFIX, C_DESC_SKEL_PREFIX, C_DESC_STUB_PREFIX, C_END_UNREFERENCED_METHODS, C_F7731_IMPL_EXTENSION, C_F77_IMPL_EXTENSION, C_F77_IMPL_METHOD_SUFFIX, C_F77_METHOD_SUFFIX, C_F77_VERSION, C_F90_ALT_SUFFIX, C_F90_IMPL_EXTENSION, C_F90_IMPL_METHOD_SUFFIX, C_F90_METHOD_SUFFIX, C_F90_VERSION, C_FORTRAN_DESC_STUB_PREFIX, C_FORTRAN_IMPL_MODULE_PREFIX, C_FORTRAN_MODULE_PREFIX, C_FORTRAN_TYPE_MODULE_PREFIX, C_GUARD_CLOSE, C_GUARD_OPEN, C_HASH, C_IFDEFINE_CLOSE, C_IFDEFINE_CXX, C_IFDEFINE_OPEN, C_INCLUDE, C_INSERT_HERE, C_INT_BACKSLASH, C_IS_IMPL, C_IS_NOT_IMPL, C_SLASH, C_UNREFERENCED_COMMENT1, C_UNREFERENCED_COMMENT2, C_UNREFERENCED_COMMENT3, MATLAB_COMMENT_OPEN

Constructor Summary

LanguageWriterForMatlab(PrintWriter writer, Context context)
Create a LanguageWriterForMatlab instance that will send output to the specified print writer object.
LanguageWriterForMatlab(PrintWriter writer, LineCountingFilterWriter lcfw, Context context)
Create a LanguageWriterForMatlab instance that will send output to the specified print writer object.

Method Summary

void
beginBlockComment(boolean is_doc)
Begin a block comment.
void
closeCxxExtern()
Close the C++ extern block at the end of the header file.
void
closeHeaderGuard()
Close the header guard at the end of the header file.
void
endBlockComment(boolean is_doc)
End a block comment.
void
generateInclude(String file, boolean guards)
Generate a user include statement for the specified include file.
void
generateSystemInclude(String file)
Generate a system include statement for the specified include file.
String
getIncludeGuard(String file)
Generate the include guard from the specified file name.
int
getLineCount()
get current line (returns -1 iff lfcw == null )
void
openCxxExtern()
Open the C++ extern block at the top of the header file.
void
openHeaderGuard(String file)
Open the header include guard at the top of the header file.
void
redirectBegin(String path, int line)
Mark a region where the debugger should be redirected to another file starting on a specific line.
void
redirectEnd(String path, int line)
End the region where the debugger can just follow this file.
String
safeCommentString(String str)
Convert a string into a string that can safely be included inside a C comment.
void
skipIncludeGuard()
Turns openHeaderGuard & closeHeaderGuard into no-ops.
static String
toSafeComment(String str)
Convert a string into a string that can safely be included inside a C comment.
static String
toSafeString(String str)
Convert a string into a string that can safely be included inside a C string.
void
writeCommentLine(String comment)
Output a single-line comment to the pretty writer stream.
void
writeSplicerTagLine(String tagLine)
(Is this appropriate?) Write the splicer tag as a language-specific comment.

Methods inherited from class gov.llnl.babel.backend.writers.LanguageWriter

beginBlockComment, endBlockComment, safeCommentString, writeBanner, writeComment, writeComment, writeComment, writeComment, writeComment, writeComment, writeComment, writeCommentLine, writeSplicerTagLine

Methods inherited from class gov.llnl.babel.backend.writers.PrettyWriter

backTab, changeTabLevel, close, defineBlockComment, disableBlockComment, disableLineBreak, enableBlockComment, enableLineBreak, enableLineBreak, flushPrintWriter, getPrintWriter, popLineBreak, print, printAligned, printSpaces, printUnformatted, println, println, printlnUnformatted, pushLineBreak, restoreFirstTabStop, setFirstTabStop, setLineBreakString, setStrictBreaking, setTabSpacing, setTemporaryFirstTabStop, tab

Field Details

d_lcfw

protected LineCountingFilterWriter d_lcfw

d_skipIncludeGuard

protected boolean d_skipIncludeGuard

Constructor Details

LanguageWriterForMatlab

public LanguageWriterForMatlab(PrintWriter writer,
                               Context context)
Create a LanguageWriterForMatlab instance that will send output to the specified print writer object. Set up the output properties of the language writer for C, which sets the first tab stop at zero, a tab spacing of three, and line breaking at column eighty.

LanguageWriterForMatlab

public LanguageWriterForMatlab(PrintWriter writer,
                               LineCountingFilterWriter lcfw,
                               Context context)
Create a LanguageWriterForMatlab instance that will send output to the specified print writer object. Set up the output properties of the language writer for C, which sets the first tab stop at zero, a tab spacing of three, and line breaking at column eighty.

Method Details

beginBlockComment

public void beginBlockComment(boolean is_doc)
Begin a block comment. The beginning of comment string is output to the pretty writer stream and the block comment mode is enabled. The comment block is closed by calling the end comment block method. Documentation comments add an additional asterisk after the open comment.
Overrides:
beginBlockComment in interface LanguageWriter

closeCxxExtern

public void closeCxxExtern()
Close the C++ extern block at the end of the header file.

closeHeaderGuard

public void closeHeaderGuard()
Close the header guard at the end of the header file.

endBlockComment

public void endBlockComment(boolean is_doc)
End a block comment. This method disables comment block output and prints the end of comment string. Documentation comments do not add a blank line whereas regular comments add a blank line after the comment.
Overrides:
endBlockComment in interface LanguageWriter

generateInclude

public void generateInclude(String file,
                            boolean guards)
Generate a user include statement for the specified include file. If the guard flag is true, then the include statement will contain redundant external include guards.

generateSystemInclude

public void generateSystemInclude(String file)
Generate a system include statement for the specified include file.

getIncludeGuard

public String getIncludeGuard(String file)
Generate the include guard from the specified file name. The guard is the file name (without extension, if it exists) with an "included_" prefix.

getLineCount

public int getLineCount()
get current line (returns -1 iff lfcw == null )
Specified by:
getLineCount in interface LineRedirector

openCxxExtern

public void openCxxExtern()
Open the C++ extern block at the top of the header file.

openHeaderGuard

public void openHeaderGuard(String file)
Open the header include guard at the top of the header file.

redirectBegin

public void redirectBegin(String path,
                          int line)
Mark a region where the debugger should be redirected to another file starting on a specific line.
Specified by:
redirectBegin in interface LineRedirector

redirectEnd

public void redirectEnd(String path,
                        int line)
End the region where the debugger can just follow this file.
Specified by:
redirectEnd in interface LineRedirector

safeCommentString

public final String safeCommentString(String str)
Convert a string into a string that can safely be included inside a C comment. This will insert a space between a slash '/' and an asterisk '*' to prevent opening a recursive comment or prematurely ending a comment.
Overrides:
safeCommentString in interface LanguageWriter
Parameters:
str - a string to make safe for inclusion in a comment
Returns:
the string with starting and ending comments changed to something safe.

skipIncludeGuard

public void skipIncludeGuard()
Turns openHeaderGuard & closeHeaderGuard into no-ops. Used for package headers to address Roundup issue 93.

toSafeComment

public static String toSafeComment(String str)
Convert a string into a string that can safely be included inside a C comment. This will insert a space between a slash '/' and an asterisk '*' to prevent opening a recursive comment or prematurely ending a comment.
Parameters:
str - a string to make safe for inclusion in a comment
Returns:
a string with starting and ending comments changed to something safe.

toSafeString

public static String toSafeString(String str)
Convert a string into a string that can safely be included inside a C string. It will convert a backslash to a double backslash. It will convert a quote into a backslash quote. It will convert control characters into a backslashed character.
Parameters:
str - a string to make safe for inclusion in a string
Returns:
a string with the special characters changed to a safe form.

writeCommentLine

public void writeCommentLine(String comment)
Output a single-line comment to the pretty writer stream. The comment should not contain any new line characters. If the comment is null, then nothing is output.
Overrides:
writeCommentLine in interface LanguageWriter

writeSplicerTagLine

public void writeSplicerTagLine(String tagLine)
(Is this appropriate?) Write the splicer tag as a language-specific comment.
Overrides:
writeSplicerTagLine in interface LanguageWriter