scale.clef2C
Class Clef2C

java.lang.Object
  |
  +--scale.clef.AcceptPredicate
        |
        +--scale.clef2C.Clef2C
All Implemented Interfaces:
DeclPredicate, ExprPredicate, Predicate, StmtPredicate, TypePredicate
Direct Known Subclasses:
Clef2Cxx

public class Clef2C
extends AcceptPredicate
implements Predicate

A class to generate C code from a Clef AST.

$Id: Clef2C.java,v 1.197 2002/01/03 21:44:25 burrill Exp $

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

This class is used primarily to generate C for declarations. However, it can also generate executable statements from a Clef AST.

Note, that as a side effect, Clef2C may change the Clef tree (for example, Clef2C changes the Clef tree to implement virtual functions).

See Also:
scale.clef, Clef2Cxx

Field Summary
protected  ClassLower classLower
          The object used to ClassType objects.
protected static int cNoPass
          An enumeration of the different passes made over types to generate types/declarations.
protected static int cPostName
          Generate type/declaration code after name
protected static int cPreName
          Generate type/declaration code before name
protected  Emit emit
          The Emit class used for generating output.
protected static int firstLabelNum
           
protected  boolean genForwardDecl
          Generate a forward declaration or the complete function?
protected  boolean genFullProcedureType
          Do we want the formals and exceptions wanted?
protected  boolean genInitialValue
          Do we want to generate the initializer for a declaration?
protected static java.lang.String idPrefix
           
protected  boolean inAggregationElements
          true if processing AggregationElements
protected static java.lang.String includeFile1
           
protected static java.lang.String includeFile2
           
