void Transaction::appendUnique(DeclGroupRef DGR) { for (const_iterator I = decls_begin(), E = decls_end(); I != E; ++I) { if (DGR.isNull() || (*I).getAsOpaquePtr() == DGR.getAsOpaquePtr()) return; } m_DeclQueue.push_back(DGR); }
void Transaction::print(llvm::raw_ostream& Out, const PrintingPolicy& Policy, unsigned Indent, bool PrintInstantiation) const { int nestedT = 0; for (const_iterator I = decls_begin(), E = decls_end(); I != E; ++I) { if (I->m_DGR.isNull()) { assert(hasNestedTransactions() && "DGR is null even if no nesting?"); // print the nested decl Out<< "\n"; Out<<"+====================================================+\n"; Out<<" Nested Transaction" << nestedT << " \n"; Out<<"+====================================================+\n"; (*m_NestedTransactions)[nestedT++]->print(Out, Policy, Indent, PrintInstantiation); Out<< "\n"; Out<<"+====================================================+\n"; Out<<" End Transaction" << nestedT << " \n"; Out<<"+====================================================+\n"; } I->print(Out, Policy, Indent, PrintInstantiation); } // Print the deserialized decls if any. for (const_iterator I = deserialized_decls_begin(), E = deserialized_decls_end(); I != E; ++I) { assert(!I->m_DGR.isNull() && "Must not contain null DGR."); I->print(Out, Policy, Indent, PrintInstantiation, "Deserialized"); } }
void Transaction::print(llvm::raw_ostream& Out, const PrintingPolicy& Policy, unsigned Indent, bool PrintInstantiation) const { int nestedT = 0; for (const_iterator I = decls_begin(), E = decls_end(); I != E; ++I) { if (I->m_DGR.isNull()) { assert(hasNestedTransactions() && "DGR is null even if no nesting?"); // print the nested decl Out<< "\n"; Out<<"+====================================================+\n"; Out<<" Nested Transaction" << nestedT << " \n"; Out<<"+====================================================+\n"; (*m_NestedTransactions)[nestedT++]->print(Out, Policy, Indent, PrintInstantiation); Out<< "\n"; Out<<"+====================================================+\n"; Out<<" End Transaction" << nestedT << " \n"; Out<<"+====================================================+\n"; } for (DeclGroupRef::const_iterator J = I->m_DGR.begin(), L = I->m_DGR.end(); J != L; ++J) if (*J) (*J)->print(Out, Policy, Indent, PrintInstantiation); else Out << "<<NULL DECL>>"; } }
TranslationUnit::TranslationUnit(NodeManager& mgr, const path& file, const ConversionSetup& setup) : mMgr(mgr), mFileName(file), setup(setup), mClang(setup, file), mSema(mPragmaList, mClang.getPreprocessor(), mClang.getASTContext(), emptyCons, true) { // check for frontend extensions pragma handlers // and add user provided pragmas to be handled // by insieme std::map<std::string, clang::PragmaNamespace*> pragmaNamespaces; for(auto extension : setup.getExtensions()) { for(auto ph : extension->getPragmaHandlers()) { std::string name = ph->getName(); // if the pragma namespace is not registered already // create and register it and store it in the map of pragma namespaces if(pragmaNamespaces.find(name) == pragmaNamespaces.end()) { pragmaNamespaces[name] = new clang::PragmaNamespace(name); mClang.getPreprocessor().AddPragmaHandler(pragmaNamespaces[name]); } // add the user provided pragma handler pragmaNamespaces[name]->AddPragma(pragma::PragmaHandlerFactory::CreatePragmaHandler<pragma::Pragma>( mClang.getPreprocessor().getIdentifierInfo(ph->getKeyword()), *ph->getToken(), ph->getName(), ph->getFunction())); } } parseClangAST(mClang, &emptyCons, mSema); // all pragmas should now have either a decl or a stmt attached. // it can be the case that a pragma is at the end of a file // and therefore not attached to anything. Find these cases // and attach the pragmas to the translation unit declaration. for(auto cur : mPragmaList) { if(!cur->isStatement() && !cur->isDecl()) { cur->setDecl(getCompiler().getASTContext().getTranslationUnitDecl()); } } if(mClang.getDiagnostics().hasErrorOccurred()) { // errors are always fatal throw ClangParsingError(mFileName); } if(setup.hasOption(ConversionSetup::DumpClangAST)) { const std::string filter = setup.getClangASTDumpFilter(); auto tuDecl = getASTContext().getTranslationUnitDecl(); // if nothing defined print the whole context if(filter.empty()) { tuDecl->dumpColor(); } else { // else filter out the right function decls auto declCtx = clang::TranslationUnitDecl::castToDeclContext(tuDecl); // iterate through the declarations inside and print (maybe) for(auto it = declCtx->decls_begin(); it != declCtx->decls_end(); ++it) { if(const clang::FunctionDecl* funDecl = llvm::dyn_cast<clang::FunctionDecl>(*it)) { if(boost::regex_match(funDecl->getNameAsString(), boost::regex(filter))) { funDecl->dumpColor(); } } } } } }
void Transaction::dump() const { int nestedT = 0; for (const_iterator I = decls_begin(), E = decls_end(); I != E; ++I) { if (I->isNull()) { assert(hasNestedTransactions() && "DGR is null even if no nesting?"); // print the nested decl llvm::outs()<<"+====================================================+\n"; llvm::outs()<<"| Nested Transaction" << nestedT << " |\n"; llvm::outs()<<"+====================================================+\n"; m_NestedTransactions[nestedT++]->dump(); llvm::outs()<<"+====================================================+\n"; llvm::outs()<<"| End Transaction" << nestedT << " |\n"; llvm::outs()<<"+====================================================+\n"; } for (DeclGroupRef::const_iterator J = I->begin(), L = I->end(); J != L;++J) (*J)->dump(); } }
void Transaction::removeNestedTransaction(Transaction* nested) { assert(hasNestedTransactions() && "Does not contain nested transactions"); int nestedPos = -1; for (size_t i = 0; i < m_NestedTransactions->size(); ++i) if ((*m_NestedTransactions)[i] == nested) { nestedPos = i; break; } assert(nestedPos > -1 && "Not found!?"); m_NestedTransactions->erase(m_NestedTransactions->begin() + nestedPos); // We need to remove the marker too. int markerPos = -1; for (iterator I = decls_begin(), E = decls_end(); I != E; ++I) { if (I->m_DGR.isNull() && I->m_Call == kCCINone) { ++markerPos; if (nestedPos == markerPos) { erase(I); // Safe because of the break stmt. break; } } } if (!m_NestedTransactions->size()) m_NestedTransactions.reset(0); }
void Transaction::erase(size_t pos) { assert(!empty() && "Erasing from an empty transaction."); m_DeclQueue.erase(decls_begin() + pos); }