typedefs: handle __typeof__
This commit is contained in:
parent
624ce205b9
commit
a09c221014
|
@ -818,6 +818,7 @@ void Tokenizer::simplifyTypedef()
|
|||
bool ptrToArray = false;
|
||||
bool refToArray = false;
|
||||
bool ptrMember = false;
|
||||
bool typeOf = false;
|
||||
Token *namespaceStart = 0;
|
||||
Token *namespaceEnd = 0;
|
||||
|
||||
|
@ -959,6 +960,18 @@ void Tokenizer::simplifyTypedef()
|
|||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// typeof
|
||||
else if (Token::simpleMatch(tok->tokAt(offset - 1), "__typeof__ (") &&
|
||||
Token::Match(tok->tokAt(offset)->link(), ") %type% ;"))
|
||||
{
|
||||
argStart = tok->tokAt(offset);
|
||||
argEnd = tok->tokAt(offset)->link();
|
||||
typeName = tok->tokAt(offset)->link()->next();
|
||||
tok = typeName->next();
|
||||
typeOf = true;
|
||||
}
|
||||
|
||||
else if (Token::Match(tok->tokAt(offset), "( *|&| const|volatile| const|volatile| %type% ) ("))
|
||||
{
|
||||
functionPtr = tok->tokAt(offset + 1)->str() == "*";
|
||||
|
@ -1592,6 +1605,36 @@ void Tokenizer::simplifyTypedef()
|
|||
tok2 = tok2->next();
|
||||
Token::createMutualLinks(tok2, tok3);
|
||||
}
|
||||
else if (typeOf)
|
||||
{
|
||||
tok2->insertToken("(");
|
||||
tok2 = tok2->next();
|
||||
Token *tok3 = tok2;
|
||||
Token *nextArgTok;
|
||||
std::stack<Token *> argLinks;
|
||||
for (nextArgTok = argStart->next(); nextArgTok != argEnd; nextArgTok = nextArgTok->next())
|
||||
{
|
||||
tok2->insertToken(nextArgTok->strAt(0));
|
||||
tok2 = tok2->next();
|
||||
|
||||
// Check for links and fix them up
|
||||
if (tok2->str() == "(" || tok2->str() == "[")
|
||||
argLinks.push(tok2);
|
||||
if (tok2->str() == ")" || tok2->str() == "]")
|
||||
{
|
||||
Token * link = argLinks.top();
|
||||
|
||||
tok2->link(link);
|
||||
link->link(tok2);
|
||||
|
||||
argLinks.pop();
|
||||
}
|
||||
}
|
||||
tok2->insertToken(")");
|
||||
tok2 = tok2->next();
|
||||
Token::createMutualLinks(tok2, tok3);
|
||||
|
||||
}
|
||||
else if (tok2->tokAt(2) && tok2->tokAt(2)->str() == "[")
|
||||
{
|
||||
while (tok2->tokAt(2) && tok2->tokAt(2)->str() == "[")
|
||||
|
|
|
@ -219,6 +219,7 @@ private:
|
|||
TEST_CASE(simplifyTypedef61); // ticket #2074 and 2075
|
||||
TEST_CASE(simplifyTypedef62); // ticket #2082
|
||||
TEST_CASE(simplifyTypedef63); // ticket #2175 'typedef float x[3];'
|
||||
TEST_CASE(simplifyTypedef64);
|
||||
|
||||
TEST_CASE(simplifyTypedefFunction1);
|
||||
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
||||
|
@ -4528,6 +4529,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void simplifyTypedef64()
|
||||
{
|
||||
const char code[] = "typedef __typeof__(__type1() + __type2()) __type;"
|
||||
"__type t;\n";
|
||||
const std::string actual(sizeof_(code));
|
||||
ASSERT_EQUALS("; __typeof__ ( __type1 ( ) + __type2 ( ) ) t ;", actual);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void simplifyTypedefFunction1()
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue