fix # 11/ Read include paths from both C and C++ language settings - #30
fix # 11/ Read include paths from both C and C++ language settings#30davidramnero wants to merge 3 commits into
Conversation
| */ | ||
| protected Collection<File> getIncludes(boolean onlyUserDefined) { | ||
| Collection<File> paths = new LinkedList<File>(); | ||
| Collection<File> paths = new LinkedHashSet<File>(); |
There was a problem hiding this comment.
to avoid duplicates if same includes are added in both c and c++ language settings
| private final IProject project; | ||
| private final IWorkspaceRoot root; | ||
| private static final String GCC_LANGUAGE_ID = "org.eclipse.cdt.core.gcc"; | ||
| private static final String GPP_LANGUAGE_ID = "org.eclipse.cdt.core.g++"; |
There was a problem hiding this comment.
hmm this does not feel rock solid to me. eclipse can use different compilers, not just gcc/g++. is it specified somewhere that getLanguageId only returns these strings for C/C++ code?
There was a problem hiding this comment.
btw the old code to compare the extension is not rock solid neither.
| } | ||
| for (ICLanguageSetting ls : allLanguageSettings) { | ||
| String id = ls.getLanguageId(); | ||
| if (GCC_LANGUAGE_ID.equals(id) || GPP_LANGUAGE_ID.equals(id)) { |
There was a problem hiding this comment.
if the file to analyze is a C file then it would be preferable to not use GPP settings. how doable would that be?
If neither GCC_LANGUAGE_ID nor GPP_LANGUAGE_ID is found but another compiler is used.. an idea could be to load all the include paths from all language settings?
There was a problem hiding this comment.
it's a good idea, I'll see what I can do
There was a problem hiding this comment.
The whole plugin seems to be built around analyzing a whole project in a batch, so it would probably require some serious re-design to achieve this
| private final IWorkspaceRoot root; | ||
| private static final String[] C_EXTENSIONS = { "c" }; | ||
| private static final String[] CPP_EXTENSIONS = { | ||
| "cpp", "cxx", "cc", "c++", "ccm", "cxxm", "c++m" |
There was a problem hiding this comment.
these are the corresponding data in cppcheck source code:
static const std::unordered_set<std::string> cpp_src_exts = {
".cpp", ".cxx", ".cc", ".c++", ".tpp", ".txx", ".ipp", ".ixx"
};
static const std::unordered_set<std::string> c_src_exts = {
".c", ".cl"
};
The extension ".C" is also common but it's often used for both C and C++ code
There was a problem hiding this comment.
we compare case insensitively so we will catch .C
Addressing: #11
The plugin already scans language settings for includes, but previously it only read in settings for c++ projects, i.e. include paths configured for c projects were ignored. This is now fixed.