scale.clef
Class Clef2C

java.lang.Object
  extended by scale.clef.Clef2C
All Implemented Interfaces:
DeclPredicate, ExprPredicate, Predicate, StmtPredicate, TypePredicate

public final class Clef2C
extends java.lang.Object
implements Predicate

A class to generate C code from a Clef AST.

$Id: Clef2C.java,v 1.4 2007-10-04 19:58:02 burrill Exp $

Copyright 2008 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

Constructor Summary
Clef2C(Emit emit, SourceLanguage lang)
          Construct a C language code generator - output goes to a file.
 
Method Summary
 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()
          Return the string file name extension for C - .c.
 void genCastType(Type t)
          Generate the type for a cast.
 void genDeclarator(Type t, java.lang.String v)
          Generate the C code for a declarator.
 void genDeclaratorFull(Type t, java.lang.String v)
          Generate the C code for a declarator.
 void genForwardRoutineDecl(RoutineDecl p)
          Generate the declaration for a routine that will be fully defined later.
 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)
          Generate the attributes (e.g., static) for a function.
 void genTypeDecl(TypeDecl td)
          Generate the C code for a TypeDecl.
static char simpleTypeName(java.lang.String name)
           
 void visitAbsoluteValueOp(AbsoluteValueOp expr)
           
 void visitAdditionAssignmentOp(AdditionAssignmentOp a)
           
 void visitAdditionOp(AdditionOp expr)
           
 void visitAddressLiteral(AddressLiteral sl)
           
 void visitAddressOp(AddressOp expr)
           
 void visitAggregateOp(AggregateOp d)
           
 void visitAggregateType(AggregateType agg)
          Generate the C code for an aggregate type.
 void visitAggregationElements(AggregationElements agg)
          Generate code for aggregate values.
 void visitAllocArrayType(AllocArrayType n)
          Generate code for a n allocatable array.
 void visitAllocatePlacementOp(AllocatePlacementOp d)
           
 void visitAllocateSettingFieldsOp(AllocateSettingFieldsOp d)
           
 void visitAltCase(AltCase d)
           
 void visitAndConditionalOp(AndConditionalOp expr)
           
 void visitAndOp(AndOp expr)
           
 void visitArithmeticIfStmt(ArithmeticIfStmt stmt)
          Generate code for an arithmetic if statement (from Fortran 77).
 void visitArrayType(ArrayType at)
          A generic array.
 void visitAssignedGotoStmt(AssignedGotoStmt n)
           
 void visitAssignLabelStmt(AssignLabelStmt s)
           
 void visitAssignmentOp(AssignmentOp d)
           
 void visitAssignSimpleOp(AssignSimpleOp a)
          Generate the C code for a regular assignment.
 void visitAtomicType(AtomicType d)
           
 void visitBitAndAssignmentOp(BitAndAssignmentOp a)
           
 void visitBitAndOp(BitAndOp expr)
           
 void visitBitComplementOp(BitComplementOp expr)
           
 void visitBitOrAssignmentOp(BitOrAssignmentOp a)
           
 void visitBitOrOp(BitOrOp expr)
           
 void visitBitShiftAssignmentOp(BitShiftAssignmentOp a)
           
 void visitBitShiftOp(BitShiftOp expr)
           
 void visitBitXorAssignmentOp(BitXorAssignmentOp a)
           
 void visitBitXorOp(BitXorOp expr)
           
 void visitBlockStmt(BlockStmt stmt)
          Generate code for a block of statements.
 void visitBooleanLiteral(BooleanLiteral n)
           
 void visitBooleanType(BooleanType n)
           
 void visitBound(Bound b)
           
 void visitBreakStmt(BreakStmt n)
           
 void visitCallFunctionOp(CallFunctionOp fun)
           
 void visitCallOp(CallOp d)
           
 void visitCaseLabelDecl(CaseLabelDecl d)
           
 void visitCaseStmt(CaseStmt stmt)
           
 void visitCharacterType(CharacterType ct)
           
 void visitCharLiteral(CharLiteral n)
           
 void visitComplexLiteral(ComplexLiteral n)
           
 void visitComplexOp(ComplexOp t)
          Generate C code to create a complex value.
 void visitComplexType(ComplexType type)
           
 void visitCompositeType(CompositeType d)
           
 void visitCompoundAssignmentOp(CompoundAssignmentOp d)
           
 void visitComputedGotoStmt(ComputedGotoStmt n)
           
 void visitContinueStmt(ContinueStmt n)
           
 void visitDeclaration(Declaration n)
           
 void visitDeclStmt(DeclStmt n)
           
 void visitDefOp(DefOp expr)
           
 void visitDeleteArrayOp(DeleteArrayOp d)
           
 void visitDeleteOp(DeleteOp d)
           
 void visitDereferenceOp(DereferenceOp expr)
           
 void visitDivisionAssignmentOp(DivisionAssignmentOp expr)
           
 void visitDivisionOp(DivisionOp expr)
           
 void visitDoLoopStmt(DoLoopStmt stmt)
           
 void visitDyadicOp(DyadicOp d)
           
 void visitEnumElementDecl(EnumElementDecl d)
           
 void visitEnumerationType(EnumerationType et)
           
 void visitEqualityOp(EqualityOp expr)
           
 void visitEquivalenceDecl(EquivalenceDecl ed)
          Generates the C code for Fortran EQUIVALENCE relations.
 void visitEvalStmt(EvalStmt n)
           
 void visitExceptionDecl(ExceptionDecl d)
           
 void visitExitStmt(ExitStmt n)
           
 void visitExponentiationOp(ExponentiationOp expr)
           
 void visitExpression(Expression n)
           
 void visitExpressionIfOp(ExpressionIfOp expr)
           
 void visitFieldDecl(FieldDecl fd)
           
 void visitFileDecl(FileDecl n)
           
 void visitFixedArrayType(FixedArrayType n)
          Generate code for a fixed array (same as a regular array).
 void visitFloatArrayLiteral(FloatArrayLiteral l)
           
 void visitFloatLiteral(FloatLiteral n)
           
 void visitFloatType(FloatType type)
           
 void visitForLoopStmt(ForLoopStmt stmt)
           
 void visitFormalDecl(FormalDecl fd)
          Generate code for formal declarations.
 void visitFortranCharType(FortranCharType type)
           
 void visitForwardProcedureDecl(ForwardProcedureDecl n)
           
 void visitGotoStmt(GotoStmt n)
           
 void visitGreaterEqualOp(GreaterEqualOp expr)
           
 void visitGreaterOp(GreaterOp expr)
           
 void visitHeapOp(HeapOp d)
           
 void visitIdAddressOp(IdAddressOp id)
           
 void visitIdReferenceOp(IdReferenceOp id)
           
 void visitIdValueOp(IdValueOp id)
           
 void visitIfStmt(IfStmt d)
           
 void visitIfThenElseStmt(IfThenElseStmt ifstmt)
          Generate code for a If-Then-Else statement.
 void visitIncompleteType(IncompleteType n)
           
 void visitIncrementOp(IncrementOp d)
           
 void visitIntArrayLiteral(IntArrayLiteral l)
           
 void visitIntegerType(IntegerType type)
           
 void visitIntLiteral(IntLiteral n)
           
 void visitLabelDecl(LabelDecl n)
           
 void visitLabelStmt(LabelStmt s)
           
 void visitLessEqualOp(LessEqualOp expr)
           
 void visitLessOp(LessOp expr)
           
 void visitLiteral(Literal l)
          Generate code for a literal.
 void visitLoopStmt(LoopStmt d)
           
 void visitMaximumOp(MaximumOp expr)
           
 void visitMinimumOp(MinimumOp expr)
           
 void visitModulusOp(ModulusOp expr)
           
 void visitMonadicOp(MonadicOp d)
           
 void visitMultiBranchStmt(MultiBranchStmt s)
           
 void visitMultiplicationAssignmentOp(MultiplicationAssignmentOp expr)
           
 void visitMultiplicationOp(MultiplicationOp expr)
           
 void visitNegativeOp(NegativeOp expr)
           
 void visitNilOp(NilOp n)
           
 void visitNode(Node n)
           
 void visitNotEqualOp(NotEqualOp expr)
           
 void visitNotOp(NotOp expr)
           
 void visitNullStmt(NullStmt n)
           
 void visitNumericType(NumericType d)
           
 void visitOrConditionalOp(OrConditionalOp expr)
           
 void visitOrOp(OrOp expr)
           
 void visitParenthesesOp(ParenthesesOp expr)
           
 void visitPointerType(PointerType p)
          Generate code for a pointer type.
 void visitPositiveOp(PositiveOp expr)
           
 void visitPostDecrementOp(PostDecrementOp expr)
           
 void visitPostIncrementOp(PostIncrementOp expr)
           
 void visitPreDecrementOp(PreDecrementOp expr)
           
 void visitPreIncrementOp(PreIncrementOp expr)
           
 void visitProcedureDecl(ProcedureDecl p)
           
 void visitProcedureType(ProcedureType p)
          Generate code for a procedure type.
 void visitRaise(Raise d)
           
 void visitRaiseWithObject(RaiseWithObject d)
           
 void visitRaiseWithType(RaiseWithType d)
           
 void visitRealType(RealType d)
           
 void visitRecordType(RecordType rt)
          Generate C code for a record type.
 void visitRefType(RefType ref)
          Generate code for a RefType.
 void visitRemainderAssignmentOp(RemainderAssignmentOp expr)
           
 void visitRemainderOp(RemainderOp expr)
           
 void visitRenamedVariableDecl(RenamedVariableDecl n)
           
 void visitRepeatUntilLoopStmt(RepeatUntilLoopStmt stmt)
           
 void visitRepeatWhileLoopStmt(RepeatWhileLoopStmt stmt)
           
 void visitReturnStmt(ReturnStmt n)
           
 void visitRoutineDecl(RoutineDecl d)
           
 void visitSelectIndirectOp(SelectIndirectOp expr)
           
 void visitSelectOp(SelectOp expr)
           
 void visitSeriesOp(SeriesOp expr)
           
 void visitSignedIntegerType(SignedIntegerType type)
           
 void visitSizeofLiteral(SizeofLiteral sl)
           
 void visitStatement(Statement d)
           
 void visitStatementOp(StatementOp so)
          Generate the C construct for the Gnu abomination called a "statement expression".
 void visitStringLiteral(StringLiteral n)
           
 void visitSubscriptAddressOp(SubscriptAddressOp n)
           
 void visitSubscriptOp(SubscriptOp expr)
           
 void visitSubscriptValueOp(SubscriptValueOp n)
           
 void visitSubstringOp(SubstringOp d)
           
 void visitSubtractionAssignmentOp(SubtractionAssignmentOp a)
           
 void visitSubtractionOp(SubtractionOp expr)
           
 void visitSwitchStmt(SwitchStmt stmt)
           
 void visitTernaryOp(TernaryOp d)
           
 void visitTestLoopStmt(TestLoopStmt d)
           
 void visitThisOp(ThisOp n)
           
 void visitTranscendental2Op(Transcendental2Op expr)
           
 void visitTranscendentalOp(TranscendentalOp expr)
           
 void visitType(Type n)
           
 void visitTypeConversionOp(TypeConversionOp t)
          Implement the conversion operator.
 void visitTypeDecl(TypeDecl td)
          Generate code for declaring a type.
 void visitTypeName(TypeName tn)
           
 void visitUnionType(UnionType ut)
           
 void visitUnknownFormals(UnknownFormals n)
           
 void visitUnsignedIntegerType(UnsignedIntegerType type)
           
 void visitVaArgOp(VaArgOp va)
          Generate the C construct for the va_arg(va_list, type) construct.
 void visitVaCopyOp(VaCopyOp vac)
           
 void visitVaEndOp(VaEndOp vae)
          Generate the C construct for the va_end(va_list) construct.
 void visitValueDecl(ValueDecl v)
           
 void visitVarArgOp(VarArgOp d)
           
 void visitVariableDecl(VariableDecl d)
           
 void visitVaStartOp(VaStartOp vas)
          Generate the C construct for the va_start(va_list, parmN) construct.
 void visitVoidType(VoidType n)
           
 void visitWhileLoopStmt(WhileLoopStmt stmt)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Clef2C

