📄 jsubbooleannode.java
字号:
package ast.booleanExpr;
/**
* the JSubBooleanNode contains the Basis-Functionality for
* Boolean account: && || < <= == != > >=
*/
public abstract class JSubBooleanNode extends ast.JSubNode {
public JSubBooleanNode (ast.IJSubNode n) {
super (n);
}
/**
* Codegeneration for OR
* @param label Label for branch
* @param test condition or negatived condition
*/
public void codegenOR (int label, boolean test) {
int labelTrue = codegen.WriteCode.getLabel ();
JSubBooleanNode node = null;
for (int i = 0; i < getNumChildren() - 1; i++) {
node = (JSubBooleanNode)getChild (i);
node.codegen (labelTrue, !test);
}
node = (JSubBooleanNode)getChild (getNumChildren() - 1);
node.codegen (label, test);
codegen.WriteCode.genLabel (labelTrue);
}
/**
* Codegeneration for AND
* @param label Label for branch
* @param test condition or negatived condition
*/
public void codegenAND (int label, boolean test) {
for (int i = 0; i < getNumChildren (); i++ ) {
JSubBooleanNode node = (JSubBooleanNode)getChild (i);
node.codegen (label, test);
}
}
/**
* Codegeneration for < <= != == > >=
* @param label Label for branch
* @param test condition or negatived condition
*/
public void codegen (int label, boolean test) {
ast.IJSubNode node = (ast.IJSubNode)getChild (0);
node.codegen ();
node = (ast.IJSubNode)getChild (1);
node.codegen ();
codegen.WriteCode.genBranchInstruction ("if_icmp" +
getCompareInstruction (test), label);
}
public void codegen () {}
public int getDepth () {
int depth = 0;
for (int i = 0; i < children.size(); i++) {
ast.IJSubNode node = (ast.IJSubNode)children.elementAt(i);
int ndepth = node.getDepth();
if (depth < ndepth)
depth = ndepth;
}
return depth;
}
/**
* amount the comparison command for the JVM
* @param test condition or negatived condition
*/
public String getCompareInstruction (boolean negation) {
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -