Beispiel #1
0
        /// <summary>
        /// Add a dim node to array node or another dim node, if one is available, it is replaced.
        /// </summary>
        /// <remarks>If parent node is the ArrayNode or DefineTypeNode of ArrayNode, then
        /// the new DimNode will replace the original DimNode which is then indented (demoted as the grandchild.
        /// If the parent node is a DimNode, then its child node is replaced and degraded, or if no child node
        /// exists, the new node is added as the child.</remarks>
        /// <param name="parentNode"></param>
        /// <param name="at"></param>
        public void addDimNode(DataNode parentNode, int at)
        {
            AbstractNode dNode = parentNode.getDataNode();

            if (dNode.GetType().Equals(typeof(DefineTypeNode)))
            {
                dNode = ((DefineTypeNode)dNode).getBaseType();
            }
            FormDim      formDim = new FormDim();
            DialogResult r       = formDim.ShowDialog(view_);

            if (r == DialogResult.OK)
            {
                string  sdname  = formDim.DimName;
                string  scount  = formDim.DimCount;
                DimNode dimNode = new DimNode(sdname, scount);
                ((ComplexNode)dNode).insertChild(dimNode, 0);                   //at irrelevant for array and dim node
                DataNode d   = new DataNode(dimNode);
                DataNode old = (DataNode)parentNode.LastNode;
                if (old != null)
                {
                    parentNode.Nodes.Remove(old);
                    d.Nodes.Add(old);
                }
                parentNode.Nodes.Add(d);
                parentNode.ExpandAll();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Add array element to the array node in the treeview from loaded document.
        /// TODO: no support for array containing arrays or unions
        /// </summary>
        /// <param name="node"></param>
        /// <param name="t"></param>
        protected void addArrayNode(TreeNode node, ArrayNode t)
        {
            DataNode dt = new DataNode(t.getElement());

            node.Nodes.Add(dt);
            if (t.getElement().isComplex())
            {
                ComplexNode ct = (ComplexNode)t.getElement();
                if (ct.GetType().Equals(typeof(StructNode)))
                {
                    addStructNode(node.LastNode, (StructNode)ct);
                }
                else if (ct.GetType().Equals(typeof(ArrayNode)))
                {
                    addArrayNode(node.LastNode, (ArrayNode)ct);
                }
                else if (ct.GetType().Equals(typeof(UnionNode)))
                {
                    addUnionNode(node.LastNode, (UnionNode)ct);
                }
            }
            // add dims
            DataNode lastNode = (DataNode)node;
            DimNode  dim      = t.getDimension();

            while (dim != null)
            {
                DataNode d = new DataNode(dim);
                lastNode.Nodes.Add(d);
                lastNode = d;
                dim      = dim.getChild();
            }
        }
Beispiel #3
0
        private string name_; //name of dimension

        #endregion Fields

        #region Constructors

        public DimNode(string name, int count)
            : base("dim")
        {
            this.name_ = name;
            this.count_ = count;
            this.child_ = null;
        }
Beispiel #4
0
 public override void removeChild(int at)
 {
     //must be removing the dim child
     if (dim_ != null)
     {
         dim_ = dim_.getChild();
     }
 }
Beispiel #5
0
        /// <summary>
        /// Remove the only child node and promote the child's child node.
        /// </summary>
        /// <param name="at">ignored here</param>
        public override void removeChild(int at)
        {
            DimNode d = this.child_;

            if (d != null)
            {
                this.child_ = d.getChild();
            }
        }
Beispiel #6
0
 /// <summary>
 /// Add a Dimension node to the leaf (lowest child)
 /// </summary>
 /// <param name="d"></param>
 public void addDescendant(DimNode d)
 {
     if (child_ != null)
     {
         child_.addDescendant(d);
     }
     else
     {
         child_ = d;
     }
 }
Beispiel #7
0
 /// <summary>
 /// Add a Dimension node to the leaf (lowest child)
 /// </summary>
 /// <param name="d"></param>
 public void addDescendant(DimNode d)
 {
     if (child_ != null)
     {
         child_.addDescendant(d);
     }
     else
     {
         child_ = d;
     }
 }
Beispiel #8
0
 /// <summary>
 /// Add or replace a child DimNode to this one, demote its child if available.
 /// </summary>
 /// <remarks>A DimNode can have only one child DimNode node. When this DimNode already has a child DimNode,
 /// the new child DimNode is set as the only child node and the old child node becomes the child node of the
 /// added child node (grandchild of this node). Note that if the given child node already has a child node,
 /// it will be lost in this case.</remarks>
 /// <param name="child"></param>
 public override void addChild(AbstractNode child)
 {
     if (child.GetType().Equals(typeof(DimNode)))
     {
         DimNode c = this.child_;
         this.child_ = (DimNode)child;
         if (c != null)
         {
             this.child_.setChild(c);
         }
     }
 }
Beispiel #9
0
 /// <summary>
 /// Add or replace a child DimNode to this one, demote its child if available.
 /// </summary>
 /// <remarks>A DimNode can have only one child DimNode node. When this DimNode already has a child DimNode,
 /// the new child DimNode is set as the only child node and the old child node becomes the child node of the
 /// added child node (grandchild of this node). Note that if the given child node already has a child node,
 /// it will be lost in this case.</remarks>
 /// <param name="child"></param>
 public override void addChild(AbstractNode child)
 {
     if (child.GetType().Equals(typeof(DimNode)))
     {
         DimNode c = this.child_;
         this.child_ = (DimNode)child;
         if (c != null)
         {
             this.child_.setChild(c);
         }
     }
 }
Beispiel #10
0
        public int getDimensionCount()
        {
            int     count = 0;
            DimNode d     = dim_;

            while (d != null)
            {
                count++;
                d = d.getChild();
            }
            return(count);
        }
Beispiel #11
0
 /// <summary>
 /// Add a dimension to the array
 /// </summary>
 /// <param name="dname">name of dimension</param>
 /// <param name="dcount">count of dimension elements</param>
 public DimNode addDimension(string dname, int dcount)
 {
     DimNode d = new DimNode(dname, dcount);
     if (dim_ == null)
     {
         dim_ = d;
     }
     else
     {
         dim_.addDescendant(d);
     }
     return d;
 }
Beispiel #12
0
 public DimNode(string name, string scount) : base("dim")
 {
     this.name_ = name;
     try
     {
         this.count_ = Convert.ToInt32(scount);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     this.child_ = null;
 }
Beispiel #13
0
        /// <summary>
        /// Add a dimension to the array
        /// </summary>
        /// <param name="dname">name of dimension</param>
        /// <param name="dcount">count of dimension elements</param>
        public DimNode addDimension(string dname, int dcount)
        {
            DimNode d = new DimNode(dname, dcount);

            if (dim_ == null)
            {
                dim_ = d;
            }
            else
            {
                dim_.addDescendant(d);
            }
            return(d);
        }
Beispiel #14
0
 public DimNode(string name, string scount)
     : base("dim")
 {
     this.name_ = name;
     try
     {
         this.count_ = Convert.ToInt32(scount);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     this.child_ = null;
 }
Beispiel #15
0
 /// <summary>
 /// Override insertChild to add only element node, dim node won't be added.
 /// </summary>
 /// <param name="child"></param>
 /// <param name="at"></param>
 public override void insertChild(AbstractNode child, int at)
 {
     if (!child.GetType().Equals(typeof(DimNode)))
     {
         setElement(child);
     }
     else
     {
         if (dim_ != null)
         {
             ((DimNode)child).setChild(dim_);
         }
         dim_ = (DimNode)child;
     }
 }
Beispiel #16
0
        private DimNode child_;         //embedded dim

        public DimNode(string name, int count) : base("dim")
        {
            this.name_  = name;
            this.count_ = count;
            this.child_ = null;
        }
Beispiel #17
0
 public void setChild(DimNode node)
 {
     this.child_ = node;
 }
Beispiel #18
0
 public override void removeChild(int at)
 {
     //must be removing the dim child
     if (dim_ != null)
     {
         dim_ = dim_.getChild();
     }
 }
Beispiel #19
0
 public void setChild(DimNode node)
 {
     this.child_ = node;
 }
Beispiel #20
0
 /// <summary>
 /// Check struct, union and array node for useType references, duplicate union case values.
 /// </summary>
 /// <remarks>
 /// This check should apply to the following scenarios:
 /// <list>
 /// A struct contains two or more member elements that have the same variable name
 /// A struct contains a useType as its member or member of its member which referenced a undefined type
 /// A struct contains no member element
 /// A union contains no case element
 /// A union contains two or more cases with the same discriminant value
 /// A union contains a useType element in any of the case elements that referenced a undefined type
 /// An array contains no dimension element
 /// An streamed array contains more than one dim element
 /// An variable-sized array's first dim element has a count (should be zero)
 /// A fixed array contains a dim element with a zero count (should be greater than 0)
 /// An array contains useType element that referenced a undefined type
 /// An array contains a variable-sized construct in its element or embeded descedants.
 /// </list>
 /// </remarks>
 /// <param name="dataNode"></param>
 /// <param name="defs"></param>
 /// <param name="report"></param>
 private static void checkComplexType(ComplexNode dataNode, Hashtable defs, ArrayList report)
 {
     if (dataNode.GetType().Equals(typeof(StructNode)))
     {
         StructNode sNode = (StructNode)dataNode;
         if (sNode.getMemberCount() > 0)
         {
             Hashtable varNames = new Hashtable();
             foreach (AbstractNode aNode in ((StructNode)dataNode).getMembers())
             {
                 //check duplicate variable names as warnings
                 checkVarNames(aNode, varNames, report);
                 checkUseType(aNode, defs, report);
             }
         }
         else
         {
             //empty struct
             report.Add("Warning: struct '" + sNode.toNodeText() + "' contains no member element.");
         }
     }
     else if (dataNode.GetType().Equals(typeof(UnionNode)))
     {
         UnionNode uNode = (UnionNode)dataNode;
         if (uNode.getCaseCount() > 0)
         {
             Hashtable cases = new Hashtable();
             foreach (CaseNode cNode in uNode.getCases())
             {
                 //case values must be unique
                 if (cases.Contains(cNode.getDiscriminantValue()))
                 {
                     report.Add("Error: duplicate case value '" + cNode.getDiscriminantValue() + "' at union type '" + dataNode.toNodeText() + "'.");
                 }
                 else
                 {
                     cases.Add(cNode.getDiscriminantValue(), cNode);
                 }
                 //if case body is useType, check type defs
                 checkUseType(cNode.getCaseBody(), defs, report);
             }
         }
         else
         {
             report.Add("Warning: union '" + uNode.toNodeText() + "' contains no case element.");
         }
     }
     else if (dataNode.GetType().Equals(typeof(ArrayNode)))
     {
         ArrayNode arrayNode = (ArrayNode)dataNode;
         if (arrayNode.getDimension() == null)
         {
             report.Add("Error: Array '" + arrayNode.toNodeText() + "' has no dimension element.");
         }
         else
         {
             if (arrayNode.isArrayStreamed() && arrayNode.getDimensionCount() > 1)
             {
                 report.Add("Warning: Streamed array contains more than one dimension.");
             }
             else if (arrayNode.isArrayFixed())
             {
                 for (DimNode dn = arrayNode.getDimension(); dn != null; dn = dn.getChild())
                 {
                     if (dn.count() <= 0)
                     {
                         report.Add("Error: array dimension is of invalid size at '" + arrayNode.toNodeText() + "'.");
                     }
                 }
             }
             else
             {
                 //first dim must be of 0 size
                 DimNode dn = arrayNode.getDimension();
                 if (dn.count() > 0)
                 {
                     report.Add("Warning: first dimension count of a variable-sized array ignored at '" + arrayNode.toNodeText() + "'.");
                 }
                 for (dn = dn.getChild(); dn != null; dn = dn.getChild())
                 {
                     if (dn.count() <= 0)
                     {
                         report.Add("Error: array dimension is of invalid size at '" + arrayNode.toNodeText() + "'.");
                     }
                 }
             }
         }
         checkUseType(arrayNode.getElement(), defs, report);
         //check for variable-sized construct contained in arrays
         checkVariableConstruct(arrayNode.getElement(), report);
     }
 }
Beispiel #21
0
 public void setDimension(DimNode dim)
 {
     dim_ = dim;
 }
Beispiel #22
0
 public void setDimension(DimNode dim)
 {
     dim_ = dim;
 }
Beispiel #23
0
 /// <summary>
 /// Remove the only child node and promote the child's child node.
 /// </summary>
 /// <param name="at">ignored here</param>
 public override void removeChild(int at)
 {
     DimNode d = this.child_;
     if (d != null)
     {
         this.child_ = d.getChild();
     }
 }
Beispiel #24
0
 /// <summary>
 /// Add a dim node to array node or another dim node, if one is available, it is replaced.
 /// </summary>
 /// <remarks>If parent node is the ArrayNode or DefineTypeNode of ArrayNode, then
 /// the new DimNode will replace the original DimNode which is then indented (demoted as the grandchild.
 /// If the parent node is a DimNode, then its child node is replaced and degraded, or if no child node
 /// exists, the new node is added as the child.</remarks>
 /// <param name="parentNode"></param>
 /// <param name="at"></param>
 public void addDimNode(DataNode parentNode, int at)
 {
     AbstractNode dNode = parentNode.getDataNode();
     if (dNode.GetType().Equals(typeof(DefineTypeNode)))
     {
         dNode = ((DefineTypeNode)dNode).getBaseType();
     }
     FormDim formDim = new FormDim();
     DialogResult r = formDim.ShowDialog(view_);
     if (r == DialogResult.OK)
     {
         string sdname = formDim.DimName;
         string scount = formDim.DimCount;
         DimNode dimNode = new DimNode(sdname, scount);
         ((ComplexNode)dNode).insertChild(dimNode, 0);	//at irrelevant for array and dim node
         DataNode d = new DataNode(dimNode);
         DataNode old = (DataNode)parentNode.LastNode;
         if (old != null)
         {
             parentNode.Nodes.Remove(old);
             d.Nodes.Add(old);
         }
         parentNode.Nodes.Add(d);
         parentNode.ExpandAll();
     }
 }
Beispiel #25
0
 /// <summary>
 /// Override insertChild to add only element node, dim node won't be added.
 /// </summary>
 /// <param name="child"></param>
 /// <param name="at"></param>
 public override void insertChild(AbstractNode child, int at)
 {
     if (!child.GetType().Equals(typeof(DimNode)))
     {
         setElement(child);
     }
     else
     {
         if (dim_ != null)
         {
             ((DimNode)child).setChild(dim_);
         }
         dim_ = (DimNode)child;
     }
 }