at.dms.kjc.common
Class ToCCommon

java.lang.Object
  extended by at.dms.kjc.KjcEmptyVisitor
      extended by at.dms.kjc.SLIREmptyVisitor
          extended by at.dms.kjc.common.ToCCommon
All Implemented Interfaces:
Constants, KjcVisitor, SLIRVisitor
Direct Known Subclasses:
LIRToC, ToC

public abstract class ToCCommon
extends SLIREmptyVisitor

Somewhat artificial class to provide common code for at.dms.kjc.common.ToC and at.dms.kjc.lir.LIRToC Hopefully keep from having to fix some bugs twice.

Author:
Allyn Dimock

Field Summary
static boolean alternatePrintsForTiming
           
protected  boolean hasBoolType
          For C code generation, the Java type 'boolean' will be printed as 'int' For C++ code generation, set hasBoolType = true; to print the Java type 'boolean' as 'bool'
protected  JExpression lastLeft
          Needed to pass info from assignment to visitNewArray *
protected  CodegenPrintWriter p
          Object with useful print routines
protected static Map<String,String> printPostfixMap
          Print postfixes: defaults to ");" useful for printing boolean.
protected static Map<String,String> printPrefixMap
          Controls visitPrintStatement.
 
Fields inherited from interface at.dms.kjc.Constants
CMP_VERSION, JAV_CLASS, JAV_CLONE, JAV_CLONEABLE, JAV_CONSTRUCTOR, JAV_ERROR, JAV_EXCEPTION, JAV_INIT, JAV_LENGTH, JAV_NAME_SEPARATOR, JAV_OBJECT, JAV_OUTER_THIS, JAV_RUNTIME, JAV_RUNTIME_EXCEPTION, JAV_STATIC_INIT, JAV_STRING, JAV_STRINGBUFFER, JAV_THIS, JAV_THROWABLE, OPE_BAND, OPE_BNOT, OPE_BOR, OPE_BSR, OPE_BXOR, OPE_EQ, OPE_GE, OPE_GT, OPE_LE, OPE_LNOT, OPE_LT, OPE_MINUS, OPE_NE, OPE_PERCENT, OPE_PLUS, OPE_POSTDEC, OPE_POSTINC, OPE_PREDEC, OPE_PREINC, OPE_SIMPLE, OPE_SL, OPE_SLASH, OPE_SR, OPE_STAR, TID_ARRAY, TID_BIT, TID_BOOLEAN, TID_BYTE, TID_CHAR, TID_CLASS, TID_DOUBLE, TID_FLOAT, TID_INT, TID_LONG, TID_SHORT, TID_VECTOR, TID_VOID, VECTOR_EMPTY
 
