Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Objectteams » Modifying Type Declaration(Hints to modify compiler behaviour on Type Declaration)
Modifying Type Declaration [message #643187] Sun, 05 December 2010 21:19 Go to next message
Yiannis Gkoufas is currently offline Yiannis GkoufasFriend
Messages: 6
Registered: December 2010
Junior Member
Hi there!
I have read and run pretty much all of the examples I have found online, but I have failed to understand how it possible to modify compiler behaviour on Type Declaration.
Can anyone provide me with some hints?

Thanks a lot!
Re: Modifying Type Declaration [message #643190 is a reply to message #643187] Sun, 05 December 2010 22:12 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1036
Registered: July 2009
Senior Member
Hi,

I'm not sure exactly how to help:

What is your goal? Do you want to do something similar
to the examples in my blog post [1] [2] [3] ?

Also, are you looking for hints on how to apply OT/J and
OT/Equinox or are you looking for advice on how class
TypeDeclaration (in the Eclipse Java Compiler?) works and
can be modified?

best,
Stephan
Re: Modifying Type Declaration [message #643191 is a reply to message #643190] Sun, 05 December 2010 22:28 Go to previous messageGo to next message
Yiannis Gkoufas is currently offline Yiannis GkoufasFriend
Messages: 6
Registered: December 2010
Junior Member
Hi Stephan,

I have studied your 3 examples but they didn't help me in my case.
I want to develop an OT plugin which makes the following enum declaration valid:

public enum enumName2 extends enumName{
three,four;
}

And, as you understand, my purpose is if the enumName is:

public enum enumName{
one,two;
}

then the enumName2 includes one,two,three,four.

Thanks!
Re: Modifying Type Declaration [message #643319 is a reply to message #643187] Mon, 06 December 2010 13:55 Go to previous messageGo to next message
Jan Marc Hoffmann is currently offline Jan Marc HoffmannFriend
Messages: 32
Registered: July 2009
Member
Correct me but I don't think Stephans example will apply here.

Adapting the TypeDeclaration won't be a problem but adjusting the Parser to parse your grammer might be problematic. You will have to modify the Parser logic which is generally only possible if you adjust the grammar and regenerate the logic tables used by the Parser to match your new grammar.

The only way around this would be to trick the Parser by manipulating the Scanner. This would be done the following way but is not trivial:

1. Create a ScannerAdaptor

- When the Scanner reads the 'extends' token, check if you are handling an enum and silently discard the 'extends' and the following 'TypeRef'. But keep them somwhere else. (Especially the positions)

- Activate the ParserAdaptor

2. Create a ParserAdaptor

- Adapt the Parser.consumeEnumHeader() method to handle your additional informations. (e.g. by a role of TypeDeclaration)

- Discard the enum which was referenced after the extends token.

But beware: This will only work if they are in the same CompilationUnit and in the fitting order.

If you want real "extends" behaviour (that keyword might not be fitting for your task OO-wise) you need to correctly resolve the referenced Enum. Which will be quite complicated.

So your task might be way more complicated than you first thought it might be. Depending on the priority of this one I would rather drop it. :=)

greetings

Jan Marc
Re: Modifying Type Declaration [message #643452 is a reply to message #643319] Mon, 06 December 2010 22:25 Go to previous messageGo to next message
Yiannis Gkoufas is currently offline Yiannis GkoufasFriend
Messages: 6
Registered: December 2010
Junior Member
Hi Jan!

Thanks a lot for your remarks, I will start coding and see what happens! Very Happy
Re: Modifying Type Declaration [message #643466 is a reply to message #643452] Mon, 06 December 2010 23:46 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1036
Registered: July 2009
Senior Member
Yiannis Gkoufas wrote on Mon, 06 December 2010 23:25
Hi Jan!

Thanks a lot for your remarks, I will start coding and see what happens! Very Happy


Good luck Smile

As Jan Marc correctly mentioned, an "extends" relationship
between enums could mean different things and you surely
won't get true sub-typing, e.g.

But feel free to ask more specific questions on how to
achieve the adaptation using OT/J.

best,
Stephan
Re: Modifying Type Declaration [message #643524 is a reply to message #643466] Tue, 07 December 2010 09:22 Go to previous messageGo to next message
Yiannis Gkoufas is currently offline Yiannis GkoufasFriend
Messages: 6
Registered: December 2010
Junior Member
Thanks a lot all, Stephan!

My first question on Jan's suggestion is this:
when saying:
"check if you are handling an enum"

it means to wait for the enum keyword and have a flag about it or is it a more high-level way to check it?
Re: Modifying Type Declaration [message #643629 is a reply to message #643524] Tue, 07 December 2010 16:52 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1036
Registered: July 2009
Senior Member
Yiannis Gkoufas wrote on Tue, 07 December 2010 10:22

My first question on Jan's suggestion is this:
when saying:
"check if you are handling an enum"

it means to wait for the enum keyword and have a flag about it or is it a more high-level way to check it?


Detecting an enum declaration by waiting for the enum
keyword sounds pretty straight forward to me Smile
Much in line with the ScannerAdaptor from my blog post.

When you look for a more high-level way, I wouldn't
actually know which way is up.

I think Jan Marcs suggestion is pointing in a good
direction already.

Perhaps the non-obvious part is where should the
flag ("I have seen the enum keyword") be stored?
Just make it a field of the role that adapts the
Scanner, and it will be immediately available
once you see the subsequent "extends".
Only make sure you define a point where the flag
will be reset if you don't see "extends" Smile

HTH
Stephan
Re: Modifying Type Declaration [message #644617 is a reply to message #643319] Mon, 13 December 2010 13:45 Go to previous messageGo to next message
Yiannis Gkoufas is currently offline Yiannis GkoufasFriend
Messages: 6
Registered: December 2010
Junior Member
Jan Marc Hoffmann wrote on Mon, 06 December 2010 08:55

2. Create a ParserAdaptor

- Adapt the Parser.consumeEnumHeader() method to handle your additional informations. (e.g. by a role of TypeDeclaration)

- Discard the enum which was referenced after the extends token.



Hi Jan!

are you sure that I have to adapt the consumeEnumHeader() method and not consumeEnumDeclaration().

Is there anywhere online code snippets of adapting consumeEnumDeclaration/Header() or consumeClassDeclaration()?

Thanks a lot!
Yiannis
Re: Modifying Type Declaration [message #644956 is a reply to message #644617] Tue, 14 December 2010 23:44 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1036
Registered: July 2009
Senior Member
Yiannis Gkoufas wrote on Mon, 13 December 2010 14:45

are you sure that I have to adapt the consumeEnumHeader() method and not consumeEnumDeclaration().



I don't think this was intended as an exact recipe Smile
So, yes, if the logic you want to insert requires that the
enum has been fully constructed then consumeEnumDeclaration()
is a better hook.

So, just go ahead, declare a callin binding to the consume
method, inspect the astStack and find the newly constructed
TypeDeclaration on top, which you may then update as desired.

cheers,
Stephan

Re: Modifying Type Declaration [message #645586 is a reply to message #644956] Sat, 18 December 2010 11:26 Go to previous message
Yiannis Gkoufas is currently offline Yiannis GkoufasFriend
Messages: 6
Registered: December 2010
Junior Member
Thanks a lot for your advices!
I think I am very close to the solution!
Cheers!
Previous Topic:CFLOW like behaviour?
Next Topic:Milestone 5 Release and other activities
Goto Forum:
  


Current Time: Fri Nov 28 08:43:21 GMT 2014

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

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