@@ -267,17 +267,36 @@ class ImplicitDerefNodeState extends TImplicitDerefNodeState {
267267 }
268268}
269269
270+ /**
271+ * A node used to represent implicit dereferencing/borrowing.
272+ */
273+ abstract class ImplicitDerefBorrowNode extends Node {
274+ /**
275+ * Gets the node that should the predecessor in a reference store-step into this
276+ * node, if any.
277+ */
278+ abstract Node getBorrowInputNode ( ) ;
279+
280+ abstract AstNode getUnderlyingAstNode ( ) ;
281+
282+ override CfgScope getCfgScope ( ) { result = this .getUnderlyingAstNode ( ) .getEnclosingCfgScope ( ) }
283+
284+ override Location getLocation ( ) { result = this .getUnderlyingAstNode ( ) .getLocation ( ) }
285+ }
286+
270287/**
271288 * A node used to represent implicit dereferencing.
272289 */
273- class ImplicitDerefNode extends Node , TImplicitDerefNode {
290+ class ImplicitDerefNode extends ImplicitDerefBorrowNode , TImplicitDerefNode {
274291 AstNode n ;
275292 DerefChain derefChain ;
276293 ImplicitDerefNodeState state ;
277294 int i ;
278295
279296 ImplicitDerefNode ( ) { this = TImplicitDerefNode ( n , derefChain , state , i , false ) }
280297
298+ override AstNode getUnderlyingAstNode ( ) { result = n }
299+
281300 private predicate isNoOp ( ) { derefChain .isNoOp ( i ) }
282301
283302 private Node getInputNode ( ) {
@@ -297,11 +316,7 @@ class ImplicitDerefNode extends Node, TImplicitDerefNode {
297316 result = this .getInputNode ( )
298317 }
299318
300- /**
301- * Gets the node that should the predecessor in a reference store-step into this
302- * node, if any.
303- */
304- Node getBorrowInputNode ( ) {
319+ override Node getBorrowInputNode ( ) {
305320 not this .isNoOp ( ) and
306321 state = TImplicitDerefNodeBorrowState ( ) and
307322 result = this .getInputNode ( )
@@ -322,10 +337,6 @@ class ImplicitDerefNode extends Node, TImplicitDerefNode {
322337 i = derefChain .length ( ) - 1
323338 }
324339
325- override CfgScope getCfgScope ( ) { result = n .getEnclosingCfgScope ( ) }
326-
327- override Location getLocation ( ) { result = n .getLocation ( ) }
328-
329340 override string toString ( ) { result = n + " [implicit deref " + i + " in state " + state + "]" }
330341}
331342
@@ -366,19 +377,15 @@ private class ImplicitDerefOutNode extends ImplicitDerefNode, OutNode {
366377/**
367378 * A node that represents the value of an expression _after_ implicit borrowing.
368379 */
369- class ImplicitBorrowNode extends Node , TImplicitBorrowNode {
380+ class ImplicitBorrowNode extends ImplicitDerefBorrowNode , TImplicitBorrowNode {
370381 AstNode n ;
371382 DerefChain derefChain ;
372383
373384 ImplicitBorrowNode ( ) { this = TImplicitBorrowNode ( n , derefChain , false ) }
374385
375- AstNode getNode ( ) { result = n }
386+ override AstNode getUnderlyingAstNode ( ) { result = n }
376387
377- /**
378- * Gets the node that should the predecessor in a reference store-step into this
379- * node.
380- */
381- Node getBorrowInputNode ( ) {
388+ override Node getBorrowInputNode ( ) {
382389 result =
383390 TImplicitDerefNode ( n , derefChain , TImplicitDerefNodeAfterDerefState ( ) ,
384391 derefChain .length ( ) - 1 , false )
@@ -387,10 +394,6 @@ class ImplicitBorrowNode extends Node, TImplicitBorrowNode {
387394 result .( AstNodeNode ) .getAstNode ( ) = n
388395 }
389396
390- override CfgScope getCfgScope ( ) { result = n .getEnclosingCfgScope ( ) }
391-
392- override Location getLocation ( ) { result = n .getLocation ( ) }
393-
394397 override string toString ( ) { result = n + " [implicit borrow]" }
395398}
396399
0 commit comments