Fields inherited from interface at.dms.classfile.Constants
ACC_ABSTRACT, ACC_FINAL, ACC_INLINE, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, ATT_CODE, ATT_CONSTANTVALUE, ATT_DEPRECATED, ATT_EXCEPTIONS, ATT_GENERIC, ATT_INNERCLASSES, ATT_LINENUMBERTABLE, ATT_LOCALVARIABLETABLE, ATT_SOURCEFILE, ATT_SYNTHETIC, CST_CLASS, CST_DOUBLE, CST_FIELD, CST_FLOAT, CST_INTEGER, CST_INTERFACEMETHOD, CST_LONG, CST_METHOD, CST_NAMEANDTYPE, CST_STRING, CST_UTF8, ENV_DEBUG_MODE, ENV_USE_CACHE, JAVA_MAGIC, JAVA_MAJOR, JAVA_MINOR, MAX_CODE_PER_METHOD, opc_aaload, opc_aastore, opc_aconst_null, opc_aload, opc_aload_0, opc_aload_1, opc_aload_2, opc_aload_3, opc_anewarray, opc_areturn, opc_arraylength, opc_astore, opc_astore_0, opc_astore_1, opc_astore_2, opc_astore_3, opc_athrow, opc_baload, opc_bastore, opc_bipush, opc_caload, opc_castore, opc_checkcast, opc_d2f, opc_d2i, opc_d2l, opc_dadd, opc_daload, opc_dastore, opc_dcmpg, opc_dcmpl, opc_dconst_0, opc_dconst_1, opc_ddiv, opc_dload, opc_dload_0, opc_dload_1, opc_dload_2, opc_dload_3, opc_dmul, opc_dneg, opc_drem, opc_dreturn, opc_dstore, opc_dstore_0, opc_dstore_1, opc_dstore_2, opc_dstore_3, opc_dsub, opc_dup, opc_dup_x1, opc_dup_x2, opc_dup2, opc_dup2_x1, opc_dup2_x2, opc_f2d, opc_f2i, opc_f2l, opc_fadd, opc_faload, opc_fastore, opc_fcmpg, opc_fcmpl, opc_fconst_0, opc_fconst_1, opc_fconst_2, opc_fdiv, opc_fload, opc_fload_0, opc_fload_1, opc_fload_2, opc_fload_3, opc_fmul, opc_fneg, opc_frem, opc_freturn, opc_fstore, opc_fstore_0, opc_fstore_1, opc_fstore_2, opc_fstore_3, opc_fsub, opc_getfield, opc_getstatic, opc_goto, opc_goto_w, opc_i2b, opc_i2c, opc_i2d, opc_i2f, opc_i2l, opc_i2s, opc_iadd, opc_iaload, opc_iand, opc_iastore, opc_iconst_0, opc_iconst_1, opc_iconst_2, opc_iconst_3, opc_iconst_4, opc_iconst_5, opc_iconst_m1, opc_idiv, opc_if_acmpeq, opc_if_acmpne, opc_if_icmpeq, opc_if_icmpge, opc_if_icmpgt, opc_if_icmple, opc_if_icmplt, opc_if_icmpne, opc_ifeq, opc_ifge, opc_ifgt, opc_ifle, opc_iflt, opc_ifne, opc_ifnonnull, opc_ifnull, opc_iinc, opc_iload, opc_iload_0, opc_iload_1, opc_iload_2, opc_iload_3, opc_imul, opc_ineg, opc_instanceof, opc_invokeinterface, opc_invokespecial, opc_invokestatic, opc_invokevirtual, opc_ior, opc_irem, opc_ireturn, opc_ishl, opc_ishr, opc_istore, opc_istore_0, opc_istore_1, opc_istore_2, opc_istore_3, opc_isub, opc_iushr, opc_ixor, opc_jsr, opc_jsr_w, opc_l2d, opc_l2f, opc_l2i, opc_ladd, opc_laload, opc_land, opc_lastore, opc_lcmp, opc_lconst_0, opc_lconst_1, opc_ldc, opc_ldc_w, opc_ldc2_w, opc_ldiv, opc_lload, opc_lload_0, opc_lload_1, opc_lload_2, opc_lload_3, opc_lmul, opc_lneg, opc_lookupswitch, opc_lor, opc_lrem, opc_lreturn, opc_lshl, opc_lshr, opc_lstore, opc_lstore_0, opc_lstore_1, opc_lstore_2, opc_lstore_3, opc_lsub, opc_lushr, opc_lxor, opc_monitorenter, opc_monitorexit, opc_multianewarray, opc_new, opc_newarray, opc_nop, opc_pop, opc_pop2, opc_putfield, opc_putstatic, opc_ret, opc_return, opc_saload, opc_sastore, opc_sipush, opc_swap, opc_tableswitch, opc_wide, opc_xxxunusedxxx, POO_ASCII_CONSTANT, POO_CLASS_CONSTANT, POO_DOUBLE_CONSTANT, POO_FLOAT_CONSTANT, POO_INTEGER_CONSTANT, POO_LONG_CONSTANT, POO_NAT_CONSTANT, POO_REF_CONSTANT, POO_STRING_CONSTANT, TYP_ADDRESS, TYP_DOUBLE, TYP_FLOAT, TYP_INT, TYP_LONG, TYP_REFERENCE, TYP_VOID
 
Constructor Summary
protected ToCCommon()
          With no parameters: create a new string TabbedPrintWriter for output
protected ToCCommon(CodegenPrintWriter p)
          With a TabbedPrintWriter: use the given TabbedPrintWriter for output and start off with no indentation yet.
 
Method Summary
 CodegenPrintWriter getPrinter()
          Make sure anyone can get the printer to insert code generated outside of a descendant of this class.
 String[] makeArrayStrings(JPhylum[] dims)
          Generate an array of code strings for an array of JPhylums.
 String makeString(JPhylum e)
          Generate a code string for a JExpression or JStatement
protected  void printDecl(CType s, String ident)
          Prints a declaration for the given type with the given identifier.
protected  boolean printExp(JExpression expr)
           
