Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

unitNode Class Reference

Holds the AST of one translation unit. More...

#include <ast.h>

Inheritance diagram for unitNode::

Node List of all members.

Public Methods

 unitNode (string input_file, string output_file, const Coord coord=Coord::Unknown)
 Create a new translation unit from a source file. More...

virtual ~unitNode ()
 Destroy a unitNode. More...

void parse (str_list *cpp_flags)
 Parse the input file. More...

void fixup ()
 Run fixup passes. More...

void merge_in (def_list *defs)
 Merge in external definitions. More...

void enter_scope ()
 Enter a new scope. More...

void exit_scope ()
 Exit scope. More...

virtual void dataflow (FlowVal *v, FlowProblem &fp)
 Run the dataflow analyzer. More...

virtual Nodeclone () const
 Clone the input node. More...

virtual void output (output_context &ct, Node *par)
 Generate C code. More...

Accessors
Methods to get and set fields in the class.

def_listdefs ()
const def_listdefs () const
int symbol_level () const
Identifiers_tabletypes () const
Tags_tabletags () const
string & input_file ()
string & output_file ()
int errors () const
void inc_errors ()
int warnings () const
void inc_warnings ()
decl_listundef_funcs ()
suespec_listsuespecs ()
AST Traversal
Methods to uniformly traverse the AST. See the documentation in the Node class.

virtual void visit (Visitor *the_visitor)
 Dispatch a Visitor. More...

virtual void walk (Walker &the_walker)
 Dispatch a Walker. More...

virtual Nodechange (Changer &the_changer, bool redispatch=false)
 Dispatch a Changer. More...


Private Methods

FILE * _open_input_file (str_list *cpp_flags)
 Open the input file. More...


Private Attributes

TREE def_list _defs
 The external definitions. More...

int _symbol_level
 Depth of the scope. More...

Identifiers_table_types
 Table of type names. More...

Tags_table_tags
 Table of struct/union tags. More...

string _input_file
 Source file name. More...

string _output_file
 The output file name. More...

int _errors
 The number of errors. More...

int _warnings
 The number of warnings. More...

TREE decl_list _undef_funcs
 Undeclared functions. More...

TREE suespec_list _suespecs
 struct/enum/union contents. More...


Detailed Description

Holds the AST of one translation unit.

A translation unit corresponds to a single input source file (with all header files included). To parse a source file in, create a unitNode and then call the parse() method. However, this is typically done by the main driver, which also handles the flags provided on the command line.

All instances of unitNode created by the main driver are stored in a global list in the CBZ class.

The NodeType is Unit.

In addition to containing the AST for the code, unitNode contains auxillary information gathered during the parsing. This includes:


Constructor & Destructor Documentation

unitNode::unitNode string    input_file,
string    output_file,
const Coord    coord = Coord::Unknown
 

Create a new translation unit from a source file.

Instantiate a new unitNode with the given input and output source file names. This is typically done automatically by the front-end driver.

Parameters:
input_file  the name of the input source file.
output_file  the name of the output source file.
coord  the location of the construct in the source file.

unitNode::~unitNode   [virtual]
 

Destroy a unitNode.

Warning:
Do not use the destructors to delete AST nodes. Instead, rely on the node garbage collector.


Member Function Documentation

FILE * unitNode::_open_input_file str_list   cpp_flags [private]
 

Open the input file.

Node * unitNode::change Changer   the_changer,
bool    redispatch = false
[virtual]
 

Dispatch a Changer.

This abstract method works much the walker, but allows the tree to be changed.

Parameters:
the_changer  the specific Changer object to use.
redispatch  pass true to revisit parts of the tree that have changed.

Reimplemented from Node.

virtual Node* unitNode::clone   const [inline, virtual]
 

Clone the input node.

This is not a "deep" clone, so be careful. For a deep clone, use the clone_changer class.

Returns:
a shallow copy of the node (no subtrees are copied).

Reimplemented from Node.

void unitNode::dataflow FlowVal   v,
FlowProblem   fp
[virtual]
 

