1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +02:00
cdt/core
Marc-Andre Laperle cb0797481f Bug 566918 - [C++17] Support for __has_include (standard) and
__has_include_next (extension)

__has_include evaluates whether of the header name passed as parameter
exists. This can only be evaluated as part of a #if directive.
Interestingly, it also has to be reported as defined, i.e. #if
defined(__has_include) or #ifdef. In order to report this as defined,
this implementation adds it as a macro but during macro expansion, it's
actually converted as a dedicated token type. Then this token gets
evaluated during normal preprocessor expression evaluation.

In order to parse header names, there were several options. The main
problem is that header tokens (tQUOTE_HEADER_NAME, tSYSTEM_HEADER_NAME)
are actually produced by the Lexer as part of a special mode
(setInsideIncludeDirective) set during the handling of #include. For
expression evaluation, the tokens are already generated without
setInsideIncludeDirective therefore we only have plain string
and < > tokens.

One approach would be to generate header tokens "earlier" than executing
we need to track a new state while fetching token to configure the Lexer
(setInsideIncludeDirective) when in the context of an __has_include.
There are also complications due to macro expansion within the
__has_include where after one expansion, we don't have a lexer in the
context anymore, introducing more changes.

Another approach would be to remove the Header token creation from the
Lexer itself and let the preprocessor assemble the tokens into an header
string, in both cases of #include and __has_include. This mostly works
and is the approach used in Clang, but the problem is that whereas Clang
keeps track of leading spaces of tokens, CDT doesn't. This means with
such change that CDT would now allow #include <  iostream  > (notice the
white space). I think this is too big of a downside and also too big of
a change to introduce this handling of whitespace at the token level.

The approach used here is more conservative and isolated but also shares
less common logic with #include processing. The non-header token
(string, <, etc) are assembled into a header string only in the case of
a __has_include. So a downside will be that #include and __has_include
will be inconsistent in regards of leading/trailing space parsing but I
feel like this is better than making #include more permissive.

Change-Id: I5b9f5c616c8d999e0c916a85b41f96e20037b651
Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com>
2020-09-27 15:12:52 -04:00
..
org.eclipse.cdt.core Bug 566918 - [C++17] Support for __has_include (standard) and 2020-09-27 15:12:52 -04:00
org.eclipse.cdt.core.linux Bug 566511: [releng] Add missing UTF-8 encoding for all CDT projects 2020-08-30 20:02:41 -04:00
org.eclipse.cdt.core.linux.aarch64 Bug 565836: Include plugin.properties properly for aarch64 2020-09-01 07:39:58 -04:00
org.eclipse.cdt.core.linux.ppc64le Bug 521515: Build ppc64le libraries on HIPP 2020-09-02 20:27:03 -04:00
org.eclipse.cdt.core.linux.x86_64 Bug 566511: [releng] Add missing UTF-8 encoding for all CDT projects 2020-08-30 20:02:41 -04:00
org.eclipse.cdt.core.macosx Bug 566511: [releng] Add missing UTF-8 encoding for all CDT projects 2020-08-30 20:02:41 -04:00
org.eclipse.cdt.core.native Bug 521515: Build ppc64le libraries on HIPP 2020-09-02 20:27:03 -04:00
org.eclipse.cdt.core.tests Bug 566918 - [C++17] Support for __has_include (standard) and 2020-09-27 15:12:52 -04:00
org.eclipse.cdt.core.win32 Bug 566511: [releng] Add missing UTF-8 encoding for all CDT projects 2020-08-30 20:02:41 -04:00
org.eclipse.cdt.core.win32.x86_64 Bug 566511: [releng] Add missing UTF-8 encoding for all CDT projects 2020-08-30 20:02:41 -04:00
org.eclipse.cdt.ui Bug 546610: fix writeaccess_highlight color in dark theme 2020-09-07 10:55:00 -04:00
org.eclipse.cdt.ui.tests Bug 566918 - [C++17] Support for __has_include (standard) and 2020-09-27 15:12:52 -04:00
pom.xml [releng] Bump version to 10.0.0 2020-04-11 17:46:58 -04:00