This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Condition for while and switch statements
- To: dyp at perchine dot com
- Subject: Re: Condition for while and switch statements
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Mon, 23 Oct 2000 07:44:16 -0700
- Cc: gcc at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Organization: CodeSourcery, LLC
- References: <00102314014800.06211@dyp.perchine.com>
>>>>> "Denis" == Denis Perchine <dyp@perchine.com> writes:
Denis> Hello,
Denis> I have quite interesting problem. In c-tree.texi it is
Denis> described that switch and while statement have either
Denis> expression or var declaration as condition. But I always
Denis> get TREE_LIST.
The documentation didn't quite match reality there. I've attached a
fix.
I'm glad to see that so many people are looking at the c-tree.texi
documentation.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2000-10-23 Mark Mitchell <mark@codesourcery.com>
* c-tree.texi: Improve documentation for IF_STMTs and related
conditional statements.
Index: c-tree.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-tree.texi,v
retrieving revision 1.2
diff -c -p -r1.2 c-tree.texi
*** c-tree.texi 2000/09/30 08:04:00 1.2
--- c-tree.texi 2000/10/23 14:41:50
*************** always have pointer type.
*** 1574,1583 ****
@item IF_STMT
Used to represent an @code{if} statement. The @code{IF_COND} is the
! expression or statement used as the condition. If the condition is a
! statement, it will always be a @code{DECL_STMT}; the variable will then
! be used as the condition.
The @code{THEN_CLAUSE} represents the statement given by the @code{then}
condition, while the @code{ELSE_CLAUSE} represents the statement given
by the @code{else} condition.
--- 1574,1594 ----
@item IF_STMT
Used to represent an @code{if} statement. The @code{IF_COND} is the
! expression.
+ If the condition is a @code{TREE_LIST}, then the @code{TREE_PURPOSE} is
+ a statement (usually a @code{DECL_STMT}). Each time the coondition is
+ evaluated, the statement should be executed. Then, the
+ @code{TREE_VALUE} should be used as the conditional expression itself.
+ This representation is used to handle C++ code like this:
+
+ @example
+ if (int i = 7) ...
+ @end example
+
+ where there is a new local variable (or variables) declared within the
+ condition.
+
The @code{THEN_CLAUSE} represents the statement given by the @code{then}
condition, while the @code{ELSE_CLAUSE} represents the statement given
by the @code{else} condition.
*************** cleanups must be executed in the reverse
*** 1643,1651 ****
@item SWITCH_STMT
Used to represent a @code{switch} statement. The @code{SWITCH_COND} is
! the expression on which the switch is occurring. (It may be either a
! statement, or an expression.) The @code{SWITCH_BODY} is the body of the
! switch statement.
@item TRY_BLOCK
Used to represent a @code{try} block. The body of the try block is
--- 1654,1663 ----
@item SWITCH_STMT
Used to represent a @code{switch} statement. The @code{SWITCH_COND} is
! the expression on which the switch is occurring. See the documentation
! for an @code{IF_STMT} for more information on the representation used
! for the condition. The @code{SWITCH_BODY} is the body of the switch
! statement.
@item TRY_BLOCK
Used to represent a @code{try} block. The body of the try block is
*************** And, if an exception is thrown while the
*** 1665,1673 ****
@item WHILE_STMT
Used to represent a @code{while} loop. The @code{WHILE_COND} is the
! termination condition for the loop. This condition may be either a
! statement or an expression. If the condition is a statement, it will
! always be a @code{DECL_STMT}; see @code{IF_STMT} for more information.
The @code{WHILE_BODY} is the body of the loop.
--- 1677,1685 ----
@item WHILE_STMT
Used to represent a @code{while} loop. The @code{WHILE_COND} is the
! termination condition for the loop. See the documentation for an
! @code{IF_STMT} for more information on the representation used for the
! condition.
The @code{WHILE_BODY} is the body of the loop.