Skip to content

Commit

Permalink
abstract-tree: introduce getValueOf() helper
Browse files Browse the repository at this point in the history
... to simplify the code that used its implementation
  • Loading branch information
kdudka committed Feb 16, 2021
1 parent da9a6a8 commit 0bb7083
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/abstract-tree.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,14 @@ inline T valueOf(const pt::ptree &node, const char *path, const T &defVal)
return opt.get_value_or(defVal);
}

inline std::string getStringValue(const pt::ptree *const node)
{
return node->get_value<std::string>();
}

inline std::string getStringValue(const pt::ptree::const_iterator it)
{
return getStringValue(&it->second);
}

#endif /* H_GUARD_ABSTRACT_TREE_H */
22 changes: 11 additions & 11 deletions src/xml-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool /* continue */ skipLdArgs(
continue;
}

const std::string argVal = (*pIt)->second.get_value<std::string>();
const std::string argVal = getStringValue(*pIt);
if (argVal == "--preload")
goto skip_arg;

Expand Down Expand Up @@ -103,7 +103,7 @@ void readExeArgs(
break;

*pArgs += " ";
*pArgs += it->second.get_value<std::string>();
*pArgs += getStringValue(it);
}
}

Expand Down Expand Up @@ -144,12 +144,12 @@ std::string readMsg(const pt::ptree &defNode)
const pt::ptree *whatNode;
if (findChildOf(&whatNode, defNode, "what"))
// message found in <what>...</what>
return whatNode->get_value<std::string>();
return getStringValue(whatNode);

if (findChildOf(&whatNode, defNode, "xwhat")
&& findChildOf(&whatNode, *whatNode, "text"))
// message found in <xwhat><text>...</text></xwhat>
return whatNode->get_value<std::string>();
return getStringValue(whatNode);

// message not found
return "<unknown>";
Expand Down Expand Up @@ -195,7 +195,7 @@ void readStack(Defect *pDef, const pt::ptree &stackNode)
const pt::ptree *fileNode;
if (findChildOf(&fileNode, frameNode, "file")) {
// read absolute path of the source file
noteEvt.fileName = fileNode->get_value<std::string>();
noteEvt.fileName = getStringValue(fileNode);
const std::string dir = valueOf<std::string>(frameNode, "dir", "");
if (!dir.empty())
noteEvt.fileName = dir + "/" + noteEvt.fileName;
Expand All @@ -206,12 +206,12 @@ void readStack(Defect *pDef, const pt::ptree &stackNode)
}
else if (findChildOf(&fileNode, frameNode, "obj")) {
// pick path of the object file
noteEvt.fileName = fileNode->get_value<std::string>();
noteEvt.fileName = getStringValue(fileNode);
keyEventScore = 4;
}
else if (findChildOf(&fileNode, frameNode, "ip")) {
// pick address of the code in memory
noteEvt.fileName = fileNode->get_value<std::string>();
noteEvt.fileName = getStringValue(fileNode);
keyEventScore = 2;
}
else {
Expand Down Expand Up @@ -254,9 +254,9 @@ bool ValgrindTreeDecoder::readNode(Defect *pDef, pt::ptree::const_iterator defIt
keyEvent.msg = readMsg(defNode);

// read "kind" of the report
pt::ptree::const_assoc_iterator itKind = defNode.find("kind");
if (defNode.not_found() != itKind)
keyEvent.event += "[" + itKind->second.get_value<std::string>() + "]";
const std::string kind = valueOf<std::string>(defNode, "kind", "");
if (!kind.empty())
keyEvent.event += "[" + kind + "]";

// go through stack trace
const pt::ptree *stackNode;
Expand All @@ -270,7 +270,7 @@ bool ValgrindTreeDecoder::readNode(Defect *pDef, pt::ptree::const_iterator defIt
DefEvent auxEvent = def.events[def.keyEventIdx];
auxEvent.event = "note";
auxEvent.verbosityLevel = /* note */ 1;
auxEvent.msg = auxwhat->get_value<std::string>();
auxEvent.msg = getStringValue(auxwhat);
def.events.insert(def.events.begin() + def.keyEventIdx + 1, auxEvent);
}

Expand Down

0 comments on commit 0bb7083

Please sign in to comment.