SymbolDatabase: Better handling of valuetypes in AST

This commit is contained in:
Daniel Marjamäki 2015-10-04 23:27:58 +02:00
parent 30a942af0b
commit f35c24d4af
2 changed files with 10 additions and 5 deletions

View File

@ -3709,11 +3709,11 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype)
valuetype->sign = ValueType::Sign::UNKNOWN_SIGN;
valuetype->type = ValueType::Type::UNKNOWN_TYPE;
while (Token::Match(type, "%name%|*|&") && !type->variable()) {
if (type->str() == "signed")
if (type->isSigned())
valuetype->sign = ValueType::Sign::SIGNED;
else if (type->str() == "unsigned")
else if (type->isUnsigned())
valuetype->sign = ValueType::Sign::UNSIGNED;
else if (type->str() == "bool")
if (type->str() == "bool")
valuetype->type = ValueType::Type::BOOL;
else if (type->str() == "char")
valuetype->type = ValueType::Type::CHAR;
@ -3755,7 +3755,7 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens)
::setValueType(tok, ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, 1U);
else if (tok->str() == "(") {
// cast
if (!tok->astOperand2() && !Token::Match(tok, "( %name%")) {
if (!tok->astOperand2() && Token::Match(tok, "( %name%")) {
ValueType valuetype;
if (Token::simpleMatch(parsedecl(tok->next(), &valuetype), ")"))
::setValueType(tok, valuetype.sign, valuetype.type, valuetype.pointer);

View File

@ -2969,12 +2969,17 @@ private:
ASSERT_EQUALS("char", typeOf("*\"hello\"", "*"));
// Variable calculations
ASSERT_EQUALS("int", typeOf("int x; a = x + 1;", "+"));
ASSERT_EQUALS("int", typeOf("int x; a = x + 1;", "+"));
ASSERT_EQUALS("float", typeOf("float x; a = x + 1;", "+"));
ASSERT_EQUALS("signed int", typeOf("signed x; a = x + 1;", "x +"));
ASSERT_EQUALS("unsigned int", typeOf("unsigned x; a = x + 1;", "x +"));
// array..
ASSERT_EQUALS("int*", typeOf("int x[10]; a = x + 1;", "+"));
ASSERT_EQUALS("int", typeOf("int x[10]; a = x[0] + 1;", "+"));
// cast..
ASSERT_EQUALS("char", typeOf("a = (char)32;", "("));
}
};