public Clef2C(Emit emit,
              SourceLanguage lang)
Construct a C language code generator - output goes to a file.

Parameters:
emit - is the Emit instance used to generate the C program.
lang - the source language
See Also:
Emit
Method Detail

fileExt

public java.lang.String fileExt()
Return 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

genCastType

public void genCastType(Type t)
Generate the type for a cast. Special rules apply to this case to avoid ambiguity when programs write crap like
 Person *Person = (Person *) 0;
 


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

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)
Generate the C code for a declarator. This differs from genDeclarator in that the full procedure declaration is generated.


visitNode

public void visitNode(Node n)
Specified by:
visitNode in interface Predicate

visitExceptionDecl

public void visitExceptionDecl(ExceptionDecl d)
Specified by:
visitExceptionDecl in interface DeclPredicate

visitCaseLabelDecl

public void visitCaseLabelDecl(CaseLabelDecl d)
Specified by:
visitCaseLabelDecl in interface DeclPredicate

visitDeclaration

public void visitDeclaration(Declaration n)
Specified by:
visitDeclaration in interface DeclPredicate

visitRoutineDecl

public void visitRoutineDecl(RoutineDecl d)
Specified by:
visitRoutineDecl in interface DeclPredicate

visitRealType

public void visitRealType(RealType d)
Specified by:
visitRealType in interface TypePredicate

