| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectscale.clef.Clef2C
public final class Clef2C
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).
scale.clef| Constructor Summary | |
|---|---|
| Clef2C(Emit emit,
       SourceLanguage lang)Construct a C language code generator - output goes to a file. | |
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public Clef2C(Emit emit,
              SourceLanguage lang)
emit - is the Emit instance used to generate the C program.lang - the source languageEmit| Method Detail | 
|---|
public java.lang.String fileExt()
.c.
public final void codeGen(Node root)
root - root node of the Clef treepublic void genCastType(Type t)
Person *Person = (Person *) 0;
public java.lang.String convertDeclName(Declaration decl,
                                        boolean address)
decl - is the Declarationaddress - is true if an address form of the name is needed
public void genDeclarator(Type t,
                          java.lang.String v)
 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.
t - the clef type to generate in Cv - the name of the defined object
public void genDeclaratorFull(Type t,
                              java.lang.String v)
genDeclarator in that the full procedure
 declaration is generated.
public void visitNode(Node n)
visitNode in interface Predicatepublic void visitExceptionDecl(ExceptionDecl d)
visitExceptionDecl in interface DeclPredicatepublic void visitCaseLabelDecl(CaseLabelDecl d)
visitCaseLabelDecl in interface DeclPredicatepublic void visitDeclaration(Declaration n)
visitDeclaration in interface DeclPredicatepublic void visitRoutineDecl(RoutineDecl d)
visitRoutineDecl in interface DeclPredicatepublic void visitRealType(RealType d)
visitRealType in interface TypePredicatepublic void visitRaiseWithType(RaiseWithType d)
visitRaiseWithType in interface TypePredicatepublic void visitRaiseWithObject(RaiseWithObject d)
visitRaiseWithObject in interface TypePredicatepublic void visitRaise(Raise d)
visitRaise in interface TypePredicatepublic void visitNumericType(NumericType d)
visitNumericType in interface TypePredicatepublic void visitCompositeType(CompositeType d)
visitCompositeType in interface TypePredicatepublic void visitAtomicType(AtomicType d)
visitAtomicType in interface TypePredicatepublic void visitAltCase(AltCase d)
visitAltCase in interface StmtPredicatepublic void visitIfStmt(IfStmt d)
visitIfStmt in interface StmtPredicatepublic void visitTestLoopStmt(TestLoopStmt d)
visitTestLoopStmt in interface StmtPredicatepublic void visitLoopStmt(LoopStmt d)
visitLoopStmt in interface StmtPredicatepublic void visitStatement(Statement d)
visitStatement in interface StmtPredicatepublic void visitVarArgOp(VarArgOp d)
visitVarArgOp in interface ExprPredicatepublic void visitTernaryOp(TernaryOp d)
visitTernaryOp in interface ExprPredicatepublic void visitSubstringOp(SubstringOp d)
visitSubstringOp in interface ExprPredicatepublic void visitIncrementOp(IncrementOp d)
visitIncrementOp in interface ExprPredicatepublic void visitHeapOp(HeapOp d)
visitHeapOp in interface ExprPredicatepublic void visitDyadicOp(DyadicOp d)
visitDyadicOp in interface ExprPredicatepublic void visitDeleteOp(DeleteOp d)
visitDeleteOp in interface ExprPredicatepublic void visitDeleteArrayOp(DeleteArrayOp d)
visitDeleteArrayOp in interface ExprPredicatepublic void visitCompoundAssignmentOp(CompoundAssignmentOp d)
visitCompoundAssignmentOp in interface ExprPredicatepublic void visitCallOp(CallOp d)
visitCallOp in interface ExprPredicatepublic void visitAssignmentOp(AssignmentOp d)
visitAssignmentOp in interface ExprPredicatepublic void visitMonadicOp(MonadicOp d)
visitMonadicOp in interface ExprPredicatepublic void visitAllocateSettingFieldsOp(AllocateSettingFieldsOp d)
visitAllocateSettingFieldsOp in interface ExprPredicatepublic void visitAllocatePlacementOp(AllocatePlacementOp d)
visitAllocatePlacementOp in interface ExprPredicatepublic void visitAggregateOp(AggregateOp d)
visitAggregateOp in interface ExprPredicatepublic void visitTypeDecl(TypeDecl td)
TypeDecl node) to determine the name.  We need to do this
 because different types place names in different places.
