Skip to content

Commit 53c3868

Browse files
committed
feat: Add convenient API to simplecpp:DUI for adding different type of search paths
1 parent ce48c54 commit 53c3868

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ int main(int argc, char **argv)
4343
}
4444
case 'I': { // include path
4545
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
46-
dui.searchPaths.push_back({value, simplecpp::DUI::PathKind::Include});
46+
dui.addIncludePath(value);
4747
found = true;
4848
break;
4949
}
5050
case 'F': { // framework path
5151
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
52-
dui.searchPaths.push_back({value, simplecpp::DUI::PathKind::Framework});
52+
dui.addFrameworkPath(value);
5353
found = true;
5454
break;
5555
}
@@ -61,7 +61,7 @@ int main(int argc, char **argv)
6161
use_istream = true;
6262
found = true;
6363
} else if (std::strncmp(arg, "-iframework", 11) == 0) {
64-
dui.searchPaths.push_back({arg + 11, simplecpp::DUI::PathKind::SystemFramework});
64+
dui.addSystemFrameworkPath(arg + 11);
6565
found = true;
6666
}
6767
break;

simplecpp.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,19 @@ namespace simplecpp {
423423
PathKind kind;
424424
};
425425

426+
// Mirrors compiler option -I<dir>
427+
void addIncludePath(const std::string& path) {
428+
searchPaths.push_back({path, PathKind::Include});
429+
}
430+
// Mirrors compiler option -F<dir>
431+
void addFrameworkPath(const std::string& path) {
432+
searchPaths.push_back({path, PathKind::Framework});
433+
}
434+
// Mirrors compiler option -iframework<dir>
435+
void addSystemFrameworkPath(const std::string& path) {
436+
searchPaths.push_back({path, PathKind::SystemFramework});
437+
}
438+
426439
std::list<std::string> defines;
427440
std::set<std::string> undefined;
428441

test.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,11 +2158,9 @@ static void appleFrameworkIncludeTest()
21582158
simplecpp::TokenList tokens2(files);
21592159
simplecpp::DUI dui;
21602160
#ifdef SIMPLECPP_TEST_SOURCE_DIR
2161-
dui.searchPaths.push_back({testSourceDir + "/testsuite",
2162-
simplecpp::DUI::PathKind::Framework
2163-
});
2161+
dui.addFrameworkPath(testSourceDir + "/testsuite");
21642162
#else
2165-
dui.searchPaths.push_back({"./testsuite", simplecpp::DUI::PathKind::Framework});
2163+
dui.addFrameworkPath("./testsuite");
21662164
#endif
21672165
simplecpp::OutputList outputList;
21682166
simplecpp::preprocess(tokens2, rawtokens, files, cache, dui, &outputList);
@@ -2187,11 +2185,9 @@ static void appleFrameworkHasIncludeTest()
21872185
simplecpp::TokenList tokens2(files);
21882186
simplecpp::DUI dui;
21892187
#ifdef SIMPLECPP_TEST_SOURCE_DIR
2190-
dui.searchPaths.push_back({testSourceDir + "/testsuite",
2191-
simplecpp::DUI::PathKind::Framework
2192-
});
2188+
dui.addFrameworkPath(testSourceDir + "/testsuite");
21932189
#else
2194-
dui.searchPaths.push_back({"./testsuite", simplecpp::DUI::PathKind::Framework});
2190+
dui.addFrameworkPath("./testsuite");
21952191
#endif
21962192
dui.std = "c++17"; // enable __has_include
21972193

0 commit comments

Comments
 (0)