templates: replace constructor/destructor names when expanding template classes

This commit is contained in:
Daniel Marjamäki 2009-03-15 17:07:05 +01:00
parent b26955b9f8
commit 9b06b22053
2 changed files with 21 additions and 14 deletions

View File

@ -533,25 +533,18 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
const std::string name2(name + "<" + type2 + ">"); const std::string name2(name + "<" + type2 + ">");
// Create copy of template.. // Create copy of template..
const Token *tok3 = tok->next();
for (unsigned int i = 0; i <= type.size(); ++i)
{
if (i == type.size())
addtoken(tok3->str().c_str(), tok3->linenr(), tok3->fileIndex());
else if (tok3->str() == type[i])
{
addtoken(types2[i].c_str(), tok3->linenr(), tok3->fileIndex());
break;
}
}
addtoken(name2.c_str(), tok3->linenr(), tok3->fileIndex());
int indentlevel = 0; int indentlevel = 0;
for (tok3 = tok3->tokAt(2); tok3; tok3 = tok3->next()) for (const Token *tok3 = tok->next(); tok3; tok3 = tok3->next())
{ {
for (unsigned int i = 0; i <= type.size(); ++i) for (unsigned int i = 0; i <= type.size(); ++i)
{ {
if (i == type.size()) if (i == type.size())
{
if (tok3->str() == name)
addtoken(name2.c_str(), tok3->linenr(), tok3->fileIndex());
else
addtoken(tok3->str().c_str(), tok3->linenr(), tok3->fileIndex()); addtoken(tok3->str().c_str(), tok3->linenr(), tok3->fileIndex());
}
else if (tok3->str() == type[i]) else if (tok3->str() == type[i])
{ {
addtoken(types2[i].c_str(), tok3->linenr(), tok3->fileIndex()); addtoken(types2[i].c_str(), tok3->linenr(), tok3->fileIndex());

View File

@ -80,6 +80,7 @@ private:
TEST_CASE(template1); TEST_CASE(template1);
TEST_CASE(template2); TEST_CASE(template2);
TEST_CASE(template3); TEST_CASE(template3);
TEST_CASE(template4);
TEST_CASE(namespaces); TEST_CASE(namespaces);
} }
@ -494,6 +495,19 @@ private:
ASSERT_EQUALS(expected, sizeof_(code)); ASSERT_EQUALS(expected, sizeof_(code));
} }
void template4()
{
const char code[] = "template <classname T> class Fred { Fred(); };\n"
"Fred<float> fred;";
const std::string expected(" "
"template < classname T > class Fred { Fred ( ) ; } ; "
"Fred<float> fred ; "
"class Fred<float> { Fred<float> ( ) ; }");
ASSERT_EQUALS(expected, sizeof_(code));
}
void namespaces() void namespaces()
{ {