Valency of rare earths in RIn3 and RSn3: Ab initio analysis of electric-field gradients