Commit Graph

566 Commits

Author SHA1 Message Date
Andre Hartmann
2df71c5798 Lexer: Support the integer suffixes LU and LLU also
Before we only supported UL and ULL.

And add tests for all variants of allowed integer suffixes.

Fixes: QTCREATORBUG-25604
Change-Id: Id92f371d2effa7456d2d50891a6c29810c5c4c75
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-04-19 09:16:55 +00:00
Christian Kandeler
a995a4633f CPlusPlus: Do not mis-classify bitfield declarations as initializations
Fixes: QTCREATORBUG-25390
Change-Id: I1976b7db2996f5a09db73adbd127aac9ab92d57d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-02-25 15:55:54 +00:00
hjk
a5b93b54c8 CPlusPlus: Add missing line and column info for lambda functions
Task-number: QTCREATORBUG-25242
Change-Id: I5032bb04879e30f5516471e2038dc4b6bb3477f8
Reviewed-by: hjk <hjk@qt.io>
2021-02-05 08:51:09 +00:00
Eike Ziller
1e78fdb71f Merge remote-tracking branch 'origin/4.14'
Change-Id: Id4c4c06b086dfe38960f4d68694ae23f3e00109f
2020-12-03 11:57:42 +01:00
Christian Kandeler
ff2322ac0b CPlusPlus: Fix mis-classification of pure virtuals
Syntactically, they do have an initializer, but they are not
initializations.

Change-Id: I0556b279ce2d173868585cbce085b803c1cff285
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-12-03 09:09:52 +00:00
Christian Kandeler
dc66d30076 CPlusPlus: Support C++11 attributes also for function parameters
Fixes: QTCREATORBUG-24636
Change-Id: I9dc3d2cc6ca102b09f6b040455fa901c362dae7d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-11-12 13:16:34 +00:00
Christian Kandeler
59f8bd4702 CPlusPlus: Expose "static" specifier also for function declarations
To be able to do this, the parser needs to store the decl specifier list
in FunctionDeclaratorAST objects, the same way it is done for
FunctionDefinitionAST.

Task-number: QTCREATORBUG-24894
Change-Id: I475fb08b1f14c63f3050d72dff200c1b08df5789
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-11-11 15:41:27 +00:00
Eike Ziller
1d2b5db02f Merge remote-tracking branch 'origin/4.14'
Change-Id: I2ae0eb18782224e48cd20d41907f9dfea6ee1771
2020-11-10 13:42:46 +01:00
Christian Kandeler
e41f3eb607 CPlusPlus: Fix "find usages" categorization for sizeof and array access
Task-number: QTCREATORBUG-24894
Change-Id: I65fa097785b19e181f15178ad6d30608899316c0
Reviewed-by: André Hartmann <aha_1980@gmx.de>
2020-11-09 12:50:07 +00:00
Christian Kandeler
882dd60aad C++: Extend alias declaration support in built-in parser
The type-id in an alias declaration can also define a new type.

Change-Id: I65dc397d2526c56334676c6ab522564f6748d594
Task-number: QTCREATORBUG-24875
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-11-09 10:56:17 +00:00
Christian Kandeler
42d34015e2 CPlusPlus: Provide information about the "static" specifier
... to the function type.
This fixes the issue for function *definitions*. For function
*declarations*, we need to amend the parser.

Task-number: QTCREATORBUG-24894
Change-Id: I02043d8b974c2c64dcd739c7e05ce44fd277b5d3
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-11-09 10:55:38 +00:00
Christian Kandeler
1988d89198 CPlusPlus: Check for static member functions in FindUsages
Static member functions cannot modify the object and therefore must not
be reported as writable references.
Note that this does not have an effect yet, as the function type lacks
information about the "static" specifier.

Task-number: QTCREATORBUG-24894
Change-Id: Ib04a17864a0ca5b7610579a2f5efbcfde257e08a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-11-09 09:51:08 +00:00
Christian Kandeler
de1e12f3af CPlusPlus: Correctly categorize post-increment and -decrement accesses
Change-Id: Id21c13ea58f6747c226d91aff2b00c3409faa880
Reviewed-by: André Hartmann <aha_1980@gmx.de>
2020-11-04 13:24:33 +00:00
Christian Kandeler
a88266798f CPlusPlus: Differentiate declarations with an initializer
... from those without one, and display the former like write accesses.