protected  void printLParen()
          Print a left parenthesis if not in statement context.
protected  void printRParen()
          Print a right parenthesis if not in statement context.
protected  void printType(CType s)
          Print a CType.
protected  List<JExpression> splitForPrint(JExpression exp)
          Split expression into list of expressions for print.
 void visitBitwiseComplementExpression(JUnaryExpression self, JExpression expr)
          prints a bitwise complement expression
 void visitBlockStatement(JBlock self, JavaStyleComment[] comments)
          prints an block statement
 void visitBreakStatement(JBreakStatement self, String label)
          prints a break statement
 void visitCastExpression(JCastExpression self, JExpression expr, CType type)
          prints a cast expression
 void visitClassExpression(JClassExpression self, CType type)
          Print a class Name.
 void visitCompoundAssignmentExpression(JCompoundAssignmentExpression self, int oper, JExpression left, JExpression right)
          prints a compound expression
 void visitCompoundStatement(JCompoundStatement self, JStatement[] body)
          prints a compound statement: 2-argument form
 void visitCompoundStatement(JStatement[] body)
          prints a compound statement
 void visitConditionalExpression(JConditionalExpression self, JExpression cond, JExpression left, JExpression right)
          prints a conditional expression
 void visitContinueStatement(JContinueStatement self, String label)
          prints a continue statement
 void visitDoStatement(JDoStatement self, JExpression cond, JStatement body)
          prints a do statement
 void visitEmittedTextExpression(JEmittedTextExpression self, Object[] parts)
          Code generation for JEmittedTextExpression: bits of text, types, subexpressions emitted in order.
 void visitEmptyStatement(JEmptyStatement self)
          Emits code for an empty statement.
 void visitEqualityExpression(JEqualityExpression self, boolean equal, JExpression left, JExpression right)
          prints an equality expression
 void visitExpressionListStatement(JExpressionListStatement self, JExpression[] expr)
          prints an expression list statement
 void visitExpressionStatement(JExpressionStatement self, JExpression expr)
          prints an expression statement
 void visitForStatement(JForStatement self, JStatement init, JExpression cond, JStatement incr, JStatement body)
          Emit code for a "for" statement.
 void visitLabeledStatement(JLabeledStatement self, String label, JStatement stmt)
          prints a labeled statement
 void visitLocalVariableExpression(JLocalVariableExpression self, String ident)
          prints a local variable expression
 void visitLogicalComplementExpression(JUnaryExpression self, JExpression expr)
          prints a logical complement expression
 void visitMarker(SIRMarker self)
          Print marker as a comment.
 void visitParenthesedExpression(JParenthesedExpression self, JExpression expr)
          prints a parenthesed expression
 void visitPostfixExpression(JPostfixExpression self, int oper, JExpression expr)
          prints a postfix expression
 void visitPrefixExpression(JPrefixExpression self, int oper, JExpression expr)
          prints a prefix expression
 void visitPrintStatement(SIRPrintStatement self, JExpression exp)
          Process a Print statment, table driven to allow several backends Deals with the problem of string concatenation in Java not translating to our output languages C or C++
 void visitReturnStatement(JReturnStatement self, JExpression expr)
          prints a return statement
 void visitShiftExpression(JShiftExpression self, int oper, JExpression left, JExpression right)
          prints a shift expression
 void visitSwitchStatement(JSwitchStatement self, JExpression expr, JSwitchGroup[] body)
          prints a switch statement
 void visitTypeDeclarationStatement(JTypeDeclarationStatement self, JTypeDeclaration decl)
          prints a type declaration statement
 void visitTypeNameExpression(JTypeNameExpression self, CType type)
          prints a type name expression
 void visitUnaryMinusExpression(JUnaryExpression self, JExpression expr)
          prints an unary minus expression
 void visitUnaryPlusExpression(JUnaryExpression self, JExpression expr)
          prints an unary plus expression
 void visitUnaryPromoteExpression(JUnaryPromote self, JExpression expr, CType type)
          prints a cast expression
 void visitVariableDeclarationStatement(JVariableDeclarationStatement self, JVariableDefinition[] vars)
          prints a variable declaration statement
 void visitWhileStatement(JWhileStatement self, JExpression cond, JStatement body)
          prints a while statement
 
