Пример #1
0
        private static bool ProcedureTypeConformToIndexerType(IProcedureType derivedType, IIndexerType baseType, IErrorList errorList, ISource sourceLocation)
        {
            bool Result = true;

            Debug.Assert(derivedType.ResolvedBaseType.IsAssigned);
            Debug.Assert(baseType.ResolvedBaseType.IsAssigned);

            Result &= TypeConformToBase(derivedType.ResolvedBaseType.Item, baseType.ResolvedBaseType.Item, errorList, sourceLocation, isConversionAllowed: false);

            if (baseType.IndexerKind != BaseNode.UtilityType.WriteOnly)
            {
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result = false;
            }

            bool MatchingOverload = false;

            foreach (ICommandOverloadType DerivedOverload in derivedType.OverloadList)
            {
                MatchingOverload |= ProcedureTypeConformToIndexerTypeOverloads(DerivedOverload, baseType, errorList, sourceLocation);
            }

            if (!MatchingOverload)
            {
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result = false;
            }

            return(Result);
        }
Пример #2
0
        /// <summary>
        /// Applies the rule.
        /// </summary>
        /// <param name="node">The node instance to modify.</param>
        /// <param name="data">Private data from CheckConsistency().</param>
        public override void Apply(ICommandInstruction node, object data)
        {
            IResultException     ResolvedException = ((Tuple <IResultException, ICompiledFeature, ICommandOverloadType, IFeatureCall, IProcedureType>)data).Item1;
            ICompiledFeature     SelectedFeature   = ((Tuple <IResultException, ICompiledFeature, ICommandOverloadType, IFeatureCall, IProcedureType>)data).Item2;
            ICommandOverloadType SelectedOverload  = ((Tuple <IResultException, ICompiledFeature, ICommandOverloadType, IFeatureCall, IProcedureType>)data).Item3;
            IFeatureCall         FeatureCall       = ((Tuple <IResultException, ICompiledFeature, ICommandOverloadType, IFeatureCall, IProcedureType>)data).Item4;
            IProcedureType       CommandFinalType  = ((Tuple <IResultException, ICompiledFeature, ICommandOverloadType, IFeatureCall, IProcedureType>)data).Item5;

            node.ResolvedException.Item = ResolvedException;
            node.SelectedFeature.Item   = SelectedFeature;
            node.SelectedOverload.Item  = SelectedOverload;
            node.FeatureCall.Item       = FeatureCall;
            node.CommandFinalType.Item  = CommandFinalType;
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpProcedureType"/> class.
        /// </summary>
        /// <param name="context">The creation context.</param>
        /// <param name="source">The Easly type from which the C# type is created.</param>
        /// <param name="originatingTypedef">The typedef where this type is declared.</param>
        protected CSharpProcedureType(ICSharpContext context, IProcedureType source, ICSharpTypedef originatingTypedef)
            : base(context, source, originatingTypedef)
        {
            Debug.Assert(source.OverloadList.Count > 0);

            ICSharpClass Owner = context.GetClass(source.EmbeddingClass);

            BaseType = Create(context, source.ResolvedBaseType.Item) as ICSharpTypeWithFeature;
            Debug.Assert(BaseType != null);

            foreach (ICommandOverloadType OverloadType in source.OverloadList)
            {
                ICSharpCommandOverloadType NewOverloadType = CSharpCommandOverloadType.Create(context, OverloadType, Owner);
                OverloadTypeList.Add(NewOverloadType);
            }
        }
Пример #4
0
        private static bool TypeConformToProcedureType(ICompiledType derivedType, IProcedureType baseType, IErrorList errorList, ISource sourceLocation)
        {
            bool Result    = false;
            bool IsHandled = false;

            if (derivedType is IClassType AsClassType)
            {
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result    = false;
                IsHandled = true;
            }
            else if (derivedType is IFunctionType AsFunctionType)
            {
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result    = false;
                IsHandled = true;
            }
            else if (derivedType is IProcedureType AsProcedureType)
            {
                Result    = ProcedureTypeConformToProcedureType(AsProcedureType, baseType, errorList, sourceLocation);
                IsHandled = true;
            }
            else if (derivedType is IPropertyType AsPropertyType)
            {
                Result    = PropertyTypeConformToProcedureType(AsPropertyType, baseType, errorList, sourceLocation);
                IsHandled = true;
            }
            else if (derivedType is IIndexerType AsIndexerType)
            {
                Result    = IndexerTypeConformToProcedureType(AsIndexerType, baseType, errorList, sourceLocation);
                IsHandled = true;
            }
            else if (derivedType is ITupleType AsTupleType)
            {
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result    = false;
                IsHandled = true;
            }

            Debug.Assert(IsHandled);
            return(Result);
        }
Пример #5
0
        /// <summary>
        /// Compares two types.
        /// </summary>
        /// <param name="type1">The first type.</param>
        /// <param name="type2">The second type.</param>
        public static bool TypesHaveIdenticalSignature(IProcedureType type1, IProcedureType type2)
        {
            bool IsIdentical = true;

            IsIdentical &= ObjectType.TypesHaveIdenticalSignature(type1.ResolvedBaseType.Item, type2.ResolvedBaseType.Item);
            IsIdentical &= type1.OverloadList.Count == type2.OverloadList.Count;

            foreach (ICommandOverloadType Overload1 in type1.OverloadList)
            {
                bool MatchingOverload = false;

                foreach (ICommandOverloadType Overload2 in type2.OverloadList)
                {
                    MatchingOverload |= CommandOverloadType.CommandOverloadsHaveIdenticalSignature(Overload1, Overload2);
                }

                IsIdentical &= MatchingOverload;
            }

            return(IsIdentical);
        }
Пример #6
0
        private static bool ProcedureTypeConformToPropertyType(IProcedureType derivedType, IPropertyType baseType, IErrorList errorList, ISource sourceLocation)
        {
            bool Result = true;

            Debug.Assert(derivedType.ResolvedBaseType.IsAssigned);
            Debug.Assert(baseType.ResolvedBaseType.IsAssigned);

            Result &= TypeConformToBase(derivedType.ResolvedBaseType.Item, baseType.ResolvedBaseType.Item, errorList, sourceLocation, isConversionAllowed: false);

            if (baseType.PropertyKind != BaseNode.UtilityType.WriteOnly)
            {
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result = false;
            }

            IErrorList AllOverloadErrorList    = new ErrorList();
            bool       MatchingDerivedOverload = false;

            foreach (ICommandOverloadType DerivedOverload in derivedType.OverloadList)
            {
                IErrorList OverloadErrorList = new ErrorList();
                bool       IsMatching        = CommandOverloadHasPropertyConformingBase(DerivedOverload, baseType, OverloadErrorList, sourceLocation);
                if (!IsMatching)
                {
                    Debug.Assert(!OverloadErrorList.IsEmpty);
                    AllOverloadErrorList.AddError(OverloadErrorList.At(0));
                }

                MatchingDerivedOverload |= IsMatching;
            }

            if (!MatchingDerivedOverload)
            {
                errorList.AddErrors(AllOverloadErrorList);
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result = false;
            }

            return(Result);
        }
Пример #7
0
        private static bool ProcedureTypeConformToProcedureType(IProcedureType derivedType, IProcedureType baseType, IErrorList errorList, ISource sourceLocation)
        {
            bool Result = true;

            Debug.Assert(derivedType.ResolvedBaseType.IsAssigned);
            Debug.Assert(baseType.ResolvedBaseType.IsAssigned);

            Result &= TypeConformToBase(derivedType.ResolvedBaseType.Item, baseType.ResolvedBaseType.Item, errorList, sourceLocation, isConversionAllowed: false);

            IErrorList AllOverloadErrorList = new ErrorList();

            foreach (ICommandOverloadType BaseOverload in baseType.OverloadList)
            {
                bool MatchingDerivedOverload = false;
                foreach (ICommandOverloadType DerivedOverload in derivedType.OverloadList)
                {
                    IErrorList OverloadErrorList = new ErrorList();
                    if (!CommandOverloadConformToBase(DerivedOverload, BaseOverload, OverloadErrorList, DerivedOverload))
                    {
                        Debug.Assert(!OverloadErrorList.IsEmpty);
                        AllOverloadErrorList.AddError(OverloadErrorList.At(0));
                    }
                    else
                    {
                        MatchingDerivedOverload = true;
                    }
                }

                if (!MatchingDerivedOverload)
                {
                    errorList.AddErrors(AllOverloadErrorList);
                    errorList.AddError(new ErrorOverloadMismatchConformance(sourceLocation, derivedType, baseType));
                    Result = false;
                }
            }

            return(Result);
        }
Пример #8
0
        private static bool IndexerTypeConformToProcedureType(IIndexerType derivedType, IProcedureType baseType, IErrorList errorList, ISource sourceLocation)
        {
            bool Result = true;

            Debug.Assert(derivedType.ResolvedBaseType.IsAssigned);
            Debug.Assert(baseType.ResolvedBaseType.IsAssigned);

            Result &= TypeConformToBase(derivedType.ResolvedBaseType.Item, baseType.ResolvedBaseType.Item, errorList, sourceLocation, isConversionAllowed: false);

            if (derivedType.IndexerKind == BaseNode.UtilityType.ReadOnly)
            {
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result = false;
            }

            if (baseType.OverloadList.Count > 1)
            {
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result = false;
            }

            ICommandOverloadType SingleOverload = baseType.OverloadList[0];

            if (SingleOverload.ParameterList.Count != derivedType.IndexParameterList.Count + 1 || SingleOverload.ParameterEnd != BaseNode.ParameterEndStatus.Closed)
            {
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result = false;
            }

            for (int i = 0; i + 1 < SingleOverload.ParameterList.Count && i < derivedType.IndexParameterList.Count; i++)
            {
                IEntityDeclaration BaseParameter    = SingleOverload.ParameterList[i];
                IEntityDeclaration DerivedParameter = derivedType.IndexParameterList[i];

                Debug.Assert(BaseParameter.ValidEntity.IsAssigned);
                Debug.Assert(BaseParameter.ValidEntity.Item.ResolvedEffectiveType.IsAssigned);
                Debug.Assert(DerivedParameter.ValidEntity.IsAssigned);
                Debug.Assert(DerivedParameter.ValidEntity.Item.ResolvedEffectiveType.IsAssigned);

                Result &= TypeConformToBase(DerivedParameter.ValidEntity.Item.ResolvedEffectiveType.Item, BaseParameter.ValidEntity.Item.ResolvedEffectiveType.Item, errorList, sourceLocation, isConversionAllowed: false);
            }

            if (SingleOverload.ParameterList.Count == derivedType.IndexParameterList.Count + 1)
            {
                Debug.Assert(derivedType.ResolvedEntityType.IsAssigned);

                IEntityDeclaration LastParameter = SingleOverload.ParameterList[derivedType.IndexParameterList.Count];
                Debug.Assert(LastParameter.ValidEntity.IsAssigned);
                Debug.Assert(LastParameter.ValidEntity.Item.ResolvedEffectiveType.IsAssigned);

                Result &= TypeConformToBase(derivedType.ResolvedEntityType.Item, LastParameter.ValidEntity.Item.ResolvedEffectiveType.Item, errorList, sourceLocation, isConversionAllowed: false);
            }

            Result &= ExceptionListConformToBase(derivedType.SetExceptionIdentifierList, SingleOverload.ExceptionIdentifierList, errorList, sourceLocation);

            return(Result);
        }
        /// <summary>
        /// Checks for errors before applying a rule.
        /// </summary>
        /// <param name="node">The node instance to check.</param>
        /// <param name="dataList">Optional data collected during inspection of sources.</param>
        /// <param name="data">Private data to give to Apply() upon return.</param>
        /// <returns>True if an error occured.</returns>
        public override bool CheckConsistency(IThrowInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            data = null;
            bool Success = true;

            IObjectType   ThrowExceptionType = (IObjectType)node.ExceptionType;
            ICompiledType ResolvedType       = ThrowExceptionType.ResolvedType.Item;
            IIdentifier   CreationRoutine    = (IIdentifier)node.CreationRoutine;
            string        ValidText          = CreationRoutine.ValidText.Item;
            IClass        EmbeddingClass     = node.EmbeddingClass;

            if (!Expression.IsLanguageTypeAvailable(LanguageClasses.Exception.Guid, node, out ITypeName ExceptionTypeName, out ICompiledType ExceptionType))
            {
                AddSourceError(new ErrorExceptionTypeMissing(node));
                return(false);
            }

            if (!ObjectType.TypeConformToBase(ResolvedType, ExceptionType, isConversionAllowed: true))
            {
                AddSourceError(new ErrorExceptionTypeRequired(node));
                return(false);
            }

            if (!FeatureName.TableContain(ResolvedType.FeatureTable, ValidText, out IFeatureName Key, out IFeatureInstance Value))
            {
                AddSourceError(new ErrorUnknownIdentifier(CreationRoutine, ValidText));
                return(false);
            }

            if (Value.Feature is CreationFeature AsCreationFeature)
            {
                List <IExpressionType> MergedArgumentList = new List <IExpressionType>();
                if (!Argument.Validate(node.ArgumentList, MergedArgumentList, out TypeArgumentStyles TypeArgumentStyle, ErrorList))
                {
                    return(false);
                }

                IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >();
                Debug.Assert(AsCreationFeature.ResolvedAgentType.IsAssigned);
                ICompiledType  FinalType       = AsCreationFeature.ResolvedAgentType.Item;
                IProcedureType AsProcedureType = FinalType as IProcedureType;
                Debug.Assert(AsProcedureType != null);

                foreach (ICommandOverloadType Overload in AsProcedureType.OverloadList)
                {
                    ParameterTableList.Add(Overload.ParameterTable);
                }

                if (!Argument.ArgumentsConformToParameters(ParameterTableList, MergedArgumentList, TypeArgumentStyle, ErrorList, node, out int SelectedIndex))
                {
                    return(false);
                }

                ICommandOverloadType SelectedOverload = AsProcedureType.OverloadList[SelectedIndex];

                IResultException ResolvedException = new ResultException();
                ResolvedException.Add(ValidText);

                Debug.Assert(ResolvedException.At(0).Text == ValidText);
                Debug.Assert(ResolvedException.At(0).ValidText.IsAssigned);
                Debug.Assert(ResolvedException.At(0).ValidText.Item == ValidText);

                foreach (IArgument Item in node.ArgumentList)
                {
                    ResultException.Merge(ResolvedException, Item.ResolvedException.Item);
                }

                ResultException.Merge(ResolvedException, SelectedOverload.ExceptionIdentifierList);

                IFeatureCall FeatureCall = new FeatureCall(SelectedOverload.ParameterTable, new List <IParameter>(), node.ArgumentList, MergedArgumentList, TypeArgumentStyle);

                data = new Tuple <ICompiledType, IResultException, IFeatureCall>(ResolvedType, ResolvedException, FeatureCall);
            }
            else
            {
                AddSourceError(new ErrorCreationFeatureRequired(CreationRoutine, ValidText));
                return(false);
            }

            return(Success);
        }
Пример #10
0
 /// <summary>
 /// Create a new C# type.
 /// </summary>
 /// <param name="context">The creation context.</param>
 /// <param name="source">The Easly type from which the C# type is created.</param>
 /// <param name="originatingTypedef">The typedef where this type is declared.</param>
 public static ICSharpProcedureType Create(ICSharpContext context, IProcedureType source, ICSharpTypedef originatingTypedef)
 {
     return(new CSharpProcedureType(context, source, originatingTypedef));
 }
Пример #11
0
 /// <summary>
 /// Create a new C# type.
 /// </summary>
 /// <param name="context">The creation context.</param>
 /// <param name="source">The Easly type from which the C# type is created.</param>
 public static ICSharpProcedureType Create(ICSharpContext context, IProcedureType source)
 {
     return(new CSharpProcedureType(context, source));
 }
Пример #12
0
        private static bool PropertyTypeConformToProcedureType(IPropertyType derivedType, IProcedureType baseType, IErrorList errorList, ISource sourceLocation)
        {
            bool Result = true;

            Debug.Assert(derivedType.ResolvedBaseType.IsAssigned);
            Debug.Assert(baseType.ResolvedBaseType.IsAssigned);

            Result &= TypeConformToBase(derivedType.ResolvedBaseType.Item, baseType.ResolvedBaseType.Item, errorList, sourceLocation, isConversionAllowed: false);

            if (derivedType.PropertyKind == BaseNode.UtilityType.ReadOnly)
            {
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result = false;
            }

            if (baseType.OverloadList.Count > 1)
            {
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result = false;
            }

            ICommandOverloadType SingleOverload = baseType.OverloadList[0];

            if (SingleOverload.ParameterList.Count != 1 || SingleOverload.ParameterEnd != BaseNode.ParameterEndStatus.Closed)
            {
                errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType));
                Result = false;
            }

            if (SingleOverload.ParameterList.Count == 1)
            {
                IEntityDeclaration OverloadValue = SingleOverload.ParameterList[0];
                Debug.Assert(derivedType.ResolvedEntityType.IsAssigned);
                Debug.Assert(OverloadValue.ValidEntity.IsAssigned);
                Debug.Assert(OverloadValue.ValidEntity.Item.ResolvedEffectiveType.IsAssigned);

                Result &= TypeConformToBase(derivedType.ResolvedEntityType.Item, OverloadValue.ValidEntity.Item.ResolvedEffectiveType.Item, errorList, sourceLocation, isConversionAllowed: false);
                Result &= ExceptionListConformToBase(derivedType.SetExceptionIdentifierList, SingleOverload.ExceptionIdentifierList, errorList, sourceLocation);
            }

            return(Result);
        }
