Skip to content

Commit d1f511d

Browse files
committed
test simplecpp#444
1 parent 5ba370f commit d1f511d

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

externals/simplecpp/simplecpp.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,7 @@ static std::string openHeader(std::ifstream &f, const std::string &path)
31733173
return "";
31743174
}
31753175

3176-
static std::string getRelativeFileName(const std::string &baseFile, const std::string &header)
3176+
static std::string getRelativeFileName(const std::string &baseFile, const std::string &header, bool returnAbsolutePath)
31773177
{
31783178
const std::string baseFileSimplified = simplecpp::simplifyPath(baseFile);
31793179
const std::string baseFileAbsolute = isAbsolutePath(baseFileSimplified) ?
@@ -3185,12 +3185,12 @@ static std::string getRelativeFileName(const std::string &baseFile, const std::s
31853185
headerSimplified :
31863186
simplecpp::simplifyPath(dirPath(baseFileAbsolute) + headerSimplified);
31873187

3188-
return extractRelativePathFromAbsolute(path);
3188+
return returnAbsolutePath ? toAbsolutePath(path) : extractRelativePathFromAbsolute(path);
31893189
}
31903190

31913191
static std::string openHeaderRelative(std::ifstream &f, const std::string &sourcefile, const std::string &header)
31923192
{
3193-
return openHeader(f, getRelativeFileName(sourcefile, header));
3193+
return openHeader(f, getRelativeFileName(sourcefile, header, isAbsolutePath(sourcefile)));
31943194
}
31953195

31963196
// returns the simplified header path:
@@ -3273,11 +3273,18 @@ static std::string getFileIdPath(const std::map<std::string, simplecpp::TokenLis
32733273
}
32743274

32753275
if (!systemheader) {
3276-
const std::string relativeOrAbsoluteFilename = getRelativeFileName(sourcefile, header);// unknown if absolute or relative, but always simplified
3277-
const std::string match = findPathInMapBothRelativeAndAbsolute(filedata, relativeOrAbsoluteFilename);
3276+
const std::string absoluteFilename = getRelativeFileName(sourcefile, header, true);
3277+
const std::string match = findPathInMapBothRelativeAndAbsolute(filedata, absoluteFilename);
32783278
if (!match.empty()) {
32793279
return match;
32803280
}
3281+
// if the file exists but hasn't been loaded yet then we need to stop searching here or we could get a false match
3282+
std::ifstream f;
3283+
openHeader(f, relativeOrAbsoluteFilename);
3284+
if (f.is_open()) {
3285+
f.close();
3286+
return "";
3287+
}
32813288
} else if (filedata.find(header) != filedata.end()) {
32823289
return header;// system header that its file is already in the filedata - return that as is
32833290
}

0 commit comments

Comments
 (0)