MCPcopy
hub / github.com/MadAppGang/dingo / SharedTempVar

Method SharedTempVar

pkg/codegen/match.go:47–59  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

45// Uses incrementing counter to ensure positive numbers in variable names.
46// Falls back to local counter if no shared counter is provided.
47func (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

Callers 5

generateMatchSwitchMethod · 0.95
generateOptionMatchMethod · 0.95
generateResultMatchMethod · 0.95

Calls 1

TempVarMethod · 0.80

Tested by

no test coverage detected