diff --git a/lib/library.cpp b/lib/library.cpp index 199bc0ea4..da14983ac 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -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()); } diff --git a/lib/library.h b/lib/library.h index d75c50f76..3afce05f7 100644 --- a/lib/library.h +++ b/lib/library.h @@ -290,6 +290,15 @@ public: std::set returnuninitdata; std::vector 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::const_iterator it = podtypes.find(name); + return (it != podtypes.end()) ? &(it->second) : nullptr; + } + private: class ExportedFunctions { public: @@ -359,7 +368,7 @@ private: std::map > _importers; // keywords that import variables/functions std::map _reflection; // invocation of reflection std::map > _formatstr; // Parameters for format string checking - + std::map podtypes; // pod types const ArgumentChecks * getarg(const std::string &functionName, int argnr) const; diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index e036ca7fb..f580f3368 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -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[] = "\n" + "\n" + " \n" + ""; + 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)