Commit c06aa51e by Mark Mitchell Committed by Mark Mitchell

c-tree.texi: Moved here from cp/ir.texi.

	* c-tree.texi: Moved here from cp/ir.texi.  Documented nested
	functions.  Generalize to handle both C and C++.
	* Makefile.in (c-tree.info): New target.
	(info): Add c-tree.info.

	* ir.texi: Move to ../c-tree.texi.

From-SVN: r36592
parent fba54939
2000-09-24 Mark Mitchell <mark@codesourcery.com>
* c-tree.texi: Moved here from cp/ir.texi. Documented nested
functions. Generalize to handle both C and C++.
* Makefile.in (c-tree.info): New target.
(info): Add c-tree.info.
Sun Sep 24 09:15:48 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu> Sun Sep 24 09:15:48 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* expr.c (store_field): If BITSIZE is negative, use size of type. * expr.c (store_field): If BITSIZE is negative, use size of type.
......
...@@ -2082,7 +2082,7 @@ stmp-fixproto: fixhdr.ready fixproto stmp-int-hdrs ...@@ -2082,7 +2082,7 @@ stmp-fixproto: fixhdr.ready fixproto stmp-int-hdrs
# Remake the info files. # Remake the info files.
doc: $(BUILD_INFO) gccbug doc: $(BUILD_INFO) gccbug
info: cpp.info gcc.info lang.info info: cpp.info gcc.info lang.info c-tree.info
cpp.info: $(srcdir)/cpp.texi cpp.info: $(srcdir)/cpp.texi
$(MAKEINFO) $(MAKEINFOFLAGS) -I$(srcdir) -o cpp.info $(srcdir)/cpp.texi $(MAKEINFO) $(MAKEINFOFLAGS) -I$(srcdir) -o cpp.info $(srcdir)/cpp.texi
...@@ -2092,6 +2092,10 @@ gcc.info: $(srcdir)/gcc.texi $(srcdir)/extend.texi $(srcdir)/install.texi \ ...@@ -2092,6 +2092,10 @@ gcc.info: $(srcdir)/gcc.texi $(srcdir)/extend.texi $(srcdir)/install.texi \
$(srcdir)/tm.texi $(srcdir)/gcov.texi $(srcdir)/tm.texi $(srcdir)/gcov.texi
$(MAKEINFO) $(MAKEINFOFLAGS) -I$(srcdir) -o gcc.info $(srcdir)/gcc.texi $(MAKEINFO) $(MAKEINFOFLAGS) -I$(srcdir) -o gcc.info $(srcdir)/gcc.texi
c-tree.info: $(srcdir)/c-tree.texi
$(MAKEINFO) $(MAKEINFOFLAGS) -I$(srcdir) -o c-tree.info \
$(srcdir)/c-tree.texi
dvi: gcc.dvi cpp.dvi lang.dvi dvi: gcc.dvi cpp.dvi lang.dvi
# This works with GNU Make's default rule. # This works with GNU Make's default rule.
......
...@@ -24,12 +24,12 @@ ...@@ -24,12 +24,12 @@
@c --------------------------------------------------------------------- @c ---------------------------------------------------------------------
@setfilename ir.info @setfilename ir.info
@settitle G++ Internal Representation @settitle C/C++ Internal Representation
@setchapternewpage on @setchapternewpage on
@ifinfo @ifinfo
This manual documents the internal representation used by G++ to represent This manual documents the internal representation used by GCC to represent
C++ source programs. C and C++ source programs.
Copyright (c) 1999, 2000 Free Software Foundation, Inc. Copyright (c) 1999, 2000 Free Software Foundation, Inc.
@end ifinfo @end ifinfo
...@@ -39,7 +39,7 @@ Copyright (c) 1999, 2000 Free Software Foundation, Inc. ...@@ -39,7 +39,7 @@ Copyright (c) 1999, 2000 Free Software Foundation, Inc.
@c --------------------------------------------------------------------- @c ---------------------------------------------------------------------
@titlepage @titlepage
@title G++ Internal Representation @title C/C++ Internal Representation
@author CodeSourcery, LLC <info@@codesourcery.com> @author CodeSourcery, LLC <info@@codesourcery.com>
@page @page
@vskip 0pt plus 1filll @vskip 0pt plus 1filll
...@@ -51,36 +51,43 @@ Copyright @copyright{} 1999, 2000 Free Software Foundation, Inc. ...@@ -51,36 +51,43 @@ Copyright @copyright{} 1999, 2000 Free Software Foundation, Inc.
@c --------------------------------------------------------------------- @c ---------------------------------------------------------------------
@node Top @node Top
@top G++ Internal Representation @top C/C++ Internal Representation
This manual documents the internal representation used by G++ to This manual documents the internal representation used by GCC and C++ to
represent C++ source programs. When presented with a C++ source represent C and C++ source programs. When presented with a C or C++
program, G++ parses the program, performs semantic analysis (including source program, GCC parses the program, performs semantic analysis
the generation of error messages), and then produces the internal (including the generation of error messages), and then produces the
representation described here. This representation contains a complete internal representation described here. This representation contains a
representation for the entire translation unit provided as input to the complete representation for the entire translation unit provided as
G++ front-end. This representation is then typically processed by a input to the front-end. This representation is then typically processed
code-generator in order to produce machine code, but could also be used by a code-generator in order to produce machine code, but could also be
in the creation of source browsers, intelligent editors, automatic used in the creation of source browsers, intelligent editors, automatic
documentation generators, interpreters, and any other programs needing documentation generators, interpreters, and any other programs needing
the ability to process C++ code. the ability to process C or C++ code.
This manual explains the internal representation. In particular, this This manual explains the internal representation. In particular, this
manual documents the internal representation for C++ source constructs, manual documents the internal representation for C and C++ source
and the macros, functions, and variables that can be used to access constructs, and the macros, functions, and variables that can be used to
these constructs. access these constructs.
If you are developing a ``back-end'', be it is a code-generator or some If you are developing a ``back-end'', be it is a code-generator or some
other tool, that uses this representation, you may occasionally find other tool, that uses this representation, you may occasionally find
that you need to ask questions not easily answered by the functions and that you need to ask questions not easily answered by the functions and
macros available here. If that situation occurs, it is quite likely macros available here. If that situation occurs, it is quite likely
that G++ already supports the functionality you desire, but that the that GCC already supports the functionality you desire, but that the
interface is simply not documented here. In that case, you should ask interface is simply not documented here. In that case, you should ask
the G++ maintainers (via mail to @url{mailto:gcc@@gcc.gnu.org}) about the GCC maintainers (via mail to @url{mailto:gcc@@gcc.gnu.org}) about
documenting the functionality you require. Similarly, if you find documenting the functionality you require. Similarly, if you find
yourself writing functions that do not deal directly with your back-end, yourself writing functions that do not deal directly with your back-end,
but instead might be useful to other people using the G++ front-end, you but instead might be useful to other people using the GCC front-end, you
should submit your patches for inclusion in G++. should submit your patches for inclusion in GCC.
This manual documents the C++ representation which is largely a superset
of the representation used in the C front-end. There is only one
construct used in C that does not appear in the C++ front-end and that
is the GNU ``nested function'' extension. Many of the macros documented
here do not apply in C because the corresponding language constructs do
not appear in C.
@menu @menu
* Deficiencies:: Topics net yet covered in this document. * Deficiencies:: Topics net yet covered in this document.
...@@ -344,9 +351,9 @@ The elements are indexed from zero. ...@@ -344,9 +351,9 @@ The elements are indexed from zero.
@findex TYPE_FIELDS @findex TYPE_FIELDS
@findex TYPE_PTROBV_P @findex TYPE_PTROBV_P
All C++ types have corresponding tree nodes. However, you should not All types have corresponding tree nodes. However, you should not assume
assume that there is exactly one tree node corresponding to each C++ that there is exactly one tree node corresponding to each type. There
type. There are often several. are often several nodes each of which correspond to the same type.
For the most part, different kinds of types have different tree codes. For the most part, different kinds of types have different tree codes.
(For example, pointer types use a @code{POINTER_TYPE} code while arrays (For example, pointer types use a @code{POINTER_TYPE} code while arrays
...@@ -1068,6 +1075,20 @@ the @code{DECL_REAL_CONTEXT} for @code{f} will be the ...@@ -1068,6 +1075,20 @@ the @code{DECL_REAL_CONTEXT} for @code{f} will be the
@code{global_namespace}, but the @code{DECL_CLASS_CONTEXT} will be the @code{global_namespace}, but the @code{DECL_CLASS_CONTEXT} will be the
@code{RECORD_TYPE} for @code{C}. @code{RECORD_TYPE} for @code{C}.
The @code{DECL_REAL_CONTEXT} and @code{DECL_CLASS_CONTEXT} are not
availble in C; instead you should simply use @code{DECL_CONTEXT}. In C,
the @code{DECL_CONTEXT} for a function maybe another function. This
representation indicates that the GNU nested function extension is in
use. For details on the semantics of nested functions, see the GCC
Manual. The nested function can refer to local variables in its
containing function. Such references are not explicitly marked in the
tree sturcture; back-ends must look at the @code{DECL_CONTEXT} for the
referenced @code{VAR_DECL}. If the @code{DECL_CONTEXT} for the
referenced @code{VAR_DECL} is not the same as the function currently
being processed, and neither @code{DECL_EXTERNAL} nor @code{DECL_STATIC}
hold, then the reference is to a local variable in a containing
function, and the back-end must take appropriate action.
@menu @menu
* Function Basics:: Function names, linkage, and so forth. * Function Basics:: Function names, linkage, and so forth.
* Function Bodies:: The statements that make up a function body. * Function Bodies:: The statements that make up a function body.
...@@ -1429,7 +1450,7 @@ statement like: ...@@ -1429,7 +1450,7 @@ statement like:
asm ("mov x, y"); asm ("mov x, y");
@end example @end example
The @code{ASM_STRING} macro will return a @code{STRING_CST} node for The @code{ASM_STRING} macro will return a @code{STRING_CST} node for
@code{"mov x, y"}. If the original statement made use of G++'s @code{"mov x, y"}. If the original statement made use of the
extended-assembly syntax, then @code{ASM_OUTPUTS}, extended-assembly syntax, then @code{ASM_OUTPUTS},
@code{ASM_INPUTS}, and @code{ASM_CLOBBERS} will be the outputs, inputs, @code{ASM_INPUTS}, and @code{ASM_CLOBBERS} will be the outputs, inputs,
and clobbers for the statement, represented as @code{STRING_CST} nodes. and clobbers for the statement, represented as @code{STRING_CST} nodes.
...@@ -1467,7 +1488,7 @@ the same type as the condition expression in the switch statement. ...@@ -1467,7 +1488,7 @@ the same type as the condition expression in the switch statement.
Otherwise, if both @code{CASE_LOW} and @code{CASE_HIGH} are defined, the Otherwise, if both @code{CASE_LOW} and @code{CASE_HIGH} are defined, the
statement is a range of case labels. Such statements originate with the statement is a range of case labels. Such statements originate with the
G++ extension that allows users to write things of the form: extension that allows users to write things of the form:
@example @example
case 2 ... 5: case 2 ... 5:
@end example @end example
...@@ -1508,7 +1529,10 @@ Used to mark the beginning (if @code{CTOR_BEGIN_P} holds) or end (if ...@@ -1508,7 +1529,10 @@ Used to mark the beginning (if @code{CTOR_BEGIN_P} holds) or end (if
Used to represent a local declaration. The @code{DECL_STMT_DECL} macro Used to represent a local declaration. The @code{DECL_STMT_DECL} macro
can be used to obtain the entity declared. This declaration may be a can be used to obtain the entity declared. This declaration may be a
@code{LABEL_DECL}, indicating that the label declared is a local label. @code{LABEL_DECL}, indicating that the label declared is a local label.
(As an extension, GCC allows the declaration of labels with scope.) (As an extension, GCC allows the declaration of labels with scope.) In
C, this declaration may be a @code{FUNCTION_DECL}, indicating the
use of the GCC nested function extension. For more information,
@pxref{Functions}.
@item DO_STMT @item DO_STMT
...@@ -1542,7 +1566,7 @@ expressions. ...@@ -1542,7 +1566,7 @@ expressions.
@item GOTO_STMT @item GOTO_STMT
Used to represent a @code{goto} statement. The @code{GOTO_DESTINATION} Used to represent a @code{goto} statement. The @code{GOTO_DESTINATION}
will usually be a @code{LABEL_DECL}. However, if G++'s ``computed will usually be a @code{LABEL_DECL}. However, if the ``computed
goto'' extension has been used, the @code{GOTO_DESTINATION} will be an goto'' extension has been used, the @code{GOTO_DESTINATION} will be an
arbitrary expression indicating the destination. This expression will arbitrary expression indicating the destination. This expression will
always have pointer type. always have pointer type.
...@@ -1731,11 +1755,11 @@ certain kinds of node being shared, nor should rely on certain kinds of ...@@ -1731,11 +1755,11 @@ certain kinds of node being shared, nor should rely on certain kinds of
nodes being unshared. nodes being unshared.
The following macros can be used with all expression nodes: The following macros can be used with all expression nodes:
@ftable @code @ftable @code
@item TREE_TYPE @item TREE_TYPE
Returns the type of the expression. This value may not be precisely the Returns the type of the expression. This value may not be precisely the
same type that would be given the expression in the original C++ same type that would be given the expression in the original program.
program.
@end ftable @end ftable
In what follows, some nodes that one might expect to always have type In what follows, some nodes that one might expect to always have type
...@@ -1750,6 +1774,7 @@ Below, we list the various kinds of expression nodes. Except where ...@@ -1750,6 +1774,7 @@ Below, we list the various kinds of expression nodes. Except where
noted otherwise, the operands to an expression are accessed using the noted otherwise, the operands to an expression are accessed using the
@code{TREE_OPERAND} macro. For example, to access the first operand to @code{TREE_OPERAND} macro. For example, to access the first operand to
a binary plus expression @code{expr}, use: a binary plus expression @code{expr}, use:
@example @example
TREE_OPERAND (expr, 0) TREE_OPERAND (expr, 0)
@end example @end example
...@@ -1759,6 +1784,7 @@ As this example indicates, the operands are zero-indexed. ...@@ -1759,6 +1784,7 @@ As this example indicates, the operands are zero-indexed.
The table below begins with constants, moves on to unary expressions, The table below begins with constants, moves on to unary expressions,
then proceeds to binary expressions, and concludes with various other then proceeds to binary expressions, and concludes with various other
kinds of expressions: kinds of expressions:
@table @code @table @code
@item INTEGER_CST @item INTEGER_CST
These nodes represent integer constants. Note that the type of these These nodes represent integer constants. Note that the type of these
...@@ -1871,7 +1897,7 @@ These nodes are used to represent the address of an object. (These ...@@ -1871,7 +1897,7 @@ These nodes are used to represent the address of an object. (These
expressions will always have pointer or reference type.) The operand may expressions will always have pointer or reference type.) The operand may
be another expression, or it may be a declaration. be another expression, or it may be a declaration.
As an extension, G++ allows users to take the address of a label. In As an extension, GCC allows users to take the address of a label. In
this case, the operand of the @code{ADDR_EXPR} will be a this case, the operand of the @code{ADDR_EXPR} will be a
@code{LABEL_DECL}. The type of such an expression is @code{void*}. @code{LABEL_DECL}. The type of such an expression is @code{void*}.
...@@ -1939,7 +1965,7 @@ an expression for the code that should be executed to throw the ...@@ -1939,7 +1965,7 @@ an expression for the code that should be executed to throw the
exception. However, there is one implicit action not represented in exception. However, there is one implicit action not represented in
that expression; namely the call to @code{__throw}. This function takes that expression; namely the call to @code{__throw}. This function takes
no arguments. If @code{setjmp}/@code{longjmp} exceptions are used, the no arguments. If @code{setjmp}/@code{longjmp} exceptions are used, the
function @code{__sjthrow} is called instead. The normal G++ back-end function @code{__sjthrow} is called instead. The normal GCC back-end
uses the function @code{emit_throw} to generate this code; you can uses the function @code{emit_throw} to generate this code; you can
examine this function to see what needs to be done. examine this function to see what needs to be done.
...@@ -1972,7 +1998,7 @@ boolean or integral type. ...@@ -1972,7 +1998,7 @@ boolean or integral type.
@itemx TRUTH_XOR_EXPR @itemx TRUTH_XOR_EXPR
These nodes represent logical and, logical or, and logical exclusive or. These nodes represent logical and, logical or, and logical exclusive or.
They are strict; both arguments are always evaluated. There are no They are strict; both arguments are always evaluated. There are no
corresponding operators in C++, but the front-end will sometimes corresponding operators in C or C++, but the front-end will sometimes
generate these expressions anyhow, if it can tell that strictness does generate these expressions anyhow, if it can tell that strictness does
not matter. not matter.
...@@ -2038,26 +2064,30 @@ operand is the object (rather than a pointer to it); the second operand ...@@ -2038,26 +2064,30 @@ operand is the object (rather than a pointer to it); the second operand
is the @code{FIELD_DECL} for the data member. is the @code{FIELD_DECL} for the data member.
@item COMPOUND_EXPR @item COMPOUND_EXPR
These nodes represent C or C++ comma-expressions. The first operand is These nodes represent comma-expressions. The first operand is an
an expression whose value is computed and thrown away prior to the expression whose value is computed and thrown away prior to the
evaluation of the second operand. The value of the entire expression is evaluation of the second operand. The value of the entire expression is
the value of the second operand. the value of the second operand.
@item COND_EXPR @item COND_EXPR
These nodes represent C or C++ @code{?:} expressions. The first operand These nodes represent @code{?:} expressions. The first operand
is of boolean or integral type. If it evaluates to a non-zero value, is of boolean or integral type. If it evaluates to a non-zero value,
the second operand should be evaluated, and returned as the value of the the second operand should be evaluated, and returned as the value of the
expression. Otherwise, the third operand is evaluated, and returned as expression. Otherwise, the third operand is evaluated, and returned as
the value of the expression. As a GNU extension, the middle operand of the value of the expression. As a GNU extension, the middle operand of
the @code{?:} operator may be omitted in the source, like this: the @code{?:} operator may be omitted in the source, like this:
@example @example
x ? : 3 x ? : 3
@end example @end example
@noindent @noindent
which is equivalent to which is equivalent to
@example @example
x ? x : 3 x ? x : 3
@end example @end example
@noindent
assuming that @code{x} is an expression without side-effects. However, assuming that @code{x} is an expression without side-effects. However,
in the case that the first operation causes side effects, the in the case that the first operation causes side effects, the
side-effects occur only once. Consumers of the internal representation side-effects occur only once. Consumers of the internal representation
...@@ -2080,7 +2110,7 @@ arguments and some arguments are not explicitly provided at the call ...@@ -2080,7 +2110,7 @@ arguments and some arguments are not explicitly provided at the call
sites. sites.
@item STMT_EXPR @item STMT_EXPR
These nodes are used to represent G++'s statement-expression extension. These nodes are used to represent GCC's statement-expression extension.
The statement-expression extension allows code like this: The statement-expression extension allows code like this:
@example @example
int f() @{ return (@{ int j; j = 3; j + 7; @}); @} int f() @{ return (@{ int j; j = 3; j + 7; @}); @}
......
2000-09-24 Mark Mitchell <mark@codesourcery.com>
* ir.texi: Move to ../c-tree.texi.
2000-09-20 Jason Merrill <jason@redhat.com> 2000-09-20 Jason Merrill <jason@redhat.com>
* decl2.c (get_guard): Check DECL_FUNCTION_SCOPE_P. * decl2.c (get_guard): Check DECL_FUNCTION_SCOPE_P.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment