~TreeNode(){ ChildMap::iterator it = children.begin(); while(it != children.end()){ delete it->second; it++; } }
/** * get list of all the child nodes */ void TreeNode::getChildren(std::vector<TreeNode *> & childrenOfNode){ childrenOfNode.clear(); ChildMap::iterator it = children.begin(); while(it != children.end()){ childrenOfNode.push_back(it->second); it++; } }
void XMLreader::mainProcessorIni( std::vector<TiXmlNode*> pParentVect ) { std::map<plint, TiXmlNode*> parents; for (pluint iParent=0; iParent<pParentVect.size(); ++iParent) { PLB_PRECONDITION( pParentVect[iParent]->Type()==TiXmlNode::DOCUMENT || pParentVect[iParent]->Type()==TiXmlNode::ELEMENT ); TiXmlElement* pParentElement = pParentVect[iParent]->ToElement(); plint id=0; if (pParentElement) { const char* attribute = pParentElement->Attribute("id"); if (attribute) { std::stringstream attributestr(attribute); attributestr >> id; } } parents[id] = pParentVect[iParent]; } plint numId = (plint)parents.size(); global::mpi().bCast(&numId, 1); std::map<plint, TiXmlNode*>::iterator it = parents.begin(); name = it->second->ValueStr(); global::mpi().bCast(name); for (; it != parents.end(); ++it) { plint id = it->first; global::mpi().bCast(&id, 1); TiXmlNode* pParent = it->second; Data& data = data_map[id]; data.text=""; typedef std::map<std::string, std::vector<TiXmlNode*> > ChildMap; ChildMap childMap; TiXmlNode* pChild; for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) { int type = pChild->Type(); if ( type==TiXmlNode::ELEMENT ) { std::string name(pChild->Value()); childMap[name].push_back(pChild); } else if ( type==TiXmlNode::TEXT ) { data.text = pChild->ToText()->ValueStr(); } } global::mpi().bCast(data.text); plint numChildren = (plint) childMap.size(); global::mpi().bCast(&numChildren, 1); for (ChildMap::iterator it = childMap.begin(); it != childMap.end(); ++it) { std::vector<TiXmlNode*> pChildVect = it->second; data.children.push_back( new XMLreader( pChildVect ) ); } } }
void XMLreader::mainProcessorIni( std::vector<TiXmlNode*> pParentVect ) { std::map<int, TiXmlNode*> parents; for (unsigned iParent=0; iParent<pParentVect.size(); ++iParent) { EPC_ASSERT( pParentVect[iParent]->Type()==TiXmlNode::DOCUMENT || pParentVect[iParent]->Type()==TiXmlNode::ELEMENT ); TiXmlElement* pParentElement = pParentVect[iParent]->ToElement(); int id=0; if (pParentElement) { const char* attribute = pParentElement->Attribute("id"); if (attribute) { std::stringstream attributestr(attribute); attributestr >> id; } } parents[id] = pParentVect[iParent]; } std::map<int, TiXmlNode*>::iterator it = parents.begin(); name = it->second->ValueStr(); for (; it != parents.end(); ++it) { int id = it->first; TiXmlNode* pParent = it->second; Data& data = data_map[id]; data.text=""; typedef std::map<std::string, std::vector<TiXmlNode*> > ChildMap; ChildMap childMap; TiXmlNode* pChild; for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) { int type = pChild->Type(); if ( type==TiXmlNode::ELEMENT ) { std::string name(pChild->Value()); childMap[name].push_back(pChild); } else if ( type==TiXmlNode::TEXT ) { data.text = pChild->ToText()->ValueStr(); } } for (ChildMap::iterator it = childMap.begin(); it != childMap.end(); ++it) { std::vector<TiXmlNode*> pChildVect = it->second; data.children.push_back( new XMLreader( pChildVect ) ); } } }
/** * Obtain a node given its name components (relative from root) */ TreeNode & getNode(SArray<SString> &nameComponents, int indexOfComponentToBeExamined){ if ((unsigned)indexOfComponentToBeExamined == nameComponents.size()){ return *this; } const SString nodeName = nameComponents[indexOfComponentToBeExamined]; ChildMap::iterator it = children.find(nodeName); if (it == children.end()){ throw BrowseException(); } TreeNode * node = it->second; // recurse down tree branchs return node->getNode(nameComponents, indexOfComponentToBeExamined+1); }
void ClangASTNodesEmitter::run(raw_ostream &OS) { emitSourceFileHeader("List of AST nodes of a particular kind", OS); // Write the preamble OS << "#ifndef ABSTRACT_" << macroName(Root.getName()) << "\n"; OS << "# define ABSTRACT_" << macroName(Root.getName()) << "(Type) Type\n"; OS << "#endif\n"; OS << "#ifndef " << macroName(Root.getName()) << "_RANGE\n"; OS << "# define " << macroName(Root.getName()) << "_RANGE(Base, First, Last)\n"; OS << "#endif\n\n"; OS << "#ifndef LAST_" << macroName(Root.getName()) << "_RANGE\n"; OS << "# define LAST_" << macroName(Root.getName()) << "_RANGE(Base, First, Last) " << macroName(Root.getName()) << "_RANGE(Base, First, Last)\n"; OS << "#endif\n\n"; // Emit statements const std::vector<Record*> Stmts = Records.getAllDerivedDefinitions(Root.getName()); ChildMap Tree; for (unsigned i = 0, e = Stmts.size(); i != e; ++i) { Record *R = Stmts[i]; if (R->getValue("Base")) Tree.insert(std::make_pair(R->getValueAsDef("Base"), R)); else Tree.insert(std::make_pair(&Root, R)); } EmitNode(Tree, OS, &Root); OS << "#undef " << macroName(Root.getName()) << "\n"; OS << "#undef " << macroName(Root.getName()) << "_RANGE\n"; OS << "#undef LAST_" << macroName(Root.getName()) << "_RANGE\n"; OS << "#undef ABSTRACT_" << macroName(Root.getName()) << "\n"; }
// Returns the first and last non-abstract subrecords // Called recursively to ensure that nodes remain contiguous std::pair<Record *, Record *> ClangASTNodesEmitter::EmitNode( const ChildMap &Tree, raw_ostream &OS, Record *Base) { std::string BaseName = macroName(Base->getName()); ChildIterator i = Tree.lower_bound(Base), e = Tree.upper_bound(Base); Record *First = 0, *Last = 0; // This might be the pseudo-node for Stmt; don't assume it has an Abstract // bit if (Base->getValue("Abstract") && !Base->getValueAsBit("Abstract")) First = Last = Base; for (; i != e; ++i) { Record *R = i->second; bool Abstract = R->getValueAsBit("Abstract"); std::string NodeName = macroName(R->getName()); OS << "#ifndef " << NodeName << "\n"; OS << "# define " << NodeName << "(Type, Base) " << BaseName << "(Type, Base)\n"; OS << "#endif\n"; if (Abstract) OS << "ABSTRACT_" << macroName(Root.getName()) << "(" << NodeName << "(" << R->getName() << ", " << baseName(*Base) << "))\n"; else OS << NodeName << "(" << R->getName() << ", " << baseName(*Base) << ")\n"; if (Tree.find(R) != Tree.end()) { const std::pair<Record *, Record *> &Result = EmitNode(Tree, OS, R); if (!First && Result.first) First = Result.first; if (Result.second) Last = Result.second; } else { if (!Abstract) { Last = R; if (!First) First = R; } } OS << "#undef " << NodeName << "\n\n"; } if (First) { assert (Last && "Got a first node but not a last node for a range!"); if (Base == &Root) OS << "LAST_" << macroName(Root.getName()) << "_RANGE("; else OS << macroName(Root.getName()) << "_RANGE("; OS << Base->getName() << ", " << First->getName() << ", " << Last->getName() << ")\n\n"; } return std::make_pair(First, Last); }