Book a Demo

Author Topic: Creating a C Language Dialect for Code Generation  (Read 3290 times)

TWirtgen

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Creating a C Language Dialect for Code Generation
« on: May 29, 2014, 06:41:11 pm »
Hello,

I have started to create my own C Language dialect for Code generation by copying the template from the built-in C language in the Code Template Editor. I've modified the templates just a bit to verify that the generated code for the *.c and *.h-files is now really coming from my templates. This part is working. :)

As known, the generation of code-files starts with the classes found directly below a selected package.

My understanding is that the initial/root-templates are "File" and "File Impl" and that "File" would usually generate the *.h file and "File Impl" would generate the *.c file. For the built-in languages, then menu -> Tools -> Options -> Source Code Engineering provides a way to customize the file extensions for "File" and "File Impl".

However, I don't understand how I can tell the code generator which file-extension to create for custom languages, as they do not appear in the menu mentioned above. I've looked in the EA help files and in the forum, but wasn't successful. With my C dialect, EA first generated both *.c and *.h files, then after some editing only the *.h file and after some other changes it generates a file named according to the class name, but without any file-extension. I'm unaware that my editing was influencing the file extension, but deducing from the changed behaviour, there must be a way to tell EA which files and file-extensions to generate for the initial template in invokes.

Is it also possible to configure EA to generate additional files from the initial class, e.g. "%fileName%.xyz" and invoke a custom root template to generate it's contents or are the root templates "File" and "File Impl" hardcoded in EA?

I'd really appreciate helpful comments. ::)

best regards

Thomas

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Creating a C Language Dialect for Code Generat
« Reply #1 on: May 30, 2014, 08:55:59 am »
See the following page for how to set the extensions.

http://www.sparxsystems.com/enterprise_architect_user_guide/10/extending_uml_models/define_code_options.html

File and File Impl are hard coded. You won't get more than those two files out of a single generation of a class.

TWirtgen

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Creating a C Language Dialect for Code Generat
« Reply #2 on: June 05, 2014, 07:22:54 am »
Hello Simon,

thank you very much - that was what I needed, and it's actually in the help file - great! I've now added he following XML snippet:

<CodeOptions>
    <CodeOption name="DefaultExtension">.hh</CodeOption>
    <CodeOption name="ImplementationExtension">.cc</CodeOption>
    <CodeOption name="DefaultSourceDirectory"></CodeOption>
    <CodeOption name="ImplementationPath">.\</CodeOption>
    <CodeOption name="HasImplementation">true</CodeOption>
</CodeOptions>

and could now customize the setting for "DefaultExtension" to ".hh" (verified by looking into menu -> Tools -> Options -> Source Code Engineering). However, the Source Extension does not appear at all, despite the code options above.

By looking at all default languages I've recognized that for the language C, the extensions are named "HeaderExtension" and "SourceExtension" instead of "DefaultExtension". Do I need to change the options to get a source extension of ".cc"? Maybe like this:

   <CodeOption name="HeaderExtension">.hh</CodeOption>
    <CodeOption name="SourceExtension">.cc</CodeOption>


Is the boolean switch maybe "HasSource" instead of "HasImplementation" or did I make any mistake in the XML?

I'm using EA version 10.0.1006 on Windows7 (64bit).

Thanks for feedback.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Creating a C Language Dialect for Code Generat
« Reply #3 on: June 05, 2014, 09:02:03 am »
No, you've got the options right.

Have you put something in the File Impl template and tried generating?