|
20 | 20 | #include "helpers.h" |
21 | 21 | #include "settings.h" |
22 | 22 | #include "standards.h" |
| 23 | +#include "symboldatabase.h" |
23 | 24 | #include "token.h" |
24 | 25 | #include "tokenlist.h" |
25 | 26 | #include "vfvalue.h" |
@@ -131,6 +132,7 @@ class TestToken : public TestFixture { |
131 | 132 | TEST_CASE(update_property_info_etype_c); |
132 | 133 | TEST_CASE(update_property_info_etype_cpp); |
133 | 134 | TEST_CASE(update_property_info_replace); // #13743 |
| 135 | + TEST_CASE(update_property_info_symbol_cleared); |
134 | 136 |
|
135 | 137 | TEST_CASE(varid_reset); |
136 | 138 | } |
@@ -1504,6 +1506,76 @@ class TestToken : public TestFixture { |
1504 | 1506 | assert_tok(&tok, Token::Type::eType, false, true); |
1505 | 1507 | } |
1506 | 1508 |
|
| 1509 | + void update_property_info_symbol_cleared() const |
| 1510 | + { |
| 1511 | + // clearing the symbol association of a token must restore the token type that |
| 1512 | + // follows from the string. The compiled Token::Match variants (MATCHCOMPILER) |
| 1513 | + // check the token type for literal patterns, so a standard type or keyword left |
| 1514 | + // as eName makes the compiled and the parsed pattern matching disagree. |
| 1515 | + const ::Type type; |
| 1516 | + { |
| 1517 | + // a standard type is eType again after the associated type is cleared |
| 1518 | + TokenList list_cpp{settingsDefault, Standards::Language::CPP}; |
| 1519 | + auto tokensFrontBack = std::make_shared<TokensFrontBack>(); |
| 1520 | + Token tok(list_cpp, std::move(tokensFrontBack)); |
| 1521 | + tok.str("void"); |
| 1522 | + assert_tok(&tok, Token::Type::eType, /*l=*/ false, /*std=*/ true); |
| 1523 | + tok.type(&type); |
| 1524 | + assert_tok(&tok, Token::Type::eType, /*l=*/ false, /*std=*/ true); |
| 1525 | + tok.type(nullptr); |
| 1526 | + assert_tok(&tok, Token::Type::eType, /*l=*/ false, /*std=*/ true); |
| 1527 | + } |
| 1528 | + { |
| 1529 | + // a keyword is eKeyword again after the associated type is cleared |
| 1530 | + // ("auto" gets the deduced type attached and cleared) |
| 1531 | + TokenList list_cpp{settingsDefault, Standards::Language::CPP}; |
| 1532 | + auto tokensFrontBack = std::make_shared<TokensFrontBack>(); |
| 1533 | + Token tok(list_cpp, std::move(tokensFrontBack)); |
| 1534 | + tok.str("auto"); |
| 1535 | + assert_tok(&tok, Token::Type::eKeyword); |
| 1536 | + tok.type(&type); |
| 1537 | + assert_tok(&tok, Token::Type::eType); |
| 1538 | + tok.type(nullptr); |
| 1539 | + assert_tok(&tok, Token::Type::eKeyword); |
| 1540 | + } |
| 1541 | + { |
| 1542 | + // a plain name is eName again after the associated type is cleared |
| 1543 | + TokenList list_cpp{settingsDefault, Standards::Language::CPP}; |
| 1544 | + auto tokensFrontBack = std::make_shared<TokensFrontBack>(); |
| 1545 | + Token tok(list_cpp, std::move(tokensFrontBack)); |
| 1546 | + tok.str("MyClass"); |
| 1547 | + assert_tok(&tok, Token::Type::eName); |
| 1548 | + tok.type(&type); |
| 1549 | + assert_tok(&tok, Token::Type::eType); |
| 1550 | + tok.type(nullptr); |
| 1551 | + assert_tok(&tok, Token::Type::eName); |
| 1552 | + } |
| 1553 | + { |
| 1554 | + // a plain name is eName again after the associated function is cleared |
| 1555 | + TokenList list_cpp{settingsDefault, Standards::Language::CPP}; |
| 1556 | + auto tokensFrontBack = std::make_shared<TokensFrontBack>(); |
| 1557 | + Token tok(list_cpp, std::move(tokensFrontBack)); |
| 1558 | + tok.str("f"); |
| 1559 | + const Function function(&tok, ""); |
| 1560 | + tok.function(&function); |
| 1561 | + assert_tok(&tok, Token::Type::eFunction); |
| 1562 | + tok.function(nullptr); |
| 1563 | + assert_tok(&tok, Token::Type::eName); |
| 1564 | + } |
| 1565 | + { |
| 1566 | + // a plain name is eName again after the associated variable is cleared |
| 1567 | + TokenList list_cpp{settingsDefault, Standards::Language::CPP}; |
| 1568 | + auto tokensFrontBack = std::make_shared<TokensFrontBack>(); |
| 1569 | + Token tok(list_cpp, std::move(tokensFrontBack)); |
| 1570 | + tok.str("x"); |
| 1571 | + const Variable var(&tok, nullptr, nullptr, 0, AccessControl::Public, nullptr, nullptr, settingsDefault); |
| 1572 | + tok.variable(&var); |
| 1573 | + assert_tok(&tok, Token::Type::eVariable); |
| 1574 | + tok.variable(nullptr); |
| 1575 | + assert_tok(&tok, Token::Type::eName); |
| 1576 | + } |
| 1577 | + } |
| 1578 | + |
1507 | 1579 | void varid_reset() const |
1508 | 1580 | { |
1509 | 1581 | TokenList list_c{settingsDefault, Standards::Language::C}; |
|
0 commit comments