mirror of https://github.com/Icinga/icinga2.git
Clean up the DebugHint class
This commit is contained in:
parent
77b746841a
commit
ea729b2b6c
|
@ -188,10 +188,12 @@ void ObjectListCommand::PrintHints(std::ostream& fp, const Dictionary::Ptr& debu
|
||||||
|
|
||||||
Array::Ptr messages = debug_hints->Get("messages");
|
Array::Ptr messages = debug_hints->Get("messages");
|
||||||
|
|
||||||
ObjectLock olock(messages);
|
if (messages) {
|
||||||
|
ObjectLock olock(messages);
|
||||||
|
|
||||||
BOOST_FOREACH(const Value& msg, messages) {
|
BOOST_FOREACH(const Value& msg, messages) {
|
||||||
PrintHint(fp, msg, indent);
|
PrintHint(fp, msg, indent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -282,7 +282,8 @@ Value DictExpression::DoEvaluate(const Object::Ptr& context, DebugHint *dhint) c
|
||||||
|
|
||||||
Value SetExpression::DoEvaluate(const Object::Ptr& context, DebugHint *dhint) const
|
Value SetExpression::DoEvaluate(const Object::Ptr& context, DebugHint *dhint) const
|
||||||
{
|
{
|
||||||
DebugHint *sdhint = dhint;
|
DebugHint *psdhint = dhint;
|
||||||
|
DebugHint sdhint;
|
||||||
|
|
||||||
Value parent, object;
|
Value parent, object;
|
||||||
String index;
|
String index;
|
||||||
|
@ -291,8 +292,10 @@ Value SetExpression::DoEvaluate(const Object::Ptr& context, DebugHint *dhint) co
|
||||||
Expression *indexExpr = m_Indexer[i];
|
Expression *indexExpr = m_Indexer[i];
|
||||||
String tempindex = indexExpr->Evaluate(context, dhint);
|
String tempindex = indexExpr->Evaluate(context, dhint);
|
||||||
|
|
||||||
if (sdhint)
|
if (psdhint) {
|
||||||
sdhint = sdhint->GetChild(tempindex);
|
sdhint = psdhint->GetChild(tempindex);
|
||||||
|
psdhint = &sdhint;
|
||||||
|
}
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
parent = context;
|
parent = context;
|
||||||
|
@ -311,7 +314,7 @@ Value SetExpression::DoEvaluate(const Object::Ptr& context, DebugHint *dhint) co
|
||||||
LiteralExpression *eindex = MakeLiteral(tempindex);
|
LiteralExpression *eindex = MakeLiteral(tempindex);
|
||||||
|
|
||||||
IndexerExpression eip(eparent, eindex, m_DebugInfo);
|
IndexerExpression eip(eparent, eindex, m_DebugInfo);
|
||||||
object = eip.Evaluate(context, sdhint);
|
object = eip.Evaluate(context, psdhint);
|
||||||
|
|
||||||
if (i != m_Indexer.size() - 1 && object.IsEmpty()) {
|
if (i != m_Indexer.size() - 1 && object.IsEmpty()) {
|
||||||
object = new Dictionary();
|
object = new Dictionary();
|
||||||
|
@ -346,8 +349,8 @@ Value SetExpression::DoEvaluate(const Object::Ptr& context, DebugHint *dhint) co
|
||||||
|
|
||||||
SetField(parent, index, right);
|
SetField(parent, index, right);
|
||||||
|
|
||||||
if (sdhint)
|
if (psdhint)
|
||||||
sdhint->AddMessage("=", m_DebugInfo);
|
psdhint->AddMessage("=", m_DebugInfo);
|
||||||
|
|
||||||
return right;
|
return right;
|
||||||
}
|
}
|
||||||
|
@ -524,37 +527,6 @@ Value ForExpression::DoEvaluate(const Object::Ptr& context, DebugHint *dhint) co
|
||||||
return Empty;
|
return Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr DebugHint::ToDictionary(void) const
|
|
||||||
{
|
|
||||||
Dictionary::Ptr result = new Dictionary();
|
|
||||||
|
|
||||||
Array::Ptr messages = new Array();
|
|
||||||
typedef std::pair<String, DebugInfo> MessageType;
|
|
||||||
BOOST_FOREACH(const MessageType& message, Messages) {
|
|
||||||
Array::Ptr amsg = new Array();
|
|
||||||
amsg->Add(message.first);
|
|
||||||
amsg->Add(message.second.Path);
|
|
||||||
amsg->Add(message.second.FirstLine);
|
|
||||||
amsg->Add(message.second.FirstColumn);
|
|
||||||
amsg->Add(message.second.LastLine);
|
|
||||||
amsg->Add(message.second.LastColumn);
|
|
||||||
messages->Add(amsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
result->Set("messages", messages);
|
|
||||||
|
|
||||||
Dictionary::Ptr properties = new Dictionary();
|
|
||||||
|
|
||||||
typedef std::map<String, DebugHint>::value_type ChildType;
|
|
||||||
BOOST_FOREACH(const ChildType& kv, Children) {
|
|
||||||
properties->Set(kv.first, kv.second.ToDictionary());
|
|
||||||
}
|
|
||||||
|
|
||||||
result->Set("properties", properties);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Expression::HasField(const Object::Ptr& context, const String& field)
|
bool Expression::HasField(const Object::Ptr& context, const String& field)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr dict = dynamic_pointer_cast<Dictionary>(context);
|
Dictionary::Ptr dict = dynamic_pointer_cast<Dictionary>(context);
|
||||||
|
|
|
@ -31,20 +31,60 @@ namespace icinga
|
||||||
|
|
||||||
struct DebugHint
|
struct DebugHint
|
||||||
{
|
{
|
||||||
std::vector<std::pair<String, DebugInfo> > Messages;
|
public:
|
||||||
std::map<String, DebugHint> Children;
|
DebugHint(const Dictionary::Ptr& hints = Dictionary::Ptr())
|
||||||
|
: m_Hints(hints)
|
||||||
|
{ }
|
||||||
|
|
||||||
inline void AddMessage(const String& message, const DebugInfo& di)
|
inline void AddMessage(const String& message, const DebugInfo& di)
|
||||||
{
|
{
|
||||||
Messages.push_back(std::make_pair(message, di));
|
if (!m_Hints)
|
||||||
|
m_Hints = new Dictionary();
|
||||||
|
|
||||||
|
if (!m_Messages) {
|
||||||
|
m_Messages = new Array();
|
||||||
|
m_Hints->Set("messages", m_Messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
Array::Ptr amsg = new Array();
|
||||||
|
amsg->Add(message);
|
||||||
|
amsg->Add(di.Path);
|
||||||
|
amsg->Add(di.FirstLine);
|
||||||
|
amsg->Add(di.FirstColumn);
|
||||||
|
amsg->Add(di.LastLine);
|
||||||
|
amsg->Add(di.LastColumn);
|
||||||
|
m_Messages->Add(amsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline DebugHint *GetChild(const String& name)
|
inline DebugHint GetChild(const String& name)
|
||||||
{
|
{
|
||||||
return &Children[name];
|
if (!m_Hints)
|
||||||
|
m_Hints = new Dictionary();
|
||||||
|
|
||||||
|
if (!m_Children) {
|
||||||
|
m_Children = new Dictionary;
|
||||||
|
m_Hints->Set("properties", m_Children);
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary::Ptr child = m_Children->Get(name);
|
||||||
|
|
||||||
|
if (!child) {
|
||||||
|
child = new Dictionary();
|
||||||
|
m_Children->Set(name, child);
|
||||||
|
}
|
||||||
|
|
||||||
|
return DebugHint(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr ToDictionary(void) const;
|
Dictionary::Ptr ToDictionary(void) const
|
||||||
|
{
|
||||||
|
return m_Hints;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Dictionary::Ptr m_Hints;
|
||||||
|
Array::Ptr m_Messages;
|
||||||
|
Dictionary::Ptr m_Children;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum CombinedSetOp
|
enum CombinedSetOp
|
||||||
|
|
Loading…
Reference in New Issue