protected  boolean inTypeRef
          A flag which indicates if we are generating an aggregate/enum defintion or reference (e.g., struct A {int a;}; vs.
protected  Keyword keywords
          Target language keywords (i.e., C and C++ have different sets of keywords)
protected  int labelNum
          Current label number.
protected static java.lang.String labelPrefix
           
protected  java.util.Hashtable labelToInt
          Map label strings to integers (needed for fortran)
protected  SourceLanguage lang
          Information that is specific to the source language
protected  Declaration myDecl
          The declaration associated with a type.
protected  int typePass
          The current pass number for type declarations.
 
Constructor Summary
protected Clef2C(Emit emit, Keyword keywords, SourceLanguage lang)
          Construct a C language code generator - output goes to a file Either the Clef tree needs to be specified or the source language - but not both.
  Clef2C(Emit em, SourceLanguage lang)
          Construct a C language code generator - output goes to a file
 
Method Summary
 void closeParens(Expression expr)
          Code to generate the closing parenthesis for an expression.
 void codeGen(Node root)
          Generate code for Clef tree
 java.lang.String convertDeclName(Declaration decl, boolean address)
          Convert the name of the declaration for display.
 java.lang.String fileExt()
          Get the file name extension for the C language.
protected  void genActuals(CallFunctionOp f)
          Generate code for the actual arguments for a function call.
protected  void genActuals(CallMethodOp m)
          Generate code for the actual arguments.
protected  void genArgumentList(java.util.Enumeration argList, ProcedureType s)
          Generate code for the actuals arguments to a function.
protected  void genColMajorSubscript(ArrayType arrayType, java.util.Enumeration sub)
          Convert a column major array subscript to a row major array subscript.
 void genDeclarator(Type t, java.lang.String v)
          Generate the C code for a declarator.
 void genDeclaratorFull(Type t, java.lang.String v)
           
protected  void genDecls(SymtabScope scope)
          Generate code for declarations.
protected  void genExceptionList(java.util.Enumeration args)
          Generate code for exceptions.
protected  void genFormals(ProcedureType s)
          Generate code for a list of formal arguments.
 void genForwardRoutineDecl(RoutineDecl p)
           
static void genIncludes(SourceLanguage sl, Emit emit)
          Generate the include files needed for the generated C code.
 void genIntrinsicOp(java.lang.String op, Type t1, Expression e1, Type t2, Expression e2)
          Generate a call to a routine that is part of the Scale runtime library.
 void genRoutineAttributes(RoutineDecl p)
           
protected  void genStatements(Statement s)
          Generate code for a list of statements.
 void genTypeDecl(TypeDecl td)
           
protected  void genTypeReference(java.lang.String kind)
          Generate the C code for a type reference.
 ClassLower getClassLower()
           
protected  java.lang.String identifierName(IdReferenceOp id)
          Create a unique identifier name given a IdReferenceOp node.
protected  java.lang.String labelName(java.lang.String n)
          Create a unique label name - we prepend the label with "_L_" to ensure that label is legal for C/C++ and that it is unique.
protected  int mapLabelToInt(java.lang.String label)
          We maintain a mapping between labels and integer values for Fortran labels (i.e., for assign statements).
 java.lang.String mapTypeToString(Type t)
          Map a type to a string.
 void openParens(Expression expr)
          Code to generate a parenthesis for an expression.
protected  int precedence(Type t)
          Return a precedence value for types.
 void visitAbsoluteValueOp(Node n)
           
 void visitAdditionAssignmentOp(Node n)
           
 void visitAdditionOp(Node n)
           
 void visitAddressLiteral(Node n)
           
 void visitAddressOp(Node n)
           
 void visitAggregateType(Node n)
          Generate the C code for an aggregate type.
 void visitAggregationElementOp(Node n)
          This node represents a single expression in the initializer.
 void visitAggregationElements(Node n)
          Generate code for aggregate values.
 void visitAllocateOp(Node n)
          Allocate an object (when the allocation occurs implicitly).
 void visitAlternateReturnStmt(Node n)
           
 void visitAndConditionalOp(Node n)
           
 void visitAndOp(Node n)
           
 void visitArgument(Node n)
           
 void visitArithmeticIfStmt(Node n)
          Generate code for an arithmetic if statement (from Fortran 77).
 void visitArrayEqualityOp(Node n)
           
 void visitArrayGreaterEqualOp(Node n)
           
 void visitArrayGreaterOp(Node n)
           
 void visitArrayInequalityOp(Node n)
           
 void visitArrayLessEqualOp(Node n)
           
 void visitArrayLessOp(Node n)
           
 void visitArrayRelOp(Node n)
           
 void visitArrayType(Node n)
          A generic array.
 void visitAssignComponentsOp(Node n)
          Generate C code for assigning aggregates or arrays.
 void visitAssignedGotoStmt(Node n)
           
 void visitAssignFixedStringOp(Node n)
           
 void visitAssignLabelStmt(Node n)
           
 void visitAssignSimpleOp(Node n)
          Generate the C code for a regular assignment.
 void visitBitAndAssignmentOp(Node n)
           
 void visitBitAndOp(Node n)
           
 void visitBitComplementOp(Node n)
           
 void visitBitOrAssignmentOp(Node n)
           
 void visitBitOrOp(Node n)
           
 void visitBitShiftAssignmentOp(Node n)
           
 void visitBitShiftOp(Node n)
           
 void visitBitXorAssignmentOp(Node n)
           
 void visitBitXorOp(Node n)
           
 void visitBlockStmt(Node n)
          Generate code for a block of statements.
We emit braces around the block of statements and we generate declarations (if we generate C code) for all symbols declared in the block.
 void visitBooleanLiteral(Node n)
           
 void visitBooleanType(Node n)
           
 void visitBound(Node n)
           
 void visitBreakStmt(Node n)
           
 void visitCallFunctionOp(Node n)
           
 void visitCallMethodOp(Node n)
          Generate code for a call to a method.
 void visitCaseStmt(Node n)
           
 void visitCharacterType(Node n)
           
 void visitCharLiteral(Node n)
           
 void visitClassType(Node n)
          Generate C code for a class type.
 void visitComplexType(Node n)
           
 void visitComputedGotoStmt(Node n)
           
 void visitConcatenationOp(Node n)
           
 void visitConstantDecl(Node n)
           
 void visitConstructorDecl(Node n)
          Generate code for a constructor (modeled after C++ constructors).
 void visitContinueStmt(Node n)
           
 void visitDeclaration(Node n)
           
 void visitDeclStmt(Node n)
           
 void visitDefiniteAgElementOp(Node n)
          This node represents a single expression in the initializer.
 void visitDereferenceOp(Node n)
           
 void visitDestructorDecl(Node n)
           
 void visitDivisionAssignmentOp(Node n)
           
 void visitDivisionOp(Node n)
           
 void visitDoLoopStmt(Node n)
           
 void visitEntryDecl(Node n)
           
 void visitEnumElementDecl(Node n)
           
 void visitEnumerationType(Node n)
           
 void visitEqualityOp(Node n)
           
 void visitEquivalenceDecl(Node n)
          Generates the C code for Fortran EQUIVALENCE relations.
 void visitEvalStmt(Node n)
           
 void visitExitStmt(Node n)
           
 void visitExponentiationOp(Node n)
           
 void visitExpression(Node n)
           
 void visitExpressionIfOp(Node n)
           
 void visitFieldDecl(Node n)
           
 void visitFileDecl(Node n)
           
 void visitFixedArrayType(Node n)
          Generate code for a fixed array (same as a regular array).
 void visitFloatArrayLiteral(Node n)
           
 void visitFloatLiteral(Node n)
           
 void visitFloatType(Node n)
           
 void visitForLoopStmt(Node n)
           
 void visitFormalDecl(Node n)
          Generate code for formal declarations.
 void visitForwardProcedureDecl(Node n)
           
 void visitGotoStmt(Node n)
           
 void visitGreaterEqualOp(Node n)
           
 void visitGreaterOp(Node n)
           
 void visitIdAddressOp(Node n)
           
 void visitIdReferenceOp(Node n)
           
 void visitIdValueOp(Node n)
           
 void visitIfThenElseStmt(Node n)
          Generate code for a If-Then-Else statement.
 void visitIncompleteType(Node n)
           
 void visitIndefiniteAgElementOp(Node n)
          This node represents a single expression in the initializer.
 void visitInitializer(Node n)
          Generate code for constructor initializers.
 void visitIntArrayLiteral(Node n)
           
 void visitIntegerType(Node n)
           
 void visitIntLiteral(Node n)
           
 void visitLabelDecl(Node n)
           
 void visitLabelStmt(Node n)
           
 void visitLessEqualOp(Node n)
           
 void visitLessOp(Node n)
           
 void visitLiteral(Node n)
          Generate code for a literal.
 void visitMaximumOp(Node n)
           
 void visitMethodDecl(Node n)
           
 void visitMethodType(Node n)
          Generate code for a method's signature.
 void visitMinimumOp(Node n)
           
 void visitModulusOp(Node n)
           
 void visitMultiBranchStmt(Node n)
           
 void visitMultiplicationAssignmentOp(Node n)
           
 void visitMultiplicationOp(Node n)
           
 void visitNegativeOp(Node n)
           
 void visitNilOp(Node n)
           
 void visitNotEqualOp(Node n)
           
 void visitNotOp(Node n)
           
 void visitNullStmt(Node n)
           
 void visitOrConditionalOp(Node n)
           
 void visitOrOp(Node n)
           
 void visitParenthesesOp(Node n)
           
 void visitPointerType(Node n)
          Generate code for a pointer type.
 void visitPositionalArgumentOp(Node n)
          Generate code for an actual argument.
 void visitPositiveOp(Node n)
           
 void visitPostDecrementOp(Node n)
           
 void visitPostIncrementOp(Node n)
           
 void visitPreDecrementOp(Node n)
           
 void visitPreIncrementOp(Node n)
           
 void visitProcedureDecl(Node n)
           
 void visitProcedureType(Node n)
          Generate code for a procedure type.
 void visitRangeType(Node n)
           
 void visitRecordType(Node n)
          Generate C code for a record type.
 void visitRefType(Node n)
          Generate code for a RefType.
 void visitRemainderAssignmentOp(Node n)
           
 void visitRemainderOp(Node n)
           
 void visitRenamedVariableDecl(Node n)
           
 void visitRepeatUntilLoopStmt(Node n)
           
 void visitRepeatWhileLoopStmt(Node n)
           
 void visitReturnStmt(Node n)
           
 void visitSelectIndirectOp(Node n)
           
 void visitSelectOp(Node n)
           
 void visitSeriesOp(Node n)
           
 void visitSizeofLiteral(Node n)
           
 void visitStringLiteral(Node n)
           
 void visitSubscriptAddressOp(Node n)
           
 void visitSubscriptOp(Node n)
           
 void visitSubscriptValueOp(Node n)
           
 void visitSubtractionAssignmentOp(Node n)
           
 void visitSubtractionOp(Node n)
           
 void visitSwitchStmt(Node n)
           
 void visitThisOp(Node n)
           
 void visitTranscendental2Op(Node n)
           
 void visitTranscendentalOp(Node n)
           
 void visitType(Node n)
           
 void visitTypeConversion2Op(Node n)
          Implement the conversion operator.
 void visitTypeConversionDecl(Node n)
          A Type Conversion routine is a special case of a Method.
 void visitTypeConversionOp(Node n)
          Implement the conversion operator.
 void visitTypeDecl(Node n)
          Generate code for declaring a type.
 void visitTypeName(Node n)
           
 void visitUnionType(Node n)
           
 void visitUnknownFormals(Node n)
           
 void visitVaArgOp(Node n)
          Generate the C construct for the va_arg(va_list, type) construct.
 void visitVaEndOp(Node n)
          Generate the C construct for the va_end(va_list) construct.
 void visitValueDecl(Node n)
          Generate C code for declarations (also known as declarators).
 void visitVariableDecl(Node n)
           
 void visitVaStartOp(Node n)
          Generate the C construct for the va_start(va_list, parmN) construct.
 void visitVoidType(Node n)
           
 void visitWhileLoopStmt(Node n)
           
 
Methods inherited from class scale.clef.AcceptPredicate
visitAggregateOp, visitAllocateOpenArray, visitAllocatePlacementOp, visitAllocateSettingFieldsOp, visitAltCase, visitAltReturnFormal, visitArithmeticOp, visitArrayOp, visitAssignmentOp, visitAtomicType, visitBitwiseOp, visitBooleanDyadicOp, visitBooleanMonadicOp, visitBooleanOp, visitBranchStmt, visitCallOp, visitCaseLabelDecl, visitCatchAllStmt, visitCatchExceptionStmt, visitCompositeType, visitCompoundAssignmentOp, visitConditionalStmt, visitDeleteArrayOp, visitDeleteOp, visitDyadicOp, visitElseHandlerStmt, visitExceptionDecl, visitExceptionHandlerStmt, visitExceptionHandlerWithArgumentStmt, visitExceptionKey, visitExceptionStmt, visitFixedType, visitFriendDecl, visitHeapOp, visitIfStmt, visitIncrementOp, visitInterfaceDecl, visitJumpStmt, visitLeaveStmt, visitLoopStmt, visitMethodReferenceDecl, visitNamedArgumentOp, visitNamingStmt, visitNode, visitNumericOp, visitNumericType, visitOffsetType, visitOperator, visitOrderingOp, visitPanicStmt, visitPointerOp, visitPositionAnyOp, visitPositionOp, visitPositionRangeOp, visitPositionSingleOp, visitRaise, visitRaiseStmt, visitRaiseWithObject, visitRaiseWithType, visitRealType, visitRelationalOp, visitRoutineDecl, visitSelectRelativeIndirectOp, visitSelectRelativeOp, visitStatement, visitStructMultiBranchStmt, visitSuperType, visitTestLoopStmt, visitThrowStmt, visitTranscendental2OP, visitTranscendentalOP, visitTryExceptStmt, visitTryFinallyStmt, visitTryStmt, visitTypecaseAlt, visitTypecaseKey, visitTypecaseStmt, visitVarArgOp, visitWithAliasStmt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface scale.clef.Predicate
visitNode
 
Methods inherited from interface scale.clef.DeclPredicate
visitAltReturnFormal, visitCaseLabelDecl, visitExceptionDecl, visitFriendDecl, visitMethodReferenceDecl, visitRoutineDecl
 
Methods inherited from interface scale.clef.TypePredicate
visitAtomicType, visitCompositeType, visitFixedType, visitNumericType, visitOffsetType, visitRaise, visitRaiseWithObject, visitRaiseWithType, visitRealType, visitSuperType
 
Methods inherited from interface scale.clef.StmtPredicate
visitAltCase, visitBranchStmt, visitCatchAllStmt, visitCatchExceptionStmt, visitConditionalStmt, visitElseHandlerStmt, visitExceptionHandlerStmt, visitExceptionHandlerWithArgumentStmt, visitExceptionKey, visitExceptionStmt, visitIfStmt, visitJumpStmt, visitLeaveStmt, visitLoopStmt, visitNamingStmt, visitPanicStmt, visitRaiseStmt, visitStatement, visitStructMultiBranchStmt, visitTestLoopStmt, visitThrowStmt, visitTryExceptStmt, visitTryFinallyStmt, visitTryStmt, visitTypecaseAlt, visitTypecaseKey, visitTypecaseStmt, visitWithAliasStmt
 
Methods inherited from interface scale.clef.ExprPredicate
visitAggregateOp, visitAllocateOpenArray, visitAllocatePlacementOp, visitAllocateSettingFieldsOp, visitArithmeticOp, visitArrayOp, visitAssignmentOp, visitBitwiseOp, visitBooleanDyadicOp, visitBooleanMonadicOp, visitBooleanOp, visitCallOp, visitCompoundAssignmentOp, visitDeleteArrayOp, visitDeleteOp, visitDyadicOp, visitHeapOp, visitIncrementOp, visitNamedArgumentOp, visitNumericOp, visitOperator, visitOrderingOp, visitPointerOp, visitPositionAnyOp, visitPositionOp, visitPositionRangeOp, visitPositionSingleOp, visitRelationalOp, visitSelectRelativeIndirectOp, visitSelectRelativeOp, visitVarArgOp
 

Field Detail

emit

protected Emit emit
The Emit class used for generating output.

keywords

protected Keyword keywords
Target language keywords (i.e., C and C++ have different sets of keywords)

lang

protected SourceLanguage lang
Information that is specific to the source language

labelNum

protected int labelNum
Current label number. We need to generate labels for certain Clef constructs.

labelToInt

protected java.util.Hashtable labelToInt
Map label strings to integers (needed for fortran)

classLower

protected ClassLower classLower
The object used to ClassType objects.

cNoPass

protected static final int cNoPass
An enumeration of the different passes made over types to generate types/declarations. We make two passes - a pass before the type name is generated and a pass after the type name is generated. In C, this is neccessary since the place where the name is placed depends upon the type.

Default value - means we aren't generating types.


cPreName

protected static final int cPreName
Generate type/declaration code before name

cPostName

protected static final int cPostName
Generate type/declaration code after name

typePass

protected int typePass
The current pass number for type declarations. We need to generate multiple passes for C types since C has prefix and postfix type declaration attributes (such as "*" (pointer), "[]" (array) ,"()" (function)

genInitialValue

protected boolean genInitialValue
Do we want to generate the initializer for a declaration?

inAggregationElements

protected boolean inAggregationElements
true if processing AggregationElements

genForwardDecl

protected boolean genForwardDecl
Generate a forward declaration or the complete function?

genFullProcedureType

protected boolean genFullProcedureType
Do we want the formals and exceptions wanted?

inTypeRef

protected boolean inTypeRef
A flag which indicates if we are generating an aggregate/enum defintion or reference (e.g., struct A {int a;}; vs. struct A). By default, we generate a type reference (inTypeRef == true). But, in declarations, we generate a type definition (inTypeRef == false).

myDecl

protected Declaration myDecl
The declaration associated with a type.

firstLabelNum

protected static final int firstLabelNum

labelPrefix

protected static java.lang.String labelPrefix

idPrefix

protected static java.lang.String idPrefix

includeFile1

protected static java.lang.String includeFile1

includeFile2

protected static java.lang.String includeFile2
Constructor Detail

Clef2C

public Clef2C(Emit em,
              SourceLanguage lang)
Construct a C language code generator - output goes to a file
Parameters:
em - is the Emit instance used to generate the C program.
lang - the source language
See Also:
Emit

Clef2C

protected Clef2C(Emit emit,
                 Keyword keywords,
                 SourceLanguage lang)
Construct a C language code generator - output goes to a file Either the Clef tree needs to be specified or the source language - but not both.
Parameters:
em - is the Emit instance used to generate the C program.
k - keywords for the language
lang - the source language
See Also:
Emit
Method Detail

fileExt

public java.lang.String fileExt()
Get the file name extension for the C language.
Returns:
the string file name extension for C - .c

codeGen

public final void codeGen(Node root)
Generate code for Clef tree
Parameters:
root - root node of the Clef tree

openParens

public void openParens(Expression expr)
Code to generate a parenthesis for an expression. We do not generate parenthesis for an expression if the parent node is a statement.
Parameters:
expr - the expression after the parenthesis

closeParens

public void closeParens(Expression expr)
Code to generate the closing parenthesis for an expression. We do not generate parenthesis for an expression if the parent node is a statement.
Parameters:
expr - the expression after the parenthesis

mapTypeToString

public java.lang.String mapTypeToString(Type t)
Map a type to a string. The string representation is based upon the size of the type or the symbolic value of the type. If a symbolic value is available use it, otherwise use the bit size.
Returns:
the string representation of the type

mapLabelToInt

protected int mapLabelToInt(java.lang.String label)
We maintain a mapping between labels and integer values for Fortran labels (i.e., for assign statements). The label index may be reset at procedure boundaries.

genDecls

protected void genDecls(SymtabScope scope)
Generate code for declarations. We obtain the declarations from the symbol table. We don't generate declarations for: The code in visitLabelDecl should be empty (so that we don't generate the declaration). We should never see a FieldDecl node - they always appear in the scope of the construct they are defined in (e.g., struct, class, etc..). We need to make an explicit check for EnumElementDecl.

labelName

protected java.lang.String labelName(java.lang.String n)
Create a unique label name - we prepend the label with "_L_" to ensure that label is legal for C/C++ and that it is unique. For example, fortran labels are numbers which is illegal in C.

identifierName

protected java.lang.String identifierName(IdReferenceOp id)
Create a unique identifier name given a IdReferenceOp node.
There is a special case when the name is a class member. We need to determine the object class to determine the relationship between the object class and the class that the member belongs too. Either the classes are the same or the class of the member is a super class of the object class. We represent the super class as a field in the derived class.
Parameters:
id - the IdReferenceOp node.

convertDeclName

public java.lang.String convertDeclName(Declaration decl,
                                        boolean address)
Convert the name of the declaration for display. If it is an EquivalenceDecl, create a reference to the base variable.
Parameters:
decl - is the Declaration
address - is true if an address form of the name is needed

genColMajorSubscript

protected void genColMajorSubscript(ArrayType arrayType,
                                    java.util.Enumeration sub)
Convert a column major array subscript to a row major array subscript. If the array is multidimensional, we have translated it to a single dimensional array. We then have to correct the subscript expression.
We try to generate output that closely matches the output from the EDG fortran compiler.
Parameters:
arrayType - the array type
dimensions - the subscript expressions

genFormals

protected void genFormals(ProcedureType s)
Generate code for a list of formal arguments.

genActuals

protected void genActuals(CallMethodOp m)
Generate code for the actual arguments. For a method call, we need to add code which passes the object as the first parameter.

genActuals

protected void genActuals(CallFunctionOp f)
Generate code for the actual arguments for a function call.
Parameters:
f - the clef node for a regular function call

genArgumentList

protected void genArgumentList(java.util.Enumeration argList,
                               ProcedureType s)
Generate code for the actuals arguments to a function. We check each actual against the formals to determine how the arguments are passed (eg., by reference or by value). If there are no formals at all then the signature parameter is null.
Parameters:
args - the list of arguments.
s - the signature of the function (maybe null)

genExceptionList

protected void genExceptionList(java.util.Enumeration args)
Generate code for exceptions. For C we don't generate anything.

genTypeReference

protected void genTypeReference(java.lang.String kind)
Generate the C code for a type reference. We use this routine for structs, unions, classes, and enums.
We do not emit the name of the type we are currently generating a type declaration (using TypeDecl or TypeName). That is the responsibility of genDeclarator.
Parameters:
kind - a string representing the C type (e.g., struct)
t - the Clef type node

genDeclarator

public void genDeclarator(Type t,
                          java.lang.String v)
Generate the C code for a declarator. This is difficult in C due to pointers, arrays, and function types. It takes two passes to generate the declarator - this routine is a wrapper which makes sure the two passes are made.
We generate type specifiers here as well. Except for pointers because the type specifier is placed after the "*" symbol.
On the first pass we traverse the type to find the simple type. On the way back up the clef tree representing the type, we generate pointer declarators. Then, we make another traversal of the type tree and generate arrays and functions.
The routine generates superfluous parens - many could be removed by making simple checks for precedence relations.
Parameters:
t - the clef type to generate in C
v - the name of the defined object

genDeclaratorFull

public void genDeclaratorFull(Type t,
                              java.lang.String v)

genStatements

protected void genStatements(Statement s)
Generate code for a list of statements. If there if just one statement then we surround the statement by braces {}. We do that in case we need to generate temporaries for the single statement (which means there will be multiple statements). If the statement if a BlockStmt node then the braces are generated in visitBlockStmt.
Parameters:
s - a Clef statement node

precedence

protected int precedence(Type t)
Return a precedence value for types. We assign precendence values to declarators that use operators (e.g., arrays, functions, pointers). The precendence values are relative to the other operators - larger values mean higher precedence.
Parameters:
t - the type of the declarator
Returns:
an integer representing the precendence value for the type relative to the other values.

visitDeclaration

public void visitDeclaration(Node n)
Specified by:
visitDeclaration in interface DeclPredicate
Overrides:
visitDeclaration in class AcceptPredicate

visitTypeDecl

public void visitTypeDecl(Node n)
Generate code for declaring a type. We assume that the name of the type declaration is generated by the type. That is, the type looks at the parent (the TypeDecl node) to determine the name. We need to do this because different types place names in different places.
Specified by:
visitTypeDecl in interface DeclPredicate
Overrides:
visitTypeDecl in class AcceptPredicate

genTypeDecl

public void genTypeDecl(TypeDecl td)

visitTypeName

public void visitTypeName(Node n)
Specified by:
visitTypeName in interface DeclPredicate
Overrides:
visitTypeName in class AcceptPredicate

visitValueDecl

public void visitValueDecl(Node n)
Generate C code for declarations (also known as declarators). Unfortunately, it gets a little tricky in C - there are basically 5 different types of declarators in C.
  1. Simple Declarator,
  2. (Declarator),
  3. Function Declarator,
  4. Array Declarator,
  5. Pointer Declarator
Specified by:
visitValueDecl in interface DeclPredicate
Overrides:
visitValueDecl in class AcceptPredicate

visitLabelDecl

public void visitLabelDecl(Node n)
Specified by:
visitLabelDecl in interface DeclPredicate
Overrides:
visitLabelDecl in class AcceptPredicate

visitVariableDecl

public void visitVariableDecl(Node n)
Specified by:
visitVariableDecl in interface DeclPredicate
Overrides:
visitVariableDecl in class AcceptPredicate

visitRenamedVariableDecl

public void visitRenamedVariableDecl(Node n)
Specified by:
visitRenamedVariableDecl in interface DeclPredicate
Overrides:
visitRenamedVariableDecl in class AcceptPredicate

visitEquivalenceDecl

public void visitEquivalenceDecl(Node n)
Generates the C code for Fortran EQUIVALENCE relations. The Equivalenced array is converted to a C pointer variable that is initialized to an address using the equivalence relationship.
Specified by:
visitEquivalenceDecl in interface DeclPredicate
Overrides:
visitEquivalenceDecl in class AcceptPredicate

visitFormalDecl

public void visitFormalDecl(Node n)
Generate code for formal declarations. In C, we do not generate the default expression, since it isn't legal (so we can't call visitValueDecl to generate the declaration). The default value is handled by the caller.
Specified by:
visitFormalDecl in interface DeclPredicate
Overrides:
visitFormalDecl in class AcceptPredicate
Parameters:
n - the FormalDecl node

