Parse C files in C mode
ClosedPublic

Authored by skalinichev on Mar 2 2016, 8:18 AM.

Details

Summary

Now there are 2 language profiles: one for C++, another one for C. The language type is determined by mime type.
Since *.h files used in C and C++, by default they are parsed in C++ mode, to change that behavior there is a "Parse *.h headers in plain C" check-box.

BUG: 357774
BUG: 357615
BUG: 57156

Diff Detail

Repository
R32 KDevelop
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
skalinichev updated this revision to Diff 2512.Mar 2 2016, 8:18 AM
skalinichev retitled this revision from to Parse C files in C mode.
skalinichev updated this object.
skalinichev edited the test plan for this revision. (Show Details)
skalinichev set the repository for this revision to R32 KDevelop.
skalinichev added a project: KDevelop.
skalinichev added subscribers: KDevelop, kdevelop-devel.
kfunk added a subscriber: kfunk.Mar 2 2016, 10:17 AM

Generally: Please rename "CPP" -> "Cpp" in variable names, etc.

languages/plugins/custom-definesandincludes/compilerprovider/compilerprovider.cpp
136

lt -> type or languageType

154

Code duplication, factor out functionality?

languages/plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp
85

Initialize in ctor?

languages/plugins/custom-definesandincludes/compilerprovider/settingsmanager.h
73

CPP -> Cpp

languages/plugins/custom-definesandincludes/definesandincludesmanager.cpp
292

I've seen this code snippet before :)

Please share code

kfunk requested changes to this revision.Mar 2 2016, 10:17 AM
kfunk added a reviewer: kfunk.

Forgot to say: Rest looks good to me, great work!

This revision now requires changes to proceed.Mar 2 2016, 10:17 AM
mwolff requested changes to this revision.Mar 2 2016, 10:47 AM
mwolff added a reviewer: mwolff.
mwolff added a subscriber: mwolff.

Excellent step towards the right direction - many thanks Sergey! I got some more nitpicks, once those and Kevin's are attended to I think we can merge this. Yay! Finally proper C support in KDevelop :)

languages/clang/tests/test_assistants.cpp
548 ↗(On Diff #2512)

unrelated change, should not be required

languages/clang/tests/test_duchain.cpp
1575

This should stay at .c. Actually, we should probably now run the test twice - once for .c and once for .cpp.

languages/plugins/custom-definesandincludes/compilerprovider/compilerprovider.cpp
136

and use auto on the lhs.

languages/plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp
61

this breaks backwards compatibility for those that already use the kdevelop 5 beta. could we stick to the old name for Cpp, and only introduce a new key for the two other args?

languages/plugins/custom-definesandincludes/compilerprovider/settingsmanager.h
40

indent

43

indent

languages/plugins/custom-definesandincludes/definesandincludesmanager.cpp
293

wrap literals with QLatin1String, use .compare with Qt::CaseInsensitive

305

auto args = m_settings->defaultParserArguments();
return lt == Utils::C ? args.cArguments : args.cppArguments;

languages/plugins/custom-definesandincludes/kcm_widget/parserwidget.cpp
94

using sender() is not so nice, please make this two distinct functions and connect them individually

languages/plugins/custom-definesandincludes/kcm_widget/parserwidget.ui
20

wrap the *.h in <code> or <tt> tags

With this patch I get
"warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]"
when parsing C files. Although innocuous, it would be nice not to have this warning being spammed.

skalinichev updated this revision to Diff 2598.Mar 7 2016, 6:46 AM
skalinichev edited edge metadata.
skalinichev marked 15 inline comments as done.

Address review issues.

With this patch I get
"warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]"
when parsing C files. Although innocuous, it would be nice not to have this warning being spammed.

I don't think it's related to this patch. You'll probably get the same warning even without it, e.g. if you change language profile to C. Adding -Wno-unused-command-line-argument to the parser arguments can be a solution here.

kfunk accepted this revision.Mar 7 2016, 7:41 AM
kfunk edited edge metadata.

Rest LGTM, great work!

languages/plugins/custom-definesandincludes/definesandincludesmanager.cpp
286

Nitpick: lt -> languageType

294

Nitpick: lt -> languageType

languages/plugins/custom-definesandincludes/kcm_widget/parserwidget.ui
44

Cpp -> Cpp

113

Cpp -> Cpp

This revision was automatically updated to reflect the committed changes.
kfunk added a comment.Mar 9 2016, 5:14 PM

Some more remarks

languages/plugins/custom-definesandincludes/kcm_widget/parserwidget.ui
176

Just noticed: That does not belong here, does it? We're in the C profile selection.

181

Dito

186

Dito

skalinichev added inline comments.Mar 10 2016, 6:09 PM
languages/plugins/custom-definesandincludes/kcm_widget/parserwidget.ui
176

Well, I actually think that it's quite useful. E.g. I've seen a couple of project that started as plain C, but with time were ported to C++, without changing file extensions.

So IMO it's ok to keep it here. Though I agree that it's not a common use case, and those items at least should be moved at the bottom of the list or masked otherwise...