MCPcopy Index your code
hub / github.com/expr-lang/expr / isPointerPlusAcc

Function isPointerPlusAcc

optimizer/sum_range.go:71–102  ·  view source on GitHub ↗

isPointerPlusAcc checks if the node represents `# + #acc` pattern

(node Node)

Source from the content-addressed store, hash-verified

69
70// isPointerPlusAcc checks if the node represents `# + #acc` pattern
71func isPointerPlusAcc(node Node) bool {
72 predicate, ok := node.(*PredicateNode)
73 if !ok {
74 return false
75 }
76
77 binary, ok := predicate.Node.(*BinaryNode)
78 if !ok {
79 return false
80 }
81
82 if binary.Operator != "+" {
83 return false
84 }
85
86 // Check for # + #acc (pointer + accumulator)
87 leftPointer, leftIsPointer := binary.Left.(*PointerNode)
88 rightPointer, rightIsPointer := binary.Right.(*PointerNode)
89
90 if leftIsPointer && rightIsPointer {
91 // # + #acc: Left is pointer (Name=""), Right is acc (Name="acc")
92 if leftPointer.Name == "" && rightPointer.Name == "acc" {
93 return true
94 }
95 // #acc + #: Left is acc (Name="acc"), Right is pointer (Name="")
96 if leftPointer.Name == "acc" && rightPointer.Name == "" {
97 return true
98 }
99 }
100
101 return false
102}
103
104// applySumPredicate tries to compute the result of sum(m..n, predicate) at compile time.
105// Returns (result, true) if optimization is possible, (0, false) otherwise.

Callers 1

VisitMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…