Exemplo n.º 1
0
        public ElementModification Copy()
        {
            var copy = new ElementModification();

            copy.Reference    = Reference.Copy();
            copy.Modification = Modification.Copy();
            return(copy);
        }
Exemplo n.º 2
0
        Class createClass(Class c, Modification qm)
        {
            var qmod = Merge(qm, c.Modification);

            if (qmod == c.Modification)
            {
                return(c);
            }
            else
            {
                return new ImplicitClass()
                       {
                           ID = c.ID, Definition = c.Definition, Modification = qmod, Parent = c.Parent
                       }
            };
        }

        Modification qualify(Class c, Modification mod, Instance host)
        {
            if (mod == null)
            {
                return(null);
            }

            foreach (var em in mod.Modifications)
            {
            }
            return(mod);
        }

        Class getClass(Class c, ComponentDeclaration e, Modification qm, Instance host)
        {
            var type = lookupClass(c, e.Clause.Type, host);
            var qmod = qualify(c, e.Modification, host);

            qmod = Merge(qm, qmod);
            return(createClass(type, qmod));
        }

        Modification Merge(Modification env, Modification mod)
        {
            if (env == null)
            {
                return(mod);
            }
            else if (mod == null)
            {
                return(env);
            }
            else
            {
                var result = env.Copy();
                foreach (var em in mod.Modifications)
                {
                    if (Select(env, em.Reference.ID) == null)
                    {
                        result.Modifications.Add(em);
                    }
                }
                foreach (var e in mod.Redeclarations)
                {
                    //if(redeclare(env, e.ID)==null)
                    //result.Redeclarations.Add(e);
                }

                if (env.Value == null)
                {
                    result.Value = mod.Value;
                }

                return(result);
            }
        }

        Modification Select(Modification env, string ID)
        {
            if (env == null || env.Modifications == null)
            {
                return(null);
            }

            var x = env.Modifications.FirstOrDefault(x => x.Reference.ID == ID);

            if (x != null)
            {
                if (x.Reference.Next == null)
                {
                    return(x.Modification);
                }
                else
                {
                    var mod = new Modification();
                    var em  = new ElementModification {
                        Reference = x.Reference.Next, Modification = x.Modification
                    };
                    mod.Modifications.Add(em);
                    return(mod);
                }
            }
            else
            {
                return(null);
            }
        }

        Instance Elaborate(Class c, Instance host)
        {
            if (c.Definition == null)
            {
            }
            foreach (var ext in c.Definition.Elements.OfType <Extends>())
            {
            }

            foreach (var clause in c.Definition.Elements.OfType <ComponentClause>())
            {
                foreach (var decl in clause.Declarations)
                {
                    decl.Clause = clause;

                    var qmod = Select(c.Modification, decl.ID);

                    var type = getClass(c, decl, qmod, host);
                    var comp = Elaborate(type, new Instance());
                    comp.ID   = decl.ID;
                    comp.Type = type.ID;
                    if (isSimpleType(type.ID))
                    {
                        comp.Source = decl.Clause;
                    }
                    host.Parts.Add(comp);
                }
            }

            foreach (var eqsec in c.Definition.Elements.OfType <EquationSection>())
            {
                foreach (var eq in eqsec.Equations)
                {
                    host.Equations.Add(eq);
                }
            }


            if (c.Modification != null)
            {
                host.Value = c.Modification.Value;
            }
            return(host);
        }
    }