home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / Blitz / BlitzSrc / ast.cc < prev    next >
C/C++ Source or Header  |  2007-09-19  |  36KB  |  1,764 lines

  1. // ast.cc  --  Methods for AstNode classes
  2. //
  3. // KPL Compiler
  4. //
  5. // Copyright 2002-2007, Harry H. Porter III
  6. //
  7. // This file may be freely copied, modified and compiled, on the sole
  8. // condition that if you modify it...
  9. //   (1) Your name and the date of modification is added to this comment
  10. //       under "Modifications by", and
  11. //   (2) Your name and the date of modification is added to the printHelp()
  12. //       routine in file "main.cc" under "Modifications by".
  13. //
  14. // Original Author:
  15. //   06/15/02 - Harry H. Porter III
  16. //
  17. // Modifcations by:
  18. //   03/15/06 - Harry H. Porter III
  19. //
  20. //
  21.  
  22. #include "main.h"
  23.  
  24.  
  25.  
  26. //----------  AstNode  ----------
  27.  
  28. void AstNode::prettyPrint (int indent) {
  29.   programLogicError ("Routine prettyPrint should have been overridden (AstNode)");
  30. }
  31.  
  32.  
  33.  
  34. //----------  Header  ----------
  35.  
  36. void Header::prettyPrint (int indent) {
  37.   ppIndent (indent);
  38.   printf ("header \"");
  39.   printString (stdout, packageName);
  40.   printf ("\"\n\n");
  41.   if (uses) {
  42.     ppIndent (indent+2);
  43.     printf ("uses\n");
  44.     uses->prettyPrint (indent+4);
  45.     printf ("\n");
  46.   }
  47.   printConsts (indent+2, consts);
  48.   if (consts) printf ("\n");
  49.   printErrorDecls (indent+2, errors);
  50.   if (errors) printf ("\n");
  51.   printVarDecls (indent+2, globals);
  52.   if (globals) printf ("\n");
  53.   printTypeDefs (indent+2, typeDefs);
  54.   if (typeDefs) printf ("\n");
  55.   printFunctionProtos (indent+2, functionProtos);
  56.   if (functionProtos) printf ("\n");
  57.   printFunctions (indent+2, functions);
  58.   if (closures) {
  59.     ppIndent (indent+2);
  60.     printf ("closures\n\n");
  61.     printFunctions (indent+4, closures);
  62.   }
  63.   if (interfaces) {
  64.     interfaces->prettyPrint (indent+2);
  65.   }
  66.   if (classes) {
  67.     classes->prettyPrint (indent+2);
  68.   }
  69.   ppIndent (indent);
  70.   printf ("endHeader\n");
  71. }
  72.  
  73.  
  74.  
  75. //----------  Code  ----------
  76.  
  77. void Code::prettyPrint (int indent) {
  78.   ppIndent (indent);
  79.   printf ("code \"");
  80.   printString (stdout, packageName);
  81.   printf ("\"\n");
  82.   printErrorDecls (indent+2, errors);
  83.   printConsts (indent+2, consts);
  84.   printVarDecls (indent+2, globals);
  85.   printTypeDefs (indent+2, typeDefs);
  86.   printFunctions (indent+2, functions);
  87.   if (interfaces) {
  88.     interfaces->prettyPrint (indent+2);
  89.   }
  90.   if (classes) {
  91.     classes->prettyPrint (indent+2);
  92.   }
  93.   if (behaviors) {
  94.     behaviors->prettyPrint (indent+2);
  95.   }
  96.   ppIndent (indent);
  97.   printf ("endCode\n");
  98. }
  99.  
  100.  
  101.  
  102. //----------  Uses  ----------
  103.  
  104. void Uses::prettyPrint (int indent) {
  105.   ppIndent (indent);
  106.   printString (stdout, id);
  107.   if (renamings) {
  108.     printf ("\n");
  109.     ppIndent (indent+2);
  110.     printf ("renaming\n");
  111.     renamings->prettyPrint (indent+4);
  112.   }
  113.   if (next) {
  114.     printf (",\n");
  115.     next->prettyPrint (indent);
  116.   } else {
  117.     printf ("\n");
  118.   }
  119. }
  120.  
  121.  
  122.  
  123. //----------  Renaming  ----------
  124.  
  125. void Renaming::prettyPrint (int indent) {
  126.   // This routine begins with an indent, but does not print the final \n.
  127.   ppIndent (indent);
  128.   printString (stdout, from);
  129.   printf (" to ");
  130.   printString (stdout, to);
  131.   if (next) {
  132.     printf (",\n");
  133.     next->prettyPrint (indent);
  134.   }
  135. }
  136.  
  137.  
  138.  
  139. //----------  Abstract  ----------
  140.  
  141. void Abstract::prettyPrint (int indent) {
  142.   printf ("prettyPrint (Abstract) should have been overridden\n");
  143. }
  144.  
  145.  
  146.  
  147. //----------  Interface  ----------
  148.  
  149. void Interface::prettyPrint (int indent) {
  150.   MethodProto * p;
  151.  
  152.   ppIndent (indent);
  153.   // printf ("[%08x:]", this);
  154.   printf ("interface ");
  155.   printString (stdout, id);
  156.   printTypeParms (indent+8, typeParms);
  157.   printf ("\n");
  158.   if (extends) {
  159.     ppIndent (indent+2);
  160.     printf ("extends ");
  161.     extends->prettyPrint (indent+6);
  162.     printf ("\n");
  163.   }
  164.   if (methodProtos) {
  165.     ppIndent (indent+2);
  166.     printf ("messages\n");
  167.     p = methodProtos;
  168.     while (p) {
  169.       ppIndent (indent+4);
  170.       p->prettyPrint (indent+6);
  171.       printf ("\n");
  172.       p = p->next;
  173.     }
  174.   }
  175.   if (inheritedMethodProtos) {
  176.     ppIndent (indent+2);
  177.     printf ("inheritedMethodProtos\n");
  178.     p = inheritedMethodProtos;
  179.     while (p) {
  180.       ppIndent (indent+4);
  181.       p->prettyPrint (indent+6);
  182.       printf ("\n");
  183.       p = p->next;
  184.     }
  185.   }
  186.   if (offsetToSelector) {
  187.     offsetToSelector->printOffsetToSelector("OFFSET-TO-SELECTOR:");
  188.     // selectorToOffset->printSelectorToOffset();
  189.     // unavailableOffsets->printOffsetToSelector("UNAVAILABLE-OFFSETS:");
  190.   }
  191.  
  192.   // printIndent (indent+2);
  193.   // printf ("selectorMapping:\n");
  194.   // if (selectorMapping) {
  195.   //   selectorMapping->print (indent+4);
  196.   // } else {
  197.   //   printf ("NULL\n");
  198.   // }
  199.  
  200.   ppIndent (indent);
  201.   printf ("endInterface\n\n");
  202.   if (next) {
  203.     next->prettyPrint (indent);
  204.   }
  205. }
  206.  
  207.  
  208.  
  209. //----------  ClassDef  ----------
  210.  
  211. void ClassDef::prettyPrint (int indent) {
  212.   MethodProto * p;
  213.   Method * meth;
  214.   VarDecl * f;
  215.  
  216.   ppIndent (indent);
  217.   // printf ("[%08x:]", this);
  218.   printf ("class ");
  219.   printString (stdout, id);
  220.   printTypeParms (indent+8, typeParms);
  221.   // printf (" [sizeInBytes: %d]", sizeInBytes);
  222.   printf ("\n");
  223.   if (implements) {
  224.     ppIndent (indent+2);
  225.     printf ("implements ");
  226.     implements->prettyPrint (indent+6);
  227.     printf ("\n");
  228.   }
  229.   if (superclass) {
  230.     ppIndent (indent+2);
  231.     printf ("superclass ");
  232.     superclass->prettyPrint (indent+12);
  233.     printf ("\n");
  234.   }
  235.   ppIndent (indent+2);
  236.   printf ("typeOfSelf = ");
  237.   pretty (typeOfSelf);
  238.   if (fields) {
  239.     ppIndent (indent+2);
  240.     printf ("fields\n");
  241.     f = fields;
  242.     while (f != NULL) {
  243.       f->prettyPrint (indent+4);
  244.       f = f->next;
  245.     }
  246.   }
  247.   if (methodProtos) {
  248.     ppIndent (indent+2);
  249.     printf ("methods\n");
  250.     p = methodProtos;
  251.     while (p) {
  252.       ppIndent (indent+4);
  253.       p->prettyPrint (indent+6);
  254.       printf ("\n");
  255.       p = p->next;
  256.     }
  257.   }
  258.   // Methods come from the behavior, not the syntax.
  259.   if (methods) {
  260.     meth = methods;
  261.     while (meth) {
  262.       meth->prettyPrint (indent+2);
  263.       meth = meth->next;
  264.     }
  265.   }
  266.  
  267.   // ppIndent (indent);
  268.   // printf ("=====  localMethodMapping  =====\n");
  269.   // localMethodMapping->print (indent+4);
  270.  
  271.   // ppIndent (indent);
  272.   // printf ("=====  selectorMapping  =====\n");
  273.   // selectorMapping->print (indent+4);
  274.  
  275.   if (offsetToSelector) {
  276.     offsetToSelector->printOffsetToSelector("OFFSET-TO-SELECTOR:");
  277.     // selectorToOffset->printSelectorToOffset();
  278.     // unavailableOffsets->printOffsetToSelector("UNAVAILABLE-OFFSETS:");
  279.   }
  280.  
  281.   // printIndent (indent+2);
  282.   // printf ("selectorMapping:\n");
  283.   // if (selectorMapping) {
  284.   //   selectorMapping->print (indent+4);
  285.   // } else {
  286.   //   printf ("NULL\n");
  287.   // }
  288.  
  289.   ppIndent (indent);
  290.   printf ("endClass\n\n");
  291.   if (next) {
  292.     next->prettyPrint (indent);
  293.   }
  294. }
  295.  
  296.  
  297.  
  298. //----------  Behavior  ----------
  299.  
  300. void Behavior::prettyPrint (int indent) {
  301.   Method * p;
  302.  
  303.   printf ("\n");
  304.   ppIndent (indent);
  305.   printf ("behavior ");
  306.   printString (stdout, id);
  307.   printf ("\n");
  308.  
  309.   if (methods) {
  310.     p = methods;
  311.     while (p) {
  312.       p->prettyPrint (indent+2);
  313.       p = p->next;
  314.     }
  315.   }
  316.  
  317.   ppIndent (indent);
  318.   printf ("endBehavior\n");
  319.   if (next) {
  320.     next->prettyPrint (indent);
  321.   }
  322. }
  323.  
  324.  
  325.  
  326. //----------  TypeDef  ----------
  327.  
  328. void TypeDef::prettyPrint (int indent) {
  329.   ppIndent (indent);
  330.   // printf ("[%08x:]", this);
  331.   printString (stdout, id);
  332.   printf (" = ");
  333.   type->prettyPrint (indent+2);
  334.   printf ("\n");
  335. }
  336.  
  337.  
  338.  
  339. //----------  ConstDecl  ----------
  340.  
  341. void ConstDecl::prettyPrint (int indent) {
  342.   ppIndent (indent);
  343.   printString (stdout, id);
  344.   // printf (" [%08x] ", this);
  345.   printf (" = ");
  346.   expr->prettyPrint (indent+2);
  347.   printf ("\n");
  348. }
  349.  
  350.  
  351.  
  352. //----------  ErrorDecl  ----------
  353.  
  354. void ErrorDecl::prettyPrint (int indent) {
  355.   ppIndent (indent);
  356.   // printf (" [ %08x: ] ", this);
  357.   printString (stdout, id);
  358.   printParmList (indent+8, parmList);
  359.   printf ("\n");
  360. }
  361.  
  362.  
  363.  
  364. //----------  FunctionProto  ----------
  365.  
  366. void FunctionProto::prettyPrint (int indent) {
  367.   ppIndent (indent);
  368.   if (isExternal) {
  369.     printf ("external ");
  370.   }
  371.   if (id != NULL) {
  372.     printString (stdout, id);
  373.   }
  374.   // printf (" [%08x] ", this);
  375.   printParmList (indent+8, parmList);
  376.   if (!isVoidType (retType)) {
  377.     printf (" returns ");
  378.     retType->prettyPrint (indent+12);
  379.   }
  380.   // printf (" [myFunction=%08x] ", myFunction);
  381.   printf ("\n");
  382. }
  383.  
  384.  
  385.  
  386. //----------  MethodProto  ----------
  387.  
  388. void MethodProto::prettyPrint (int indent) {
  389.   if (kind == NORMAL) {
  390.   } else if (kind == KEYWORD) {
  391.     //  This prints like "at:put: (x:int, y:int)", which is adequate...
  392.   } else if (kind == INFIX) {
  393.     printf ("infix ");
  394.   } else if (kind == PREFIX) {
  395.     printf ("prefix ");
  396.   } else {
  397.     printf ("**********  unknown kind in methodProto  ********** ");
  398.   }
  399.   if (selector != NULL) {
  400.     printString (stdout, selector);
  401.   }
  402.   printParmList (indent+8, parmList);
  403.   if (!isVoidType (retType)) {
  404.     printf (" returns ");
  405.     retType->prettyPrint (indent+12);
  406.   }
  407.   // printf ("\t\tthis = %08x ", this);
  408.   // printf ("    myMethod = %08x", myMethod);
  409.   // if (!myMethod) {
  410.   //   printf ("**********  myMethod is NULL  ********** ");
  411.   // }
  412. }
  413.  
  414.  
  415.  
  416. //----------  MethOrFunction  ----------
  417.  
  418. void MethOrFunction::prettyPrint (int indent) {
  419.   printf ("prettyPrint (MethOrFunction) not implemented\n");
  420. }
  421.  
  422.  
  423.  
  424. //----------  Function  ----------
  425.  
  426. void Function::prettyPrint (int indent) {
  427.   Catch * cat;
  428.   ppIndent (indent);
  429.   printf ("function");
  430.   if (id != NULL) {
  431.     printf (" ");
  432.     printString (stdout, id);
  433.   }
  434.   // printf (" [%08x] ", this);
  435.   printParmList (indent+8, parmList);
  436.   if (!isVoidType (retType)) {
  437.     printf (" returns ");
  438.     retType->prettyPrint (indent+12);
  439.   }
  440.   // printf (" [maxArgBytes=%08x] ", maxArgBytes);
  441.   // printf (" [myProto=%08x] ", myProto);
  442.   // printf (" [sizeInBytes: %d]", sizeInBytes);
  443.   // printf (" [containsTry: %d]", containsTry);
  444.   printf ("\n");
  445.  
  446.   for (cat=catchList; cat; cat=cat->nextInMethOrFunction) {
  447.     ppIndent (indent+6);
  448.     printf ("catches %s  label=%s\n", cat->id->chars, cat->label);
  449.   }
  450.   printVarDecls (indent+4, locals);
  451.   printStmtList (indent+4, stmts);
  452.   ppLine (indent+2, "endFunction");
  453. }
  454.  
  455.  
  456.  
  457. //----------  Method  ----------
  458.  
  459. void Method::prettyPrint (int indent) {
  460.   Catch * cat;
  461.   ppIndent (indent);
  462.   printf ("method ");
  463.   if (kind == NORMAL) {
  464.   } else if (kind == KEYWORD) {
  465.     //  This prints like "at:put: (x:int, y:int)", which is adequate...
  466.   } else if (kind == INFIX) {
  467.     printf ("infix ");
  468.   } else if (kind == PREFIX) {
  469.     printf ("prefix ");
  470.   } else {
  471.     printf ("**********  unknown kind in methodProto  ********** ");
  472.   }
  473.   if (selector != NULL) {
  474.     printString (stdout, selector);
  475.   }
  476.   printParmList (indent+8, parmList);
  477.   if (!isVoidType (retType)) {
  478.     printf (" returns ");
  479.     retType->prettyPrint (indent+8);
  480.   }
  481.   // printf ("\t\tthis = %08x ", this);
  482.   // printf ("   myMethodProto = %08x", myMethodProto);
  483.   // printf (" [containsTry: %d]", containsTry);
  484.   // if (! myMethodProto) {
  485.   //   printf ("**********  myMethodProto is NULL  ********** ");
  486.   // }
  487.   // printf ("   sizeInBytes = %d", sizeInBytes);
  488.  
  489.   printf ("\n");
  490.  
  491.   for (cat=catchList; cat; cat=cat->nextInMethOrFunction) {
  492.     ppIndent (indent+6);
  493.     printf ("catches %s  label=%s\n", cat->id->chars, cat->label);
  494.   }
  495.   printVarDecls (indent+4, locals);
  496.   printStmtList (indent+4, stmts);
  497.   ppLine (indent+2, "endMethod");
  498. }
  499.  
  500.  
  501.  
  502. //----------  TypeParm  ----------
  503.  
  504. void TypeParm::prettyPrint (int indent) {
  505.   // printf ("[%08x:]", this);
  506.   printString (stdout, id);
  507.   printf (": ");
  508.   type->prettyPrint (indent);
  509.   if (fourByteRestricted) {
  510.     printf ("[fourByteRestricted]");
  511.   }
  512.   if (next != NULL) {
  513.     printf (", ");
  514.     next->prettyPrint (indent);
  515.   }
  516. }
  517.  
  518.  
  519.  
  520. //----------  TypeArg  ----------
  521.  
  522. void TypeArg::prettyPrint (int indent) {
  523.   type->prettyPrint (indent);
  524.   if (next != NULL) {
  525.     printf (", ");
  526.     next->prettyPrint (indent);
  527.   }
  528. }
  529.  
  530.  
  531.  
  532. //----------  Type  ----------
  533.  
  534. void Type::prettyPrint (int indent) {
  535.   printf ("prettyPrint (Type) should have been overridden\n");
  536. }
  537.  
  538.  
  539.  
  540. //----------  CharType  ----------
  541.  
  542. void CharType::prettyPrint (int indent) {
  543.   printf ("char");
  544. }
  545.  
  546.  
  547.  
  548. //----------  IntType  ----------
  549.  
  550. void IntType::prettyPrint (int indent) {
  551.   printf ("int");
  552. }
  553.  
  554.  
  555.  
  556. //----------  DoubleType  ----------
  557.  
  558. void DoubleType::prettyPrint (int indent) {
  559.   printf ("double");
  560. }
  561.  
  562.  
  563.  
  564. //----------  BoolType  ----------
  565.  
  566. void BoolType::prettyPrint (int indent) {
  567.   printf ("bool");
  568. }
  569.  
  570.  
  571.  
  572. //----------  VoidType  ----------
  573.  
  574. void VoidType::prettyPrint (int indent) {
  575.   printf ("void");
  576. }
  577.  
  578.  
  579.  
  580. //----------  TypeOfNullType  ----------
  581.  
  582. void TypeOfNullType::prettyPrint (int indent) {
  583.   printf ("typeOfNull");
  584. }
  585.  
  586.  
  587.  
  588. //----------  AnyType  ----------
  589.  
  590. void AnyType::prettyPrint (int indent) {
  591.   printf ("anyType");
  592. }
  593.  
  594.  
  595.  
  596. //----------  PtrType  ----------
  597.  
  598. void PtrType::prettyPrint (int indent) {
  599.   printf ("ptr to ");
  600.   baseType->prettyPrint (indent);
  601. }
  602.  
  603.  
  604.  
  605. //----------  ArrayType  ----------
  606.  
  607. void ArrayType::prettyPrint (int indent) {
  608.   printf ("array [");
  609.   if (sizeExpr == NULL) {
  610.     printf ("*");
  611.   } else {
  612.     sizeExpr->prettyPrint (indent+2);
  613.   }
  614.   //printf (" (sizeInBytes=%d)", sizeInBytes);
  615.   //printf (" (sizeOfElements=%d)", sizeOfElements);
  616.   printf ("] of ");
  617.   baseType->prettyPrint (indent);
  618. }
  619.  
  620.  
  621.  
  622. //----------  RecordType  ----------
  623.  
  624. void RecordType::prettyPrint (int indent) {
  625.   VarDecl * field;
  626.   printf ("record\n");
  627.   for (field = fields; field != NULL; field = field->next) {
  628.     field->prettyPrint (indent+2);
  629. /***
  630.     ppIndent (indent+2);
  631.     printString (stdout, field->id);
  632.     printf (": ");
  633.     field->type->prettyPrint (indent+4);
  634. ***/
  635. //  if (field->next) {
  636.       printf ("\n");
  637. //  } else {
  638. //    printf (" ");
  639. //  }
  640.   }
  641.  
  642.   // ppIndent (indent);
  643.   // printf ("=====  fieldMapping  =====\n");
  644.   // fieldMapping->print (indent+4);
  645.  
  646.   ppIndent (indent);
  647.   printf ("endRecord");
  648.   // printf (" [sizeInBytes: %d]", sizeInBytes);
  649. }
  650.  
  651.  
  652.  
  653. //----------  FunctionType  ----------
  654.  
  655. void FunctionType::prettyPrint (int indent) {
  656.   printf ("function (");
  657.   if (parmTypes != NULL) {
  658.     parmTypes->prettyPrint (indent);
  659.   }
  660.   printf (")");
  661.   if (retType == NULL) {
  662.     printf ("**********  retType is NULL!  **********");
  663.   } else if (! isVoidType (retType)) {
  664.     printf (" returns ");
  665.     retType->prettyPrint (indent);
  666.   }
  667. }
  668.  
  669.  
  670.  
  671. //----------  NamedType  ----------
  672.  
  673. void NamedType::prettyPrint (int indent) {
  674.   if (id) {
  675.     printString (stdout, id);
  676.   } else {
  677.     printf ("**********  ID IS NULL  **********");
  678.   }
  679.   if (typeArgs != NULL) {
  680.     printf (" [");
  681.     typeArgs->prettyPrint (indent);
  682.     printf ("]");
  683.   }
  684.   // printf ("[myDef=%08x]", myDef);
  685.   // if (myDef == NULL) {
  686.   //   printf ("**********  myDef == NULL  **********");
  687.   // }
  688.   // printf ("\n=====  subst  =====\n");
  689.   // subst->print (indent+4);
  690.   // ppIndent (indent);
  691. }
  692.  
  693.  
  694.  
  695. //----------  Statement  ----------
  696.  
  697. void Statement::prettyPrint (int indent) {
  698.   printf ("prettyPrint (Statement) not implemented\n");
  699. }
  700.  
  701.  
  702.  
  703. //----------  IfStmt  ----------
  704.  
  705. void IfStmt::prettyPrint (int indent) {
  706.   ppIndent (indent);
  707.   printf ("if ");
  708.   expr->prettyPrint (indent+8);
  709.   printf ("\n");
  710.   printStmtList (indent+2, thenStmts);
  711.   if (elseStmts != NULL) {
  712.     ppLine (indent, "else");
  713.     printStmtList (indent+2, elseStmts);
  714.   }
  715.   ppLine (indent, "endIf");
  716. }
  717.  
  718.  
  719.  
  720. //----------  AssignStmt  ----------
  721.  
  722. void AssignStmt::prettyPrint (int indent) {
  723.   ppIndent (indent);
  724.   lvalue->prettyPrint (indent+8);
  725.   printf (" = ");
  726.   expr->prettyPrint (indent+8);
  727.   // printf (" [size=%d] ", sizeInBytes);
  728.   // if (dynamicCheck != 0) {
  729.   //   printf ("   -- dynamicCheck = %d", dynamicCheck);
  730.   // }
  731.   printf ("\n");
  732. }
  733.  
  734.  
  735.  
  736. //----------  CallStmt  ----------
  737.  
  738. void CallStmt::prettyPrint (int indent) {
  739.   ppIndent (indent);
  740.   if (expr) {
  741.     expr->prettyPrint (indent+4);
  742.   } else {
  743.     printf ("**********  callStmt encountered with expr == NULL  **********");
  744.   }
  745.   printf ("\n");
  746. }
  747.  
  748.  
  749.  
  750. //----------  SendStmt  ----------
  751.  
  752. void SendStmt::prettyPrint (int indent) {
  753.   ppIndent (indent);
  754.   expr->prettyPrint (indent+4);
  755.   printf ("\n");
  756. }
  757.  
  758.  
  759.  
  760. //----------  WhileStmt  ----------
  761.  
  762. void WhileStmt::prettyPrint (int indent) {
  763.   ppIndent (indent);
  764.   printf ("while ");
  765.   expr->prettyPrint (indent+8);
  766.   printf ("\n");
  767.   printStmtList (indent+2, stmts);
  768.   ppLine (indent, "endWhile");
  769. }
  770.  
  771.  
  772.  
  773. //----------  DoStmt  ----------
  774.  
  775. void DoStmt::prettyPrint (int indent) {
  776.   ppLine (indent, "do");
  777.   printStmtList (indent+2, stmts);
  778.   ppIndent (indent);
  779.   printf ("until ");
  780.   expr->prettyPrint (indent+8);
  781.   printf ("\n");
  782. }
  783.  
  784.  
  785.  
  786. //----------  BreakStmt  ----------
  787.  
  788. void BreakStmt::prettyPrint (int indent) {
  789.   ppIndent (indent);
  790.   // printf ("[enclosingStmt=0x%08x] ", enclosingStmt);
  791.   if (enclosingStmt == NULL) {
  792.     printf ("  ***************  enclosingStmt==NULL  *************** ");
  793.   }
  794.   printf ("break\n");
  795. }
  796.  
  797.  
  798.  
  799. //----------  ContinueStmt  ----------
  800.  
  801. void ContinueStmt::prettyPrint (int indent) {
  802.   ppIndent (indent);
  803.   // printf ("[enclosingStmt=0x%08x] ", enclosingStmt);
  804.   if (enclosingStmt == NULL) {
  805.     printf ("  ***************  enclosingStmt==NULL  *************** ");
  806.   }
  807.   printf ("continue\n");
  808. }
  809.  
  810.  
  811.  
  812. //----------  ReturnStmt  ----------
  813.  
  814. void ReturnStmt::prettyPrint (int indent) {
  815.   ppIndent (indent);
  816.   printf ("return ");
  817.   if (expr) {
  818.     expr->prettyPrint (indent+8);
  819.   }
  820.   if (enclosingMethOrFunction == NULL) {
  821.     printf ("  ***************  enclosingMethOrFunction==NULL  *************** ");
  822.   }
  823.   // printf (" [enclosingMethOrFunction = 0x%08x]", enclosingMethOrFunction);
  824.   printf ("\n");
  825. }
  826.  
  827.  
  828.  
  829. //----------  ForStmt  ----------
  830.  
  831. void ForStmt::prettyPrint (int indent) {
  832.   ppIndent (indent);
  833.   printf ("for ");
  834.   lvalue->prettyPrint (indent+8);
  835.   printf (" = ");
  836.   expr1->prettyPrint (indent+8);
  837.   printf (" to ");
  838.   expr2->prettyPrint (indent+8);
  839.   if (expr3 != NULL) {
  840.     printf (" by ");
  841.     expr3->prettyPrint (indent+8);
  842.   }
  843.   printf ("\n");
  844.   printStmtList (indent+2, stmts);
  845.   ppLine (indent, "endFor");
  846. }
  847.  
  848.  
  849.  
  850. //----------  SwitchStmt  ----------
  851.  
  852. void SwitchStmt::prettyPrint (int indent) {
  853.   Case * cas;
  854.   ppIndent (indent);
  855.   printf ("switch ");
  856.   expr->prettyPrint (indent+8);
  857.   // printf (" [lowValue=%d, highValue=%d]", lowValue, highValue);
  858.   printf ("\n");
  859.   cas = caseList;
  860.   while (cas != NULL) {
  861.     cas->prettyPrint (indent+2);
  862.     cas = cas->next;
  863.   }
  864.   if (defaultIncluded) {
  865.     ppLine (indent+2, "default:");
  866.     printStmtList (indent+4, defaultStmts);
  867.   }
  868.   ppLine (indent, "endSwitch");
  869. }
  870.  
  871.  
  872.  
  873. //----------  TryStmt  ----------
  874.  
  875. void TryStmt::prettyPrint (int indent) {
  876.   Catch * cat;
  877.   ppLine (indent, "try");
  878.   printStmtList (indent+4, stmts);
  879.   cat = catchList;
  880.   while (cat != NULL) {
  881.     cat->prettyPrint (indent+2);
  882.     cat = cat->next;
  883.   }
  884.   ppLine (indent, "endTry");
  885. }
  886.  
  887.  
  888.  
  889. //----------  ThrowStmt  ----------
  890.  
  891. void ThrowStmt::prettyPrint (int indent) {
  892.   ppIndent (indent);
  893.   printf ("throw ");
  894.   if (id) {
  895.     printString (stdout, id);
  896.   } else {
  897.     printf ("**********  ID IS NULL  **********");
  898.   }
  899.   printf (" (");
  900.   if (argList) {
  901.     argList->prettyPrint (indent);
  902.   }
  903.   printf (")");
  904.   // if (myDef == NULL) {
  905.   //   printf (" **********  myDef IS NULL  **********");
  906.   // }
  907.   // printf (" [myDef=%08x]", myDef);
  908.   printf ("\n");
  909. }
  910.  
  911.  
  912.  
  913. //----------  FreeStmt  ----------
  914.  
  915. void FreeStmt::prettyPrint (int indent) {
  916.   ppIndent (indent);
  917.   printf ("free (");
  918.   expr->prettyPrint (indent);
  919.   printf (")\n");
  920. }
  921.  
  922.  
  923.  
  924. //----------  DebugStmt  ----------
  925.  
  926. void DebugStmt::prettyPrint (int indent) {
  927.   ppIndent (indent);
  928.   printf ("debug\n");
  929. }
  930.  
  931.  
  932.  
  933. //----------  Case  ----------
  934.  
  935. void Case::prettyPrint (int indent) {
  936.   ppIndent (indent);
  937.   printf ("case ");
  938.   expr->prettyPrint (indent+8);
  939.   // printf (" [ivalue=%d]", ivalue);
  940.   printf (":\n");
  941.   printStmtList (indent+2, stmts);
  942. }
  943.  
  944.  
  945.  
  946. //----------  Catch  ----------
  947.  
  948. void Catch::prettyPrint (int indent) {
  949.   ppIndent (indent);
  950.   printf ("catch ");
  951.   if (id) {
  952.     printString (stdout, id);
  953.   } else {
  954.     printf ("**********  ID IS NULL  **********");
  955.   }
  956.   printParmList (indent+8, parmList);
  957.   printf (":");
  958.   // if (myDef == NULL) {
  959.   //   printf (" **********  myDef IS NULL  **********");
  960.   // }
  961.   // printf (" [myDef=%08x]", myDef);
  962.   printf ("\n");
  963.   printStmtList (indent+2, stmts);
  964. }
  965.  
  966.  
  967.  
  968. //----------  VarDecl  ----------
  969.  
  970. void VarDecl::prettyPrint (int indent) {
  971.   printf ("prettyPrint (VarDecl) not implemented\n");
  972. }
  973.  
  974.  
  975.  
  976. //----------  Global  ----------
  977.  
  978. void Global::prettyPrint (int indent) {
  979.   if (id) {
  980.     printString (stdout, id);
  981.   } else {
  982.     printf ("**********  ID IS NULL  **********");
  983.   }
  984.   // printf (" [%08x] ", this);
  985.   printf (": ");
  986.   type->prettyPrint (indent);
  987.   if (initExpr != NULL) {
  988.   printf (" = ");
  989.     initExpr->prettyPrint (indent);
  990.   }
  991.   if (offset != -1) {
  992.     printf (" **********  offset is not -1  **********");
  993.   }
  994.   // if (sizeInBytes < 0) {
  995.   //   printf (" **********  sizeInBytes is missing  **********");
  996.   // }
  997.   // printf ("   [size=%d]", sizeInBytes);
  998. }
  999.  
  1000.  
  1001.  
  1002. //----------  Local  ----------
  1003.  
  1004. void Local::prettyPrint (int indent) {
  1005.   if (id) {
  1006.     printString (stdout, id);
  1007.   } else {
  1008.     printf ("**********  ID IS NULL  **********");
  1009.   }
  1010.   // printf (" [%08x] ", this);
  1011.   printf (": ");
  1012.   if (type) {
  1013.     type->prettyPrint (indent);
  1014.   } else {
  1015.     printf ("TEMPORARY");
  1016.   }
  1017.   if (initExpr != NULL) {
  1018.   printf (" = ");
  1019.     initExpr->prettyPrint (indent);
  1020.   }
  1021.   // if (offset > -9) {
  1022.   //   printf (" **********  offset is > -9  **********");
  1023.   // }
  1024.   // if (sizeInBytes < 0) {
  1025.   //   printf (" **********  sizeInBytes is missing  **********");
  1026.   // }
  1027.   // printf ("   [offset=%d, size=%d] ", offset, sizeInBytes);
  1028.   // printf (" [offset= %d]", offset);
  1029. }
  1030.  
  1031.  
  1032.  
  1033. //----------  Parameter  ----------
  1034.  
  1035. void Parameter::prettyPrint (int indent) {
  1036.   if (id) {
  1037.     printString (stdout, id);
  1038.   } else {
  1039.     printf ("**********  ID IS NULL  **********");
  1040.   }
  1041.   // printf (" [%08x] ", this);
  1042.   printf (": ");
  1043.   type->prettyPrint (indent);
  1044.   // printf (" [offset= %d]", offset);
  1045.   // if (offset < 0) {
  1046.   //   printf (" **********  offset is missing  **********");
  1047.   // }
  1048.   // if (sizeInBytes < 0) {
  1049.   //   printf (" **********  sizeInBytes is missing  **********");
  1050.   // }
  1051.   // printf ("   [offset=%d, size=%d] ", offset, sizeInBytes);
  1052.   if (next) {
  1053.     printf (", ");
  1054.     next->prettyPrint (indent);
  1055.   }
  1056. }
  1057.  
  1058.  
  1059.  
  1060. //----------  ClassField  ----------
  1061.  
  1062. void ClassField::prettyPrint (int indent) {
  1063.   ppIndent (indent);
  1064.   printString (stdout, id);
  1065.   // printf (" [%08x] ", this);
  1066.   printf (": ");
  1067.   type->prettyPrint (indent);
  1068.   // printf ("   [offset= %d] ", offset);
  1069.   // if (offset < 0) {
  1070.   //   printf (" **********  offset is missing  **********");
  1071.   // }
  1072.   // if (sizeInBytes < 0) {
  1073.   //   printf (" **********  sizeInBytes is missing  **********");
  1074.   // }
  1075.   // printf ("   [offset=%d, size=%d] ", offset, sizeInBytes);
  1076.   printf ("\n");
  1077. }
  1078.  
  1079.  
  1080.  
  1081. //----------  RecordField  ----------
  1082.  
  1083. void RecordField::prettyPrint (int indent) {
  1084.   ppIndent (indent);
  1085.   if (id) {
  1086.     printString (stdout, id);
  1087.   } else {
  1088.     printf ("**********  ID IS NULL  **********");
  1089.   }
  1090.   printf (": ");
  1091.   type->prettyPrint (indent);
  1092.   // if (offset < 0) {
  1093.   //   printf (" **********  offset is missing  **********");
  1094.   // }
  1095.   // if (sizeInBytes < 0) {
  1096.   //   printf (" **********  sizeInBytes is missing  **********");
  1097.   // }
  1098.   // printf (" [offset= %d]", offset);
  1099.   // printf ("   [offset=%d, size=%d] ", offset, sizeInBytes);
  1100. }
  1101.  
  1102.  
  1103.  
  1104. //----------  Expression  ----------
  1105.  
  1106. void Expression::prettyPrint (int indent) {
  1107.   printf ("prettyPrint (Expression) not implemented\n");
  1108. }
  1109.  
  1110.  
  1111.  
  1112. //----------  Constant  ----------
  1113.  
  1114. void Constant::prettyPrint (int indent) {
  1115.   printf ("prettyPrint (Constant) not implemented\n");
  1116. }
  1117.  
  1118.  
  1119.  
  1120. //----------  IntConst  ----------
  1121.  
  1122. void IntConst::prettyPrint (int indent) {
  1123.   printf ("%d", ivalue);
  1124. }
  1125.  
  1126.  
  1127.  
  1128. //----------  DoubleConst  ----------
  1129.  
  1130. void DoubleConst::prettyPrint (int indent) {
  1131.   int * p;
  1132.   double r = 0.0;
  1133.  
  1134.   if (rvalue == (-1.0) / r) {
  1135.     printf ("<NegativeInfinity>");
  1136.   } else if (rvalue == (+1.0) / r) {
  1137.     printf ("<PositiveInfinity>");
  1138.   } else if (isnan (rvalue)) {
  1139.     printf ("<Not-A-Number>");
  1140.   } else if (rvalue == 0.0 && 1.0/rvalue < 0.0) {
  1141.     printf ("<NegativeZero>");
  1142.   } else {
  1143.     printf ("%.16gD", rvalue);
  1144.   }
  1145.   // p = (int *) & rvalue;
  1146.   // printf (" [0x%08x ", *p);
  1147.   // p++;
  1148.   // printf ("%08x]", *p);  
  1149. }
  1150.  
  1151.  
  1152.  
  1153. //----------  CharConst  ----------
  1154.  
  1155. void CharConst::prettyPrint (int indent) {
  1156.   printf ("\'");
  1157.   printChar (stdout, ivalue);
  1158.   printf ("\'");
  1159.   if ((ivalue & 0xffffff00) != 0) {
  1160.     printf ("**********  ivalue out of range = 0x%08x  **********", ivalue);
  1161.   }
  1162. }
  1163.  
  1164.  
  1165.  
  1166. //----------  StringConst  ----------
  1167.  
  1168. void StringConst::prettyPrint (int indent) {
  1169.   printf ("\"");
  1170.   printString (stdout, svalue);
  1171.   printf ("\"");
  1172. }
  1173.  
  1174.  
  1175.  
  1176. //----------  BoolConst  ----------
  1177.  
  1178. void BoolConst::prettyPrint (int indent) {
  1179.   if (ivalue) {
  1180.     printf ("true");
  1181.   } else {
  1182.     printf ("false");
  1183.   }
  1184. }
  1185.  
  1186.  
  1187.  
  1188. //----------  NullConst  ----------
  1189.  
  1190. void NullConst::prettyPrint (int indent) {
  1191.   printf ("null");
  1192. }
  1193.  
  1194.  
  1195.  
  1196. //----------  CallExpr  ----------
  1197.  
  1198. void CallExpr::prettyPrint (int indent) {
  1199.     if (id) {
  1200.       printString (stdout, id);
  1201.     } else {
  1202.       printf ("**********  id IS NULL  **********");
  1203.     }
  1204.     printf (" (");
  1205.     if (argList) {
  1206.       argList->prettyPrint (indent);
  1207.     }
  1208.     printf (")");
  1209.     // printf (" [myDef=%08x] ", myDef);
  1210.     // if (primitiveSymbol) {
  1211.     //   printf (" [primitiveSymbol=%s] ", symbolName (primitiveSymbol));
  1212.     // }
  1213. }
  1214.  
  1215.  
  1216.  
  1217. //----------  SendExpr  ----------
  1218.  
  1219. void SendExpr::prettyPrint (int indent) {
  1220.   if (kind == INFIX) {
  1221.     printf ("(");
  1222.     if (receiver) {
  1223.       receiver->prettyPrint (indent);
  1224.     } else {
  1225.       printf ("*****  recvr is null  *****");
  1226.     }
  1227.     printf (") ");
  1228.     if (selector) {
  1229.       printString (stdout, selector);
  1230.     } else {
  1231.       printf ("**********  selector IS NULL in SendExpr  **********");
  1232.     }
  1233.     printf (" (");
  1234.     if (argList) {
  1235.       argList->prettyPrint (indent);
  1236.     }
  1237.     printf (")");
  1238.   } else if (kind == PREFIX) {
  1239.     if (selector) {
  1240.       printString (stdout, selector);
  1241.     } else {
  1242.       printf ("**********  selector IS NULL in SendExpr  **********");
  1243.     }
  1244.     printf (" (");
  1245.     if (receiver) {
  1246.       receiver->prettyPrint (indent);
  1247.     } else {
  1248.       printf ("*****  recvr is null  *****");
  1249.     }
  1250.     printf (")");
  1251.   } else if (kind == NORMAL) {
  1252.     printf ("(");
  1253.     if (receiver) {
  1254.       receiver->prettyPrint (indent);
  1255.     } else {
  1256.       printf ("*****  recvr is null  *****");
  1257.     }
  1258.     printf (").");
  1259.     if (selector) {
  1260.       printString (stdout, selector);
  1261.     } else {
  1262.       printf ("**********  selector IS NULL in SendExpr  **********");
  1263.     }
  1264.     printf (" (");
  1265.     if (argList) {
  1266.       argList->prettyPrint (indent);
  1267.     }
  1268.     printf (")");
  1269.   } else if (kind == KEYWORD) {
  1270.     printf ("(");
  1271.     if (receiver) {
  1272.       receiver->prettyPrint (indent);
  1273.     } else {
  1274.       printf ("*****  recvr is null  *****");
  1275.     }
  1276.     printf (") ");
  1277.     if (selector) {
  1278.       printString (stdout, selector);
  1279.     } else {
  1280.       printf ("**********  selector IS NULL in SendExpr  **********");
  1281.     }
  1282.     printf (" (");
  1283.     if (argList) {
  1284.       argList->prettyPrint (indent);
  1285.     }
  1286.     printf (")");
  1287.   } else {
  1288.     printf ("**********  Invalid kind in SendExpr  **********");
  1289.   }
  1290. /***
  1291.   if (primitiveSymbol) {
  1292.     printf (" [primitiveSymbol=%s] ", symbolName (primitiveSymbol));
  1293.   }
  1294. ***/
  1295.   // if (myProto) {
  1296.   //   printf (" [myProto=%08x] ", myProto);
  1297.   // }
  1298. // qqqq  Add this back for security while testing...
  1299.   // if ((myProto == NULL) && (primitiveSymbol == 0)) {
  1300.   //   printf ("**********  myProto and primitiveSymbol are missing  **********");
  1301.   // }
  1302. }
  1303.  
  1304.  
  1305.  
  1306. //----------  SelfExpr  ----------
  1307.  
  1308. void SelfExpr::prettyPrint (int indent) {
  1309.   printf ("self");
  1310. }
  1311.  
  1312.  
  1313.  
  1314. //----------  SuperExpr  ----------
  1315.  
  1316. void SuperExpr::prettyPrint (int indent) {
  1317.   printf ("super");
  1318. }
  1319.  
  1320.  
  1321.  
  1322. //----------  FieldAccess  ----------
  1323.  
  1324. void FieldAccess::prettyPrint (int indent) {
  1325.     printf ("(");
  1326.     expr->prettyPrint (indent);
  1327.     printf (").");
  1328.     if (id) {
  1329.       printString (stdout, id);
  1330.     } else {
  1331.       printf ("**********  id IS NULL  **********");
  1332.     }
  1333.     // printf ("[offset=%d]", offset);
  1334. }
  1335.  
  1336.  
  1337.  
  1338. //----------  ArrayAccess  ----------
  1339.  
  1340. void ArrayAccess::prettyPrint (int indent) {
  1341.     printf ("(");
  1342.     arrayExpr->prettyPrint (indent+2);
  1343.     printf (" [");
  1344.     indexExpr->prettyPrint (indent+4);
  1345.     printf ("]");
  1346.     // printf ("[sizeOfElements=%d]", sizeOfElements);
  1347.     printf (")");
  1348. }
  1349.  
  1350.  
  1351.  
  1352. //----------  Constructor  ----------
  1353.  
  1354. void Constructor::prettyPrint (int indent) {
  1355.  
  1356.   if (allocKind == NEW) {
  1357.     printf ("new ");
  1358.   } else if (allocKind == ALLOC) {
  1359.     printf ("alloc ");
  1360.   } else {
  1361.     programLogicError ("Unexpected allocKind in Constructor");
  1362.   }
  1363.  
  1364.   if (type) {
  1365.     type->prettyPrint (indent+8+12);
  1366.   } else {
  1367.     printf ("**********  type IS NULL  **********");
  1368.   }
  1369.   // printf (" [%s]", symbolName (kind));     // ARRAY, RECORD, CLASS; EOF=error
  1370.   // printf (" [sizeInBytes=%d]", sizeInBytes);
  1371.   // if (myClass) {
  1372.   //   printf (" [myClass=%s]", myClass->id->chars);
  1373.   // } else {
  1374.   //   printf (" [myClass=NULL]");  // Will be null for Arrays & records
  1375.   // }
  1376.   if (countValueList) {
  1377.     printf (" {");
  1378.     countValueList->prettyPrint (indent+8+12);
  1379.     printf ("}");
  1380.   } else if (fieldInits) {
  1381.     printf (" {");
  1382.     fieldInits->prettyPrint (indent+8+12);
  1383.     printf ("}");
  1384.   }
  1385. }
  1386.  
  1387.  
  1388.  
  1389. //----------  ClosureExpr  ----------
  1390.  
  1391. void ClosureExpr::prettyPrint (int indent) {
  1392.   printf ("\n");
  1393.   function->prettyPrint (indent);
  1394. }
  1395.  
  1396.  
  1397.  
  1398. //----------  VariableExpr  ----------
  1399.  
  1400. void VariableExpr::prettyPrint (int indent) {
  1401.   printString (stdout, id);
  1402.   // printf ("[myDef=%08x]", myDef);
  1403. }
  1404.  
  1405.  
  1406.  
  1407. //----------  AsPtrToExpr  ----------
  1408.  
  1409. void AsPtrToExpr::prettyPrint (int indent) {
  1410.   printf ("(");
  1411.   expr->prettyPrint (indent);
  1412.   printf (") asPtrTo ");
  1413.   type->prettyPrint (indent);
  1414. }
  1415.  
  1416.  
  1417.  
  1418. //----------  AsIntegerExpr  ----------
  1419.  
  1420. void AsIntegerExpr::prettyPrint (int indent) {
  1421.   printf ("(");
  1422.   expr->prettyPrint (indent);
  1423.   printf (") asInteger");
  1424. }
  1425.  
  1426.  
  1427.  
  1428. //----------  ArraySizeExpr  ----------
  1429.  
  1430. void ArraySizeExpr::prettyPrint (int indent) {
  1431.   printf ("(");
  1432.   expr->prettyPrint (indent);
  1433.   printf (") arraySize");
  1434. }
  1435.  
  1436.  
  1437.  
  1438. //----------  IsInstanceOfExpr  ----------
  1439.  
  1440. void IsInstanceOfExpr::prettyPrint (int indent) {
  1441.   printf ("(");
  1442.   expr->prettyPrint (indent);
  1443.   printf (") isInstanceOf ");
  1444.   type->prettyPrint (indent);
  1445. }
  1446.  
  1447.  
  1448.  
  1449. //----------  IsKindOfExpr  ----------
  1450.  
  1451. void IsKindOfExpr::prettyPrint (int indent) {
  1452.   printf ("(");
  1453.   expr->prettyPrint (indent);
  1454.   printf (") isKindOf ");
  1455.   type->prettyPrint (indent);
  1456. }
  1457.  
  1458.  
  1459.  
  1460. //----------  SizeOfExpr  ----------
  1461.  
  1462. void SizeOfExpr::prettyPrint (int indent) {
  1463.   printf ("sizeOf (");
  1464.   type->prettyPrint (indent);
  1465.   printf (")");
  1466. }
  1467.  
  1468.  
  1469.  
  1470. //----------  DynamicCheck  ----------
  1471.  
  1472. void DynamicCheck::prettyPrint (int indent) {
  1473.   printf ("DynamicCheck (");
  1474.   expr->prettyPrint (indent);
  1475.   printf (", kind=%d, expectedArraySize=%d, arraySizeInBytes=%d)",
  1476.           kind, expectedArraySize, arraySizeInBytes);
  1477. }
  1478.  
  1479.  
  1480.  
  1481. //----------  Argument  ----------
  1482.  
  1483. void Argument::prettyPrint (int indent) {
  1484.   expr->prettyPrint (indent);
  1485.   if (next != NULL) {
  1486.     printf (", ");
  1487.     next->prettyPrint (indent);
  1488.   }
  1489. }
  1490.  
  1491.  
  1492.  
  1493. //----------  CountValue  ----------
  1494.  
  1495. void CountValue::prettyPrint (int indent) {
  1496.   if (count) {
  1497.     count->prettyPrint (indent);
  1498.     printf (" of ");
  1499.   }
  1500.   value->prettyPrint (indent);
  1501.   if (next != NULL) {
  1502.     printf (", ");
  1503.     next->prettyPrint (indent);
  1504.   }
  1505. }
  1506.  
  1507.  
  1508.  
  1509. //----------  FieldInit  ----------
  1510.  
  1511. void FieldInit::prettyPrint (int indent) {
  1512.   if (id) {
  1513.     printString (stdout, id);
  1514.   } else {
  1515.     printf ("**********  id IS NULL  **********");
  1516.   }
  1517.   printf (" = ");
  1518.   expr->prettyPrint (indent);
  1519.   // if (offset < 0) {
  1520.   //   printf (" **********  offset is missing  **********");
  1521.   // }
  1522.   // if (sizeInBytes < 0) {
  1523.   //   printf (" **********  sizeInBytes is missing  **********");
  1524.   // }
  1525.   // printf (" [offset=%d, size=%d]", offset, sizeInBytes);
  1526.   if (next != NULL) {
  1527.     printf (", ");
  1528.     next->prettyPrint (indent);
  1529.   }
  1530. }
  1531.  
  1532.  
  1533.  
  1534. // pretty (ast)
  1535. //
  1536. // This routine prints the given ast node, followed by a newline.  It is used
  1537. // in debugging.
  1538. //
  1539. void pretty (AstNode * ast) {
  1540.   if (ast) {
  1541.     ast->prettyPrint (4);
  1542.     printf ("\n");
  1543.   } else {
  1544.     printf ("NULL\n");
  1545.   }
  1546. }
  1547.  
  1548.  
  1549.  
  1550. // pretty2 (ast)
  1551. //
  1552. // This routine prettyPrints the given ast node.  If passed NULL,
  1553. // it simply prints it.  It does not print a newline.
  1554. //
  1555. void pretty2 (int indent, AstNode * ast) {
  1556.   if (ast) {
  1557.     ast->prettyPrint (10);
  1558.   } else {
  1559.     printf ("NULL");
  1560.   }
  1561. }
  1562.  
  1563.  
  1564.  
  1565. // printStmtList (in, stmtList)
  1566. //
  1567. // Print out the list of statments, indented by "in", each on a separate
  1568. // line.
  1569. //
  1570. void printStmtList (int indent, Statement * p) {
  1571.   while (p != NULL) {
  1572. /****
  1573.     fflush (stdout);
  1574.     printf ("<<<");
  1575.     printf ("p=%08x ", p);
  1576.     printf ("p->op=%d ", p->op);
  1577.     fflush (stdout);
  1578.     printf ("p->op=%s", symbolName (p->op));
  1579.     printf (">>>");
  1580.     fflush (stdout);
  1581. ****/
  1582.     p->prettyPrint (indent);
  1583.     p = p->next;
  1584.   }
  1585. }
  1586.  
  1587.  
  1588.  
  1589. // printVarDecls (in, list)
  1590. //
  1591. // Print out the list of VarDecls, indented by "in", each on a separate
  1592. // line.
  1593. //
  1594. void printVarDecls (int indent, VarDecl * p) {
  1595.   if (p == NULL) {
  1596.     return;
  1597.   }
  1598.   ppIndent (indent);
  1599.   printf ("var ");
  1600.   p->prettyPrint (indent+4);
  1601.   printf ("\n");
  1602.   p = p->next;
  1603.   while (p != NULL) {
  1604. /****
  1605.     fflush (stdout);
  1606.     printf ("<<<");
  1607.     printf ("p=%08x ", p);
  1608.     printf ("p->op=%d ", p->op);
  1609.     fflush (stdout);
  1610.     printf ("p->op=%s", symbolName (p->op));
  1611.     printf (">>>");
  1612.     fflush (stdout);
  1613. ****/
  1614.     ppIndent (indent+4);
  1615.     p->prettyPrint (indent+4);
  1616.     printf ("\n");
  1617.     p = p->next;
  1618.   }
  1619. }
  1620.  
  1621.  
  1622.  
  1623. // printConsts (in, list)
  1624. //
  1625. // Print out the list of ConstDecls, indented by "in", each on a separate line.
  1626. //
  1627. void printConsts (int indent, ConstDecl * p) {
  1628.   if (p == NULL) {
  1629.     return;
  1630.   }
  1631.   ppIndent (indent);
  1632.   printf ("const\n");
  1633.   while (p != NULL) {
  1634.     p->prettyPrint (indent+2);
  1635.     p = p->next;
  1636.   }
  1637. }
  1638.  
  1639.  
  1640.  
  1641. // printErrorDecls (in, list)
  1642. //
  1643. // Print out the list of ErrorDecls, indented by "in", each on a separate line.
  1644. //
  1645. void printErrorDecls (int indent, ErrorDecl * p) {
  1646.   if (p == NULL) {
  1647.     return;
  1648.   }
  1649.   ppIndent (indent);
  1650.   printf ("errors\n");
  1651.   while (p != NULL) {
  1652.     p->prettyPrint (indent+2);
  1653.     p = p->next;
  1654.   }
  1655. }
  1656.  
  1657.  
  1658.  
  1659. // printTypeDefs (in, list)
  1660. //
  1661. // Print out the list of TypeDefs, indented by "in", each on a separate line.
  1662. //
  1663. void printTypeDefs (int indent, TypeDef * p) {
  1664.   if (p == NULL) {
  1665.     return;
  1666.   }
  1667.   ppIndent (indent);
  1668.   printf ("type\n");
  1669.   while (p != NULL) {
  1670.     p->prettyPrint (indent+2);
  1671.     p = p->next;
  1672.   }
  1673. }
  1674.  
  1675.  
  1676.  
  1677. // printFunctionProtos (in, list)
  1678. //
  1679. // Print out the list of FunctionProtos, indented by "in", each on a separate
  1680. // line.
  1681. //
  1682. void printFunctionProtos (int indent, FunctionProto * p) {
  1683.   if (p == NULL) {
  1684.     return;
  1685.   }
  1686.   ppIndent (indent);
  1687.   printf ("functions\n");
  1688.   while (p != NULL) {
  1689.     p->prettyPrint (indent+2);
  1690.     p = p->next;
  1691.   }
  1692. }
  1693.  
  1694.  
  1695.  
  1696. // printFunctions (in, list)
  1697. //
  1698. // Print out the list of Functions, indented by "in", each on a separate line.
  1699. //
  1700. void printFunctions (int indent, Function * p) {
  1701.   while (p != NULL) {
  1702.     p->prettyPrint (indent);
  1703.     printf ("\n");
  1704.     p = p->next;
  1705.   }
  1706. }
  1707.  
  1708.  
  1709.  
  1710. // printParmList (in, parmList)
  1711. //
  1712. // Print out the list of Parameter nodes.  For example:
  1713. //   ()
  1714. //   (x: int, y: double)
  1715. // A leading space is printed.
  1716. //
  1717. void printParmList (int indent, Parameter * parmList) {
  1718.   printf (" (");
  1719.   if (parmList != NULL) {
  1720.     parmList->prettyPrint (indent);
  1721.   }
  1722.   printf (")");
  1723. }
  1724.  
  1725.  
  1726.  
  1727. // printTypeParms (in, parmList)
  1728. //
  1729. // Print out the list of TypeParm nodes.  For example:
  1730. //   [T1: Object, T2:Person]
  1731. // A leading space is printed.
  1732. //
  1733. void printTypeParms (int indent, TypeParm * parmList) {
  1734.   if (parmList != NULL) {
  1735.     printf (" [");
  1736.     parmList->prettyPrint (indent);
  1737.     printf ("]");
  1738.   }
  1739. }
  1740.  
  1741.  
  1742.  
  1743. // ppIndent (indent)
  1744. //
  1745. // This routine prints "indent" space characters.
  1746. //
  1747. void ppIndent (int indent) {
  1748.   int i;
  1749.   for (i=indent; i>0; i--) {
  1750.     printf (" ");
  1751.   }
  1752. }
  1753.  
  1754.  
  1755.  
  1756. // ppLine (indent, str)
  1757. //
  1758. // This routine indents, then prints the given string, then prints newline.
  1759. //
  1760. void ppLine (int indent, char * str) {
  1761.   ppIndent (indent);
  1762.   printf ("%s\n", str);
  1763. }
  1764.