Skip to content

Commit

Permalink
feat(analyzer): improve err handling a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
emil14 committed Jan 10, 2024
1 parent 0b68145 commit 7d165d0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ types {
}

const {
age 32
name 'John'
age int 32
name str 'John'
}

components {
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/analyzer/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
ErrWriteSelfIn = errors.New("Component cannot write to self inport")
ErrInportNotFound = errors.New("Referenced inport not found in component's interface")
ErrNodeNotFound = errors.New("Referenced node not found")
ErrNodePortNotFound = errors.New("Node's port not found")
ErrPortNotFound = errors.New("Port not found")
ErrNormCompWithRuntimeFunc = errors.New("Component with nodes or network cannot use #runtime_func directive")
ErrNormComponentWithoutNet = errors.New("Component must have network except it uses #runtime_func directive")
ErrNormNodeRuntimeMsg = errors.New("Node can't use #runtime_func_msg if it isn't instantiated with the component that use #runtime_func")
Expand Down
9 changes: 4 additions & 5 deletions internal/compiler/analyzer/component_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ func (a Analyzer) analyzeNetConn( //nolint:funlen
}

for _, receiver := range conn.ReceiverSide.Receivers {
inportTypeExpr, err := a.getReceiverType(receiver, compInterface.IO.Out, nodes, nodesIfaces, scope)
inportTypeExpr, err := a.resolveReceiverType(receiver, compInterface.IO.Out, nodes, nodesIfaces, scope)
if err != nil {
return compiler.Error{
Err: errors.New("Unable to get receiver type"),
Err: errors.New("Unable to resolve receiver"),
Location: &scope.Location,
Meta: &receiver.Meta,
}.Merge(err)
Expand Down Expand Up @@ -216,7 +216,7 @@ func (Analyzer) checkNodesPortsUsage(
return nil
}

func (a Analyzer) getReceiverType(
func (a Analyzer) resolveReceiverType(
receiverSide src.ConnectionReceiver,
outports map[string]src.Port,
nodes map[string]src.Node,
Expand Down Expand Up @@ -293,7 +293,6 @@ func (a Analyzer) getNodeInportType(
)
if aerr != nil {
return ts.Expr{}, compiler.Error{
Err: fmt.Errorf("Unable to resolve '%v' port type", portAddr),
Location: &location,
Meta: &portAddr.Meta,
}.Merge(aerr)
Expand All @@ -312,7 +311,7 @@ func (a Analyzer) getResolvedPortType(
port, ok := ports[portAddr.Port]
if !ok {
return ts.Expr{}, &compiler.Error{
Err: fmt.Errorf("%w '%v'", ErrNodePortNotFound, portAddr),
Err: fmt.Errorf("%w '%v'", ErrPortNotFound, portAddr),
Location: &scope.Location,
Meta: &portAddr.Meta,
}
Expand Down
15 changes: 14 additions & 1 deletion internal/compiler/parser/listener_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,20 @@ func parseTypeExpr(expr generated.ITypeExprContext) *ts.Expr {
} else if litExpr := expr.TypeLitExpr(); litExpr != nil {
result = parseLitExpr(litExpr)
} else {
panic("expr empty")
panic(&compiler.Error{
Err: errors.New("Missing type expression"),
Meta: &src.Meta{
Text: expr.GetText(),
Start: src.Position{
Line: expr.GetStart().GetLine(),
Column: expr.GetStart().GetLine(),
},
Stop: src.Position{
Line: expr.GetStop().GetLine(),
Column: expr.GetStop().GetLine(),
},
},
})
}

result.Meta = getTypeExprMeta(expr)
Expand Down
6 changes: 3 additions & 3 deletions internal/pkgmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (p Manager) Build(ctx context.Context, workdir string) (compiler.RawBuild,
}

mods := map[src.ModuleRef]compiler.RawModule{
{Path: "", Version: ""}: entryMod,
{Path: "std", Version: "0.0.1"}: stdMod,
{Path: "@"}: entryMod,
{Path: "std", Version: "0.0.1"}: stdMod, // TODO maybe remove version?
}

q := newQueue(entryMod.Manifest.Deps)
Expand Down Expand Up @@ -61,7 +61,7 @@ func (p Manager) Build(ctx context.Context, workdir string) (compiler.RawBuild,
}

return compiler.RawBuild{
EntryModRef: src.ModuleRef{Path: "", Version: ""},
EntryModRef: src.ModuleRef{Path: "@"},
Modules: mods,
}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sourcecode/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Location struct {
}

func (l Location) String() string {
if l.ModRef.Path == "" { // cur mod
if l.ModRef.Path == "@" {
return fmt.Sprintf("%v/%v.neva", l.PkgName, l.FileName)
}
return fmt.Sprintf("%v/%v/%v.neva", l.ModRef, l.PkgName, l.FileName)
Expand Down Expand Up @@ -127,7 +127,7 @@ func (s Scope) entity(entityRef EntityRef) (Entity, Location, error) {
modRef ModuleRef
)
if pkgImport.ModuleName == "@" {
modRef = s.Location.ModRef
modRef = s.Location.ModRef // FIXME s.Location.ModRef is where we are now (e.g. std)
mod = curMod
} else {
modRef = curMod.Manifest.Deps[pkgImport.ModuleName]
Expand Down

0 comments on commit 7d165d0

Please sign in to comment.