ValueType: better handling of struct member

This commit is contained in:
Daniel Marjamäki 2015-12-30 11:36:46 +01:00
parent c5c386ceb8
commit fdcab8f1bb
2 changed files with 15 additions and 15 deletions

View File

@ -3676,27 +3676,23 @@ static void setValueType(Token *tok, const ValueType &valuetype)
return;
if (parent->str() == "[" && valuetype.pointer > 0U) {
setValueType(parent, ValueType(valuetype.sign,
valuetype.type,
valuetype.pointer - 1U,
valuetype.constness >> 1,
valuetype.originalTypeName));
ValueType vt(valuetype);
vt.pointer -= 1U;
vt.constness >>= 1;
setValueType(parent, vt);
return;
}
if (parent->str() == "*" && !parent->astOperand2() && valuetype.pointer > 0U) {
setValueType(parent, ValueType(valuetype.sign,
valuetype.type,
valuetype.pointer - 1U,
valuetype.constness >> 1,
valuetype.originalTypeName));
ValueType vt(valuetype);
vt.pointer -= 1U;
vt.constness >>= 1;
setValueType(parent, vt);
return;
}
if (parent->str() == "&" && !parent->astOperand2()) {
setValueType(parent, ValueType(valuetype.sign,
valuetype.type,
valuetype.pointer + 1U,
valuetype.constness,
valuetype.originalTypeName));
ValueType vt(valuetype);
vt.pointer += 1U;
setValueType(parent, vt);
return;
}

View File

@ -3084,6 +3084,10 @@ private:
// function call..
ASSERT_EQUALS("int", typeOf("int a(int); a(5);", "( 5"));
ASSERT_EQUALS("unsigned long", typeOf("sizeof(x);", "("));
// struct member..
ASSERT_EQUALS("int", typeOf("struct AB { int a; int b; } ab; x = ab.a;", "."));
ASSERT_EQUALS("int", typeOf("struct AB { int a; int b; } *ab; x = ab[1].a;", "."));
}
};