Re: Implementing types in a compiler

pertsserver! (Mark K. Gardner)
30 Jan 1997 22:19:55 -0500

          From comp.compilers

Related articles
Implementing types in a compiler (1997-01-29)
Re: Implementing types in a compiler pertsserver! (1997-01-30)
Re: Implementing types in a compiler (John Lilley) (1997-01-30)
| List of all articles for this month |

From: pertsserver! (Mark K. Gardner)
Newsgroups: comp.compilers
Date: 30 Jan 1997 22:19:55 -0500
Organization: University of Illinois at Urbana
References: 97-01-238
Keywords: OOP, types

Paulo Jose Pinto - LEI ( wrote:
: I'm implementing an Object Pascal (Turbo Pascal v7.0 variant) compiler
: in C++ and have implemented the information regarding the types in the
: class Type which uses an union to represent all the kinds of types
: (Pointers, Methods, Constants, etc) and I use the methods to acess the
: information.
: But I DON'T LIKE this design, when I look at the code it always makes
: more sense to me to create an abstract class Type and then use
: ProcedureType, ConstType and other for all kinds of information. After
: all when we have an union in C, that should be implement in C++ as an
: abstract class and all the cases as descendents of that class. But
: this requires some sort of dynamic_cast so that I know which member
: function I can call, after all doesn't make sense to use a member
: function GetParameter (....) in ConstType.

I used the later (abstract/specific) Type design in a compiler I wrote
in C++ for the language Oberon. At the time, there was not RTTI so I
annotated the abstract Type class with a tag which I could switch upon
and then safely cast to the correct specific Type class. This worked
well for what I was doing (trying to quantify the performance impact
of using C++ in a hog-wild object-oriented way). I suspect it is not
used much in practice.

[Details about the comparison between structured and object-oriented
programming styles and implementations can be obtained via my thesis
"A Comparative Study of the Locality Characteristics of an
Object-Oriented Language" found at]

Mark K. Gardner (
University of Illinois at Urbana-Champaign
Real-Time Systems Laboratory

Post a followup to this message

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