Mode and termination analysis for higher-order logic programs