/// <summary>
        /// Create a deep copy of this type variable
        /// </summary>
        /// <returns>new type variable</returns>
        public AdvanceTypeVariable Copy()
        {
            AdvanceTypeVariable result = new AdvanceTypeVariable();

            result.Name          = this.Name;
            result.IsUpperBound  = this.IsUpperBound;
            result.Documentation = this.Documentation;
            foreach (AdvanceType b in this.Bounds)
            {
                result.Bounds.Add(b.Copy());
            }
            return(result);
        }
        /// <summary>
        /// Adds a type variable to this composite
        /// </summary>
        /// <param name="tv">type variable</param>
        /// <returns>true if it was new</returns>
        public bool AddTypeVariable(AdvanceTypeVariable tv)
        {
            if (this.TypeVariables.ContainsKey(tv.Name))
            {
                return(false);
            }
            else
            {
                AdvanceType t = new AdvanceType();
                t.TypeVariable     = tv;
                t.TypeVariableName = tv.Name;
                this.AddSharedTypeVariable(tv.Name, t);

                return(true);
            }
        }
        /// <summary>
        /// Fill object data from xml node
        /// </summary>
        /// <param name="source">Source Xml</param>
        protected override void LoadFromXmlNode(XmlNode source)
        {
            this.Id            = GetAttribute(source, "id");
            this.Documentation = GetAttribute(source, "documentation", null);
            this.Keywords      = GetListAttribute(source, "keywords");
            this.Visuals       = CreateFromXml <AdvanceBlockVisuals>(source);
            HashSet <string> usedIds = new HashSet <string>();

            foreach (XmlNode n in GetChildren(source, "*"))
            {
                switch (n.Name)
                {
                case "block":
                    AdvanceBlockReference b = CreateFromXml <AdvanceBlockReference>(n);
                    b.parent = this;
                    if (usedIds.Contains(b.Id))
                    {
                        this.ThrowDuplicatedIdentifierException(n, b.Id);
                    }
                    else
                    {
                        this.Blocks.Add(b.Id, b);
                        usedIds.Add(b.Id);
                    }
                    break;

                case "composite-block":
                    AdvanceCompositeBlock cb = CreateFromXml <AdvanceCompositeBlock>(n);
                    cb.Parent = this;
                    if (usedIds.Contains(cb.Id))
                    {
                        this.ThrowDuplicatedIdentifierException(n, cb.Id);
                    }
                    else
                    {
                        this.Composites.Add(cb.Id, cb);
                        usedIds.Add(cb.Id);
                    }
                    break;

                case "constant":
                    AdvanceConstantBlock c = CreateFromXml <AdvanceConstantBlock>(n);
                    if (usedIds.Contains(c.Id))
                    {
                        this.ThrowDuplicatedIdentifierException(n, c.Id);
                    }
                    else
                    {
                        this.Constants.Add(c.Id, c);
                        usedIds.Add(c.Id);
                    }
                    break;

                case "bind":
                    AdvanceBlockBind bb = CreateFromXml <AdvanceBlockBind>(n);
                    bb.Parent = this;
                    this.Bindings.Add(bb);
                    break;

                case "type-variable":
                    AdvanceTypeVariable tv = CreateFromXml <AdvanceTypeVariable>(n);
                    if (!this.AddTypeVariable(tv))
                    {
                        this.ThrowDuplicatedIdentifierException(n, tv.Name);
                    }
                    break;

                case "input":
                    AdvanceCompositeBlockParameterDescription inp = CreateFromXml <AdvanceCompositeBlockParameterDescription>(n);
                    if (!this.AddInput(inp))
                    {
                        this.ThrowDuplicatedIdentifierException(n, inp.Id);
                    }
                    break;

                case "output":
                    AdvanceCompositeBlockParameterDescription outp = CreateFromXml <AdvanceCompositeBlockParameterDescription>(n);
                    if (!this.AddOutput(outp))
                    {
                        this.ThrowDuplicatedIdentifierException(n, outp.Id);
                    }
                    break;
                }
            }
            this.LinkTypeVariables();
        }
