Differential D15764 Diff 42359 plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
Changeset View
Changeset View
Standalone View
Standalone View
plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 42 | switch (type) { | |||
---|---|---|---|---|---|
45 | case Utils::Cpp: | 45 | case Utils::Cpp: | ||
46 | return QStringLiteral("-xc++"); | 46 | return QStringLiteral("-xc++"); | ||
47 | case Utils::OpenCl: | 47 | case Utils::OpenCl: | ||
48 | return QStringLiteral("-xcl"); | 48 | return QStringLiteral("-xcl"); | ||
49 | case Utils::Cuda: | 49 | case Utils::Cuda: | ||
50 | return QStringLiteral("-xcuda"); | 50 | return QStringLiteral("-xcuda"); | ||
51 | case Utils::ObjC: | 51 | case Utils::ObjC: | ||
52 | return QStringLiteral("-xobjective-c"); | 52 | return QStringLiteral("-xobjective-c"); | ||
53 | case Utils::ObjCpp: | ||||
54 | return QStringLiteral("-xobjective-c++"); | ||||
53 | default: | 55 | default: | ||
54 | Q_UNREACHABLE(); | 56 | Q_UNREACHABLE(); | ||
55 | } | 57 | } | ||
56 | } | 58 | } | ||
57 | 59 | | |||
58 | QString languageStandard(const QString& arguments) | 60 | QString languageStandard(const QString& arguments, Utils::LanguageType type) | ||
59 | { | 61 | { | ||
60 | // TODO: handle -ansi flag: In C mode, this is equivalent to -std=c90. In C++ mode, it is equivalent to -std=c++98. | 62 | // TODO: handle -ansi flag: In C mode, this is equivalent to -std=c90. In C++ mode, it is equivalent to -std=c++98. | ||
61 | const QRegularExpression regexp(QStringLiteral("-std=(\\S+)")); | 63 | const QRegularExpression regexp(QStringLiteral("-std=(\\S+)")); | ||
62 | auto result = regexp.match(arguments); | 64 | auto result = regexp.match(arguments); | ||
63 | if (result.hasMatch()) | 65 | if (result.hasMatch()) | ||
64 | return result.captured(0); | 66 | return result.captured(0); | ||
65 | 67 | | |||
66 | // no -std= flag passed -> assume c++11 | 68 | // no -std= flag passed -> assume c++11 | ||
67 | return QStringLiteral("-std=c++11"); | 69 | return (type == Utils::Cpp || type == Utils::ObjCpp) ? QStringLiteral("-std=c++11") : QStringLiteral(""); | ||
aaronpuchert: Does ObjC++ not have a `-std=` flag? | |||||
Why do you ask, it's getting -std=c++11 here (if no -std flag was given yet)? rjvbb: Why do you ask, it's getting `-std=c++11` here (if no -std flag was given yet)? | |||||
Now that we pass in the language type, maybe we should handle all cases. So for C and ObjC we don't want to return an empty string, but (say) -std=c99. Maybe we can make this match the default arguments in plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp. aaronpuchert: Now that we pass in the language type, maybe we should handle all cases. So for `C` and `ObjC`… | |||||
Done. You know I dislike multiple exit points but for you I avoided a temp. var and as many kinda superfluous breaks ;) rjvbb: Done. You know I dislike multiple exit points but for you I avoided a temp. var and as many… | |||||
68 | } | 70 | } | ||
69 | 71 | | |||
70 | } | 72 | } | ||
71 | 73 | | |||
72 | Defines GccLikeCompiler::defines(Utils::LanguageType type, const QString& arguments) const | 74 | Defines GccLikeCompiler::defines(Utils::LanguageType type, const QString& arguments) const | ||
73 | { | 75 | { | ||
74 | auto& data = m_definesIncludes[arguments]; | 76 | auto& data = m_definesIncludes[arguments]; | ||
75 | if (!data.definedMacros.isEmpty() ) { | 77 | if (!data.definedMacros.isEmpty() ) { | ||
76 | return data.definedMacros; | 78 | return data.definedMacros; | ||
77 | } | 79 | } | ||
78 | 80 | | |||
aaronpuchert: I think this could be `Q_UNREACHABLE()`. | |||||
79 | // #define a 1 | 81 | // #define a 1 | ||
80 | // #define a | 82 | // #define a | ||
81 | QRegExp defineExpression(QStringLiteral("#define\\s+(\\S+)(?:\\s+(.*)\\s*)?")); | 83 | QRegExp defineExpression(QStringLiteral("#define\\s+(\\S+)(?:\\s+(.*)\\s*)?")); | ||
82 | 84 | | |||
83 | const auto rt = ICore::self()->runtimeController()->currentRuntime(); | 85 | const auto rt = ICore::self()->runtimeController()->currentRuntime(); | ||
84 | QProcess proc; | 86 | QProcess proc; | ||
85 | proc.setProcessChannelMode( QProcess::MergedChannels ); | 87 | proc.setProcessChannelMode( QProcess::MergedChannels ); | ||
86 | 88 | | |||
87 | // TODO: what about -mXXX or -target= flags, some of these change search paths/defines | 89 | // TODO: what about -mXXX or -target= flags, some of these change search paths/defines | ||
88 | const QStringList compilerArguments{ | 90 | const QStringList compilerArguments{ | ||
89 | languageOption(type), | 91 | languageOption(type), | ||
90 | languageStandard(arguments), | 92 | languageStandard(arguments, type), | ||
91 | QStringLiteral("-dM"), | 93 | QStringLiteral("-dM"), | ||
92 | QStringLiteral("-E"), | 94 | QStringLiteral("-E"), | ||
93 | QStringLiteral("-"), | 95 | QStringLiteral("-"), | ||
94 | }; | 96 | }; | ||
95 | proc.setStandardInputFile(QProcess::nullDevice()); | 97 | proc.setStandardInputFile(QProcess::nullDevice()); | ||
96 | proc.setProgram(path()); | 98 | proc.setProgram(path()); | ||
97 | proc.setArguments(compilerArguments); | 99 | proc.setArguments(compilerArguments); | ||
98 | rt->startProcess(&proc); | 100 | rt->startProcess(&proc); | ||
Show All 40 Lines | 124 | { | |||
139 | // /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward | 141 | // /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward | ||
140 | // /usr/local/include | 142 | // /usr/local/include | ||
141 | // /usr/lib/gcc/i486-linux-gnu/4.1.2/include | 143 | // /usr/lib/gcc/i486-linux-gnu/4.1.2/include | ||
142 | // /usr/include | 144 | // /usr/include | ||
143 | // End of search list. | 145 | // End of search list. | ||
144 | 146 | | |||
145 | const QStringList compilerArguments{ | 147 | const QStringList compilerArguments{ | ||
146 | languageOption(type), | 148 | languageOption(type), | ||
147 | languageStandard(arguments), | 149 | languageStandard(arguments, type), | ||
148 | QStringLiteral("-E"), | 150 | QStringLiteral("-E"), | ||
149 | QStringLiteral("-v"), | 151 | QStringLiteral("-v"), | ||
150 | QStringLiteral("-"), | 152 | QStringLiteral("-"), | ||
151 | }; | 153 | }; | ||
152 | 154 | | |||
153 | proc.setStandardInputFile(QProcess::nullDevice()); | 155 | proc.setStandardInputFile(QProcess::nullDevice()); | ||
154 | proc.setProgram(path()); | 156 | proc.setProgram(path()); | ||
155 | proc.setArguments(compilerArguments); | 157 | proc.setArguments(compilerArguments); | ||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |
Does ObjC++ not have a -std= flag?