Exemple #1
0
        ///<summary>
        /// Resolves given node and then all its heir nodes recursively using DFS.
        ///</summary>
        private static void ResolveInheritanceNodeAndHeirs(InheritanceNode node)
        {
            //Error check
            // if we've reached a resolved node by traversing the tree, then it means
            // that there's a cycle, note that we're not reporting the full cycle in
            // the error message here, but only the last node which created a cycle
            if (node.resolved)
            {
                throw new Exception("Cyclic inheritance detected for Tyd node:\n" + node.tydNode.FullTyd);
            }

            //Resolve this node
            {
                if (node.source == null)
                {
                    // No source - Just use the original node
                    node.resolved = true;
                }
                else
                {
                    //Source exists - We now inherit from it
                    //We must use source's RESOLVED node here because our source can have its own source.
                    if (!node.source.resolved)
                    {
                        throw new Exception("Tried to resolve Tyd inheritance node " + node + " whose source has not been resolved yet. This means that this method was called in incorrect order.");
                    }

                    CheckForDuplicateNodes(node.tydNode);

                    node.resolved = true;

                    //Write resolved node's class attribute
                    //Original takes precedence over source; source takes precedence over default
                    var attClass = node.tydNode.AttributeClass ?? node.source.tydNode.AttributeClass;
                    node.tydNode.SetupAttributes(attClass, null, null, false);

                    //Apply inheritance from source to node
                    ApplyInheritance(node.source.tydNode, node.tydNode);
                }
            }

            //Recur to the heirs and resolve them too
            for (int i = 0; i < node.HeirCount(); i++)
            {
                ResolveInheritanceNodeAndHeirs(node.GetHeir(i));
            }
        }