|
39 | 39 | #include "timer.h" |
40 | 40 | #include "utils.h" |
41 | 41 |
|
| 42 | +#include "frontend.h" |
| 43 | + |
42 | 44 | #include <algorithm> |
43 | 45 | #include <cassert> |
44 | 46 | #include <climits> |
@@ -221,40 +223,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[]) |
221 | 223 |
|
222 | 224 | mFileSettings.clear(); |
223 | 225 |
|
224 | | - if (mSettings.enforcedLang != Standards::Language::None) |
225 | | - { |
226 | | - // apply enforced language |
227 | | - for (auto& fs : fileSettings) |
228 | | - { |
229 | | - if (mSettings.library.markupFile(fs.filename())) |
230 | | - continue; |
231 | | - fs.file.setLang(mSettings.enforcedLang); |
232 | | - } |
233 | | - } |
234 | | - else |
235 | | - { |
236 | | - // identify files |
237 | | - for (auto& fs : fileSettings) |
238 | | - { |
239 | | - if (mSettings.library.markupFile(fs.filename())) |
240 | | - continue; |
241 | | - assert(fs.file.lang() == Standards::Language::None); |
242 | | - bool header = false; |
243 | | - fs.file.setLang(Path::identify(fs.filename(), mSettings.cppHeaderProbe, &header)); |
244 | | - // unknown extensions default to C++ |
245 | | - if (!header && fs.file.lang() == Standards::Language::None) |
246 | | - fs.file.setLang(Standards::Language::CPP); |
247 | | - } |
248 | | - } |
249 | | - |
250 | | - // enforce the language since markup files are special and do not adhere to the enforced language |
251 | | - for (auto& fs : fileSettings) |
252 | | - { |
253 | | - if (mSettings.library.markupFile(fs.filename())) { |
254 | | - assert(fs.file.lang() == Standards::Language::None); |
255 | | - fs.file.setLang(Standards::Language::C); |
256 | | - } |
257 | | - } |
| 226 | + frontend::applyLang(fileSettings, mSettings, mEnforcedLang); |
258 | 227 |
|
259 | 228 | // sort the markup last |
260 | 229 | std::copy_if(fileSettings.cbegin(), fileSettings.cend(), std::back_inserter(mFileSettings), [&](const FileSettings &fs) { |
@@ -324,14 +293,14 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[]) |
324 | 293 | files = std::move(filesResolved); |
325 | 294 | } |
326 | 295 |
|
327 | | - if (mSettings.enforcedLang != Standards::Language::None) |
| 296 | + if (mEnforcedLang != Standards::Language::None) |
328 | 297 | { |
329 | 298 | // apply enforced language |
330 | 299 | for (auto& f : files) |
331 | 300 | { |
332 | 301 | if (mSettings.library.markupFile(f.path())) |
333 | 302 | continue; |
334 | | - f.setLang(mSettings.enforcedLang); |
| 303 | + f.setLang(mEnforcedLang); |
335 | 304 | } |
336 | 305 | } |
337 | 306 | else |
@@ -985,9 +954,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a |
985 | 954 | } |
986 | 955 |
|
987 | 956 | if (str == "c") |
988 | | - mSettings.enforcedLang = Standards::Language::C; |
| 957 | + mEnforcedLang = Standards::Language::C; |
989 | 958 | else if (str == "c++") |
990 | | - mSettings.enforcedLang = Standards::Language::CPP; |
| 959 | + mEnforcedLang = Standards::Language::CPP; |
991 | 960 | else { |
992 | 961 | mLogger.printError("unknown language '" + str + "' enforced."); |
993 | 962 | return Result::Fail; |
|
0 commit comments