Methods inherited from class at.dms.kjc.SLIREmptyVisitor
visitCreatePortalExpression, visitDynamicToken, visitFileReader, visitFileWriter, visitFunctionPointer, visitIdentity, visitInitStatement, visitInlineAssembly, visitInterfaceTable, visitLatency, visitLatencyMax, visitLatencyRange, visitLatencySet, visitMainFunction, visitMessageStatement, visitNode, visitPeekExpression, visitPopExpression, visitPortal, visitPushExpression, visitRangeExpression, visitRegisterReceiver, visitRegReceiverStatement, visitRegSenderStatement, visitSetBodyOfFeedback, visitSetChild, visitSetDecode, visitSetDelay, visitSetEncode, visitSetJoiner, visitSetLoopOfFeedback, visitSetParallelStream, visitSetPeek, visitSetPop, visitSetPush, visitSetSplitter, visitSetStreamType, visitSetTape, visitSetWork, visitVectorLiteral, visitWorkEntry, visitWorkExit
 
Methods inherited from class at.dms.kjc.KjcEmptyVisitor
visitArgs, visitArrayAccessExpression, visitArrayInitializer, visitArrayLengthExpression, visitAssignmentExpression, visitBinaryExpression, visitBitwiseExpression, visitBooleanLiteral, visitByteLiteral, visitCatchClause, visitCharLiteral, visitClassBody, visitClassDeclaration, visitClassImport, visitComment, visitComments, visitCompilationUnit, visitConstructorCall, visitConstructorDeclaration, visitDoubleLiteral, visitFieldDeclaration, visitFieldExpression, visitFloatLiteral, visitFormalParameters, visitIfStatement, visitInnerClassDeclaration, visitInstanceofExpression, visitInterfaceDeclaration, visitIntLiteral, visitJavadoc, visitLongLiteral, visitMethodCallExpression, visitMethodDeclaration, visitNameExpression, visitNewArrayExpression, visitNullLiteral, visitPackageImport, visitPackageName, visitQualifiedAnonymousCreation, visitQualifiedInstanceCreation, visitRelationalExpression, visitShortLiteral, visitStringLiteral, visitSuperExpression, visitSwitchGroup, visitSwitchLabel, visitSynchronizedStatement, visitThisExpression, visitThrowStatement, visitTryCatchStatement, visitTryFinallyStatement, visitUnqualifiedAnonymousCreation, visitUnqualifiedInstanceCreation, visitVariableDefinition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface at.dms.kjc.KjcVisitor
visitArrayAccessExpression, visitArrayInitializer, visitArrayLengthExpression, visitAssignmentExpression, visitBinaryExpression, visitBitwiseExpression, visitBooleanLiteral, visitByteLiteral, visitCatchClause, visitCharLiteral, visitClassBody, visitClassDeclaration, visitClassImport, visitComment, visitComments, visitCompilationUnit, visitConstructorCall, visitConstructorDeclaration, visitDoubleLiteral, visitFieldDeclaration, visitFieldExpression, visitFloatLiteral, visitFormalParameters, visitIfStatement, visitInnerClassDeclaration, visitInstanceofExpression, visitInterfaceDeclaration, visitIntLiteral, visitJavadoc, visitLongLiteral, visitMethodCallExpression, visitMethodDeclaration, visitNameExpression, visitNewArrayExpression, visitNullLiteral, visitPackageImport, visitPackageName, visitQualifiedAnonymousCreation, visitQualifiedInstanceCreation, visitRelationalExpression, visitShortLiteral, visitStringLiteral, visitSuperExpression, visitSwitchGroup, visitSwitchLabel, visitSynchronizedStatement, visitThisExpression, visitThrowStatement, visitTryCatchStatement, visitTryFinallyStatement, visitUnqualifiedAnonymousCreation, visitUnqualifiedInstanceCreation, visitVariableDefinition
 

Field Detail

alternatePrintsForTiming

public static boolean alternatePrintsForTiming

printPrefixMap

protected static Map<String,String> printPrefixMap
Controls visitPrintStatement. Can override for a backend by writing to this variable. initialized by a static block. Can be overridden in a static block in a subclass by printPrefixMap.clear(); printPrefixMap.put... If there is more than one printer inheriting from ToCCommon and your inheritance structure is not linear then you may have to write to printPrefixMap from a constructor rather than from a static block. If your backend does more on prints than the common backend, you will probably want to override printExp.


printPostfixMap

protected static Map<String,String> printPostfixMap
Print postfixes: defaults to ");" useful for printing boolean.


