示例#1
0
        public ConstraintMatch ArgumentMatchesParameterConstraints(ComputationContext ctx, EntityInstance closedTemplate,
                                                                   TemplateParameter param)
        {
            foreach (IEntityInstance arg in this.elements)
            {
                ConstraintMatch match = arg.ArgumentMatchesParameterConstraints(ctx, closedTemplate, param);
                if (match != ConstraintMatch.Yes)
                {
                    return(match);
                }
            }

            return(ConstraintMatch.Yes);
        }
示例#2
0
        public static IEnumerable <TypeDefinition> AvailableTraits(this EntityInstance instance, ComputationContext ctx)
        {
            IEntityScope scope = instance.Target.Cast <TemplateDefinition>();

            if (scope is TypeDefinition typedef)
            {
                foreach (TypeDefinition trait in typedef.AssociatedTraits)
                {
                    // todo: once computed which traits fit maybe we could cache them within given instance?
                    ConstraintMatch match = TypeMatcher.ArgumentsMatchConstraintsOf(ctx, trait.Name.Parameters, instance);
                    if (match != ConstraintMatch.Yes)
                    {
                        continue;
                    }

                    yield return(trait);
                }
            }
        }
示例#3
0
        public static ConstraintMatch ArgumentsMatchConstraintsOf(ComputationContext ctx,
                                                                  IEnumerable <TemplateParameter> templateParameters, EntityInstance closedTemplate)
        {
            if (templateParameters.Count() != closedTemplate.TemplateArguments.Count)
            {
                return(ConstraintMatch.UndefinedTemplateArguments);
            }

            foreach (Tuple <TemplateParameter, IEntityInstance> param_arg in templateParameters
                     .SyncZip(closedTemplate.TemplateArguments))
            {
                ConstraintMatch match = param_arg.Item2.ArgumentMatchesParameterConstraints(ctx, closedTemplate, param_arg.Item1);
                if (match != ConstraintMatch.Yes)
                {
                    return(match);
                }
            }

            return(ConstraintMatch.Yes);
        }