Пример #13
0
        /// <summary>
        /// Checks for errors before applying a rule.
        /// </summary>
        /// <param name="node">The node instance to check.</param>
        /// <param name="dataList">Optional data collected during inspection of sources.</param>
        /// <param name="data">Private data to give to Apply() upon return.</param>
        /// <returns>True if an error occured.</returns>
        public override bool CheckConsistency(ICommandInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            data = null;
            bool Success = true;

            IQualifiedName      Command   = (IQualifiedName)node.Command;
            IList <IIdentifier> ValidPath = Command.ValidPath.Item;
            IClass     EmbeddingClass     = node.EmbeddingClass;
            IClassType BaseType           = EmbeddingClass.ResolvedClassType.Item;

            ISealableDictionary <string, IScopeAttributeFeature> LocalScope = Scope.CurrentScope(node);

            if (!ObjectType.GetQualifiedPathFinalType(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, ErrorList, out ICompiledFeature FinalFeature, out IDiscrete FinalDiscrete, out ITypeName FinalTypeName, out ICompiledType FinalType, out bool InheritBySideAttribute))
            {
                return(false);
            }

            Debug.Assert(FinalFeature != null);

            IList <IArgument>      ArgumentList       = node.ArgumentList;
            List <IExpressionType> MergedArgumentList = new List <IExpressionType>();

            if (!Argument.Validate(ArgumentList, MergedArgumentList, out TypeArgumentStyles ArgumentStyle, ErrorList))
            {
                return(false);
            }

            IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >();
            ICommandOverloadType       SelectedOverload            = null;
            ISealableList <IParameter> SelectedParameterList       = null;
            IProcedureType             CommandFinalType            = null;
            bool IsHandled = false;

            switch (FinalType)
            {
            case IFunctionType AsFunctionType:
            case IPropertyType AsPropertyType:
                AddSourceError(new ErrorInvalidInstruction(node));
                Success   = false;
                IsHandled = true;
                break;

            case IProcedureType AsProcedureType:
                foreach (ICommandOverloadType Overload in AsProcedureType.OverloadList)
                {
                    ParameterTableList.Add(Overload.ParameterTable);
                }

                int SelectedIndex;
                if (!Argument.ArgumentsConformToParameters(ParameterTableList, MergedArgumentList, ArgumentStyle, ErrorList, node, out SelectedIndex))
                {
                    Success = false;
                }
                else
                {
                    SelectedOverload      = AsProcedureType.OverloadList[SelectedIndex];
                    SelectedParameterList = ParameterTableList[SelectedIndex];
                    CommandFinalType      = AsProcedureType;
                }
                IsHandled = true;
                break;
            }

            Debug.Assert(IsHandled);

            if (Success)
            {
                ObjectType.FillResultPath(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, Command.ValidResultTypePath.Item);

                IResultException ResolvedException = new ResultException();

                foreach (IArgument Item in node.ArgumentList)
                {
                    ResultException.Merge(ResolvedException, Item.ResolvedException.Item);
                }

                IList <IIdentifier> CommandInstructionException = SelectedOverload.ExceptionIdentifierList;
                ResultException.Merge(ResolvedException, CommandInstructionException);

                IFeatureCall FeatureCall = new FeatureCall(SelectedParameterList, new List <IParameter>(), ArgumentList, MergedArgumentList, ArgumentStyle);

                data = new Tuple <IResultException, ICompiledFeature, ICommandOverloadType, IFeatureCall, IProcedureType>(ResolvedException, FinalFeature, SelectedOverload, FeatureCall, CommandFinalType);
            }

            return(Success);
        }
