@@ -133,6 +133,7 @@ private module Cached {
133133 not scopeDefinesParameterVariable ( scope , name , _) and
134134 not inherits ( scope , name , _)
135135 } or
136+ TSelfVariable ( SelfBase:: Range scope ) or
136137 TLocalVariableSynth ( AstNode n , int i ) { any ( Synthesis s ) .localVariable ( n , i ) }
137138
138139 // Db types that can be vcalls
@@ -307,7 +308,8 @@ private module Cached {
307308 access ( this , _) or
308309 this instanceof Ruby:: GlobalVariable or
309310 this instanceof Ruby:: InstanceVariable or
310- this instanceof Ruby:: ClassVariable
311+ this instanceof Ruby:: ClassVariable or
312+ this instanceof Ruby:: Self
311313 }
312314 }
313315
@@ -374,9 +376,10 @@ abstract class VariableImpl extends TVariable {
374376 abstract Location getLocationImpl ( ) ;
375377}
376378
377- class TVariableReal = TGlobalVariable or TClassVariable or TInstanceVariable or TLocalVariableReal ;
379+ class TVariableReal =
380+ TGlobalVariable or TClassVariable or TInstanceVariable or TLocalVariableReal or TSelfVariable ;
378381
379- class TLocalVariable = TLocalVariableReal or TLocalVariableSynth ;
382+ class TLocalVariable = TLocalVariableReal or TLocalVariableSynth or TSelfVariable ;
380383
381384/**
382385 * This class only exists to avoid negative recursion warnings. Ideally,
@@ -475,6 +478,18 @@ class ClassVariableImpl extends VariableReal, TClassVariable {
475478 final override Scope:: Range getDeclaringScopeImpl ( ) { result = scope }
476479}
477480
481+ class SelfVariableImpl extends VariableReal , TSelfVariable {
482+ private SelfBase:: Range scope ;
483+
484+ SelfVariableImpl ( ) { this = TSelfVariable ( scope ) }
485+
486+ final override string getNameImpl ( ) { result = "self" }
487+
488+ final override Location getLocationImpl ( ) { result = scope .getLocation ( ) }
489+
490+ final override Scope:: Range getDeclaringScopeImpl ( ) { result = scope }
491+ }
492+
478493abstract class VariableAccessImpl extends Expr , TVariableAccess {
479494 abstract VariableImpl getVariableImpl ( ) ;
480495}
@@ -602,3 +617,26 @@ private class ClassVariableAccessSynth extends ClassVariableAccessRealImpl,
602617
603618 final override string toString ( ) { result = v .getName ( ) }
604619}
620+
621+ abstract class SelfVariableAccessImpl extends LocalVariableAccessImpl , TSelfVariableAccess { }
622+
623+ private class SelfVariableAccessReal extends SelfVariableAccessImpl , TSelfReal {
624+ private Ruby:: Self self ;
625+ private SelfVariable var ;
626+
627+ SelfVariableAccessReal ( ) { this = TSelfReal ( self ) and var = TSelfVariable ( scopeOf ( self ) ) }
628+
629+ final override SelfVariable getVariableImpl ( ) { result = var }
630+
631+ final override string toString ( ) { result = var .toString ( ) }
632+ }
633+
634+ private class SelfVariableAccessSynth extends SelfVariableAccessImpl , TSelfSynth {
635+ private SelfVariable v ;
636+
637+ SelfVariableAccessSynth ( ) { this = TSelfSynth ( _, _, v ) }
638+
639+ final override LocalVariable getVariableImpl ( ) { result = v }
640+
641+ final override string toString ( ) { result = v .getName ( ) }
642+ }
0 commit comments