473,657 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2887
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_Soc k" <pu*********@ho tmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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<typena me Elem_T>
BOOST_IDL_BEGIN 1(IStack)
BOOST_IDL_FN1(P ush, void, (const Elem_T&, x))
BOOST_IDL_FN0(P op, const Elem_T&)
BOOST_IDL_FN0(P eek, const Elem_T&)
BOOST_IDL_FN0(I sEmpty, Bool)
BOOST_IDL_END1( IStack)

There is the contract:

template<typena me Stack_T, typename Elem_T>
struct Stack_contract : public Stack_T
{
// type identities
typedef Stack_T inherited;
// constructor
Stack_contract( ) { }
template<typena me 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<typena me 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<typena me 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
5254
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
2
8679
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 my software by using request code which will generate on my web. It must be unique for that machine, I suppose. - it doesn't matter if generator can be cracked. I will proud to someone want crack my piece of software.:)) - I think that I was...
0
2410
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 narrowed it down to the Scrubber.py file.. If this seems like a quick step me through, I would be very appreciative, could get you something on your Amazon wish-list (that is me on my knees begging).. From just my basic understanding, it...
8
2381
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 code generator generator code generator. If you run it on some other non-generator code you get a code generator generator generator. Watch your bracketisation in all that. The idea is to generate code which generate code which looks exactly like...
41
2512
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 my purposes. As this code was posted long time ago (November 1998) I would like to ask if the principles used in this code are still valid in the "modern" Python and if/how it can be improved (revrited) using futures of current version of...
3
2063
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 an XML document structure based on an XML file as input. I have to build some classes that allow me to generate some very complex/large/nasty XML documents for use in B2B exchange of data (like
29
2555
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 this: Result = ( Mode == 2 ? TwoWayFunc : FourWayFunc ) ( Param1, Param2, Param3 );
4
1430
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). Personally, I don't like code generators. I inherited two web applications that use LLBLGen, and they are just impossible to debug. It generates so many classes and so much code that isn't actually used. In my case, I'm maintaining web app with...
3
1788
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 include(). But I want to also serve them through RSS, and found that in that case the PHP source code is served -- it's not being evaluated. So it seems obvious that I need to first evaluate those PHP snippets, store the result in a variable, and use...
5
1626
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 any type.""" output_lessons = self.lesson_data if type: filtered_lessons = filter(lambda x: x == type, self.lesson_data) if filtered_lessons:
0
8394
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.