@@ -85,10 +85,32 @@ class Expr extends StmtParent, @expr {
8585 override string toString ( ) { none ( ) }
8686
8787 /** Gets the value of this expression, if it is a constant. */
88- string getValue ( ) { exists ( @value v | values ( v , result , _) and valuebind ( v , underlyingElement ( this ) ) ) }
88+ string getValue ( ) { exists ( @value v | values ( v , result ) and valuebind ( v , underlyingElement ( this ) ) ) }
89+
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+
95+ /**
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 ( ) )
106+ }
89107
90108 /** Gets the source text for the value of this expression, if it is a constant. */
91- string getValueText ( ) { exists ( @value v | values ( v , _, result ) and valuebind ( v , underlyingElement ( this ) ) ) }
109+ string getValueText ( ) {
110+ if exists ( this .getValueTextFollowingConversions ( ) )
111+ then result = this .getValueTextFollowingConversions ( )
112+ else result = this .getValue ( )
113+ }
92114
93115 /** Holds if this expression has a value that can be determined at compile time. */
94116 cached
0 commit comments