logic: switched to using wstring for compiler flags

* removed getter for strings from QtDirectoryListBox because it is not used anymore
* regard encoding of clang error messages
This commit is contained in:
mlangkabel
2018-02-09 13:37:30 +01:00
parent 9773c30fdc
commit 333fc7eea2
25 changed files with 250 additions and 261 deletions
@@ -7,7 +7,7 @@ IndexerCommandCxx::IndexerCommandCxx(
const FilePath& workingDirectory,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths,
const std::vector<std::string>& compilerFlags
const std::vector<std::wstring>& compilerFlags
)
: IndexerCommand(sourceFilePath, indexedPaths, excludedPaths)
, m_workingDirectory(workingDirectory)
@@ -49,7 +49,7 @@ const std::vector<FilePath>& IndexerCommandCxx::getFrameworkSearchPaths() const
return m_frameworkSearchPaths;
}
const std::vector<std::string>& IndexerCommandCxx::getCompilerFlags() const
const std::vector<std::wstring>& IndexerCommandCxx::getCompilerFlags() const
{
return m_compilerFlags;
}
+3 -3
View File
@@ -19,20 +19,20 @@ public:
const FilePath& workingDirectory,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths,
const std::vector<std::string>& compilerFlags);
const std::vector<std::wstring>& compilerFlags);
virtual size_t getByteSize(size_t stringSize) const override;
const std::vector<FilePath>& getSystemHeaderSearchPaths() const;
const std::vector<FilePath>& getFrameworkSearchPaths() const;
const std::vector<std::string>& getCompilerFlags() const;
const std::vector<std::wstring>& getCompilerFlags() const;
const FilePath& getWorkingDirectory() const;
private:
FilePath m_workingDirectory;
std::vector<FilePath> m_systemHeaderSearchPaths;
std::vector<FilePath> m_frameworkSearchPaths;
std::vector<std::string> m_compilerFlags;
std::vector<std::wstring> m_compilerFlags;
};
#endif // INDEXER_COMMAND_CXXL_H
@@ -13,7 +13,7 @@ std::vector<FilePath> IndexerCommandCxxCdb::getSourceFilesFromCDB(const FilePath
if (!error.empty())
{
const std::string message = "Loading Clang compilation database failed with error: \"" + error + "\"";
const std::wstring message = L"Loading Clang compilation database failed with error: \"" + utility::decodeFromUtf8(error) + L"\"";
LOG_ERROR(message);
MessageStatus(message, true).dispatch();
}
@@ -44,7 +44,7 @@ IndexerCommandCxxCdb::IndexerCommandCxxCdb(
const std::set<FilePath>& indexedPaths,
const std::set<FilePath>& excludedPaths,
const FilePath& workingDirectory,
const std::vector<std::string>& compilerFlags,
const std::vector<std::wstring>& compilerFlags,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths
)
@@ -25,7 +25,7 @@ public:
const std::set<FilePath>& indexedPaths,
const std::set<FilePath>& excludedPaths,
const FilePath& workingDirectory,
const std::vector<std::string>& compilerFlags,
const std::vector<std::wstring>& compilerFlags,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths);
@@ -13,7 +13,7 @@ IndexerCommandCxxEmpty::IndexerCommandCxxEmpty(
const std::string& languageStandard,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths,
const std::vector<std::string>& compilerFlags
const std::vector<std::wstring>& compilerFlags
)
: IndexerCommandCxx(sourceFilePath, indexedPaths, excludedPaths, workingDirectory, systemHeaderSearchPaths, frameworkSearchPaths, compilerFlags)
, m_languageStandard(languageStandard)
@@ -19,7 +19,7 @@ public:
const std::string& languageStandard,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths,
const std::vector<std::string>& compilerFlags);
const std::vector<std::wstring>& compilerFlags);
virtual IndexerCommandType getIndexerCommandType() const override;
virtual size_t getByteSize(size_t stringSize) const override;
+21 -12
View File
@@ -75,9 +75,12 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand)
clang::tooling::CompileCommand compileCommand;
compileCommand.Filename = indexerCommand->getSourceFilePath().str();
compileCommand.Directory = indexerCommand->getWorkingDirectory().str();
compileCommand.CommandLine = utility::concat(indexerCommand->getCompilerFlags(), getCommandlineArgumentsEssential(
std::vector<std::string>(), indexerCommand->getSystemHeaderSearchPaths(), indexerCommand->getFrameworkSearchPaths()
));
compileCommand.CommandLine = utility::concat(
utility::convert<std::wstring, std::string>(indexerCommand->getCompilerFlags(), [](const std::wstring & flag) { return utility::encodeToUtf8(flag); }),
getCommandlineArgumentsEssential(
std::vector<std::wstring>(), indexerCommand->getSystemHeaderSearchPaths(), indexerCommand->getFrameworkSearchPaths()
)
);
if (!utility::isPrefix("-", compileCommand.CommandLine.front()))
{
@@ -93,14 +96,17 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxEmpty> indexerComman
{
clang::tooling::CompileCommand compileCommand;
compileCommand.Filename = utility::encodeToUtf8(indexerCommand->getSourceFilePath().wstr());
compileCommand.Directory = indexerCommand->getWorkingDirectory().str();
compileCommand.CommandLine = prependSyntaxOnlyToolArgs(appendFilePath(getCommandlineArguments(indexerCommand), utility::encodeToUtf8(indexerCommand->getSourceFilePath().wstr())));
compileCommand.Directory = utility::encodeToUtf8(indexerCommand->getWorkingDirectory().wstr());
compileCommand.CommandLine = prependSyntaxOnlyToolArgs(appendFilePath(
getCommandlineArguments(indexerCommand),
utility::encodeToUtf8(indexerCommand->getSourceFilePath().wstr())
));
CxxCompilationDatabaseSingle compilationDatabase(compileCommand);
runTool(&compilationDatabase, indexerCommand->getSourceFilePath());
}
void CxxParser::buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent, std::vector<std::string> compilerFlags)
void CxxParser::buildIndex(const std::wstring& fileName, std::shared_ptr<TextAccess> fileContent, std::vector<std::wstring> compilerFlags)
{
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache = std::make_shared<CanonicalFilePathCache>();
@@ -114,7 +120,7 @@ void CxxParser::buildIndex(const std::string& fileName, std::shared_ptr<TextAcce
actionFactory.create(),
fileContent->getText(),
args,
fileName
utility::encodeToUtf8(fileName)
);
}
@@ -133,7 +139,7 @@ void CxxParser::runTool(clang::tooling::CompilationDatabase* compilationDatabase
}
std::vector<std::string> CxxParser::getCommandlineArgumentsEssential(
const std::vector<std::string>& compilerFlags, const std::vector<FilePath>& systemHeaderSearchPaths, const std::vector<FilePath>& frameworkSearchPaths
const std::vector<std::wstring>& compilerFlags, const std::vector<FilePath>& systemHeaderSearchPaths, const std::vector<FilePath>& frameworkSearchPaths
) const {
std::vector<std::string> args;
@@ -156,18 +162,21 @@ std::vector<std::string> CxxParser::getCommandlineArgumentsEssential(
// This option tells clang just to continue parsing no matter how manny errors have been thrown.
args.push_back("-ferror-limit=0");
args.insert(args.end(), compilerFlags.begin(), compilerFlags.end());
for (const std::wstring& compilerFlag: compilerFlags)
{
args.push_back(utility::encodeToUtf8(compilerFlag));
}
for (const FilePath& path: systemHeaderSearchPaths)
for (const FilePath& path : systemHeaderSearchPaths)
{
args.push_back("-isystem");
args.push_back(path.str());
args.push_back(utility::encodeToUtf8(path.wstr()));
}
for (const FilePath& path: frameworkSearchPaths)
{
args.push_back("-iframework");
args.push_back(path.str());
args.push_back(utility::encodeToUtf8(path.wstr()));
}
return args;
+2 -2
View File
@@ -26,13 +26,13 @@ public:
void buildIndex(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand);
void buildIndex(std::shared_ptr<IndexerCommandCxxEmpty> indexerCommand);
void buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent, std::vector<std::string> compilerFlags = {});
void buildIndex(const std::wstring& fileName, std::shared_ptr<TextAccess> fileContent, std::vector<std::wstring> compilerFlags = {});
private:
void runTool(clang::tooling::CompilationDatabase* compilationDatabase, const FilePath& sourceFilePath);
std::vector<std::string> getCommandlineArgumentsEssential(
const std::vector<std::string>& compilerFlags,
const std::vector<std::wstring>& compilerFlags,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths) const;
std::vector<std::string> getCommandlineArguments(std::shared_ptr<IndexerCommandCxxEmpty> indexerCommand) const;
+6 -3
View File
@@ -66,7 +66,7 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxCdb::getIndexerComman
utility::append(frameworkSearchPaths, m_settings->getFrameworkSearchPathsExpandedAndAbsolute());
utility::append(frameworkSearchPaths, appSettings->getFrameworkSearchPathsExpanded());
const std::vector<std::string> compilerFlags = m_settings->getCompilerFlags();
const std::vector<std::wstring> compilerFlags = m_settings->getCompilerFlags();
std::set<FilePath> indexedPaths = getIndexedPaths();
std::set<FilePath> excludedPaths = getExcludedPaths();
@@ -87,7 +87,7 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxCdb::getIndexerComman
if (!error.empty())
{
const std::string message = "Loading Clang compilation database failed with error: \"" + error + "\"";
const std::wstring message = L"Loading Clang compilation database failed with error: \"" + utility::decodeFromUtf8(error) + L"\"";
LOG_ERROR(message);
MessageStatus(message, true).dispatch();
}
@@ -110,7 +110,10 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxCdb::getIndexerComman
indexedPaths,
excludedPaths,
FilePath(command.Directory),
utility::concat(command.CommandLine, compilerFlags),
utility::concat(
utility::convert<std::string, std::wstring>(command.CommandLine, [](const std::string& arg) { return utility::decodeFromUtf8(arg); }),
compilerFlags
),
systemHeaderSearchPaths,
frameworkSearchPaths
));
+2 -2
View File
@@ -40,9 +40,9 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxEmpty::getIndexerComm
utility::append(frameworkSearchPaths, m_settings->getFrameworkSearchPathsExpandedAndAbsolute());
utility::append(frameworkSearchPaths, appSettings->getFrameworkSearchPathsExpanded());
std::vector<std::string> compilerFlags;
std::vector<std::wstring> compilerFlags;
{
const std::string targetFlag = m_settings->getTargetFlag();
const std::wstring targetFlag = m_settings->getTargetFlag();
if (!targetFlag.empty())
{
compilerFlags.push_back(targetFlag);