/// <summary> /// Finds the matching nodes of a <see cref="IClassConstantExpression"/>. /// </summary> /// <param name="node">The agent expression to check.</param> /// <param name="errorList">The list of errors found.</param> /// <param name="resolvedResult">The expression result types upon return.</param> /// <param name="resolvedException">Exceptions the expression can throw upon return.</param> /// <param name="constantSourceList">Sources of the constant expression upon return, if any.</param> /// <param name="expressionConstant">The expression constant upon return.</param> /// <param name="resolvedFinalFeature">The feature if the end of the path is a feature.</param> /// <param name="resolvedFinalDiscrete">The discrete if the end of the path is a discrete.</param> /// <param name="resolvedClassTypeName">The class type name upon return.</param> /// <param name="resolvedClassType">The class name upon return.</param> public static bool ResolveCompilerReferences(IClassConstantExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant, out IConstantFeature resolvedFinalFeature, out IDiscrete resolvedFinalDiscrete, out ITypeName resolvedClassTypeName, out IClassType resolvedClassType) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; resolvedFinalFeature = null; resolvedFinalDiscrete = null; resolvedClassTypeName = null; resolvedClassType = null; IIdentifier ClassIdentifier = (IIdentifier)node.ClassIdentifier; IIdentifier ConstantIdentifier = (IIdentifier)node.ConstantIdentifier; IClass EmbeddingClass = node.EmbeddingClass; string ValidClassText = ClassIdentifier.ValidText.Item; string ValidConstantText = ConstantIdentifier.ValidText.Item; ISealableDictionary <string, IImportedClass> ClassTable = EmbeddingClass.ImportedClassTable; if (!ClassTable.ContainsKey(ValidClassText)) { errorList.AddError(new ErrorUnknownIdentifier(ClassIdentifier, ValidClassText)); return(false); } IClass BaseClass = ClassTable[ValidClassText].Item; resolvedClassTypeName = BaseClass.ResolvedClassTypeName.Item; resolvedClassType = BaseClass.ResolvedClassType.Item; ITypeName ConstantTypeName; ICompiledType ConstantType; ISealableDictionary <IFeatureName, IDiscrete> DiscreteTable = BaseClass.DiscreteTable; ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = BaseClass.FeatureTable; if (FeatureName.TableContain(DiscreteTable, ValidConstantText, out IFeatureName Key, out IDiscrete Discrete)) { if (!Expression.IsLanguageTypeAvailable(LanguageClasses.Number.Guid, node, out ITypeName NumberTypeName, out ICompiledType NumberType)) { errorList.AddError(new ErrorNumberTypeMissing(node)); return(false); } if (Discrete.NumericValue.IsAssigned) { constantSourceList.Add((IExpression)Discrete.NumericValue.Item); } else { expressionConstant = new DiscreteLanguageConstant(Discrete); } resolvedFinalDiscrete = Discrete; ConstantTypeName = NumberTypeName; ConstantType = NumberType; }
private static bool CheckAssignemntIdentifier(IErrorList errorList, ISealableDictionary <IFeatureName, IFeatureInstance> featureTable, ISealableDictionary <string, ICompiledFeature> assignedFeatureTable, IIdentifier identifierItem) { bool Success = true; string ValidIdentifierText = identifierItem.ValidText.Item; if (assignedFeatureTable.ContainsKey(ValidIdentifierText)) { errorList.AddError(new ErrorIdentifierAlreadyListed(identifierItem, ValidIdentifierText)); Success = false; } else { if (FeatureName.TableContain(featureTable, ValidIdentifierText, out IFeatureName Key, out IFeatureInstance FeatureItem)) { bool ValidFeature = false; if (FeatureItem.Feature is AttributeFeature AsAttributeFeature) { ValidFeature = true; } else if (FeatureItem.Feature is IPropertyFeature AsPropertyFeature) { bool IsHandled = false; switch (AsPropertyFeature.PropertyKind) { case BaseNode.UtilityType.ReadOnly: ValidFeature = !AsPropertyFeature.GetterBody.IsAssigned; IsHandled = true; break; case BaseNode.UtilityType.ReadWrite: ValidFeature = !(AsPropertyFeature.GetterBody.IsAssigned && !AsPropertyFeature.SetterBody.IsAssigned); IsHandled = true; break; case BaseNode.UtilityType.WriteOnly: ValidFeature = true; IsHandled = true; break; } Debug.Assert(IsHandled); } if (ValidFeature) { assignedFeatureTable.Add(ValidIdentifierText, FeatureItem.Feature); } else { errorList.AddError(new ErrorAttributeOrPropertyRequired(identifierItem, ValidIdentifierText)); Success = false; } }
/// <summary> /// Gets the object a path is refering to. /// </summary> /// <param name="baseClass">The class where the path is used.</param> /// <param name="baseType">The type at the start of the path.</param> /// <param name="localScope">The local scope.</param> /// <param name="validPath">The path.</param> /// <param name="index">Index of the current identifier in the path.</param> /// <param name="errorList">The list of errors found.</param> /// <param name="finalFeature">The feature at the end of the path, if any, upon return.</param> /// <param name="finalDiscrete">The discrete at the end of the path, if any, upon return.</param> /// <param name="finalTypeName">The type name of the result.</param> /// <param name="finalType">The type of the result.</param> /// <param name="inheritBySideAttribute">Inherited from an effective body.</param> public static bool GetQualifiedPathFinalType(IClass baseClass, ICompiledType baseType, ISealableDictionary <string, IScopeAttributeFeature> localScope, IList <IIdentifier> validPath, int index, IErrorList errorList, out ICompiledFeature finalFeature, out IDiscrete finalDiscrete, out ITypeName finalTypeName, out ICompiledType finalType, out bool inheritBySideAttribute) { finalFeature = null; finalDiscrete = null; finalTypeName = null; finalType = null; inheritBySideAttribute = false; ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = baseType.FeatureTable; IIdentifier ValidIdentifier = validPath[index]; string ValidText = ValidIdentifier.ValidText.Item; if (index == 0 && localScope.ContainsKey(ValidText)) { return(GetQualifiedPathFinalTypeFromLocal(baseClass, baseType, localScope, validPath, index, errorList, out finalFeature, out finalDiscrete, out finalTypeName, out finalType, out inheritBySideAttribute)); } else if (FeatureName.TableContain(FeatureTable, ValidText, out IFeatureName Key, out IFeatureInstance Instance)) { return(GetQualifiedPathFinalTypeAsFeature(baseClass, baseType, localScope, validPath, index, errorList, Instance, out finalFeature, out finalDiscrete, out finalTypeName, out finalType, out inheritBySideAttribute)); }
/// <summary> /// Apply changes in this instance to arguments. /// </summary> /// <param name="importedClassTable">The table of imported classes</param> /// <param name="exportTable">The list of exports to change.</param> /// <param name="errorList">The list of errors found.</param> public virtual bool ApplyChange(ISealableDictionary <string, IImportedClass> importedClassTable, ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > exportTable, IErrorList errorList) { if (!ExportIdentifierExists(exportTable, errorList, out IFeatureName CurrentExportName, out ISealableDictionary <string, IClass> CurrentClassTable)) { return(false); } ISealableDictionary <string, ISealableDictionary <string, IClass> > ListedExportTable = new SealableDictionary <string, ISealableDictionary <string, IClass> >(); // string (export name) -> hashtable // string (class name) -> Class ISealableDictionary <string, IClass> ListedClassTable = new SealableDictionary <string, IClass>(); // string (class name) -> Class bool InvalidExportChange = false; foreach (IIdentifier IdentifierItem in IdentifierList) { Debug.Assert(IdentifierItem.ValidText.IsAssigned); string ValidIdentifier = IdentifierItem.ValidText.Item; if (FeatureName.TableContain(exportTable, ValidIdentifier, out IFeatureName EntryName, out ISealableDictionary <string, IClass> ListedExport)) { Debug.Assert(!ListedExportTable.ContainsKey(ValidIdentifier)); ListedExportTable.Add(ValidIdentifier, ListedExport); }
/// <summary> /// Finds the matching nodes of a <see cref="IAgentExpression"/>. /// </summary> /// <param name="node">The agent expression to check.</param> /// <param name="errorList">The list of errors found.</param> /// <param name="resolvedResult">The expression result types upon return.</param> /// <param name="resolvedException">Exceptions the expression can throw upon return.</param> /// <param name="constantSourceList">Sources of the constant expression upon return, if any.</param> /// <param name="expressionConstant">The constant value upon return, if any.</param> /// <param name="resolvedFeature">The feature found upon return.</param> public static bool ResolveCompilerReferences(IAgentExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant, out ICompiledFeature resolvedFeature) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; resolvedFeature = null; IIdentifier Delegated = (IIdentifier)node.Delegated; Debug.Assert(Delegated.ValidText.IsAssigned); string ValidText = Delegated.ValidText.Item; IFeatureInstance FeatureInstance; if (node.BaseType.IsAssigned) { IObjectType BaseType = (IObjectType)node.BaseType.Item; ICompiledType ResolvedBaseType = BaseType.ResolvedType.Item; ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = null; switch (ResolvedBaseType) { case IClassType AsClassType: FeatureTable = AsClassType.FeatureTable; break; case IFormalGenericType AsFormalGenericType: foreach (IConstraint Item in AsFormalGenericType.FormalGeneric.ConstraintList) { if (Item.ResolvedTypeWithRename.Item is IClassType Parent) { FeatureTable = Parent.FeatureTable; if (FeatureName.TableContain(FeatureTable, ValidText, out IFeatureName ParentKey, out IFeatureInstance ParentFeatureInstance)) { break; } } } break; } if (FeatureTable == null) { errorList.AddError(new ErrorClassTypeRequired(node)); return(false); } if (!FeatureName.TableContain(FeatureTable, ValidText, out IFeatureName Key, out FeatureInstance)) { errorList.AddError(new ErrorUnknownIdentifier(node, ValidText)); return(false); } } else { IClass EmbeddingClass = node.EmbeddingClass; if (!FeatureName.TableContain(EmbeddingClass.FeatureTable, ValidText, out IFeatureName Key, out FeatureInstance)) { errorList.AddError(new ErrorUnknownIdentifier(node, ValidText)); return(false); } } Debug.Assert(FeatureInstance.Feature != null); resolvedFeature = FeatureInstance.Feature; resolvedResult = new ResultType(resolvedFeature.ResolvedAgentTypeName.Item, resolvedFeature.ResolvedAgentType.Item, string.Empty); resolvedException = new ResultException(); expressionConstant = new AgentLanguageConstant(resolvedFeature); #if COVERAGE Debug.Assert(!node.IsComplex); #endif return(true); }
/// <summary> /// Finds the matching nodes of a <see cref="IUnaryOperatorExpression"/>. /// </summary> /// <param name="node">The agent expression to check.</param> /// <param name="errorList">The list of errors found.</param> /// <param name="resolvedResult">The expression result types upon return.</param> /// <param name="resolvedException">Exceptions the expression can throw upon return.</param> /// <param name="constantSourceList">Sources of the constant expression upon return, if any.</param> /// <param name="expressionConstant">The constant value upon return, if any.</param> /// <param name="selectedFeature">The matching feature upon return.</param> /// <param name="selectedOverload">The matching overload in <paramref name="selectedFeature"/> upon return.</param> /// <param name="selectedOverloadType">The matching overload type upon return.</param> public static bool ResolveCompilerReferences(IUnaryOperatorExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant, out IFunctionFeature selectedFeature, out IQueryOverload selectedOverload, out IQueryOverloadType selectedOverloadType) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; selectedFeature = null; selectedOverload = null; selectedOverloadType = null; IIdentifier Operator = (IIdentifier)node.Operator; string ValidText = Operator.ValidText.Item; IExpression RightExpression = (IExpression)node.RightExpression; IResultType RightResult = RightExpression.ResolvedResult.Item; if (!RightResult.TryGetResult(out ICompiledType RightExpressionType)) { errorList.AddError(new ErrorInvalidExpression(RightExpression)); return(false); } if (RightExpressionType is IClassType AsClassType) { ISealableDictionary <IFeatureName, IFeatureInstance> RightFeatureTable = AsClassType.FeatureTable; if (!FeatureName.TableContain(RightFeatureTable, ValidText, out IFeatureName Key, out IFeatureInstance Value)) { errorList.AddError(new ErrorUnknownIdentifier(RightExpression, ValidText)); return(false); } ICompiledFeature OperatorFeature = Value.Feature; ICompiledType OperatorType = OperatorFeature.ResolvedAgentType.Item; if (OperatorFeature is IFunctionFeature AsFunctionFeature && OperatorType is IFunctionType AsFunctionType) { IList <IQueryOverloadType> OperatorOverloadList = AsFunctionType.OverloadList; int SelectedOperatorIndex = -1; for (int i = 0; i < OperatorOverloadList.Count; i++) { IQueryOverloadType Overload = OperatorOverloadList[i]; if (Overload.ParameterList.Count == 0 && Overload.ResultList.Count == 1) { SelectedOperatorIndex = i; break; } } if (SelectedOperatorIndex < 0) { errorList.AddError(new ErrorInvalidOperator(Operator, ValidText)); return(false); } resolvedResult = Feature.CommonResultType(AsFunctionType.OverloadList); selectedFeature = AsFunctionFeature; selectedOverload = AsFunctionFeature.OverloadList[SelectedOperatorIndex]; selectedOverloadType = OperatorOverloadList[SelectedOperatorIndex]; resolvedException = new ResultException(selectedOverloadType.ExceptionIdentifierList); constantSourceList.Add(RightExpression); } else { errorList.AddError(new ErrorInvalidOperator(Operator, ValidText)); return(false); } }
/// <summary> /// Finds the matching nodes of a <see cref="IBinaryOperatorExpression"/>. /// </summary> /// <param name="node">The agent expression to check.</param> /// <param name="errorList">The list of errors found.</param> /// <param name="resolvedResult">The expression result types upon return.</param> /// <param name="resolvedException">Exceptions the expression can throw upon return.</param> /// <param name="constantSourceList">Sources of the constant expression upon return, if any.</param> /// <param name="expressionConstant">The constant value upon return, if any.</param> /// <param name="selectedFeature">The matching feature upon return.</param> /// <param name="selectedOverload">The matching overload in <paramref name="selectedFeature"/> upon return.</param> /// <param name="featureCall">Details of the feature call.</param> public static bool ResolveCompilerReferences(IBinaryOperatorExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant, out IFunctionFeature selectedFeature, out IQueryOverload selectedOverload, out IFeatureCall featureCall) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; selectedFeature = null; selectedOverload = null; featureCall = null; IExpression LeftExpression = (IExpression)node.LeftExpression; IIdentifier Operator = (IIdentifier)node.Operator; IExpression RightExpression = (IExpression)node.RightExpression; IResultType LeftResult = LeftExpression.ResolvedResult.Item; if (LeftResult.TryGetResult(out ICompiledType LeftExpressionType)) { if (LeftExpressionType is IClassType AsClassType) { string OperatorName = Operator.ValidText.Item; ISealableDictionary <IFeatureName, IFeatureInstance> LeftFeatureTable = AsClassType.FeatureTable; if (!FeatureName.TableContain(LeftFeatureTable, OperatorName, out IFeatureName Key, out IFeatureInstance Value)) { errorList.AddError(new ErrorUnknownIdentifier(Operator, OperatorName)); return(false); } Debug.Assert(Value.Feature != null); ICompiledFeature OperatorFeature = Value.Feature; ICompiledType OperatorType = OperatorFeature.ResolvedAgentType.Item; if (OperatorFeature is IFunctionFeature AsFunctionFeature && OperatorType is FunctionType AsFunctionType) { IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); foreach (IQueryOverloadType Overload in AsFunctionType.OverloadList) { ParameterTableList.Add(Overload.ParameterTable); } IResultType RightResult = RightExpression.ResolvedResult.Item; if (!Argument.ArgumentsConformToParameters(ParameterTableList, RightResult.ToList(), TypeArgumentStyles.Positional, errorList, Operator, out int SelectedIndex)) { return(false); } IQueryOverloadType SelectedOverloadType = AsFunctionType.OverloadList[SelectedIndex]; resolvedResult = new ResultType(SelectedOverloadType.ResultTypeList); selectedFeature = AsFunctionFeature; selectedOverload = AsFunctionFeature.OverloadList[SelectedIndex]; IArgument FirstArgument = new PositionalArgument(RightExpression); IList <IArgument> ArgumentList = new List <IArgument>() { FirstArgument }; List <IExpressionType> MergedArgumentList = new List <IExpressionType>(); bool IsArgumentValid = Argument.Validate(ArgumentList, MergedArgumentList, out TypeArgumentStyles TypeArgumentStyle, errorList); Debug.Assert(IsArgumentValid); featureCall = new FeatureCall(SelectedOverloadType.ParameterTable, SelectedOverloadType.ResultTable, ArgumentList, MergedArgumentList, TypeArgumentStyle); resolvedException = new ResultException(SelectedOverloadType.ExceptionIdentifierList); constantSourceList.Add(LeftExpression); constantSourceList.Add(RightExpression); } else { errorList.AddError(new ErrorInvalidOperator(Operator, OperatorName)); return(false); } } else { errorList.AddError(new ErrorInvalidExpression(LeftExpression)); return(false); } }