00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00035 #include "variabletreenode.h"
00036
00037 VariableTreeNode::VariableTreeNode():
00038 parent(NULL), var(TAGID_ROOT), direct_output(false) {
00039 }
00040
00041 VariableTreeNode::VariableTreeNode(VariableTreeNode * _parent, unsigned _var,
00042 bool _direct_output):parent(_parent),
00043 var(_var),
00044 direct_output(_direct_output) {
00045 }
00046
00047 VariableTreeNode::~VariableTreeNode() {
00048 for (unsigned i = 0; i < children.size(); i++) {
00049 delete children[i];
00050 }
00051 }
00052
00053 bool VariableTreeNode::insertNode(unsigned parent_var,
00054 unsigned introduced_var, bool direct_output) {
00055 if (parent_var == var) {
00056 VariableTreeNode *child =
00057 new VariableTreeNode(this, introduced_var, direct_output);
00058 children.push_back(child);
00059
00060 return true;
00061 } else {
00062 bool created = false;
00063
00064 for (unsigned i = 0; i < children.size() && !created; i++) {
00065 created =
00066 children[i]->insertNode(parent_var, introduced_var,
00067 direct_output);
00068 }
00069
00070 return created;
00071 }
00072 }
00073
00074 void VariableTreeNode::print(OutputStream & dos) {
00075 print(dos, 0);
00076 dos << resetIndents();
00077 }
00078
00079 void VariableTreeNode::print(OutputStream & dos, unsigned indents) {
00080 dos << resetIndents() << incrementIndents(indents);
00081 dos << writeIndents();
00082 dos << "($" << VarName::getInstance()->getVarname(var) << ")";
00083 if (direct_output) {
00084 dos << " *";
00085 }
00086 dos << NEWLINE;
00087 for (unsigned i = 0; i < children.size(); i++) {
00088 children[i]->print(dos, indents + 1);
00089 }
00090 }