C-Breeze
C Compiler Infrastructure

[ Project home page]
Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

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)
string type_name (typeNode *t)
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

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

list< arrayNode * > _canonical1
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.

Definition at line 51 of file nodeinfo.cc.

References _file, _line, _read_mode, _verbose, getNode(), index2node, node2index, CBZ::PrintLineOffset, and strings.

NodeInfo::~NodeInfo  
 

Destructor: Destroy an instance of this class.

Definition at line 342 of file nodeinfo.cc.


Member Function Documentation

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

Definition at line 1766 of file nodeinfo.cc.

References _canonical1, _canonical2, Array, def_type(), Prim, Node::typ(), and typeNode::type().

Referenced by nodeIndex(), and writeType().

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.

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

Definition at line 1745 of file nodeinfo.cc.

References Array, def, Enum, Func, Prim, Ptr, Struct, sueSpec, Tdef, Node::typ(), and Union.

Referenced by canonical(), and writeType().

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

Definition at line 1472 of file nodeinfo.cc.

References _verbose, CBZ::Files, CBZ::Program, unit_list_p, and Coord::Unknown.

Referenced by readCall(), readDecl(), readExprOrStmt(), readProc(), and readsuef().

Node * NodeInfo::getNode string    s [private]
 

Definition at line 348 of file nodeinfo.cc.

References _read_mode, Array, Binary, Block, Break, Call, Case, Cast, Continue, Decl, Do, Enum, Expr, For, Func, Id, If, Initializer, Label, MAX_Typ, NodeType, Proc, Ptr, readCall(), readDecl(), readExprOrStmt(), readProc(), readType(), Return, Struct, sueSpec, Switch, Tdef, Ternary, TypNames, Unary, Union, CBZ::Warning(), and While.

Referenced by NodeInfo().

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

Definition at line 1515 of file nodeinfo.cc.

References Decl, def, def_list_p, unitNode::defs(), unitNode::input_file(), declNode::name(), Node::typ(), and declNode::type().

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.

Referenced by P::run().

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.

Referenced by P::run().

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

Definition at line 752 of file nodeinfo.cc.

References decl_list_p, and type_name().

Referenced by readProc().

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(), and Node::typ().

Referenced by W::at_call(), W::at_proc(), W::at_type(), and P::run().

int NodeInfo::nStrings   [inline]
 

Obtain number of lines in file.

Definition at line 153 of file nodeinfo.h.

Referenced by P::run().

bool NodeInfo::read_mode void    [inline]
 

Query if it is read mode.

Definition at line 126 of file nodeinfo.h.

callNode * NodeInfo::readCall string    s [private]
 

Definition at line 862 of file nodeinfo.cc.

References Node::coord(), getCoord(), index2node, CBZ::Program, Node::typ(), Unit, and unit_list_p.

Referenced by getNode().

declNode * NodeInfo::readDecl string    s [private]
 

Definition at line 1022 of file nodeinfo.cc.

References Node::coord(), getCoord(), index2node, strings, Node::typ(), and Unit.

Referenced by getNode().

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

Definition at line 979 of file nodeinfo.cc.

References Node::coord(), getCoord(), index2node, Node::typ(), and Unit.

Referenced by getNode().

procNode * NodeInfo::readProc string    s [private]
 

Definition at line 590 of file nodeinfo.cc.

References _read_mode, procNode::decl(), decl_list, def, def_list_p, unitNode::defs(), Func, getCoord(), match_args(), declNode::name(), Proc, CBZ::Program, Node::typ(), declNode::type(), and unit_list_p.

Referenced by getNode().

typeNode * NodeInfo::readsuef string    s [private]
 

Definition at line 519 of file nodeinfo.cc.

References _read_mode, Node::coord(), Decl, def_list_p, unitNode::defs(), Enum, Func, getCoord(), NodeType, CBZ::Program, Struct, sueSpec, suespec_list_p, unitNode::suespecs(), Coord::to_string(), Node::typ(), typeNode::type(), Union, and unit_list_p.

Referenced by readType().

typeNode * NodeInfo::readType string    s [private]
 

Definition at line 411 of file nodeinfo.cc.

