Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages
NodeInfo Class ReferenceHelper 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) |
typeNode * | getType (unitNode *unit, string s) |
string | type_name (typeNode *t) |
typeNode * | def_type (typeNode *ty) |
Public Member Functions |
|
| NodeInfo (string filename, bool readmode, bool verbose) |
| Constructor: Create an instance of this class.
|
| ~NodeInfo () |
| Destructor: Destroy an instance of this class.
|
|
bool | read_mode (void) |
| Query if it is read mode.
|
string | index (int i) |
| Obtain the string at a line.
|
Node * | indexNode (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.
|
|
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 |
arrayNode * | canonical (arrayNode *array) |
| Get the canonical array for a given array.
|
Private Member Functions |
|
Methods for read-mode
|
Node * | getNode (string s) |
typeNode * | readType (string s) |
procNode * | readProc (string s) |
typeNode * | readsuef (string s) |
callNode * | readCall (string s) |
Node * | readExprOrStmt (string s, NodeType typ) |
declNode * | readDecl (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. |
|
Destructor: Destroy an instance of this class.
Definition at line 342 of file nodeinfo.cc. |
Member Function Documentation
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. |
|
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] |
|
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(). |
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] |
|
int NodeInfo::nodeIndex |
( |
Node * |
node |
) |
[inline] |
|
int NodeInfo::nStrings |
( |
|
) |
[inline] |
|
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] |
|
declNode * NodeInfo::readDecl |
( |
string |
s |
) |
[private] |
|
Node * NodeInfo::readExprOrStmt |
( |
string |
s, |
|
|
NodeType |
typ |
|
) |
[private] |
|
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] |
|
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 |
|
) |
|
|
void NodeInfo::writeDecl |
( |
declNode * |
d, |
|
|
int |
container = -1 |
|
) |
|
|
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 |
|
) |
|
|
void NodeInfo::writeString |
( |
string |
s |
) |
|
|
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]
|
|
Member Data Documentation
list< arrayNode * > NodeInfo::_canonical1 [static, private]
|
|
FILE* NodeInfo::_file [private]
|
|
int NodeInfo::_line [private]
|
|
bool NodeInfo::_read_mode [private]
|
|
bool NodeInfo::_verbose [private]
|
|
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]
|
|
map<int,string> NodeInfo::strings [private]
|
|
The documentation for this class was generated from the following files:
|