473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

C++ code generator

I am considering writing a code generator which takes interfaces
specifications in the following style:

interface IStack<class Elem_T>
invariant: // number of items pushed >= number of items popped
{
Bool IsEmpty();
precondition: result = number of items pushed == number of items popped
void Push(const Elem_T& x);
void Pop();
precondition: IsEmpty() == false
postcondition: // result = most recent pushed item which hasn't been
popped
const Elem_T& Top();
precondition: IsEmpty() == false
}

The code generator would output a C++ class to represent the interface (
using the BIL, see http://www.codeproject.com/cpp/retrofitpolymorphism.asp )
It would also output a contract class which verifies the preconditions /
postconditions / etc. It would also ouput a stub implementation class. That
is a class which implements the interface but does nothing.

This is actually only scratching the surface of what I would do with it: I
would also support pseudo-code class definitions, which implement Heron
style classes.

The feature list for the classes would be considerably more far reaching:
- aspect oriented programming support (
http://www.heron-language.com/aspect...ogramming.html )
- self / inherited keywords
- delegation
- implicit result variables
- properties
- _ctor and _dtor named constructors and destructors

I am trying to gauge the level of interest in such a tool. Thanks in
advance, and feel free to share your two cents.

--
Christopher Diggins
http://www.cdiggins.com
http://www.heron-language.com
Jul 22 '05 #1
3 2874
christopher diggins wrote:
I am considering writing a code generator which takes interfaces
specifications in the following style:

interface IStack<class Elem_T>
invariant: // number of items pushed >= number of items popped
{
Bool IsEmpty();
precondition: result = number of items pushed == number of items popped void Push(const Elem_T& x);
void Pop();
precondition: IsEmpty() == false
postcondition: // result = most recent pushed item which hasn't been popped
const Elem_T& Top();
precondition: IsEmpty() == false
}


Code generation tools are good things in most cases. However,
there's something, um, skewed about requiring psuedo code as
input to such a tool. The level of effort required to create
the input you've typed here is too large compared to the result.

Instead, how about a menu driven something-or-other that lets
you select certain items from a list, then blasts the appropriate
text into a file for you. Put a nice GUI on there and you've got
something.

Of course, with the example you've got, what you've got is a
fairly straightforward template class. So, the question that
arises fairly quickly is, what's wrong with just providing that
fairly straightforward template class? Template classes are
pretty cool.
Socks

Jul 22 '05 #2
"Puppet_Sock" <pu*********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
christopher diggins wrote:
I am considering writing a code generator which takes interfaces
specifications in the following style:

interface IStack<class Elem_T>
invariant: // number of items pushed >= number of items popped
{
Bool IsEmpty();
precondition: result = number of items pushed == number of items popped
void Push(const Elem_T& x);
void Pop();
precondition: IsEmpty() == false
postcondition: // result = most recent pushed item which hasn't

been
popped
const Elem_T& Top();
precondition: IsEmpty() == false
}


Code generation tools are good things in most cases. However,
there's something, um, skewed about requiring psuedo code as
input to such a tool. The level of effort required to create
the input you've typed here is too large compared to the result.


I don't see how I could reduce it down further.

Take a look at the code needed to replicate the interface:

template<typename Elem_T>
BOOST_IDL_BEGIN1(IStack)
BOOST_IDL_FN1(Push, void, (const Elem_T&, x))
BOOST_IDL_FN0(Pop, const Elem_T&)
BOOST_IDL_FN0(Peek, const Elem_T&)
BOOST_IDL_FN0(IsEmpty, Bool)
BOOST_IDL_END1(IStack)

There is the contract:

template<typename Stack_T, typename Elem_T>
struct Stack_contract : public Stack_T
{
// type identities
typedef Stack_T inherited;
// constructor
Stack_contract() { }
template<typename Arg_T> Stack_contract(const Arg_T& x) : inherited(X)
{ };
// contract verification
const Elem_T& Pop() { PRE(!IsEmpty()); return inherited::Pop(); }
const Elem_T& Peek() { PRE(!IsEmpty()); return inherited::Peek(); }
};

The wrapper :

template<typename Stack_T, typename Elem_T>
struct Stack_wrapper
{
#ifdef APPLY_CONTRACTS
typedef Stack_ext<Stack_contract<Stack_T, Elem_T>, Elem_T> type;
#else
typedef Stack_ext<Stack_T, Elem_T> type;
#endif
};

And a stub:

template<typename Elem_T>
struct Stack_strub
{
Stack_stub() { }
// IStack implementation
const Elem_T& Peek() { }
const Elem_T& Pop() { }
void Push(const Elem_T& x) { }
Bool IsEmpty() { }
};
Instead, how about a menu driven something-or-other that lets
you select certain items from a list, then blasts the appropriate
text into a file for you. Put a nice GUI on there and you've got
something.
This is an interesting idea.
Of course, with the example you've got, what you've got is a
fairly straightforward template class. So, the question that
arises fairly quickly is, what's wrong with just providing that
fairly straightforward template class? Template classes are
pretty cool.
All of this is not as easy to implement as it might seem on first glance
check out http://www.ootl.org/src/collections.hpp
Socks


Thanks for your feedback
CD
Jul 22 '05 #3
what you have to ask yourself is why create yet another templating
language.

C++ has one built in already.
There is already a standard IDL, for doing just this.
There is XML/UML formats for this also ->
http://www.yy.ics.keio.ac.jp/~suzuki/project/uxf/
Tools like SWIG do this already for other languages to C/C++ mappings.
There are tonnes of template based parsers and frameworks, some like
EMF that are already integrated into an IDE ( Eclipse )

second you have to answer, is your idea and implementation so much
better than everyone elses that people are going to drop what they are
doing, learn your NEW language/syntax/api or whatever and adopt it
because it saves them so much time and effort ( including the learning
curve ).
First pass at your suggestion my answer to the second question is a NO.

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
2
by: Dado | last post by:
Do you know where to find some peace of software/code which I can implemented in my desktop java application which will protect it from illegal using? I imagine something like: buyer can install...
0
by: Chris McKeever | last post by:
I am trying to modify the Mailman Python code to stop mapping MIME-types and use the extension of the attachment instead. I am pretty much clueless as to what I need to do here, but I think I have...
8
by: Thomas Stegen | last post by:
I have written a code generator. To be more specific it is a code generator generator. As in a generator that generates code generators. If you run the generator on its own source code you get a...
41
by: Petr Jakes | last post by:
Hello, I am trying to study/understand OOP principles using Python. I have found following code http://tinyurl.com/a4zkn about FSM (finite state machine) on this list, which looks quite useful for...
3
by: joshblair | last post by:
Hello, Has anyone ever seen or created such a code generator? I'm looking for a sample of a code generator that will generate code (preferably one that uses C# and the XMLTextWriter) to create...
29
by: Ancient_Hacker | last post by:
A while back I had to recompile some old code, originally written by a really good programmer, but one prone to use every trick in the book, and then some. There was a statement, something like...
4
by: VMI | last post by:
In the next few weeks, we'll be discussing what standards will be used for our web development, and one of the suggestions was to use a code generator (in our case, the first version of LLBLGen)....
3
by: Sander Tekelenburg | last post by:
Situation: I store news articles as individual PHP files. Each file contains HTML and now and then some embedded PHP snippets. Serving those news articles on the Web works fine, through...
5
by: james | last post by:
To give an example of what I mean I have already altered the code: def output_random_lesson_of_type(self, type=None): """Output a lesson of a specific type. If no type is passed in then output...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.