github.com/blueinnovationsgroup/can-go@v0.0.0-20230518195432-d0567cda0028/pkg/dbc/analysis/passes/signalbounds/analyzer.go (about)

     1  package signalbounds
     2  
     3  import (
     4  	"github.com/blueinnovationsgroup/can-go/pkg/dbc"
     5  	"github.com/blueinnovationsgroup/can-go/pkg/dbc/analysis"
     6  )
     7  
     8  func Analyzer() *analysis.Analyzer {
     9  	return &analysis.Analyzer{
    10  		Name: "signalbounds",
    11  		Doc:  "check that signal start and end bits are within bounds of the message size",
    12  		Run:  run,
    13  	}
    14  }
    15  
    16  func run(pass *analysis.Pass) error {
    17  	for _, def := range pass.File.Defs {
    18  		message, ok := def.(*dbc.MessageDef)
    19  		if !ok || dbc.IsIndependentSignalsMessage(message) {
    20  			continue
    21  		}
    22  		for i := range message.Signals {
    23  			signal := &message.Signals[i]
    24  			if signal.StartBit >= 8*message.Size {
    25  				pass.Reportf(signal.Pos, "start bit out of bounds")
    26  			}
    27  			// TODO: Check end bit
    28  		}
    29  	}
    30  	return nil
    31  }