visitTypeDecl in interface DeclPredicatepublic void genTypeDecl(TypeDecl td)
TypeDecl.
public void visitTypeName(TypeName tn)
visitTypeName in interface DeclPredicatepublic void visitValueDecl(ValueDecl v)
visitValueDecl in interface DeclPredicatepublic void visitLabelDecl(LabelDecl n)
visitLabelDecl in interface DeclPredicatepublic void visitVariableDecl(VariableDecl d)
visitVariableDecl in interface DeclPredicatepublic void visitRenamedVariableDecl(RenamedVariableDecl n)
visitRenamedVariableDecl in interface DeclPredicatepublic void visitEquivalenceDecl(EquivalenceDecl ed)
EQUIVALENCE
 relations.  The equivalenced array is converted to a C pointer
 variable that is initialized to an address using the equivalence
 relationship.
visitEquivalenceDecl in interface DeclPredicatepublic void visitFormalDecl(FormalDecl fd)
visitValueDecl to generate the
 declaration). The default value is handled by the caller.
visitFormalDecl in interface DeclPredicatefd - the FormalDecl nodepublic void visitUnknownFormals(UnknownFormals n)
visitUnknownFormals in interface DeclPredicatepublic void visitFieldDecl(FieldDecl fd)
visitFieldDecl in interface DeclPredicatepublic void genRoutineAttributes(RoutineDecl p)
static) for a function.
public void visitProcedureDecl(ProcedureDecl p)
visitProcedureDecl in interface DeclPredicatepublic void genForwardRoutineDecl(RoutineDecl p)
public void visitForwardProcedureDecl(ForwardProcedureDecl n)
visitForwardProcedureDecl in interface DeclPredicatepublic void visitFileDecl(FileDecl n)
visitFileDecl in interface DeclPredicatepublic void visitEnumElementDecl(EnumElementDecl d)
visitEnumElementDecl in interface DeclPredicatepublic void visitType(Type n)
visitType in interface TypePredicatepublic void visitVoidType(VoidType n)
visitVoidType in interface TypePredicatepublic void visitRefType(RefType ref)
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.
visitRefType in interface TypePredicatepublic void visitProcedureType(ProcedureType p)
visitProcedureType in interface TypePredicatep - is the clef node for a ProcedureTypepublic void visitIncompleteType(IncompleteType n)
visitIncompleteType in interface TypePredicatepublic void visitPointerType(PointerType p)
    int * const const_pointer
    const int *pointer_to_const;
 .
 Note: we make multple passes over the type.  The generated code
 depends upon which pass.
visitPointerType in interface TypePredicatep - the pointer type clef nodepublic void visitArrayType(ArrayType at)
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.
visitArrayType in interface TypePredicateat - is an array typepublic void visitAggregateType(AggregateType agg)
We assume that the aggregate head has already been generated via a call to genTypeNameProlog() and that the enclosing braces are generated.
visitAggregateType in interface TypePredicateRecordType, 
UnionTypepublic void visitComplexType(ComplexType type)
visitComplexType in interface TypePredicatepublic void visitBound(Bound b)
visitBound in interface TypePredicatepublic void visitFixedArrayType(FixedArrayType n)
visitFixedArrayType in interface TypePredicaten - a FixedArray Clef nodepublic void visitAllocArrayType(AllocArrayType n)
visitAllocArrayType in interface TypePredicatepublic void visitRecordType(RecordType rt)
visitRecordType in interface TypePredicatevisitAggregateType(scale.clef.type.AggregateType)public void visitFloatType(FloatType type)
visitFloatType in interface TypePredicatepublic void visitIntegerType(IntegerType type)
visitIntegerType in interface TypePredicatepublic void visitSignedIntegerType(SignedIntegerType type)
visitSignedIntegerType in interface TypePredicatepublic void visitUnsignedIntegerType(UnsignedIntegerType type)
visitUnsignedIntegerType in interface TypePredicatepublic void visitFortranCharType(FortranCharType type)
visitFortranCharType in interface TypePredicatepublic void visitEnumerationType(EnumerationType et)
visitEnumerationType in interface TypePredicatepublic void visitUnionType(UnionType ut)
visitUnionType in interface TypePredicatepublic void visitCharacterType(CharacterType ct)
visitCharacterType in interface TypePredicatepublic void visitBooleanType(BooleanType n)
visitBooleanType in interface TypePredicatepublic void visitBlockStmt(BlockStmt stmt)
visitBlockStmt in interface StmtPredicatepublic void visitMultiBranchStmt(MultiBranchStmt s)
visitMultiBranchStmt in interface StmtPredicatepublic void visitIfThenElseStmt(IfThenElseStmt ifstmt)
visitIfThenElseStmt in interface StmtPredicatepublic void visitArithmeticIfStmt(ArithmeticIfStmt stmt)
   if (e == 0)
     goto L_Equal;
   else if (e < 0)
     goto L_Less; }
   else
     goto L_Greater;
 
