Library: added 'stdtype' attribute in <podtype> element so we can configure standard types better

This commit is contained in:
Daniel Marjamäki 2019-09-29 16:48:25 +02:00
parent 40c3e68e07
commit 69a54b0ee9
5 changed files with 56 additions and 15 deletions

View File

@ -442,6 +442,18 @@
<element name="podtype">
<attribute name="name"><ref name="DATA-EXTNAME"/></attribute>
<optional>
<attribute name="stdtype">
<choice>
<value>bool</value>
<value>char</value>
<value>short</value>
<value>int</value>
<value>long</value>
<value>long long</value>
</choice>
</attribute>
</optional>
<optional>
<attribute name="size">
<choice>

View File

@ -7833,21 +7833,21 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
<podtype name="jmp_buf"/>
<podtype name="std::streamsize,streamsize" sign="s"/>
<podtype name="std::streamoff,streamoff" sign="s"/>
<podtype name="std::atomic_bool"/>
<podtype name="std::atomic_char"/>
<podtype name="std::atomic_schar"/>
<podtype name="std::atomic_uchar"/>
<podtype name="std::atomic_short"/>
<podtype name="std::atomic_ushort"/>
<podtype name="std::atomic_int"/>
<podtype name="std::atomic_uint"/>
<podtype name="std::atomic_long"/>
<podtype name="std::atomic_ulong"/>
<podtype name="std::atomic_llong"/>
<podtype name="std::atomic_ullong"/>
<podtype name="std::atomic_char16_t"/>
<podtype name="std::atomic_char32_t"/>
<podtype name="std::atomic_wchar_t"/>
<podtype name="std::atomic_bool" stdtype="bool"/>
<podtype name="std::atomic_char" stdtype="char"/>
<podtype name="std::atomic_schar" stdtype="char" sign="s"/>
<podtype name="std::atomic_uchar" stdtype="char" sign="u"/>
<podtype name="std::atomic_short" stdtype="short" sign="s"/>
<podtype name="std::atomic_ushort" stdtype="short" sign="u"/>
<podtype name="std::atomic_int" stdtype="int" sign="s"/>
<podtype name="std::atomic_uint" stdtype="int" sign="u"/>
<podtype name="std::atomic_long" stdtype="long" sign="s"/>
<podtype name="std::atomic_ulong" stdtype="long" sign="u"/>
<podtype name="std::atomic_llong" stdtype="long long" sign="s"/>
<podtype name="std::atomic_ullong" stdtype="long long" sign="u"/>
<podtype name="std::atomic_char16_t" size="2"/>
<podtype name="std::atomic_char32_t" size="4"/>
<podtype name="std::atomic_wchar_t" size="2"/>
<podtype name="std::atomic_int_least8_t"/>
<podtype name="std::atomic_uint_least8_t"/>
<podtype name="std::atomic_int_least16_t"/>

View File

@ -513,6 +513,22 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
if (!name)
return Error(MISSING_ATTRIBUTE, "name");
PodType podType = {0};
podType.stdtype = PodType::NO;
const char * const stdtype = node->Attribute("stdtype");
if (stdtype) {
if (std::strcmp(stdtype, "bool") == 0)
podType.stdtype = PodType::BOOL;
else if (std::strcmp(stdtype, "char") == 0)
podType.stdtype = PodType::CHAR;
else if (std::strcmp(stdtype, "short") == 0)
podType.stdtype = PodType::SHORT;
else if (std::strcmp(stdtype, "int") == 0)
podType.stdtype = PodType::INT;
else if (std::strcmp(stdtype, "long") == 0)
podType.stdtype = PodType::LONG;
else if (std::strcmp(stdtype, "long long") == 0)
podType.stdtype = PodType::LONGLONG;
}
const char * const size = node->Attribute("size");
if (size)
podType.size = atoi(size);

View File

@ -412,6 +412,7 @@ public:
struct PodType {
unsigned int size;
char sign;
enum { NO, BOOL, CHAR, SHORT, INT, LONG, LONGLONG } stdtype;
};
const struct PodType *podtype(const std::string &name) const {
const std::map<std::string, struct PodType>::const_iterator it = mPodTypes.find(name);

View File

@ -5682,6 +5682,18 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings *sett
type = ValueType::Type::LONG;
else if (podtype->size == settings->sizeof_long_long)
type = ValueType::Type::LONGLONG;
else if (podtype->stdtype == Library::PodType::BOOL)
type = ValueType::Type::BOOL;
else if (podtype->stdtype == Library::PodType::CHAR)
type = ValueType::Type::CHAR;
else if (podtype->stdtype == Library::PodType::SHORT)
type = ValueType::Type::SHORT;
else if (podtype->stdtype == Library::PodType::INT)
type = ValueType::Type::INT;
else if (podtype->stdtype == Library::PodType::LONG)
type = ValueType::Type::LONG;
else if (podtype->stdtype == Library::PodType::LONGLONG)
type = ValueType::Type::LONGLONG;
else
type = ValueType::Type::UNKNOWN_INT;
sign = (podtype->sign == 'u') ? ValueType::UNSIGNED : ValueType::SIGNED;