Merge pull request #877 from nasa/char_sized_enums

Add support for char-sized enums
This commit is contained in:
dbankieris 2019-10-04 12:21:31 -05:00 committed by GitHub
commit 5e11a40a69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -9,7 +9,7 @@ EnumDataType::EnumDataType( EnumDictionary * enumDictionary,
std::string name,
size_t enumSize) {
if ((enumSize == sizeof(int)) || (enumSize == sizeof(short))) {
if ((enumSize == sizeof(int)) || (enumSize == sizeof(short) || (enumSize == sizeof(char))) {
this->enumSize = enumSize;
} // FIXME: else throw?
@ -107,6 +107,8 @@ void EnumDataType::clearValue(void * address) const {
*(int*)address = 0;
} else if (enumSize == sizeof(short)) {
*(short*)address = 0;
} else if (enumSize == sizeof(char)) {
*(char*)address = 0;
} else {
std::cerr << "ERROR: Enumeration of size " << enumSize << "is not supported.";
}
@ -121,6 +123,8 @@ void EnumDataType::assignValue(void * address, Value * value) const {
*(int*)address = numeric_value_p->getIntegerValue();
} else if (enumSize == sizeof(short)) {
*(short*)address = numeric_value_p->getIntegerValue();
} else if (enumSize == sizeof(char)) {
*(char*)address = numeric_value_p->getIntegerValue();
} else {
std::cerr << "ERROR: Enumeration of size " << enumSize << "is not supported.";
}
@ -137,6 +141,8 @@ void EnumDataType::printValue(std::ostream &s, void *address) const {
value = *(int*)address;
} else if (enumSize == sizeof(short)) {
value = *(short*)address;
} else if (enumSize == sizeof(char)) {
value = *(char*)address;
} else {
std::cerr << "ERROR: Enumeration of size " << enumSize << "is not supported.";
}

View File

@ -114,6 +114,14 @@ int Trick::MemoryManager::assign_recursive(void* base_addr, ATTRIBUTES* attr, in
<< " = " << *(short*)assign_addr << ";" << std::endl;
std::cout.flush();
}
} else if ((size_t)attr->size == sizeof(char)) {
assign_addr = (char*)base_addr + offset * sizeof(char);
*(char *)assign_addr = vval_char(v_tree->v_data);
if (debug_level) {
std::cout << std::endl << "Assignment (Enum): *(char*)" << (void*)assign_addr
<< " = " << *(char*)assign_addr << ";" << std::endl;
std::cout.flush();
}
} else {
std::stringstream message;
message << "Enumeration of size " << attr->size << " is not supported.";