/// <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); } }
private static void BuildResultListNoResult(ICSharpUsingCollection usingCollection, IList <ICSharpParameter> resultList, ref string parameterListText, ref string parameterNameListText, out string resultTypeText) { resultTypeText = "void"; foreach (ICSharpParameter Result in resultList) { ICSharpScopeAttributeFeature ResultAttribute = Result.Feature; ICSharpType ParameterType = ResultAttribute.Type; CSharpTypeFormats ParameterFormat = ParameterType.HasInterfaceText ? CSharpTypeFormats.AsInterface : CSharpTypeFormats.Normal; string TypeString = ParameterType.Type2CSharpString(usingCollection, ParameterFormat, CSharpNamespaceFormats.None); string AttributeString = CSharpNames.ToCSharpIdentifier(Result.Name); if (parameterListText.Length > 0) { parameterListText += ", "; } if (parameterNameListText.Length > 0) { parameterNameListText += ", "; } parameterListText += $"out {TypeString} {AttributeString}"; parameterNameListText += $"out {AttributeString}"; } }
private static void CSharpAssignmentArgumentList(ICSharpWriter writer, ICSharpExpressionContext expressionContext, ICSharpFeatureCall featureCall, int skippedIndex, bool isAgentCall, out string callText, out IList <string> outgoingResultList) { IList <ICSharpParameter> ParameterList = featureCall.ParameterList; IList <ICSharpParameter> ResultList = featureCall.ResultList; IList <ICSharpArgument> ArgumentList = featureCall.ArgumentList; int i; callText = string.Empty; for (i = 0; i < ParameterList.Count; i++) { if (callText.Length > 0) { callText += ", "; } ICSharpParameter Parameter = ParameterList[i]; string ParameterName = Parameter.Name; ICSharpExpression SourceExpression = null; foreach (ICSharpAssignmentArgument Argument in ArgumentList) { foreach (string Name in Argument.ParameterNameList) { if (ParameterName == Name) { SourceExpression = Argument.SourceExpression; break; } } } if (SourceExpression != null) { ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext(); SourceExpression.WriteCSharp(writer, SourceExpressionContext, -1); callText += SourceExpressionContext.ResultListAsArgument; } else { ICSharpScopeAttributeFeature Feature = Parameter.Feature; ICSharpExpression DefaultValue = Feature.DefaultValue; Debug.Assert(DefaultValue != null); ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext(); DefaultValue.WriteCSharp(writer, SourceExpressionContext, -1); callText += SourceExpressionContext.ResultListAsArgument; } } CSharpAssignmentResultList(writer, expressionContext, featureCall, skippedIndex, isAgentCall, ref callText, out outgoingResultList); }
private static void CSharpPositionalArgumentList(ICSharpWriter writer, ICSharpExpressionContext expressionContext, ICSharpFeatureCall featureCall, int skippedIndex, bool isAgentCall, out string callText, out IList <string> outgoingResultList) { IList <ICSharpParameter> ParameterList = featureCall.ParameterList; IList <ICSharpParameter> ResultList = featureCall.ResultList; IList <ICSharpArgument> ArgumentList = featureCall.ArgumentList; int i, j; callText = string.Empty; i = 0; j = 0; for (; i < ArgumentList.Count; i++) { if (callText.Length > 0) { callText += ", "; } ICSharpPositionalArgument Argument = ArgumentList[i] as ICSharpPositionalArgument; Debug.Assert(Argument != null); ICSharpExpression SourceExpression = Argument.SourceExpression; ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext(); SourceExpression.WriteCSharp(writer, SourceExpressionContext, -1); callText += SourceExpressionContext.ResultListAsArgument; j += SourceExpressionContext.CompleteDestinationNameList.Count; if (SourceExpressionContext.ReturnValue != null) { j++; } } i = j; for (; i < ParameterList.Count; i++) { if (callText.Length > 0) { callText += ", "; } ICSharpParameter Parameter = ParameterList[i]; ICSharpScopeAttributeFeature Feature = Parameter.Feature; ICSharpExpression DefaultValue = Feature.DefaultValue; Debug.Assert(DefaultValue != null); ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext(); DefaultValue.WriteCSharp(writer, SourceExpressionContext, -1); callText += SourceExpressionContext.ResultListAsArgument; } CSharpAssignmentResultList(writer, expressionContext, featureCall, skippedIndex, isAgentCall, ref callText, out outgoingResultList); }
private static void BuildResultListSingle(ICSharpUsingCollection usingCollection, IList <ICSharpParameter> resultList, out string resultTypeText) { Debug.Assert(resultList.Count == 1); ICSharpParameter Result = resultList[0]; ICSharpScopeAttributeFeature ResultAttribute = Result.Feature; /*if (FeatureTextType == FeatureTextTypes.Interface) * ResultType = CSharpTypes.Type2CSharpString(ResultAttribute.ResolvedFeatureType.Item, Context, CSharpTypeFormats.AsInterface); * else * ResultType = CSharpTypes.Type2CSharpString(ResultAttribute.ResolvedFeatureType.Item, Context, CSharpTypeFormats.None);*/ resultTypeText = ResultAttribute.Type.Type2CSharpString(usingCollection, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpEffectiveBody"/> class. /// </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> protected CSharpEffectiveBody(ICSharpContext context, ICSharpFeature parentFeature, IEffectiveBody source) : base(context, parentFeature, source) { foreach (IInstruction Instruction in source.BodyInstructionList) { ICSharpInstruction NewInstruction = CSharpInstruction.Create(context, parentFeature, Instruction); BodyInstructionList.Add(NewInstruction); } ICSharpClass Owner = parentFeature.Owner; foreach (IEntityDeclaration Item in source.EntityDeclarationList) { ICSharpScopeAttributeFeature NewDeclaration = CSharpScopeAttributeFeature.Create(context, Owner, Item.ValidEntity.Item); EntityDeclarationList.Add(NewDeclaration); } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpScope"/> 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 CSharpScope(ICSharpContext context, ICSharpFeature parentFeature, IScope source) : base(source) { ParentFeature = parentFeature; foreach (IEntityDeclaration Declaration in source.EntityDeclarationList) { ICSharpScopeAttributeFeature NewDeclaration = CSharpScopeAttributeFeature.Create(context, parentFeature.Owner, Declaration.ValidEntity.Item); EntityDeclarationList.Add(NewDeclaration); } foreach (IInstruction Instruction in source.InstructionList) { ICSharpInstruction NewInstruction = CSharpInstruction.Create(context, parentFeature, Instruction); InstructionList.Add(NewInstruction); } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpForLoopInstruction"/> 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 CSharpForLoopInstruction(ICSharpContext context, ICSharpFeature parentFeature, IForLoopInstruction source) : base(context, parentFeature, source) { foreach (IEntityDeclaration Declaration in source.EntityDeclarationList) { ICSharpScopeAttributeFeature NewDeclaration = CSharpScopeAttributeFeature.Create(context, parentFeature.Owner, Declaration.ValidEntity.Item); EntityDeclarationList.Add(NewDeclaration); } foreach (IInstruction Instruction in source.InitInstructionList) { ICSharpInstruction NewInstruction = Create(context, parentFeature, Instruction); InitInstructionList.Add(NewInstruction); } WhileCondition = CSharpExpression.Create(context, (IExpression)source.WhileCondition); foreach (IInstruction Instruction in source.LoopInstructionList) { ICSharpInstruction NewInstruction = Create(context, parentFeature, Instruction); LoopInstructionList.Add(NewInstruction); } foreach (IInstruction Instruction in source.IterationInstructionList) { ICSharpInstruction NewInstruction = Create(context, parentFeature, Instruction); IterationInstructionList.Add(NewInstruction); } if (source.Variant.IsAssigned) { VariantExpression = CSharpExpression.Create(context, (IExpression)source.Variant.Item); } foreach (IAssertion Item in Source.InvariantList) { ICSharpAssertion NewAssertion = CSharpAssertion.Create(context, Item); InvariantList.Add(NewAssertion); } }
private static void BuildResultListWithResult(ICSharpUsingCollection usingCollection, IList <ICSharpParameter> resultList, int resultIndex, ref string parameterListText, ref string parameterNameListText, out string resultTypeText) { resultTypeText = null; for (int i = 0; i < resultList.Count; i++) { ICSharpParameter Result = resultList[i]; ICSharpScopeAttributeFeature ResultAttribute = Result.Feature; ICSharpType ParameterType = ResultAttribute.Type; CSharpTypeFormats ParameterFormat = ParameterType.HasInterfaceText ? CSharpTypeFormats.AsInterface : CSharpTypeFormats.Normal; string TypeString = ParameterType.Type2CSharpString(usingCollection, ParameterFormat, CSharpNamespaceFormats.None); string AttributeString = CSharpNames.ToCSharpIdentifier(Result.Name); if (i == resultIndex) { resultTypeText = TypeString; } else { if (parameterListText.Length > 0) { parameterListText += ", "; } if (parameterNameListText.Length > 0) { parameterNameListText += ", "; } parameterListText += $"out {TypeString} {AttributeString}"; parameterNameListText += $"out {AttributeString}"; } } Debug.Assert(resultTypeText != null); }
/// <summary> /// Writes down the C# instruction. /// </summary> /// <param name="writer">The stream on which to write.</param> public override void WriteCSharp(ICSharpWriter writer) { Debug.Assert(WriteDown); ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext(); OverList.WriteCSharp(writer, SourceExpressionContext, -1); string OverListString = SourceExpressionContext.ReturnValue; ICSharpScopeAttributeFeature Indexer = IndexerList[0]; string IndexerNameString = Indexer.Name; string TypeString = Indexer.Type.Type2CSharpString(writer, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None); //TODO: support multiple indexers and IterationType if (ExitEntityName != null) { string ExitEntityNameString = CSharpNames.ToCSharpIdentifier(ExitEntityName); writer.WriteIndentedLine($"{ExitEntityNameString} = false;"); writer.WriteIndentedLine($"foreach ({TypeString} {IndexerNameString} in {OverListString})"); writer.WriteIndentedLine("{"); LoopInstructions.WriteCSharp(writer, CSharpCurlyBracketsInsertions.AlreadyInserted, false); WriteCSharpInvariant(writer); writer.WriteEmptyLine(); writer.IncreaseIndent(); writer.WriteIndentedLine($"if ({ExitEntityNameString})"); writer.IncreaseIndent(); writer.WriteIndentedLine("break;"); writer.DecreaseIndent(); writer.DecreaseIndent(); writer.WriteIndentedLine("}"); } else if (InvariantList.Count > 0) { writer.WriteIndentedLine($"foreach ({TypeString} {IndexerNameString} in {OverListString})"); writer.WriteIndentedLine("{"); LoopInstructions.WriteCSharp(writer, CSharpCurlyBracketsInsertions.AlreadyInserted, false); writer.IncreaseIndent(); WriteCSharpInvariant(writer); writer.DecreaseIndent(); writer.WriteIndentedLine("}"); } else { writer.WriteIndentedLine($"foreach ({TypeString} {IndexerNameString} in {OverListString})"); LoopInstructions.WriteCSharp(writer, CSharpCurlyBracketsInsertions.Indifferent, false); } //TODO: InvariantBlocks //TODO: Variant }