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

     1  package intervals
     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: "intervals",
    11  		Doc:  "check that all intervals are valid (min <= max)",
    12  		Run:  run,
    13  	}
    14  }
    15  
    16  func run(pass *analysis.Pass) error {
    17  	for _, def := range pass.File.Defs {
    18  		switch def := def.(type) {
    19  		case *dbc.EnvironmentVariableDef:
    20  			if def.Minimum > def.Maximum {
    21  				pass.Reportf(def.Pos, "invalid interval: [%f, %f]", def.Minimum, def.Maximum)
    22  			}
    23  		case *dbc.MessageDef:
    24  			for i := range def.Signals {
    25  				signal := &def.Signals[i]
    26  				if signal.Minimum > signal.Maximum {
    27  					pass.Reportf(def.Pos, "invalid interval: [%f, %f]", signal.Minimum, signal.Maximum)
    28  				}
    29  			}
    30  		case *dbc.AttributeDef:
    31  			if def.MinimumInt > def.MaximumInt || def.MinimumFloat > def.MaximumFloat {
    32  				pass.Reportf(def.Pos, "invalid interval: [%d, %d]", def.MinimumInt, def.MaximumInt)
    33  			}
    34  			if def.MinimumFloat > def.MaximumFloat {
    35  				pass.Reportf(def.Pos, "invalid interval: [%f, %f]", def.MinimumFloat, def.MaximumFloat)
    36  			}
    37  		}
    38  	}
    39  	return nil
    40  }