visitUnknownFormals

public void visitUnknownFormals(Node n)
Specified by:
visitUnknownFormals in interface DeclPredicate
Overrides:
visitUnknownFormals in class AcceptPredicate

visitFieldDecl

public void visitFieldDecl(Node n)
Specified by:
visitFieldDecl in interface DeclPredicate
Overrides:
visitFieldDecl in class AcceptPredicate

visitConstantDecl

public void visitConstantDecl(Node n)
Specified by:
visitConstantDecl in interface DeclPredicate
Overrides:
visitConstantDecl in class AcceptPredicate

genRoutineAttributes

public void genRoutineAttributes(RoutineDecl p)

visitProcedureDecl

public void visitProcedureDecl(Node n)
Specified by:
visitProcedureDecl in interface DeclPredicate
Overrides:
visitProcedureDecl in class AcceptPredicate

genForwardRoutineDecl

public void genForwardRoutineDecl(RoutineDecl p)

visitMethodDecl

public void visitMethodDecl(Node n)
Specified by:
visitMethodDecl in interface DeclPredicate
Overrides:
visitMethodDecl in class AcceptPredicate

visitTypeConversionDecl

public void visitTypeConversionDecl(Node n)
A Type Conversion routine is a special case of a Method.
Specified by:
visitTypeConversionDecl in interface DeclPredicate
Overrides:
visitTypeConversionDecl in class AcceptPredicate

