This is an archive of the discontinued LLVM Phabricator instance.

Make FileSpec::Dump use FileSpec::GetPath(), not the other way around.
AbandonedPublic

Authored by zturner on May 22 2015, 11:42 AM.

Details

Reviewers
None
Summary

We need FileSpec::Dump() to format the result according to the paths' internal path syntax. So this means backslashes on windows, for example. GetPath already has the ability to do this, but GetPath was calling Dump and then adding the denormalization logic on top of that. So the change here is to make it work the other way around. Have GetPath call dump instead, and then just append the trailing slash if necessary. This way Dump can just call GetPath(true).

Diff Detail

Event Timeline

zturner updated this revision to Diff 26335.May 22 2015, 11:42 AM
zturner retitled this revision from to Make FileSpec::Dump use FileSpec::GetPath(), not the other way around..
zturner updated this object.
zturner edited the test plan for this revision. (Show Details)
zturner added a reviewer: chaoren.
zturner added a subscriber: Unknown Object (MLST).
zturner added inline comments.
source/Host/common/FileSpec.cpp
845

Ignore this line, I had it in for debugging purposes. Forgot to remove it before uploading.

chaoren added inline comments.May 22 2015, 11:55 AM
source/Host/common/FileSpec.cpp
628

How about just s->PutCString(GetPath().c_str())?

831

s/AsCString/GetStringRef/

839

See above.

chaoren requested changes to this revision.May 22 2015, 2:31 PM
chaoren edited edge metadata.
chaoren added inline comments.
source/Host/common/FileSpec.cpp
619

Please ignore this comment. Phabricator won't let me delete.

629

We also need m_directory && !m_directory.GetStringRef().endswith("/")

This revision now requires changes to proceed.May 22 2015, 2:31 PM
zturner added inline comments.May 22 2015, 2:47 PM
source/Host/common/FileSpec.cpp
629

Ahh, I think I need to fix the endswith() check in GetPath instead. Previously GetPath() was calling Dump with trailing_slash=false, so that means anyone calling GetPath() directly was getting back something that never had a trailing slash. But with this change, it's possible for a direct call to GetPath() to include a trailing slash.

So if I fix it there, I can just remove this whole branch and the entire function is just

if (s)
    s->PutCString(GetPath().c_str());
zturner updated this revision to Diff 26633.May 27 2015, 2:10 PM
zturner edited edge metadata.

Let's see if this is better. GetPath() should now NEVER append a trailing slash, and Dump() should now ALWAYS append a trailing slash. there were no users of Dump() passing false, so I assume the ability to choose wasn't needed, which is why I removed the argument.

chaoren requested changes to this revision.May 27 2015, 3:12 PM
chaoren edited edge metadata.
chaoren added inline comments.
source/Host/common/FileSpec.cpp
630

What if path == "/"?

844

What if m_directory == '/'? We'd get //filename.

This revision now requires changes to proceed.May 27 2015, 3:12 PM
chaoren added inline comments.May 27 2015, 3:14 PM
source/Host/common/FileSpec.cpp
844

Nevermind, you trimmed away the single '/'. But there's another problem if m_directory == '/' and m_filename is empty, you return an empty string.

GetPath() is supposed to have not put a trailing slash in that case. See
the call to rtrim() in GetPath()

chaoren resigned from this revision.May 28 2015, 10:34 AM
chaoren removed a reviewer: chaoren.
zturner abandoned this revision.May 28 2015, 11:19 AM