import java.util.List;

public class CheckParams implements Visitor {
	List<FunctionDef> globalFuns;
	
	@Override
	public void visit(Type type) {
		// TODO Auto-generated method stub

	}

	@Override
	public void visit(Param param) {
		// TODO Auto-generated method stub

	}

	@Override
	public void visit(IfExp ifExp) {
		ifExp.cond.welcome(this);
		ifExp.alt1.welcome(this);
		ifExp.alt2.welcome(this);
	}

	@Override
	public void visit(App app) {
		for (Exp arg:app.args){
			arg.welcome(this);
		}
		
		for (FunctionDef gf:globalFuns){
			if (gf.name.equals(app.functionName)){
				if (gf.params.size()==app.args.size())
					return;
				else throw new RuntimeException("wrong number of args");
			}
		}
		throw new RuntimeException("undefined Function");
	}

	@Override
	public void visit(OpExp opExp) {
		opExp.left.welcome(this);
		opExp.right.welcome(this);
	}

	@Override
	public void visit(Var var) {
		// TODO Auto-generated method stub

	}

	@Override
	public void visit(IntLiteral intLiteral) {
		// TODO Auto-generated method stub

	}

	@Override
	public void visit(FunctionDef functionDef) {
		// TODO Auto-generated method stub

	}

	@Override
	public void visit(Program program) {
		globalFuns=program.functions;
		for (FunctionDef f:program.functions){
			f.body.welcome(this);
		}
		program.e.welcome(this);
	}

}
