[RFC] type safe trees (aka, reinventing C++ in C)

Chris Lattner sabre@nondot.org
Wed Jun 23 17:29:00 GMT 2004


Nathan Sidwell wrote:
> Ok, this hierarchy is not strictly linear, but that's not the point.
> The point is that one will have routines that want to deal with
> named_decls, and not care whether it's a variable, parameter, function
> or whatever.  With the simple two level scheme we'd have had to make all
> these types sibling classes, whereas we really want to make them a
> hierarchy.

> So, we want a hierarchy and we don't know apriori how many levels there
> will be. Cfront-lite here we come :)

This really isn't too hard to do in even a moderately simple way.  Case in
point, check out the llvmgcc IR used to represent LLVM code (this is an
LLVM IR representation writen in "oo" C):
http://llvm.x10sys.com/cgi-bin/cvsweb.cgi/llvm-gcc/gcc/llvm-representation.h?rev=1.7

While this is not the most beautiful code in the world (accessors
scattered around), it does faithfully represent the following "class
hierarchy" in an efficient and clean way:

llvm_value
  llvm_constant
    llvm_constant_expr
    llvm_constant_aggregate
    llvm_function
    llvm_global
  llvm_argument
  llvm_instruction
  llvm_basicblock

Obviously this is a simple hierarchy, but it should illustrate the point.
This doesn't need layers of macros and preprocessing to implement.

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/



More information about the Gcc mailing list