Commit Graph

53 Commits

Author SHA1 Message Date
Leandro Melo
d1b65bbf83 C++: Discard comments in macro definitions
Task-number: QTCREATORBUG-7815

Change-Id: Id3e6b018bfd58b0f0072c637d69721a4bde1603a
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
2012-09-05 16:35:33 +02:00
Leandro Melo
d87835cc90 C++: Always skip unknown preprocessor "directives"
Task-number: QTCREATORBUG-7780

Change-Id: Ie93704feff17ad8229e50fb1133048f2c7598dea
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: hjk <qthjk@ovi.com>
2012-08-29 16:07:40 +02:00
Leandro Melo
009d6b1e2f C++: Handle C++ style comments in macro expansion
Notice that a similar problem still exists for which we
need to fix the lexer when there's a C style commend which
 ends with a backslash-newline.

Task-number: QTCREATORBUG-7713

Change-Id: I0f6d561703984f917fa5ed29de020ad0bdc5aaf0
Reviewed-by: David Schulz <david.schulz@nokia.com>
Reviewed-by: hjk <qthjk@ovi.com>
2012-08-23 15:00:53 +02:00
Leandro Melo
b53d562816 C++: Take multiline strings into account when preprocessing
It was creating extra line(s)...

Change-Id: If28a9ccf16195c71747479db838a5589ea6683a0
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-08-23 14:35:53 +02:00
Christian Kamm
41e140da04 C++: Fix line number information after multiline comments.
Task-number: QTCREATORBUG-7702
Change-Id: I0ec2e1eb9bf1c556b0a426d4405df1c48b5653ed
Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
2012-08-07 11:31:06 +02:00
Eike Ziller
e0e8cf3ada Contact -> qt-project.org
Change-Id: I7134d7de30bcf9f9dcfad42520dd45ee083a852d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
2012-07-19 13:23:21 +02:00
Leandro Melo
d6ccffc06c C++: Core changes in preprocessing
Summary of most relevant items:

- Preprocessor output format change. No more gen true/false. Instead
  a more intuitive and natural expansion (like from a real compiler) is
  performed directly corresponding to the macro invocation. Notice that
  information about the generated tokens is not lost, because it's now
  embedded in the expansion section header (in terms of lines and columns
  as explained in the code). In addition the location on where the macro
  expansion happens is also documented for future use.

- Fix line control directives and associated token line numbers.
  This was not detected in tests cases because some of them were
  actually wrong: Within expansions the line information was being
  considered as originally computed in the macro definition, while
  the desired and expected for Creator's reporting mechanism (just
  like regular compilers) is the line from the expanded version
  of the tokens.

- Do not allow for eager expansion. This was previously being done
  inside define directives. However, it's not allowed and might
  lead to incorrect results, since the argument substitution should
  only happen upon the macro invocation (and following nested ones).
  At least GCC and clang are consistent with that. See test case
  tst_Preprocessor:dont_eagerly_expand for a detailed explanation.

- Revive the 'expanded' token flag. This is used to mark every token
  that originates from a macro expansion. Notice, however, that
  expanded tokens are not necessarily generated tokens (although
  every generated token is a expanded token). Expanded tokens that
  are not generated are those which are still considered by our
  code model features, since they are visible on the editor. The
  translation unit is smart enough to calculate line/column position
  for such tokens based on the information from the expansion section
  header.

- How expansions are tracked has also changed. Now, we simply add
  two surrounding marker tokens to each "top-level" expansion
  sequence. There is an enumeration that control expansion states.
  Also, no "previous" token is kept around.

- Preprocessor client methods suffered a change in signature so
  they now receive the line number of the action in question as
  a paramater. Previously such line could be retrieved by the client
  implementation by accessing the environment line. However, this
  is not reliable because we try to avoid synchronization of the
  output/environment lines in order to avoid unnecessary output,
  while expanding macros or handling preprocessor directives.

- Although macros are not expanded during define directives (as
  mentioned above) the preprocessor client is now "notified"
  when it sees a macro. This is to allow usage tracking.

- Other small stuff.

This is all in one patch because the fixes are a consequence
of the change in preprocessing control.

