SymbolDatabase: Better handling of valuetypes in AST
This commit is contained in:
parent
30a942af0b
commit
f35c24d4af
|
@ -3709,11 +3709,11 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype)
|
||||||
valuetype->sign = ValueType::Sign::UNKNOWN_SIGN;
|
valuetype->sign = ValueType::Sign::UNKNOWN_SIGN;
|
||||||
valuetype->type = ValueType::Type::UNKNOWN_TYPE;
|
valuetype->type = ValueType::Type::UNKNOWN_TYPE;
|
||||||
while (Token::Match(type, "%name%|*|&") && !type->variable()) {
|
while (Token::Match(type, "%name%|*|&") && !type->variable()) {
|
||||||
if (type->str() == "signed")
|
if (type->isSigned())
|
||||||
valuetype->sign = ValueType::Sign::SIGNED;
|
valuetype->sign = ValueType::Sign::SIGNED;
|
||||||
else if (type->str() == "unsigned")
|
else if (type->isUnsigned())
|
||||||
valuetype->sign = ValueType::Sign::UNSIGNED;
|
valuetype->sign = ValueType::Sign::UNSIGNED;
|
||||||
else if (type->str() == "bool")
|
if (type->str() == "bool")
|
||||||
valuetype->type = ValueType::Type::BOOL;
|
valuetype->type = ValueType::Type::BOOL;
|
||||||
else if (type->str() == "char")
|
else if (type->str() == "char")
|
||||||
valuetype->type = ValueType::Type::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);
|
::setValueType(tok, ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, 1U);
|
||||||
else if (tok->str() == "(") {
|
else if (tok->str() == "(") {
|
||||||
// cast
|
// cast
|
||||||
if (!tok->astOperand2() && !Token::Match(tok, "( %name%")) {
|
if (!tok->astOperand2() && Token::Match(tok, "( %name%")) {
|
||||||
ValueType valuetype;
|
ValueType valuetype;
|
||||||
if (Token::simpleMatch(parsedecl(tok->next(), &valuetype), ")"))
|
if (Token::simpleMatch(parsedecl(tok->next(), &valuetype), ")"))
|
||||||
::setValueType(tok, valuetype.sign, valuetype.type, valuetype.pointer);
|
::setValueType(tok, valuetype.sign, valuetype.type, valuetype.pointer);
|
||||||
|
|
|
@ -2969,12 +2969,17 @@ private:
|
||||||
ASSERT_EQUALS("char", typeOf("*\"hello\"", "*"));
|
ASSERT_EQUALS("char", typeOf("*\"hello\"", "*"));
|
||||||
|
|
||||||
// Variable calculations
|
// 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("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..
|
// array..
|
||||||
ASSERT_EQUALS("int*", typeOf("int x[10]; a = x + 1;", "+"));
|
ASSERT_EQUALS("int*", typeOf("int x[10]; a = x + 1;", "+"));
|
||||||
ASSERT_EQUALS("int", typeOf("int x[10]; a = x[0] + 1;", "+"));
|
ASSERT_EQUALS("int", typeOf("int x[10]; a = x[0] + 1;", "+"));
|
||||||
|
|
||||||
|
// cast..
|
||||||
|
ASSERT_EQUALS("char", typeOf("a = (char)32;", "("));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue