-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from capnproto/enhancement/promised-cap
Return capnp.Client from promised :Capability type
- Loading branch information
Showing
7 changed files
with
130 additions
and
573 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package main | ||
|
||
import "capnproto.org/go/capnp/v3/internal/schema" | ||
|
||
type anyPointerRenderStrategy interface { | ||
StructParams() any | ||
ListParams() any | ||
CapabilityParams() any | ||
PtrParams() any | ||
} | ||
|
||
type anyPointer struct { | ||
G *generator | ||
Type schema.Type | ||
} | ||
|
||
func (ap anyPointer) Render(s anyPointerRenderStrategy) error { | ||
switch ap.Type.AnyPointer().Which() { | ||
case schema.Type_anyPointer_Which_unconstrained: | ||
return ap.RenderUnconstrained(s) | ||
|
||
case schema.Type_anyPointer_Which_parameter: | ||
// TODO(soon): implement parameter | ||
case schema.Type_anyPointer_Which_implicitMethodParameter: | ||
// TODO(soon): implement implicit method parameter | ||
} | ||
|
||
return ap.G.r.Render(s.PtrParams()) | ||
} | ||
|
||
func (ap anyPointer) RenderUnconstrained(s anyPointerRenderStrategy) error { | ||
switch ap.Type.AnyPointer().Unconstrained().Which() { | ||
case schema.Type_anyPointer_unconstrained_Which_struct: | ||
return ap.G.r.Render(s.StructParams()) | ||
|
||
case schema.Type_anyPointer_unconstrained_Which_list: | ||
return ap.G.r.Render(s.ListParams()) | ||
|
||
case schema.Type_anyPointer_unconstrained_Which_capability: | ||
return ap.G.r.Render(s.CapabilityParams()) | ||
} | ||
|
||
return ap.G.r.Render(s.PtrParams()) | ||
} | ||
|
||
type structAnyPointerRenderStrategy struct { | ||
Params structFieldParams | ||
Default staticDataRef | ||
} | ||
|
||
func (s structAnyPointerRenderStrategy) StructParams() any { | ||
return s.PtrParams() // TODO(soon): implement AnyStruct | ||
} | ||
|
||
func (s structAnyPointerRenderStrategy) ListParams() any { | ||
return s.PtrParams() // TODO(soon): implement AnyList | ||
} | ||
|
||
func (s structAnyPointerRenderStrategy) CapabilityParams() any { | ||
return structCapabilityFieldParams(s.Params) | ||
} | ||
|
||
func (s structAnyPointerRenderStrategy) PtrParams() any { | ||
return structPointerFieldParams{ | ||
structFieldParams: s.Params, | ||
Default: s.Default, | ||
} | ||
} | ||
|
||
type promiseAnyPointerRenderStrategy struct { | ||
G *generator | ||
Node *node | ||
Field field | ||
} | ||
|
||
func (s promiseAnyPointerRenderStrategy) StructParams() any { | ||
return s.PtrParams() // TODO(soon): implement AnyStruct | ||
} | ||
|
||
func (s promiseAnyPointerRenderStrategy) ListParams() any { | ||
return s.PtrParams() // TODO(soon): implement AnyList | ||
} | ||
|
||
func (s promiseAnyPointerRenderStrategy) CapabilityParams() any { | ||
return promiseCapabilityFieldParams(s) | ||
} | ||
|
||
func (s promiseAnyPointerRenderStrategy) PtrParams() any { | ||
return promiseFieldAnyPointerParams(s) | ||
} | ||
|
||
func isAnyCap(ap schema.Type_anyPointer) bool { | ||
if ap.Which() != schema.Type_anyPointer_Which_unconstrained { | ||
return false | ||
} | ||
|
||
which := ap.Unconstrained().Which() | ||
return which == schema.Type_anyPointer_unconstrained_Which_capability | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
func (p {{.Node.Name}}_Future) {{.Field.Name|title}}() capnp.Client { | ||
return p.Future.Field({{.Field.Slot.Offset}}, nil).Client() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.