@@ -87,31 +87,28 @@ class Expr extends StmtParent, @expr {
8787 /** Gets the value of this expression, if it is a constant. */
8888 string getValue ( ) { exists ( @value v | values ( v , result ) and valuebind ( v , underlyingElement ( this ) ) ) }
8989
90+ /** Gets the value text of this expression that's in the database. */
91+ private string getDbValueText ( ) {
92+ exists ( @value v | valuebind ( v , underlyingElement ( this ) ) and valuetext ( v , result ) )
93+ }
94+
9095 /**
91- * Walk along the sequence of `getConversion()s` until we reach
92- * one with a valuetext, and then return that valuetext, if any.
93- * For example, in an invocation of `#define THREE (1+2)`, there
94- * will not be a valuetext for `1+2`, but the conversion `(1+2)`
95- * will have valuetext `THREE`.
96- */
97- private string getValueTextFollowingConversions ( Expr e ) {
98- e = this .getConversion * ( )
99- and
100- e .getValue ( ) = this .getValue ( )
101- and
102- ( if exists ( @value v |
103- valuebind ( v , underlyingElement ( e ) ) and
104- valuetext ( v , _) )
105- then exists ( @value v |
106- valuebind ( v , underlyingElement ( e ) ) and
107- valuetext ( v , result ) )
108- else result = this .getValueTextFollowingConversions ( e .getConversion ( ) ) )
96+ * Gets the value text of `this`. If it doesn't have one, then instead
97+ * gets the value text is `this`'s nearest compatible conversion, if any.
98+ */
99+ private string getValueTextFollowingConversions ( ) {
100+ if exists ( this .getDbValueText ( ) )
101+ then result = this .getDbValueText ( )
102+ else exists ( Expr e |
103+ e = this .getConversion ( ) and
104+ e .getValue ( ) = this .getValue ( ) and
105+ result = e .getValueTextFollowingConversions ( ) )
109106 }
110107
111108 /** Gets the source text for the value of this expression, if it is a constant. */
112109 string getValueText ( ) {
113- if exists ( this .getValueTextFollowingConversions ( this ) )
114- then result = this .getValueTextFollowingConversions ( this )
110+ if exists ( this .getValueTextFollowingConversions ( ) )
111+ then result = this .getValueTextFollowingConversions ( )
115112 else result = this .getValue ( )
116113 }
117114
0 commit comments