Пример #14
0
        /// <summary>
        /// Checks for errors before applying a rule.
        /// </summary>
        /// <param name="node">The node instance to check.</param>
        /// <param name="dataList">Optional data collected during inspection of sources.</param>
        /// <param name="data">Private data to give to Apply() upon return.</param>
        /// <returns>True if an error occured.</returns>
        public override bool CheckConsistency(IPrecursorInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            data = null;
            bool Success = true;

            IClass     EmbeddingClass = node.EmbeddingClass;
            IClassType BaseType       = EmbeddingClass.ResolvedClassType.Item;
            ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = EmbeddingClass.FeatureTable;
            IFeature InnerFeature = node.EmbeddingFeature;

            if (InnerFeature is IIndexerFeature AsIndexerFeature)
            {
                AddSourceError(new ErrorPrecursorNotAllowedInIndexer(node));
                return(false);
            }
            else
            {
                IFeature         AsNamedFeature = InnerFeature;
                IFeatureInstance Instance       = FeatureTable[AsNamedFeature.ValidFeatureName.Item];
                OnceReference <IFeatureInstance> SelectedPrecursor = new OnceReference <IFeatureInstance>();
                IList <IPrecursorInstance>       PrecursorList     = Instance.PrecursorList;

                if (node.AncestorType.IsAssigned)
                {
                    IObjectType DeclaredAncestor = (IObjectType)node.AncestorType.Item;

                    if (DeclaredAncestor.ResolvedType.Item is IClassType AsClassTypeAncestor)
                    {
                        foreach (IPrecursorInstance Item in PrecursorList)
                        {
                            if (Item.Ancestor.BaseClass == AsClassTypeAncestor.BaseClass)
                            {
                                SelectedPrecursor.Item = Item.Precursor;
                                break;
                            }
                        }
                    }

                    if (!SelectedPrecursor.IsAssigned)
                    {
                        AddSourceError(new ErrorInvalidPrecursor(DeclaredAncestor));
                        return(false);
                    }
                }
                else if (Instance.PrecursorList.Count > 1)
                {
                    AddSourceError(new ErrorInvalidPrecursor(node));
                    return(false);
                }
                else if (Instance.PrecursorList.Count == 0)
                {
                    AddSourceError(new ErrorNoPrecursor(node));
                    return(false);
                }
                else
                {
                    SelectedPrecursor.Item = Instance.PrecursorList[0].Precursor;
                }

                List <IExpressionType> MergedArgumentList = new List <IExpressionType>();
                if (!Argument.Validate(node.ArgumentList, MergedArgumentList, out TypeArgumentStyles TypeArgumentStyle, ErrorList))
                {
                    return(false);
                }

                IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >();

                ICompiledFeature           OperatorFeature = SelectedPrecursor.Item.Feature;
                ICompiledType              OperatorType    = OperatorFeature.ResolvedAgentType.Item;
                IList <IIdentifier>        PrecursorInstructionException = null;
                ISealableList <IParameter> SelectedParameterList         = null;

                // This has been checked in the type pass.
                IProcedureType AsProcedureType = OperatorType as IProcedureType;
                Debug.Assert(AsProcedureType != null);
                foreach (ICommandOverloadType Overload in AsProcedureType.OverloadList)
                {
                    ParameterTableList.Add(Overload.ParameterTable);
                }

                if (!Argument.ArgumentsConformToParameters(ParameterTableList, MergedArgumentList, TypeArgumentStyle, ErrorList, node, out int SelectedIndex))
                {
                    return(false);
                }

                ICommandOverloadType SelectedOverload = AsProcedureType.OverloadList[SelectedIndex];
                PrecursorInstructionException = SelectedOverload.ExceptionIdentifierList;
                SelectedParameterList         = SelectedOverload.ParameterTable;

                IResultException ResolvedException = new ResultException();

                foreach (IArgument Item in node.ArgumentList)
                {
                    ResultException.Merge(ResolvedException, Item.ResolvedException.Item);
                }

                ResultException.Merge(ResolvedException, PrecursorInstructionException);

                IFeatureCall FeatureCall = new FeatureCall(SelectedParameterList, new List <IParameter>(), node.ArgumentList, MergedArgumentList, TypeArgumentStyle);

                data = new Tuple <IResultException, IFeatureCall>(ResolvedException, FeatureCall);
            }

            return(Success);
        }