References Array, Func, index2node, primNode::merge_in(), Ptr, readsuef(), sueSpec, and Node::typ().

Referenced by getNode().

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

Definition at line 1710 of file nodeinfo.cc.

References Array, Enum, Func, Prim, Ptr, Struct, sueSpec, Tdef, basic_type::to_string(), Node::typ(), and Union.

Referenced by match_args(), writeProc(), and writeType().

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.

Definition at line 1335 of file nodeinfo.cc.

References Binary, Call, Id, Node::typ(), TypNames, and Unary.

Referenced by W::at_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.

Definition at line 1426 of file nodeinfo.cc.

References _file, _line, _read_mode, Node::coord(), Decl, index2node, declNode::name(), node2index, strings, and TypNames.

Referenced by W::at_decl().

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 should be used instead, respectively.

Definition at line 1405 of file nodeinfo.cc.

References _file, _line, _read_mode, Node::coord(), Coord::file(), index2node, node2index, strings, Node::typ(), and TypNames.

void NodeInfo::writeProc procNode   proc
 

Write node for a procedure.

Definition at line 1306 of file nodeinfo.cc.

References _file, _line, _read_mode, Node::coord(), procNode::decl(), decl_list, decl_list_p, Func, index2node, declNode::name(), node2index, strings, Node::typ(), declNode::type(), and type_name().

Referenced by W::at_call(), and W::at_proc().

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.

Definition at line 1444 of file nodeinfo.cc.

References _file, _line, _read_mode, Node::coord(), Coord::file(), index2node, node2index, strings, Node::typ(), and TypNames.

Referenced by W::at_stmt().

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.

Definition at line 1463 of file nodeinfo.cc.

References _file, _line, index2node, and strings.

Referenced by W::at_call().

void NodeInfo::writeType typeNode   t
 

Write node for a type.

Definition at line 1095 of file nodeinfo.cc.

References _file, _line, _read_mode, Array, canonical(), Node::coord(), def_type(), Func, index2node, suespecNode::name(), node2index, suespecNode::owner(), Prim, Ptr, strings, sueSpec, Tdef, Node::typ(), typeNode::type(), and type_name().

Referenced by W::at_type().


Friends And Related Function Documentation

friend class NodeLocator [friend]
 

Locate an AST node.

Definition at line 258 of file nodeinfo.h.

Referenced by NodeLocator::findCall(), NodeLocator::findDecl(), and NodeLocator::findExprOrStmt().


Member Data Documentation

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

Definition at line 115 of file nodeinfo.cc.

Referenced by canonical().

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

Definition at line 116 of file nodeinfo.cc.

Referenced by canonical().

FILE* NodeInfo::_file [private]
 

Definition at line 84 of file nodeinfo.h.

Referenced by NodeInfo(), writeDecl(), writeExpr(), writeProc(), writeStmt(), writeString(), and writeType().

int NodeInfo::_line [private]
 

Definition at line 92 of file nodeinfo.h.

Referenced by NodeInfo(), writeDecl(), writeExpr(), writeProc(), writeStmt(), writeString(), and writeType().

bool NodeInfo::_read_mode [private]
 

Definition at line 85 of file nodeinfo.h.

Referenced by getNode(), NodeInfo(), readProc(), readsuef(), writeDecl(), writeExpr(), writeProc(), writeStmt(), and writeType().

bool NodeInfo::_verbose [private]
 

Definition at line 86 of file nodeinfo.h.

Referenced by getCoord(), and NodeInfo().

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

Definition at line 90 of file nodeinfo.h.

Referenced by NodeInfo(), readCall(), readDecl(), readExprOrStmt(), readType(), writeDecl(), writeExpr(), writeProc(), writeStmt(), writeString(), and writeType().

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

Definition at line 91 of file nodeinfo.h.

Referenced by NodeInfo(), writeDecl(), writeExpr(), writeProc(), writeStmt(), and writeType().

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

Definition at line 89 of file nodeinfo.h.

Referenced by NodeInfo(), readDecl(), writeDecl(), writeExpr(), writeProc(), writeStmt(), writeString(), and writeType().


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

Generated on August 27, 2003
Back to the C-Breeze home page