/// <summary> /// Creates a new C# body. /// </summary> /// <param name="context">The creation context.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="source">The Easly body from which the C# body is created.</param> public static ICSharpBody Create(ICSharpContext context, ICSharpFeature parentFeature, ICompiledBody source) { ICSharpBody Result = null; switch (source) { case IDeferredBody AsDeferredBody: Result = CSharpDeferredBody.Create(context, parentFeature, AsDeferredBody); break; case IEffectiveBody AsEffectiveBody: Result = CSharpEffectiveBody.Create(context, parentFeature, AsEffectiveBody); break; case IExternBody AsExternBody: Result = CSharpExternBody.Create(context, parentFeature, AsExternBody); break; case IPrecursorBody AsPrecursorBody: Result = CSharpPrecursorBody.Create(context, parentFeature, AsPrecursorBody); break; } Debug.Assert(Result != null); return(Result); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpEntityExpression"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly expression from which the C# expression is created.</param> protected CSharpEntityExpression(ICSharpContext context, IEntityExpression source) : base(context, source) { if (Source.ResolvedFinalFeature.IsAssigned) { ICompiledFeature ResolvedFeature = Source.ResolvedFinalFeature.Item; if (ResolvedFeature is IScopeAttributeFeature AsScopeAttributeFeature) { ICSharpClass Owner = context.GetClass(source.EmbeddingClass); Feature = CSharpScopeAttributeFeature.Create(context, Owner, AsScopeAttributeFeature); } else { Feature = context.GetFeature(Source.ResolvedFinalFeature.Item); } } if (Source.ResolvedFinalDiscrete.IsAssigned) { ICSharpClass Class = context.GetClass(Source.ResolvedFinalDiscrete.Item.EmbeddingClass); foreach (ICSharpDiscrete Item in Class.DiscreteList) { if (Item.Source == Source.ResolvedFinalDiscrete.Item) { Debug.Assert(Discrete == null); Discrete = Item; } } } Debug.Assert((Feature != null && Discrete == null) || (Feature == null && Discrete != null)); Query = CSharpQualifiedName.Create(context, (IQualifiedName)Source.Query, Feature, Discrete, false); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpInstruction"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="source">The Easly instruction from which the C# instruction is created.</param> protected CSharpInstruction(ICSharpContext context, ICSharpFeature parentFeature, IInstruction source) { Debug.Assert(source != null); ParentFeature = parentFeature; Source = source; }
/// <summary> /// Initializes a new instance of the <see cref="CSharpOverLoopInstruction"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="source">The Easly instruction from which the C# instruction is created.</param> protected CSharpOverLoopInstruction(ICSharpContext context, ICSharpFeature parentFeature, IOverLoopInstruction source) : base(context, parentFeature, source) { OverList = CSharpExpression.Create(context, (IExpression)source.OverList); LoopInstructions = CSharpScope.Create(context, parentFeature, (IScope)source.LoopInstructions); foreach (IName Name in source.IndexerList) { string IndexerName = Name.ValidText.Item; IScopeAttributeFeature IndexerFeature = Source.InnerLoopScope[IndexerName]; ICSharpScopeAttributeFeature NewIndexer = CSharpScopeAttributeFeature.Create(context, ParentFeature.Owner, IndexerFeature); IndexerList.Add(NewIndexer); } if (source.ExitEntityName.IsAssigned) { ExitEntityName = ((IIdentifier)source.ExitEntityName.Item).ValidText.Item; } foreach (IAssertion Item in Source.InvariantList) { ICSharpAssertion NewAssertion = CSharpAssertion.Create(context, Item); InvariantList.Add(NewAssertion); } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpIndexAssignmentInstruction"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="source">The Easly instruction from which the C# instruction is created.</param> protected CSharpIndexAssignmentInstruction(ICSharpContext context, ICSharpFeature parentFeature, IIndexAssignmentInstruction source) : base(context, parentFeature, source) { Destination = CSharpQualifiedName.Create(context, (IQualifiedName)source.Destination, parentFeature, null, false); FeatureCall = new CSharpFeatureCall(context, source.FeatureCall.Item); SourceExpression = CSharpExpression.Create(context, (IExpression)source.Source); }
/// <summary> /// Initializes the feature precursor hierarchy. /// </summary> /// <param name="context">The initialization context.</param> public override void InitHierarchy(ICSharpContext context) { if (Instance.OriginalPrecursor.IsAssigned) { IPrecursorInstance Item = Instance.OriginalPrecursor.Item; ICompiledFeature PrecursorFeature = Item.Precursor.Feature; OriginalPrecursor = context.GetFeature(PrecursorFeature) as ICSharpProcedureFeature; Debug.Assert(OriginalPrecursor != null); IList <ICSharpOverload> PrecursorOverloadList = OriginalPrecursor.OverloadList; foreach (ICSharpCommandOverload Overload in OverloadList) { ICommandOverloadType ResolvedAssociatedType = Overload.Source.ResolvedAssociatedType.Item; ICSharpCommandOverload ParentPrecursorOverload = null; foreach (ICSharpCommandOverload PrecursorOverload in PrecursorOverloadList) { ICommandOverloadType PrecursorResolvedAssociatedType = PrecursorOverload.Source.ResolvedAssociatedType.Item; if (ObjectType.CommandOverloadConformToBase(ResolvedAssociatedType, PrecursorResolvedAssociatedType, ErrorList.Ignored, ErrorList.NoLocation)) { Debug.Assert(ParentPrecursorOverload == null); ParentPrecursorOverload = PrecursorOverload; } } Debug.Assert(ParentPrecursorOverload != null); Overload.SetPrecursor(ParentPrecursorOverload); } } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpUnaryOperatorExpression"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly expression from which the C# expression is created.</param> protected CSharpUnaryOperatorExpression(ICSharpContext context, IUnaryOperatorExpression source) : base(context, source) { RightExpression = Create(context, (IExpression)source.RightExpression); Operator = context.GetFeature(source.SelectedFeature.Item) as ICSharpFunctionFeature; Debug.Assert(Operator != null); FeatureCall = new CSharpFeatureCall(context, new FeatureCall()); IResultType ResolvedRightResult = RightExpression.Source.ResolvedResult.Item; IExpressionType PreferredRightResult = ResolvedRightResult.Preferred; Debug.Assert(PreferredRightResult != null); if (PreferredRightResult.ValueType is IClassType AsClassType) { if (AsClassType.BaseClass.ClassGuid == LanguageClasses.Number.Guid) { IsCallingNumberFeature = true; } } if (IsCallingNumberFeature) { Debug.Assert(ResolvedRightResult.Count == 1); } Debug.Assert(Source.SelectedOverload.IsAssigned); IQueryOverload Overload = Source.SelectedOverload.Item; IQueryOverloadType ResolvedAssociatedType = Overload.ResolvedAssociatedType.Item; SelectedOverloadType = CSharpQueryOverloadType.Create(context, ResolvedAssociatedType, Operator.Owner); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpFeatureCall"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">Details of the feature call.</param> public CSharpFeatureCall(ICSharpContext context, IFeatureCall source) { foreach (IParameter Item in source.ParameterList) { ICSharpClass Owner = context.GetClass(Item.ResolvedParameter.Location.EmbeddingClass); ICSharpParameter NewParameter = CSharpParameter.Create(context, Item, Owner); ParameterList.Add(NewParameter); } foreach (IParameter Item in source.ResultList) { ICSharpClass Owner = context.GetClass(Item.ResolvedParameter.Location.EmbeddingClass); ICSharpParameter NewParameter = CSharpParameter.Create(context, Item, Owner); ResultList.Add(NewParameter); } foreach (IArgument Item in source.ArgumentList) { ICSharpArgument NewArgument = CSharpArgument.Create(context, Item); ArgumentList.Add(NewArgument); } Debug.Assert(ParameterList.Count >= ArgumentList.Count); Count = ParameterList.Count; ArgumentStyle = source.TypeArgumentStyle; }
/// <summary> /// Initializes a new instance of the <see cref="CSharpExpression"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly expression from which the C# expression is created.</param> protected CSharpExpression(ICSharpContext context, IExpression source) { Debug.Assert(source != null); Source = source; NumberType = CSharpNumberTypes.NotApplicable; }
/// <summary> /// Initializes a new instance of the <see cref="CSharpAttachmentInstruction"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="source">The Easly instruction from which the C# instruction is created.</param> protected CSharpAttachmentInstruction(ICSharpContext context, ICSharpFeature parentFeature, IAttachmentInstruction source) : base(context, parentFeature, source) { SourceExpression = CSharpExpression.Create(context, (IExpression)source.Source); IResultType ResolvedResult = SourceExpression.Source.ResolvedResult.Item; for (int i = 0; i < source.EntityNameList.Count; i++) { IName EntityName = source.EntityNameList[i]; string ValidName = EntityName.ValidText.Item; EntityNameList.Add(new CSharpVariableContext(ValidName)); } foreach (IAttachment Attachment in source.AttachmentList) { ICSharpAttachment NewAttachment = CSharpAttachment.Create(context, this, Attachment); AttachmentList.Add(NewAttachment); } if (source.ElseInstructions.IsAssigned) { ElseInstructions = CSharpScope.Create(context, parentFeature, (IScope)source.ElseInstructions.Item); } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpQualifiedName"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly node from which the C# node is created.</param> /// <param name="feature">The feature at the end of the path. Can be null.</param> /// <param name="discrete">The discrete at the end of the path. Can be null.</param> /// <param name="inheritBySideAttribute">Inherit the side-by-side attribute.</param> protected CSharpQualifiedName(ICSharpContext context, IQualifiedName source, ICSharpFeature feature, ICSharpDiscrete discrete, bool inheritBySideAttribute) : base(source) { Debug.Assert((feature != null && discrete == null) || (feature == null && discrete != null)); Feature = feature; Discrete = discrete; InheritBySideAttribute = inheritBySideAttribute; IsAttributeWithContract = feature is ICSharpAttributeFeature AsAttributeFeature && AsAttributeFeature.Source.EnsureList.Count > 0; foreach (IExpressionType Item in source.ValidResultTypePath.Item) { ICSharpClass ItemClass; if (Item.ValueType is IClassType AsClassType) { ItemClass = context.GetClass(AsClassType.BaseClass); } else { ItemClass = null; } ClassPath.Add(ItemClass); } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpPrecursorIndexExpression"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly expression from which the C# expression is created.</param> protected CSharpPrecursorIndexExpression(ICSharpContext context, IPrecursorIndexExpression source) : base(context, source) { ParentFeature = context.GetFeature((ICompiledFeature)source.EmbeddingFeature) as ICSharpIndexerFeature; Debug.Assert(ParentFeature != null); FeatureCall = new CSharpFeatureCall(context, source.FeatureCall.Item); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpConditional"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="source">The Easly node from which the C# node is created.</param> protected CSharpConditional(ICSharpContext context, ICSharpFeature parentFeature, IConditional source) : base(source) { ParentFeature = parentFeature; BooleanExpression = CSharpExpression.Create(context, (IExpression)source.BooleanExpression); Instructions = CSharpScope.Create(context, parentFeature, (IScope)source.Instructions); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpPropertyType"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly type from which the C# type is created.</param> protected CSharpPropertyType(ICSharpContext context, IPropertyType source) : base(context, source) { BaseType = Create(context, source.ResolvedBaseType.Item) as ICSharpTypeWithFeature; Debug.Assert(BaseType != null); EntityType = Create(context, source.ResolvedEntityType.Item); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpType"/> 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 CSharpType(ICSharpContext context, ICompiledType source, ICSharpTypedef originatingTypedef) { Debug.Assert(source != null); Debug.Assert(originatingTypedef != null); Source = source; OriginatingTypedef = originatingTypedef; }
/// <summary> /// Initializes the feature overloads and bodies. /// </summary> /// <param name="context">The initialization context.</param> public override void InitOverloadsAndBodies(ICSharpContext context) { foreach (ICommandOverload Overload in Source.OverloadList) { ICSharpCommandOverload NewOverload = CSharpCommandOverload.Create(context, Overload, this, Owner); OverloadList.Add(NewOverload); } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpCreateInstruction"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="source">The Easly instruction from which the C# instruction is created.</param> protected CSharpCreateInstruction(ICSharpContext context, ICSharpFeature parentFeature, ICreateInstruction source) : base(context, parentFeature, source) { EntityType = CSharpType.Create(context, source.ResolvedEntityType.Item); CreatedObjectName = ((IIdentifier)source.EntityIdentifier).ValidText.Item; CreationRoutineName = ((IIdentifier)source.CreationRoutineIdentifier).ValidText.Item; FeatureCall = new CSharpFeatureCall(context, source.FeatureCall.Item); }
/// <summary> /// Initializes the feature overloads and bodies. /// </summary> /// <param name="context">The initialization context.</param> public override void InitOverloadsAndBodies(ICSharpContext context) { Type = CSharpType.Create(context, Source.ResolvedEffectiveType.Item); if (Source.DefaultValue.IsAssigned) { DefaultValue = CSharpExpression.Create(context, Source.DefaultValue.Item); } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpCommandOverloadType"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly node from which the C# node is created.</param> /// <param name="owner">The class where the overload is declared.</param> protected CSharpCommandOverloadType(ICSharpContext context, ICommandOverloadType source, ICSharpClass owner) : base(source) { foreach (IParameter Parameter in source.ParameterTable) { ICSharpParameter NewParameter = CSharpParameter.Create(context, Parameter, owner); ParameterList.Add(NewParameter); } }
/// <summary> /// Initializes the feature overloads and bodies. /// </summary> /// <param name="context">The initialization context.</param> public override void InitOverloadsAndBodies(ICSharpContext context) { Type = CSharpType.Create(context, Source.ResolvedEntityType.Item); foreach (IAssertion Assertion in Source.EnsureList) { ICSharpAssertion NewAssertion = CSharpAssertion.Create(context, Assertion); EnsureList.Add(NewAssertion); } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpAssertion"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly node from which the C# node is created.</param> protected CSharpAssertion(ICSharpContext context, IAssertion source) : base(source) { if (source.Tag.IsAssigned) { Tag = ((IName)source.Tag.Item).ValidText.Item; } BooleanExpression = CSharpExpression.Create(context, (IExpression)source.BooleanExpression); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpDiscrete"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly node from which the C# node is created.</param> protected CSharpDiscrete(ICSharpContext context, IDiscrete source) : base(source) { Name = source.ValidDiscreteName.Item.Name; if (source.NumericValue.IsAssigned) { ExplicitValue = CSharpExpression.Create(context, (IExpression)source.NumericValue.Item); } }
/// <summary> /// Initializes the feature precursor hierarchy. /// </summary> /// <param name="context">The initialization context.</param> public override void InitHierarchy(ICSharpContext context) { if (Instance.OriginalPrecursor.IsAssigned) { IPrecursorInstance Item = Instance.OriginalPrecursor.Item; ICompiledFeature PrecursorFeature = Item.Precursor.Feature; OriginalPrecursor = context.GetFeature(PrecursorFeature) as ICSharpPropertyFeature; Debug.Assert(OriginalPrecursor != null); } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpManifestNumberExpression"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly expression from which the C# expression is created.</param> protected CSharpManifestNumberExpression(ICSharpContext context, IManifestNumberExpression source) : base(context, source) { FormattedNumber FormattedNumber = FormattedNumber.Parse(Source.ValidText.Item); Debug.Assert(FormattedNumber.IsValid); NumberType = FormattedNumber.Value.IsInteger ? CSharpNumberTypes.Integer : CSharpNumberTypes.Real; Debug.Assert(NumberType != CSharpNumberTypes.NotApplicable && NumberType != CSharpNumberTypes.Unknown); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpInitializedObjectExpression"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly expression from which the C# expression is created.</param> protected CSharpInitializedObjectExpression(ICSharpContext context, IInitializedObjectExpression source) : base(context, source) { Class = context.GetClass(source.ResolvedClassType.Item.BaseClass); foreach (IAssignmentArgument Argument in source.AssignmentList) { ICSharpAssignmentArgument NewAssignment = CSharpAssignmentArgument.Create(context, Argument); AssignmentList.Add(NewAssignment); } }
/// <summary> /// Initializes the C# generic. /// </summary> /// <param name="context">The creation context.</param> public void Init(ICSharpContext context) { foreach (IConstraint Constraint in Source.ConstraintList) { ICSharpConstraint NewConstraint = CSharpConstraint.Create(context, Constraint); ConstraintList.Add(NewConstraint); } // Create the type after constraints have been listed. Type = CSharpFormalGenericType.Create(context, Source.ResolvedGenericType.Item); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpAssignmentArgument"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly argument from which the C# argument is created.</param> protected CSharpAssignmentArgument(ICSharpContext context, IAssignmentArgument source) : base(context, source) { IExpression ArgumentSource = (IExpression)source.Source; SourceExpression = CSharpExpression.Create(context, ArgumentSource); foreach (IIdentifier Item in source.ParameterList) { ParameterNameList.Add(Item.ValidText.Item); } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpWith"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="source">The Easly node from which the C# node is created.</param> protected CSharpWith(ICSharpContext context, ICSharpFeature parentFeature, IWith source) : base(source) { ParentFeature = parentFeature; foreach (IRange Range in source.RangeList) { AddValueToList(Range.ResolvedRange.Item); } Instructions = CSharpScope.Create(context, parentFeature, (IScope)source.Instructions); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpCommandOverload"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly node from which the C# node is created.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="owner">The class where the overload is declared.</param> protected CSharpCommandOverload(ICSharpContext context, ICommandOverload source, ICSharpFeature parentFeature, ICSharpClass owner) : base(source) { ParentFeature = parentFeature; foreach (IParameter Parameter in source.ParameterTable) { ICSharpParameter NewParameter = CSharpParameter.Create(context, Parameter, owner); ParameterList.Add(NewParameter); } Body = CSharpBody.Create(context, parentFeature, source.ResolvedBody.Item); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpContinuation"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="source">The Easly node from which the C# node is created.</param> protected CSharpContinuation(ICSharpContext context, ICSharpFeature parentFeature, IContinuation source) : base(source) { ParentFeature = parentFeature; Instructions = CSharpScope.Create(context, parentFeature, (IScope)source.Instructions); foreach (IInstruction Instruction in source.CleanupList) { ICSharpInstruction NewInstruction = CSharpInstruction.Create(context, parentFeature, Instruction); CleanupList.Add(NewInstruction); } }