Refactor calculation of variables, common to many generators.

Patch by Slava Chigrin <vchigrin@yandex-team.ru>.

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/25757002

git-svn-id: http://gyp.googlecode.com/svn/trunk@1747 78cadc50-ecff-11dd-a971-7dbc132099af