#define DEBUG_TYPE "ctags-emitter"
-namespace llvm { extern SourceMgr SrcMgr; }
-
namespace {
class Tag {
: Id(&Name), Loc(Location) {}
int operator<(const Tag &B) const { return *Id < *B.Id; }
void emit(raw_ostream &OS) const {
- int BufferID = SrcMgr.FindBufferContainingLoc(Loc);
- MemoryBuffer *CurMB = SrcMgr.getBufferInfo(BufferID).Buffer;
+ const MemoryBuffer *CurMB =
+ SrcMgr.getMemoryBuffer(SrcMgr.FindBufferContainingLoc(Loc));
const char *BufferName = CurMB->getBufferIdentifier();
std::pair<unsigned, unsigned> LineAndColumn = SrcMgr.getLineAndColumn(Loc);
OS << *Id << "\t" << BufferName << "\t" << LineAndColumn.first << "\n";
SMLoc CTagsEmitter::locate(const Record *R) {
ArrayRef<SMLoc> Locs = R->getLoc();
- if (Locs.empty()) {
- SMLoc NullLoc;
- return NullLoc;
- }
- return Locs.front();
+ return !Locs.empty() ? Locs.front() : SMLoc();
}
void CTagsEmitter::run(raw_ostream &OS) {
- const std::map<std::string, Record *> &Classes = Records.getClasses();
- const std::map<std::string, Record *> &Defs = Records.getDefs();
+ const auto &Classes = Records.getClasses();
+ const auto &Defs = Records.getDefs();
std::vector<Tag> Tags;
// Collect tags.
Tags.reserve(Classes.size() + Defs.size());
- for (std::map<std::string, Record *>::const_iterator I = Classes.begin(),
- E = Classes.end();
- I != E; ++I)
- Tags.push_back(Tag(I->first, locate(I->second)));
- for (std::map<std::string, Record *>::const_iterator I = Defs.begin(),
- E = Defs.end();
- I != E; ++I)
- Tags.push_back(Tag(I->first, locate(I->second)));
+ for (const auto &C : Classes)
+ Tags.push_back(Tag(C.first, locate(C.second.get())));
+ for (const auto &D : Defs)
+ Tags.push_back(Tag(D.first, locate(D.second.get())));
// Emit tags.
std::sort(Tags.begin(), Tags.end());
OS << "!_TAG_FILE_FORMAT\t1\t/original ctags format/\n";
OS << "!_TAG_FILE_SORTED\t1\t/0=unsorted, 1=sorted, 2=foldcase/\n";
- for (std::vector<Tag>::const_iterator I = Tags.begin(), E = Tags.end();
- I != E; ++I)
- I->emit(OS);
+ for (const Tag &T : Tags)
+ T.emit(OS);
}
namespace llvm {