@@ -1398,6 +1398,12 @@ class DpctGlobalInfo {
13981398 getHeaderInsertedBitMap () {
13991399 return HeaderInsertedBitMap;
14001400 }
1401+ static bool &getIsAfterBitsStdcxxStatus () { return IsAfterBitsStdcxx; }
1402+ static std::map<clang::tooling::UnifiedPath,
1403+ std::set<clang::tooling::UnifiedPath>> &
1404+ getAfterBitsStdcxxFilesMap () {
1405+ return AfterBitsStdcxxFiles;
1406+ }
14011407 std::shared_ptr<DpctFileInfo>
14021408 insertFile (const clang::tooling::UnifiedPath &FilePath) {
14031409 return insertObject (FileMap, FilePath);
@@ -1407,7 +1413,10 @@ class DpctGlobalInfo {
14071413 return findObject (FileMap, FilePath);
14081414 }
14091415 std::shared_ptr<DpctFileInfo> getMainFile () const { return MainFile; }
1410- void setMainFile (std::shared_ptr<DpctFileInfo> Main) { MainFile = Main; }
1416+ void setMainFile (std::shared_ptr<DpctFileInfo> Main) {
1417+ getIsAfterBitsStdcxxStatus () = false ;
1418+ MainFile = Main;
1419+ }
14111420 void recordIncludingRelationship (
14121421 const clang::tooling::UnifiedPath &CurrentFileName,
14131422 const clang::tooling::UnifiedPath &IncludedFileName);
@@ -1726,6 +1735,17 @@ class DpctGlobalInfo {
17261735 static std::unordered_map<clang::tooling::UnifiedPath,
17271736 std::bitset<HeaderType::NUM_HEADERS>>
17281737 HeaderInsertedBitMap;
1738+ // `IsAfterBitsStdcxx` is used as a flag. It is set to true when PP meet
1739+ // <bits/stdc++.h>. It is reset to false when starting to process a new
1740+ // translation unit.
1741+ static bool IsAfterBitsStdcxx;
1742+ // If `IsAfterBitsStdcxx` is true, it means <bits/stdc++.h> is already
1743+ // included, so the tool will record all files included since this time point.
1744+ // When inserting `sycl.hpp`, the tool can check if the insert location is in
1745+ // the map, if it is, the tool will also insert `sycl.hpp` at the main file.
1746+ static std::map<clang::tooling::UnifiedPath /* MainFile*/ ,
1747+ std::set<clang::tooling::UnifiedPath>>
1748+ AfterBitsStdcxxFiles;
17291749};
17301750
17311751// / Generate mangle name of FunctionDecl as key of DeviceFunctionInfo.
0 commit comments