visitInitializer

public void visitInitializer(Node n)
Generate code for constructor initializers. Initializers are used for the base classes and members of a class. We assume that we are processing a ConstructorDecl and that we are currently generating code for the body of the constructor.
Specified by:
visitInitializer in interface DeclPredicate
Overrides:
visitInitializer in class AcceptPredicate

visitConstructorDecl

public void visitConstructorDecl(Node n)
Generate code for a constructor (modeled after C++ constructors). We have a couple of assumptions:
  1. Object allocation occurs prior to the constructor,
  2. We don't allow assignment to the this pointer,
  3. The FE has ordered the initalizers appropriately
The constructor-initializer list contains all the initializations that must be done for base classes and members (the order is defined by the FE). We generate extra code to perform the following tasks:
  1. If the class has virtual base classes, then we add another parameter to the constructor for each virtual base class.
  2. Call the constructor of each direct base class.
  3. Set the virtual function table pointer
  4. Generate the programmer defined statements
Specified by:
visitConstructorDecl in interface DeclPredicate
Overrides:
visitConstructorDecl in class AcceptPredicate
Parameters:
n - the ConstructorDecl Clef node

visitDestructorDecl

public void visitDestructorDecl(Node n)
Specified by:
visitDestructorDecl in interface DeclPredicate
Overrides:
visitDestructorDecl in class AcceptPredicate

visitForwardProcedureDecl

public void visitForwardProcedureDecl(Node n)
Specified by:
visitForwardProcedureDecl in interface DeclPredicate
Overrides:
visitForwardProcedureDecl in class AcceptPredicate

genIncludes

public static void genIncludes(SourceLanguage sl,
                               Emit emit)
Generate the include files needed for the generated C code.
Parameters:
sl - specifies the original source language
emit - is the Emit object ued to output the code

visitFileDecl

public void visitFileDecl(Node n)
Specified by:
visitFileDecl in interface DeclPredicate
Overrides:
visitFileDecl in class AcceptPredicate

visitEnumElementDecl

public void visitEnumElementDecl(Node n)
Specified by:
visitEnumElementDecl in interface DeclPredicate
Overrides:
visitEnumElementDecl in class AcceptPredicate

visitEntryDecl

public void visitEntryDecl(Node n)

visitType

public void visitType(Node n)
Specified by:
visitType in interface TypePredicate
Overrides:
visitType in class AcceptPredicate

visitVoidType

public void visitVoidType(Node n)
Specified by:
visitVoidType in interface TypePredicate
Overrides:
visitVoidType in class AcceptPredicate

visitRefType

public void visitRefType(Node n)
Generate code for a RefType. No type code is actually generated for a RefType node. Instead, the RefType node may contain attributes which we need to generate code for. The order that the attributes are generated depends upon the real type that the RefType contains.
Specified by:
visitRefType in interface TypePredicate
Overrides:
visitRefType in class AcceptPredicate

visitProcedureType