lastLeft

protected JExpression lastLeft
Needed to pass info from assignment to visitNewArray *


p

protected CodegenPrintWriter p
Object with useful print routines


hasBoolType

protected boolean hasBoolType
For C code generation, the Java type 'boolean' will be printed as 'int' For C++ code generation, set hasBoolType = true; to print the Java type 'boolean' as 'bool'

Constructor Detail

ToCCommon

protected ToCCommon()
With no parameters: create a new string TabbedPrintWriter for output


ToCCommon

protected ToCCommon(CodegenPrintWriter p)
With a TabbedPrintWriter: use the given TabbedPrintWriter for output and start off with no indentation yet.

Method Detail

getPrinter

public CodegenPrintWriter getPrinter()
Make sure anyone can get the printer to insert code generated outside of a descendant of this class.


printLParen

protected void printLParen()
Print a left parenthesis if not in statement context.


printRParen

protected void printRParen()
Print a right parenthesis if not in statement context.


makeString

public String makeString(JPhylum e)
Generate a code string for a JExpression or JStatement

usage:
(new mySubClass()).makeString(e);

Relies on the subclass's nullary constructor doing something sensible.

Parameters:
e - a JPhylum (superclass of Jexpression and Jstatement)
Returns:
code generated for the expression.

makeArrayStrings

public String[] makeArrayStrings(JPhylum[] dims)
Generate an array of code strings for an array of JPhylums. Usually used to generate code for each of CArrayType's dimensions.

usual usage:
String[] dims_code = (new mySubClass()).makeArrayStrings(((CArrayType)type).getDims());
or, if called from a within an object method of a subclass:
String[] dims_code = this.makeArrayStrings(((CArrayType)type).getDims());

Relies on the subclass's nullary constructor doing something sensible.

Parameters:
dims - an array of JExpression
Returns:
array of String conatining generated code for each expression

visitForStatement

public void visitForStatement(JForStatement self,
                              JStatement init,
                              JExpression cond,
                              JStatement incr,
                              JStatement body)
Emit code for a "for" statement.

Specified by:
visitForStatement in interface KjcVisitor
Overrides:
visitForStatement in class KjcEmptyVisitor

visitEmptyStatement

public void visitEmptyStatement(JEmptyStatement self)
Emits code for an empty statement. Works with visitForStatment, if you override one then override both.

Specified by:
visitEmptyStatement in interface KjcVisitor
Overrides:
visitEmptyStatement in class KjcEmptyVisitor

visitWhileStatement

public void visitWhileStatement(JWhileStatement self,
                                JExpression cond,
                                JStatement body)
prints a while statement

Specified by:
visitWhileStatement in interface KjcVisitor
Overrides:
visitWhileStatement in class KjcEmptyVisitor

visitVariableDeclarationStatement

public void visitVariableDeclarationStatement(JVariableDeclarationStatement self,
                                              JVariableDefinition[] vars)
prints a variable declaration statement

Specified by:
visitVariableDeclarationStatement in interface KjcVisitor
Overrides:
visitVariableDeclarationStatement in class KjcEmptyVisitor

visitSwitchStatement

public void visitSwitchStatement(JSwitchStatement self,
                                 JExpression expr,
                                 JSwitchGroup[] body)
prints a switch statement

Specified by:
visitSwitchStatement in interface KjcVisitor
Overrides:
visitSwitchStatement in class KjcEmptyVisitor

visitReturnStatement

public void visitReturnStatement(JReturnStatement self,
                                 JExpression expr)
prints a return statement

Specified by:
visitReturnStatement in interface KjcVisitor
Overrides:
visitReturnStatement in class KjcEmptyVisitor

visitLabeledStatement

public void visitLabeledStatement(JLabeledStatement self,
                                  String label,
                                  JStatement stmt)
prints a labeled statement

Specified by:
visitLabeledStatement in interface KjcVisitor
Overrides:
visitLabeledStatement in class KjcEmptyVisitor

visitCompoundStatement

public void visitCompoundStatement(JCompoundStatement self,
                                   JStatement[] body)
prints a compound statement: 2-argument form

Specified by:
visitCompoundStatement in interface KjcVisitor
Overrides:
visitCompoundStatement in class KjcEmptyVisitor

visitExpressionStatement

public void visitExpressionStatement(JExpressionStatement self,
                                     JExpression expr)
prints an expression statement

