Beispiel #1
0
	core::annotations::Location convertClangSrcLoc(core::NodeManager& man, const clang::SourceManager& sm, clang::SourceLocation start,
	                                               clang::SourceLocation end) {
		// check file validity
		FileID&& fileId = sm.getFileID(start);
		if(fileId.isInvalid()) return core::annotations::Location::getShared();
		const clang::FileEntry* fileEntry = sm.getFileEntryForID(fileId);
		// if we cannot get the file entry, lets try to get the source filename directly
		std::string filename;
		if(!fileEntry) {
			StringRef s = sm.getFilename(start);
			filename = s.str();
		} else {
			assert_true(fileEntry);
			filename = fileEntry->getName();
		}
		// update macro locations, if required
		start = getExpansionLoc(sm, start);
		end = getExpansionLoc(sm, end);
		// generate location object
		core::IRBuilder builder(man);
		return core::annotations::Location(builder.stringValue(filename.c_str()),
		                                   core::annotations::TextPosition(sm.getSpellingLineNumber(start), sm.getSpellingColumnNumber(start)),
		                                   core::annotations::TextPosition(sm.getSpellingLineNumber(end), sm.getSpellingColumnNumber(end)));
	}