visitArithmeticIfStmt in interface StmtPredicatepublic void visitComputedGotoStmt(ComputedGotoStmt n)
visitComputedGotoStmt in interface StmtPredicatepublic void visitAssignLabelStmt(AssignLabelStmt s)
visitAssignLabelStmt in interface StmtPredicatepublic void visitAssignedGotoStmt(AssignedGotoStmt n)
visitAssignedGotoStmt in interface StmtPredicatepublic void visitCaseStmt(CaseStmt stmt)
visitCaseStmt in interface StmtPredicatepublic void visitSwitchStmt(SwitchStmt stmt)
visitSwitchStmt in interface StmtPredicatepublic void visitWhileLoopStmt(WhileLoopStmt stmt)
visitWhileLoopStmt in interface StmtPredicatepublic void visitRepeatWhileLoopStmt(RepeatWhileLoopStmt stmt)
visitRepeatWhileLoopStmt in interface StmtPredicatepublic void visitRepeatUntilLoopStmt(RepeatUntilLoopStmt stmt)
visitRepeatUntilLoopStmt in interface StmtPredicatepublic void visitDoLoopStmt(DoLoopStmt stmt)
visitDoLoopStmt in interface StmtPredicatepublic void visitForLoopStmt(ForLoopStmt stmt)
visitForLoopStmt in interface StmtPredicatepublic void visitBreakStmt(BreakStmt n)
visitBreakStmt in interface StmtPredicatepublic void visitContinueStmt(ContinueStmt n)
visitContinueStmt in interface StmtPredicatepublic void visitGotoStmt(GotoStmt n)
visitGotoStmt in interface StmtPredicatepublic void visitReturnStmt(ReturnStmt n)
visitReturnStmt in interface StmtPredicatepublic void visitExitStmt(ExitStmt n)
visitExitStmt in interface StmtPredicatepublic void visitEvalStmt(EvalStmt n)
visitEvalStmt in interface StmtPredicatepublic void visitDeclStmt(DeclStmt n)
visitDeclStmt in interface StmtPredicatepublic void visitNullStmt(NullStmt n)
visitNullStmt in interface StmtPredicatepublic void visitLabelStmt(LabelStmt s)
visitLabelStmt in interface StmtPredicatepublic void visitExpression(Expression n)
visitExpression in interface ExprPredicatepublic void visitLiteral(Literal l)
visitLiteral in interface ExprPredicatel - the literal nodepublic void visitStringLiteral(StringLiteral n)
visitStringLiteral in interface ExprPredicatepublic void visitBooleanLiteral(BooleanLiteral n)
visitBooleanLiteral in interface ExprPredicatepublic void visitCharLiteral(CharLiteral n)
visitCharLiteral in interface ExprPredicatepublic void visitIntLiteral(IntLiteral n)
visitIntLiteral in interface ExprPredicatepublic void visitIntArrayLiteral(IntArrayLiteral l)
visitIntArrayLiteral in interface ExprPredicatepublic void visitFloatLiteral(FloatLiteral n)
visitFloatLiteral in interface ExprPredicatepublic void visitComplexLiteral(ComplexLiteral n)
visitComplexLiteral in interface ExprPredicatepublic void visitFloatArrayLiteral(FloatArrayLiteral l)
visitFloatArrayLiteral in interface ExprPredicatepublic void visitSizeofLiteral(SizeofLiteral sl)
visitSizeofLiteral in interface ExprPredicatepublic void visitAddressLiteral(AddressLiteral sl)
visitAddressLiteral in interface ExprPredicatepublic void visitIdAddressOp(IdAddressOp id)
visitIdAddressOp in interface ExprPredicatepublic void visitIdValueOp(IdValueOp id)
visitIdValueOp in interface ExprPredicatepublic void visitIdReferenceOp(IdReferenceOp id)
visitIdReferenceOp in interface ExprPredicatepublic void visitSeriesOp(SeriesOp expr)
visitSeriesOp in interface ExprPredicatepublic void visitParenthesesOp(ParenthesesOp expr)
visitParenthesesOp in interface ExprPredicatepublic void visitAggregationElements(AggregationElements agg)
We use several stages to generate the C code.
visitAggregationElements in interface ExprPredicatepublic void visitAssignSimpleOp(AssignSimpleOp a)
visitAssignSimpleOp in interface ExprPredicatepublic void visitDefOp(DefOp expr)
visitDefOp in interface ExprPredicatepublic void visitPositiveOp(PositiveOp expr)
visitPositiveOp in interface ExprPredicatepublic static char simpleTypeName(java.lang.String name)
public void genIntrinsicOp(java.lang.String op,
                           Type t1,
                           Expression e1,
                           Type t2,
                           Expression e2)