Specified by:
visitExpressionStatement in interface KjcVisitor
Overrides:
visitExpressionStatement in class KjcEmptyVisitor

visitExpressionListStatement

public void visitExpressionListStatement(JExpressionListStatement self,
                                         JExpression[] expr)
prints an expression list statement

Specified by:
visitExpressionListStatement in interface KjcVisitor
Overrides:
visitExpressionListStatement in class KjcEmptyVisitor

visitDoStatement

public void visitDoStatement(JDoStatement self,
                             JExpression cond,
                             JStatement body)
prints a do statement

Specified by:
visitDoStatement in interface KjcVisitor
Overrides:
visitDoStatement in class KjcEmptyVisitor

visitContinueStatement

public void visitContinueStatement(JContinueStatement self,
                                   String label)
prints a continue statement

Specified by:
visitContinueStatement in interface KjcVisitor
Overrides:
visitContinueStatement in class KjcEmptyVisitor

visitBreakStatement

public void visitBreakStatement(JBreakStatement self,
                                String label)
prints a break statement

Specified by:
visitBreakStatement in interface KjcVisitor
Overrides:
visitBreakStatement in class KjcEmptyVisitor

visitCompoundStatement

public void visitCompoundStatement(JStatement[] body)
prints a compound statement

Overrides:
visitCompoundStatement in class KjcEmptyVisitor

visitBlockStatement

public void visitBlockStatement(JBlock self,
                                JavaStyleComment[] comments)
prints an block statement

Specified by:
visitBlockStatement in interface KjcVisitor
Overrides:
visitBlockStatement in class KjcEmptyVisitor

visitTypeDeclarationStatement

public void visitTypeDeclarationStatement(JTypeDeclarationStatement self,
                                          JTypeDeclaration decl)
prints a type declaration statement

Specified by:
visitTypeDeclarationStatement in interface KjcVisitor
Overrides:
visitTypeDeclarationStatement in class KjcEmptyVisitor

visitEmittedTextExpression

public void visitEmittedTextExpression(JEmittedTextExpression self,
                                       Object[] parts)
Code generation for JEmittedTextExpression: bits of text, types, subexpressions emitted in order.

Specified by:
visitEmittedTextExpression in interface KjcVisitor
Overrides:
visitEmittedTextExpression in class KjcEmptyVisitor
Parameters:
self -

visitUnaryPlusExpression

public void visitUnaryPlusExpression(JUnaryExpression self,
                                     JExpression expr)
prints an unary plus expression

Specified by:
visitUnaryPlusExpression in interface KjcVisitor
Overrides:
visitUnaryPlusExpression in class KjcEmptyVisitor

visitUnaryMinusExpression

public void visitUnaryMinusExpression(JUnaryExpression self,
                                      JExpression expr)
prints an unary minus expression

Specified by:
visitUnaryMinusExpression in interface KjcVisitor
Overrides:
visitUnaryMinusExpression in class KjcEmptyVisitor

visitBitwiseComplementExpression

public void visitBitwiseComplementExpression(JUnaryExpression self,
                                             JExpression expr)
prints a bitwise complement expression

Specified by:
visitBitwiseComplementExpression in interface KjcVisitor
Overrides:
visitBitwiseComplementExpression in class KjcEmptyVisitor

visitLogicalComplementExpression

public void visitLogicalComplementExpression(JUnaryExpression self,
                                             JExpression expr)
prints a logical complement expression

Specified by:
visitLogicalComplementExpression in interface KjcVisitor
Overrides:
visitLogicalComplementExpression in class KjcEmptyVisitor

visitTypeNameExpression

public void visitTypeNameExpression(JTypeNameExpression self,
                                    CType type)
prints a type name expression

Specified by:
visitTypeNameExpression in interface KjcVisitor
Overrides:
visitTypeNameExpression in class KjcEmptyVisitor

visitShiftExpression

public void visitShiftExpression(JShiftExpression self,
                                 int oper,
                                 JExpression left,
                                 JExpression right)
prints a shift expression

Specified by:
visitShiftExpression in interface KjcVisitor
Overrides:
visitShiftExpression in class KjcEmptyVisitor

visitPrefixExpression

public void visitPrefixExpression(JPrefixExpression self,
                                  int oper,
                                  JExpression expr)
prints a prefix expression

Specified by:
visitPrefixExpression in interface KjcVisitor
Overrides:
visitPrefixExpression in class KjcEmptyVisitor