Example #4
0
        /// <summary>
        /// Fill object data from xml node
        /// </summary>
        /// <param name="source"></param>
        protected override void LoadFromXmlNode(XmlNode source)
        {
            this.Id            = GetAttribute(source, "id");
            this.DisplayName   = GetAttribute(source, "displayname", null);
            this.Documentation = GetUriAttribute(source, "documentation");
            this.Tooltip       = GetAttribute(source, "tooltip", null);
            this.Keywords      = GetListAttribute(source, "keywords");
            this.Category      = GetAttribute(source, "category", null);

            List <AdvanceType> typeRefs = new List <AdvanceType>();
            Dictionary <String, AdvanceType> sharedTypes = new Dictionary <string, AdvanceType>();

            foreach (XmlNode tp in GetChildren(source, "type-variable"))
            {
                AdvanceTypeVariable bpd = CreateFromXml <AdvanceTypeVariable>(tp);
                if (this.TypeVariables.ContainsKey(bpd.Name))
                {
                    this.ThrowDuplicatedIdentifierException(tp, this.Id);
                }
                typeRefs.AddRange(bpd.Bounds);
                AdvanceType st = new AdvanceType();
                st.TypeVariableName = bpd.Name;
                st.TypeVariable     = bpd;
                sharedTypes.Add(bpd.Name, st);
            }

            //	throw new MissingTypeVariableException(root.getXPath(), b.typeVariableName);
            while (typeRefs.Count > 0)
            {
                AdvanceType tvb = typeRefs[0];
                typeRefs.RemoveAt(0);
                if (tvb.TypeVariableName != null)
                {
                    if (!this.TypeVariables.TryGetValue(tvb.TypeVariableName, out tvb.TypeVariable))
                    {
                        this.ThrowMissingTypeVariableException(source, tvb.TypeVariableName);
                    }
                }
                else
                {
                    typeRefs.AddRange(tvb.TypeArguments);
                }
            }

            List <AdvanceType> typeParams = new List <AdvanceType>();

            this.HasVarargs = false;
            foreach (XmlNode inode in GetChildren(source, "input"))
            {
                AdvanceBlockParameterDescription bpd = CreateFromXml <AdvanceBlockParameterDescription>(inode);
                this.HasVarargs |= bpd.Varargs;
                if (this.Inputs.ContainsKey(bpd.Id))
                {
                    this.ThrowDuplicatedIdentifierException(inode, bpd.Id);
                }
                else
                {
                    this.Inputs.Add(bpd.Id, bpd);
                }
                // use the shared type object instead of an individual type
                if (sharedTypes.ContainsKey(bpd.Type.TypeVariableName))
                {
                    bpd.Type = sharedTypes[bpd.Type.TypeVariableName];
                }
                typeParams.Add(bpd.Type);
            }
            foreach (XmlNode onode in GetChildren(source, "output"))
            {
                AdvanceBlockParameterDescription bpd = CreateFromXml <AdvanceBlockParameterDescription>(onode);
                if (this.Outputs.ContainsKey(bpd.Id))
                {
                    this.ThrowDuplicatedIdentifierException(onode, bpd.Id);
                }
                else
                {
                    this.Inputs.Add(bpd.Id, bpd);
                }
                // use the shared type object instead of an individual type
                if (sharedTypes.ContainsKey(bpd.Type.TypeVariableName))
                {
                    bpd.Type = sharedTypes[bpd.Type.TypeVariableName];
                }
                typeParams.Add(bpd.Type);
            }

            while (typeParams.Count > 0)
            {
                AdvanceType at = typeParams[0];
                typeParams.RemoveAt(0);
                if (at.Kind == TypeKind.VARIABLE_TYPE && at.TypeVariable == null)
                {
                    this.TypeVariables.TryGetValue(at.TypeVariableName, out at.TypeVariable);
                }
                else if (at.Kind == TypeKind.PARAMETRIC_TYPE)
                {
                    for (int i = 0; i < at.TypeArguments.Count; i++)
                    {
                        AdvanceType ta = at.TypeArguments[i];
                        if (ta.Kind == TypeKind.VARIABLE_TYPE)
                        {
                            AdvanceType sv;
                            if (!sharedTypes.TryGetValue(ta.TypeVariableName, out sv))
                            {
                                this.ThrowMissingTypeVariableException(source, ta.TypeVariableName);
                            }
                            at.TypeArguments[i] = sv;
                        }
                    }
                    typeParams.AddRange(at.TypeArguments);
                }
            }
        }