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) |
static string | type_name (typeNode *t) |
static 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 |
static 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 |
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. |
|
Destructor: Destroy an instance of this class.
|
Member Function Documentation
|
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. |
Coord NodeInfo::getCoord |
( |
string |
s, |
|
|
unitNode ** |
unit |
|
) |
[private] |
|
Node* NodeInfo::getNode |
( |
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:
-
- 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] |
|
bool NodeInfo::read_mode |
( |
void |
|
) |
[inline] |
|
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 |
) |
|
|
Friends And Related Function Documentation
friend class NodeLocator [friend] |
|
Member Data Documentation
The documentation for this class was generated from the following file:
|