This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: TREE representation of class



Dachuan Yu writes:

> Is there any document on how classes are represented as tree nodes?

>From the gcc documentation:

  Using and Porting the GNU Compiler Collection (GCC)
  http://gcc.gnu.org/onlinedocs/gcc-3.0.1/gcc.html

>From there:

  18. Trees: The intermediate representation used by the C and C++ front ends
  http://gcc.gnu.org/onlinedocs/gcc-3.0.1/gcc_18.html#SEC172

> All I learned so far is that it's represented as some "record type".

Yes. You access their content using the macros defined in gcc/tree.h
or gcc/java/java-tree.h.  The tree code (TREE_CODE(x)) tells the kind
of the tree node (see gcc/tree.def and gcc/java/java-tree.def to see
which uses the kinds are intended for.) Based on the kind of a tree
node, you use other macros to access relevant inner fields. Note that
some macros apply to all tree nodes (TREE_CODE for example) some other
depend on the class of the tree node (expr, etc...) and some other
depend on a particular kind. These access macros are checking for
misuses, this is done based on their TREE_CODE, see gcc/tree.c:TREE_CHECK.

Knowing what the macros are doing is important only in certain
debugging situation, for example if you want to get to the char * of
an IDENTIFIER_NODE (node->identifier.id->str, which is equivalent to
IDENTIFIER_POINTER (node).)

> If I want to add new stuff into the representation of a class, say
> another table besides the vtable, can I simply add one more "field"
> to that "record"?

You would be better off modifying the way actual vtables are built and
used when the call are emitted (see build_invokevirtual for the
arithmetic.)

> And what's the common practice when the class representation is
> used? In other words, how do I access the "field" of the "record"
> which represents a class?

You almost always want to add extra fields in tree nodes at the
language (read front-end for the language) level. For tree bearing
declaration of things (DECLs as they're called) you use the
DECL_LANG_SPECIFIC hook. Look at gcc/java/java-tree.h:880. The
lang_decl data structure defines additional fields we need for Java
function decls. These fields should be accessed through macros (for
example the field throw_list is accessed through DECL_FUNCTION_THROWS(DECL).)

If your node uses DECL_LANG_SPECIFIC, it up to you to judge whether
the extension should be always allocated or allocated only when
needed. This is usually done testing DECL_LANG_SPECIFIC (x), see for
instance MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC in gcc/java/java-tree.h

./A


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]