ValueType: Handle void pointers
This commit is contained in:
parent
bd1037e95b
commit
c5c386ceb8
|
@ -3799,6 +3799,8 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype)
|
||||||
valuetype->sign = ValueType::Sign::UNSIGNED;
|
valuetype->sign = ValueType::Sign::UNSIGNED;
|
||||||
if (type->str() == "const")
|
if (type->str() == "const")
|
||||||
valuetype->constness |= (1 << (valuetype->pointer - pointer0));
|
valuetype->constness |= (1 << (valuetype->pointer - pointer0));
|
||||||
|
else if (type->str() == "void")
|
||||||
|
valuetype->type = ValueType::Type::VOID;
|
||||||
else if (type->str() == "bool")
|
else if (type->str() == "bool")
|
||||||
valuetype->type = ValueType::Type::BOOL;
|
valuetype->type = ValueType::Type::BOOL;
|
||||||
else if (type->str() == "char")
|
else if (type->str() == "char")
|
||||||
|
@ -3901,7 +3903,9 @@ std::string ValueType::str() const
|
||||||
std::string ret;
|
std::string ret;
|
||||||
if (constness & 1)
|
if (constness & 1)
|
||||||
ret = " const";
|
ret = " const";
|
||||||
if (isIntegral()) {
|
if (type == VOID)
|
||||||
|
ret += " void";
|
||||||
|
else if (isIntegral()) {
|
||||||
if (sign == SIGNED)
|
if (sign == SIGNED)
|
||||||
ret += " signed";
|
ret += " signed";
|
||||||
else if (sign == UNSIGNED)
|
else if (sign == UNSIGNED)
|
||||||
|
|
|
@ -1051,7 +1051,7 @@ private:
|
||||||
class CPPCHECKLIB ValueType {
|
class CPPCHECKLIB ValueType {
|
||||||
public:
|
public:
|
||||||
enum Sign {UNKNOWN_SIGN, SIGNED, UNSIGNED} sign;
|
enum Sign {UNKNOWN_SIGN, SIGNED, UNSIGNED} sign;
|
||||||
enum Type {UNKNOWN_TYPE, NONSTD, BOOL, CHAR, SHORT, INT, LONG, LONGLONG, FLOAT, DOUBLE, LONGDOUBLE} type;
|
enum Type {UNKNOWN_TYPE, NONSTD, VOID, BOOL, CHAR, SHORT, INT, LONG, LONGLONG, FLOAT, DOUBLE, LONGDOUBLE} type;
|
||||||
unsigned int pointer; // 0=>not pointer, 1=>*, 2=>**, 3=>***, etc
|
unsigned int pointer; // 0=>not pointer, 1=>*, 2=>**, 3=>***, etc
|
||||||
unsigned int constness; // bit 0=data, bit 1=*, bit 2=**
|
unsigned int constness; // bit 0=data, bit 1=*, bit 2=**
|
||||||
const Scope *typeScope;
|
const Scope *typeScope;
|
||||||
|
|
|
@ -3044,6 +3044,7 @@ private:
|
||||||
ASSERT_EQUALS("const short *", typeOf("L\"hello\" + 1", "+"));
|
ASSERT_EQUALS("const short *", typeOf("L\"hello\" + 1", "+"));
|
||||||
|
|
||||||
// Variable calculations
|
// Variable calculations
|
||||||
|
ASSERT_EQUALS("void *", typeOf("void *p; a = p + 1;", "+"));
|
||||||
ASSERT_EQUALS("int", typeOf("int x; a = x + 1;", "+"));
|
ASSERT_EQUALS("int", typeOf("int x; a = x + 1;", "+"));
|
||||||
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;", "+"));
|
||||||
|
@ -3061,10 +3062,12 @@ private:
|
||||||
ASSERT_EQUALS("int", typeOf("struct X {int i;}; void f(struct X x) { x.i }", "."));
|
ASSERT_EQUALS("int", typeOf("struct X {int i;}; void f(struct X x) { x.i }", "."));
|
||||||
|
|
||||||
// array..
|
// array..
|
||||||
|
ASSERT_EQUALS("void * *", typeOf("void * x[10]; a = x + 0;", "+"));
|
||||||
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..
|
// cast..
|
||||||
|
ASSERT_EQUALS("void *", typeOf("a = (void *)0;", "("));
|
||||||
ASSERT_EQUALS("char", typeOf("a = (char)32;", "("));
|
ASSERT_EQUALS("char", typeOf("a = (char)32;", "("));
|
||||||
ASSERT_EQUALS("long", typeOf("a = (long)32;", "("));
|
ASSERT_EQUALS("long", typeOf("a = (long)32;", "("));
|
||||||
ASSERT_EQUALS("long", typeOf("a = (long int)32;", "("));
|
ASSERT_EQUALS("long", typeOf("a = (long int)32;", "("));
|
||||||
|
|
Loading…
Reference in New Issue