llvmir some opt
This commit is contained in:
58
frontend/ast/val/ConstInitVal.java
Normal file
58
frontend/ast/val/ConstInitVal.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package frontend.ast.val;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import error.Errors;
|
||||
import frontend.ast.Node;
|
||||
import frontend.ast.SyntaxType;
|
||||
import frontend.ast.exp.ConstExp;
|
||||
import frontend.ast.token.TokenNode;
|
||||
import frontend.lexer.TokenStream;
|
||||
import frontend.lexer.TokenType;
|
||||
|
||||
public class ConstInitVal extends Node {
|
||||
public ConstInitVal(TokenStream ts) {
|
||||
super(SyntaxType.CONST_INIT_VAL, ts);
|
||||
}
|
||||
|
||||
public void parse(Errors errors) {
|
||||
if (getCurrToken().getType() != TokenType.LBRACE) {
|
||||
ConstExp cep = new ConstExp(this.ts);
|
||||
cep.parse(errors);
|
||||
addChild(cep);
|
||||
} else {
|
||||
TokenNode lbrace = new TokenNode(this.ts);
|
||||
addChild(lbrace);
|
||||
if (getCurrToken().getType() != TokenType.RBRACE) {
|
||||
while (true) { // judge rbrace or not ??
|
||||
ConstExp cep = new ConstExp(this.ts);
|
||||
cep.parse(errors);
|
||||
addChild(cep);
|
||||
if (getCurrToken().getType() == TokenType.COMMA) {
|
||||
TokenNode comma = new TokenNode(this.ts);
|
||||
addChild(comma);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
TokenNode rbrace = new TokenNode(this.ts);
|
||||
addChild(rbrace);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Integer> getValue() {
|
||||
ArrayList<Integer> valueList = new ArrayList<>();
|
||||
if (getChild(0) instanceof ConstExp) {
|
||||
valueList.add(((ConstExp) getChild(0)).getValue());
|
||||
return valueList;
|
||||
} else {
|
||||
for (int i = 1; i < getChildren().size(); i += 2) {
|
||||
if (getChild(i) instanceof ConstExp) {
|
||||
valueList.add(((ConstExp) getChild(i)).getValue());
|
||||
}
|
||||
}
|
||||
return valueList;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user