refactor out common code between syntactic valdef and vardef