OperatorIsImmutable returns true if the given expression corresponds to a constant operator. Note importantly that this will return true for all expr types other than FuncExpr, CastExpr, UnaryExpr, BinaryExpr, and ComparisonExpr. It does not do any recursive searching.
(expr Expr)
| 15 | // expr types other than FuncExpr, CastExpr, UnaryExpr, BinaryExpr, and |
| 16 | // ComparisonExpr. It does not do any recursive searching. |
| 17 | func OperatorIsImmutable(expr Expr) bool { |
| 18 | switch t := expr.(type) { |
| 19 | case *FuncExpr: |
| 20 | return t.ResolvedOverload().Class == NormalClass && t.fn.Volatility <= volatility.Immutable |
| 21 | |
| 22 | case *CastExpr: |
| 23 | v, ok := cast.LookupCastVolatility(t.Expr.(TypedExpr).ResolvedType(), t.typ) |
| 24 | return ok && v <= volatility.Immutable |
| 25 | |
| 26 | case *UnaryExpr: |
| 27 | return t.op.Volatility <= volatility.Immutable |
| 28 | |
| 29 | case *BinaryExpr: |
| 30 | return t.Op.Volatility <= volatility.Immutable |
| 31 | |
| 32 | case *ComparisonExpr: |
| 33 | return t.Op.Volatility <= volatility.Immutable |
| 34 | |
| 35 | default: |
| 36 | return true |
| 37 | } |
| 38 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…