Git commit 24e2f759694c0f5c467e27731fd447bdf289c3ab by Ren=C3=A9 J.V. Berti= n. Committed on 27/09/2018 at 17:50. Pushed by rjvbb into branch '5.3'. Support for Objective-C++ in the custom-definesandincludes plugin Differential Revision: https://phabricator.kde.org/D15764 M +18 -5 plugins/custom-definesandincludes/compilerprovider/gcclikeco= mpiler.cpp M +1 -0 plugins/custom-definesandincludes/compilerprovider/icompiler= .h M +14 -1 plugins/custom-definesandincludes/compilerprovider/settingsm= anager.cpp M +2 -0 plugins/custom-definesandincludes/kcm_widget/parserwidget.cpp https://commits.kde.org/kdevelop/24e2f759694c0f5c467e27731fd447bdf289c3ab diff --git a/plugins/custom-definesandincludes/compilerprovider/gcclikecomp= iler.cpp b/plugins/custom-definesandincludes/compilerprovider/gcclikecompil= er.cpp index b6c8d8e703..45cfaa96cc 100644 --- a/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp +++ b/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp @@ -50,12 +50,14 @@ QString languageOption(Utils::LanguageType type) return QStringLiteral("-xcuda"); case Utils::ObjC: return QStringLiteral("-xobjective-c"); + case Utils::ObjCpp: + return QStringLiteral("-xobjective-c++"); default: Q_UNREACHABLE(); } } = -QString languageStandard(const QString& arguments) +QString languageStandard(const QString& arguments, Utils::LanguageType typ= e) { // TODO: handle -ansi flag: In C mode, this is equivalent to -std=3Dc9= 0. In C++ mode, it is equivalent to -std=3Dc++98. const QRegularExpression regexp(QStringLiteral("-std=3D(\\S+)")); @@ -63,8 +65,19 @@ QString languageStandard(const QString& arguments) if (result.hasMatch()) return result.captured(0); = - // no -std=3D flag passed -> assume c++11 - return QStringLiteral("-std=3Dc++11"); + switch (type) { + case Utils::C: + case Utils::ObjC: + return QStringLiteral("-std=3Dc99"); + case Utils::Cpp: + case Utils::ObjCpp: + case Utils::Cuda: + return QStringLiteral("-std=3Dc++11"); + case Utils::OpenCl: + return QStringLiteral("-cl-std=3DCL1.1"); + default: + Q_UNREACHABLE(); + } } = } @@ -87,7 +100,7 @@ Defines GccLikeCompiler::defines(Utils::LanguageType typ= e, const QString& argume // TODO: what about -mXXX or -target=3D flags, some of these change se= arch paths/defines const QStringList compilerArguments{ languageOption(type), - languageStandard(arguments), + languageStandard(arguments, type), QStringLiteral("-dM"), QStringLiteral("-E"), QStringLiteral("-"), @@ -144,7 +157,7 @@ Path::List GccLikeCompiler::includes(Utils::LanguageTyp= e type, const QString& ar = const QStringList compilerArguments{ languageOption(type), - languageStandard(arguments), + languageStandard(arguments, type), QStringLiteral("-E"), QStringLiteral("-v"), QStringLiteral("-"), diff --git a/plugins/custom-definesandincludes/compilerprovider/icompiler.h= b/plugins/custom-definesandincludes/compilerprovider/icompiler.h index cb8bb716cc..aa33a72ac1 100644 --- a/plugins/custom-definesandincludes/compilerprovider/icompiler.h +++ b/plugins/custom-definesandincludes/compilerprovider/icompiler.h @@ -38,6 +38,7 @@ enum LanguageType OpenCl, Cuda, ObjC, + ObjCpp, = Other }; diff --git a/plugins/custom-definesandincludes/compilerprovider/settingsman= ager.cpp b/plugins/custom-definesandincludes/compilerprovider/settingsmanag= er.cpp index 7e107c28dd..845c2bf94e 100644 --- a/plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp +++ b/plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp @@ -71,7 +71,12 @@ QString parserArgumentsKey(Utils::LanguageType languageT= ype) return QStringLiteral("parserArgumentsOpenCL"); case Utils::Cuda: return QStringLiteral("parserArgumentsCuda"); + // TODO: is there a need for "parserArgumentsObjC[++]" and if so how/w= here + // if not, merge the ObjC cases with the C/C++ cases. case Utils::ObjC: + return QStringLiteral("parserArgumentsC"); + case Utils::ObjCpp: + return QStringLiteral("parserArguments"); case Utils::Other: break; } @@ -99,7 +104,11 @@ ParserArguments createDefaultArguments() arguments[Utils::Cpp] =3D QStringLiteral("-ferror-limit=3D100 -fspell-= checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std= =3Dc++11"); arguments[Utils::OpenCl] =3D QStringLiteral("-ferror-limit=3D100 -fspe= ll-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -cl= -std=3DCL1.1"); arguments[Utils::Cuda] =3D QStringLiteral("-ferror-limit=3D100 -fspell= -checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std= =3Dc++11"); - arguments[Utils::ObjC] =3D QStringLiteral("-ferror-limit=3D100 -fspell= -checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std= =3Dc99"); + // For now, use the same arguments for ObjC(++) as for C(++). -Wall en= ables a number + // of language-specific warnings, removing the need to add them explic= itly. + // (https://embeddedartistry.com/blog/2017/3/7/clang-weverything) + arguments[Utils::ObjC] =3D arguments[Utils::C]; + arguments[Utils::ObjCpp] =3D arguments[Utils::Cpp]; arguments.parseAmbiguousAsCPP =3D true; = return arguments; @@ -439,6 +448,10 @@ LanguageType languageType(const QString& path, bool tr= eatAmbiguousAsCPP) return Cpp; } = + if (mimeType =3D=3D QStringLiteral("text/x-objc++src")) { + return ObjCpp; + } + if (mimeType =3D=3D QStringLiteral("text/x-objcsrc")) { return ObjC; } diff --git a/plugins/custom-definesandincludes/kcm_widget/parserwidget.cpp = b/plugins/custom-definesandincludes/kcm_widget/parserwidget.cpp index 6ccb46ccb5..a39f03e565 100644 --- a/plugins/custom-definesandincludes/kcm_widget/parserwidget.cpp +++ b/plugins/custom-definesandincludes/kcm_widget/parserwidget.cpp @@ -57,6 +57,8 @@ QString languageDefaultStandard(Utils::LanguageType langu= ageType) return QStringLiteral("c++11"); case Utils::ObjC: return QStringLiteral("c99"); + case Utils::ObjCpp: + return QStringLiteral("c++11"); case Utils::Other: break; }