public void visitProcedureType(Node n)
Generate code for a procedure type.
Again, this is a two pass algorithm when the type is used in a declarator. On the first, pass we generate the return type. On the second pass, we generate a parameter list. The function name is generate in between.
Specified by:
visitProcedureType in interface TypePredicate
Overrides:
visitProcedureType in class AcceptPredicate
Parameters:
n - is the clef node for a ProcedureType

visitMethodType

public void visitMethodType(Node n)
Generate code for a method's signature.
Specified by:
visitMethodType in interface TypePredicate
Overrides:
visitMethodType in class AcceptPredicate

visitIncompleteType

public void visitIncompleteType(Node n)
Specified by:
visitIncompleteType in interface TypePredicate
Overrides:
visitIncompleteType in class AcceptPredicate

visitPointerType

public void visitPointerType(Node n)
Generate code for a pointer type. If type attributes are specified then they are placed after the pointer type (for all other types, the attributes are placed before). This enables us to generate the correct code both a constant pointer and a pointer to constant data which are defined as follows:
int * const const_pointer
const int *pointer_to_const; .
Note: we make multple passes over the type. The generated code depends upon which pass.
Specified by:
visitPointerType in interface TypePredicate
Overrides:
visitPointerType in class AcceptPredicate
Parameters:
n - the pointer type clef node

visitArrayType

public void visitArrayType(Node n)
A generic array. In most cases, we'll call one of the subclasses of array type (ie., fixed array, open array).
To generate code for arrays, we may need to make two passes. One the first pass, we generate the element type. On the second pass, we generate the array index expression. In between, we generate the name of the array.
Specified by:
visitArrayType in interface TypePredicate
Overrides:
visitArrayType in class AcceptPredicate
Parameters:
n - an Array Clef node

visitAggregateType

public void visitAggregateType(Node n)
Generate the C code for an aggregate type. Basically, just print out the fields. This routine should be called by a subclass (which includes RecordType, UnionType, and ClassType.

We assume that the aggregate head has already been generated via a call to genTypeNameProlog() and that the enclosing braces are generated. or ClassType.

Specified by:
visitAggregateType in interface TypePredicate
Overrides:
visitAggregateType in class AcceptPredicate
See Also:
RecordType, UnionType, ClassType

visitComplexType

public void visitComplexType(Node n)
Specified by:
visitComplexType in interface TypePredicate
Overrides:
visitComplexType in class AcceptPredicate

visitBound

public void visitBound(Node n)
Specified by:
visitBound in interface TypePredicate
Overrides:
visitBound in class AcceptPredicate

visitRangeType

public void visitRangeType(Node n)
Specified by:
visitRangeType in interface TypePredicate
Overrides:
visitRangeType in class AcceptPredicate

visitFixedArrayType

public void visitFixedArrayType(Node n)
Generate code for a fixed array (same as a regular array). To generate code for arrays, we may need to make two passes. One the first pass, we generate the element type. On the second pass, we generate the array index expression. In between, we generate the name of the array.
Specified by:
visitFixedArrayType in interface TypePredicate
Overrides:
visitFixedArrayType in class AcceptPredicate
Parameters:
n - a FixedArray Clef node

getClassLower

public ClassLower getClassLower()

visitClassType

public void visitClassType(Node n)
Generate C code for a class type. A class type is represented as a C struct type. The order of processing is :
  1. Emit external function definitions (before class definition)
  2. Emit definitions for static function (before class definition) We emit functions in two passes. First the prototype, then the body. But, the body is generated after the class since it may refererence fields in the class.
  3. Emit definitions for typedef statements (before class def.).
  4. Create the class as a struct
  5. Generate direct nonvirtual base classes at beginning of the structure.
  6. Generate the fields of the class
  7. Generate virtual function ptr. (if class has virtual functions)
  8. Generate pointers for virtual base classes. (if class has any VBCs)
  9. Generate space for virtual base classes.
  10. Create subobjects for class with virtual base classes.
Nonvirtual direct base class are represented as structs. We prepend the name with __b_.
Virtual base classes are represented as pointers to structs We prepend the name with __p_. The actual space for the virtual base class is a struct that appears at the end of the class definition. We prepend the name with __v_.

Note that if inTypeRef is true we just generate the name of the class.

Specified by:
visitClassType in interface TypePredicate
Overrides:
visitClassType in class AcceptPredicate
See Also:
visitAggregateType(scale.clef.Node)

visitRecordType

public void visitRecordType(Node n)
Generate C code for a record type.

Similar code is generated for records, unions, and classes.

Specified by:
visitRecordType in interface TypePredicate
Overrides:
visitRecordType in class AcceptPredicate
See Also:
visitAggregateType(scale.clef.Node)

visitFloatType

public void visitFloatType(Node n)
Specified by:
visitFloatType in interface TypePredicate
Overrides:
visitFloatType in class AcceptPredicate

visitIntegerType

public void visitIntegerType(Node n)
Specified by:
visitIntegerType in interface TypePredicate
Overrides:
visitIntegerType in class AcceptPredicate

visitEnumerationType

public void visitEnumerationType(Node n)
Specified by:
visitEnumerationType in interface TypePredicate
Overrides:
visitEnumerationType in class AcceptPredicate

visitUnionType

public void visitUnionType(Node n)
Specified by:
visitUnionType in interface TypePredicate
Overrides:
visitUnionType in class AcceptPredicate

visitCharacterType

public void visitCharacterType(Node n)
Specified by:
visitCharacterType in interface TypePredicate
Overrides:
visitCharacterType in class AcceptPredicate

visitBooleanType

public void visitBooleanType(Node n)
Specified by:
visitBooleanType in interface TypePredicate
Overrides:
visitBooleanType in class AcceptPredicate

visitBlockStmt

public void visitBlockStmt(Node n)
Generate code for a block of statements.
We emit braces around the block of statements and we generate declarations (if we generate C code) for all symbols declared in the block. Also, we advance the symbol table pointer to point to the current scope.
We have to compute the temporaries needed in the block and generate declarations for them here.
Specified by:
visitBlockStmt in interface StmtPredicate
Overrides:
visitBlockStmt in class AcceptPredicate

visitMultiBranchStmt

public void visitMultiBranchStmt(Node n)
Specified by:
visitMultiBranchStmt in interface StmtPredicate
Overrides:
visitMultiBranchStmt in class AcceptPredicate

visitIfThenElseStmt

public void visitIfThenElseStmt(Node n)
Generate code for a If-Then-Else statement. Should be straightforward, but, we need to be careful for nested Ifs. If the If-statement or Else-statement is another If then we need to generate brackets in order to avoid the dangling-else problem.
Specified by:
visitIfThenElseStmt in interface StmtPredicate
Overrides:
visitIfThenElseStmt in class AcceptPredicate

visitArithmeticIfStmt

public void visitArithmeticIfStmt(Node n)
Generate code for an arithmetic if statement (from Fortran 77). The code generated is:
   if (e == 0)
     goto L_Equal;
   else if (e < 0)
     goto L_Less; }
   else
     goto L_Greater;
 
Specified by:
visitArithmeticIfStmt in interface StmtPredicate
Overrides:
visitArithmeticIfStmt in class AcceptPredicate

visitComputedGotoStmt

public void visitComputedGotoStmt(Node n)
Specified by:
visitComputedGotoStmt in interface StmtPredicate
Overrides:
visitComputedGotoStmt in class AcceptPredicate

visitAssignLabelStmt

public void visitAssignLabelStmt(Node n)
Specified by:
visitAssignLabelStmt in interface StmtPredicate
Overrides:
visitAssignLabelStmt in class AcceptPredicate

visitAssignedGotoStmt

public void visitAssignedGotoStmt(Node n)
Specified by:
visitAssignedGotoStmt in interface StmtPredicate
Overrides:
visitAssignedGotoStmt in class AcceptPredicate

visitCaseStmt

public void visitCaseStmt(Node n)
Specified by:
visitCaseStmt in interface StmtPredicate
Overrides:
visitCaseStmt in class AcceptPredicate

visitSwitchStmt

public void visitSwitchStmt(Node n)
Specified by:
visitSwitchStmt in interface StmtPredicate
Overrides:
visitSwitchStmt in class AcceptPredicate

