[REFACTOR] Refactored some of the generic-lambda capturing code.

Employed the following refactorings:
  - Renamed some functions
  - Introduced explaining variables
  - Cleaned up & added comments
  - Used Optional<unsigned> for return value instead of an out parameter
  - Added assertions
  - Constified a few member functions
  
No functionality change.
All regressions pass.  



git-svn-id: http://llvm.org/svn/llvm-project/cfe/trunk@196662 91177308-0d34-0410-b5e6-96231b3b80d8