fix: "." and ".." in included header paths not correctly handled

This commit is contained in:
Roy Qu 2022-10-23 23:06:55 +08:00
parent e13217a395
commit 09c7b5e791
4 changed files with 41 additions and 35 deletions

View File

@ -814,18 +814,12 @@ void CppParser::parseFile(const QString &fileName, bool inProject, bool onlyIfNo
if (onlyIfNotParsed && mPreprocessor.scannedFiles().contains(fName))
return;
if (inProject) {
QSet<QString> filesToReparsed = calculateFilesToBeReparsed(fileName);
internalInvalidateFiles(filesToReparsed);
QStringList files = sortFilesByIncludeRelations(filesToReparsed);
if (inProject)
mProjectFiles.insert(fileName);
else {
mProjectFiles.remove(fileName);
}
// Parse from disk or stream
mFilesToScanCount = files.count();
mFilesScannedCount = 0;
@ -836,6 +830,24 @@ void CppParser::parseFile(const QString &fileName, bool inProject, bool onlyIfNo
internalParse(file);
}
}
} else {
internalInvalidateFile(fileName);
mFilesToScanCount = 1;
mFilesScannedCount = 0;
mFilesScannedCount++;
emit onProgress(fileName,mFilesToScanCount,mFilesScannedCount);
internalParse(fileName);
}
// if (inProject)
// mProjectFiles.insert(fileName);
// else {
// mProjectFiles.remove(fileName);
// }
// Parse from disk or stream
}
}
@ -1442,7 +1454,8 @@ QStringList CppParser::sortFilesByIncludeRelations(const QSet<QString> &files)
if (mOnGetFileStream) {
mOnGetFileStream(file,buffer);
}
mPreprocessor.setScanOptions(mParseGlobalHeaders, mParseLocalHeaders);
//we only use local include relations
mPreprocessor.setScanOptions(false, true);
mPreprocessor.preprocess(file,buffer);
mPreprocessor.clearTempResults();
}
@ -4324,11 +4337,12 @@ QSet<QString> CppParser::calculateFilesToBeReparsed(const QString &fileName)
return QSet<QString>();
QSet<QString> result;
result.insert(fileName);
foreach (const QString& file,mPreprocessor.includesList().keys()) {
foreach (const QString& file, mProjectFiles) {
PFileIncludes fileIncludes = mPreprocessor.includesList()[file];
if (fileIncludes->includeFiles.contains(fileName))
if (fileIncludes->includeFiles.contains(fileName)) {
result.insert(file);
}
}
return result;
}

View File

@ -479,7 +479,6 @@ void CppPreprocessor::handleInclude(const QString &line, bool fromNext)
mOnGetFileStream(fileName,buffer);
}
openInclude(fileName, buffer);
//oldCurrentIncludes->includeFiles.insert(fileName,true);
}
void CppPreprocessor::handlePreprocessor(const QString &value)
@ -730,12 +729,6 @@ void CppPreprocessor::openInclude(const QString &fileName, QStringList bufferedT
// do NOT create a new item for a file that's already in the list
mCurrentIncludes = std::make_shared<FileIncludes>();
mCurrentIncludes->baseFile = fileName;
//mCurrentIncludes->includeFiles;
//mCurrentIncludes->usings;
//mCurrentIncludes->statements;
//mCurrentIncludes->scopes;
//mCurrentIncludes->dependedFiles;
//mCurrentIncludes->dependingFiles;
mIncludesList.insert(fileName,mCurrentIncludes);
}
@ -748,7 +741,7 @@ void CppPreprocessor::openInclude(const QString &fileName, QStringList bufferedT
mScannedFiles.insert(fileName);
// Only load up the file if we are allowed to parse it
bool isSystemFile = isSystemHeaderFile(fileName, mIncludePaths);
bool isSystemFile = isSystemHeaderFile(fileName, mIncludePaths) || isSystemHeaderFile(fileName, mProjectIncludePaths);
if ((mParseSystem && isSystemFile) || (mParseLocal && !isSystemFile)) {
if (!bufferedText.isEmpty()) {
parsedFile->buffer = bufferedText;
@ -764,9 +757,6 @@ void CppPreprocessor::openInclude(const QString &fileName, QStringList bufferedT
foreach (const QString& incFile,fileIncludes->includeFiles.keys()) {
file->fileIncludes->includeFiles.insert(incFile,false);
}
// file->fileIncludes->includeFiles =
// file->fileIncludes->includeFiles.unite(fileIncludes->includeFiles);
// file->fileIncludes->includeFiles.insert(fileIncludes->includeFiles);
}
}
mIncludes.append(parsedFile);

View File

@ -391,6 +391,7 @@ QString getHeaderFilename(const QString &relativeTo, const QString &line,
}
}
}
return result;
}
@ -400,7 +401,7 @@ QString getLocalHeaderFilename(const QString &relativeTo, const QString &fileNam
QDir dir = relativeFile.dir();
// Search local directory
if (dir.exists(fileName)) {
return dir.absoluteFilePath(fileName);
return QDir::cleanPath(dir.absoluteFilePath(fileName));
}
return "";
}
@ -411,8 +412,9 @@ QString getSystemHeaderFilename(const QString &fileName, const QStringList& incl
// Search compiler include directories
for (const QString& path:includePaths) {
QDir dir(path);
if (dir.exists(fileName))
return dir.absoluteFilePath(fileName);
if (dir.exists(fileName)) {
return QDir::cleanPath(dir.absoluteFilePath(fileName));
}
}
//not found
return "";

View File

@ -76,14 +76,14 @@ enum StatementKind {
skEnumType,
skEnumClassType,
skTypedef,
skConstructor,
skDestructor,
skFunction,
skVariable,
skGlobalVariable,
skLocalVariable,
skEnum,
skOperator,
skConstructor,
skDestructor,
skParameter,
skBlock,
skUserCodeSnippet, // user code template