renan-guimaraes / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

An "op" property on TBinaryOpExpr would be very helpful #384

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
TBinaryOpExpr's class declaration comes with the comment:
// left "op" right

It exposes Left and Right properties, but no way to tell what the operator is.  
The only way seems to be to examine the class type directly and have some sort 
of lookup, which is a rather poor solution since there are many, many 
descendants of TBinaryOpExpr and more expression types are being added on a 
regular basis as development of DWS continues.

It would be very nice, for code generation purposes, if TBinaryOpExpr exposed 
some enum property that represented the operator used in the expression.

Original issue reported on code.google.com by masonwhe...@gmail.com on 2 May 2013 at 6:44

GoogleCodeExporter commented 9 years ago
Well, the whole point of having class is to explicitly avoid the need for a 
global enumeration of operators, so that operators can be added, refined or 
differentiated without constraints.

This allows to distinguish between integer addition and string concatenation 
f.i. which would both be '+' in Pascal, but are respectively '+' and '||' in 
SQL f.i.
Also when optimizations are active operators can get "mutated" to different 
things, from constants to specific expressions. For instance an integer 
addition can be mutated to an increment in some circumstances.

(oh and a new operator indeed just got added, for "string in string")

Original comment by zar...@gmail.com on 3 May 2013 at 10:09

GoogleCodeExporter commented 9 years ago

Original comment by zar...@gmail.com on 17 May 2013 at 10:12