Homework B (benchmarks)

This commit is contained in:
Carlos Galindo 2020-01-15 22:38:07 +01:00
parent 72cc3206c4
commit 76fbabdf53
Signed by: kauron
GPG key ID: 83E68706DEE119A3
141 changed files with 7540 additions and 2032 deletions

View file

@ -4,18 +4,21 @@ import cd.ir.Ast.Decl;
import cd.ir.Ast.Expr;
import cd.ir.Ast.Stmt;
/** A visitor that visits any kind of node */
public class AstVisitor<R,A> extends ExprVisitor<R,A> {
/**
* Recurse and process {@code ast}. It is preferred to
/**
* A visitor that visits any kind of node
*/
public class AstVisitor<R, A> extends ExprVisitor<R, A> {
/**
* Recurse and process {@code ast}. It is preferred to
* call this rather than calling accept directly, since
* it can be overloaded to introduce memoization,
* for example. */
* it can be overloaded to introduce memoization,
* for example.
*/
public R visit(Ast ast, A arg) {
return ast.accept(this, arg);
}
/**
* Overrides {@link ExprVisitor#visitChildren(Expr, Object)} and
* delegates to the more general {@link #visitChildren(Ast, Object)}
@ -26,11 +29,11 @@ public class AstVisitor<R,A> extends ExprVisitor<R,A> {
public final R visitChildren(Expr ast, A arg) {
return visitChildren((Ast) ast, arg);
}
/**
* A handy function which visits the children of {@code ast},
* providing "arg" to each of them. It returns the result of
* the last child in the list. It is invoked by the method
* the last child in the list. It is invoked by the method
* {@link #dflt(Ast, Object)} by default.
*/
public R visitChildren(Ast ast, A arg) {
@ -39,35 +42,39 @@ public class AstVisitor<R,A> extends ExprVisitor<R,A> {
lastValue = visit(child, arg);
return lastValue;
}
/**
/**
* The default action for default actions is to call this,
* which simply recurses to any children. Also called
* by seq() by default. */
* by seq() by default.
*/
protected R dflt(Ast ast, A arg) {
return visitChildren(ast, arg);
}
/**
* The default action for statements is to call this */
/**
* The default action for statements is to call this
*/
protected R dfltStmt(Stmt ast, A arg) {
return dflt(ast, arg);
}
/**
* The default action for expressions is to call this */
/**
* The default action for expressions is to call this
*/
@Override
protected R dfltExpr(Expr ast, A arg) {
return dflt(ast, arg);
}
/**
/**
* The default action for AST nodes representing declarations
* is to call this function */
* is to call this function
*/
protected R dfltDecl(Decl ast, A arg) {
return dflt(ast, arg);
}
public R assign(Ast.Assign ast, A arg) {
return dfltStmt(ast, arg);
}
@ -79,23 +86,23 @@ public class AstVisitor<R,A> extends ExprVisitor<R,A> {
public R builtInWriteln(Ast.BuiltInWriteln ast, A arg) {
return dfltStmt(ast, arg);
}
public R classDecl(Ast.ClassDecl ast, A arg) {
return dfltDecl(ast, arg);
}
public R methodDecl(Ast.MethodDecl ast, A arg) {
return dfltDecl(ast, arg);
}
public R varDecl(Ast.VarDecl ast, A arg) {
return dfltDecl(ast, arg);
}
public R ifElse(Ast.IfElse ast, A arg) {
return dfltStmt(ast, arg);
}
public R returnStmt(Ast.ReturnStmt ast, A arg) {
return dfltStmt(ast, arg);
}
@ -107,11 +114,11 @@ public class AstVisitor<R,A> extends ExprVisitor<R,A> {
public R nop(Ast.Nop ast, A arg) {
return dfltStmt(ast, arg);
}
public R seq(Ast.Seq ast, A arg) {
return dflt(ast, arg);
}
public R whileLoop(Ast.WhileLoop ast, A arg) {
return dfltStmt(ast, arg);
}