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

Method Generate

pkg/codegen/lambda.go:38–71  ·  view source on GitHub ↗

Generate produces Go code for the lambda expression. Output format: func(param1 type1, param2 type2, ...) returnType { body } For expression bodies, wraps in { return ... }. For block bodies, uses as-is. Source mappings track: - Lambda start position → entire generated function

()

Source from the content-addressed store, hash-verified

36// Source mappings track:
37// - Lambda start position → entire generated function
38func (g *LambdaCodeGen) Generate() ast.CodeGenResult {
39 if g.expr == nil {
40 return ast.CodeGenResult{}
41 }
42
43 // func(
44 g.Write("func(")
45
46 // Parameters
47 g.generateParams()
48
49 // )
50 g.WriteByte(')')
51
52 // Return type
53 // - If explicitly specified: use it
54 // - If expression body (has return stmt): default to 'any' as placeholder
55 // - If block body: NO DEFAULT (may be void)
56 // The type inferrer will replace 'any' with actual types when in call context
57 if g.expr.ReturnType != "" {
58 g.WriteByte(' ')
59 g.Write(g.expr.ReturnType)
60 } else if !g.expr.IsBlock {
61 // Expression body - add 'any' return type so { return ... } is valid
62 g.Write(" any")
63 }
64 // Block bodies have no default return type (may be void)
65
66 // Body
67 g.WriteByte(' ')
68 g.generateBody()
69
70 return g.Result()
71}
72
73// generateParams generates the parameter list.
74//

Calls 5

generateParamsMethod · 0.95
generateBodyMethod · 0.95
WriteByteMethod · 0.80
ResultMethod · 0.80
WriteMethod · 0.45