visitRaiseWithType

public void visitRaiseWithType(RaiseWithType d)
Specified by:
visitRaiseWithType in interface TypePredicate

visitRaiseWithObject

public void visitRaiseWithObject(RaiseWithObject d)
Specified by:
visitRaiseWithObject in interface TypePredicate

visitRaise

public void visitRaise(Raise d)
Specified by:
visitRaise in interface TypePredicate

visitNumericType

public void visitNumericType(NumericType d)
Specified by:
visitNumericType in interface TypePredicate

visitCompositeType

public void visitCompositeType(CompositeType d)
Specified by:
visitCompositeType in interface TypePredicate

visitAtomicType

public void visitAtomicType(AtomicType d)
Specified by:
visitAtomicType in interface TypePredicate

visitAltCase

public void visitAltCase(AltCase d)
Specified by:
visitAltCase in interface StmtPredicate

visitIfStmt

public void visitIfStmt(IfStmt d)
Specified by:
visitIfStmt in interface StmtPredicate

visitTestLoopStmt

public void visitTestLoopStmt(TestLoopStmt d)
Specified by:
visitTestLoopStmt in interface StmtPredicate

visitLoopStmt

public void visitLoopStmt(LoopStmt d)
Specified by:
visitLoopStmt in interface StmtPredicate

