From 4a2a6d999a486956d52ace891ef8a2a949e7d6ee Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 5 Mar 2015 13:18:15 +0100 Subject: [PATCH] Fix incorrect debug hints for nested attributes fixes #8604 --- lib/config/expression.cpp | 8 +++++- lib/config/expression.hpp | 54 ++++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp index 6e8b18203..7350a97ae 100644 --- a/lib/config/expression.cpp +++ b/lib/config/expression.cpp @@ -598,12 +598,17 @@ bool IndexerExpression::GetReference(ScriptFrame& frame, bool init_dict, Value * Value vparent; String vindex; DebugHint *psdhint = NULL; + bool free_psd = false; + + if (dhint) + psdhint = *dhint; if (m_Operand1->GetReference(frame, init_dict, &vparent, &vindex, &psdhint)) { if (init_dict && VMOps::GetField(vparent, vindex, m_Operand1->GetDebugInfo()).IsEmpty()) VMOps::SetField(vparent, vindex, new Dictionary(), m_Operand1->GetDebugInfo()); *parent = VMOps::GetField(vparent, vindex, m_DebugInfo); + free_psd = true; } else { ExpressionResult operand1 = m_Operand1->Evaluate(frame); *parent = operand1.GetValue(); @@ -615,7 +620,8 @@ bool IndexerExpression::GetReference(ScriptFrame& frame, bool init_dict, Value * if (dhint && psdhint) *dhint = new DebugHint(psdhint->GetChild(*index)); - delete psdhint; + if (free_psd) + delete psdhint; return true; } diff --git a/lib/config/expression.hpp b/lib/config/expression.hpp index 0180c2be9..6f7dbfe53 100644 --- a/lib/config/expression.hpp +++ b/lib/config/expression.hpp @@ -44,14 +44,6 @@ public: inline void AddMessage(const String& message, const DebugInfo& 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); @@ -59,24 +51,18 @@ public: amsg->Add(di.FirstColumn); amsg->Add(di.LastLine); amsg->Add(di.LastColumn); - m_Messages->Add(amsg); + GetMessages()->Add(amsg); } inline DebugHint GetChild(const String& name) { - if (!m_Hints) - m_Hints = new Dictionary(); + Dictionary::Ptr children = GetChildren(); - if (!m_Children) { - m_Children = new Dictionary; - m_Hints->Set("properties", m_Children); - } - - Dictionary::Ptr child = m_Children->Get(name); + Dictionary::Ptr child = children->Get(name); if (!child) { child = new Dictionary(); - m_Children->Set(name, child); + children->Set(name, child); } return DebugHint(child); @@ -89,8 +75,36 @@ public: private: Dictionary::Ptr m_Hints; - Array::Ptr m_Messages; - Dictionary::Ptr m_Children; + + Array::Ptr GetMessages(void) + { + if (!m_Hints) + m_Hints = new Dictionary(); + + Array::Ptr messages = m_Hints->Get("messages"); + + if (!messages) { + messages = new Array(); + m_Hints->Set("messages", messages); + } + + return messages; + } + + Dictionary::Ptr GetChildren(void) + { + if (!m_Hints) + m_Hints = new Dictionary(); + + Dictionary::Ptr children = m_Hints->Get("properties"); + + if (!children) { + children = new Dictionary; + m_Hints->Set("properties", children); + } + + return children; + } }; enum CombinedSetOp -- 2.40.0