/// <summary> /// Reset some intermediate results. /// </summary> /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param> public void Reset(IRuleTemplateList ruleTemplateList) { bool IsHandled = false; if (ruleTemplateList == RuleTemplateSet.Identifiers || ruleTemplateList == RuleTemplateSet.Contract || ruleTemplateList == RuleTemplateSet.Body) { IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Types) { ResolvedBaseTypeName = new OnceReference <ITypeName>(); ResolvedBaseType = new OnceReference <IClassType>(); ResolvedEntityTypeName = new OnceReference <ITypeName>(); ResolvedEntityType = new OnceReference <ICompiledType>(); ParameterTable = new SealableList <IParameter>(); ResolvedTypeName = new OnceReference <ITypeName>(); ResolvedType = new OnceReference <ICompiledType>(); DiscreteTable = new SealableDictionary <IFeatureName, IDiscrete>(); FeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>(); ExportTable = new SealableDictionary <IFeatureName, ISealableDictionary <string, IClass> >(); ConformanceTable = new SealableDictionary <ITypeName, ICompiledType>(); InstancingRecordList = new List <TypeInstancingRecord>(); OriginatingTypedef = new OnceReference <ITypedef>(); IsHandled = true; } Debug.Assert(IsHandled); }
/// <summary> /// Reset some intermediate results. /// </summary> /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param> public void Reset(IRuleTemplateList ruleTemplateList) { bool IsHandled = false; if (ruleTemplateList == RuleTemplateSet.Identifiers || ruleTemplateList == RuleTemplateSet.Body) { IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Types) { LocalScope = new SealableDictionary <string, IScopeAttributeFeature>(); InnerScopes = new List <IScopeHolder>(); FullScope = new SealableDictionary <string, IScopeAttributeFeature>(); ParameterTable = new SealableList <IParameter>(); ResolvedAssociatedType = new OnceReference <ICommandOverloadType>(); IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Contract) { AdditionalScope = new SealableDictionary <string, IScopeAttributeFeature>(); AdditionalScope.Seal(); ResolvedBody = new OnceReference <ICompiledBody>(); IsHandled = true; } Debug.Assert(IsHandled); }
private static bool ResolveCallClass(IPrecursorExpression node, IFeatureInstance selectedPrecursor, List <IExpressionType> mergedArgumentList, TypeArgumentStyles argumentStyle, IErrorList errorList, ref ResolvedExpression resolvedExpression, out ISealableList <IParameter> selectedParameterList, out ISealableList <IParameter> selectedResultList, out List <IExpressionType> resolvedArgumentList) { selectedParameterList = null; selectedResultList = null; resolvedArgumentList = null; IList <IArgument> ArgumentList = node.ArgumentList; if (ArgumentList.Count > 0) { errorList.AddError(new ErrorInvalidExpression(node)); return(false); } else { ICompiledFeature OperatorFeature = selectedPrecursor.Feature; ITypeName OperatorTypeName = OperatorFeature.ResolvedEffectiveTypeName.Item; ICompiledType OperatorType = OperatorFeature.ResolvedEffectiveType.Item; IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); resolvedExpression.ResolvedResult = new ResultType(OperatorTypeName, OperatorType, string.Empty); resolvedExpression.ResolvedException = new ResultException(); selectedParameterList = new SealableList <IParameter>(); selectedResultList = new SealableList <IParameter>(); resolvedArgumentList = new List <IExpressionType>(); } return(true); }
/// <summary> /// Finds the matching nodes of a <see cref="IResultOfExpression"/>. /// </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> public static bool ResolveCompilerReferences(IResultOfExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; IExpression Source = (IExpression)node.Source; IResultType ResolvedSourceResult = Source.ResolvedResult.Item; int ResultNameIndex = ResolvedSourceResult.ResultNameIndex; if (ResultNameIndex < 0) { errorList.AddError(new ErrorInvalidExpression(node)); return(false); } Debug.Assert(ResolvedSourceResult.Preferred != null); resolvedResult = new ResultType(ResolvedSourceResult.Preferred); constantSourceList.Add(Source); ResultException.Propagate(Source.ResolvedException, out resolvedException); #if COVERAGE Debug.Assert(node.IsComplex); #endif return(true); }
/// <summary> /// Reset some intermediate results. /// </summary> /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param> public void Reset(IRuleTemplateList ruleTemplateList) { bool IsHandled = false; if (ruleTemplateList == RuleTemplateSet.Identifiers || ruleTemplateList == RuleTemplateSet.Types) { IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Contract) { ResolvedResult = new OnceReference <IResultType>(); ConstantSourceList = new SealableList <IExpression>(); ExpressionConstant = new OnceReference <ILanguageConstant>(); ResolvedFinalFeature = new OnceReference <ICompiledFeature>(); ResolvedFinalDiscrete = new OnceReference <IDiscrete>(); IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Body) { ResolvedException = new OnceReference <IResultException>(); SelectedResultList = new SealableList <IParameter>(); SelectedOverload = new OnceReference <IQueryOverload>(); SelectedOverloadType = new OnceReference <IQueryOverloadType>(); FeatureCall = new OnceReference <IFeatureCall>(); InheritBySideAttribute = false; IsHandled = true; } Debug.Assert(IsHandled); }
/// <summary> /// Reset some intermediate results. /// </summary> /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param> public void Reset(IRuleTemplateList ruleTemplateList) { bool IsHandled = false; if (ruleTemplateList == RuleTemplateSet.Identifiers || ruleTemplateList == RuleTemplateSet.Types) { IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Contract) { ResolvedResult = new OnceReference <IResultType>(); ConstantSourceList = new SealableList <IExpression>(); ExpressionConstant = new OnceReference <ILanguageConstant>(); ResolvedPrecursor = new OnceReference <IFeatureInstance>(); IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Body) { ResolvedException = new OnceReference <IResultException>(); ResolvedIndexer = new OnceReference <IIndexerFeature>(); FeatureCall = new OnceReference <IFeatureCall>(); IsHandled = true; } Debug.Assert(IsHandled); }
/// <summary> /// Reset some intermediate results. /// </summary> /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param> public void Reset(IRuleTemplateList ruleTemplateList) { bool IsHandled = false; if (ruleTemplateList == RuleTemplateSet.Identifiers || ruleTemplateList == RuleTemplateSet.Types) { IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Contract) { ResolvedResult = new OnceReference <IResultType>(); ConstantSourceList = new SealableList <IExpression>(); ExpressionConstant = new OnceReference <ILanguageConstant>(); ResolvedAgentTypeName = new OnceReference <ITypeName>(); ResolvedAgentType = new OnceReference <ICompiledType>(); ResolvedFeature = new OnceReference <ICompiledFeature>(); IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Body) { ResolvedException = new OnceReference <IResultException>(); IsHandled = true; } Debug.Assert(IsHandled); }
/// <summary> /// Finds the matching nodes of a <see cref="IUnaryNotExpression"/>. /// </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> public static bool ResolveCompilerReferences(IUnaryNotExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; IExpression RightExpression = (IExpression)node.RightExpression; IClass EmbeddingClass = node.EmbeddingClass; bool IsRightClassType = Expression.GetClassTypeOfExpression(RightExpression, errorList, out IClassType RightExpressionClassType); if (!IsRightClassType) { return(false); } Expression.IsLanguageTypeAvailable(LanguageClasses.Boolean.Guid, node, out ITypeName BooleanTypeName, out ICompiledType BooleanType); Expression.IsLanguageTypeAvailable(LanguageClasses.Event.Guid, node, out ITypeName EventTypeName, out ICompiledType EventType); Debug.Assert(RightExpressionClassType == BooleanType || RightExpressionClassType == EventType); node.SetIsEventExpression(RightExpressionClassType != BooleanType); constantSourceList.Add(RightExpression); resolvedResult = new ResultType(BooleanTypeName, BooleanType, string.Empty); ResultException.Propagate(RightExpression.ResolvedException, out resolvedException); #if COVERAGE Debug.Assert(node.IsComplex); #endif return(true); }
/// <summary> /// Finds the matching nodes of a <see cref="IManifestCharacterExpression"/>. /// </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> public static bool ResolveCompilerReferences(IManifestCharacterExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; IClass EmbeddingClass = node.EmbeddingClass; string ValidText = node.ValidText.Item; Debug.Assert(ValidText.Length == 1); char ValidChar = ValidText[0]; if (!Expression.IsLanguageTypeAvailable(LanguageClasses.Character.Guid, node, out ITypeName CharacterTypeName, out ICompiledType CharacterType)) { errorList.AddError(new ErrorCharacterTypeMissing(node)); return(false); } resolvedResult = new ResultType(CharacterTypeName, CharacterType, string.Empty); resolvedException = new ResultException(); expressionConstant = new CharacterLanguageConstant(ValidChar); #if COVERAGE Debug.Assert(!node.IsComplex); #endif return(true); }
/// <summary> /// Finds the matching nodes of a <see cref="IManifestNumberExpression"/>. /// </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 type upon return.</param> public static bool ResolveCompilerReferences(IManifestNumberExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; IClass EmbeddingClass = node.EmbeddingClass; string NumberText = node.ValidText.Item; ISealableDictionary <ITypeName, ICompiledType> TypeTable = EmbeddingClass.TypeTable; if (!Expression.IsLanguageTypeAvailable(LanguageClasses.Number.Guid, node, out ITypeName NumberTypeName, out ICompiledType NumberType)) { errorList.AddError(new ErrorNumberTypeMissing(node)); return(false); } resolvedResult = new ResultType(NumberTypeName, NumberType, string.Empty); resolvedException = new ResultException(); FormattedNumber FormattedNumber = FormattedNumber.Parse(NumberText); Debug.Assert(string.IsNullOrEmpty(FormattedNumber.InvalidText)); expressionConstant = new NumberLanguageConstant(FormattedNumber.Value); #if COVERAGE Debug.Assert(!node.IsComplex); #endif return(true); }
/// <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; }
/// <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(IQueryOverloadType node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; ISealableList <IParameter> ParameterTable = new SealableList <IParameter>(); ISealableList <IParameter> ResultTable = new SealableList <IParameter>(); foreach (IEntityDeclaration Item in node.ParameterList) { IName ParameterName = (IName)Item.EntityName; Debug.Assert(ParameterName.ValidText.IsAssigned); string ValidText = ParameterName.ValidText.Item; IScopeAttributeFeature ParameterFeature = Item.ValidEntity.Item; if (Parameter.TableContainsName(ParameterTable, ValidText)) { AddSourceError(new ErrorDuplicateName(ParameterName, ValidText)); Success = false; } else { ParameterTable.Add(new Parameter(ValidText, ParameterFeature)); } } foreach (IEntityDeclaration Item in node.ResultList) { IName ResultName = (IName)Item.EntityName; Debug.Assert(ResultName.ValidText.IsAssigned); string ValidText = ResultName.ValidText.Item; IScopeAttributeFeature ResultFeature = Item.ValidEntity.Item; if (Parameter.TableContainsName(ResultTable, ValidText) || Parameter.TableContainsName(ParameterTable, ValidText)) { AddSourceError(new ErrorDuplicateName(ResultName, ValidText)); Success = false; } else { ResultTable.Add(new Parameter(ValidText, ResultFeature)); } } if (Success) { data = new Tuple <ISealableList <IParameter>, ISealableList <IParameter> >(ParameterTable, ResultTable); } return(Success); }
/// <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(ICommandOverload node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = new SealableDictionary <string, IScopeAttributeFeature>(); ISealableList <IParameter> ParameterTable = new SealableList <IParameter>(); foreach (EntityDeclaration Item in node.ParameterList) { IName SourceName = (IName)Item.EntityName; string ValidName = SourceName.ValidText.Item; if (CheckedScope.ContainsKey(ValidName)) { AddSourceError(new ErrorDuplicateName(SourceName, ValidName)); Success = false; } else { CheckedScope.Add(ValidName, Item.ValidEntity.Item); ParameterTable.Add(new Parameter(ValidName, Item.ValidEntity.Item)); } } IList <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedScope, node.InnerScopes, ConflictList); foreach (IEntityDeclaration Item in node.ParameterList) { IScopeAttributeFeature LocalEntity = Item.ValidEntity.Item; string ValidFeatureName = LocalEntity.ValidFeatureName.Item.Name; if (ConflictList.Contains(ValidFeatureName)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidFeatureName)); Success = false; } } if (Success) { data = new Tuple <ISealableDictionary <string, IScopeAttributeFeature>, ISealableList <IParameter> >(CheckedScope, ParameterTable); } return(Success); }
/// <summary> /// Finds the matching nodes of a <see cref="IInitializedObjectExpression"/>. /// </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="initializedObjectTypeName">The initialized object type name upon return.</param> /// <param name="initializedObjectType">The initialized object type upon return.</param> /// <param name="assignedFeatureTable">The table of assigned values upon return.</param> public static bool ResolveCompilerReferences(IInitializedObjectExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant, out ITypeName initializedObjectTypeName, out IClassType initializedObjectType, out ISealableDictionary <string, ICompiledFeature> assignedFeatureTable) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; initializedObjectTypeName = null; initializedObjectType = null; assignedFeatureTable = new SealableDictionary <string, ICompiledFeature>(); IIdentifier ClassIdentifier = (IIdentifier)node.ClassIdentifier; IList <IAssignmentArgument> AssignmentList = node.AssignmentList; IClass EmbeddingClass = node.EmbeddingClass; string ValidText = ClassIdentifier.ValidText.Item; if (!EmbeddingClass.ImportedClassTable.ContainsKey(ValidText)) { errorList.AddError(new ErrorUnknownIdentifier(ClassIdentifier, ValidText)); return(false); } IClass BaseClass = EmbeddingClass.ImportedClassTable[ValidText].Item; Debug.Assert(BaseClass.ResolvedClassTypeName.IsAssigned); Debug.Assert(BaseClass.ResolvedClassType.IsAssigned); initializedObjectTypeName = BaseClass.ResolvedClassTypeName.Item; initializedObjectType = BaseClass.ResolvedClassType.Item; if (!CheckAssignemntList(node, errorList, BaseClass.FeatureTable, constantSourceList, assignedFeatureTable)) { return(false); } resolvedResult = new ResultType(initializedObjectTypeName, initializedObjectType, string.Empty); if (!ResolveObjectInitialization(node, errorList, assignedFeatureTable)) { return(false); } resolvedException = new ResultException(); #if COVERAGE Debug.Assert(!node.IsComplex); #endif return(true); }
/// <summary> /// Finds the matching nodes of a <see cref="IKeywordExpression"/>. /// </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> public static bool ResolveCompilerReferences(IKeywordExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; IClass EmbeddingClass = node.EmbeddingClass; BaseNode.Keyword Value = node.Value; if (!IsKeywordAvailable(Value, node, errorList, out ITypeName KeywordTypeName, out ICompiledType KeywordType)) { return(false); } resolvedResult = new ResultType(KeywordTypeName, KeywordType, Value.ToString()); resolvedException = new ResultException(); bool IsHandled = false; switch (Value) { case BaseNode.Keyword.True: case BaseNode.Keyword.False: expressionConstant = new BooleanLanguageConstant(Value == BaseNode.Keyword.True); IsHandled = true; break; case BaseNode.Keyword.Current: case BaseNode.Keyword.Value: case BaseNode.Keyword.Result: case BaseNode.Keyword.Retry: case BaseNode.Keyword.Exception: case BaseNode.Keyword.Indexer: IsHandled = true; break; } Debug.Assert(IsHandled); #if COVERAGE Debug.Assert(!node.IsComplex); #endif return(true); }
/// <summary> /// Initializes a new instance of the <see cref="ParserOptions" /> class. /// </summary> /// <param name="template">The template.</param> /// <param name="sourceStream">The source stream.</param> /// <param name="encoding">The encoding.</param> public ParserOptions([NotNull] string template, [CanBeNull] Func <Stream> sourceStream, [CanBeNull] Encoding encoding) { Template = template ?? ""; StreamFactory = new ByteCounterFactory(sourceStream); Encoding = encoding ?? Encoding.UTF8; _formatters = new MorestachioFormatterService(); Null = string.Empty; MaxSize = 0; DisableContentEscaping = false; Timeout = TimeSpan.Zero; PartialStackSize = 255; _customDocumentItemProviders = new SealableList <CustomDocumentItemProvider>(); CultureInfo = CultureInfo.CurrentCulture; }
/// <summary> /// Reset some intermediate results. /// </summary> /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param> public void Reset(IRuleTemplateList ruleTemplateList) { bool IsHandled = false; if (ruleTemplateList == RuleTemplateSet.Identifiers || ruleTemplateList == RuleTemplateSet.Contract || ruleTemplateList == RuleTemplateSet.Body) { IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Types) { TypeName = null; ParameterTable = new SealableList <IParameter>(); IsHandled = true; } Debug.Assert(IsHandled); }
/// <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(IIndexerType node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; IObjectType BaseTypeItem = (IObjectType)node.BaseType; Debug.Assert(BaseTypeItem.ResolvedType.IsAssigned); IClassType BaseType = BaseTypeItem.ResolvedType.Item as IClassType; if (BaseType == null) { AddSourceError(new ErrorClassTypeRequired(node)); Success = false; } ISealableList <IParameter> ParameterTable = new SealableList <IParameter>(); foreach (IEntityDeclaration Item in node.IndexParameterList) { IName ParameterName = (IName)Item.EntityName; string ValidText = ParameterName.ValidText.Item; IScopeAttributeFeature ParameterFeature = Item.ValidEntity.Item; if (Parameter.TableContainsName(ParameterTable, ValidText)) { AddSourceError(new ErrorDuplicateName(ParameterName, ValidText)); Success = false; } else { ParameterTable.Add(new Parameter(ValidText, ParameterFeature)); } } if (Success) { data = new Tuple <IClassType, ISealableList <IParameter> >(BaseType, ParameterTable); } return(Success); }
/// <summary> /// Finds the matching nodes of a <see cref="INewExpression"/>. /// </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 matching feature upon return.</param> public static bool ResolveCompilerReferences(INewExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant, out ICompiledFeature resolvedFinalFeature) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; resolvedFinalFeature = null; IClass EmbeddingClass = node.EmbeddingClass; IQualifiedName Object = (IQualifiedName)node.Object; IList <IIdentifier> ValidPath = Object.ValidPath.Item; IClassType BaseType = EmbeddingClass.ResolvedClassType.Item; if (!Expression.IsLanguageTypeAvailable(LanguageClasses.Boolean.Guid, node, out ITypeName BooleanTypeName, out ICompiledType BooleanType)) { errorList.AddError(new ErrorBooleanTypeMissing(node)); return(false); } 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); } if (FinalFeature == null) { errorList.AddError(new ErrorConstantNewExpression(node)); return(false); } ObjectType.FillResultPath(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, Object.ValidResultTypePath.Item); resolvedResult = new ResultType(BooleanTypeName, BooleanType, string.Empty); resolvedException = new ResultException(); resolvedFinalFeature = FinalFeature; #if COVERAGE Debug.Assert(!node.IsComplex); #endif return(true); }
/// <summary> /// Reset some intermediate results. /// </summary> /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param> public void Reset(IRuleTemplateList ruleTemplateList) { bool IsHandled = false; if (ruleTemplateList == RuleTemplateSet.Identifiers) { IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Types) { ResolvedAgentTypeName = new OnceReference <ITypeName>(); ResolvedAgentType = new OnceReference <ICompiledType>(); ResolvedEffectiveTypeName = new OnceReference <ITypeName>(); ResolvedEffectiveType = new OnceReference <ICompiledType>(); ValidFeatureName = new OnceReference <IFeatureName>(); ResolvedFeature = new OnceReference <ICompiledFeature>(); ResolvedEntityTypeName = new OnceReference <ITypeName>(); ResolvedEntityType = new OnceReference <ICompiledType>(); ParameterTable = new SealableList <IParameter>(); LocalScope = new SealableDictionary <string, IScopeAttributeFeature>(); LocalGetScope = new SealableDictionary <string, IScopeAttributeFeature>(); LocalSetScope = new SealableDictionary <string, IScopeAttributeFeature>(); InnerScopes = new List <IScopeHolder>(); InnerGetScopes = new List <IScopeHolder>(); InnerSetScopes = new List <IScopeHolder>(); FullScope = new SealableDictionary <string, IScopeAttributeFeature>(); FullGetScope = new SealableDictionary <string, IScopeAttributeFeature>(); FullSetScope = new SealableDictionary <string, IScopeAttributeFeature>(); IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Contract) { AdditionalScope = new SealableDictionary <string, IScopeAttributeFeature>(); AdditionalScope.Seal(); IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Body) { IsCallingPrecursor = false; IsHandled = true; } Debug.Assert(IsHandled); }
/// <summary> /// Finds the matching nodes of a <see cref="IAssertionTagExpression"/>. /// </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> public static bool ResolveCompilerReferences(IAssertionTagExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant) { IExpression ResolvedBooleanExpression = node.ResolvedBooleanExpression.Item; resolvedResult = ResolvedBooleanExpression.ResolvedResult.Item; ResultException.Propagate(ResolvedBooleanExpression.ResolvedException, out resolvedException); expressionConstant = NeutralLanguageConstant.NotConstant; constantSourceList = new SealableList <IExpression>() { ResolvedBooleanExpression }; #if COVERAGE Debug.Assert(!node.IsComplex); #endif return(true); }
/// <summary> /// Finds the matching nodes of a <see cref="ICloneOfExpression"/>. /// </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> public static bool ResolveCompilerReferences(ICloneOfExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; IExpression Source = (IExpression)node.Source; IResultType ResolvedSourceResult = Source.ResolvedResult.Item; foreach (IExpressionType Item in ResolvedSourceResult) { if (Item.ValueType is IClassType AsClassType) { IClass BaseClass = AsClassType.BaseClass; if (BaseClass.Cloneable == BaseNode.CloneableStatus.Cloneable) { AsClassType.MarkAsUsedInCloneOf(); } else { errorList.AddError(new ErrorCloningNotAllowed(node, BaseClass.ValidClassName)); return(false); } } else { errorList.AddError(new ErrorClassTypeRequired(node)); return(false); } } resolvedResult = ResolvedSourceResult; ResultException.Propagate(Source.ResolvedException, out resolvedException); #if COVERAGE Debug.Assert(node.IsComplex); #endif return(true); }
/// <summary> /// Reset some intermediate results. /// </summary> /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param> public void Reset(IRuleTemplateList ruleTemplateList) { bool IsHandled = false; if (ruleTemplateList == RuleTemplateSet.Identifiers || ruleTemplateList == RuleTemplateSet.Contract || ruleTemplateList == RuleTemplateSet.Body) { IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Types) { TypeName = null; ParameterTable = new SealableList <IParameter>(); ResultTable = new SealableList <IParameter>(); ConformantResultTable = new SealableList <ICompiledType>(); ResultTypeList = new List <IExpressionType>(); IsHandled = true; } Debug.Assert(IsHandled); }
private static bool ResolveCallProperty(IPrecursorExpression node, IFeatureInstance selectedPrecursor, IPropertyType callType, List <IExpressionType> mergedArgumentList, TypeArgumentStyles argumentStyle, IErrorList errorList, ref ResolvedExpression resolvedExpression, out ISealableList <IParameter> selectedParameterList, out ISealableList <IParameter> selectedResultList, out List <IExpressionType> resolvedArgumentList) { selectedParameterList = null; selectedResultList = null; resolvedArgumentList = null; IList <IArgument> ArgumentList = node.ArgumentList; if (ArgumentList.Count > 0) { errorList.AddError(new ErrorInvalidExpression(node)); return(false); } else { ICompiledFeature OperatorFeature = selectedPrecursor.Feature; IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); IPropertyFeature Property = (IPropertyFeature)OperatorFeature; string PropertyName = ((IFeatureWithName)Property).EntityName.Text; resolvedExpression.ResolvedResult = new ResultType(callType.ResolvedEntityTypeName.Item, callType.ResolvedEntityType.Item, PropertyName); resolvedExpression.ResolvedException = new ResultException(); if (Property.GetterBody.IsAssigned) { IBody GetterBody = (IBody)Property.GetterBody.Item; resolvedExpression.ResolvedException = new ResultException(GetterBody.ExceptionIdentifierList); } selectedParameterList = new SealableList <IParameter>(); selectedResultList = new SealableList <IParameter>(); resolvedArgumentList = new List <IExpressionType>(); return(true); } }
/// <summary> /// Finds the matching nodes of a <see cref="IEqualityExpression"/>. /// </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> public static bool ResolveCompilerReferences(IEqualityExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; IExpression LeftExpression = (IExpression)node.LeftExpression; IExpression RightExpression = (IExpression)node.RightExpression; IClass EmbeddingClass = node.EmbeddingClass; IResultType LeftResult = LeftExpression.ResolvedResult.Item; IResultType RightResult = RightExpression.ResolvedResult.Item; if (LeftResult.Count != RightResult.Count) { errorList.AddError(new ErrorExpressionResultMismatch(node)); return(false); } if (!Expression.IsLanguageTypeAvailable(LanguageClasses.Boolean.Guid, node, out ITypeName ResultTypeName, out ICompiledType ResultType)) { errorList.AddError(new ErrorBooleanTypeMissing(node)); return(false); } if (LeftResult.Count > 1) { int MismatchingResultCount = 0; foreach (IExpressionType LeftItem in LeftResult) { ICompiledType LeftExpressionType = LeftItem.ValueType; bool MatchingNameFound = false; foreach (IExpressionType RightItem in RightResult) { if (LeftItem.Name == RightItem.Name) { MatchingNameFound = true; ICompiledType RightExpressionType = RightItem.ValueType; if (!ObjectType.TypeConformToBase(LeftExpressionType, RightExpressionType, isConversionAllowed: true) && !ObjectType.TypeConformToBase(RightExpressionType, LeftExpressionType, isConversionAllowed: true)) { MismatchingResultCount++; } break; } } if (!MatchingNameFound) { MismatchingResultCount++; } } if (MismatchingResultCount > 0) { errorList.AddError(new ErrorExpressionResultMismatch(node)); return(false); } } resolvedResult = new ResultType(ResultTypeName, ResultType, string.Empty); constantSourceList.Add(LeftExpression); constantSourceList.Add(RightExpression); resolvedException = new ResultException(); ResultException.Merge(resolvedException, LeftExpression.ResolvedException); ResultException.Merge(resolvedException, RightExpression.ResolvedException); #if COVERAGE Debug.Assert(node.IsComplex); #endif return(true); }
/// <summary> /// Finds the matching nodes of a <see cref="IEntityExpression"/>. /// </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> public static bool ResolveCompilerReferences(IEntityExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant, out ICompiledFeature resolvedFinalFeature, out IDiscrete resolvedFinalDiscrete) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; resolvedFinalFeature = null; resolvedFinalDiscrete = null; IQualifiedName Query = (IQualifiedName)node.Query; IClass EmbeddingClass = (Class)node.EmbeddingClass; IClassType BaseType = EmbeddingClass.ResolvedClassType.Item; if (!Expression.IsLanguageTypeAvailable(LanguageClasses.Entity.Guid, node, out ITypeName ResultTypeName, out ICompiledType ResultType)) { errorList.AddError(new ErrorEntityTypeMissing(node)); return(false); } IList <IIdentifier> ValidPath = Query.ValidPath.Item; IIdentifier LastIdentifier = ValidPath[ValidPath.Count - 1]; string ValidText = LastIdentifier.ValidText.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); } Guid EntityGuid; if (FinalFeature is IFeatureWithEntity AsFeatureWithEntity) { ObjectType.FillResultPath(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, Query.ValidResultTypePath.Item); resolvedFinalFeature = FinalFeature; EntityGuid = AsFeatureWithEntity.EntityGuid; expressionConstant = new EntityLanguageConstant(AsFeatureWithEntity); } else { Debug.Assert(FinalDiscrete != null); resolvedFinalDiscrete = FinalDiscrete; EntityGuid = LanguageClasses.NamedFeatureEntity.Guid; expressionConstant = new EntityLanguageConstant(resolvedFinalDiscrete); } ITypeName EntityTypeName = EmbeddingClass.ImportedLanguageTypeTable[EntityGuid].Item1; ICompiledType EntityType = EmbeddingClass.ImportedLanguageTypeTable[EntityGuid].Item2; resolvedResult = new ResultType(EntityTypeName, EntityType, ValidText); resolvedException = new ResultException(); #if COVERAGE Debug.Assert(!node.IsComplex); #endif return(true); }
/// <summary> /// Reset some intermediate results. /// </summary> /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param> public void Reset(IRuleTemplateList ruleTemplateList) { bool IsHandled = false; if (ruleTemplateList == RuleTemplateSet.Identifiers) { IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Types) { LocalGenericTable = new SealableDictionary <string, ICompiledType>(); GenericTable = new SealableDictionary <string, ICompiledType>(); LocalDiscreteTable = new SealableDictionary <IFeatureName, IDiscrete>(); DiscreteTable = new SealableDictionary <IFeatureName, IDiscrete>(); DiscreteWithValueTable = new SealableDictionary <IFeatureName, IExpression>(); LocalTypedefTable = new SealableDictionary <IFeatureName, ITypedefType>(); TypedefTable = new SealableDictionary <IFeatureName, ITypedefType>(); LocalFeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>(); FeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>(); InheritedClassTypeTable = new SealableDictionary <IClassType, IObjectType>(); LocalNamespaceTable = new SealableDictionary <string, ISealableDictionary>(); LocalExportTable = new SealableDictionary <IFeatureName, ISealableDictionary <string, IClass> >(); ExportTable = new SealableDictionary <IFeatureName, ISealableDictionary <string, IClass> >(); ConversionFromTable = new SealableDictionary <IFeatureName, ICreationFeature>(); ConversionToTable = new SealableDictionary <IFeatureName, IFunctionFeature>(); ResolvedClassTypeName = new OnceReference <ITypeName>(); ResolvedClassType = new OnceReference <IClassType>(); GenericInstanceList = new List <IClassType>(); TypeTable = new SealableDictionary <ITypeName, ICompiledType>(); ClassIndexer = new OptionalReference <IIndexerFeature>(); ClassGroupList = new SealableList <IClass>(); ClassGroup = new OnceReference <SingleClassGroup>(); InheritanceTable = new SealableDictionary <ITypeName, ICompiledType>(); ResolvedImportedClassTable = new SealableDictionary <ITypeName, IClassType>(); ResolvedAsCompiledType = new OnceReference <ICompiledType>(); BodyList = new List <IBody>(); CommandOverloadList = new List <ICommandOverload>(); QueryOverloadList = new List <IQueryOverload>(); NodeWithDefaultList = new List <IExpression>(); NodeWithNumberConstantList = new List <IExpression>(); ImportedLanguageTypeTable = new Dictionary <Guid, Tuple <ITypeName, IClassType> >(); NamespaceTable = new SealableDictionary <string, ISealableDictionary>(); LocalScope = new SealableDictionary <string, IScopeAttributeFeature>(); LocalScope.Seal(); InnerScopes = new List <IScopeHolder>(); FullScope = new SealableDictionary <string, IScopeAttributeFeature>(); IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Contract) { AdditionalScope = new SealableDictionary <string, IScopeAttributeFeature>(); AdditionalScope.Seal(); ResolvedBodyTagList = new OnceReference <IList <IBody> >(); ResolvedNodeWithDefaultList = new OnceReference <IList <IExpression> >(); ResolvedNodeWithNumberConstantList = new OnceReference <IList <IExpression> >(); InheritedBodyTagListTable = new SealableDictionary <IClassType, IList <IBody> >(); InitializedObjectList = new List <IInitializedObjectExpression>(); IsHandled = true; } else if (ruleTemplateList == RuleTemplateSet.Body) { ResolvedBodyList = new OnceReference <IList <IBody> >(); AssignedDiscreteTable = new SealableDictionary <IDiscrete, string>(); IsHandled = true; } Debug.Assert(IsHandled); }
/// <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(IQueryOverload node, object data) { IClass EmbeddingClass = node.EmbeddingClass; IFeature EmbeddingFeature = node.EmbeddingFeature; ISealableList <IParameter> ParameterTable = new SealableList <IParameter>(); ISealableList <IParameter> ResultTable = new SealableList <IParameter>(); foreach (IEntityDeclaration Item in node.ParameterList) { IName SourceName = (IName)Item.EntityName; Debug.Assert(SourceName.ValidText.IsAssigned); string ValidName = SourceName.ValidText.Item; ParameterTable.Add(new Parameter(ValidName, Item.ValidEntity.Item)); } // Ensured since the root is valid. Debug.Assert(node.ResultList.Count > 0); foreach (IEntityDeclaration Item in node.ResultList) { IName SourceName = (IName)Item.EntityName; Debug.Assert(SourceName.ValidText.IsAssigned); string ValidName = SourceName.ValidText.Item; ResultTable.Add(new Parameter(ValidName, Item.ValidEntity.Item)); } node.ParameterTable.AddRange(ParameterTable); node.ParameterTable.Seal(); node.ResultTable.AddRange(ResultTable); node.ResultTable.Seal(); foreach (IParameter Parameter in ResultTable) { Debug.Assert(Parameter.ResolvedParameter.ResolvedEffectiveType.IsAssigned); node.ConformantResultTable.Add(Parameter.ResolvedParameter.ResolvedEffectiveType.Item); } Debug.Assert(ResultTable.Count > 0); ITypeName BestResultTypeName = null; ICompiledType BestResultType = null; foreach (IParameter Item in ResultTable) { Debug.Assert(Item.ResolvedParameter.ResolvedEffectiveTypeName.IsAssigned); Debug.Assert(Item.ResolvedParameter.ResolvedEffectiveType.IsAssigned); if (BestResultType == null || Item.Name == nameof(BaseNode.Keyword.Result)) { BestResultTypeName = Item.ResolvedParameter.ResolvedEffectiveTypeName.Item; BestResultType = Item.ResolvedParameter.ResolvedEffectiveType.Item; } } node.ResolvedResultTypeName.Item = BestResultTypeName; node.ResolvedResultType.Item = BestResultType; IBody QueryBody = (IBody)node.QueryBody; IQueryOverloadType AssociatedType = new QueryOverloadType(node.ParameterList, node.ParameterEnd, node.ResultList, QueryBody.RequireList, QueryBody.EnsureList, QueryBody.ExceptionIdentifierList); AssociatedType.ParameterTable.AddRange(ParameterTable); AssociatedType.ParameterTable.Seal(); AssociatedType.ResultTable.AddRange(ResultTable); AssociatedType.ResultTable.Seal(); foreach (IParameter Parameter in ResultTable) { Debug.Assert(Parameter.ResolvedParameter.ResolvedEffectiveType.IsAssigned); AssociatedType.ConformantResultTable.Add(Parameter.ResolvedParameter.ResolvedEffectiveType.Item); } node.ResolvedAssociatedType.Item = AssociatedType; Debug.Assert(!node.ConformantResultTable.IsSealed); Debug.Assert(!AssociatedType.ConformantResultTable.IsSealed); }
/// <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="IBinaryConditionalExpression"/>. /// </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> public static bool ResolveCompilerReferences(IBinaryConditionalExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; IExpression LeftExpression = (IExpression)node.LeftExpression; BaseNode.ConditionalTypes Conditional = node.Conditional; IExpression RightExpression = (IExpression)node.RightExpression; IClass EmbeddingClass = node.EmbeddingClass; bool IsLeftClassType = Expression.GetClassTypeOfExpression(LeftExpression, errorList, out IClassType LeftExpressionClassType); bool IsRightClassType = Expression.GetClassTypeOfExpression(RightExpression, errorList, out IClassType RightExpressionClassType); if (!IsLeftClassType || !IsRightClassType) { return(false); } Expression.IsLanguageTypeAvailable(LanguageClasses.Boolean.Guid, node, out ITypeName BooleanTypeName, out ICompiledType BooleanType); Expression.IsLanguageTypeAvailable(LanguageClasses.Event.Guid, node, out ITypeName EventTypeName, out ICompiledType EventType); Debug.Assert(LeftExpressionClassType == BooleanType || LeftExpressionClassType == EventType); Debug.Assert(RightExpressionClassType == BooleanType || RightExpressionClassType == EventType); if (LeftExpressionClassType != RightExpressionClassType) { errorList.AddError(new ErrorInvalidExpression(LeftExpression)); return(false); } bool IsEventExpression = LeftExpressionClassType != BooleanType; if (IsEventExpression) { if (!((node.ParentSource is IBinaryConditionalExpression) || (node.ParentSource is IConditional) || (node.ParentSource is ICheckInstruction))) { errorList.AddError(new ErrorInvalidExpression(node)); return(false); } resolvedResult = new ResultType(EventTypeName, EventType, string.Empty); } else { resolvedResult = new ResultType(BooleanTypeName, BooleanType, string.Empty); } constantSourceList.Add(LeftExpression); constantSourceList.Add(RightExpression); resolvedException = new ResultException(); ResultException.Merge(resolvedException, LeftExpression.ResolvedException); ResultException.Merge(resolvedException, RightExpression.ResolvedException); #if COVERAGE Debug.Assert(node.IsComplex); #endif return(true); }