visitPostfixExpression

public void visitPostfixExpression(JPostfixExpression self,
                                   int oper,
                                   JExpression expr)
prints a postfix expression

Specified by:
visitPostfixExpression in interface KjcVisitor
Overrides:
visitPostfixExpression in class KjcEmptyVisitor

visitParenthesedExpression

public void visitParenthesedExpression(JParenthesedExpression self,
                                       JExpression expr)
prints a parenthesed expression

Specified by:
visitParenthesedExpression in interface KjcVisitor
Overrides:
visitParenthesedExpression in class KjcEmptyVisitor

visitLocalVariableExpression

public void visitLocalVariableExpression(JLocalVariableExpression self,
                                         String ident)
prints a local variable expression

Specified by:
visitLocalVariableExpression in interface KjcVisitor
Overrides:
visitLocalVariableExpression in class KjcEmptyVisitor

visitEqualityExpression

public void visitEqualityExpression(JEqualityExpression self,
                                    boolean equal,
                                    JExpression left,
                                    JExpression right)
prints an equality expression

Specified by:
visitEqualityExpression in interface KjcVisitor
Overrides:
visitEqualityExpression in class KjcEmptyVisitor

visitConditionalExpression

public void visitConditionalExpression(JConditionalExpression self,
                                       JExpression cond,
                                       JExpression left,
                                       JExpression right)
prints a conditional expression

Specified by:
visitConditionalExpression in interface KjcVisitor
Overrides:
visitConditionalExpression in class KjcEmptyVisitor

visitCompoundAssignmentExpression

public void visitCompoundAssignmentExpression(JCompoundAssignmentExpression self,
                                              int oper,
                                              JExpression left,
                                              JExpression right)
prints a compound expression

Specified by:
visitCompoundAssignmentExpression in interface KjcVisitor
Overrides:
visitCompoundAssignmentExpression in class KjcEmptyVisitor

visitCastExpression

public void visitCastExpression(JCastExpression self,
                                JExpression expr,
                                CType type)
prints a cast expression

Specified by:
visitCastExpression in interface KjcVisitor
Overrides:
visitCastExpression in class KjcEmptyVisitor

visitUnaryPromoteExpression

public void visitUnaryPromoteExpression(JUnaryPromote self,
                                        JExpression expr,
                                        CType type)
prints a cast expression

Specified by:
visitUnaryPromoteExpression in interface KjcVisitor
Overrides:
visitUnaryPromoteExpression in class KjcEmptyVisitor

splitForPrint

protected List<JExpression> splitForPrint(JExpression exp)
Split expression into list of expressions for print. The C backends are not set up to perform Java-like string concatenation, and the C++ backends often can not perform string concatenation because of semantic diffrences between the C++ + operator and the Java + operator. We solve this by looking for all string contatenations reachable from the root of the expression without going through any operator other than string concatenation and return a List of expressions -- in left-to-right order -- that were connected by string concatenation in the original expression. I am following the belief that there are some expressions for which no type can be found. As per previous implementations, such expressions do not cause an uncaught exception, but they may generate bad code...

Parameters:
exp -
Returns:
list of expressions that had been string concatenated.

printExp

protected boolean printExp(JExpression expr)

visitPrintStatement

public void visitPrintStatement(SIRPrintStatement self,
                                JExpression exp)
Process a Print statment, table driven to allow several backends Deals with the problem of string concatenation in Java not translating to our output languages C or C++

Specified by:
visitPrintStatement in interface SLIRVisitor
Overrides:
visitPrintStatement in class SLIREmptyVisitor

visitMarker

public void visitMarker(SIRMarker self)
Print marker as a comment.

Specified by:
visitMarker in interface SLIRVisitor
Overrides:
visitMarker in class SLIREmptyVisitor

printDecl

protected void printDecl(CType s,
                         String ident)
Prints a declaration for the given type with the given identifier. Prints int x[10][10] for arrays.

Parameters:
s - the type to declare
ident - the identifier to declare

visitClassExpression

public void visitClassExpression(JClassExpression self,
                                 CType type)
Print a class Name.

Specified by:
visitClassExpression in interface KjcVisitor
Overrides:
visitClassExpression in class KjcEmptyVisitor
Parameters:
self - a JClassExpression
type - s CType, presumably a CCLassNameType....

printType

protected void printType(CType s)
Print a CType.

Parameters:
s - a CType to be printed.