Esempio n. 1
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();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Add child node to the parent at the given position. Both TreeView and document are added implicitly.
        /// </summary>
        /// <param name="parentNode">DatasetNode, StructNode, or UnionNode</param>
        /// <param name="childNode">Any data node</param>
        /// <param name="at">Position to insert the child</param>
        /// <returns></returns>
        private void addChildNode(DataNode parentNode, DataNode childNode, int at)
        {
            ComplexNode dataNode = null;

            if (parentNode.getDataNode().GetType().Equals(typeof(DefineTypeNode)))
            {
                dataNode = ((DefineTypeNode)parentNode.getDataNode()).getBaseType();
            }
            else
            {
                dataNode = (ComplexNode)parentNode.getDataNode();
            }
            dataNode.insertChild(childNode.getDataNode(), at);
            parentNode.Nodes.Insert(at, childNode);
        }
Esempio n. 3
0
        /// <summary>
        /// Delete a selected node.
        /// </summary>
        /// <remarks>
        /// definitions and dataset: nop
        /// primitive:	delete
        /// complex:	delete
        /// useType:	delete
        /// case:		delete
        /// dim:		delete
        /// </remarks>
        /// <param name="theNode"></param>
        public void deleteNode(DataNode theNode)
        {
            DataNode parentNode = (DataNode)theNode.Parent;

            if (parentNode.getDataNode().isComplex())
            {
                ComplexNode aNode = (ComplexNode)parentNode.getDataNode();
                aNode.removeChild(parentNode.Nodes.IndexOf(theNode));
                if (theNode.getDataNode().GetType().Equals(typeof(DimNode)))
                {
                    //promote its child node if any
                    DataNode childNode = (DataNode)theNode.FirstNode;
                    parentNode.Nodes.Remove(theNode);
                    if (childNode != null)
                    {
                        parentNode.Nodes.Add(childNode);
                    }
                }
                else
                {
                    parentNode.Nodes.Remove(theNode);
                }
            }
        }
Esempio n. 4
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);
     }
 }
Esempio n. 5
0
 public void setBaseType(ComplexNode bnode)
 {
     baseType_ = bnode;
 }
Esempio n. 6
0
 public DefineTypeNode(string typeName, ComplexNode baseType)
     : base(typeName)
 {
     baseType_ = baseType;
 }
Esempio n. 7
0
 public void setBaseType(ComplexNode bnode)
 {
     baseType_ = bnode;
 }
Esempio n. 8
0
 public DefineTypeNode(string typeName, ComplexNode baseType) : base(typeName)
 {
     baseType_ = baseType;
 }
Esempio n. 9
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);
     }
 }