Run the dataflow analyzer.

Each subclass overrides this method to define it's semantics for dataflow analysis. It alters the input flow value to reflect the effect of the node within the given flow problem, calling dataflow() on it's subtrees as necessary. See the dataflow analysis documentation for more information.

Parameters:
v  the flow value to pass through the node.
fp  the flow problem (specifying the transfer functions).

Reimplemented from Node.

const def_list& unitNode::defs   const [inline]
 

def_list& unitNode::defs   [inline]
 

void unitNode::enter_scope  
 

Enter a new scope.

int unitNode::errors   const [inline]
 

void unitNode::exit_scope  
 

Exit scope.

void unitNode::fixup  
 

Run fixup passes.

Run the various fix-up passes, just as we would after parsing.

void unitNode::inc_errors   [inline]
 

void unitNode::inc_warnings   [inline]
 

string& unitNode::input_file   [inline]
 

void unitNode::merge_in def_list   defs [inline]
 

Merge in external definitions.

void unitNode::output output_context   ct,
Node   parent
[virtual]
 

Generate C code.

Each subclass overrides this method to define how to produce the output C code. To use this method, pass an output_context and a null parent.

Parameters:
ct  the output context which describes the formatting.
par  the parent node (or null, if at the top of a subtree).

Reimplemented from Node.

string& unitNode::output_file   [inline]
 

void unitNode::parse str_list   cpp_flags
 

Parse the input file.

Run the parser on the input file using the given preprocessor flags. The resulting AST is stored in the various unitNode fields ( _defs, _types, etc.).

Parameters:
cpp_flags  a list of strings, each one is a preprocessor flag.

suespec_list& unitNode::suespecs   [inline]
 

int unitNode::symbol_level   const [inline]
 

Tags_table* unitNode::tags   const [inline]
 

Identifiers_table* unitNode::types   const [inline]
 

decl_list& unitNode::undef_funcs   [inline]
 

void unitNode::visit Visitor   the_visitor [virtual]
 

Dispatch a Visitor.

This abstract method is the entry point for the visitor design pattern. Each node subclass defines a visit() method that calls the appropriate at_ method in the visitor. For more information see the Visitor documentation.

Parameters:
the_visitor  the specific Visitor object to use.

Reimplemented from Node.

void unitNode::walk Walker   the_walker [virtual]
 

Dispatch a Walker.

This abstract method works much like the visitor, but instead walks the entire underlying subtree calling the appropriate at_ method at each node. For more information see the Walker documentation.

Parameters:
the_walker  the specific Walker object to use.

Reimplemented from Node.

int unitNode::warnings   const [inline]
 


Member Data Documentation

TREE def_list unitNode::_defs [private]
 

The external definitions.

The list of external definitions (top level) parsed in from the source. This is the top of the AST.

int unitNode::_errors [private]
 

The number of errors.

The number of errors encountered during parsing.

string unitNode::_input_file [private]
 

Source file name.

The name of the source file from which this AST was parsed.

string unitNode::_output_file [private]
 

The output file name.

The name of the output file to which the resulting code is written (only if the -c-code flag is given).

TREE suespec_list unitNode::_suespecs [private]
 

struct/enum/union contents.

During parsing, we maintain a separate, global list of the contents of struct/enum/union definitions. The reason is that this avoids the problem of which declaration "owns" the content definition. Instead, all uses of the s/u/e type simply refer to one of the elements of this list.

int unitNode::_symbol_level [private]
 

Depth of the scope.

Tags_table* unitNode::_tags [private]
 

Table of struct/union tags.

Identifiers_table* unitNode::_types [private]
 

Table of type names.

TREE decl_list unitNode::_undef_funcs [private]
 

Undeclared functions.

This list will contain a function declaration for any functions not explicitly declared in the source.

int unitNode::_warnings [private]
 

The number of warnings.

The number of warnings encountered during parsing.


The documentation for this class was generated from the following files:
Generated on Thu Jan 10 12:06:35 2002 for C-Breeze by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001