visitWhileLoopStmt

public void visitWhileLoopStmt(Node n)
Specified by:
visitWhileLoopStmt in interface StmtPredicate
Overrides:
visitWhileLoopStmt in class AcceptPredicate

visitRepeatWhileLoopStmt

public void visitRepeatWhileLoopStmt(Node n)
Specified by:
visitRepeatWhileLoopStmt in interface StmtPredicate
Overrides:
visitRepeatWhileLoopStmt in class AcceptPredicate

visitRepeatUntilLoopStmt

public void visitRepeatUntilLoopStmt(Node n)
Specified by:
visitRepeatUntilLoopStmt in interface StmtPredicate
Overrides:
visitRepeatUntilLoopStmt in class AcceptPredicate

visitDoLoopStmt

public void visitDoLoopStmt(Node n)
Specified by:
visitDoLoopStmt in interface StmtPredicate
Overrides:
visitDoLoopStmt in class AcceptPredicate

visitForLoopStmt

public void visitForLoopStmt(Node n)
Specified by:
visitForLoopStmt in interface StmtPredicate
Overrides:
visitForLoopStmt in class AcceptPredicate

visitBreakStmt

public void visitBreakStmt(Node n)
Specified by:
visitBreakStmt in interface StmtPredicate
Overrides:
visitBreakStmt in class AcceptPredicate

visitContinueStmt

public void visitContinueStmt(Node n)
Specified by:
visitContinueStmt in interface StmtPredicate
Overrides:
visitContinueStmt in class AcceptPredicate

visitGotoStmt

public void visitGotoStmt(Node n)
Specified by:
visitGotoStmt in interface StmtPredicate
Overrides:
visitGotoStmt in class AcceptPredicate

visitReturnStmt

public void visitReturnStmt(Node n)
Specified by:
visitReturnStmt in interface StmtPredicate
Overrides:
visitReturnStmt in class AcceptPredicate

visitExitStmt

public void visitExitStmt(Node n)
Specified by:
visitExitStmt in interface StmtPredicate
Overrides:
visitExitStmt in class AcceptPredicate

visitAlternateReturnStmt

public void visitAlternateReturnStmt(Node n)
Specified by:
visitAlternateReturnStmt in interface StmtPredicate
Overrides:
visitAlternateReturnStmt in class AcceptPredicate

visitEvalStmt

public void visitEvalStmt(Node n)
Specified by:
visitEvalStmt in interface StmtPredicate
Overrides:
visitEvalStmt in class AcceptPredicate

visitDeclStmt

public void visitDeclStmt(Node n)
Specified by:
visitDeclStmt in interface StmtPredicate
Overrides:
visitDeclStmt in class AcceptPredicate

visitNullStmt

public void visitNullStmt(Node n)
Specified by:
visitNullStmt in interface StmtPredicate
Overrides:
visitNullStmt in class AcceptPredicate

visitLabelStmt

public void visitLabelStmt(Node n)
Specified by:
visitLabelStmt in interface StmtPredicate
Overrides:
visitLabelStmt in class AcceptPredicate

visitExpression

public void visitExpression(Node n)
Specified by:
visitExpression in interface ExprPredicate
Overrides:
visitExpression in class AcceptPredicate

visitLiteral

public void visitLiteral(Node n)
Generate code for a literal. We need to ensure that the string does not have invalid C characters. We either convert invalid C characters to escape code or just ignore the chracter.
Specified by:
visitLiteral in interface ExprPredicate
Overrides:
visitLiteral in class AcceptPredicate
Parameters:
n - the literal node

visitStringLiteral

public void visitStringLiteral(Node n)
Specified by:
visitStringLiteral in interface ExprPredicate
Overrides:
visitStringLiteral in class AcceptPredicate

visitBooleanLiteral

public void visitBooleanLiteral(Node n)
Specified by:
visitBooleanLiteral in interface ExprPredicate
Overrides:
visitBooleanLiteral in class AcceptPredicate

visitCharLiteral

public void visitCharLiteral(Node n)
Specified by:
visitCharLiteral in interface ExprPredicate
Overrides:
visitCharLiteral in class AcceptPredicate

visitIntLiteral

public void visitIntLiteral(Node n)
Specified by:
visitIntLiteral in interface ExprPredicate
Overrides:
visitIntLiteral in class AcceptPredicate

visitIntArrayLiteral

public void visitIntArrayLiteral(Node n)
Specified by:
visitIntArrayLiteral in interface ExprPredicate
Overrides:
visitIntArrayLiteral in class AcceptPredicate

visitFloatLiteral

public void visitFloatLiteral(Node n)
Specified by:
visitFloatLiteral in interface ExprPredicate
Overrides:
visitFloatLiteral in class AcceptPredicate

visitFloatArrayLiteral

public void visitFloatArrayLiteral(Node n)
Specified by:
visitFloatArrayLiteral in interface ExprPredicate
Overrides:
visitFloatArrayLiteral in class AcceptPredicate

visitSizeofLiteral

public void visitSizeofLiteral(Node n)
Specified by:
visitSizeofLiteral in interface ExprPredicate
Overrides:
visitSizeofLiteral in class AcceptPredicate

visitAddressLiteral

public void visitAddressLiteral(Node n)
Specified by:
visitAddressLiteral in interface ExprPredicate
Overrides:
visitAddressLiteral in class AcceptPredicate

visitIdAddressOp

public void visitIdAddressOp(Node n)
Specified by:
visitIdAddressOp in interface ExprPredicate
Overrides:
visitIdAddressOp in class AcceptPredicate

visitIdValueOp

public void visitIdValueOp(Node n)
Specified by:
visitIdValueOp in interface ExprPredicate
Overrides:
visitIdValueOp in class AcceptPredicate

visitIdReferenceOp

public void visitIdReferenceOp(Node n)
Specified by:
visitIdReferenceOp in interface ExprPredicate
Overrides:
visitIdReferenceOp in class AcceptPredicate

visitSeriesOp

public void visitSeriesOp(Node n)
Specified by:
visitSeriesOp in interface ExprPredicate
Overrides:
visitSeriesOp in class AcceptPredicate

visitParenthesesOp

public void visitParenthesesOp(Node n)
Specified by:
visitParenthesesOp in interface ExprPredicate
Overrides:
visitParenthesesOp in class AcceptPredicate

visitAggregationElementOp

