Re: Translating OO program to procedural program

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
11 Oct 2006 23:18:48 -0400

          From comp.compilers

Related articles
Translating OO program to procedural program samhng@gmail.com (=?iso-8859-1?B?bW9vcJk=?=) (2006-10-10)
Re: Translating OO program to procedural program pjb@informatimago.com (Pascal Bourguignon) (2006-10-11)
Re: Translating OO program to procedural program oliverhunt@gmail.com (oliverhunt@gmail.com) (2006-10-11)
Re: Translating OO program to procedural program napi@axiomsol.com (napi) (2006-10-11)
Re: Translating OO program to procedural program mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-10-11)
Re: Translating OO program to procedural program torbenm@app-6.diku.dk (2006-10-11)
Re: Translating OO program to procedural program englere_geo@yahoo.com (Eric) (2006-10-11)
Re: Translating OO program to procedural program DrDiettrich1@aol.com (Hans-Peter Diettrich) (2006-10-11)
Re: Translating OO program to procedural program int2k@gmx.net (Wolfram Fenske) (2006-10-11)
Re: Translating OO program to procedural program tommy.thorn@gmail.com (Tommy Thorn) (2006-10-11)
Re: Translating OO program to procedural program JoachimPimiskern@web.de (Joachim Pimiskern) (2006-10-12)
[1 later articles]
| List of all articles for this month |

From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Newsgroups: comp.compilers
Date: 11 Oct 2006 23:18:48 -0400
Organization: cbb software GmbH
References: 06-10-039
Keywords: OOP, comment

On 10 Oct 2006 23:36:02 -0400, moop™ wrote:


> I am working on a project translates OO programs to procedural
> programs, such as translating C++ to C and the like. I hope this
> effort can be spreaded out to other langs, so I am working on to
> abstract the common issues of doing so. I know there is a pinoneer
> attempt is C Front which produce C++ programs via a C compiler, I want
> to have a look on that, but still cannot find it now, anyone can
> suggest this to me?


Hmm, I presume there is a lot of C++ to C compilers out here...


> My approach is just to rename the methods with the instance name so
> that they can be placed in a single source file and then be compiled
> later by the procedural lang compiler. For instance,
>
> class A{
> B b;
> void method(){
> b.run();
> }
> }
>
> class B{
> void run(){
> ...
> }
> }
>
> If the main rountine is
> void main(){
> A a = new A();
> a.method();
> }
>
> then the program would be translated to
> void a_method(){
> a_b_run();
> }
>
> void a_b_run(){
> ...
> }




Why? To me, obviously, it should be sort of:


void A_method (A * this)
{
      A_method (B * this);
}


void main ()
{
      A * a;
      a = (A *) malloc (...);
      A_default_ctor (a); // omitted if empty
      A_method (a);
}


> But I feel it is really not an adaptable way when dealing with
> declaration inside iterations whose number of iteration is not sure,
> means that we cannot change the names of the reference inside the
> iteration.
> for(...){
> A a = new A();
> }
> So far I am a little bit frustrated on this approach, anyone has
> better idea? Pls share your thoughts, thank you!


You can't resolve dynamic dispatch at compile time, can you? So you have to
pass the hidden parameter explicitly, rather than trying to pack it in some
naming scheme. In general, which is not OO-specific, you seem to be trying
to remove parameter of a procedure by making one new procedure per each
possible parameter value! (:-)) Just consider a recursive procedure.


--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
[There's only a few C++ to C compilers, since it's no easier to do that
than to generate machine code. See the previous message for some
references. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.