예제 #1
0
        public bool Equals(TemplateTranslation obj)
        {
            if (Object.ReferenceEquals(this, obj))
            {
                return(true);
            }

            if (Object.ReferenceEquals(obj, null))
            {
                return(false);
            }

            //return this.table.Count == obj.table.Count && !this.table.Except(obj.table).Any();
            if (this.table.Count != obj.table.Count)
            {
                return(false);
            }

            foreach (KeyValuePair <TemplateParameter, IEntityInstance> entry in this.table)
            {
                if (!obj.table.TryGetValue(entry.Key, out IEntityInstance value))
                {
                    return(false);
                }
                else if (!Object.Equals(entry.Value, value))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #2
0
        private EntityInstance(RuntimeCore core, IEntity target,
                               TemplateTranslation translation, TypeMutability overrideMutability,
                               Lifetime lifetime)
        {
            if (target == null)
            {
                throw new ArgumentNullException("Instance has to be created for existing entity");
            }

            this.core        = core;
            this.Target      = target;
            this.Translation = translation;

            this.Lifetime = lifetime;

            this.OverrideMutability = overrideMutability;

            this.nameOf = Later.Create(() => NameReference.Create(
                                           OverrideMutability,
                                           null, this.Target.Name.Name, this.TemplateArguments.Select(it => it.NameOf),
                                           target: this, isLocal: false));
            this.pureNameOf = Later.Create(() => NameReference.Create(
                                               null, this.Target.Name.Name, this.TemplateArguments.Select(it => it.NameOf),
                                               target: this, isLocal: false));
        }
예제 #3
0
        public static TemplateTranslation OverriddenTraitWithHostParameters(TemplateTranslation translation, TypeDefinition trait)
        {
            if (translation.table.Count == 0)
            {
                return(translation);
            }

            return(translation.overridden(trait.Name.Parameters, trait.AssociatedHost.Name.Parameters.Select(it => it.InstanceOf)));
        }
예제 #4
0
        internal static EntityInstance CreateUnregistered(RuntimeCore core, IEntity target,
                                                          TemplateTranslation translation,
                                                          TypeMutability overrideMutability,
                                                          Lifetime lifetime)
        {
            var instance = new EntityInstance(core, target, translation, overrideMutability, lifetime);

            return(instance);
        }
예제 #5
0
        public static TemplateTranslation Translated(TemplateTranslation baseTranslation,
                                                     TemplateTranslation through, ref bool translated)
        {
            if (baseTranslation == null || through == null)
            {
                throw new ArgumentNullException();
            }

            if (baseTranslation.table.Count == 0 || through.table.Count == 0)
            {
                return(baseTranslation);
            }

            var dict = Later.Create(() => baseTranslation.table.ToDictionary(it => it.Key, it => it.Value));

            foreach (KeyValuePair <TemplateParameter, IEntityInstance> entry in baseTranslation.table)
            {
                if (entry.Value != null)
                {
                    bool            trans          = false;
                    IEntityInstance entityInstance = entry.Value.TranslateThrough(ref trans, through);

                    if (trans)
                    {
                        dict.Value[entry.Key] = entityInstance;
                    }
                }
                else if (through.Translate(entry.Key, out IEntityInstance value))
                {
                    dict.Value[entry.Key] = value;
                }
            }

            if (dict.HasValue)
            {
                translated = true;
                return(new TemplateTranslation(baseTranslation.parametersProvider, dict.Value));
            }
            else
            {
                return(baseTranslation);
            }
        }
예제 #6
0
        public IEntityInstance TranslateThrough(ref bool translated, TemplateTranslation closedTranslation)
        {
            var  result = new List <IEntityInstance>();
            bool trans  = false;

            foreach (IEntityInstance open in elements)
            {
                result.Add(open.TranslateThrough(ref trans, closedTranslation));
            }

            if (trans)
            {
                translated = true;
                return(createNew(result));
            }
            else
            {
                return(this);
            }
        }
예제 #7
0
        public static TemplateTranslation CreateParameterless(IEntity entity)
        {
            TemplateDefinition parent_template = entity.EnclosingNode <TemplateDefinition>();

            if (parent_template == null)
            {
                return(Empty);
            }

            TemplateTranslation parent_trans = parent_template.InstanceOf.Translation;

            if (parent_trans.parametersProvider == null)
            {
                return(parent_trans);
            }
            else
            {
                // the case when the parent has some parameter, then we have to pass null as parameter provider
                // because we are parameterless
                return(new TemplateTranslation(null, parent_trans.table));
            }
        }
예제 #8
0
        public IEntityInstance TranslateThrough(ref bool translated, TemplateTranslation translation)
        {
            // consider:
            // Coll<T,A> implements IColl<A>
            // and then you have Coll<Int,String> (closedTemplate) -- so how does IColl looks now?
            // IColl<String> (since A maps to String)
            // and we compute it here
            // or let's say we have type Foo<T> and one of its methods returns T
            // then we have instance Foo<String> (closedTemplate), what T is then? (String)

            if (translation == null || translation == TemplateTranslation.Empty)
            {
                return(this);
            }

            if (this.TargetsTemplateParameter)
            {
                if (translation.Translate(this.TemplateParameterTarget, out IEntityInstance trans))
                {
                    if (!this.IsIdentical(trans))
                    {
                        translated = true;
                    }

                    return(trans);
                }

                return(this);
            }
            else
            {
                TemplateTranslation combo_translation = TemplateTranslation.Translated(this.Translation, translation, ref translated);

                EntityInstance result = this.Target.GetInstance(this.OverrideMutability, combo_translation, this.Lifetime);

                return(result);
            }
        }
예제 #9
0
        public IEntityInstance TranslationOf(IEntityInstance openTemplate, ref bool translated, TemplateTranslation closedTranslation)
        {
            bool trans = false;

            foreach (IEntityInstance closed in elements)
            {
                openTemplate = closed.TranslationOf(openTemplate, ref trans, closedTranslation);
            }

            if (trans)
            {
                translated = true;
            }

            return(openTemplate);
        }
예제 #10
0
        internal EntityInstance Build(IEnumerable <IEntityInstance> templateArguments, TypeMutability overrideMutability)
        {
            TemplateTranslation combined = this.Translation.Overridden(templateArguments);

            return(this.Target.GetInstance(overrideMutability, combined, this.Lifetime));
        }
예제 #11
0
        internal EntityInstance TranslateThroughTraitHost(TypeDefinition trait)
        {
            TemplateTranslation combined = TemplateTranslation.OverriddenTraitWithHostParameters(this.Translation, trait: trait);

            return(this.Target.GetInstance(this.OverrideMutability, combined, Lifetime.Timeless));
        }
예제 #12
0
 public IEntityInstance TranslationOf(IEntityInstance openTemplate, ref bool translated, TemplateTranslation closedTranslation)
 {
     return(openTemplate.TranslateThrough(ref translated, closedTranslation ?? this.Translation));
 }