Overloaded Operation Rules?

Hello I am lost with Overloaded Operation Rules.

The doc says :

Overloaded Operation Rules
Overloaded operation rules reside within a root node of concept OverloadedOpRulesContainer. Each
overloaded operation rule consists of:
   • an applicable operation concept, i.e. a reference to a concept of operation to which a rule is
     applicable (e.g. PlusExpression);
   • left and right operand type restrictions, which contain a type which restricts a type of left/right
     operand, respectively. A restriction can be either exact or not, which means that a type of an

      operand should be exactly a type in a restriction(if restriction is exact), or its subtype(if not exact),

      for a rule to be applicable to such operand types;

• a function itself, which returns a type of operation by operation, left and right operand types.

How can define such an operation?

If i have Peer>Apple and Cat>Dog, yes I do want a different operation (no sexual conotation here he...) but how do I define it???

Could some one give a clear example of it.

Thanks a lot



Hi Guys, anyone having any examples or ideas?



Hi Thomas!

for instance, the following code in BL determines type of an operation + :

operation concepts: PlusExpression| MinusExpression| DivExpression| MulExpression| RemExpression| BinaryBitwiseOperation                                                                                                                                                 
left operand type: <Numeric>.descriptor is exact: false use strong subtyping false                                                                                                                                                                                       
right operand type: <Numeric>.descriptor is exact: false use strong subtyping false                                                                                                                                                                                      
operation type:                                                                                                                                                                                                                                                          
(operation, leftOperandType, rightOperandType)->node< > {
  if (leftOperandType.isInstanceOf(NullType) || rightOperandType.isInstanceOf(NullType)) {
    return null;
  } else {
    return Queries.getBinaryOperationType(leftOperandType, rightOperandType);

"operation concepts" are concepts for which this rule is applicable, PlusExpression is among them;

"left operand type" and "right operand type" are types for left and right operands, respectively. "is exact" determines whether the type of an operand should be exact as written or the rule is applicable to their subtypes.

here it is written if an operation is PlusExpression (or others), left and right operand have numeric type, then this rule is applied.

after the word "type" goes a function which determines a type of an operation.
operation concepts: PlusExpression                                                                                                                                                                                                                                       
one operand type: <string> is exact: false use strong subtyping false                                                                                                                                                                                                    
operation type:                                                                                                                                                                                                                                                          
(operation, leftOperandType, rightOperandType)->node< > {
  return <string>;

this rule is applicable if a plus expression has at list one operand of type string (or subtypes). then it returns string type as a type of an operation.                                                                                                                                                                                                     

Regards, Cyril.            


Please sign in to leave a comment.