snoot: immed_and_type_for_C_intconst: properly parse "0"
[suif.git] / html / suif1_18.html
blobc8f18642609a9324d3d213d497fa8c11bd75f3d9
1 <HTML>
2 <HEAD>
3 <!-- This HTML file has been created by texi2html 1.54
4 from suif1.texi on 28 April 1999 -->
6 <TITLE>The SUIF Version 1 Library - Block Nodes</TITLE>
7 <link href="suif1_19.html" rel=Next>
8 <link href="suif1_17.html" rel=Previous>
9 <link href="suif1_toc.html" rel=ToC>
11 </HEAD>
12 <BODY>
13 <p>Go to the <A HREF="suif1_1.html">first</A>, <A HREF="suif1_17.html">previous</A>, <A HREF="suif1_19.html">next</A>, <A HREF="suif1_113.html">last</A> section, <A HREF="suif1_toc.html">table of contents</A>.
14 <P><HR><P>
17 <H3><A NAME="SEC18" HREF="suif1_toc.html#TOC18">Block Nodes</A></H3>
18 <P>
19 <A NAME="IDX106"></A>
20 <A NAME="IDX107"></A>
21 <A NAME="IDX108"></A>
23 </P>
24 <P>
25 <A NAME="IDX109"></A>
26 A <CODE>tree_block</CODE> node introduces a new scope. Nested scopes are
27 useful for retaining scope information from source programs and for
28 debugging purposes. They are also very useful for implementing code
29 transformations. For example, name conflicts are easily avoided by
30 introducing new scopes.
32 </P>
33 <P>
34 <A NAME="IDX110"></A>
35 <A NAME="IDX111"></A>
36 <A NAME="IDX112"></A>
37 <A NAME="IDX113"></A>
38 A <CODE>tree_block</CODE> node contains a <CODE>block_symtab</CODE> symbol table and
39 a tree node list for the body. The symbol table is accessed with the
40 <CODE>symtab</CODE> and <CODE>set_symtab</CODE> methods. The <CODE>body</CODE> and
41 <CODE>set_body</CODE> methods are used to get and set the list of tree nodes
42 inside the block.
44 </P>
45 <P>
46 There is a one-to-one correspondence between a <CODE>tree_block</CODE> and its
47 symbol table, and the hierarchy of symbol tables within a procedure must
48 parallel the hierarchy of <CODE>tree_block</CODE> nodes. When inserting a
49 <CODE>tree_block</CODE> into an AST, the new block's symbol table must be
50 inserted in the appropriate place in the symbol table hierarchy. When a
51 <CODE>tree_block</CODE> is destroyed, the associated symbol table is detached
52 from its parent table and destroyed. However, the converse is not
53 true--when a <CODE>block_symtab</CODE> is deleted, the corresponding
54 <CODE>tree_block</CODE> node is not deleted.
56 </P>
57 <P>
58 The entries in a block's symbol table may not be referenced from outside
59 the block. There are no other restrictions on <CODE>tree_block</CODE> nodes.
60 The bodies may be empty or contain any kinds of tree nodes. Blocks are
61 usually entered from the beginning but that is not required; unlike
62 other AST nodes, branches into the middle of a block are allowed.
64 </P>
65 <P>
66 As an example, the following code creates a new <CODE>tree_block</CODE> and
67 its associated symbol table. It then adds the new block to the
68 body of an existing block node:
70 </P>
72 <PRE>
73 block_symtab *new_symtab = new block_symtab("my_symtab");
74 cur_block-&#62;symtab()-&#62;add_child(new_symtab);
75 tree_node_list *tl = new tree_node_list;
76 tree_block *new_block = new tree_block(tl, new_symtab);
77 cur_block-&#62;body()-&#62;append(new_block);
78 </PRE>
80 <P><HR><P>
81 <p>Go to the <A HREF="suif1_1.html">first</A>, <A HREF="suif1_17.html">previous</A>, <A HREF="suif1_19.html">next</A>, <A HREF="suif1_113.html">last</A> section, <A HREF="suif1_toc.html">table of contents</A>.
82 </BODY>
83 </HTML>