Array::Ptr messages = debug_hints->Get("messages");
- ObjectLock olock(messages);
+ if (messages) {
+ ObjectLock olock(messages);
- BOOST_FOREACH(const Value& msg, messages) {
- PrintHint(fp, msg, indent);
+ BOOST_FOREACH(const Value& msg, messages) {
+ PrintHint(fp, msg, indent);
+ }
}
}
Value SetExpression::DoEvaluate(const Object::Ptr& context, DebugHint *dhint) const
{
- DebugHint *sdhint = dhint;
+ DebugHint *psdhint = dhint;
+ DebugHint sdhint;
Value parent, object;
String index;
Expression *indexExpr = m_Indexer[i];
String tempindex = indexExpr->Evaluate(context, dhint);
- if (sdhint)
- sdhint = sdhint->GetChild(tempindex);
+ if (psdhint) {
+ sdhint = psdhint->GetChild(tempindex);
+ psdhint = &sdhint;
+ }
if (i == 0)
parent = context;
LiteralExpression *eindex = MakeLiteral(tempindex);
IndexerExpression eip(eparent, eindex, m_DebugInfo);
- object = eip.Evaluate(context, sdhint);
+ object = eip.Evaluate(context, psdhint);
if (i != m_Indexer.size() - 1 && object.IsEmpty()) {
object = new Dictionary();
SetField(parent, index, right);
- if (sdhint)
- sdhint->AddMessage("=", m_DebugInfo);
+ if (psdhint)
+ psdhint->AddMessage("=", m_DebugInfo);
return right;
}
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)
{
Dictionary::Ptr dict = dynamic_pointer_cast<Dictionary>(context);
struct DebugHint
{
- std::vector<std::pair<String, DebugInfo> > Messages;
- std::map<String, DebugHint> Children;
+public:
+ DebugHint(const Dictionary::Ptr& hints = Dictionary::Ptr())
+ : m_Hints(hints)
+ { }
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)
+ {
+ 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);
}
- inline DebugHint *GetChild(const String& name)
+ Dictionary::Ptr ToDictionary(void) const
{
- return &Children[name];
+ return m_Hints;
}
- Dictionary::Ptr ToDictionary(void) const;
+private:
+ Dictionary::Ptr m_Hints;
+ Array::Ptr m_Messages;
+ Dictionary::Ptr m_Children;
};
enum CombinedSetOp