goose: refactor *gen.inject

The function had grown too long. Several related cleanups:

- Factored out the function return value logic, which had been
  duplicated between providers and injectors.
- Moved code generation for different provider call types into separate
  functions. This moves injector-specific state to a new type
  injectorGen to keep the parameter count down.
- Since it's infeasible to keep the "shadow pass" collecting import
  identifiers in sync the spread out logic, the injector code
  generation is just run twice, with initial output discarded.
- Removed the zero value logic left over from Optional.

Reviewed-by: Tuo Shan <shantuo@google.com>
This commit is contained in:
Ross Light
2018-05-08 16:26:38 -04:00
parent 10676a814b
commit 3c0eaf830e
3 changed files with 278 additions and 246 deletions

View File

@@ -48,9 +48,8 @@ type call struct {
name string
// args is a list of arguments to call the provider with. Each element is:
// a) one of the givens (args[i] < len(given)),
// b) the result of a previous provider call (args[i] >= len(given)), or
// c) the zero value for the type (args[i] == -1).
// a) one of the givens (args[i] < len(given)), or
// b) the result of a previous provider call (args[i] >= len(given))
//
// This will be nil for kind == valueExpr.
args []int