Skip to content

Commit

Permalink
wip(analyzer): overloading
Browse files Browse the repository at this point in the history
  • Loading branch information
emil14 committed Jan 16, 2025
1 parent 06026c4 commit 86df41e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .vscode/bookmarks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"path": "internal/compiler/analyzer/nodes.go",
"bookmarks": [
{
"line": 363,
"column": 33,
"line": 209,
"column": 2,
"label": ""
}
]
Expand Down
8 changes: 4 additions & 4 deletions internal/compiler/analyzer/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (a Analyzer) analyzeNormalConnection(
return nil, err
}

analyzedReceiverSide, err := a.analyzeReceiverSide(
analyzedReceivers, err := a.analyzeReceivers(
normConn.Receivers,
scope,
iface,
Expand All @@ -162,12 +162,12 @@ func (a Analyzer) analyzeNormalConnection(

return &src.NormalConnection{
Senders: analyzedSenders,
Receivers: analyzedReceiverSide,
Receivers: analyzedReceivers,
Meta: normConn.Meta,
}, nil
}

func (a Analyzer) analyzeReceiverSide(
func (a Analyzer) analyzeReceivers(
receiverSide []src.ConnectionReceiver,
scope src.Scope,
iface src.Interface,
Expand Down Expand Up @@ -363,7 +363,7 @@ func (a Analyzer) analyzeSwitchReceiver(
}
}

analyzedDefault, err := a.analyzeReceiverSide(
analyzedDefault, err := a.analyzeReceivers(
receiver.Switch.Default,
scope,
iface,
Expand Down
8 changes: 7 additions & 1 deletion internal/compiler/analyzer/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (a Analyzer) analyzeNodes(
}

analyzedNode, nodeInterface, err := a.analyzeNode(
nodeName,
flowIface,
node,
scope,
Expand All @@ -54,6 +55,7 @@ func (a Analyzer) analyzeNodes(
}

func (a Analyzer) analyzeNode(
name string,
iface src.Interface,
node src.Node,
scope src.Scope,
Expand Down Expand Up @@ -137,6 +139,7 @@ func (a Analyzer) analyzeNode(
} else {
var err *compiler.Error
nodeIface, overloadIndex, err = a.getComponentNodeInterface(
name,
nodeEntity,
hasBind,
node,
Expand Down Expand Up @@ -205,6 +208,7 @@ func (a Analyzer) analyzeNode(
resolvedFlowDI := make(map[string]src.Node, len(node.DIArgs))
for depName, depNode := range node.DIArgs {
resolvedDep, _, err := a.analyzeNode(
name, // TODO make sure DI works with overloading (example: Reduce{Add})
iface,
depNode,
scope,
Expand Down Expand Up @@ -236,6 +240,7 @@ func (a Analyzer) analyzeNode(
// It also performs some validation.
// Overloading at the level of sourcecode is implemented here.
func (a Analyzer) getComponentNodeInterface(
name string,
entity src.Entity,
hasBind bool,
node src.Node,
Expand All @@ -250,7 +255,7 @@ func (a Analyzer) getComponentNodeInterface(
if len(entity.Component) == 1 {
version = entity.Component[0]
} else {
v, err := a.getNodeOverloadIndex(node, net, entity.Component, scope)
v, err := a.getNodeOverloadIndex(name, node, net, entity.Component, scope)
if err != nil {
return src.Interface{}, nil, &compiler.Error{
Message: "Node can't use #bind if it isn't instantiated with the component that use #extern",
Expand Down Expand Up @@ -356,6 +361,7 @@ func (a Analyzer) getComponentNodeInterface(
}

func (a Analyzer) getNodeOverloadIndex(
name string,
node src.Node,
net []src.Connection,
versions []src.Component,
Expand Down

0 comments on commit 86df41e

Please sign in to comment.