Task-number: QTCREATORBUG-24894
Change-Id: I5e2d83b2a3ec4735054441c346687f97eeb039fb
Reviewed-by: André Hartmann <aha_1980@gmx.de>
2020-11-04 13:02:52 +00:00
Christian Kandeler
cf6757406d CPlusPlus: Properly categorize usages in if statements
Change-Id: I5f6e5fa14ea51cd9e61a9e2e96c110ca618be429
Reviewed-by: André Hartmann <aha_1980@gmx.de>
2020-11-04 13:02:34 +00:00
Christian Kandeler
89644e4a06 CPlusPlus: Properly categorize usages in switch and case statements
Change-Id: Iafbbdcca23db38d82bbc5bb24a39dac2a6d0a764
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-11-02 16:03:28 +00:00
Eike Ziller
d54f7b0eb2 Fix building tests with Qt6
Task-number: QTCREATORBUG-24098
Change-Id: I192245125f04f8350597bbe481d80d3f8ba0cae0
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-10-30 15:15:25 +00:00
Christian Kandeler
b58ca33ff6 CppTools: Categorize the delete operator as a write access
... in the "Find Usages" results.

Change-Id: Ib399bf762c717b7d4439be26b9180574aefce7e3
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-10-21 09:12:33 +00:00
Christian Kandeler
f244a7ea4c CPlusPlus: Consider member initializations
... when checking usage types.

Change-Id: Ic875f3bcae9cf045dbb062670e8cf941de533404
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-09-18 11:01:47 +00:00
Christian Kandeler
ee8e102cbc CPlusPlus: Look at all overloads
... when trying to find out the usage type of a function argument.
Otherwise, we potentially ignore functions which have additional
overloads with a shorter parameter list than is required for the call.

Change-Id: I02bf2cb359ea9d506e2644388234dc28fa072445
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-09-15 09:23:48 +00:00
Christian Kandeler
45dd074441 CPlusPlus: Categorize "Find Usages" results
That is, find out whether a certain access was a read, a write, a
declaration or something else, and report the result to upper layers.
Follow-up patches can make this information visible to users.

Task-number: QTCREATORBUG-12734
Task-number: QTCREATORBUG-19373
Change-Id: Iee79e39dd1eb5a986a7e27846991e0e01b2c3a2f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-09-03 14:32:47 +00:00
Christian Kandeler
1652396ece CppTools: Fix CppSelectionChanger autotest
... on Windows.
We need to open the test file in text mode. Otherwise the raw string
literal will contain carriage returns. As these get dropped by
QTextDocument, the offsets will be inconsistent with the ones reported by
the tokens, causing the test to fail.

Change-Id: I161a3f5791c33416ff732f90fd615cf39d8152ce
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-08-31 09:15:50 +00:00
Eike Ziller
f296ed1328 Merge remote-tracking branch 'origin/4.13' into master
Change-Id: I1c426d95eedd82bd4470a64a9bafd734d23081ac
2020-08-13 11:41:32 +02:00
Christian Kandeler
0615d0ec06 CPlusPlus: Fix expectations in preprocessor autotest
... regarding unfinished macro calls.
Amends df0ffd8bb8.

Change-Id: Ia7b8752860ac9207e702697cbee87f16a39dd1dd
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-08-12 08:21:32 +00:00
Christian Kandeler
3f9427200b CppTools: Fix formatting for lambdas with trailing return type
After the arrow, the state is still the same, as now a type is expected.
Only after the opening brace does the actual function start.

Fixes: QTCREATORBUG-18497
Change-Id: I7bf18fbd6907d36f8869af3a78ad617cf0ee9dbb
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-31 08:15:18 +00:00
Christian Kandeler
22830fd5e2 Tests: Fix deprecation warning
Task-number: QTCREATORBUG-24098
Change-Id: Icea21e446173537d8fdb8113f1eff7d7176c34b3
Reviewed-by: hjk <hjk@qt.io>
2020-06-26 10:31:18 +00:00
Volodymyr Zibarov
40173ad4ab C++: Fix auto variable resolving for template class constructor call
Code snippet:
template<class T> struct MyStruct { int value; };
int main() {
    auto s = MyStruct<int>();
    s.value;  // "value" is not found
}

This fixes find usages for unique_ptr declared as auto like this:
auto ptr = std::unique_ptr<MyStruct>(new MyStruct());
ptr->value;

Also fixes in-place constructors:
std::unique_ptr<MyStruct>(new MyStruct())->value;

Fixes: QTCREATORBUG-15364
Change-Id: I8d452a77fe85e63665ec8d4c4afbcf8aad063121
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-06-22 14:27:49 +00:00
Christian Kandeler
8eac3fba80 CPlusPlus: Fix lexer crash
At some point in the preprocessing stage, some tokens get "squeezed", so
their associated string no longer refers to the document content, but
only to their own symbol. However, there is at least one context that
operated under the assumption that the token's offset still pointed into
the "global" string. As the token's offset is zero after parsing, this
lead to the same piece of code being preprocessed in an infinite loop.

