Home » Modeling » M2T (model-to-text transformation) » Questions about generation code for Objective C and small games for iPhone
Questions about generation code for Objective C and small games for iPhone [message #900578] |
Tue, 07 August 2012 15:54  |
Ricardo1980 Missing name Messages: 11 Registered: November 2011 |
Junior Member |
|
|
Hello out there!
I'm new to M2T and have some questions. I'd like to create a system to create simple iOS games (something like interactive ebooks for children). I already have an idea of my required metamodel and diagrams, but I have some questions regarding code generation.
I'm reading about different M2T tools: Acceleo, Xtend, CommentTemplate, Xpand and Mofscript, but actually I don't have real experience and all this stuff is new to me. So I'd like to know your opinions about which one could be better for this project. Let me know your ideas.
The code I want to generate have to use cocos2d as a 2d engine, and evidently Objective C as a language. Because of this, ARC (automatic reference counting) cannot be use, so I have to manage the memory manually, using retain and release. Is this a problem with code generators? I ask this because usually they usually generate Java, where memory is managed automatically using a garbage collector. Is this a problem for some code generators?
Another question I have is, when you generate code, do you also generate project files?
I mean, when using Xcode for creating a project, a file (package) .xcodeproj is created, that has a XML file with all .h and .m files for compiling the project.
Do you usually generate this kind of configuration files with M2T, or just generate a command line to compile all generated files?
I see a MDD project for the iPhone called iPhonical that it seems generates a full iOS program and even launches the simulator from Eclipse, see the video in their website (I can't post links).
Thanks a lot for your suggestions, I appreciate it a lot.
|
|
| | |
Re: Questions about generation code for Objective C and small games for iPhone [message #901531 is a reply to message #900639] |
Mon, 13 August 2012 09:16  |
|
Hi,
Most of the generic code generators (Acceleo, Xtend, CommentTemplate, Xpand and Mofscript) will work the same way. I don't know CommentTemplate but it seems to be similar to the other tools. You write some template that are composed of static pieces of code (in black in the following screenshot) and dynamic ones (in blue) that will use elements from your input model to compute the generated code.

This implies that you have a model representing your code first. This model need to contain the concept that you want to represent in your code (you can define those concepts in a meta-model). It is easy to create a meta-model with the various graphical (ecore tools), tree based (ecore) or textual tools available (xcore).
After that, there are tools that can take your meta-model to generate the tooling matching the concepts defined in your meta-model to let you easily create models. You can generate in one or two clicks a text based tooling (Xtext), a tree based tooling (ecore), or even a form based tooling (EEF). You can also create a graphical tooling for your meta-model but I think that it's a bit more difficult with tools like GMF or Graphiti.
When you have your meta-model and some instances (models), you can generate code from those models. You could also use an existing meta-model as your starting point like UML (which contains familiar concepts like classes or interfaces) but with a custom meta-model you could directly manipulate the concept of your domain. For an iPhone application, you could use concepts like Views or Buttons, this way your tooling generated could let you manipulate familiar concepts instead of having generic programming concepts. It could also help you to create more powerful generators. For example, if you need ten classes to create one complex view in your application, you could use ten instances of the concepts Class of UML and then create a code generator that take an instance of Class and generate a good old Objective-C class. If you defined a concept ComplexView then you could create a generator that takes a ComplexView and generate the ten classes at the same time. If you need to have dozens of those complex views, it is easier to manipulate your model.
You can see here a small domain specific language created with Xtext for Android applications that let you manipulate Android specific concepts directly:
application "My First App" => org.xtext.example.droid.myfirstapp
screen Welcome { }
screen Main { }
More about this DSL here.
The generic code generators that you talked about will all require you to write the template necessary for the code generation. One code option is to start with a prototype of the code you want to generate and then create a model representing this prototype and try to build the generator which, using this model, could re-generate the code of the original prototype. After that you can add more feature to your prototype, your meta-model and your generator.
Among the tools available to generate code, I would recommend Xtend or Acceleo (Full disclosure: I am the leader of Acceleo ) since they are the ones with the most serious tooling. Xpand is nice but I'm pretty sure that you can do with Xtend everything that Xpand does and more (both products are from the same company). As for the features of the generated code, well it only depends on the template that you will write. Is you look at the template generating Python in the previous screenshot, if I want it to have any kind of additional features, I'll have to write it by myself or I'll have to find someone who did it already. The advantage is that you can have the code generated exactly like you want.
Regards,
Stephane Begaudeau, Obeo
--
Twitter: @sbegaudeau & @acceleo
Google+: stephane.begaudeau & acceleo
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo
[Updated on: Mon, 13 August 2012 09:20] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Tue Jul 05 07:48:58 GMT 2022
Powered by FUDForum. Page generated in 0.02318 seconds
|