Skip to content

Commit b846951

Browse files
committed
refactor config paths
1 parent 3faf936 commit b846951

File tree

4 files changed

+55
-21
lines changed

4 files changed

+55
-21
lines changed

include/mrdox/Config.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class Config
5252
std::vector<std::string> inputFileFilter_;
5353
bool verbose_ = true;
5454

55+
llvm::SmallString<0>
56+
makeAbsolute(llvm::StringRef relPath);
57+
5558
explicit Config(llvm::StringRef configDir);
5659

5760
public:
@@ -137,6 +140,15 @@ class Config
137140
return sourceRoot_;
138141
}
139142

143+
/** Returns true if the translation unit should be visited.
144+
145+
@param filePath The posix-style full path
146+
to the file being processed.
147+
*/
148+
bool
149+
shouldVisitTU(
150+
llvm::StringRef filePath) const noexcept;
151+
140152
/** Returns true if the file should be visited.
141153
142154
If the file is visited, then prefix is
@@ -174,6 +186,12 @@ class Config
174186
Symbol documentation will not be emitted unless
175187
the corresponding source file is a child of this
176188
directory.
189+
190+
If the specified directory is relative, then
191+
the full path will be computed relative to
192+
@ref configDir().
193+
194+
@param dirPath The directory.
177195
*/
178196
llvm::Error
179197
setSourceRoot(

source/lib/Config.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ struct llvm::yaml::MappingTraits<
6565
namespace clang {
6666
namespace mrdox {
6767

68+
//------------------------------------------------
69+
70+
llvm::SmallString<0>
71+
Config::
72+
makeAbsolute(llvm::StringRef relPath)
73+
{
74+
namespace fs = llvm::sys::fs;
75+
namespace path = llvm::sys::path;
76+
77+
if(path::is_absolute(relPath))
78+
return relPath;
79+
llvm::SmallString<0> result(configDir());
80+
path::append(result, relPath);
81+
return result;
82+
}
83+
6884
Config::
6985
Config(
7086
llvm::StringRef configDir)
@@ -136,6 +152,14 @@ loadFromFile(
136152
//
137153
//------------------------------------------------
138154

155+
bool
156+
Config::
157+
shouldVisitTU(
158+
llvm::StringRef filePath) const noexcept
159+
{
160+
return true;
161+
}
162+
139163
bool
140164
Config::
141165
shouldVisitFile(
@@ -146,9 +170,8 @@ shouldVisitFile(
146170

147171
llvm::SmallString<32> temp;
148172
temp = filePath;
149-
if(! path::replace_path_prefix(temp, sourceRoot_, ""))
173+
if(! path::replace_path_prefix(temp, sourceRoot_, "", path::Style::posix))
150174
return false;
151-
152175
prefixPath.assign(sourceRoot_.begin(), sourceRoot_.end());
153176
makeDirsy(prefixPath);
154177
return true;
@@ -168,20 +191,11 @@ setSourceRoot(
168191
namespace fs = llvm::sys::fs;
169192
namespace path = llvm::sys::path;
170193

171-
llvm::SmallString<0> temp(dirPath);
172-
if(! path::is_absolute(sourceRoot_, path::Style::posix))
173-
{
174-
std::error_code ec = fs::make_absolute(temp);
175-
if(ec)
176-
return makeError("fs::make_absolute got '", ec, "'");
177-
}
178-
194+
auto temp = makeAbsolute(dirPath);
179195
path::remove_dots(temp, true, path::Style::posix);
180-
181-
// This is required for filterSourceFile to work
196+
convert_to_slash(temp);
182197
makeDirsy(temp, path::Style::posix);
183198
sourceRoot_ = temp.str();
184-
185199
return llvm::Error::success();
186200
}
187201

source/lib/Visitor.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ Visitor::
3535
HandleTranslationUnit(
3636
ASTContext& Context)
3737
{
38-
#if 0
39-
llvm::Optional<llvm::StringRef> path =
38+
llvm::Optional<llvm::StringRef> filePath =
4039
Context.getSourceManager().getNonBuiltinFilenameForID(
4140
Context.getSourceManager().getMainFileID());
42-
if(path)
41+
if(filePath)
4342
{
44-
llvm::StringRef s = *path;
43+
llvm::SmallString<0> s(*filePath);
44+
convert_to_slash(s);
45+
if(config_.shouldVisitTU(s))
46+
TraverseDecl(Context.getTranslationUnitDecl());
4547
}
46-
#endif
47-
TraverseDecl(Context.getTranslationUnitDecl());
4848
}
4949

5050
template<typename T>
@@ -80,7 +80,7 @@ mapDecl(T const* D)
8080
// cached filter entry already exists
8181
FileFilter const& ff = result.first->second;
8282
if(! ff.include)
83-
return false;
83+
return true;
8484
filePath = loc.getFilename(); // native
8585
convert_to_slash(filePath);
8686
// VFALCO we could assert that the prefix
@@ -96,7 +96,7 @@ mapDecl(T const* D)
9696
FileFilter& ff = result.first->second;
9797
ff.include = config_.shouldVisitFile(filePath, ff.prefix);
9898
if(! ff.include)
99-
return false;
99+
return true;
100100
// VFALCO we could assert that the prefix
101101
// matches and just lop off the
102102
// first ff.prefix.size() characters.

source/lib/utility.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ convert_to_slash(
3030
llvm::sys::path::Style::native);
3131

3232
/** Append a separator if not already present.
33+
34+
This is required for llvm::sys::path::append to work.
3335
*/
3436
void
3537
makeDirsy(

0 commit comments

Comments
 (0)