Fixes: QTCREATORBUG-19525
Change-Id: I231ba51811cfa0b5c6dfe7f75fe0384472252c6f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-06-18 07:52:02 +00:00
Volodymyr Zibarov
9be4a5f839 C++: Fix Find Usages false positive results for function arguments
Code snippet:
void bar();         // call find usages for bar from here
void foo(int bar);  // bar from here should not be in results

Add test for member function false positives, that is part of
QTCREATORBUG-2176. That was already fixed before.

Fixes: QTCREATORBUG-2176
Change-Id: I9a079caa83bbaea1edb7ba6aeb151d4d4c77952f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-06-15 13:19:51 +00:00
Volodymyr Zibarov
7d82741602 C++: Fix find usage to see Catch test functions bodies
Catch test functions defined with function-like macros.
To speed-up semantic analysis, find usages does not expand function-like
macros.
Semantic fails with "expected a function declarator" on such functions
and skips function body.
To avoid that, we create dummy function type specifically for this case

Change-Id: Ie2f2464ee57aa4dc86eed07b8b699458f95c0266
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-06-15 10:16:06 +00:00
Volodymyr Zibarov
3ad203b56e C++: Fix variable template parsing in expression
Fix parser to not fail on TemplateId without parentheses, for example:
int i = foo<int> + foo<char>;

This fixes std::pair structure parsing in MSVC headers and find Usages
to work with pair->first and pair->second.

Change-Id: Ic300ea99d44a749705430d5eb47b2744715af995
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-06-04 08:18:40 +00:00
Christian Kandeler
02f2841a41 CppTools: Fix formatting for new-style function declaration
Fixes: QTCREATORBUG-23502
Change-Id: Ie80fe9aa77ffbf0b9ecc531841e78f2bd80de37e
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-06-04 07:21:39 +00:00
Volodymyr Zibarov
9ee693ee22 C++: fix built-in code model to work with shared_ptr on MSVC 2017
These changes target Find Usages feature to work with shared_ptr.
Improve libs/3rdparty/cplusplus and plugins/cplusplus:
parse __declspec() attribute,
call to variadic function template without specified template arguments,
if constexpr,
c++11 attributes [[value]],
function templates with default parameters,
resolve order for function vs template with default parameter,
template operator->() with default arguments,
template specialization with numeric values,
find best partial specialization,
fix partial specialization for non-first specialized argument

Fixes: QTCREATORBUG-7866
Fixes: QTCREATORBUG-20781
Fixes: QTCREATORBUG-22857
Fixes: QTCREATORBUG-17825
Change-Id: I31a080f7729edfb2ee9650f1aff48daeba5a673b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Nikolai Kosjar <pinaceae.pinus@gmail.com>
2020-05-29 12:39:28 +00:00
Christian Kandeler
1989dbe0d7 Built-in lexer: Recognize also reserved user-defined literals
Otherwise, we trip over uses of operators from the standard
library such as std::chrono's operator"" ms(), potentially breaking
basic code navigation.
Amends 425811291d.

Fixes: QTCREATORBUG-24067
Change-Id: I3b2863ce88ee3787414e7a1acdf25f368041cdb4
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2020-05-28 08:36:56 +00:00
Christian Kandeler
e4fb3de165 C++: Add tests for recent indentation fixes
Change-Id: I90ae2da3a82bff2e966c4327cf8e42f7ebbddd27
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-05-27 04:45:12 +00:00
Eike Ziller
53819123e7 Simplify RPATHs for qmake build
Use central rpath.pri for setting RPATHs and qttestrpath.pri for tests.
Simplify install names of plugins and libraries on macOS to be just
@rpath/libName, which follows convention better and makes setting up
RPATHs easier.

Preparation for moving tools one directory level down on macOS, to
be able to add a qt.conf for the tools generically.

Task-number: QTCREATORBUG-23120
Change-Id: I16625d48904abd3a7f4c2ad7bbba5916cdc400cd
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2019-11-04 10:31:55 +00:00
Cristian Adam
486aaabd21 CMake Build: Use same Qt compiler defines for tests
Source code needed adjustments though.

Change-Id: I78b4610a6bb895a385c7c30a6c92c97a276b89dd
Reviewed-by: hjk <hjk@qt.io>
2019-09-10 15:05:59 +00:00
hjk
7ab6783e24 Standardize on int for line and column values
Recently tons of warnings show up for presumably "problematic"
singned <-> unsigned and size conversions.

