Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotations (changes and documentation) #215

Closed
jakhog opened this issue Mar 27, 2018 · 3 comments
Closed

Annotations (changes and documentation) #215

jakhog opened this issue Mar 27, 2018 · 3 comments

Comments

@jakhog
Copy link

jakhog commented Mar 27, 2018

Automatic documentation of platform annotations has been discussed a few times already (#187 and #34), and although a proposed solution is currently available in Documentrospection, it is not used or maintained.

Further, many platform annotations that we use, are more flags than they are values. But the current grammar says that annotations have to be '@' ANNOTATION_ID (STRING_LIT|EXTERN). So we usually end up doing either e.g. @sync_send "" or @sync_send "true". This is slightly annoying.

I propose two solutions:

Solution 1 - Documentation

We could link the AnnotatedElementHelper more closely to the Compilers or the Contexts, and enforce that the compiler registers what annotations it uses, together with a short string explaining the usage and possibly the elements where it can be applied.

What I'm thinking, is that in a Compiler constructor, we do something like:

ctx.registerAnnotation("sync_send", "Send messages by calling functions instead of using the FIFO", "message");
ctx.registerAnnotation("fork_thread", "Call this function in a new Thread", "function");

Then we switch the AnnotatedElementHelper calls to something like

ctx.hasAnnotation(element, "sync_send");
ctx.hasAnnotation(element, "sync_send", "true");
ctx.getAnnotation(element, "sync_send");

And if you try to get an annotation you haven't defined, we print a warning, and possibly don't return anything from those methods, so that we are sure that we properly declare everything.

If we go with this approach, it would be really easy to programmatically generate a list of the currently supported annotations, and their usage, by simply looping through all compilers (and protocols), and printing the results. So that you could use the compiler.registry cli or a new button in Eclipse to get that list.

Solution 2 - Flag annotations

This one is a bit simpler (and slightly unrelated). I propose that we make the string literal following the annotation id optional. So that we can use them as flags as well.

I don't think this would cause any parser conflicts, as I don't think there is any way of declaring an annotation just before any other string literal.

Solution 2 - Done!

@jakhog
Copy link
Author

jakhog commented Mar 27, 2018

Also somewhat related to #214

@brice-morin
Copy link
Collaborator

Note that we might use an EClass instead of the string to give the scope of annotations. Something like ThingMLPackage.eINSTANCE.getThing(), which might give us some more control, and also avoid typos, etc.

@brice-morin
Copy link
Collaborator

Note we might also declare optional default values for the annotations (which we typically use in the getOrElse)

brice-morin added a commit that referenced this issue Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants