Go to the previous, next section.

Creating New Entries

To make it easier to add new entries, the symbol tables provide methods that combine the steps of creating new objects and then entering them in the tables. Some of these methods automatically make sure that the new entries have unique names and that is particularly useful.

New variables can be added to tables anywhere in the symbol table hierarchy. The new_var method creates a new variable with a given name and type and then enters the new variable symbol in the table. The new_unique_var method is similar, but it also checks that the name of the new variable is unique. If not, it appends a number to the specified name until it is unique. With this method, the base name is optional; the default value is `suif_tmp'.

Procedure symbols can be created in global and file symbol tables using the new_proc method. The name of the procedure, its type, and the source language must be specified. There is currently no method to automatically create a new procedure symbol with a unique name.

Because label symbols may only be declared within procedures, the new_label and new_unique_label methods are provided in the block_symtab class. The only parameter of these methods is the name of the label. The name is optional for new_unique_label; its default value is `L'. Just as with variables, unique label names are created by adding a number to the end of the base names.

Within a procedure, new inner scopes may be created to be used with new tree_block nodes. The block_symtab class provides the new_unique_child method to create a new symbol table, give it a unique name, and add it to the list of children. The unique name is created by appending a number to the optional base name. If the base name is not given, it defaults to `block'. This method is not needed at the global level, because the child symbol tables there correspond to procedures which should already have unique names.

Finally, new variable definitions can be added to any symbol table using the define_var method. The parameters are the variable symbol and the alignment for the storage to be defined. It returns a pointer to the new variable definition object, so that you can attach initial data annotations to it.

Go to the previous, next section.