The Qt side uses 'int', and that's the biggest 'integration surface'
for us, so instead of establishing some internal boundary between
signed and unsigned areas, push that boundary out of creator core code,
and use 'int' everywhere.

Because it reduces friction further, also do it in libcplusplus.

Change-Id: I84f3b79852c8029713e7ea6f133ffb9ef7030a70
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2019-07-26 09:23:48 +00:00
hjk
251287f0d3 Avoid warning on empty expressions
For some reason, Q_UNUSED includes already a semicolon, adding one
on the user side creates an additional empty statement.

Change-Id: I9c5e8fac381345a60792cb75e2938fd53958d3b0
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-07-23 11:55:59 +00:00
Joel Smith
8c437362bc C++: Support single quote digit separator in integer literals
C++14 supports the use of single quotes inserted between integer digits
as a separator.  Updates the built-in C++ code model to recognize such
quotes.  This fixes highlighting and indentation issues.

Change-Id: Ic35ce93060b96700a11d108dce1f3cf6c4543632
Fixes: QTCREATORBUG-14939
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2019-07-09 08:59:23 +00:00
Cristian Adam
61fcdd0459 Clang build: Fix compilation with MSVC2017
Change-Id: I677614dc8f9de503131d8ac490a723c9fc5f7beb
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2019-06-17 15:40:39 +00:00
hjk
2f7ca2ce44 CPlusPlus: Avoid a few deprecation warnings
The alternatives have been around since 2012.

Change-Id: I0aa15d59efe8a547e2ad622ffda689746960d48c
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2019-06-05 05:43:34 +00:00
Cristian Adam
d855b84c5d Qt Creator CMake port
Based on Tobias Hunger's work from a few months ago.

The CMake configuration needs libclang and Qt paths specified as
CMAKE_PREFIX_PATH.

Auto tests are run with "ctest". At the moment the pass rate is 87%.

Change-Id: Iba98e39bf22077d52706dce6c85986be67a6eab0
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2019-05-17 13:33:28 +00:00
Xiaofeng Wang
4dd4d088c5 C++: fix StarBindFlags behavior
Without Overview::BindToIdentifier, a space between
return type(endsWithPtrOrRef) and identifier should be added.

Change-Id: I3cd2d053bf137b35a58e7422f45cbd5b96eeb151
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2019-01-30 04:42:03 +00:00
Ivan Donchevskii
645bbf5dd6 CPlusPlus: Block function-like macro name for arguments expansion
Arguments of funstion-like macro may contain the name of this
macro. The attempt to expand it results into infinite recursion.

Patch solves that by saving the macro name until the arguments
are collected to determine that it should not be expanded.

Fixes: QTCREATORBUG-21642
Change-Id: Iafb404ecd3959a2f1011c12c1c3f1c0c54ed3547
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2019-01-17 08:52:40 +00:00
Nikolai Kosjar
aac1bebace C++: Fix parsing enum specifier II
This amends the obviously wrong
de975aca4f, which did not honored nameless
enum specifiers.

This fixes e.g. "Find Usages" for declarations following "enum {};".

Change-Id: Id98c074156f576b9a63e6c25dab38721ca34e496
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2018-10-24 12:47:03 +00:00
Colin Duquesnoy
2a016d05b2 Add support for nested namespaces (C++17)
Task-number: QTCREATORBUG-16774
Change-Id: I3de3ac65810213e21c9a3bafef2474d252e191f7
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-02-09 17:54:30 +00:00
Nikolai Kosjar
76006a1353 C++: Fix crash with invalid raw string literal
While parsing a document Bind::asStringLiteral() Token::spell() was
called for a raw string literal token with a Token::literal nullptr.

This is due scanRawStringLiteral() not properly aborting for
invalid/incomplete code and that the code paths handling
multi-line-raw-strings were not limited to the highlighting case.

Address both cases.

Task-number: QTCREATORBUG-18941
Change-Id: I489d288ccbd7b59be396dada846613ff555436cf
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2017-09-20 07:38:04 +00:00
Eike Ziller
4e35cc2ea8 Fix that raw string literals that close on same line were not terminated
With the built-in model, which affects basic highlighting.

Task-number: QTCREATORBUG-17720
Change-Id: I7369d7288d9c2c8e5ef36fc27549121014527e58
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-05-19 13:50:42 +00:00
Eike Ziller
1704c484a8 Merge remote-tracking branch 'origin/4.2'
Change-Id: I9006dd493707ae626ae3502541599c8789e1aab0
2017-02-27 15:17:37 +01:00