some files aren't too happy in a library
[suif.git] / html / suif1_52.html
blob05e4859e58b6c7609e0c2daa51c758f0d1519549
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 - Symbol Features</TITLE>
7 <link href="suif1_53.html" rel=Next>
8 <link href="suif1_51.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_51.html">previous</A>, <A HREF="suif1_53.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 <H2><A NAME="SEC52" HREF="suif1_toc.html#TOC52">Basic Features of Symbols</A></H2>
19 <P>
20 <A NAME="IDX336"></A>
21 <A NAME="IDX337"></A>
22 The <CODE>sym_node</CODE> class defines several fields that are used by all
23 kinds of symbols. The most obvious of these is the symbol name. Each
24 symbol has a name that should be unique within the symbol table where it
25 is defined. The <CODE>name</CODE> and <CODE>set_name</CODE> methods access this
26 field. The names are automatically entered in the lexicon
27 (see section <A HREF="suif1_102.html#SEC102">Lexicon</A>) by <CODE>set_name</CODE>. Because the name of a symbol
28 alone is generally insufficient to uniquely identify it, the symbols are
29 also given ID numbers. See section <A HREF="suif1_50.html#SEC50">Numbering Types and Symbols</A>.
31 </P>
32 <P>
33 <A NAME="IDX338"></A>
34 When a symbol is entered in a symbol table, it automatically records a
35 pointer to that parent table. Similarly, when the symbol is removed
36 from the symbol table, its parent pointer is cleared. The <CODE>parent</CODE>
37 method retrieves this parent pointer.
39 </P>
40 <P>
41 <A NAME="IDX339"></A>
42 <A NAME="IDX340"></A>
43 <A NAME="IDX341"></A>
44 All symbols contain flags to specify various attributes. The
45 <CODE>sym_node</CODE> class provides methods to access these flags. The
46 <CODE>is_userdef</CODE> method tests a flag to see if it is a user-defined
47 symbol (from the source code) or a new symbol introduced by the
48 compiler. The <CODE>set_userdef</CODE> and <CODE>reset_userdef</CODE> methods
49 change the value of this flag.
51 </P>
52 <P>
53 <A NAME="IDX342"></A>
54 Another flag is used to mark symbols that are only declarations of
55 external symbols, rather than actual definitions. This flag is set
56 automatically. The <CODE>is_extern</CODE> method retrieves its value. Label
57 symbols are never <CODE>extern</CODE>. A procedure symbol is <CODE>extern</CODE>
58 unless the procedure body is defined in the input file(s). A global
59 variable symbol is <CODE>extern</CODE> unless it has a separate definition
60 (see section <A HREF="suif1_58.html#SEC58">Variable Definitions</A>); no other variables are <CODE>extern</CODE>.
62 </P>
63 <P>
64 <A NAME="IDX343"></A>
65 <A NAME="IDX344"></A>
66 Since symbols may be treated differently depending on their scopes, the
67 <CODE>sym_node</CODE> class includes methods to determine which kind of symbol
68 table contains a symbol. The <CODE>is_global</CODE> method checks if the
69 parent table is a global or file symbol table. This is really only
70 useful for variable symbols, because procedures are always global and
71 labels are never global. The <CODE>is_private</CODE> method checks if a
72 symbol is global but private to one source file by checking if the
73 parent symbol table is a file symbol table. This is obviously
74 irrelevant for label symbols.
76 </P>
77 <P>
78 <A NAME="IDX345"></A>
79 <A NAME="IDX346"></A>
80 The <CODE>add_to_table</CODE> and <CODE>remove_from_table</CODE> methods are
81 provided for convenience when adding or removing symbols from symbol
82 tables. In the case of variable symbols, the entire hierarchy of
83 sub-variables (see section <A HREF="suif1_57.html#SEC57">Sub-Variables</A>) is added or removed at one time
84 by this method.
86 </P>
87 <P>
88 <A NAME="IDX347"></A>
89 The <CODE>copy</CODE> method makes a copy of a symbol. This is a virtual
90 function so it copies the fields that are specific to each kind of
91 symbol. However, it only copies the symbol itself: copying a procedure
92 symbol will not copy the procedure body and copying a variable symbol
93 will not copy the variable definition. The <CODE>copy</CODE> method does not
94 copy annotations on the symbol, either. Since the copy will have the
95 same name as the original symbol, it should generally be renamed or used
96 in a different symbol table.
98 </P>
99 <P>
100 <A NAME="IDX348"></A>
101 <A NAME="IDX349"></A>
102 Two different methods are available for printing symbols. The
103 <CODE>print</CODE> method just prints the name of the symbol. Label symbols
104 are prefixed by <SAMP>`L:'</SAMP> and procedure symbols by <SAMP>`P:'</SAMP> to
105 distinguish them from variable symbols. The <CODE>print_full</CODE> method is
106 used by the library when listing the contents of symbol tables. It
107 includes all the fields from the <CODE>sym_node</CODE>.
109 </P>
111 <P><HR><P>
112 <p>Go to the <A HREF="suif1_1.html">first</A>, <A HREF="suif1_51.html">previous</A>, <A HREF="suif1_53.html">next</A>, <A HREF="suif1_113.html">last</A> section, <A HREF="suif1_toc.html">table of contents</A>.
113 </BODY>
114 </HTML>