localvariable.java
来自「一个JAVA编写的简单编译器」· Java 代码 · 共 61 行
JAVA
61 行
package ast.declaration;
public class LocalVariable extends ast.declaration.JSubObject {
private boolean iAmAParameter;
private static int currentNoInThisLevel;
private int no; // current number of varible
// to count local Variable. 0 = this,
public static void reset () {
currentNoInThisLevel = 0;
}
public LocalVariable (String name, boolean iAmAParameter) {
super (name, ast.declaration.JSubObject.TINT);
this.iAmAParameter = iAmAParameter;
no = currentNoInThisLevel++;
}
public String toString () {
return "" + no;
}
public void dump (String prefix) {
char c = ' ';
if (iAmAParameter)
c = 'p';
System.out.print ("local" + c + ' ' + no + " ");
super.dump (prefix);
}
public void genXML (java.io.PrintStream p, String prefix) {
p.println (prefix + "<localvariable name = \"" + getName () +"\"/>");
}
public boolean isParameter () {
return iAmAParameter;
}
public String getStoreString () {
StringBuffer buffer = new StringBuffer ("istore");
if (no <= 3)
buffer.append ('_');//istroe_0,1,2,3 pop int to local variable position 0,1,2,3.
else
buffer.append (' ');//it is functionally equivalent to istore_
buffer.append (no);
return buffer.toString ();
}
public String getLoadString () {
StringBuffer buffer = new StringBuffer ("iload");
if (no <= 3)
buffer.append ('_');//iload_0,1,2,3 pushes int from local variable position 0,1,2,3.
else
buffer.append (' ');//it is functionally equivalent to iload_
buffer.append (no);
return buffer.toString ();
}
public String getXMLType () {
return "local";
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?