llvmir some opt
This commit is contained in:
60
frontend/ast/func/MainFuncDef.java
Normal file
60
frontend/ast/func/MainFuncDef.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package frontend.ast.func;
|
||||
|
||||
import error.ErrorType;
|
||||
import error.Errors;
|
||||
import error.Error;
|
||||
import frontend.ast.Node;
|
||||
import frontend.ast.SyntaxType;
|
||||
import frontend.ast.block.BlockItem;
|
||||
import frontend.ast.decl.Decl;
|
||||
import frontend.lexer.TokenStream;
|
||||
import frontend.ast.token.TokenNode;
|
||||
import frontend.lexer.TokenType;
|
||||
import frontend.ast.block.Block;
|
||||
|
||||
public class MainFuncDef extends Node {
|
||||
public MainFuncDef(TokenStream ts) {
|
||||
super(SyntaxType.MAIN_FUNC_DEF, ts);
|
||||
}
|
||||
|
||||
public void parse(Errors errors) {
|
||||
TokenNode intkk = new TokenNode(this.ts);
|
||||
addChild(intkk);
|
||||
TokenNode mainkk = new TokenNode(this.ts);
|
||||
addChild(mainkk);
|
||||
TokenNode lparent = new TokenNode(this.ts);
|
||||
addChild(lparent);
|
||||
if (getCurrToken().getType() != TokenType.RPARENT) {
|
||||
errors.addError(new Error(this.ts.peek(-1).getLine(), ErrorType.j));
|
||||
} else {
|
||||
TokenNode rparent = new TokenNode(this.ts);
|
||||
addChild(rparent);
|
||||
}
|
||||
Block block = new Block(this.ts);
|
||||
block.setIsFuncBlock(true);
|
||||
block.parse(errors);
|
||||
addChild(block);
|
||||
}
|
||||
|
||||
public void checkReturnNode(Errors errors) {
|
||||
Block block = (Block) getChild(getChildren().size() - 1);
|
||||
TokenNode rbrace = (TokenNode) block.getChild(block.getChildren().size() - 1);
|
||||
if (block.getChildren().size() == 2) {
|
||||
errors.addError(new Error(rbrace.getLine(), ErrorType.g));
|
||||
} else {
|
||||
BlockItem bit = (BlockItem) block.getChild(block.getChildren().size() - 2);
|
||||
if (bit.getChild(0) instanceof Decl) {
|
||||
errors.addError(new Error(rbrace.getLine(), ErrorType.g));
|
||||
} else {
|
||||
if (!(bit.getChild(0).getChild(0) instanceof TokenNode)) {
|
||||
errors.addError(new Error(rbrace.getLine(), ErrorType.g));
|
||||
} else {
|
||||
TokenNode returnNode = (TokenNode) bit.getChild(0).getChild(0);
|
||||
if (returnNode.getType() != TokenType.RETURNTK) {
|
||||
errors.addError(new Error(rbrace.getLine(), ErrorType.g));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user