ValueType: struct member

This commit is contained in:
Daniel Marjamäki 2015-10-11 10:48:08 +02:00
parent 9738cc66eb
commit 5b082aa799
3 changed files with 36 additions and 10 deletions

View File

@ -3650,6 +3650,18 @@ bool SymbolDatabase::isReservedName(const std::string& iName) const
return (c_keywords.find(iName) != c_keywords.cend()) || (isCPP() && (cpp_keywords.find(iName) != cpp_keywords.cend()));
}
static const Token * parsedecl(const Token *type, ValueType * const valuetype);
static void setValueType(Token *tok, const ValueType &valuetype);
static void setValueType(Token *tok, const Variable &var)
{
ValueType valuetype;
valuetype.pointer = var.dimensions().size();
valuetype.typeScope = var.typeScope();
if (parsedecl(var.typeStartToken(), &valuetype))
::setValueType(tok, valuetype);
}
static void setValueType(Token *tok, const ValueType &valuetype)
{
tok->setValueType(new ValueType(valuetype));
@ -3684,6 +3696,22 @@ static void setValueType(Token *tok, const ValueType &valuetype)
return;
}
if (parent->str() == "." &&
valuetype.typeScope &&
parent->astOperand2() && parent->astOperand2()->isName() && !parent->astOperand2()->valueType()) {
const std::string &name = parent->astOperand2()->str();
const Scope *typeScope = parent->astOperand1()->valueType()->typeScope;
if (!typeScope)
return;
for (std::list<Variable>::const_iterator it = typeScope->varlist.begin(); it != typeScope->varlist.end(); ++it) {
const Variable &var = *it;
if (var.nameToken()->str() == name) {
setValueType(parent, var);
return;
}
}
}
if (parent->astOperand2() && !parent->astOperand2()->valueType())
return;
const ValueType *vt1 = parent->astOperand1()->valueType();
@ -3842,11 +3870,7 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens)
::setValueType(tok, valuetype);
}
} else if (tok->variable()) {
const Variable *var = tok->variable();
ValueType valuetype;
valuetype.pointer = var->dimensions().size();
if (parsedecl(var->typeStartToken(), &valuetype))
::setValueType(tok, valuetype);
setValueType(tok, *tok->variable());
}
}
}

View File

@ -1045,13 +1045,14 @@ public:
enum Type {UNKNOWN_TYPE, NONSTD, BOOL, CHAR, SHORT, INT, LONG, LONGLONG, FLOAT, DOUBLE, LONGDOUBLE} type;
unsigned int pointer; // 0=>not pointer, 1=>*, 2=>**, 3=>***, etc
unsigned int constness; // bit 0=data, bit 1=*, bit 2=**
const Scope *typeScope;
std::string originalTypeName;
ValueType() : sign(UNKNOWN_SIGN), type(UNKNOWN_TYPE), pointer(0U), constness(0U) {}
ValueType(const ValueType &vt) : sign(vt.sign), type(vt.type), pointer(vt.pointer), constness(vt.constness), originalTypeName(vt.originalTypeName) {}
ValueType(enum Sign s, enum Type t, unsigned int p) : sign(s), type(t), pointer(p), constness(0U) {}
ValueType(enum Sign s, enum Type t, unsigned int p, unsigned int c) : sign(s), type(t), pointer(p), constness(c) {}
ValueType(enum Sign s, enum Type t, unsigned int p, unsigned int c, const std::string &otn) : sign(s), type(t), pointer(p), constness(c), originalTypeName(otn) {}
ValueType() : sign(UNKNOWN_SIGN), type(UNKNOWN_TYPE), pointer(0U), constness(0U), typeScope(nullptr) {}
ValueType(const ValueType &vt) : sign(vt.sign), type(vt.type), pointer(vt.pointer), constness(vt.constness), typeScope(vt.typeScope), originalTypeName(vt.originalTypeName) {}
ValueType(enum Sign s, enum Type t, unsigned int p) : sign(s), type(t), pointer(p), constness(0U), typeScope(nullptr) {}
ValueType(enum Sign s, enum Type t, unsigned int p, unsigned int c) : sign(s), type(t), pointer(p), constness(c), typeScope(nullptr) {}
ValueType(enum Sign s, enum Type t, unsigned int p, unsigned int c, const std::string &otn) : sign(s), type(t), pointer(p), constness(c), typeScope(nullptr), originalTypeName(otn) {}
bool isIntegral() const {
return (type >= ValueType::Type::BOOL && type <= ValueType::Type::LONGLONG);

View File

@ -2992,6 +2992,7 @@ private:
ASSERT_EQUALS("int *", typeOf("int x; a = &x;", "&"));
ASSERT_EQUALS("long double", typeOf("long double x; dostuff(x,1);", "x ,"));
ASSERT_EQUALS("long double *", typeOf("long double x; dostuff(&x,1);", "& x ,"));
ASSERT_EQUALS("int", typeOf("struct X {int i;}; void f(struct X x) { x.i }", "."));
// array..
ASSERT_EQUALS("int *", typeOf("int x[10]; a = x + 1;", "+"));