home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VPage / Java.bin / CLASSES.ZIP / sun / tools / tree / Expression.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-08  |  9.4 KB  |  454 lines

  1. package sun.tools.tree;
  2.  
  3. import java.io.PrintStream;
  4. import java.util.Hashtable;
  5. import sun.tools.asm.Assembler;
  6. import sun.tools.asm.Label;
  7. import sun.tools.java.AmbiguousField;
  8. import sun.tools.java.ClassDeclaration;
  9. import sun.tools.java.ClassDefinition;
  10. import sun.tools.java.ClassNotFound;
  11. import sun.tools.java.CompilerError;
  12. import sun.tools.java.Constants;
  13. import sun.tools.java.Environment;
  14. import sun.tools.java.FieldDefinition;
  15. import sun.tools.java.Identifier;
  16. import sun.tools.java.Type;
  17.  
  18. public class Expression extends Node {
  19.    Type type;
  20.  
  21.    Expression(int var1, int var2, Type var3) {
  22.       super(var1, var2);
  23.       this.type = var3;
  24.    }
  25.  
  26.    public Expression getImplementation() {
  27.       return this;
  28.    }
  29.  
  30.    public Type getType() {
  31.       return this.type;
  32.    }
  33.  
  34.    int precedence() {
  35.       return super.op < Constants.opPrecedence.length ? Constants.opPrecedence[super.op] : 100;
  36.    }
  37.  
  38.    public Expression order() {
  39.       return this;
  40.    }
  41.  
  42.    public boolean isConstant() {
  43.       return false;
  44.    }
  45.  
  46.    public Object getValue() {
  47.       return null;
  48.    }
  49.  
  50.    public boolean equals(int var1) {
  51.       return false;
  52.    }
  53.  
  54.    public boolean equals(boolean var1) {
  55.       return false;
  56.    }
  57.  
  58.    public boolean equals(Identifier var1) {
  59.       return false;
  60.    }
  61.  
  62.    public boolean equals(String var1) {
  63.       return false;
  64.    }
  65.  
  66.    public boolean isNull() {
  67.       return false;
  68.    }
  69.  
  70.    public boolean isNonNull() {
  71.       return false;
  72.    }
  73.  
  74.    public boolean equalsDefault() {
  75.       return false;
  76.    }
  77.  
  78.    Type toType(Environment var1, Context var2) {
  79.       var1.error(super.where, "invalid.type.expr");
  80.       return Type.tError;
  81.    }
  82.  
  83.    public boolean fitsType(Environment var1, Context var2, Type var3) {
  84.       try {
  85.          if (var1.isMoreSpecific(this.type, var3)) {
  86.             return true;
  87.          } else {
  88.             if (this.type.isType(4) && this.isConstant() && var2 != null) {
  89.                Expression var4 = this.inlineValue(var1, var2);
  90.                if (var4 != this && var4 instanceof ConstantExpression) {
  91.                   return var4.fitsType(var1, var2, var3);
  92.                }
  93.             }
  94.  
  95.             return false;
  96.          }
  97.       } catch (ClassNotFound var5) {
  98.          return false;
  99.       }
  100.    }
  101.  
  102.    public boolean fitsType(Environment var1, Type var2) {
  103.       return this.fitsType(var1, (Context)null, var2);
  104.    }
  105.  
  106.    public Vset checkValue(Environment var1, Context var2, Vset var3, Hashtable var4) {
  107.       return var3;
  108.    }
  109.  
  110.    public Vset checkInitializer(Environment var1, Context var2, Vset var3, Type var4, Hashtable var5) {
  111.       return this.checkValue(var1, var2, var3, var5);
  112.    }
  113.  
  114.    public Vset check(Environment var1, Context var2, Vset var3, Hashtable var4) {
  115.       throw new CompilerError("check failed");
  116.    }
  117.  
  118.    public Vset checkLHS(Environment var1, Context var2, Vset var3, Hashtable var4) {
  119.       var1.error(super.where, "invalid.lhs.assignment");
  120.       this.type = Type.tError;
  121.       return var3;
  122.    }
  123.  
  124.    public Vset checkAssignOp(Environment var1, Context var2, Vset var3, Hashtable var4, Expression var5) {
  125.       if (var5 instanceof IncDecExpression) {
  126.          var1.error(super.where, "invalid.arg", Constants.opNames[var5.op]);
  127.       } else {
  128.          var1.error(super.where, "invalid.lhs.assignment");
  129.       }
  130.  
  131.       this.type = Type.tError;
  132.       return var3;
  133.    }
  134.  
  135.    public Vset checkAmbigName(Environment var1, Context var2, Vset var3, Hashtable var4, UnaryExpression var5) {
  136.       return this.checkValue(var1, var2, var3, var4);
  137.    }
  138.  
  139.    public ConditionVars checkCondition(Environment var1, Context var2, Vset var3, Hashtable var4) {
  140.       ConditionVars var5 = new ConditionVars();
  141.       this.checkCondition(var1, var2, var3, var4, var5);
  142.       return var5;
  143.    }
  144.  
  145.    public void checkCondition(Environment var1, Context var2, Vset var3, Hashtable var4, ConditionVars var5) {
  146.       var5.vsTrue = var5.vsFalse = this.checkValue(var1, var2, var3, var4);
  147.       var5.vsFalse = var5.vsFalse.copy();
  148.    }
  149.  
  150.    Expression eval() {
  151.       return this;
  152.    }
  153.  
  154.    Expression simplify() {
  155.       return this;
  156.    }
  157.  
  158.    public Expression inline(Environment var1, Context var2) {
  159.       return null;
  160.    }
  161.  
  162.    public Expression inlineValue(Environment var1, Context var2) {
  163.       return this;
  164.    }
  165.  
  166.    public Expression inlineLHS(Environment var1, Context var2) {
  167.       return null;
  168.    }
  169.  
  170.    public int costInline(int var1, Environment var2, Context var3) {
  171.       return 1;
  172.    }
  173.  
  174.    void codeBranch(Environment var1, Context var2, Assembler var3, Label var4, boolean var5) {
  175.       if (this.type.isType(0)) {
  176.          this.codeValue(var1, var2, var3);
  177.          var3.add(super.where, var5 ? 154 : 153, var4, var5);
  178.       } else {
  179.          throw new CompilerError("codeBranch " + Constants.opNames[super.op]);
  180.       }
  181.    }
  182.  
  183.    public void codeValue(Environment var1, Context var2, Assembler var3) {
  184.       if (this.type.isType(0)) {
  185.          Label var4 = new Label();
  186.          Label var5 = new Label();
  187.          this.codeBranch(var1, var2, var3, var4, true);
  188.          var3.add(true, super.where, 18, new Integer(0));
  189.          var3.add(true, super.where, 167, var5);
  190.          var3.add(var4);
  191.          var3.add(true, super.where, 18, new Integer(1));
  192.          var3.add(var5);
  193.       } else {
  194.          throw new CompilerError("codeValue");
  195.       }
  196.    }
  197.  
  198.    public void code(Environment var1, Context var2, Assembler var3) {
  199.       this.codeValue(var1, var2, var3);
  200.       switch (this.type.getTypeCode()) {
  201.          case 5:
  202.          case 7:
  203.             var3.add(super.where, 88);
  204.             return;
  205.          default:
  206.             var3.add(super.where, 87);
  207.          case 11:
  208.       }
  209.    }
  210.  
  211.    int codeLValue(Environment var1, Context var2, Assembler var3) {
  212.       this.print(System.out);
  213.       throw new CompilerError("invalid lhs");
  214.    }
  215.  
  216.    void codeLoad(Environment var1, Context var2, Assembler var3) {
  217.       this.print(System.out);
  218.       throw new CompilerError("invalid load");
  219.    }
  220.  
  221.    void codeStore(Environment var1, Context var2, Assembler var3) {
  222.       this.print(System.out);
  223.       throw new CompilerError("invalid store");
  224.    }
  225.  
  226.    void ensureString(Environment var1, Context var2, Assembler var3) throws ClassNotFound, AmbiguousField {
  227.       if (this.type != Type.tString || !this.isNonNull()) {
  228.          Type[] var4 = new Type[]{this.type};
  229.          ClassDefinition var5 = var2.field.getClassDefinition();
  230.          ClassDeclaration var6 = var1.getClassDeclaration(Type.tString);
  231.          FieldDefinition var7 = var6.getClassDefinition(var1).matchMethod(var1, var5, Constants.idValueOf, var4);
  232.          var3.add(super.where, 184, var7);
  233.       }
  234.    }
  235.  
  236.    void codeAppend(Environment var1, Context var2, Assembler var3, ClassDeclaration var4, boolean var5) throws ClassNotFound, AmbiguousField {
  237.       ClassDefinition var6 = var2.field.getClassDefinition();
  238.       if (var5) {
  239.          var3.add(super.where, 187, var4);
  240.          var3.add(super.where, 89);
  241.          FieldDefinition var9;
  242.          if (this.equals("")) {
  243.             var9 = var4.getClassDefinition(var1).matchMethod(var1, var6, Constants.idInit);
  244.          } else {
  245.             this.codeValue(var1, var2, var3);
  246.             this.ensureString(var1, var2, var3);
  247.             Type[] var10 = new Type[]{Type.tString};
  248.             var9 = var4.getClassDefinition(var1).matchMethod(var1, var6, Constants.idInit, var10);
  249.          }
  250.  
  251.          var3.add(super.where, 183, var9);
  252.       } else {
  253.          Type[] var8 = new Type[]{this.type};
  254.          this.codeValue(var1, var2, var3);
  255.          FieldDefinition var7 = var4.getClassDefinition(var1).matchMethod(var1, var6, Constants.idAppend, var8);
  256.          var3.add(super.where, 182, var7);
  257.       }
  258.    }
  259.  
  260.    void codeDup(Environment var1, Context var2, Assembler var3, int var4, int var5) {
  261.       switch (var4) {
  262.          case 0:
  263.             return;
  264.          case 1:
  265.             switch (var5) {
  266.                case 0:
  267.                   var3.add(super.where, 89);
  268.                   return;
  269.                case 1:
  270.                   var3.add(super.where, 90);
  271.                   return;
  272.                case 2:
  273.                   var3.add(super.where, 91);
  274.                   return;
  275.                default:
  276.                   throw new CompilerError("can't dup: " + var4 + ", " + var5);
  277.             }
  278.          case 2:
  279.             switch (var5) {
  280.                case 0:
  281.                   var3.add(super.where, 92);
  282.                   return;
  283.                case 1:
  284.                   var3.add(super.where, 93);
  285.                   return;
  286.                case 2:
  287.                   var3.add(super.where, 94);
  288.                   return;
  289.             }
  290.       }
  291.  
  292.       throw new CompilerError("can't dup: " + var4 + ", " + var5);
  293.    }
  294.  
  295.    void codeConversion(Environment var1, Context var2, Assembler var3, Type var4, Type var5) {
  296.       int var6 = var4.getTypeCode();
  297.       int var7 = var5.getTypeCode();
  298.       switch (var7) {
  299.          case 0:
  300.             if (var6 == 0) {
  301.                return;
  302.             }
  303.             break;
  304.          case 1:
  305.             if (var6 != 1) {
  306.                this.codeConversion(var1, var2, var3, var4, Type.tInt);
  307.                var3.add(super.where, 145);
  308.             }
  309.  
  310.             return;
  311.          case 2:
  312.             if (var6 != 2) {
  313.                this.codeConversion(var1, var2, var3, var4, Type.tInt);
  314.                var3.add(super.where, 146);
  315.             }
  316.  
  317.             return;
  318.          case 3:
  319.             if (var6 != 3) {
  320.                this.codeConversion(var1, var2, var3, var4, Type.tInt);
  321.                var3.add(super.where, 147);
  322.             }
  323.  
  324.             return;
  325.          case 4:
  326.             switch (var6) {
  327.                case 1:
  328.                case 2:
  329.                case 3:
  330.                case 4:
  331.                   return;
  332.                case 5:
  333.                   var3.add(super.where, 136);
  334.                   return;
  335.                case 6:
  336.                   var3.add(super.where, 139);
  337.                   return;
  338.                case 7:
  339.                   var3.add(super.where, 142);
  340.                   return;
  341.                default:
  342.                   throw new CompilerError("codeConversion: " + var6 + ", " + var7);
  343.             }
  344.          case 5:
  345.             switch (var6) {
  346.                case 1:
  347.                case 2:
  348.                case 3:
  349.                case 4:
  350.                   var3.add(super.where, 133);
  351.                   return;
  352.                case 5:
  353.                   return;
  354.                case 6:
  355.                   var3.add(super.where, 140);
  356.                   return;
  357.                case 7:
  358.                   var3.add(super.where, 143);
  359.                   return;
  360.                default:
  361.                   throw new CompilerError("codeConversion: " + var6 + ", " + var7);
  362.             }
  363.          case 6:
  364.             switch (var6) {
  365.                case 1:
  366.                case 2:
  367.                case 3:
  368.                case 4:
  369.                   var3.add(super.where, 134);
  370.                   return;
  371.                case 5:
  372.                   var3.add(super.where, 137);
  373.                   return;
  374.                case 6:
  375.                   return;
  376.                case 7:
  377.                   var3.add(super.where, 144);
  378.                   return;
  379.                default:
  380.                   throw new CompilerError("codeConversion: " + var6 + ", " + var7);
  381.             }
  382.          case 7:
  383.             switch (var6) {
  384.                case 1:
  385.                case 2:
  386.                case 3:
  387.                case 4:
  388.                   var3.add(super.where, 135);
  389.                   return;
  390.                case 5:
  391.                   var3.add(super.where, 138);
  392.                   return;
  393.                case 6:
  394.                   var3.add(super.where, 141);
  395.                   return;
  396.                case 7:
  397.                   return;
  398.             }
  399.          case 8:
  400.          default:
  401.             break;
  402.          case 9:
  403.             switch (var6) {
  404.                case 8:
  405.                   return;
  406.                case 9:
  407.                case 10:
  408.                   try {
  409.                      if (!var1.implicitCast(var4, var5)) {
  410.                         var3.add(super.where, 192, var5);
  411.                      }
  412.  
  413.                      return;
  414.                   } catch (ClassNotFound var10) {
  415.                      throw new CompilerError(var10);
  416.                   }
  417.                default:
  418.                   throw new CompilerError("codeConversion: " + var6 + ", " + var7);
  419.             }
  420.          case 10:
  421.             switch (var6) {
  422.                case 8:
  423.                   return;
  424.                case 9:
  425.                case 10:
  426.                   try {
  427.                      if (!var1.implicitCast(var4, var5)) {
  428.                         var3.add(super.where, 192, var1.getClassDeclaration(var5));
  429.                         return;
  430.                      }
  431.  
  432.                      return;
  433.                   } catch (ClassNotFound var9) {
  434.                      throw new CompilerError(var9);
  435.                   }
  436.             }
  437.       }
  438.  
  439.       throw new CompilerError("codeConversion: " + var6 + ", " + var7);
  440.    }
  441.  
  442.    public Expression firstConstructor() {
  443.       return null;
  444.    }
  445.  
  446.    public Expression copyInline(Context var1) {
  447.       return (Expression)((Node)this).clone();
  448.    }
  449.  
  450.    public void print(PrintStream var1) {
  451.       var1.print(Constants.opNames[super.op]);
  452.    }
  453. }
  454.