Book a Demo

Author Topic: Exception specification code generation  (Read 3240 times)

gmpff

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Exception specification code generation
« on: December 01, 2003, 07:32:09 am »

I am struggling to get EA to generate exception specifications for C++ code. I set the "throws" tag on my methods, but to no avail. After scratching in the code templates, I uncovered the following (which may or may not mean something):

The code template used for generating exception specifications for C++ code seems suspect. The line in question is

 %opTag:" throws" ? "throw " value : ""%
               ^^^

and is part of the "Operation Declaration" C++ code template (9th line from the bottom on EA 3.60.653). Note the space before the 't' in the "throws" tagname. Is this perhaps an error in the template ?

A similar occurence (tagname prefixed by space), involving "opStereotype", happens a few lines down -  does those spaces carry special significance ?

I "fixed" this by removing the space, but still no exception specification: it appears that there may be a problem with EA's conditional expressions (or in my head).

I create a class, "aclass" and set a tag, "atag" with value, "avalue". When I generate code for the class from the following class template:

// 1. %classTag:"atag"%
// 2. %classTag:"atag" != "" ? "yes" : "no"%
// 3. %classTag:"atag" ? "yes" : "no"%
%if classTag:"atag" != ""%
// 4. %classTag:"atag"%
%endIf%

I get the result:

// 1. avalue
// 2.
// 3.
// 4. avalue

As you can see, the tag does contain the correct value, but the conditional expressions all seem to evaluate to empty (not just stuck on false but completely empty). As number 3 is similar to the one used for the exception specifications, I suspect that that is where the problem with the exception specifications lies.

I eventually got exception specifications working, but only after using an explicit if (i.e. no conditional expression).


benc

  • EA Administrator
  • EA User
  • *****
  • Posts: 200
  • Karma: +0/-0
    • View Profile
Re: Exception specification code generation
« Reply #1 on: December 03, 2003, 09:06:18 pm »
Hi gmpff,

Thanks for the note and detailed information.

The code template is in error: the "throws" and the "stereotype" macros
should not contain those spaces. The template has been updated for the
next release of EA (Build 654). Additionally, there appears to be a bug
in the form of the conditional expression used.

As you pointed out this form does not work:
%opTag:" throws" ? "throw " value : ""%

(The bug appears to be particular to tagged value conditional expressions only)

This form works:
%opTag:"throws"=="" ? "" : " throw " value%


As regards the use of the != operator in these macros.

Quote
// 2. %classTag:"atag" != "" ? "yes" : "no"%


This is not expected to work. Only the == operator is available. The reason you'll see blank output is because the macro was not recognised as valid. Admittedly this is an odd limitation and will probably be addressed in a future version. The limitation is easily overcome however, using one of the following:

%tag:"name"=="" ? "value_empty" : "value_non_empty"%

or (as you discovered);

%if tag:"name"!=""%
value_non_empty
%endIf%

I hope this explains. Thanks again for your feedback.

Regards,
Ben

gmpff

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Exception specification code generation
« Reply #2 on: December 05, 2003, 03:13:44 am »
Hi Ben,

Thanks for the response and for fixing the bugs. I'll use == in future.

Thanks for a great product !

Regards,

  g.