Пример #15
0
        /// <summary>
        /// Creates a procedure type with resolved arguments.
        /// </summary>
        /// <param name="baseTypeName">Name of the resolved base type.</param>
        /// <param name="baseType">The base type.</param>
        /// <param name="resolvedBaseType">The resolved base type.</param>
        /// <param name="overloadList">The list of resolved overloads.</param>
        /// <param name="resolvedTypeName">The type name upon return.</param>
        /// <param name="resolvedType">The type upon return.</param>
        public static void BuildType(ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, IList <ICommandOverloadType> overloadList, out ITypeName resolvedTypeName, out IProcedureType resolvedType)
        {
            IProcedureType ResolvedProcedureType = new ProcedureType(baseTypeName, baseType, resolvedBaseType, overloadList);

            resolvedTypeName = new TypeName(ResolvedProcedureType.TypeFriendlyName);
            resolvedType     = ResolvedProcedureType;
        }
Пример #16
0
        /// <summary>
        /// Checks if a matching procedure type exists in a type table.
        /// </summary>
        /// <param name="typeTable">The table of existing types.</param>
        /// <param name="baseType">The resolved base type.</param>
        /// <param name="overloadList">The list of resolved overloads.</param>
        /// <param name="resolvedTypeName">The type name upon return.</param>
        /// <param name="resolvedType">The type upon return.</param>
        public static bool TypeTableContaining(ISealableDictionary <ITypeName, ICompiledType> typeTable, ICompiledTypeWithFeature baseType, IList <ICommandOverloadType> overloadList, out ITypeName resolvedTypeName, out IProcedureType resolvedType)
        {
            resolvedTypeName = null;
            resolvedType     = null;
            bool Result = false;

            foreach (KeyValuePair <ITypeName, ICompiledType> Entry in typeTable)
            {
                if (Entry.Value is IProcedureType AsProcedureType)
                {
                    if (AsProcedureType.ResolvedBaseType.Item == baseType && AsProcedureType.OverloadList.Count == overloadList.Count)
                    {
                        bool AllOverloadsEqual = true;
                        foreach (ICommandOverloadType OverloadItem in overloadList)
                        {
                            AllOverloadsEqual &= IsCommandOverloadMatching(typeTable, OverloadItem, AsProcedureType.OverloadList);
                        }

                        if (AllOverloadsEqual)
                        {
                            Debug.Assert(!Result);

                            resolvedTypeName = Entry.Key;
                            resolvedType     = AsProcedureType;
                            Result           = true;
                        }
                    }
                }
            }

            return(Result);
        }
Пример #17
0
 /// <summary>
 /// Locates, or creates, a resolved procedure type.
 /// </summary>
 /// <param name="typeTable">The table of existing types.</param>
 /// <param name="baseTypeName">Name of the resolved base type.</param>
 /// <param name="baseType">The base type.</param>
 /// <param name="resolvedBaseType">The resolved base type.</param>
 /// <param name="overloadList">The list of resolved overloads.</param>
 /// <param name="resolvedTypeName">The type name upon return.</param>
 /// <param name="resolvedType">The type upon return.</param>
 public static void ResolveType(ISealableDictionary <ITypeName, ICompiledType> typeTable, ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, IList <ICommandOverloadType> overloadList, out ITypeName resolvedTypeName, out IProcedureType resolvedType)
 {
     if (!TypeTableContaining(typeTable, resolvedBaseType, overloadList, out resolvedTypeName, out resolvedType))
     {
         BuildType(baseTypeName, baseType, resolvedBaseType, overloadList, out resolvedTypeName, out resolvedType);
         typeTable.Add(resolvedTypeName, resolvedType);
     }
 }