Skip to content

Commit 670e4a0

Browse files
authored
TemplateSimplifier: removed need for test class friend declaration / cleaned up member access (#8068)
1 parent c1d9276 commit 670e4a0

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/templatesimplifier.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ struct newInstantiation;
4545

4646
/** @brief Simplify templates from the preprocessed and partially simplified code. */
4747
class CPPCHECKLIB TemplateSimplifier {
48-
friend class TestSimplifyTemplate;
49-
5048
public:
5149
explicit TemplateSimplifier(Tokenizer &tokenizer);
5250

@@ -267,6 +265,7 @@ class CPPCHECKLIB TemplateSimplifier {
267265
static Token *findTemplateDeclarationEnd(Token *tok);
268266
static const Token *findTemplateDeclarationEnd(const Token *tok);
269267

268+
protected:
270269
/**
271270
* Match template declaration/instantiation
272271
* @param instance template instantiation
@@ -277,6 +276,7 @@ class CPPCHECKLIB TemplateSimplifier {
277276
*/
278277
static bool instantiateMatch(const Token *instance, std::size_t numberOfArguments, bool variadic, const char patternAfter[]);
279278

279+
public: // TODO: only needs to be public for tests
280280
/**
281281
* Match template declaration/instantiation
282282
* @param tok The ">" token e.g. before "class"
@@ -285,6 +285,7 @@ class CPPCHECKLIB TemplateSimplifier {
285285
*/
286286
int getTemplateNamePosition(const Token *tok);
287287

288+
private:
288289
/**
289290
* Get class template name position
290291
* @param tok The ">" token e.g. before "class"
@@ -309,6 +310,7 @@ class CPPCHECKLIB TemplateSimplifier {
309310
* */
310311
static bool getTemplateNamePositionTemplateVariable(const Token *tok, int &namepos);
311312

313+
public:
312314
/**
313315
* Simplify templates
314316
* @param maxtime time when the simplification should be stopped
@@ -324,6 +326,7 @@ class CPPCHECKLIB TemplateSimplifier {
324326
*/
325327
static bool simplifyNumericCalculations(Token *tok, bool isTemplate = true);
326328

329+
private:
327330
/**
328331
* Simplify constant calculations such as "1+2" => "3".
329332
* This also performs simple cleanup of parentheses etc.
@@ -338,7 +341,6 @@ class CPPCHECKLIB TemplateSimplifier {
338341
*/
339342
void simplifyTemplateArgs(Token *start, const Token *end, std::vector<newInstantiation>* newInst = nullptr);
340343

341-
private:
342344
/**
343345
* Get template declarations
344346
* @return true if code has templates.
@@ -445,6 +447,7 @@ class CPPCHECKLIB TemplateSimplifier {
445447
const std::list<std::string> &typeStringsUsedInTemplateInstantiation,
446448
const std::string &newName);
447449

450+
protected:
448451
/**
449452
* @brief TemplateParametersInDeclaration
450453
* @param tok template < typename T, typename S >
@@ -456,6 +459,7 @@ class CPPCHECKLIB TemplateSimplifier {
456459
const Token * tok,
457460
std::vector<const Token *> & typeParametersInDeclaration);
458461

462+
private:
459463
/**
460464
* Remove a specific "template < ..." template class/function
461465
*/

test/testsimplifytemplate.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ class TestSimplifyTemplate : public TestFixture {
321321
TEST_CASE(dumpTemplateArgFrom);
322322
}
323323

324+
class TemplateSimplifierTest : public TemplateSimplifier
325+
{
326+
friend class TestSimplifyTemplate;
327+
};
328+
324329
class TokenizerTest : public Tokenizer
325330
{
326331
friend class TestSimplifyTemplate;
@@ -5649,7 +5654,7 @@ class TestSimplifyTemplate : public TestFixture {
56495654
tokenizer.splitTemplateRightAngleBrackets(false);
56505655

56515656
std::vector<const Token *> typeParametersInDeclaration;
5652-
TemplateSimplifier::getTemplateParametersInDeclaration(tokenizer.tokens()->tokAt(2), typeParametersInDeclaration);
5657+
TemplateSimplifierTest::getTemplateParametersInDeclaration(tokenizer.tokens()->tokAt(2), typeParametersInDeclaration);
56535658

56545659
if (params.size() != typeParametersInDeclaration.size())
56555660
return false;
@@ -5949,7 +5954,7 @@ class TestSimplifyTemplate : public TestFixture {
59495954

59505955
ASSERT_LOC(tokenizer.tokenize(code), file, line);
59515956

5952-
return (TemplateSimplifier::instantiateMatch)(tokenizer.tokens(), numberOfArguments, false, patternAfter);
5957+
return (TemplateSimplifierTest::instantiateMatch)(tokenizer.tokens(), numberOfArguments, false, patternAfter);
59535958
}
59545959

59555960
void instantiateMatchTest() {

0 commit comments

Comments
 (0)