public void visitAggregationElementOp(Node n)
This node represents a single expression in the initializer. The parent, AggregationElements, is responsible for emitting the intializer in the code place (since a AggregationElementOp may represent a sequence of non-contiguous elements or may represent a specific element.
Specified by:
visitAggregationElementOp in interface ExprPredicate
Overrides:
visitAggregationElementOp in class AcceptPredicate

visitDefiniteAgElementOp

public void visitDefiniteAgElementOp(Node n)
This node represents a single expression in the initializer. The parent, AggregationElements, is responsible for emitting the intializer in the code place (since a AggregationElementOp may represent a sequence of non-contiguous elements or may represent a specific element.
Specified by:
visitDefiniteAgElementOp in interface ExprPredicate
Overrides:
visitDefiniteAgElementOp in class AcceptPredicate

visitIndefiniteAgElementOp

public void visitIndefiniteAgElementOp(Node n)
This node represents a single expression in the initializer. The parent, AggregationElements, is responsible for emitting the intializer in the code place (since a AggregationElementOp may represent a sequence of non-contiguous elements or may represent a specific element.
Specified by:
visitIndefiniteAgElementOp in interface ExprPredicate
Overrides:
visitIndefiniteAgElementOp in class AcceptPredicate

visitAggregationElements

public void visitAggregationElements(Node n)
Generate code for aggregate values. This routine is responsible for ordering the AggregationElements to occur for user-specified positions.
We use several stages to generate the C code.
  1. Copy the AggreationElementOp nodes to a Vector (we make a separate copy for each "bound" node). We record the low and high values for each one.
  2. Generate the code for each node in the Vector in order.
Specified by:
visitAggregationElements in interface ExprPredicate
Overrides:
visitAggregationElements in class AcceptPredicate

visitAssignSimpleOp

public void visitAssignSimpleOp(Node n)
Generate the C code for a regular assignment.
Specified by:
visitAssignSimpleOp in interface ExprPredicate
Overrides:
visitAssignSimpleOp in class AcceptPredicate

visitAssignComponentsOp

public void visitAssignComponentsOp(Node n)
Generate C code for assigning aggregates or arrays. In C, asssigning aggregates is simple - just use the normal assignment operator. But, assigning arrays is more difficult since C does not define assignment for array (i.e., an array assignment is just a pointer assignment). For array assignment, we need to generate code which copies the elements of the source array to the target array.
Specified by:
visitAssignComponentsOp in interface ExprPredicate
Overrides:
visitAssignComponentsOp in class AcceptPredicate

visitAssignFixedStringOp

public void visitAssignFixedStringOp(Node n)
Specified by:
visitAssignFixedStringOp in interface ExprPredicate
Overrides:
visitAssignFixedStringOp in class AcceptPredicate

visitPositiveOp

public void visitPositiveOp(Node n)
Specified by:
visitPositiveOp in interface ExprPredicate
Overrides:
visitPositiveOp in class AcceptPredicate

genIntrinsicOp

public void genIntrinsicOp(java.lang.String op,
                           Type t1,
                           Expression e1,
                           Type t2,
                           Expression e2)
Generate a call to a routine that is part of the Scale runtime library. This is used mainly for operations on complex values.

visitNegativeOp

public void visitNegativeOp(Node n)
Specified by:
visitNegativeOp in interface ExprPredicate
Overrides:
visitNegativeOp in class AcceptPredicate

visitTranscendentalOp

public void visitTranscendentalOp(Node n)
Specified by:
visitTranscendentalOp in interface ExprPredicate

visitTranscendental2Op

public void visitTranscendental2Op(Node n)
Specified by:
visitTranscendental2Op in interface ExprPredicate

visitAbsoluteValueOp

public void visitAbsoluteValueOp(Node n)
Specified by:
visitAbsoluteValueOp in interface ExprPredicate
Overrides:
visitAbsoluteValueOp in class AcceptPredicate

visitMinimumOp

public void visitMinimumOp(Node n)
Specified by:
visitMinimumOp in interface ExprPredicate
Overrides:
visitMinimumOp in class AcceptPredicate

visitMaximumOp

public void visitMaximumOp(Node n)
Specified by:
visitMaximumOp in interface ExprPredicate
Overrides:
visitMaximumOp in class AcceptPredicate

visitAdditionOp

public void visitAdditionOp(Node n)
Specified by:
visitAdditionOp in interface ExprPredicate
Overrides:
visitAdditionOp in class AcceptPredicate

visitSubtractionOp

public void visitSubtractionOp(Node n)
Specified by:
visitSubtractionOp in interface ExprPredicate
Overrides:
visitSubtractionOp in class AcceptPredicate

visitMultiplicationOp

public void visitMultiplicationOp(Node n)
Specified by:
visitMultiplicationOp in interface ExprPredicate
Overrides:
visitMultiplicationOp in class AcceptPredicate

visitDivisionOp

public void visitDivisionOp(Node n)
Specified by:
visitDivisionOp in interface ExprPredicate
Overrides:
visitDivisionOp in class AcceptPredicate

visitModulusOp

public void visitModulusOp(Node n)
Specified by:
visitModulusOp in interface ExprPredicate
Overrides:
visitModulusOp in class AcceptPredicate

visitRemainderOp

public void visitRemainderOp(Node n)
Specified by:
visitRemainderOp in interface ExprPredicate
Overrides:
visitRemainderOp in class AcceptPredicate

visitExponentiationOp

public void visitExponentiationOp(Node n)
Specified by:
visitExponentiationOp in interface ExprPredicate
Overrides:
visitExponentiationOp in class AcceptPredicate

visitPreDecrementOp

public void visitPreDecrementOp(Node n)
Specified by:
visitPreDecrementOp in interface ExprPredicate
Overrides:
visitPreDecrementOp in class AcceptPredicate

visitPreIncrementOp

public void visitPreIncrementOp(Node n)
Specified by:
visitPreIncrementOp in interface ExprPredicate
Overrides:
visitPreIncrementOp in class AcceptPredicate

visitPostDecrementOp

public void visitPostDecrementOp(Node n)
Specified by:
visitPostDecrementOp in interface ExprPredicate
Overrides:
visitPostDecrementOp in class AcceptPredicate

visitPostIncrementOp

public void visitPostIncrementOp(Node n)
Specified by:
visitPostIncrementOp in interface ExprPredicate
Overrides:
visitPostIncrementOp in class AcceptPredicate

visitEqualityOp

public void visitEqualityOp(Node n)
Specified by:
visitEqualityOp in interface ExprPredicate
Overrides:
visitEqualityOp in class AcceptPredicate

visitNotEqualOp

public void visitNotEqualOp(Node n)
Specified by:
visitNotEqualOp in interface ExprPredicate
Overrides:
visitNotEqualOp in class AcceptPredicate

visitGreaterOp

public void visitGreaterOp(Node n)
Specified by:
visitGreaterOp in interface ExprPredicate
Overrides:
visitGreaterOp in class AcceptPredicate

visitGreaterEqualOp

public void visitGreaterEqualOp(Node n)
Specified by:
visitGreaterEqualOp in interface ExprPredicate
Overrides:
visitGreaterEqualOp in class AcceptPredicate

visitLessOp

public void visitLessOp(Node n)
Specified by:
visitLessOp in interface ExprPredicate
Overrides:
visitLessOp in class AcceptPredicate

visitLessEqualOp

public void visitLessEqualOp(Node n)
Specified by:
visitLessEqualOp in interface ExprPredicate
Overrides:
visitLessEqualOp in class AcceptPredicate

visitBitComplementOp

public void visitBitComplementOp(Node n)
Specified by:
visitBitComplementOp in interface ExprPredicate
Overrides:
visitBitComplementOp in class AcceptPredicate

visitBitAndOp

public void visitBitAndOp(Node n)
Specified by:
visitBitAndOp in interface ExprPredicate
Overrides:
visitBitAndOp in class AcceptPredicate

visitBitXorOp

public void visitBitXorOp(Node n)
Specified by:
visitBitXorOp in interface ExprPredicate
Overrides:
visitBitXorOp in class AcceptPredicate

visitBitOrOp

public void visitBitOrOp(Node n)
Specified by:
visitBitOrOp in interface ExprPredicate
Overrides:
visitBitOrOp in class AcceptPredicate

visitBitShiftOp

public void visitBitShiftOp(Node n)
Specified by:
visitBitShiftOp in interface ExprPredicate
Overrides:
visitBitShiftOp in class AcceptPredicate

visitMultiplicationAssignmentOp

public void visitMultiplicationAssignmentOp(Node n)
Specified by:
visitMultiplicationAssignmentOp in interface ExprPredicate
Overrides:
visitMultiplicationAssignmentOp in class AcceptPredicate

visitDivisionAssignmentOp

public void visitDivisionAssignmentOp(Node n)
Specified by:
visitDivisionAssignmentOp in interface ExprPredicate
Overrides:
visitDivisionAssignmentOp in class AcceptPredicate

visitRemainderAssignmentOp

public void visitRemainderAssignmentOp(Node n)
Specified by:
visitRemainderAssignmentOp in interface ExprPredicate
Overrides:
visitRemainderAssignmentOp in class AcceptPredicate

visitAdditionAssignmentOp

public void visitAdditionAssignmentOp(Node n)
Specified by:
visitAdditionAssignmentOp in interface ExprPredicate
Overrides:
visitAdditionAssignmentOp in class AcceptPredicate

visitSubtractionAssignmentOp

public void visitSubtractionAssignmentOp(Node n)
Specified by:
visitSubtractionAssignmentOp in interface ExprPredicate
Overrides:
visitSubtractionAssignmentOp in class AcceptPredicate

visitBitShiftAssignmentOp

public void visitBitShiftAssignmentOp(Node n)
Specified by:
visitBitShiftAssignmentOp in interface ExprPredicate
Overrides:
visitBitShiftAssignmentOp in class AcceptPredicate

visitBitAndAssignmentOp

public void visitBitAndAssignmentOp(Node n)
Specified by:
visitBitAndAssignmentOp in interface ExprPredicate
Overrides:
visitBitAndAssignmentOp in class AcceptPredicate

visitBitXorAssignmentOp

public void visitBitXorAssignmentOp(Node n)
Specified by:
visitBitXorAssignmentOp in interface ExprPredicate
Overrides:
visitBitXorAssignmentOp in class AcceptPredicate

visitBitOrAssignmentOp

public void visitBitOrAssignmentOp(Node n)
Specified by:
visitBitOrAssignmentOp in interface ExprPredicate
Overrides:
visitBitOrAssignmentOp in class AcceptPredicate

visitNotOp

public void visitNotOp(Node n)
Specified by:
visitNotOp in interface ExprPredicate
Overrides:
visitNotOp in class AcceptPredicate

visitAndOp

public void visitAndOp(Node n)
Specified by:
visitAndOp in interface ExprPredicate
Overrides:
visitAndOp in class AcceptPredicate

visitOrOp

public void visitOrOp(Node n)
Specified by:
visitOrOp in interface ExprPredicate
Overrides:
visitOrOp in class AcceptPredicate

visitAndConditionalOp

public void visitAndConditionalOp(Node n)
Specified by:
visitAndConditionalOp in interface ExprPredicate
Overrides:
visitAndConditionalOp in class AcceptPredicate

visitOrConditionalOp

public void visitOrConditionalOp(Node n)
Specified by:
visitOrConditionalOp in interface ExprPredicate
Overrides:
visitOrConditionalOp in class AcceptPredicate

visitExpressionIfOp

public void visitExpressionIfOp(Node n)
Specified by:
visitExpressionIfOp in interface ExprPredicate
Overrides:
visitExpressionIfOp in class AcceptPredicate

visitAddressOp

public void visitAddressOp(Node n)
Specified by:
visitAddressOp in interface ExprPredicate
Overrides:
visitAddressOp in class AcceptPredicate

visitDereferenceOp

public void visitDereferenceOp(Node n)
Specified by:
visitDereferenceOp in interface ExprPredicate
Overrides:
visitDereferenceOp in class AcceptPredicate

visitNilOp

public void visitNilOp(Node n)
Specified by:
visitNilOp in interface ExprPredicate
Overrides:
visitNilOp in class AcceptPredicate

visitThisOp

public void visitThisOp(Node n)
Specified by:
visitThisOp in interface ExprPredicate
Overrides:
visitThisOp in class AcceptPredicate

visitSelectOp

public void visitSelectOp(Node n)
Specified by:
visitSelectOp in interface ExprPredicate
Overrides:
visitSelectOp in class AcceptPredicate

visitSelectIndirectOp

public void visitSelectIndirectOp(Node n)
Specified by:
visitSelectIndirectOp in interface ExprPredicate
Overrides:
visitSelectIndirectOp in class AcceptPredicate

visitSubscriptValueOp

public void visitSubscriptValueOp(Node n)
Specified by:
visitSubscriptValueOp in interface ExprPredicate
Overrides:
visitSubscriptValueOp in class AcceptPredicate

visitSubscriptAddressOp

public void visitSubscriptAddressOp(Node n)
Specified by:
visitSubscriptAddressOp in interface ExprPredicate
Overrides:
visitSubscriptAddressOp in class AcceptPredicate

visitSubscriptOp

public void visitSubscriptOp(Node n)
Specified by:
visitSubscriptOp in interface ExprPredicate
Overrides:
visitSubscriptOp in class AcceptPredicate

visitArrayRelOp

public void visitArrayRelOp(Node n)
Specified by:
visitArrayRelOp in interface ExprPredicate
Overrides:
visitArrayRelOp in class AcceptPredicate

visitArrayEqualityOp

public void visitArrayEqualityOp(Node n)
Specified by:
visitArrayEqualityOp in interface ExprPredicate
Overrides:
visitArrayEqualityOp in class AcceptPredicate

visitArrayInequalityOp

public void visitArrayInequalityOp(Node n)
Specified by:
visitArrayInequalityOp in interface ExprPredicate
Overrides:
visitArrayInequalityOp in class AcceptPredicate

visitArrayGreaterOp

public void visitArrayGreaterOp(Node n)
Specified by:
visitArrayGreaterOp in interface ExprPredicate
Overrides:
visitArrayGreaterOp in class AcceptPredicate

visitArrayGreaterEqualOp

public void visitArrayGreaterEqualOp(Node n)
Specified by:
visitArrayGreaterEqualOp in interface ExprPredicate
Overrides:
visitArrayGreaterEqualOp in class AcceptPredicate

visitArrayLessOp

public void visitArrayLessOp(Node n)
Specified by:
visitArrayLessOp in interface ExprPredicate
Overrides:
visitArrayLessOp in class AcceptPredicate

visitArrayLessEqualOp

public void visitArrayLessEqualOp(Node n)
Specified by:
visitArrayLessEqualOp in interface ExprPredicate
Overrides:
visitArrayLessEqualOp in class AcceptPredicate

visitConcatenationOp

public void visitConcatenationOp(Node n)
Specified by:
visitConcatenationOp in interface ExprPredicate
Overrides:
visitConcatenationOp in class AcceptPredicate

visitArgument

public void visitArgument(Node n)
Specified by:
visitArgument in interface ExprPredicate
Overrides:
visitArgument in class AcceptPredicate

visitPositionalArgumentOp

public void visitPositionalArgumentOp(Node n)
Generate code for an actual argument. The PositionalArgumentOp is really just an operator to hold an expression.
Specified by:
visitPositionalArgumentOp in interface ExprPredicate
Overrides:
visitPositionalArgumentOp in class AcceptPredicate

visitCallFunctionOp

public void visitCallFunctionOp(Node n)
Specified by:
visitCallFunctionOp in interface ExprPredicate
Overrides:
visitCallFunctionOp in class AcceptPredicate

visitCallMethodOp

public void visitCallMethodOp(Node n)
Generate code for a call to a method. A method may be a virtual function call - in this case we must call via the virtual table function pointer.
Specified by:
visitCallMethodOp in interface ExprPredicate
Overrides:
visitCallMethodOp in class AcceptPredicate
See Also:
ClassLower

visitAllocateOp

public void visitAllocateOp(Node n)
Allocate an object (when the allocation occurs implicitly). An allocation expression must do three things (at least in C++):
  1. Find storage for the object to be create,
  2. Initialize that object
  3. Return a suitably typed pointer to the object
    Specified by:
    visitAllocateOp in interface ExprPredicate
    Overrides:
    visitAllocateOp in class AcceptPredicate
    Parameters:
    n - the Clef AllocateOp node

visitTypeConversionOp

public void visitTypeConversionOp(Node n)
Implement the conversion operator. The code generated for the conversion depends upon the type of conversion.
We do not generate code for cast conversions to AggregateTypes since these are illegal in C. For an ArrayType, we generate a cast to a pointer to the array's element type (we should only see this at function calls)
Specified by:
visitTypeConversionOp in interface ExprPredicate
Overrides:
visitTypeConversionOp in class AcceptPredicate

visitTypeConversion2Op

public void visitTypeConversion2Op(Node n)
Implement the conversion operator. The code generated for the conversion depends upon the type of conversion.
We do not generate code for cast conversions to AggregateTypes since these are illegal in C. For an ArrayType, we generate a cast to a pointer to the array's element type (we should only see this at function calls)
Specified by:
visitTypeConversion2Op in interface ExprPredicate
Overrides:
visitTypeConversion2Op in class AcceptPredicate
Throws:
InternalError - for errors

visitVaStartOp

public void visitVaStartOp(Node n)
Generate the C construct for the va_start(va_list, parmN) construct.
Specified by:
visitVaStartOp in interface ExprPredicate
Overrides:
visitVaStartOp in class AcceptPredicate

visitVaArgOp

public void visitVaArgOp(Node n)
Generate the C construct for the va_arg(va_list, type) construct.
Specified by:
visitVaArgOp in interface ExprPredicate
Overrides:
visitVaArgOp in class AcceptPredicate

visitVaEndOp

public void visitVaEndOp(Node n)
Generate the C construct for the va_end(va_list) construct.
Specified by:
visitVaEndOp in interface ExprPredicate
Overrides:
visitVaEndOp in class AcceptPredicate