Bug Vanquisher

19 October 2007

Major Changes in CPPCodeProvider

Filed under: C++ — Tanveer Badar @ 11:40 AM

So far, if you have noticed CPPCodeProvider did not have a concept of separate declaration/definition for the various objects it supported. Apart from that it was not possible to render UserDefinedType, mainly because I was being lazy all this time.

Of course, if you are wondering what the hell CPPCodeProvider is, here are some links which explain it in much more details: part 1, part 2, part 3, part 4, part 5 and part 6.

One day, I asked myself how to render a udt (user defined type). There are all sorts of issues with a udt. There is an ordering among the members of a type. All enumerations, unions, member types and typedefinitions must be (at least) declared before their first use, otherwise, compiler whines. But they cannot be defined at that point because of the dependencies they themselves have upon each other. In addition, unnamed enumeration and unions must be defined completely at that point because they have no name associated with them and a declaration can not be rendered.

This means rendering has to be done in two phases to be safe. First, all types are declared and then, functions, operators, constructors, destructors are declared if they are not inline functions. After that these declared items are defined out of band only if they are not inline. Member types have a similar requirement, unless they specify that they must be defined inline, their definition is always moved out of class.

Member variables are defined and declared inline unless they are static but not constant and do not have integral type.

A member type that inherits from containing type can never be defined inline, so there is a check to override inline specification for member types if one of their base types coincides with the container.

This coves one major change. The other one is the separation of declarations from definitions. For example, write in CodeObject is overloaded and the two declarations are:

void write( std::wostream& os , unsigned long tabs ) const;
void write( std::wostream& declos , std::wostream& defos , unsigned long decltabs , unsigned long deftabs ) const;

As always, these functions call their respective virtual counterpart overloads writetext. write with two arguments always renders anything inline while the other function separates declaration from definition.

This means, it is now possible to have a header containing all the function declarations and class definitions and have their definitions/implementations in a separate file. However, if a class/function is templated you will not be able to override correct behavior with either function and they will be defined instead of declared. Second overload of writetext will refer to the first one in that case passing only declos/decltabs for correct rendering.

One major feature I still miss is to properly support partial and complete specialization. Even during writetext implementation for udts I faced that challenge of how the user will be able to pass template parameter information to base classes and member variable declarations. Expect to see these issues fixed in a future update as someone does have to wait.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: