[clang-tools-extra] r230665 - Fixed canonical path function.

John Thompson john.thompson.jtsoftware at gmail.com
Fri Feb 27 10:56:39 PST 2015


+    if (B->compare(".") == 0) {
+    }

Hopefully this clause causes paths like ./node.h and node1/./node2.h to
become node.h and node1/node2.h, respectively.

I'm not sure what you mean by filesystem TS.

One question is whether a "normalization" function should convert relative
paths to absolute.  In this case I opted not to make it absolute.

I decided to put it locally for now, due to time constraints.  Later I can
move it when I can take more time to write a test and so forth.  Actually I
think if might be an inefficient function, as I think it might do array
resizing as it builds up the new path and allocates a new string for the
return, but it's sufficient for my needs.

Comments about suitability for path.h/cpp would be appreciated.

-John


On Thu, Feb 26, 2015 at 3:51 PM, Sean Silva <chisophugis at gmail.com> wrote:

> +    if (B->compare(".") == 0) {
> +    }
>
> ?
>
> Also, does this function implement the corresponding function of the
> filesystem TS correctly? If so, we should probably move it to sys::path.
>
> -- Sean Silva
>
> On Thu, Feb 26, 2015 at 11:31 AM, John Thompson <
> John.Thompson.JTSoftware at gmail.com> wrote:
>
>> Author: jtsoftware
>> Date: Thu Feb 26 13:31:10 2015
>> New Revision: 230665
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=230665&view=rev
>> Log:
>> Fixed canonical path function.
>>
>> Modified:
>>     clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp
>>     clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
>>
>> Modified: clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp?rev=230665&r1=230664&r2=230665&view=diff
>>
>> ==============================================================================
>> --- clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp (original)
>> +++ clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp Thu Feb 26
>> 13:31:10 2015
>> @@ -341,13 +341,31 @@ bool ModularizeUtilities::collectUmbrell
>>    }
>>    return true;
>>  }
>> +
>> +std::string normalize(StringRef Path) {
>> +  SmallString<128> Buffer;
>> +  llvm::sys::path::const_iterator B = llvm::sys::path::begin(Path),
>> +    E = llvm::sys::path::end(Path);
>> +  while (B != E) {
>> +    if (B->compare(".") == 0) {
>> +    }
>> +    else if (B->compare("..") == 0)
>> +      llvm::sys::path::remove_filename(Buffer);
>> +    else
>> +      llvm::sys::path::append(Buffer, *B);
>> +    ++B;
>> +  }
>> +  if (Path.endswith("/") || Path.endswith("\\"))
>> +    Buffer.append(1, Path.back());
>> +  return Buffer.c_str();
>> +}
>>
>>  // Convert header path to canonical form.
>>  // The canonical form is basically just use forward slashes, and remove
>> "./".
>>  // \param FilePath The file path, relative to the module map directory.
>>  // \returns The file path in canonical form.
>>  std::string ModularizeUtilities::getCanonicalPath(StringRef FilePath) {
>> -  std::string Tmp(FilePath);
>> +  std::string Tmp(normalize(FilePath));
>>    std::replace(Tmp.begin(), Tmp.end(), '\\', '/');
>>    StringRef Tmp2(Tmp);
>>    if (Tmp2.startswith("./"))
>>
>> Modified: clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp?rev=230665&r1=230664&r2=230665&view=diff
>>
>> ==============================================================================
>> --- clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp (original)
>> +++ clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp Thu Feb 26
>> 13:31:10 2015
>> @@ -251,6 +251,7 @@
>>  #include "llvm/ADT/SmallSet.h"
>>  #include "llvm/Support/StringPool.h"
>>  #include "llvm/Support/raw_ostream.h"
>> +#include "ModularizeUtilities.h"
>>
>>  namespace Modularize {
>>
>> @@ -930,8 +931,8 @@ public:
>>      // and block statement.
>>      clang::FileID FileID =
>> PP.getSourceManager().getFileID(BlockStartLoc);
>>      std::string SourcePath = getSourceLocationFile(PP, BlockStartLoc);
>> +    SourcePath = ModularizeUtilities::getCanonicalPath(SourcePath);
>>      HeaderHandle SourceHandle = findHeaderHandle(SourcePath);
>> -    // FIXME: Go back and fix getSourceLocation to use a canonical form.
>>      if (SourceHandle == -1)
>>        return true;
>>      int BlockStartLine, BlockStartColumn, BlockEndLine, BlockEndColumn;
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>


-- 
John Thompson
John.Thompson.JTSoftware at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150227/c3613a61/attachment.html>


More information about the cfe-commits mailing list