public void visitNegativeOp(NegativeOp expr)
visitNegativeOp in interface ExprPredicatepublic void visitTranscendentalOp(TranscendentalOp expr)
visitTranscendentalOp in interface ExprPredicatepublic void visitTranscendental2Op(Transcendental2Op expr)
visitTranscendental2Op in interface ExprPredicatepublic void visitAbsoluteValueOp(AbsoluteValueOp expr)
visitAbsoluteValueOp in interface ExprPredicatepublic void visitMinimumOp(MinimumOp expr)
visitMinimumOp in interface ExprPredicatepublic void visitMaximumOp(MaximumOp expr)
visitMaximumOp in interface ExprPredicatepublic void visitAdditionOp(AdditionOp expr)
visitAdditionOp in interface ExprPredicatepublic void visitSubtractionOp(SubtractionOp expr)
visitSubtractionOp in interface ExprPredicatepublic void visitMultiplicationOp(MultiplicationOp expr)
visitMultiplicationOp in interface ExprPredicatepublic void visitDivisionOp(DivisionOp expr)
visitDivisionOp in interface ExprPredicatepublic void visitModulusOp(ModulusOp expr)
visitModulusOp in interface ExprPredicatepublic void visitRemainderOp(RemainderOp expr)
visitRemainderOp in interface ExprPredicatepublic void visitExponentiationOp(ExponentiationOp expr)
visitExponentiationOp in interface ExprPredicatepublic void visitPreDecrementOp(PreDecrementOp expr)
visitPreDecrementOp in interface ExprPredicatepublic void visitPreIncrementOp(PreIncrementOp expr)
visitPreIncrementOp in interface ExprPredicatepublic void visitPostDecrementOp(PostDecrementOp expr)
visitPostDecrementOp in interface ExprPredicatepublic void visitPostIncrementOp(PostIncrementOp expr)
visitPostIncrementOp in interface ExprPredicatepublic void visitEqualityOp(EqualityOp expr)
visitEqualityOp in interface ExprPredicatepublic void visitNotEqualOp(NotEqualOp expr)
visitNotEqualOp in interface ExprPredicatepublic void visitGreaterOp(GreaterOp expr)
visitGreaterOp in interface ExprPredicatepublic void visitGreaterEqualOp(GreaterEqualOp expr)
visitGreaterEqualOp in interface ExprPredicatepublic void visitLessOp(LessOp expr)
visitLessOp in interface ExprPredicatepublic void visitLessEqualOp(LessEqualOp expr)
visitLessEqualOp in interface ExprPredicatepublic void visitBitComplementOp(BitComplementOp expr)
visitBitComplementOp in interface ExprPredicatepublic void visitBitAndOp(BitAndOp expr)
visitBitAndOp in interface ExprPredicatepublic void visitBitXorOp(BitXorOp expr)
visitBitXorOp in interface ExprPredicatepublic void visitBitOrOp(BitOrOp expr)
visitBitOrOp in interface ExprPredicatepublic void visitBitShiftOp(BitShiftOp expr)
visitBitShiftOp in interface ExprPredicatepublic void visitMultiplicationAssignmentOp(MultiplicationAssignmentOp expr)
visitMultiplicationAssignmentOp in interface ExprPredicatepublic void visitDivisionAssignmentOp(DivisionAssignmentOp expr)
visitDivisionAssignmentOp in interface ExprPredicatepublic void visitRemainderAssignmentOp(RemainderAssignmentOp expr)
visitRemainderAssignmentOp in interface ExprPredicatepublic void visitAdditionAssignmentOp(AdditionAssignmentOp a)
visitAdditionAssignmentOp in interface ExprPredicatepublic void visitSubtractionAssignmentOp(SubtractionAssignmentOp a)
visitSubtractionAssignmentOp in interface ExprPredicatepublic void visitBitShiftAssignmentOp(BitShiftAssignmentOp a)
visitBitShiftAssignmentOp in interface ExprPredicatepublic void visitBitAndAssignmentOp(BitAndAssignmentOp a)
visitBitAndAssignmentOp in interface ExprPredicatepublic void visitBitXorAssignmentOp(BitXorAssignmentOp a)
visitBitXorAssignmentOp in interface ExprPredicatepublic void visitBitOrAssignmentOp(BitOrAssignmentOp a)
visitBitOrAssignmentOp in interface ExprPredicatepublic void visitNotOp(NotOp expr)
visitNotOp in interface ExprPredicatepublic void visitAndOp(AndOp expr)
visitAndOp in interface ExprPredicatepublic void visitOrOp(OrOp expr)
visitOrOp in interface ExprPredicatepublic void visitAndConditionalOp(AndConditionalOp expr)
visitAndConditionalOp in interface ExprPredicatepublic void visitOrConditionalOp(OrConditionalOp expr)
visitOrConditionalOp in interface ExprPredicatepublic void visitExpressionIfOp(ExpressionIfOp expr)
visitExpressionIfOp in interface ExprPredicatepublic void visitAddressOp(AddressOp expr)
visitAddressOp in interface ExprPredicatepublic void visitDereferenceOp(DereferenceOp expr)
visitDereferenceOp in interface ExprPredicatepublic void visitNilOp(NilOp n)
visitNilOp in interface ExprPredicatepublic void visitThisOp(ThisOp n)
visitThisOp in interface ExprPredicatepublic void visitSelectOp(SelectOp expr)
visitSelectOp in interface ExprPredicatepublic void visitSelectIndirectOp(SelectIndirectOp expr)
visitSelectIndirectOp in interface ExprPredicatepublic void visitSubscriptValueOp(SubscriptValueOp n)
visitSubscriptValueOp in interface ExprPredicatepublic void visitSubscriptAddressOp(SubscriptAddressOp n)
visitSubscriptAddressOp in interface ExprPredicatepublic void visitSubscriptOp(SubscriptOp expr)
visitSubscriptOp in interface ExprPredicatepublic void visitCallFunctionOp(CallFunctionOp fun)
visitCallFunctionOp in interface ExprPredicatepublic void visitTypeConversionOp(TypeConversionOp t)
 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).
visitTypeConversionOp in interface ExprPredicatepublic void visitComplexOp(ComplexOp t)
visitComplexOp in interface ExprPredicateInternalError - for errorspublic void visitVaStartOp(VaStartOp vas)
va_start(va_list,
 parmN) construct.
visitVaStartOp in interface ExprPredicatepublic void visitVaArgOp(VaArgOp va)
va_arg(va_list,
 type) construct.
visitVaArgOp in interface ExprPredicatepublic void visitVaCopyOp(VaCopyOp vac)
visitVaCopyOp in interface ExprPredicatepublic void visitStatementOp(StatementOp so)
visitStatementOp in interface ExprPredicatepublic void visitVaEndOp(VaEndOp vae)
va_end(va_list)
 construct.
visitVaEndOp in interface ExprPredicate| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||