Commit Graph

101 Commits

Author SHA1 Message Date
Daniel Marjamäki c89512d8d6 Update copyright year 2020-12-05 09:28:33 +01:00
Daniel Marjamäki 8a1c16a560 Tokenizer: add daca debug messages when right angle brackets in templates are not handled well 2020-11-29 16:07:56 +01:00
Dmitry-Me 7d6582c7a5 Resolve C4800 Visual C++ warning 2019-12-16 18:11:12 +03:00
IOBYTE 3a1aec8850 template simplifier: ignore friend templates (#2122)
* template simplifier: ignore friend templates

friend templates were interpreted as variable templates

* fix cppcheck warning
2019-09-01 09:56:33 +02:00
IOBYTE 5fc5e3728d template simplifier: refactor TemplateSimplifier::TokenAndName into a… (#2073)
* template simplifier: refactor TemplateSimplifier::TokenAndName into a class

assert when more than one family flag is set

* fix function parameter names
2019-08-10 08:42:12 +02:00
Armin Müller 785cc69644 Typos found by running "codespell" (#2072) 2019-08-08 21:05:28 +02:00
Paul Fultz II 8cd8a2671c Fix issue 9211: No error on divide by zero outside template instatiation
I am not sure how to add a test for this.
2019-07-18 14:55:30 +02:00
IOBYTE e551057f59 Refactor Tokenizer::simplifyUsing to use continue to reduce indentation (#1967)
* Refactor Tokenizer::simplifyUsing to use continue to reduce indentation

added function findTemplateDeclarationEnd to skip template declarations
to reduce duplicate code

* fix travis build
2019-07-07 18:33:33 +02:00
albert-github 280a0a7b2f Wrong argument name used in documentation (#1937)
Trivial error in documentation
2019-06-30 15:41:53 +02:00
Scott Furry 1994b21ae5 Minor Corrections to Doxygen data (#1935)
Increasing the verbosity in Clang, warnings were produced that identified
differences in code and doxygen-formatted comments.

Corrections applied to silence warnings yet still convey intent of original comments.
2019-06-30 09:17:42 +02:00
IOBYTE 16788df055 template simplifier: various small fixes (#1916)
* fix adding instantiation of first argument to an instantiation

* add support for function pointer template variables

* fix more cases where templates ending in ">>" are changed to end in "> >"

* fix travis build

* standard types can't be a template parameter name

* remove redundant level == 0 checks

* fix lambda in template variable

* fix a test
2019-06-28 11:14:20 +02:00
IOBYTE 46b543ba27 template simplifier: stop running passes when nothing was simplified. (#1914) 2019-06-23 10:55:09 +02:00
IOBYTE 5af8beecf6 template simplifier: specialized member class not recognized causing wrong instantiation (#1876)
Specialized member classes declared outsize the class were not
recognized. This caused the the member class to be instantiated rather
than the specialized class. We already had a test for this but it was
wrong so it went unnoticed.
2019-06-09 08:11:59 +02:00
IOBYTE 81e41f129a template simplifier: improve populating template specialization maps (#1873)
Declaration to specialization mapping is still not perfect.
2019-06-07 08:22:34 +02:00
IOBYTE bee248b2de token simplifier: fix namespace, token link and syntax error support for template type aliases (#1863) 2019-06-01 10:52:29 +02:00
IOBYTE 1e7f5010eb template simplifier: fix expansion of template arguments in default parameter instantiation (#1857) 2019-05-28 21:32:37 +02:00
Paul Fultz II eb1c9ba357 Cache template name position to improve performance
This improves the performance of the templatesimplefier by caching the template name position. I am not sure if the works entirely correctly but all the tests do pass with this change. Running this with gtest headers without removing unused template headers the time went from 48s to 5s, almost a 10x improvement.
2019-05-25 10:08:51 +02:00
IOBYTE 5efb23ffff template simplifier: fix instantiation of variadic template with no arguments (#1848)
* template simplifier: fix instantiation of variadic template with no arguments

* fix white space change

* add support for <class...>

* add variadic template flag
2019-05-23 20:53:26 +02:00
IOBYTE 592ff56b90 template simplifier: fix single parameter template with default value (#1842)
* template simplifier: fix single parameter template with default value

* fix derived class with single default argument
2019-05-19 19:19:57 +02:00
Daniel Marjamäki 57c6628732 Revert 'Cleaning up unsimplified templates'. This fix caused problems. 2019-05-16 21:11:04 +02:00
Daniel Marjamäki d58d4273f9 Cleaning up unsimplified templates 2019-05-11 13:00:03 +02:00
IOBYTE 5b72e1f568 Fixed #9040 (Type alias 'BOOL' declared with 'using' keyword breaks type detection) (#1759)
Moved simplifyUsing from TemplateSimplifier to Tokenizer.
2019-03-26 07:09:56 +01:00
IOBYTE b222953bae template simplifier: only constant fold template instantiation arguments (#1721)
* template simplifier: only constant fold template instantiation arguments

* Fix travis build.
2019-03-03 07:40:55 +01:00
Daniel Marjamäki bd7790fd8c Update copyright year 2019-02-09 07:24:06 +01:00
IOBYTE 1faae52d06 Fixed #8960 ("(debug) Unknown type 'x'." with alias in template class alias) (#1643)
* Fixed #8960 ("(debug) Unknown type 'x'." with alias in template class alias)

This commit adds non-template type alias support to the template
simplifier.  Only relatively simple type aliases are supported at this
time. More complex types will be added later.

--debug-warnings will show unsupported type aliases.

Type alias support will be removed from the symbol database in the
future.  Type alias tests have been removed from the symbol database
tests.

* Add the changes.

* Fix codacy warning.

* Fix travis warnings.
2019-02-05 08:52:23 +01:00
IOBYTE 606ba4fc1a template simplifier: add forward declaration map to debug output (#1629)
* template simplifier: add forward declaration map to debug output

* template simplifier: add partial specialization flag

* template simplifier: add specialization map and partial specialization map to debug output
2019-01-27 07:46:27 +01:00
IOBYTE 1acbdde302 Fixed #7417 ("syntax error" in valid code containing explicitly specialised variable template) (#1604) 2019-01-18 21:12:39 +01:00
Robert Reif 6ef8dad459 template simplifier: improve namespace matching
* out of line member functions are a namespace
* template<...> and *_cast<> can't be instantiations
* refactor code to use less function parameters
* fix instantiation scopes
* use full name with namespace when available
* fallback to just matching names when full name doesn't match
2019-01-14 21:32:58 +01:00
IOBYTE f0cfe03f7b template simplifier: add cli --debug-template option to print the parsed template information (#1598) 2019-01-14 08:29:32 +01:00
IOBYTE 07da4b4d37 template simplifier: Add flag variable to cache information about dec… (#1569)
* template simplifier: Add flag variable to cache information about declarations.

Also fix some cppcheck warnings.

* Make variable const.
2019-01-07 06:55:22 +01:00
IOBYTE 36dfa0f27a template simplifier: refactor to use cached information (#1548)
* use already cached name token rather than recalculating it
  multiple times

* cache end of template parameters token and use it rather than
  recalculating it multiple times

* remove unnecessary end of template token and name token checks

* remove function parameter that is already contained in another
  parameter
2018-12-30 21:16:11 +01:00
Carlo Marcelo Arenas Belón 5ae6861a0f clang warnings (#1547)
* valueflow: remove unused variable known

since e4677ae640 will trigger :

lib/valueflow.cpp:506:20: warning: unused variable 'known' [-Wunused-variable]
        const bool known = (parent->astOperand1()->hasKnownValue() ||

* templatesimplifier: cleanup

since 48c960f56c showing:

lib/templatesimplifier.h:279:16: warning: private field 'mTokenizer' is not used
      [-Wunused-private-field]
    Tokenizer *mTokenizer;
2018-12-30 11:32:48 +01:00
IOBYTE da91ce2016 Fixed #6183 (TemplateSimplifier: Does not handle methods) (#1546)
* Fixed #6183 (TemplateSimplifier: Does not handle methods)

* Fix function lookup.
2018-12-29 11:19:53 +01:00
Daniel Marjamäki 162576146e Revert "Fixed #6183 (TemplateSimplifier: Does not handle methods) (#1540)"
This reverts commit 7875555b03.
2018-12-24 20:10:00 +01:00
IOBYTE 7875555b03 Fixed #6183 (TemplateSimplifier: Does not handle methods) (#1540) 2018-12-24 07:25:11 +01:00
IOBYTE 48c960f56c template simplifier: better detection of template functions (#1539)
* template simplifier: better detection of template functions

* fix comment
2018-12-22 10:05:10 +01:00
Sebastian b51f19d530
Fix some doxygen warnings/issues in the comments (#1537) 2018-12-21 21:23:03 +01:00
rebnridgway 431d068339 Several fairly significant optimisations (#1518)
* Code changes for Token::mImpl optimisation

* Added new TokenImpl optimisation

Moving members to the TokenImpl struct reduces the size of the Token class, which is a fairly significant optimisation.  In my testing on Windows with 32-bit Release-PCRE, this change reduced the size of the Token class from 108 bits to 52 bits and reduced run-time of my test case by around 20%.

* Several optimisations

Deleted some code that ran very slowly and did nothing, as there is no need to change a Token's string to null if you are about to delete it.
Added a frontToken to simplifyCalculations to reduce the amount of work it has to do on already-simplified calculations.
Moved template removal to the end of the list as this reduces redundant iteration and saves time.

* Added tok argument to simplifyCalculations

This means callers can avoid unnecessary work if they know which tokens have already been simplified.  Passing nullptr indicates the original behaviour (starting from the front of the list).

* Removed mention of member from another change

* Re-added and optimised some code deleted in error

Changing mTemplateInstantiations to a vector avoids the high cost of doing repeated linear searches.  Changing how the code iterates through the array was necessary because the vector can be resized at several points during the loop, which breaks existing references and iterators.

* Changed mTemplateInstantiations to a vector

This is an optimisation that makes repeated linear searches of this collection significantly faster. 
Also added a copy constructor to TokenAndName so code can make copies of these objects to keep a reference if a vector gets resized.

* A cleaner optimisation to removing template tokens

This reverts the previous change to made mInstantiatedTemplates a vector and the iterator changes to support this, and makes mTypesUsedInTemplateInstantiation so the eraseTokens logic can be unified.

* Reverted vector to list

Also made mTypesUsedInTemplateInstantiation a vector of TokenAndName objects so it can share the same logic as the other members.

* Added member for template simplifier pointer

This can be used more efficiently than marking Tokens with a flag and then searching through all templates to find the one that matches.

* Turned loop inside out

This means we only have to iterate through the std::list once.  std::list is very expensive to iterate through.

* Latest code from danmar and fixed optimisations

In particular I have optimised simplifying template instantiation names as this was incredibly slow because of the number of times it had to iterate through the template instantiation list.  Previous optimisations to this weren't very effective and broke some edge cases.

* Added changes from danmar

Made mExplicitInstantiationsToDelete a vector of TokenAndName to be consistent with the rest of the members, which are cleaned up very efficiently.

* Tokens can have many templateSimplifierPointers

* templateSimplifierPointers must be kept in sync
2018-12-21 13:51:45 +01:00
IOBYTE 2090866cd0 template simplifier: remove explicit instantiations after instantiation (#1523)
* template simplifier: remove explicit instantiations after instantiation

* Fix use after free crash in clang test suite.
2018-12-17 05:58:48 +01:00
IOBYTE 358f0c473d Modify template simplifier to add forward declarations of some templa… (#1489)
* Modify template simplifier to add forward declarations of some template functions so symbol database can make sense of the expanded templates.

* Fix travis.
2018-11-23 11:36:09 +01:00
IOBYTE 69e6e11844 Fix a template simplifier namespace bug in #7145 (#1473)
* Fix a template simplifier namespace bug in #7145

* Refactor template simplifier to only call getTemplateDeclarations once per loop.
2018-11-10 16:41:14 +01:00
IOBYTE 9b67e680ae Fix template simplifier namespace support. (#1464) 2018-11-05 19:55:21 +01:00
IOBYTE adbbadec7f Fixed #8798 (template simplifier: wrong simpifications for namespaces) (#1452) 2018-10-26 14:20:13 +02:00
IOBYTE 0763fdbfad Copy template default argument values from forward declaration to declaration. (#1447)
It is possible to define default template parameter values in forward
declarations and not define any in the actual declaration.  Cppcheck
ignores forward declarations and only uses the default values in the
actual declaration so default values in forward declarations are copied
to the actual declaration when necessary.
2018-10-24 14:38:59 +02:00
IOBYTE 0a30768b59 Fixed #8693 (Template specialization: Constructor detected as normal … (#1418)
* Fixed #8693 (Template specialization: Constructor detected as normal function (functionStatic error))

Refactor template simplifier to remove the existing full specialization
function expandSpecialized and allow full specializations to use the
existing function expandTemplate.  The function expandTemplate was
modified to either expand the template like it originally did by copying
it or to modify the template in place.  Both instantiated and
uninstantiated full specializations are modified in place.  This also
fixes #8692 and probably other related tickets as well.

The function simplifyTemplates now tries twice to simplify templates so
more templates can be simplified.  We should try as many times as
necessary to find all possible templates.  We can't do that now because
uninstantiated templates are left unchanged.  It is relatively straight
forward to have the new code also expand in place uninstantiated
templates with their symbolic types but namespaces are not handled
properly (ticket #8671) and it would introduce regressions.

* Fix travis warnings.
2018-10-14 16:57:07 +02:00
Daniel Marjamäki 7833ade128 Updated copyright year 2018-10-13 18:20:31 +02:00
IOBYTE e9a44f70b2 Remove out of line member functions of instantiated template classes. (#1377)
* Remove out of line member functions of instantiated template classes.
2018-09-14 14:16:34 +02:00
IOBYTE 508e8c234b Fixed #8683 (Using deleted token with multiple template instantiations.) (#1353)
* Fixed #8683 (Using deleted token with multiple template instantiations.)

* Fixed #8321 (heap use after free: templatesimplifier)

* Add a flag to Token indicating that it has a pointer to it.

* Run dmake

* Fix one source of list pointers to deleted tokens.

Refactor TemplateSimplifier class to get access to template lists.
Remove many function parameters now that they are class variables.
Fix one source of list pointers to deleted tokens.
Add tests with no output to catch crashes.

* Run dmake again.

* Make 2 more functions private.

* Make requested changes.

* Missed one change request.

* Use TokenList rather than Tokenizer.

* Move TokenAndName constructor to cpp file so token.h is not needed in header file.
2018-09-01 11:26:10 +02:00
Daniel Marjamäki ef534c2d0d Renamed _codeWithTemplates 2018-06-16 22:03:04 +02:00
Daniel Marjamäki 79ffe1d4fc Rename _tokenizer, _settings, _errorLogger 2018-06-16 16:10:28 +02:00