visitStatement

public void visitStatement(Statement d)
Specified by:
visitStatement in interface StmtPredicate

visitVarArgOp

public void visitVarArgOp(VarArgOp d)
Specified by:
visitVarArgOp in interface ExprPredicate

visitTernaryOp

public void visitTernaryOp(TernaryOp d)
Specified by:
visitTernaryOp in interface ExprPredicate

visitSubstringOp

public void visitSubstringOp(SubstringOp d)
Specified by:
visitSubstringOp in interface ExprPredicate

visitIncrementOp

public void visitIncrementOp(IncrementOp d)
Specified by:
visitIncrementOp in interface ExprPredicate

visitHeapOp

public void visitHeapOp(HeapOp d)
Specified by:
visitHeapOp in interface ExprPredicate

visitDyadicOp

public void visitDyadicOp(DyadicOp d)
Specified by:
visitDyadicOp in interface ExprPredicate

visitDeleteOp

public void visitDeleteOp(DeleteOp d)
Specified by:
visitDeleteOp in interface ExprPredicate

visitDeleteArrayOp

public void visitDeleteArrayOp(DeleteArrayOp d)
Specified by:
visitDeleteArrayOp in interface ExprPredicate

visitCompoundAssignmentOp

public void visitCompoundAssignmentOp(CompoundAssignmentOp d)
Specified by:
visitCompoundAssignmentOp in interface ExprPredicate

visitCallOp

public void visitCallOp(CallOp d)
Specified by:
visitCallOp in interface ExprPredicate

visitAssignmentOp

public void visitAssignmentOp(AssignmentOp d)
Specified by:
visitAssignmentOp in interface ExprPredicate

visitMonadicOp

public void visitMonadicOp(MonadicOp d)
Specified by:
visitMonadicOp in interface ExprPredicate

visitAllocateSettingFieldsOp

public void visitAllocateSettingFieldsOp(AllocateSettingFieldsOp d)
Specified by:
visitAllocateSettingFieldsOp in interface ExprPredicate

visitAllocatePlacementOp

public void visitAllocatePlacementOp(AllocatePlacementOp d)
Specified by:
visitAllocatePlacementOp in interface ExprPredicate

visitAggregateOp

public void visitAggregateOp(AggregateOp d)
Specified by:
visitAggregateOp in interface ExprPredicate

visitTypeDecl

public void visitTypeDecl(TypeDecl td)
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

genTypeDecl

public void genTypeDecl(TypeDecl td)
Generate the C code for a TypeDecl.


visitTypeName

public void visitTypeName(TypeName tn)
Specified by:
visitTypeName in interface DeclPredicate

visitValueDecl

public void visitValueDecl(ValueDecl v)
Specified by:
visitValueDecl in interface DeclPredicate

visitLabelDecl

public void visitLabelDecl(LabelDecl n)
Specified by:
visitLabelDecl in interface DeclPredicate

visitVariableDecl

public void visitVariableDecl(VariableDecl d)
Specified by:
visitVariableDecl in interface DeclPredicate

visitRenamedVariableDecl

public void visitRenamedVariableDecl(RenamedVariableDecl n)
Specified by:
visitRenamedVariableDecl in interface DeclPredicate

visitEquivalenceDecl

public void visitEquivalenceDecl(EquivalenceDecl ed)
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

visitFormalDecl

public void visitFormalDecl(FormalDecl fd)
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
Parameters:
fd - the FormalDecl node

visitUnknownFormals

public void visitUnknownFormals(UnknownFormals n)
Specified by:
visitUnknownFormals in interface DeclPredicate

visitFieldDecl

public void visitFieldDecl(FieldDecl fd)
Specified by:
visitFieldDecl in interface DeclPredicate

genRoutineAttributes

public void genRoutineAttributes(RoutineDecl p)
Generate the attributes (e.g., static) for a function.


visitProcedureDecl

public void visitProcedureDecl(ProcedureDecl p)
Specified by:
visitProcedureDecl in interface DeclPredicate

genForwardRoutineDecl

public void genForwardRoutineDecl(RoutineDecl p)
Generate the declaration for a routine that will be fully defined later.


