Re: Object Oriented Compiler Design Problem

"Quinn Tyler Jackson" <qjackson@wave.home.com>
13 Sep 1998 22:23:18 -0400

          From comp.compilers

Related articles
Object Oriented Compiler Design Problem mayurnaik@my-dejanews.com (1998-09-05)
Re: Object Oriented Compiler Design Problem qjackson@wave.home.com (Quinn Tyler Jackson) (1998-09-13)
Re: Object Oriented Compiler Design Problem qjackson@wave.home.com (Quinn Tyler Jackson) (1998-09-13)
Re: Object Oriented Compiler Design Problem dwight@pentasoft.com (1998-09-13)
Object Oriented Compiler Design Problem dboucher@locus.ca (Dominique Boucher) (1998-09-13)
Re: Object Oriented Compiler Design Problem brueni@ipass.net (Dennis Brueni) (1998-09-13)
Re: Object Oriented Compiler Design Problem mikee@cetasoft.cog (1998-09-13)
Re: Object Oriented Compiler Design Problem jucie@uol.com.br (Juciê Dias Andrade) (1998-09-13)
[1 later articles]
| List of all articles for this month |
From: "Quinn Tyler Jackson" <qjackson@wave.home.com>
Newsgroups: comp.compilers
Date: 13 Sep 1998 22:23:18 -0400
Organization: Compilers Central
References: 98-09-019
Keywords: OOP, design

>The function symbol* add(symbol*, symbol*) cannot be made a virtual function
>of class symbol, since it is a friend function. But, the moment it is a
>friend function, it does not know whether the symbols to be added are
>Constants or Variables
>
>I want a suitable Object Oriented Solution to this problem. I want to avoid
>the solution using 'a union with a type field'. Also, would RTTI be a
>suitable solution? Does it not impose a large overhead?


Maybe it's just the way I think, but because I see the const'ness of a
variable as an attribute, rather than as a fully qualified subtype, I
wouldn't have defined two classes "variable" and "constant." I would have
had only one class, variable, with a boolean attribute "m_bConst", and done
something like this:


symbol* add(symbol* a, symbol* b)
{
        symbol* retval = new variable;


        if(a.is_const() && b.is_const())
        {
                retval = new variable;


                retval->set_value(a->get_value()+b->get_value());
        }
        else
        {
                // whatever it is we have to do here
        }


        return retval;
}


--
Quinn Tyler Jackson


email: qjackson@wave.home.com
url: http://www.qtj.net/~quinn/
ftp: qtj.net
--


Post a followup to this message

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