void HeaderTagger::addHeaderForDecl(const core::NodePtr& node, const clang::Decl* decl, bool attachUserDefined) const { // check whether there is a declaration at all if (!decl) return; // the node was already annotated, what is the point of doint it again? if (insieme::annotations::c::hasIncludeAttached(node)) return; if (VLOG_IS_ON(2)){ std::string name("UNNAMED"); if (const clang::NamedDecl* nmd = llvm::dyn_cast<clang::NamedDecl>(decl)) name = nmd->getQualifiedNameAsString(); VLOG(2) << "Searching header for: " << node << " of type " << node->getNodeType() << " [clang: " << name << "]" ; } string fileName = getTopLevelInclude(decl->getLocation()); // file must be a header file if (!isHeaderFile(fileName)) { VLOG(2) << "'" << fileName << "' not a headerfile"; return; // not to be attached } // do not add headers for external declarations unless those are within the std-library if (const clang::FunctionDecl* funDecl = llvm::dyn_cast<clang::FunctionDecl>(decl)) { // TODO: this is just based on integration tests - to make them work, no real foundation :( if( funDecl->isExternC() && !(isStdLibHeader(fileName) || isIntrinsicHeader(fileName)) ) return; } // get absolute path of header file fs::path header = fs::canonical(fileName); if (auto oclHeader = isOCLHeader(header)){ VLOG(2) << "OCL header to be attached: " << oclHeader; insieme::annotations::c::attachInclude(node, *oclHeader); return; }if( auto stdLibHeader = toStdLibHeader(header) ) { header = *stdLibHeader; } else if (auto interceptedLibHeader = toInterceptedLibHeader(header) ) { header = *interceptedLibHeader; } else if( auto intrinsicHeader = toIntrinsicHeader(header) ) { header = *intrinsicHeader; } else if (auto userLibHeader = toUserLibHeader(header) ) { if(attachUserDefined ) { header = *userLibHeader; } else { return; } } VLOG(2) << " header to be attached: " << header.string(); // use resulting header insieme::annotations::c::attachInclude(node, header.string()); }
void SimpleNameManager::setName(const core::NodePtr& ptr, const string& name) { // disabled since name collisions might happen with overloaded functions! // assert_true((!isUsed(name) || (lookup(ptr) && *lookup(ptr) == name))) << "Cannot bind to name already used!"; // everything is in the global scope auto names = &globalScope.names; auto used = &globalScope.usedNames; // unless it is a variable if(ptr->getNodeType() == core::NT_Variable) { names = &varScope.back().names; used = &varScope.back().usedNames; } // insert into data structures __unused auto res = names->insert(make_pair(ptr, name)); // disabled since name collisions might happen with overloaded member functions! // assert_true((res.second || res.first->second == name)) << "Tried to alter name after already being bound!"; used->insert(name); }