C-Breeze
C Compiler Infrastructure

[ Project home page]

NodeInfo Class Reference

Helper functions that help saving AST nodes and other information to file, and read back from file. More...

#include <nodeinfo.h>

List of all members.

PRIVATE_MISC

Misc methods.

Coord getCoord (string s, unitNode **unit)
typeNodegetType (unitNode *unit, string s)
static string type_name (typeNode *t)
static typeNodedef_type (typeNode *ty)

Public Member Functions

Constructors and destructors.
 NodeInfo (string filename, bool readmode, bool verbose)
 Constructor: Create an instance of this class.
 ~NodeInfo ()
 Destructor: Destroy an instance of this class.
General query and read-mode functions.
bool read_mode (void)
 Query if it is read mode.
string index (int i)
 Obtain the string at a line.
NodeindexNode (int i)
 Obtain the AST node at a line.
int nodeIndex (Node *node)
 Obtain the unique line number for an AST node.
int nStrings ()
 Obtain number of lines in file.
Write-mode functions.
For functions that take a container parameter, the node to be written is either a statement or expression. The container should be the line number for an AST node already written, such that the latter, such as a method node, `contains' the first node. That is, in the AST, the first node should be an decestor of the second. Specifying this parameter enables the information to be written to the file, so that later when the file is read, the node can be located faster.

int current_line (void)
 The current line number.
void writeType (typeNode *t)
 Write node for a type.
void writeProc (procNode *proc)
 Write node for a procedure.
void writeStmt (stmtNode *s, int container=-1)
 Write node for a statement.
void writeCall (callNode *c, int container=-1)
 Write node for a call.
void writeExpr (exprNode *expr, int container=-1)
 Write node for a expression.
void writeDecl (declNode *d, int container=-1)
 Write node for a declaration.
void writeString (string s)
 Write a string constructed by user.

Static Public Member Functions

static arrayNodecanonical (arrayNode *array)
 Get the canonical array for a given array.

Private Member Functions

PRIVATE_READ
Methods for read-mode

NodegetNode (string s)
typeNodereadType (string s)
procNodereadProc (string s)
typeNodereadsuef (string s)
callNodereadCall (string s)
NodereadExprOrStmt (string s, NodeType typ)
declNodereadDecl (string s)
bool match_args (string args, decl_list formals)

Private Attributes

FILE * _file
bool _read_mode
bool _verbose
map< int, string > strings
map< int, Node * > index2node
map< Node *, int > node2index
int _line

Static Private Attributes

static list< arrayNode * > _canonical1
static map< typeNode *, arrayNode * > _canonical2

Friends

class NodeLocator
 Locate an AST node.


Detailed Description

Helper functions that help saving AST nodes and other information to file, and read back from file.

This class helps to save program information, including AST nodes, to file, and read back from file. The file format is text and is line-sensitive, with one piece of data (such as information on one AST node) per line. For example:

     ... (16 preceding lines)
     Call:super(0) container=16 @sov/java/lang/System.java:58:4
     Constructor:Object() @sov/java/lang/Object.java:24:7
     Callgraph:17:18
In the example, 16 preceding lines are omitted. Line 17 and 18 refers to a call node and a constructor node, respectively. Line 19 is meant to say that the call node at line 17 has callee represented by line 18.

The class defines some functions that write the AST nodes. Each AST node will be written as a line at most once. User decides what node to write, and can supply more strings to write (such as line 19 in the example which represents an AST edge), but such strings have to be generated and formatted before submit for writing. In read mode, there are functions to query for the strings at specific lines.

Definition at line 82 of file nodeinfo.h.


Constructor & Destructor Documentation

NodeInfo::NodeInfo string  filename,
bool  readmode,
bool  verbose
 

Constructor: Create an instance of this class.

Parameters:
filename the file to read or write.
readmode true if the file is to be read, else data is to be written.
verbose verbose mode.
If read mode is specified, the file's content is read. If write mode is specified, a file is created, overwriting if it already exists.

NodeInfo::~NodeInfo  ) 
 

Destructor: Destroy an instance of this class.


Member Function Documentation

static arrayNode* NodeInfo::canonical arrayNode array  )  [static]
 

Get the canonical array for a given array.

Two arrays have same canonical array if they have the same component type

Referenced by nodeIndex().

int NodeInfo::current_line void   )  [inline]
 

The current line number.

Useful only in write mode. In write mode, one line of string is written to the file at a time. The function returns the last written string's line number. The first line written is line 1.

Definition at line 171 of file nodeinfo.h.

References _line.

static typeNode* NodeInfo::def_type typeNode ty  )  [static, private]
 

Coord NodeInfo::getCoord string  s,
unitNode **  unit
[private]
 

Node* NodeInfo::getNode string  s  )  [private]
 

typeNode* NodeInfo::getType unitNode unit,
string  s
[private]
 

string NodeInfo::index int  i  )  [inline]
 

Obtain the string at a line.

Parameters:
i the line number of the string to obtain.

Definition at line 130 of file nodeinfo.h.

References strings.

Node* NodeInfo::indexNode int  i  )  [inline]
 

Obtain the AST node at a line.

Parameters:
i the line number of the node to obtain.
Returns:
the node if line i is an AST node, else return NULL.

Definition at line 135 of file nodeinfo.h.

References index2node.

bool NodeInfo::match_args string  args,
decl_list  formals
[private]
 

int NodeInfo::nodeIndex Node node  )  [inline]
 

Obtain the unique line number for an AST node.

Parameters:
node the AST node
Returns:
the line number for the node, 0 if NULL or the node was never written or not read from file.

Definition at line 141 of file nodeinfo.h.

References Array, canonical(), node2index, and Node::typ().

int NodeInfo::nStrings  )  [inline]
 

Obtain number of lines in file.

Definition at line 153 of file nodeinfo.h.

References strings.

bool NodeInfo::read_mode void   )  [inline]
 

Query if it is read mode.

Definition at line 126 of file nodeinfo.h.

References _read_mode.

callNode* NodeInfo::readCall string  s  )  [private]
 

declNode* NodeInfo::readDecl string  s  )  [private]
 

Node* NodeInfo::readExprOrStmt string  s,
NodeType  typ
[private]
 

procNode* NodeInfo::readProc string  s  )  [private]
 

typeNode* NodeInfo::readsuef string  s  )  [private]
 

typeNode* NodeInfo::readType string  s  )  [private]
 

static string NodeInfo::type_name typeNode t  )  [static, private]
 

void NodeInfo::writeCall callNode c,
int  container = -1
 

Write node for a call.

Parameters:
c the call node to write.
container the container for the call.

void NodeInfo::writeDecl declNode d,
int  container = -1
 

Write node for a declaration.

Parameters:
d the declaration node to write.
container the container for the declaration.

void NodeInfo::writeExpr exprNode expr,
int  container = -1
 

Write node for a expression.

Parameters:
expr the expression node to write.
container the container for the expression.
If the expression is a call or new-expression, writeCall or writeNew should be used instead, respectively.

void NodeInfo::writeProc procNode proc  ) 
 

Write node for a procedure.

void NodeInfo::writeStmt stmtNode s,
int  container = -1
 

Write node for a statement.

Parameters:
s the statement node to write.
container the container for the statement.

void NodeInfo::writeString string  s  ) 
 

Write a string constructed by user.

The string should be contain a new line character '
' followed and terminated by the null character.

void NodeInfo::writeType typeNode t  ) 
 

Write node for a type.


Friends And Related Function Documentation

friend class NodeLocator [friend]
 

Locate an AST node.

Definition at line 255 of file nodeinfo.h.


Member Data Documentation

list<arrayNode*> NodeInfo::_canonical1 [static, private]
 

Definition at line 97 of file nodeinfo.h.

map<typeNode*,arrayNode*> NodeInfo::_canonical2 [static, private]
 

Definition at line 100 of file nodeinfo.h.

FILE* NodeInfo::_file [private]
 

Definition at line 84 of file nodeinfo.h.

int NodeInfo::_line [private]
 

Definition at line 92 of file nodeinfo.h.

Referenced by current_line().

bool NodeInfo::_read_mode [private]
 

Definition at line 85 of file nodeinfo.h.

Referenced by read_mode().

bool NodeInfo::_verbose [private]
 

Definition at line 86 of file nodeinfo.h.

map<int,Node*> NodeInfo::index2node [private]
 

Definition at line 90 of file nodeinfo.h.

Referenced by indexNode().

map<Node*,int> NodeInfo::node2index [private]
 

Definition at line 91 of file nodeinfo.h.

Referenced by nodeIndex().

map<int,string> NodeInfo::strings [private]
 

Definition at line 89 of file nodeinfo.h.

Referenced by index(), and nStrings().


The documentation for this class was generated from the following file:

Generated on February 1, 2006
Back to the C-Breeze home page