MCPcopy
hub / github.com/google/mangle / unifyModes

Function unifyModes

analysis/validation.go:1290–1309  ·  view source on GitHub ↗

unifyModes takes multiple modes definition for the statement and merges them together into a single mode definition per argument. Example: single argument modes [+,+,?] result in ?, but [+,+] results in +.

(modes []ast.Mode)

Source from the content-addressed store, hash-verified

1288// unifyModes takes multiple modes definition for the statement and merges them together into a single mode definition per argument.
1289// Example: single argument modes [+,+,?] result in ?, but [+,+] results in +.
1290func unifyModes(modes []ast.Mode) ast.Mode {
1291 if len(modes) == 0 {
1292 return ast.Mode{}
1293 }
1294
1295 var unifiedMode []ast.ArgMode
1296 for i := 0; i < len(modes[0]); i++ {
1297 argMode := modes[0][i]
1298
1299 for _, m := range modes[1:] {
1300 if argMode != m[i] {
1301 argMode = ast.ArgModeInputOutput
1302 break
1303 }
1304 }
1305 unifiedMode = append(unifiedMode, argMode)
1306 }
1307
1308 return unifiedMode
1309}
1310
1311// While checking a rule, we want to look up possible relation types.
1312// If we find several applicable ones, we return the feasible ones.

Callers 2

RewriteClauseFunction · 0.85
CheckRuleMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected