Skip to content

Commit 1a9cfb0

Browse files
committed
feat: Update DUI::addIncludePath to accept legacy parameter
1 parent 112cb2b commit 1a9cfb0

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ 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.addIncludePath(value);
46+
dui.addIncludePath(value, /* legacy= */ false);
4747
found = true;
4848
break;
4949
}

simplecpp.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,19 +424,28 @@ namespace simplecpp {
424424
PathKind kind;
425425
};
426426

427-
/** Mirrors compiler option -I<dir> */
428-
void addIncludePath(const std::string& path) {
429-
searchPaths.push_back({path, PathKind::Include});
427+
/**
428+
* Mirrors compiler option -I<dir>
429+
*
430+
* If 'legacy' is true, the path is added to the 'includePaths' vector;
431+
* otherwise, it is added to 'searchPaths' with 'PathKind::Include'.
432+
*/
433+
void addIncludePath(const std::string& path, bool legacy) {
434+
if (legacy) {
435+
includePaths.push_back(path);
436+
} else {
437+
searchPaths.push_back({path, PathKind::Include});
438+
}
430439
}
431440
/** Mirrors compiler option -I<dir> */
432441
void addSystemIncludePath(const std::string& path) {
433442
searchPaths.push_back({path, PathKind::SystemInclude});
434443
}
435-
// Mirrors compiler option -F<dir>
444+
/** Mirrors compiler option -F<dir> */
436445
void addFrameworkPath(const std::string& path) {
437446
searchPaths.push_back({path, PathKind::Framework});
438447
}
439-
// Mirrors compiler option -iframework<dir>
448+
/** Mirrors compiler option -iframework<dir> */
440449
void addSystemFrameworkPath(const std::string& path) {
441450
searchPaths.push_back({path, PathKind::SystemFramework});
442451
}

test.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ static void has_include_1()
15611561
" #endif\n"
15621562
"#endif";
15631563
simplecpp::DUI dui;
1564-
dui.includePaths.push_back(testSourceDir);
1564+
dui.addIncludePath(testSourceDir, /* legacy= */ true);
15651565
dui.std = "c++17";
15661566
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
15671567
dui.std = "c++14";
@@ -1579,7 +1579,7 @@ static void has_include_2()
15791579
" #endif\n"
15801580
"#endif";
15811581
simplecpp::DUI dui;
1582-
dui.includePaths.push_back(testSourceDir);
1582+
dui.addIncludePath(testSourceDir, /* legacy= */ true);
15831583
dui.std = "c++17";
15841584
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
15851585
ASSERT_EQUALS("", preprocess(code));
@@ -1599,7 +1599,7 @@ static void has_include_3()
15991599
// Test file not found...
16001600
ASSERT_EQUALS("\n\n\n\nB", preprocess(code, dui));
16011601
// Unless -I is set (preferably, we should differentiate -I and -isystem...)
1602-
dui.includePaths.push_back(testSourceDir + "/testsuite");
1602+
dui.addIncludePath(testSourceDir + "/testsuite", /* legacy= */ true);
16031603
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
16041604
ASSERT_EQUALS("", preprocess(code));
16051605
}
@@ -1615,7 +1615,7 @@ static void has_include_4()
16151615
"#endif";
16161616
simplecpp::DUI dui;
16171617
dui.std = "c++17";
1618-
dui.includePaths.push_back(testSourceDir);
1618+
dui.addIncludePath(testSourceDir, /* legacy= */ true);
16191619
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
16201620
ASSERT_EQUALS("", preprocess(code));
16211621
}
@@ -1631,7 +1631,7 @@ static void has_include_5()
16311631
"#endif";
16321632
simplecpp::DUI dui;
16331633
dui.std = "c++17";
1634-
dui.includePaths.push_back(testSourceDir);
1634+
dui.addIncludePath(testSourceDir, /* legacy= */ true);
16351635
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
16361636
ASSERT_EQUALS("", preprocess(code));
16371637
}
@@ -1647,7 +1647,7 @@ static void has_include_6()
16471647
"#endif";
16481648
simplecpp::DUI dui;
16491649
dui.std = "gnu99";
1650-
dui.includePaths.push_back(testSourceDir);
1650+
dui.addIncludePath(testSourceDir, /* legacy= */ true);
16511651
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
16521652
ASSERT_EQUALS("", preprocess(code));
16531653
}
@@ -2042,7 +2042,7 @@ static void missingHeader2()
20422042
simplecpp::TokenList tokens2(files);
20432043
const simplecpp::TokenList rawtokens = makeTokenList(code,files);
20442044
simplecpp::DUI dui;
2045-
dui.includePaths.push_back(".");
2045+
dui.addIncludePath(".", /* legacy= */ true);
20462046
simplecpp::preprocess(tokens2, rawtokens, files, cache, dui, &outputList);
20472047
ASSERT_EQUALS("", toString(outputList));
20482048
}
@@ -2074,7 +2074,7 @@ static void nestedInclude()
20742074
simplecpp::OutputList outputList;
20752075
simplecpp::TokenList tokens2(files);
20762076
simplecpp::DUI dui;
2077-
dui.includePaths.push_back(".");
2077+
dui.addIncludePath(".", /* legacy= */ true);
20782078
simplecpp::preprocess(tokens2, rawtokens, files, cache, dui, &outputList);
20792079

20802080
ASSERT_EQUALS("file0,1,include_nested_too_deeply,#include nested too deeply\n", toString(outputList));
@@ -2092,7 +2092,7 @@ static void systemInclude()
20922092
simplecpp::OutputList outputList;
20932093
simplecpp::TokenList tokens2(files);
20942094
simplecpp::DUI dui;
2095-
dui.includePaths.push_back("include");
2095+
dui.addIncludePath("include", /* legacy= */ true);
20962096
simplecpp::preprocess(tokens2, rawtokens, files, cache, dui, &outputList);
20972097

20982098
ASSERT_EQUALS("", toString(outputList));
@@ -2374,7 +2374,7 @@ static void include3() // #16 - crash when expanding macro from header
23742374

23752375
simplecpp::TokenList out(files);
23762376
simplecpp::DUI dui;
2377-
dui.includePaths.push_back(".");
2377+
dui.addIncludePath(".", /* legacy= */ true);
23782378
simplecpp::preprocess(out, rawtokens_c, files, cache, dui);
23792379

23802380
ASSERT_EQUALS("\n1234", out.stringify());
@@ -2401,7 +2401,7 @@ static void include4() // #27 - -include
24012401

24022402
simplecpp::TokenList out(files);
24032403
simplecpp::DUI dui;
2404-
dui.includePaths.push_back(".");
2404+
dui.addIncludePath(".", /* legacy= */ true);
24052405
dui.includes.push_back("27.h");
24062406
simplecpp::preprocess(out, rawtokens_c, files, cache, dui);
24072407

@@ -2428,7 +2428,7 @@ static void include5() // #3 - handle #include MACRO
24282428

24292429
simplecpp::TokenList out(files);
24302430
simplecpp::DUI dui;
2431-
dui.includePaths.push_back(".");
2431+
dui.addIncludePath(".", /* legacy= */ true);
24322432
simplecpp::preprocess(out, rawtokens_c, files, cache, dui);
24332433

24342434
ASSERT_EQUALS("\n#line 1 \"3.h\"\n123", out.stringify());
@@ -2474,7 +2474,7 @@ static void include7() // #include MACRO
24742474

24752475
simplecpp::TokenList out(files);
24762476
simplecpp::DUI dui;
2477-
dui.includePaths.push_back(".");
2477+
dui.addIncludePath(".", /* legacy= */ true);
24782478
simplecpp::preprocess(out, rawtokens_c, files, cache, dui);
24792479

24802480
ASSERT_EQUALS("\n#line 1 \"3.h\"\n123", out.stringify());
@@ -2512,7 +2512,7 @@ static void include9()
25122512

25132513
simplecpp::TokenList out(files);
25142514
simplecpp::DUI dui;
2515-
dui.includePaths.push_back(".");
2515+
dui.addIncludePath(".", /* legacy= */ true);
25162516
simplecpp::preprocess(out, rawtokens_c, files, cache, dui);
25172517

25182518
ASSERT_EQUALS("\n#line 2 \"1.h\"\nx = 1 ;", out.stringify());
@@ -2694,7 +2694,7 @@ static void stringify1()
26942694

26952695
simplecpp::TokenList out(files);
26962696
simplecpp::DUI dui;
2697-
dui.includePaths.push_back(".");
2697+
dui.addIncludePath(".", /* legacy= */ true);
26982698
simplecpp::preprocess(out, rawtokens_c, files, cache, dui);
26992699

27002700
ASSERT_EQUALS("\n#line 1 \"A.h\"\n1\n2\n#line 1 \"A.h\"\n1\n2", out.stringify());

0 commit comments

Comments
 (0)