visitForwardProcedureDecl

public void visitForwardProcedureDecl(ForwardProcedureDecl n)
Specified by:
visitForwardProcedureDecl in interface DeclPredicate

visitFileDecl

public void visitFileDecl(FileDecl n)
Specified by:
visitFileDecl in interface DeclPredicate

visitEnumElementDecl

public void visitEnumElementDecl(EnumElementDecl d)
Specified by:
visitEnumElementDecl in interface DeclPredicate

visitType

public void visitType(Type n)
Specified by:
visitType in interface TypePredicate

visitVoidType

public void visitVoidType(VoidType n)
Specified by:
visitVoidType in interface TypePredicate

visitRefType

public void visitRefType(RefType ref)
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

visitProcedureType

public void visitProcedureType(ProcedureType p)
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
Parameters:
p - is the clef node for a ProcedureType

visitIncompleteType

public void visitIncompleteType(IncompleteType n)
Specified by:
visitIncompleteType in interface TypePredicate

visitPointerType

public void visitPointerType(PointerType p)
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
Parameters:
p - the pointer type clef node

visitArrayType

public void visitArrayType(ArrayType at)
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
Parameters:
at - is an array type

visitAggregateType

public void visitAggregateType(AggregateType agg)
Generate the C code for an aggregate type. Basically, just print out the fields.

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

Specified by:
visitAggregateType in interface TypePredicate
See Also:
RecordType, UnionType

visitComplexType

public void visitComplexType(ComplexType type)
Specified by:
visitComplexType in interface TypePredicate

visitBound

public void visitBound(Bound b)
Specified by:
visitBound in interface TypePredicate

visitFixedArrayType

