⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 switchstmt.java

📁 JDK1.4编译器后端
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

package AST;
import java.util.HashSet;import java.util.LinkedHashSet;import java.io.FileNotFoundException;import java.io.File;import java.util.*;import beaver.*;import java.util.ArrayList;import java.util.zip.*;import java.io.*;public class SwitchStmt extends BranchTargetStmt implements Cloneable {
    public void flushCache() {        super.flushCache();        targetOf_ContinueStmt_values = null;        targetOf_BreakStmt_values = null;        isDAafter_Variable_values = null;        isDUafter_Variable_values = null;        canCompleteNormally_computed = false;        defaultCase_computed = false;        defaultCase_value = null;        end_label_computed = false;        typeInt_computed = false;        typeInt_value = null;        typeLong_computed = false;        typeLong_value = null;    }     @SuppressWarnings({"unchecked", "cast"})  public SwitchStmt clone() throws CloneNotSupportedException {        SwitchStmt node = (SwitchStmt)super.clone();        node.targetOf_ContinueStmt_values = null;        node.targetOf_BreakStmt_values = null;        node.isDAafter_Variable_values = null;        node.isDUafter_Variable_values = null;        node.canCompleteNormally_computed = false;        node.defaultCase_computed = false;        node.defaultCase_value = null;        node.end_label_computed = false;        node.typeInt_computed = false;        node.typeInt_value = null;        node.typeLong_computed = false;        node.typeLong_value = null;        node.in$Circle(false);        node.is$Final(false);    return node;    }     @SuppressWarnings({"unchecked", "cast"})  public SwitchStmt copy() {      try {          SwitchStmt node = (SwitchStmt)clone();          if(children != null) node.children = (ASTNode[])children.clone();          return node;      } catch (CloneNotSupportedException e) {      }      System.err.println("Error: Could not clone node of type " + getClass().getName() + "!");      return null;    }     @SuppressWarnings({"unchecked", "cast"})  public SwitchStmt fullCopy() {        SwitchStmt res = (SwitchStmt)copy();        for(int i = 0; i < getNumChildNoTransform(); i++) {          ASTNode node = getChildNoTransform(i);          if(node != null) node = node.fullCopy();          res.setChild(node, i);        }        return res;    }    // Declared in PrettyPrint.jadd at line 569  public void toString(StringBuffer s) {    s.append("switch (");    getExpr().toString(s);    s.append(")");    getBlock().toString(s);  }    // Declared in TypeCheck.jrag at line 343  public void typeCheck() {    TypeDecl type = getExpr().type();    if(!type.isIntegralType() || type.isLong())      error("Switch expression must be of char, byte, short, or int");  }    // Declared in CreateBCode.jrag at line 1201  public void createBCode(CodeGeneration gen) {    super.createBCode(gen);    int cond_label = hostType().constantPool().newLabel();    int switch_label = hostType().constantPool().newLabel();    gen.emitGoto(cond_label);    getBlock().createBCode(gen);    if(canCompleteNormally())      gen.emitGoto(end_label());    gen.addLabel(cond_label);    getExpr().createBCode(gen);    TreeMap map = new TreeMap();    for(int i = 0; i < getBlock().getNumStmt(); i++) {      if(getBlock().getStmt(i) instanceof ConstCase) {        ConstCase ca = (ConstCase)getBlock().getStmt(i);        map.put(new Integer(ca.getValue().constant().intValue()), ca);      }            }    long low = map.isEmpty() ? 0 : ((Integer)map.firstKey()).intValue();    long high = map.isEmpty() ? 0 : ((Integer)map.lastKey()).intValue();    long tableSwitchSize = 8L + (high - low + 1L) * 4L;    long lookupSwitchSize = 4L + map.size() * 8L;    gen.addLabel(switch_label);    if(tableSwitchSize < lookupSwitchSize) {      gen.emit(Bytecode.TABLESWITCH);      int pad = emitPad(gen);      int defaultOffset = defaultOffset(gen, switch_label);      if(defaultOffset == 0) {        defaultOffset = 1 + pad + 4 + 4 + 4 + 4 * (int)(high - low + 1);      }      gen.add4(defaultOffset);      gen.add4((int)low);      gen.add4((int)high);      for(long i = low; i <= high; i++) {        ConstCase ca = (ConstCase)map.get(new Integer((int)i));        if(ca != null) {          int offset = gen.addressOf(ca.label(gen))            - gen.addressOf(switch_label);          gen.add4(offset);        }        else {          gen.add4(defaultOffset);        }      }    }    else {      gen.emit(Bytecode.LOOKUPSWITCH);      int pad = emitPad(gen);      int defaultOffset = defaultOffset(gen, switch_label);      if(defaultOffset == 0) {        defaultOffset = 1 + pad + 4 + 4 + 8 * numCase();      }      gen.add4(defaultOffset);      gen.add4(map.size());      for(Iterator iter = map.values().iterator(); iter.hasNext(); ) {        ConstCase ca = (ConstCase)iter.next();        gen.add4(ca.getValue().constant().intValue());        int offset = gen.addressOf(ca.label(gen))          - gen.addressOf(switch_label);        gen.add4(offset);      }    }    gen.addLabel(end_label());  }    // Declared in CreateBCode.jrag at line 1278  private int emitPad(CodeGeneration gen) {    int pad = (4 - (gen.pos() % 4)) % 4;    for(int i = 0; i < pad; i++)      gen.emit(Bytecode.NOP);    if(gen.pos() % 4 != 0)      throw new Error("Switch not at 4-byte boundary:" + gen.pos());    return pad;  }    // Declared in CreateBCode.jrag at line 1286  private int defaultOffset(CodeGeneration gen, int switch_label) {    boolean hasDefault = defaultCase() != null;    if(hasDefault) {      int offset = gen.addressOf(defaultCase().label(gen))        - gen.addressOf(switch_label);      return offset;    }    return 0;  }    // Declared in java.ast at line 3    // Declared in java.ast line 205
    public SwitchStmt() {        super();

    }    // Declared in java.ast at line 10
    // Declared in java.ast line 205    public SwitchStmt(Expr p0, Block p1) {        setChild(p0, 0);        setChild(p1, 1);    }    // Declared in java.ast at line 15  protected int numChildren() {
    return 2;
  }    // Declared in java.ast at line 18
  public boolean mayHaveRewrite() { return false; }    // Declared in java.ast at line 2    // Declared in java.ast line 205    public void setExpr(Expr node) {        setChild(node, 0);    }    // Declared in java.ast at line 5    public Expr getExpr() {        return (Expr)getChild(0);    }    // Declared in java.ast at line 9    public Expr getExprNoTransform() {        return (Expr)getChildNoTransform(0);    }    // Declared in java.ast at line 2    // Declared in java.ast line 205    public void setBlock(Block node) {        setChild(node, 1);    }    // Declared in java.ast at line 5    public Block getBlock() {        return (Block)getChild(1);    }    // Declared in java.ast at line 9    public Block getBlockNoTransform() {        return (Block)getChildNoTransform(1);    }    protected java.util.Map targetOf_ContinueStmt_values;    // Declared in BranchTarget.jrag at line 73 @SuppressWarnings({"unchecked", "cast"})     public boolean targetOf(ContinueStmt stmt) {        Object _parameters = stmt;if(targetOf_ContinueStmt_values == null) targetOf_ContinueStmt_values = new java.util.HashMap(4);        if(targetOf_ContinueStmt_values.containsKey(_parameters))            return ((Boolean)targetOf_ContinueStmt_values.get(_parameters)).booleanValue();        int num = boundariesCrossed;        boolean isFinal = this.is$Final();        boolean targetOf_ContinueStmt_value = targetOf_compute(stmt);        if(isFinal && num == boundariesCrossed)            targetOf_ContinueStmt_values.put(_parameters, Boolean.valueOf(targetOf_ContinueStmt_value));        return targetOf_ContinueStmt_value;    }    private boolean targetOf_compute(ContinueStmt stmt) {  return false;  }    protected java.util.Map targetOf_BreakStmt_values;    // Declared in BranchTarget.jrag at line 77 @SuppressWarnings({"unchecked", "cast"})     public boolean targetOf(BreakStmt stmt) {        Object _parameters = stmt;if(targetOf_BreakStmt_values == null) targetOf_BreakStmt_values = new java.util.HashMap(4);        if(targetOf_BreakStmt_values.containsKey(_parameters))            return ((Boolean)targetOf_BreakStmt_values.get(_parameters)).booleanValue();        int num = boundariesCrossed;        boolean isFinal = this.is$Final();        boolean targetOf_BreakStmt_value = targetOf_compute(stmt);        if(isFinal && num == boundariesCrossed)            targetOf_BreakStmt_values.put(_parameters, Boolean.valueOf(targetOf_BreakStmt_value));        return targetOf_BreakStmt_value;    }    private boolean targetOf_compute(BreakStmt stmt) {  return !stmt.hasLabel();  }    // Declared in DefiniteAssignment.jrag at line 532 @SuppressWarnings({"unchecked", "cast"})     public boolean isDAafter(Variable v) {        Object _parameters = v;if(isDAafter_Variable_values == null) isDAafter_Variable_values = new java.util.HashMap(4);        if(isDAafter_Variable_values.containsKey(_parameters))            return ((Boolean)isDAafter_Variable_values.get(_parameters)).booleanValue();        int num = boundariesCrossed;        boolean isFinal = this.is$Final();        boolean isDAafter_Variable_value = isDAafter_compute(v);        if(isFinal && num == boundariesCrossed)            isDAafter_Variable_values.put(_parameters, Boolean.valueOf(isDAafter_Variable_value));        return isDAafter_Variable_value;    }    private boolean isDAafter_compute(Variable v) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -