Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Define infix arithmetic operations for a custom class
Define infix arithmetic operations for a custom class [message #1840045] Tue, 06 April 2021 06:32 Go to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 346
Registered: August 2013
Senior Member
Hi

Is it possible to implement something like this?

transformation Test();

main()
{
    var obj := object MyClass {};
    obj * 1;
}

intermediate class MyClass { val : Integer };
	
query MyClass::*(int : Integer) : MyClass = self;


QVTo editor doesn't show an error for "obj * 1". It shows an error only for the last query.

I tried to use the following possible aliases but with no success:
query MyClass::_*(int : Integer) : MyClass = self;
query MyClass::mult(int : Integer) : MyClass = self;
query MyClass::multiply(int : Integer) : MyClass = self;
query MyClass::multiplication(int : Integer) : MyClass = self;
Re: Define infix arithmetic operations for a custom class [message #1840046 is a reply to message #1840045] Tue, 06 April 2021 07:07 Go to previous messageGo to next message
Christopher Gerking is currently offline Christopher GerkingFriend
Messages: 116
Registered: April 2011
Senior Member
Hi

Quote:
Is it possible to implement something like this?

I'm afraid that custom infix notation is not supported.


Quote:
QVTo editor doesn't show an error for "obj * 1".

It is indeed strange that there is no error.


Quote:
query MyClass::*(int : Integer) : MyClass = self;

Why = self? I would have done it this way:

transformation Test();

main()
{
    var obj := object MyClass {};
    obj.mult(1);
}

intermediate class MyClass { val : Integer };
	
query MyClass::mult(int : Integer) : MyClass = object MyClass {
	val := self.val * int;
};
Re: Define infix arithmetic operations for a custom class [message #1840051 is a reply to message #1840046] Tue, 06 April 2021 07:56 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 346
Registered: August 2013
Senior Member
Christopher Gerking wrote on Tue, 06 April 2021 12:07
It is indeed strange that there is no error.

Thanks for answer! Because of this behaviour I decided that custom infix operators are supported, and I can define them using an alias. I will use standard queries instead as you suggest.
Re: Define infix arithmetic operations for a custom class [message #1840079 is a reply to message #1840051] Tue, 06 April 2021 12:45 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7670
Registered: July 2009
Senior Member
Hi

This is an OCL limitation.

x . name
is a PropertyCallExp, whereas

x (  ... )
is an OperationCallExp with a few magic builtin infixes.

For the Pivot-based OCL where the Standard Library has an extensible model:

	/**
	oclText[false] if either oclText[self] or oclText[b] is oclText[false].
	Otherwise oclText[true].
	**/
	operation and2(b : Boolean[1]) : Boolean[1] validating precedence=AND => 'org.eclipse.ocl.pivot.library.logical.BooleanAndOperation2'
	{
		body: if self = false then false
		      elseif b = false then false
		      else true
		      endif;
	}


The 2-valued variant of and is added using the above segment of OCL-2.5.oclstlib as an infix with AND precedence.

Sadly migration of QVTo to exploit the Pivot-based OCL is a long way away.

Regards

Ed Willink
Previous Topic:QVTo correct map references
Next Topic:Problems with color themes in Eclipse
Goto Forum:
  


Current Time: Fri Sep 20 15:11:43 GMT 2024

Powered by FUDForum. Page generated in 0.03946 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top