public void visitFixedArrayType(FixedArrayType 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
Parameters:
n - a FixedArray Clef node

visitAllocArrayType

public void visitAllocArrayType(AllocArrayType n)
Generate code for a n allocatable array. To generate code for arrays, we need generate code for the structure that represents the array at run time.

Specified by:
visitAllocArrayType in interface TypePredicate

visitRecordType

public void visitRecordType(RecordType rt)
Generate C code for a record type. Similar code is generated for records, unions, and classes.

Specified by:
visitRecordType in interface TypePredicate
See Also:
visitAggregateType(scale.clef.type.AggregateType)

visitFloatType

public void visitFloatType(FloatType type)
Specified by:
visitFloatType in interface TypePredicate

visitIntegerType

public void visitIntegerType(IntegerType type)
Specified by:
visitIntegerType in interface TypePredicate

visitSignedIntegerType

public void visitSignedIntegerType(SignedIntegerType type)
Specified by:
visitSignedIntegerType in interface TypePredicate

visitUnsignedIntegerType

public void visitUnsignedIntegerType(UnsignedIntegerType type)
Specified by:
visitUnsignedIntegerType in interface TypePredicate

visitFortranCharType

public void visitFortranCharType(FortranCharType type)
Specified by:
visitFortranCharType in interface TypePredicate

visitEnumerationType

public void visitEnumerationType(EnumerationType et)
Specified by:
visitEnumerationType in interface TypePredicate

visitUnionType

public void visitUnionType(UnionType ut)
Specified by:
visitUnionType in interface TypePredicate

visitCharacterType

public void visitCharacterType(CharacterType ct)
Specified by:
visitCharacterType in interface TypePredicate

visitBooleanType

public void visitBooleanType(BooleanType n)
Specified by:
visitBooleanType in interface TypePredicate

visitBlockStmt

public void visitBlockStmt(BlockStmt stmt)
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.

Specified by:
visitBlockStmt in interface StmtPredicate

visitMultiBranchStmt

public void visitMultiBranchStmt(MultiBranchStmt s)
Specified by:
visitMultiBranchStmt in interface StmtPredicate

visitIfThenElseStmt

public void visitIfThenElseStmt(IfThenElseStmt ifstmt)
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

visitArithmeticIfStmt

public void visitArithmeticIfStmt(ArithmeticIfStmt stmt)
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

visitComputedGotoStmt

public void visitComputedGotoStmt(ComputedGotoStmt n)
Specified by:
visitComputedGotoStmt in interface StmtPredicate

visitAssignLabelStmt

public void visitAssignLabelStmt(AssignLabelStmt s)
Specified by:
visitAssignLabelStmt in interface StmtPredicate

visitAssignedGotoStmt

public void visitAssignedGotoStmt(AssignedGotoStmt n)
Specified by:
visitAssignedGotoStmt in interface StmtPredicate

visitCaseStmt

public void visitCaseStmt(CaseStmt stmt)
Specified by:
visitCaseStmt in interface StmtPredicate

visitSwitchStmt

public void visitSwitchStmt(SwitchStmt stmt)
Specified by:
visitSwitchStmt in interface StmtPredicate

visitWhileLoopStmt

public void visitWhileLoopStmt(WhileLoopStmt stmt)
Specified by:
visitWhileLoopStmt in interface StmtPredicate

visitRepeatWhileLoopStmt

public void visitRepeatWhileLoopStmt(RepeatWhileLoopStmt stmt)
Specified by:
visitRepeatWhileLoopStmt in interface StmtPredicate

visitRepeatUntilLoopStmt

public void visitRepeatUntilLoopStmt(RepeatUntilLoopStmt stmt)
Specified by:
visitRepeatUntilLoopStmt in interface StmtPredicate

visitDoLoopStmt

public void visitDoLoopStmt(DoLoopStmt stmt)
Specified by:
visitDoLoopStmt in interface StmtPredicate

visitForLoopStmt

public void visitForLoopStmt(ForLoopStmt stmt)
Specified by:
visitForLoopStmt in interface StmtPredicate

visitBreakStmt

public void visitBreakStmt(BreakStmt n)
Specified by:
visitBreakStmt in interface StmtPredicate

visitContinueStmt

public void visitContinueStmt(ContinueStmt n)
Specified by:
visitContinueStmt in interface StmtPredicate

visitGotoStmt

public void visitGotoStmt(GotoStmt n)
Specified by:
visitGotoStmt in interface StmtPredicate

visitReturnStmt

public void visitReturnStmt(ReturnStmt n)
Specified by:
visitReturnStmt in interface StmtPredicate

visitExitStmt

public void visitExitStmt(ExitStmt n)
Specified by:
visitExitStmt in interface StmtPredicate

visitEvalStmt

public void visitEvalStmt(EvalStmt n)
Specified by:
visitEvalStmt in interface StmtPredicate

visitDeclStmt

public void visitDeclStmt(DeclStmt n)
Specified by:
visitDeclStmt in interface StmtPredicate

visitNullStmt

public void visitNullStmt(NullStmt n)
Specified by:
visitNullStmt in interface StmtPredicate

visitLabelStmt

public void visitLabelStmt(LabelStmt s)
Specified by:
visitLabelStmt in interface StmtPredicate

visitExpression

public void visitExpression(Expression n)
Specified by:
visitExpression in interface ExprPredicate

visitLiteral

public void visitLiteral(Literal l)
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
Parameters:
l - the literal node

visitStringLiteral

public void visitStringLiteral(StringLiteral n)
Specified by:
visitStringLiteral in interface ExprPredicate

visitBooleanLiteral

public void visitBooleanLiteral(BooleanLiteral n)
Specified by:
visitBooleanLiteral in interface ExprPredicate

visitCharLiteral

public void visitCharLiteral(CharLiteral n)
Specified by:
visitCharLiteral in interface ExprPredicate

visitIntLiteral

public void visitIntLiteral(IntLiteral n)
Specified by:
visitIntLiteral in interface ExprPredicate

visitIntArrayLiteral

public void visitIntArrayLiteral(IntArrayLiteral l)
Specified by:
visitIntArrayLiteral in interface ExprPredicate

visitFloatLiteral

public void visitFloatLiteral(FloatLiteral n)
Specified by:
visitFloatLiteral in interface ExprPredicate

visitComplexLiteral

public void visitComplexLiteral(ComplexLiteral n)
Specified by:
visitComplexLiteral in interface ExprPredicate

visitFloatArrayLiteral

public void visitFloatArrayLiteral(FloatArrayLiteral l)
Specified by:
visitFloatArrayLiteral in interface ExprPredicate

visitSizeofLiteral

public void visitSizeofLiteral(SizeofLiteral sl)
Specified by:
visitSizeofLiteral in interface ExprPredicate

visitAddressLiteral

public void visitAddressLiteral(AddressLiteral sl)
Specified by:
visitAddressLiteral in interface ExprPredicate

visitIdAddressOp

public void visitIdAddressOp(IdAddressOp id)
Specified by:
visitIdAddressOp in interface ExprPredicate

visitIdValueOp

public void visitIdValueOp(IdValueOp id)
Specified by:
visitIdValueOp in interface ExprPredicate

visitIdReferenceOp

public void visitIdReferenceOp(IdReferenceOp id)
Specified by:
visitIdReferenceOp in interface ExprPredicate

visitSeriesOp

public void visitSeriesOp(SeriesOp expr)
Specified by:
visitSeriesOp in interface ExprPredicate

visitParenthesesOp

public void visitParenthesesOp(ParenthesesOp expr)
Specified by:
visitParenthesesOp in interface ExprPredicate

visitAggregationElements

public void visitAggregationElements(AggregationElements agg)
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

visitAssignSimpleOp

public void visitAssignSimpleOp(AssignSimpleOp a)
Generate the C code for a regular assignment.

Specified by:
visitAssignSimpleOp in interface ExprPredicate

visitDefOp

public void visitDefOp(DefOp expr)
Specified by:
visitDefOp in interface ExprPredicate

visitPositiveOp

public void visitPositiveOp(PositiveOp expr)
Specified by:
visitPositiveOp in interface ExprPredicate

simpleTypeName

public static char simpleTypeName(java.lang.String name)

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(NegativeOp expr)
Specified by:
visitNegativeOp in interface ExprPredicate

visitTranscendentalOp

public void visitTranscendentalOp(TranscendentalOp expr)
Specified by:
visitTranscendentalOp in interface ExprPredicate

visitTranscendental2Op

public void visitTranscendental2Op(Transcendental2Op expr)
Specified by:
visitTranscendental2Op in interface ExprPredicate

visitAbsoluteValueOp

public void visitAbsoluteValueOp(AbsoluteValueOp expr)
Specified by:
visitAbsoluteValueOp in interface ExprPredicate

visitMinimumOp

public void visitMinimumOp(MinimumOp expr)
Specified by:
visitMinimumOp in interface ExprPredicate

visitMaximumOp

public void visitMaximumOp(MaximumOp expr)
Specified by:
visitMaximumOp in interface ExprPredicate

visitAdditionOp

public void visitAdditionOp(AdditionOp expr)
Specified by:
visitAdditionOp in interface ExprPredicate

visitSubtractionOp

public void visitSubtractionOp(SubtractionOp expr)
Specified by:
visitSubtractionOp in interface ExprPredicate

visitMultiplicationOp

public void visitMultiplicationOp(MultiplicationOp expr)
Specified by:
visitMultiplicationOp in interface ExprPredicate

visitDivisionOp

public void visitDivisionOp(DivisionOp expr)
Specified by:
visitDivisionOp in interface ExprPredicate

visitModulusOp

public void visitModulusOp(ModulusOp expr)
Specified by:
visitModulusOp in interface ExprPredicate

visitRemainderOp

public void visitRemainderOp(RemainderOp expr)
Specified by:
visitRemainderOp in interface ExprPredicate

visitExponentiationOp

public void visitExponentiationOp(ExponentiationOp expr)
Specified by:
visitExponentiationOp in interface ExprPredicate

visitPreDecrementOp

public void visitPreDecrementOp(PreDecrementOp expr)
Specified by:
visitPreDecrementOp in interface ExprPredicate

visitPreIncrementOp

public void visitPreIncrementOp(PreIncrementOp expr)
Specified by:
visitPreIncrementOp in interface ExprPredicate

visitPostDecrementOp

public void visitPostDecrementOp(PostDecrementOp expr)
Specified by:
visitPostDecrementOp in interface ExprPredicate

visitPostIncrementOp

public void visitPostIncrementOp(PostIncrementOp expr)
Specified by:
visitPostIncrementOp in interface ExprPredicate

visitEqualityOp

public void visitEqualityOp(EqualityOp expr)
Specified by:
visitEqualityOp in interface ExprPredicate

visitNotEqualOp

public void visitNotEqualOp(NotEqualOp expr)
Specified by:
visitNotEqualOp in interface ExprPredicate

visitGreaterOp

public void visitGreaterOp(GreaterOp expr)
Specified by:
visitGreaterOp in interface ExprPredicate

visitGreaterEqualOp

public void visitGreaterEqualOp(GreaterEqualOp expr)
Specified by:
visitGreaterEqualOp in interface ExprPredicate

visitLessOp

public void visitLessOp(LessOp expr)
Specified by:
visitLessOp in interface ExprPredicate

visitLessEqualOp

public void visitLessEqualOp(LessEqualOp expr)
Specified by:
visitLessEqualOp in interface ExprPredicate

visitBitComplementOp

public void visitBitComplementOp(BitComplementOp expr)
Specified by:
visitBitComplementOp in interface ExprPredicate

visitBitAndOp

public void visitBitAndOp(BitAndOp expr)
Specified by:
visitBitAndOp in interface ExprPredicate

visitBitXorOp

public void visitBitXorOp(BitXorOp expr)
Specified by:
visitBitXorOp in interface ExprPredicate

visitBitOrOp

public void visitBitOrOp(BitOrOp expr)
Specified by:
visitBitOrOp in interface ExprPredicate

visitBitShiftOp

public void visitBitShiftOp(BitShiftOp expr)
Specified by:
visitBitShiftOp in interface ExprPredicate

visitMultiplicationAssignmentOp

public void visitMultiplicationAssignmentOp(MultiplicationAssignmentOp expr)
Specified by:
visitMultiplicationAssignmentOp in interface ExprPredicate

visitDivisionAssignmentOp

public void visitDivisionAssignmentOp(DivisionAssignmentOp expr)
Specified by:
visitDivisionAssignmentOp in interface ExprPredicate

visitRemainderAssignmentOp

public void visitRemainderAssignmentOp(RemainderAssignmentOp expr)
Specified by:
visitRemainderAssignmentOp in interface ExprPredicate

visitAdditionAssignmentOp

public void visitAdditionAssignmentOp(AdditionAssignmentOp a)
Specified by:
visitAdditionAssignmentOp in interface ExprPredicate

visitSubtractionAssignmentOp

public void visitSubtractionAssignmentOp(SubtractionAssignmentOp a)
Specified by:
visitSubtractionAssignmentOp in interface ExprPredicate

visitBitShiftAssignmentOp

public void visitBitShiftAssignmentOp(BitShiftAssignmentOp a)
Specified by:
visitBitShiftAssignmentOp in interface ExprPredicate

visitBitAndAssignmentOp

public void visitBitAndAssignmentOp(BitAndAssignmentOp a)
Specified by:
visitBitAndAssignmentOp in interface ExprPredicate

visitBitXorAssignmentOp

public void visitBitXorAssignmentOp(BitXorAssignmentOp a)
Specified by:
visitBitXorAssignmentOp in interface ExprPredicate

visitBitOrAssignmentOp

public void visitBitOrAssignmentOp(BitOrAssignmentOp a)
Specified by:
visitBitOrAssignmentOp in interface ExprPredicate

visitNotOp

public void visitNotOp(NotOp expr)
Specified by:
visitNotOp in interface ExprPredicate

visitAndOp

public void visitAndOp(AndOp expr)
Specified by:
visitAndOp in interface ExprPredicate

visitOrOp

public void visitOrOp(OrOp expr)
Specified by:
visitOrOp in interface ExprPredicate

visitAndConditionalOp

public void visitAndConditionalOp(AndConditionalOp expr)
Specified by:
visitAndConditionalOp in interface ExprPredicate

visitOrConditionalOp

public void visitOrConditionalOp(OrConditionalOp expr)
Specified by:
visitOrConditionalOp in interface ExprPredicate

visitExpressionIfOp

public void visitExpressionIfOp(ExpressionIfOp expr)
Specified by:
visitExpressionIfOp in interface ExprPredicate

visitAddressOp

public void visitAddressOp(AddressOp expr)
Specified by:
visitAddressOp in interface ExprPredicate

visitDereferenceOp

public void visitDereferenceOp(DereferenceOp expr)
Specified by:
visitDereferenceOp in interface ExprPredicate

visitNilOp

public void visitNilOp(NilOp n)
Specified by:
visitNilOp in interface ExprPredicate

visitThisOp

public void visitThisOp(ThisOp n)
Specified by:
visitThisOp in interface ExprPredicate

visitSelectOp

public void visitSelectOp(SelectOp expr)
Specified by:
visitSelectOp in interface ExprPredicate

visitSelectIndirectOp

public void visitSelectIndirectOp(SelectIndirectOp expr)
Specified by:
visitSelectIndirectOp in interface ExprPredicate

visitSubscriptValueOp

public void visitSubscriptValueOp(SubscriptValueOp n)
Specified by:
visitSubscriptValueOp in interface ExprPredicate

visitSubscriptAddressOp

public void visitSubscriptAddressOp(SubscriptAddressOp n)
Specified by:
visitSubscriptAddressOp in interface ExprPredicate

visitSubscriptOp

public void visitSubscriptOp(SubscriptOp expr)
Specified by:
visitSubscriptOp in interface ExprPredicate

visitCallFunctionOp

public void visitCallFunctionOp(CallFunctionOp fun)
Specified by:
visitCallFunctionOp in interface ExprPredicate

visitTypeConversionOp

public void visitTypeConversionOp(TypeConversionOp t)
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 aggregate types 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

visitComplexOp

public void visitComplexOp(ComplexOp t)
Generate C code to create a complex value.

Specified by:
visitComplexOp in interface ExprPredicate
Throws:
InternalError - for errors

visitVaStartOp

public void visitVaStartOp(VaStartOp vas)
Generate the C construct for the va_start(va_list, parmN) construct.

Specified by:
visitVaStartOp in interface ExprPredicate

visitVaArgOp

public void visitVaArgOp(VaArgOp va)
Generate the C construct for the va_arg(va_list, type) construct.

Specified by:
visitVaArgOp in interface ExprPredicate

visitVaCopyOp

public void visitVaCopyOp(VaCopyOp vac)
Specified by:
visitVaCopyOp in interface ExprPredicate

visitStatementOp

public void visitStatementOp(StatementOp so)
Generate the C construct for the Gnu abomination called a "statement expression".

Specified by:
visitStatementOp in interface ExprPredicate

visitVaEndOp

public void visitVaEndOp(VaEndOp vae)
Generate the C construct for the va_end(va_list) construct.

Specified by:
visitVaEndOp in interface ExprPredicate