SymbolDatabase: Refactoring
This commit is contained in:
parent
51b5f1c286
commit
995d875cb2
|
@ -4636,17 +4636,10 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
|
||||||
valuetype->sign = ValueType::Sign::UNSIGNED;
|
valuetype->sign = ValueType::Sign::UNSIGNED;
|
||||||
else
|
else
|
||||||
valuetype->sign = defaultSignedness;
|
valuetype->sign = defaultSignedness;
|
||||||
if (enum_type->str() == "char")
|
if (ValueType::Type t = ValueType::typeFromString(enum_type->str(), enum_type->isLong()))
|
||||||
valuetype->type = ValueType::Type::CHAR;
|
valuetype->type = t;
|
||||||
else if (enum_type->str() == "short")
|
else if (enum_type->isStandardType())
|
||||||
valuetype->type = ValueType::Type::SHORT;
|
|
||||||
else if (enum_type->str() == "int")
|
|
||||||
valuetype->type = ValueType::Type::INT;
|
|
||||||
else if (enum_type->str() == "long")
|
|
||||||
valuetype->type = enum_type->isLong() ? ValueType::Type::LONGLONG : ValueType::Type::LONG;
|
|
||||||
else if (enum_type->isStandardType()) {
|
|
||||||
valuetype->fromLibraryType(enum_type->str(), settings);
|
valuetype->fromLibraryType(enum_type->str(), settings);
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
valuetype->type = ValueType::Type::INT;
|
valuetype->type = ValueType::Type::INT;
|
||||||
} else
|
} else
|
||||||
|
@ -4658,22 +4651,8 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
|
||||||
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")
|
else if (ValueType::Type t = ValueType::typeFromString(type->str(), type->isLong()))
|
||||||
valuetype->type = ValueType::Type::VOID;
|
valuetype->type = t;
|
||||||
else if (type->str() == "bool")
|
|
||||||
valuetype->type = ValueType::Type::BOOL;
|
|
||||||
else if (type->str() == "char")
|
|
||||||
valuetype->type = ValueType::Type::CHAR;
|
|
||||||
else if (type->str() == "short")
|
|
||||||
valuetype->type = ValueType::Type::SHORT;
|
|
||||||
else if (type->str() == "int")
|
|
||||||
valuetype->type = ValueType::Type::INT;
|
|
||||||
else if (type->str() == "long")
|
|
||||||
valuetype->type = type->isLong() ? ValueType::Type::LONGLONG : ValueType::Type::LONG;
|
|
||||||
else if (type->str() == "float")
|
|
||||||
valuetype->type = ValueType::Type::FLOAT;
|
|
||||||
else if (type->str() == "double")
|
|
||||||
valuetype->type = type->isLong() ? ValueType::Type::LONGDOUBLE : ValueType::Type::DOUBLE;
|
|
||||||
else if (type->str() == "auto") {
|
else if (type->str() == "auto") {
|
||||||
if (!type->valueType())
|
if (!type->valueType())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -4872,15 +4851,9 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, const Sett
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
vt.pointer = 1;
|
vt.pointer = 1;
|
||||||
const Token * const typeTok = tok->next();
|
const Token * const typeTok = tok->next();
|
||||||
// TODO: Reuse code in parsedecl
|
vt.type = ValueType::typeFromString(typeTok->str(), typeTok->isLong());
|
||||||
if (typeTok->str() == "char")
|
if (vt.type == ValueType::Type::UNKNOWN_TYPE && typeTok->isStandardType())
|
||||||
vt.type = ValueType::Type::CHAR;
|
vt.fromLibraryType(typeTok->str(), settings);
|
||||||
else if (typeTok->str() == "short")
|
|
||||||
vt.type = ValueType::Type::SHORT;
|
|
||||||
else if (typeTok->str() == "int")
|
|
||||||
vt.type = ValueType::Type::INT;
|
|
||||||
else if (typeTok->str() == "long")
|
|
||||||
vt.type = ValueType::Type::LONG;
|
|
||||||
if (typeTok->isUnsigned())
|
if (typeTok->isUnsigned())
|
||||||
vt.sign = ValueType::Sign::UNSIGNED;
|
vt.sign = ValueType::Sign::UNSIGNED;
|
||||||
else if (typeTok->isSigned())
|
else if (typeTok->isSigned())
|
||||||
|
@ -4901,6 +4874,27 @@ ValueType ValueType::parseDecl(const Token *type, const Settings *settings)
|
||||||
return vt;
|
return vt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ValueType::Type ValueType::typeFromString(const std::string &typestr, bool longType)
|
||||||
|
{
|
||||||
|
if (typestr == "void")
|
||||||
|
return ValueType::Type::VOID;
|
||||||
|
if (typestr == "bool")
|
||||||
|
return ValueType::Type::BOOL;
|
||||||
|
if (typestr== "char")
|
||||||
|
return ValueType::Type::CHAR;
|
||||||
|
if (typestr == "short")
|
||||||
|
return ValueType::Type::SHORT;
|
||||||
|
if (typestr == "int")
|
||||||
|
return ValueType::Type::INT;
|
||||||
|
if (typestr == "long")
|
||||||
|
return longType ? ValueType::Type::LONGLONG : ValueType::Type::LONG;
|
||||||
|
if (typestr == "float")
|
||||||
|
return ValueType::Type::FLOAT;
|
||||||
|
if (typestr == "double")
|
||||||
|
return longType ? ValueType::Type::LONGDOUBLE : ValueType::Type::DOUBLE;
|
||||||
|
return ValueType::Type::UNKNOWN_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
bool ValueType::fromLibraryType(const std::string &typestr, const Settings *settings)
|
bool ValueType::fromLibraryType(const std::string &typestr, const Settings *settings)
|
||||||
{
|
{
|
||||||
const Library::PodType* podtype = settings->library.podtype(typestr);
|
const Library::PodType* podtype = settings->library.podtype(typestr);
|
||||||
|
|
|
@ -1173,6 +1173,8 @@ public:
|
||||||
|
|
||||||
static ValueType parseDecl(const Token *type, const Settings *settings);
|
static ValueType parseDecl(const Token *type, const Settings *settings);
|
||||||
|
|
||||||
|
static Type typeFromString(const std::string &typestr, bool longType);
|
||||||
|
|
||||||
bool isIntegral() const {
|
bool isIntegral() const {
|
||||||
return (type >= ValueType::Type::BOOL && type <= ValueType::Type::UNKNOWN_INT);
|
return (type >= ValueType::Type::BOOL && type <= ValueType::Type::UNKNOWN_INT);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue