Library: Added 'podtype' element. Partial fix for #5623

This commit is contained in:
Daniel Marjamäki 2014-06-08 12:09:00 +02:00
parent e1513090e2
commit 9e81fa04b2
3 changed files with 41 additions and 1 deletions

View File

@ -309,6 +309,20 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
}
}
else if (strcmp(node->Name(), "podtype") == 0) {
const char * const name = node->Attribute("name");
if (!name)
return Error(MISSING_ATTRIBUTE, "name");
PodType podType = {0};
const char * const size = node->Attribute("sizeof");
if (size)
podType.size = atoi(size);
const char * const sign = node->Attribute("sign");
if (sign)
podType.sign = *sign;
podtypes[name] = podType;
}
else
return Error(BAD_ELEMENT, node->Name());
}

View File

@ -290,6 +290,15 @@ public:
std::set<std::string> returnuninitdata;
std::vector<std::string> defines; // to provide some library defines
struct PodType {
unsigned int size;
char sign;
};
const struct PodType *podtype(const std::string &name) const {
const std::map<std::string, struct PodType>::const_iterator it = podtypes.find(name);
return (it != podtypes.end()) ? &(it->second) : nullptr;
}
private:
class ExportedFunctions {
public:
@ -359,7 +368,7 @@ private:
std::map<std::string, std::set<std::string> > _importers; // keywords that import variables/functions
std::map<std::string,int> _reflection; // invocation of reflection
std::map<std::string, std::pair<bool, bool> > _formatstr; // Parameters for format string checking
std::map<std::string, struct PodType> podtypes; // pod types
const ArgumentChecks * getarg(const std::string &functionName, int argnr) const;

View File

@ -37,6 +37,7 @@ private:
TEST_CASE(memory);
TEST_CASE(memory2); // define extra "free" allocation functions
TEST_CASE(resource);
TEST_CASE(podtype);
}
void empty() const {
@ -210,6 +211,22 @@ private:
ASSERT(Library::isresource(library.alloc("CreateX")));
ASSERT_EQUALS(library.alloc("CreateX"), library.dealloc("DeleteX"));
}
void podtype() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <podtype name=\"s16\" sizeof=\"2\"/>\n"
"</def>";
tinyxml2::XMLDocument doc;
doc.Parse(xmldata, sizeof(xmldata));
Library library;
library.load(doc);
const struct Library::PodType *type = library.podtype("s16");
ASSERT_EQUALS(2U, type ? type->size : 0U);
ASSERT_EQUALS(0, type ? type->sign : '?');
}
};
REGISTER_TEST(TestLibrary)