Change-Id: I8f4c6e6366f37756ec65d0a93b79f72a3ac4ed50
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-06-25 15:49:27 +02:00
Leandro Melo
9daa34003d Revert "C++: Re-enable macro definition line test"
This reverts commit 44d8e7bef7.

The original test case was actually right. I guess I was mislead
by the recently added preprocessor tests, which are the ones
that should be corrected (together with the preprocessor, which
seems to have issues with # lineno generation).

Conflicts:

	tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp

Change-Id: I47f82ed23a37086d0d81c4b3ea2cac48fb753451
Reviewed-by: hjk <qthjk@ovi.com>
Reviewed-by: Francois Ferrand <thetypz@gmail.com>
2012-06-19 12:47:52 +02:00
Leandro Melo
f978400ae5 C++: Better handling of arg count mismatch in macros
Do not expand function-like macros at all when there's a mismatch
in the parameter/argument count.

The report below raises the issue but its expected result is not
correct. This would be the more appropriate fix.

Task-number: QTCREATORBUG-7225
Change-Id: Ide8580faa7b724d3e8b396ec1f899cc5ca7f9e7e
Reviewed-by: hjk <qthjk@ovi.com>
2012-06-19 12:47:44 +02:00
Leandro Melo
2af60cb1bf C++: Track macro argument reference even when empty
Change-Id: I6d226b4e42f94ebee41d012050c5109895f0c432
Reviewed-by: hjk <qthjk@ovi.com>
2012-06-12 18:10:56 +02:00
Leandro Melo
d90264d6c2 C++: Also expand first token after macro define
It was previously beeing skipped.

Change-Id: Iadd9b03acbcf0ee0fb4db537b8597661cb93af3f
Reviewed-by: hjk <qthjk@ovi.com>
2012-06-05 15:05:19 +02:00
Leandro Melo
ca7ac8c035 C++: Fix macro uses line info
Make sure the environment line is consistent during preprocessor
directives and identifier handling so clients can rely on consistent
information. Particularly important for macro usages.

New tests also added.

Change-Id: I962a39a86cd17b8d945d2959c2c95e2d258ea3e6
Reviewed-by: hjk <qthjk@ovi.com>
2012-06-01 14:28:03 +02:00
Leandro Melo
44d8e7bef7 C++: Re-enable macro definition line test
I believe those were actually incorrect, since the # mark
from the generated tokens `int f` should be relative to <stdin>
on the line they are defined, which is 1.

Change-Id: I663ef49ad75eb8bb0a4a4b18d4899a952011536c
Reviewed-by: Francois Ferrand <thetypz@gmail.com>
Reviewed-by: hjk <qthjk@ovi.com>
2012-05-31 18:02:08 +02:00
hjk
6d04f3ce25 preprocessor: do not loop endlessly on incomplete expressions
An missing closing parantheses after "defined(..." caused an endless loop.

Change-Id: I19b17cebc1a56880216c3bfb67c9d296f80cc064
Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
2012-05-30 13:34:38 +02:00
hjk
b13519d547 preprocessor: add an example of a macro that generates code
Change-Id: I902ebd73e039b8c3f44eca456be87809d1e1d3a4
Reviewed-by: hjk <qthjk@ovi.com>
2012-05-15 18:19:54 +02:00
hjk
2521d7d6e4 preprocessor: add (failing) test for concatenation
Change-Id: I9d51798cb4d95141d30b0609d03cd1d199088f0a
Reviewed-by: hjk <qthjk@ovi.com>
2012-04-27 17:25:30 +02:00
hjk
051c33517f preprocessor test: code cosmetics
Change-Id: I67367e501c8f19cee9023e3782c6a9175b49c6c6
Reviewed-by: hjk <qthjk@ovi.com>
2012-04-27 17:25:00 +02:00
hjk
bc01283481 preprocessor: add test cases for <=, == and >=
Change-Id: I126143daeb572a555b73dc33ad7996b22c1387f8
Reviewed-by: hjk <qthjk@ovi.com>
2012-04-26 08:48:52 +02:00
hjk
feba990f6e preprocessor: swallow ) after defined(...
Task-number: QTCREATORBUG-7256
Change-Id: I6149e56e5f50f75c9e039be9c162036a3890e2d7
Reviewed-by: David Schulz <david.schulz@nokia.com>
Reviewed-by: hjk <qthjk@ovi.com>
2012-04-25 13:41:51 +02:00
hjk
7f1f282111 preprocessor: some code style in auto test
Change-Id: I1381ce17098a87dbc3924dc86902d7cc1b1eec76
Reviewed-by: hjk <qthjk@ovi.com>
2012-04-25 09:30:34 +02:00
Erik Verbruggen
bd47622183 Fix out-of-memory crash when indenting generated tokens.
Generated tokens do not have a position in any source file, so not try
to indent them. Previously, the 'source' used was the scratch buffer,
which would not contain newlines, so the indent depth would be the
length of the scratch buffer at that point.

Task-number: QTCREATORBUG-7262
Change-Id: If94213d6dffd13dd2b47c7038ec2398ad925d904
Reviewed-by: Yuchen Deng <loaden@gmail.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
2012-04-23 11:06:35 +02:00
hjk
6d393252c4 preprocessor: rename operator() into run.
Easier to follow.

Change-Id: I6da1ca862ddb7048a6d16bf5e6ea18d6b2cfc7f8
Reviewed-by: hjk <qthjk@ovi.com>
2012-04-19 19:37:14 +02:00
hjk
538901d441 preprocessor: make Preprocessor::preprocess private
Change-Id: Ic81e3ebec1b42ae0698a340ee7e1c711225c1162
Reviewed-by: hjk <qthjk@ovi.com>
2012-04-19 18:47:03 +02:00
hjk
acf6f8f0cb preprocessor: make Environment::{resolve,remove} work on ByteArrayRefs only
Change-Id: Idb93d359bd45696a38cb863dcea30c5c377eeabb
Reviewed-by: hjk <qthjk@ovi.com>
2012-04-19 18:41:18 +02:00
hjk
3428240233 preprocessor: add autotest for defined(...) and undefined(...)
Change-Id: I7c843a449bb6db348ab374b4bd2c378b797b94cd
Reviewed-by: hjk <qthjk@ovi.com>
2012-04-19 18:38:00 +02:00
hjk
37e3853090 preprocessor tests: compile fix
Change-Id: Iab9fb8ecbad94e08d39b6fad60caaf98a85d5980
Reviewed-by: hjk <qthjk@ovi.com>
2012-04-17 09:40:34 +02:00
Francois Ferrand
68471c2100 Preprocessor: fix macro definition line.
The line corresponding to the macro definition is simply the token's
line. This caused errors in the macro definitions, since there were
multiple macros defined on the same line of the same file.

Task-number: QTCREATORBUG-7217
Change-Id: I56d17eeba677ac51f9eed283c0e964019bdfe4b7
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-04-02 17:01:52 +02:00
Francois Ferrand
1a10bcdaad Add test case to preprocessor.
- This enables some tests which had been unexpectedly disabled in
earlier test.
- Tests to show issue QTCREATORBUG-7225.
- Tests which validates somehow behavior of preprocessor for
QTCREATORBUG-7217: the test passes, so the problem is likely not in the
startExpandingMacro() notification.

Change-Id: Ib7c1433e4dcdd8c1d19fa117371f94c1645ec3fb
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-04-02 15:16:25 +02:00
Francois Ferrand
332072019a Preprocessor: Fix client notification.
- Notify end of macro if function expansion is skipped.
- Do not notify client of generated macros expansion.

Change-Id: Ic027fc13ee391425a5ebadc8e84b9305912dbcf0
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-04-02 13:49:00 +02:00
Erik Verbruggen
ff0a465403 [C++] Always output a #line as first line of the pp output.
Change-Id: I60d25109ae8fe3628b1899078a21010263787c33
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-03-30 13:24:36 +02:00
Erik Verbruggen
2a74097b54 Fix #include MACRO_NAME.
Change-Id: Id1c4046d028ad26d17b28feb53a832f3b48363f1
Reviewed-by: Erik Verbruggen <erik.verbruggen@nokia.com>
2012-03-29 17:17:00 +02:00
Erik Verbruggen
60db573660 [C++] Rewrite of the preprocessor.
This rewrite fixes a couple of issues with the pre-processor. It now
supports:
- macros in macro bodies
- stringification of parameters [cpp.stringize]
- the concatenation operator [cpp.concat]
- #include MACRO_HERE
- defined() inside macro bodies used in pp-conditions.

Change-Id: Ifdb78041fb6afadf44f939a4bd66ce2832b8601f
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-03-29 14:28:17 +02:00
Francois Ferrand
2386d701b6 Preprocessor: fix line for generated code.
The macro used to be at the same line as the first token after the
closing parenthesis.

Change-Id: I4c2d7317632baf612900e84572017aeb247d0585
Reviewed-by: Erik Verbruggen <erik.verbruggen@nokia.com>
2012-03-19 10:48:43 +01:00
Francois Ferrand
558b6e08ae Preprocessor: fix expanding macro arguments.
Expanding macro arguments can add or remove argument for a nested macro,
so the actual parameters list was not correct.

Also, remove unused arguments reference list and reserve space for the
expected number of arguments.

Change-Id: I4cf369cbb3909927c6bf65750bd715fa6f070fad
Reviewed-by: Erik Verbruggen <erik.verbruggen@nokia.com>
2012-03-19 10:35:21 +01:00
Francois Ferrand
3e9105e401 Preprocessor: fix handling of first empty argument.
First empty argument used to be dropped: e.g. MACRO(,test) would be
expanded with one parameter only, with value 'test'.

Change-Id: I693fbb7faf1360f62266fa04c4b39c2de0d159a7
Reviewed-by: Erik Verbruggen <erik.verbruggen@nokia.com>
2012-03-19 10:33:14 +01:00
Francois Ferrand
ffd58c577a Preprocessor: Handle variadic arguments (__VA_ARGS__).
Change-Id: I69aa6c5e01ea97a4413f77f20ebbb4d4beb971aa
Reviewed-by: Erik Verbruggen <erik.verbruggen@nokia.com>
2012-03-19 10:31:09 +01:00
Erik Verbruggen
3a231e734c Cleanup testcase.
Change-Id: I3db86fa5df4a2747f4c24e0414279dab59098c54
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-03-13 12:00:43 +01:00
Erik Verbruggen
a621c99a0f [C++] Add error recovery for namespace declarations.
Change-Id: I884ff9901c95467524e5eba38e91f75992d30e14
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Reviewed-by: Flex Ferrum <flexferrum@gmail.com>
2012-02-28 10:22:31 +01:00
hjk
2931a499e6 Long live the king!
Change-Id: I2b72b34c0cfeafc8bdbaf49b83ff723544f2b6e2
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
2012-01-26 19:55:36 +01:00
hjk
31600758de all: s/info@qt.nokia.com/qt-info@nokia.com/
Change-Id: If18afb5d4665924e7d9250dccbc60a65e6daa75e
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
2011-11-03 10:33:19 +01:00
Erik Verbruggen
b3237d7d42 Fixed (C)opyright headers.
Change-Id: I755bdd1788770b7edd34f06372219d27abd0af11
Reviewed-on: http://codereview.qt.nokia.com/1214
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
2011-07-06 11:57:21 +02:00
hjk
8397663964 Update license. 2011-04-13 11:49:28 +02:00
Bill King
3593fe08ae tests: add licence headers 2011-02-18 14:48:16 +01:00
Bill King
524a9ac4a8 tests: more test project cleanup 2010-10-21 14:49:58 +10:00
Bill King
1f0b600b82 Autotests: More cleanup of tests, and initial marking of components belonged to. 2010-09-02 15:32:04 +10:00
Bill King
f823c4810e Add "make check" support to testcase makefiles. 2010-07-13 11:59:37 +10:00
Erik Verbruggen
9806b1e165 Fixed pre-precessor bug.
When a PP line ended with a \ (join line) and the next line was empty
(ending th joining), the following token would be incorrectly marked as
joined.

Done-with: Roberto Raggi
2010-02-10 11:07:18 +01:00
Roberto Raggi
8ef85c6489 Removed obsoleted test. 2009-10-27 11:05:35 +01:00
Roberto Raggi
485dec6d2b Link with cplusplus library. 2009-10-26 14:40:36 +01:00
Roberto Raggi
e6d0f2ca0c Fixed the auto tests. 2009-06-19 11:19:56 +02:00