]> granicus.if.org Git - clang/commitdiff
[PCH] Sort the file decls by file offset not raw source location.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 28 Oct 2011 23:57:47 +0000 (23:57 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 28 Oct 2011 23:57:47 +0000 (23:57 +0000)
Currently sorting by raw source location does work as intended but who knows
what may change in the future..

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143256 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Serialization/ASTWriter.h
lib/Serialization/ASTWriter.cpp

index 2c747d8ea844aa2a5bc350927c86cc900cb85ffe..bad5c379bcbf738fb34366002844d94addcdbe6b 100644 (file)
@@ -146,7 +146,7 @@ private:
   /// the declaration's ID.
   std::vector<serialization::DeclOffset> DeclOffsets;
 
-  /// \brief Vector of pairs of raw location/DeclID.
+  /// \brief Sorted (by file offset) vector of pairs of file offset/DeclID.
   typedef SmallVector<std::pair<unsigned, serialization::DeclID>, 64>
     LocDeclIDsTy;
   struct DeclIDInFileInfo {
index 0c9f0a1247cdacaf86b2a5c1e436e4f81bc0b64b..1b44baa9ce5382ed3d1204cd483a0a65834a1995 100644 (file)
@@ -3501,7 +3501,9 @@ void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) {
   SourceManager &SM = Context->getSourceManager();
   SourceLocation FileLoc = SM.getFileLoc(Loc);
   assert(SM.isLocalSourceLocation(FileLoc));
-  FileID FID = SM.getFileID(FileLoc);
+  FileID FID;
+  unsigned Offset;
+  llvm::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc);
   if (FID.isInvalid())
     return;
   const SrcMgr::SLocEntry *Entry = &SM.getSLocEntry(FID);
@@ -3511,11 +3513,10 @@ void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) {
   if (!Info)
     Info = new DeclIDInFileInfo();
 
-  unsigned RawLoc = FileLoc.getRawEncoding();
-  std::pair<unsigned, serialization::DeclID> LocDecl(RawLoc, ID);
+  std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID);
   LocDeclIDsTy &Decls = Info->DeclIDs;
 
-  if (Decls.empty() || Decls.back().first <= RawLoc) {
+  if (Decls.empty() || Decls.back().first <= Offset) {
     Decls.push_back(LocDecl);
     return;
   }