@@ -13,6 +13,7 @@ CommonTree<ImplTraits>::CommonTree()
1313template <class ImplTraits >
1414CommonTree<ImplTraits>::CommonTree( const CommonTree& ctree )
1515 :m_children( ctree.m_children)
16+ ,UserData(ctree.UserData)
1617{
1718 m_startIndex = ctree.m_startIndex ;
1819 m_stopIndex = ctree.m_stopIndex ;
@@ -33,6 +34,7 @@ CommonTree<ImplTraits>::CommonTree( const CommonTokenType* token )
3334
3435template <class ImplTraits >
3536CommonTree<ImplTraits>::CommonTree( const CommonTree* tree )
37+ :UserData(tree->UserData)
3638{
3739 m_startIndex = tree->get_startIndex ();
3840 m_stopIndex = tree->get_stopIndex ();
@@ -96,7 +98,9 @@ void CommonTree<ImplTraits>::addChild(TreeTypePtr& child)
9698 if ((*i) != NULL )
9799 {
98100 m_children.push_back (std::move (*i));
99- m_children.back ()->set_parent (this );
101+ // static_cast to possible subtype (if TreeType trait defined)
102+ TreeType* tree = static_cast <TreeType*>(this );
103+ m_children.back ()->set_parent (tree);
100104 m_children.back ()->set_childIndex (m_children.size () - 1 );
101105 }
102106 }
@@ -116,7 +120,9 @@ void CommonTree<ImplTraits>::addChild(TreeTypePtr& child)
116120 {
117121 // Tree we are adding is not a Nil and might have children to copy
118122 m_children.push_back ( std::move (child) );
119- m_children.back ()->set_parent (this );
123+ // static_cast to possible subtype (if TreeType trait defined)
124+ TreeType* tree = static_cast <TreeType*>(this );
125+ m_children.back ()->set_parent (tree);
120126 m_children.back ()->set_childIndex (m_children.size () - 1 );
121127 }
122128}
@@ -185,7 +191,8 @@ void CommonTree<ImplTraits>::replaceChildren(ANTLR_INT32 startChildIndex, ANTLR_
185191 {
186192 TreeType *child = newChildrenRef.at (j);
187193 m_children[i] = child;
188- child->set_parent (this );
194+ TreeType* tree = static_cast <TreeType*>(this );
195+ child->set_parent (tree);
189196 child->set_childIndex (i);
190197 j++;
191198 }
@@ -398,7 +405,8 @@ void CommonTree<ImplTraits>::setChild(ANTLR_UINT32 i, TreeTypePtr child)
398405 m_children.resize (i+1 );
399406
400407 m_children[i] = child;
401- child->set_parent (this );
408+ TreeType* tree = static_cast <TreeType*>(this );
409+ child->set_parent (tree);
402410 child->set_childIndex (i);
403411}
404412
@@ -469,7 +477,8 @@ void CommonTree<ImplTraits>::freshenParentAndChildIndexes(ANTLR_UINT32 offset)
469477 for (; i != m_children.end (); ++i, ++c)
470478 {
471479 (*i)->set_childIndex (c);
472- (*i)->set_parent (this );
480+ TreeType* tree = static_cast <TreeType*>(this );
481+ (*i)->set_parent (tree);
473482 }
474483}
475484
0 commit comments