summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus/pp-engine.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Revert "C++: Fix highlighting for lines with predefined macros"Nikolai Kosjar2013-12-031-10/+8
| | | | | | | | | | | | | | | | | | This takes too much memory. For qtcreator.pro the numbers are as follows: Patch applied: ~ 1600MB (RES) Patch reverted: ~ 510MB (RES) This reverts commit 4c2daa90ce558c3b4287edc97127471486a411d9. Task-number: QTCREATORBUG-10973 Change-Id: I843bd7c1ea4a26a1ec55ddc14c2a34a98d040922 Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: Robert Loehning <robert.loehning@digia.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* C++: Fix highlighting for lines with predefined macrosNikolai Kosjar2013-11-291-8/+10
| | | | | | | | | | | | | | This adds definitions for the macros __FILE__, __LINE__, __DATE__ and __TIME__ on demand. As a side effect, this also introduces highlighting for the uses of these macros. Task-number: QTCREATORBUG-8036 Change-Id: Ib7546c7d45d2eecbc50c7883fc684e3497154405 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
* Revert "Preprocessor Enginge: fix bug in pp-engine.cpp"Nikolai Kosjar2013-11-291-1/+43
| | | | | | | | | | Breaks highlighting for macros using the predefined macros. This reverts commit 1d834c1126dde58dd71e595b3f5e135cc0ca4dbd. Change-Id: Ic13c407e293a806a63ff30153864530df6a32e47 Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* Preprocessor Enginge: fix bug in pp-engine.cppSimon Schäfer2013-11-281-43/+1
| | | | | | | | | | | | | Preprocessor variables __LINE__,__FILE__,__TIME__,__DATE__ where destroying the following systems when affected variables were standing within the same line with those variables: * highlighting * refactoring * local renaming Task-number: QTCREATORBUG-8036 Change-Id: I1a4b919d15812872ca5a8e63b1031ec1ab144c22 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
* Rename "[Mm]ethod(s)" to "[Ff]unction(s)"Nikolai Kosjar2013-10-101-2/+2
| | | | | | | | | | | Only methods as programming functions are affected. Besides renaming some actions like "Switch Between Function Declaration/Definition" this mostly touches (api) code comments. This is a follow-up patch to commit 872bfb7. Change-Id: Icb65e8d73b59a022f8885b14df497169543a3b92 Reviewed-by: hjk <hjk121@nokiamail.com>
* Fix MSVC-64 warnings about size_t -> int truncations in C++-lib.Friedemann Kleint2013-09-121-6/+6
| | | | | Change-Id: Ibe6f41ac15df1ec685b0d0766ff568abf6f3ae7e Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
* Fix coding style for else statementsOrgad Shaneh2013-07-171-9/+6
| | | | | Change-Id: I1309db70e98d678e150388c76ce665e988fdf081 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
* C++: Fix preprocessor blocked macro bug.Erik Verbruggen2013-06-111-9/+5
| | | | | | | | | | | | | | | | By lexing the first token after a macro call (meaning: the token after the closing parenthesis (which was passed to handleFunctionLikeMacro which in turn pushed it back into the token buffer)), a token buffer might be popped, which unblocks the macro that generated the actual param pack. The effect was that if this happens in the expansion of a recursive macro (with parameters!), the preprocessor ended up in an infinite loop. Task-number: QTCREATORBUG-9015 Task-number: QTCREATORBUG-9447 Change-Id: I0d83c59188ec15c4a948970e9fa944a17d765475 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
* C++: fix Q_CREATOR_RUN macro handlingErik Verbruggen2013-06-031-4/+0
| | | | | | | | | Moved it from the handleIfDefDirective to the pre-defined macros, so that #if defined() can also see it. Task-number: QTCREATORBUG-9322 Change-Id: Icbecad5c885dd2374b559969c99631c3ddc73844 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
* C++: do not strip trailing newlines in the preprocessor output.Erik Verbruggen2013-05-301-15/+0
| | | | | | | | | | | | | Doing so resulted in an incorrect position for the EOF token when the preprocessed output would be parsed. That in turn leads to incorrect insertion positions for refactoring actions. This is especially true when a file contains only preprocessor directives: the EOF token would point to line 1 column 1, which is usually not the place where code should be inserted. Change-Id: I7d359aa7a6c04bc52c8b873fd49ad6afc3a77319 Reviewed-by: hjk <hjk121@nokiamail.com>
* Merge remote-tracking branch 'origin/2.7'Eike Ziller2013-04-301-0/+2
|\ | | | | | | | | | | | | Conflicts: src/plugins/qmldesigner/components/formeditor/abstractcustomtool.cpp Change-Id: I4e0a85795e7f4bfcdc21d106517517b527f85104
| * C++: fix handling of empty va_args macro arguments.Francois Ferrand2013-04-291-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | Preprocessor did not correctly handle when variadic macro arguments were not provided at all, if there were other arguments: macro was not expanded in case only the non variadic arguments were given. #define MACRO(...) used to work fine for 0 or more arguments. #define MACRO(ARG0, ...) used to work only for 2 or more arguments, now fixed. Change-Id: I64e9199ceccae05618a49931c2adad8e4f9471ba Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
* | C++: Use more direct approach to recognize special Qt tokenshjk2013-04-191-49/+59
| | | | | | | | | | Change-Id: I45399a196500cbc6aecedfaa94a50890914906f1 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* | C++: Streamline preprocessor expansion buffer handlinghjk2013-04-161-46/+19
| | | | | | | | | | Change-Id: If86c73945808e871f60fdf231b91e02f66bd1b32 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* | C++: Preprocessor output buffer is always presenthjk2013-04-161-37/+29
| | | | | | | | | | Change-Id: I896423172aed0e19feaaf9144ed5f18ba99c720b Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* | Merge remote-tracking branch 'origin/2.7'Eike Ziller2013-04-081-0/+1
|\ \ | |/ | | | | | | | | | | | | | | | | Conflicts: src/plugins/android/androidrunner.cpp src/plugins/clearcase/clearcasesync.cpp src/plugins/fakevim/fakevimhandler.cpp tests/auto/ioutils/ioutils.pro Change-Id: I31587b8a4dd6aacc1e76803159da51a972878370
| * C++: pre-allocate the output buffer.Erik Verbruggen2013-04-081-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This prevents a whole lot of re-allocations when the output byte array needs to grow. It also prevents some heap fragmentation for big files. Because the preprocessed output is short lived (it will be parsed immediately after, and then discarded), it is not squeezed to the minimal size. This would result in another allocation. Change-Id: I4974be5144f88cdfc4ddc9d8330200725aa90803 Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com>
* | fix include style relating to cplusplus librariesOswald Buddenhagen2013-04-031-5/+5
|/ | | | | | | | | | | ... and adjust INCLUDEPATH accordingly. while i'm at messing with include statements, also re-order the include blocks according to policy and sort them within bigger blocks. Change-Id: I7762abfd7c4ecf59432b99db2f424e4fa25733a5 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com>
* Fix warnings introduced by reordering member variablesTobias Hunger2013-02-221-2/+2
| | | | | Change-Id: I37bc8f9bc874de52281b8597838ef8addae1a1a3 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
* Merge remote-tracking branch 'origin/2.6'Oswald Buddenhagen2013-01-311-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/plugins/autotoolsprojectmanager/AutotoolsProjectManager.pluginspec.in src/plugins/debugger/qtmessageloghandler.cpp src/plugins/debugger/qtmessagelogwindow.cpp src/plugins/madde/maemodeployconfigurationwidget.cpp src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp src/plugins/qmldesigner/designercore/include/widgetqueryview.h src/plugins/qmldesigner/designercore/metainfo/metainfoparser.cpp src/plugins/qmldesigner/designercore/model/modelnodecontextmenu.cpp src/plugins/qmldesigner/designercore/model/modelnodecontextmenu.h src/plugins/qmlprojectmanager/qmlprojectapplicationwizard.cpp src/plugins/qnx/bardescriptormagicmatcher.h src/plugins/qt4projectmanager/profilekeywords.cpp src/plugins/remotelinux/deployablefilesperprofile.cpp src/plugins/remotelinux/deployablefilesperprofile.h src/plugins/remotelinux/deploymentinfo.cpp src/plugins/remotelinux/deploymentsettingsassistant.cpp src/plugins/remotelinux/profilesupdatedialog.cpp tests/auto/icheckbuild/ichecklib.cpp tests/auto/icheckbuild/parsemanager.cpp tests/auto/icheckbuild/parsemanager.h Change-Id: Ie465a578446a089e1c502d1cb1096e84ca058104
| * Incremented year in copyright infov2.6.2Robert Loehning2013-01-291-1/+1
| | | | | | | | | | Change-Id: Ic6a9ff0359625021ebc061d22db6811814534205 Reviewed-by: Kai Koehne <kai.koehne@digia.com>
* | C++: add include-guard tracking.Erik Verbruggen2013-01-181-36/+137
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Track the typical #ifndef/#define/#endif usage in header files to see if the macro is an include guard. If so, store it in the Document. No behavioural change, just recording the name. This can be used in the future to track if a file needs to be re-parsed when a macro changes: if it was used in the file, and not defined in it nor being the include-guard, a file should be re-preprocessed and re-parsed. It can also be used to check if two files have the same include guard. Change-Id: I2715f529997a7b24a11bdbc6150652e2669f1a46 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
* | C++: fix macro calls with comment before argumentsFrancois Ferrand2013-01-181-0/+7
| | | | | | | | | | | | | | | | | | When in 'keep comments' mode, the preprocessor does not properly handle macro calls with comments between the macro name and the opening parenthesis: "FOO /*something to say*/ (45)". Change-Id: I6fe733242e4d2ccff2985d17399d0a084917415a Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* | C++: Small fixes to the token buffer.Erik Verbruggen2013-01-111-8/+25
| | | | | | | | | | | | | | | | | | | | | | - Fixed blocking macro check - Enabled buffer "compression": when tokens are generated and no new macro is being blocked, then prepend the tokens to the previous buffer. This happens a lot when undo-ing look-ahead. - Added documentation Change-Id: I6fa816d94ce4696e473bdbc4f3bf477d77e4dd51 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
* | C++: pass #include_next down to CppPreprocessor::tryIncludeFilehjk2013-01-111-4/+7
| | | | | | | | | | | | | | This does not yet resolve the file using the proper mechanism. Change-Id: I04913e8b01ae0c3411961f0c1cffe07202f06a0a Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* | Remove braces for single lines of conditionsOrgad Shaneh2013-01-081-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | #!/usr/bin/env ruby Dir.glob('**/*.cpp') { |file| # skip ast (excluding paste, astpath, and canv'ast'imer) next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i s = File.read(file) next if s.include?('qlalr') orig = s.dup s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m| res = $& if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces res else res.gsub!('} else', 'else') res.gsub!(/\n +} *\n/m, "\n") res.gsub(/ *{$/, '') end } s.gsub!(/ *$/, '') File.open(file, 'wb').write(s) if s != orig } Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc Reviewed-by: hjk <qthjk@ovi.com>
* | Faster macro expansion.hjk2012-12-201-20/+17
| | | | | | | | | | | | | | | | Turns out QByteArray::setNum() is unnecessarily slow (will be fixed independently), but even then, we can be faster. Change-Id: I663bd2b8cc844bbe800879bccfa57999d020ba3b Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
* | C++: Remove hard-coded configuration file name.Erik Verbruggen2012-12-041-1/+3
|/ | | | | Change-Id: Ibe4cc69eafd14dab7707862b1068ce1e21b1d8e0 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
* C++: Fix outdated macro usage info in documents.Erik Verbruggen2012-10-151-0/+3
| | | | | | | | | | | Record revisions of documents in macro definitions and usages. Then, when searching for usages, check the revision of the documents against the revision of the macros. If they are out-of-sync, repreprocess the documents to get up-to-date info. Task-number: QTCREATORBUG-7872 Change-Id: I846bb52ec660024728ab117a9fb7e43382a50e63 Reviewed-by: Christian Stenger <christian.stenger@digia.com>
* Adjust license headershjk2012-10-051-21/+20
| | | | | Change-Id: Ice592c6de9951ee3b2c4cb52ed0bb3b6770e0825 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
* C++: Fix memory leak in preprocessor.Nikolai Kosjar2012-09-191-0/+2
| | | | | | | | | This addresses the main memory leak revealed in QTCREATORBUG-7645. The other leaks seem to have their origin in Qt. Task-Number: QTCREATORBUG-7645. Change-Id: I77f45449416c143b222ed5f5c905cba9674f95bb Reviewed-by: Christian Kamm <kamm@incasoftware.de>
* C++: Fine tune behavior of "expand macros" flagLeandro Melo2012-09-111-1/+4
| | | | | | | | | | | Even if "expand funcion-like macros" is unset we still perform the expansion in the case it's already doing so - when it originally started from an object-like macro. Task-number: QTCREATORBUG-7712 Change-Id: Ie2a24de227f757d195146477d48246472082d28a Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: hjk <qthjk@ovi.com>
* C++: Discard comments in macro definitionsLeandro Melo2012-09-051-1/+3
| | | | | | | | Task-number: QTCREATORBUG-7815 Change-Id: Id3e6b018bfd58b0f0072c637d69721a4bde1603a Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
* C++: Always skip unknown preprocessor "directives"Leandro Melo2012-08-291-2/+2
| | | | | | | | Task-number: QTCREATORBUG-7780 Change-Id: Ie93704feff17ad8229e50fb1133048f2c7598dea Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: hjk <qthjk@ovi.com>
* C++: Handle C++ style comments in macro expansionLeandro Melo2012-08-231-1/+15
| | | | | | | | | | | | 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>
* C++: Take multiline strings into account when preprocessingLeandro Melo2012-08-231-4/+4
| | | | | | | It was creating extra line(s)... Change-Id: If28a9ccf16195c71747479db838a5589ea6683a0 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
* C++: Fix line number information after multiline comments.Christian Kamm2012-08-071-2/+8
| | | | | | Task-number: QTCREATORBUG-7702 Change-Id: I0ec2e1eb9bf1c556b0a426d4405df1c48b5653ed Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
* C++: Expand object-like macros in fast preprocessing mode again.Christian Kamm2012-08-071-8/+8
| | | | | | Task-number: QTCREATORBUG-7512 Change-Id: I59898a0449f1f6997963e0f31c47293358a773f6 Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
* rename QtDebug to QDebughjk2012-08-061-1/+1
| | | | | | | More uniform. Change-Id: I1c6057981f4c2b3170a4e69f0674fe4caf1143a2 Reviewed-by: Robert Loehning <robert.loehning@nokia.com>
* Contact -> qt-project.orgEike Ziller2012-07-191-3/+1
| | | | | Change-Id: I7134d7de30bcf9f9dcfad42520dd45ee083a852d Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* C++: Parse emit/Q_EMIT properlyLeandro Melo2012-06-281-0/+4
| | | | | | | | | | | | | | | | | The parser now understands emit/Q_EMIT as an expression statement. Also, the recent fixes in the preprocessor introduced a side-effect in the hanlding of code such as: emit signal(); Member signal started being treated as a local use (parsed as a declaration) and possibily being highlighted as unused variable. Previously that worked by accident since there was an inconsistency in the preprocessor on which only object-like macros were being expanded even when the "no expand" flag was set. Then, the code mentioned above was being parsed as an expression, what kind of worked. Change-Id: I47a68ed4c1c1702872620b8ed7c7264fb0997034 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
* C++: Core changes in preprocessingLeandro Melo2012-06-251-211/+499
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* C++: Better handling of arg count mismatch in macrosLeandro Melo2012-06-191-8/+19
| | | | | | | | | | | | 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>
* C++: Track macro argument reference even when emptyLeandro Melo2012-06-121-6/+10
| | | | | Change-Id: I6d226b4e42f94ebee41d012050c5109895f0c432 Reviewed-by: hjk <qthjk@ovi.com>
* C++: Also expand first token after macro defineLeandro Melo2012-06-051-4/+10
| | | | | | | It was previously beeing skipped. Change-Id: Iadd9b03acbcf0ee0fb4db537b8597661cb93af3f Reviewed-by: hjk <qthjk@ovi.com>
* C++: Fix macro uses line infoLeandro Melo2012-06-011-12/+29
| | | | | | | | | | | 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>
* preprocessor: do not loop endlessly on incomplete expressionshjk2012-05-301-6/+6
| | | | | | | An missing closing parantheses after "defined(..." caused an endless loop. Change-Id: I19b17cebc1a56880216c3bfb67c9d296f80cc064 Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
* C++: Fix argument tracking in macro expansionLeandro Melo2012-05-231-31/+61
| | | | | | | | | | | Due to latest changes the macro arguments were no longer being tracked. Then they were no available in the document's macro uses. The patch also makes sure that the preprocessor condition to be expanded is spelled exactly as in the source code (this guarantees that offsets will be properly calculated). Change-Id: I8aff0c3aca0c528ef2c4bcfa56ff1c3da2961060 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
* Fix ICC warnings about commas at the end of enumsThiago Macieira2012-05-231-1/+1
| | | | | | | They're non-standard. Remove them. Change-Id: I58dc093c2459747ce0183685d325522fb51e86ab Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
* preprocessor: concatenate tokens need to preserve previous whitespacehjk2012-05-021-1/+3
| | | | | Change-Id: Ibca5737ad906c1db7e1bf4e15e5c92030e87c0bb Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>