SharedTempVar generates unique temp var names using shared counter if available. Uses incrementing counter to ensure positive numbers in variable names. Falls back to local counter if no shared counter is provided.
(base string)
| 45 | // Uses incrementing counter to ensure positive numbers in variable names. |
| 46 | // Falls back to local counter if no shared counter is provided. |
| 47 | func (g *MatchCodeGen) SharedTempVar(base string) string { |
| 48 | if g.Context != nil && g.Context.TempCounter != nil { |
| 49 | // Increment counter to get unique name |
| 50 | // First call gets no suffix, subsequent calls get 1, 2, 3, ... |
| 51 | counter := *g.Context.TempCounter |
| 52 | *g.Context.TempCounter++ |
| 53 | if counter == 0 { |
| 54 | return base |
| 55 | } |
| 56 | return fmt.Sprintf("%s%d", base, counter) |
| 57 | } |
| 58 | return g.TempVar(base) |
| 59 | } |
| 60 | |
| 61 | // Constructor is in expr.go to avoid import cycles |
| 62 |
no test coverage detected