Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,28 +897,47 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
} else if (functionnodename == "returnValue") {
if (const char *expr = functionnode->GetText())
mData->mReturnValue[name] = expr;
if (const char *type = functionnode->Attribute("type"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this original code is more natural and readable imho than the new code. The Ir benefit is small. Do you measure a full analysis of a project or just analysis of some file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I measured the start-up only. Like I said it will mainly help the tests where we load a lot of libraries. It's a 2% gain and more is possible.

mData->mReturnValueType[name] = type;
if (const char *container = functionnode->Attribute("container"))
mData->mReturnValueContainer[name] = strToInt<int>(container);
// cppcheck-suppress shadowFunction - TODO: fix this
if (const char *unknownReturnValues = functionnode->Attribute("unknownValues")) {
if (std::strcmp(unknownReturnValues, "all") == 0) {
std::vector<MathLib::bigint> values{LLONG_MIN, LLONG_MAX};
mData->mUnknownReturnValues[name] = std::move(values);
for (const auto* attr = functionnode->FirstAttribute(); attr; attr = attr->Next())
{
const char* const attr_n = attr->Name();
if (strcmp(attr_n, "type") == 0)
mData->mReturnValueType[name] = attr->Value();
else if (strcmp(attr_n, "container") == 0)
mData->mReturnValueContainer[name] = strToInt<int>(attr->Value()); // TODO: use IntValue()?
else if (strcmp(attr_n, "unknownValues") == 0) {
if (std::strcmp(attr->Value(), "all") == 0) {
std::vector<MathLib::bigint> values{LLONG_MIN, LLONG_MAX};
mData->mUnknownReturnValues[name] = std::move(values);
}
}
}
} else if (functionnodename == "arg") {
const char* argNrString = functionnode->Attribute("nr");
const char* argNrString = nullptr;
const char* defaultString = nullptr;
const char* argDirection = nullptr;
const char* argIndirect = nullptr;

for (const auto* attr = functionnode->FirstAttribute(); attr; attr = attr->Next())
{
const char* const attr_n = attr->Name();
if (strcmp(attr_n, "nr") == 0)
argNrString = attr->Value();
else if (strcmp(attr_n, "default") == 0)
defaultString = attr->Value();
else if (strcmp(attr_n, "direction") == 0)
argDirection = attr->Value();
else if (strcmp(attr_n, "indirect") == 0)
argIndirect = attr->Value();
}

if (!argNrString)
return Error(ErrorCode::MISSING_ATTRIBUTE, "nr");
const bool bAnyArg = strcmp(argNrString, "any") == 0;
const bool bVariadicArg = strcmp(argNrString, "variadic") == 0;
const int nr = (bAnyArg || bVariadicArg) ? -1 : strToInt<int>(argNrString);
ArgumentChecks &ac = func.argumentChecks[nr];
ac.optional = functionnode->Attribute("default") != nullptr;
ac.optional = defaultString != nullptr;
ac.variadic = bVariadicArg;
const char * const argDirection = functionnode->Attribute("direction");
if (argDirection) {
const size_t argDirLen = strlen(argDirection);
ArgumentChecks::Direction dir = ArgumentChecks::Direction::DIR_UNKNOWN;
Expand All @@ -929,8 +948,8 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
} else if (!strncmp(argDirection, "inout", argDirLen)) {
dir = ArgumentChecks::Direction::DIR_INOUT;
}
if (const char* const argIndirect = functionnode->Attribute("indirect")) {
const int indirect = strToInt<int>(argIndirect);
if (argIndirect) {
const int indirect = strToInt<int>(argIndirect); // TODO: use IntValue()?
ac.direction[indirect] = dir; // TODO: handle multiple directions/indirect levels
}
else
Expand Down
Loading