/// <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> /// 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); string CoexistingPrecursorName = string.Empty; string CoexistingPrecursorRootName = ParentFeature.CoexistingPrecursorName; if (!string.IsNullOrEmpty(CoexistingPrecursorRootName)) { CoexistingPrecursorName = CSharpNames.ToCSharpIdentifier(CoexistingPrecursorRootName + " " + "Base"); } ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext(); string ArgumentListString = CSharpArgument.CSharpArgumentList(writer, ExpressionContext, FeatureCall); if (CoexistingPrecursorName.Length > 0) { writer.WriteIndentedLine($"{CoexistingPrecursorName}({ArgumentListString});"); } else { string ProcedureName = CSharpNames.ToCSharpIdentifier(ParentFeature.Name); writer.WriteIndentedLine($"base.{ProcedureName}({ArgumentListString});"); } }
private void WriteCSharpAgentCall(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex) { CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, skippedIndex, true, out string ArgumentListText, out IList <string> OutgoingResultList); string QueryText = Query.CSharpText(writer, 0); IIdentifier AgentIdentifier = (IIdentifier)Source.Query.Path[Source.Query.Path.Count - 1]; string AgentIdentifierText = CSharpNames.ToCSharpIdentifier(AgentIdentifier.ValidText.Item); if (Source.Query.Path.Count > 1) { QueryText = Query.CSharpText(writer, 1); } else { QueryText = "this"; } if (FeatureCall.ArgumentList.Count > 0) { expressionContext.SetSingleReturnValue($"{AgentIdentifierText}({QueryText}, {ArgumentListText})"); } else { expressionContext.SetSingleReturnValue($"{AgentIdentifierText}({QueryText})"); } }
private void WriteCSharpImplementationEffective(ICSharpWriter writer, ICSharpEffectiveBody effectiveBody, bool isOverride, string nameString, CSharpExports exportStatus, bool isConstructor, ref bool isFirstFeature, ref bool isMultiline) { CSharpArgument.BuildParameterList(writer, ParameterList, out string ParameterEntityList, out string ParameterNameList); CSharpAssertion.WriteContract(writer, effectiveBody.RequireList, effectiveBody.EnsureList, CSharpContractLocations.Other, true, ref isFirstFeature, ref isMultiline); bool SkipFirstInstruction = false; if (isConstructor) { WriteCSharpImplementationConstructor(writer, isOverride, nameString, exportStatus, ref isFirstFeature, ref isMultiline, ref SkipFirstInstruction); } else { string ExportStatusText = CSharpNames.ComposedExportStatus(isOverride, false, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} void {nameString}({ParameterEntityList})"); } ICSharpEffectiveBody AsEffectiveBody = Body as ICSharpEffectiveBody; AsEffectiveBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets, string.Empty, SkipFirstInstruction, new List <string>()); isMultiline = true; }
/// <summary> /// Gets the source code corresponding to the expression. /// </summary> /// <param name="writer">The stream on which to write.</param> /// <param name="expressionContext">The context.</param> /// <param name="skippedIndex">Index of a destination to skip.</param> public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex) { Debug.Assert(WriteDown); CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, skippedIndex, false, out string ArgumentListText, out IList <string> OutgoingResultList); expressionContext.SetSingleReturnValue($"base[{ArgumentListText}]"); }
private void WriteCSharpInterface(ICSharpWriter writer, bool isOverride, string nameString, CSharpExports exportStatus, bool isConstructor, ref bool isFirstFeature, ref bool isMultiline) { CSharpArgument.BuildParameterList(writer, ParameterList, out string ParameterEntityList, out string ParameterNameList); if (!isConstructor) { writer.WriteIndentedLine($"void {nameString}({ParameterEntityList});"); isMultiline = false; } }
private void WriteCSharpImplementationDeferred(ICSharpWriter writer, ICSharpDeferredBody deferredBody, bool isOverride, string nameString, CSharpExports exportStatus, bool isConstructor, ref bool isFirstFeature, ref bool isMultiline) { CSharpArgument.BuildParameterList(writer, ParameterList, out string ParameterEntityList, out string ParameterNameList); CSharpAssertion.WriteContract(writer, deferredBody.RequireList, deferredBody.EnsureList, CSharpContractLocations.Other, true, ref isFirstFeature, ref isMultiline); string ExportStatusText = CSharpNames.ComposedExportStatus(false, true, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} void {nameString}({ParameterEntityList});"); isMultiline = false; }
private void WriteCSharpInterface(ICSharpWriter writer, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline) { isMultiline = false; string ResultType = EntityType.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None); CSharpArgument.BuildParameterList(writer, IndexParameterList, out string ParameterEntityList, out string ParameterNameList); string Accessors = "{ get; }"; writer.WriteIndentedLine($"{ResultType} this[{ParameterEntityList}] {Accessors}"); }
/// <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); string ExceptionTypeString = ExceptionType.Type2CSharpString(writer, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None); ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext(); string ArgumentListString = CSharpArgument.CSharpArgumentList(writer, ExpressionContext, FeatureCall); // TODO: CreationRoutine writer.WriteIndentedLine($"throw new {ExceptionTypeString}({ArgumentListString});"); }
/// <summary> /// Gets the source code corresponding to the expression. /// </summary> /// <param name="writer">The stream on which to write.</param> /// <param name="expressionContext">The context.</param> /// <param name="skippedIndex">Index of a destination to skip.</param> public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex) { Debug.Assert(WriteDown); ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext(); IndexedExpression.WriteCSharp(writer, SourceExpressionContext, -1); string IndexedText = SourceExpressionContext.ReturnValue; CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, -1, false, out string ArgumentListText, out IList <string> OutgoingResultList); expressionContext.SetSingleReturnValue($"{IndexedText}[{ArgumentListText}]"); }
/// <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(); SourceExpression.WriteCSharp(writer, SourceExpressionContext, -1); string SourceString = SourceExpressionContext.ReturnValue; ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext(); string ArgumentListString = CSharpArgument.CSharpArgumentList(writer, ExpressionContext, FeatureCall); writer.WriteIndentedLine($"base[{ArgumentListString}] = {SourceString};"); }
private void WriteCSharpFeatureCall(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex) { Feature.GetOutputFormat(SelectedOverloadType, out int OutgoingParameterCount, out int ReturnValueIndex); CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, ReturnValueIndex, false, out string ArgumentListText, out IList <string> OutgoingResultList); string QueryText = Query.CSharpText(writer, 0); Debug.Assert(OutgoingParameterCount > 0); if (OutgoingParameterCount == 1) { if (ArgumentListText.Length > 0) { expressionContext.SetSingleReturnValue($"{QueryText}({ArgumentListText})"); } else if (Feature is ICSharpFunctionFeature) { expressionContext.SetSingleReturnValue($"{QueryText}()"); } else { if (writer.AttachmentMap.ContainsKey(QueryText)) { QueryText = writer.AttachmentMap[QueryText]; } expressionContext.SetSingleReturnValue(QueryText); } } else { if (ReturnValueIndex >= 0) { string TemporaryResultName = writer.GetTemporaryName(); writer.WriteIndentedLine($"var {TemporaryResultName} = {QueryText}({ArgumentListText});"); OutgoingResultList.Insert(ReturnValueIndex, TemporaryResultName); } else { writer.WriteIndentedLine($"{QueryText}({ArgumentListText});"); } expressionContext.SetMultipleResult(OutgoingResultList, ReturnValueIndex); } }
private void WriteCSharpImplementationConstructor(ICSharpWriter writer, bool isOverride, string nameString, CSharpExports exportStatus, ref bool isFirstFeature, ref bool isMultiline, ref bool skipFirstInstruction) { CSharpArgument.BuildParameterList(writer, ParameterList, out string ParameterEntityList, out string ParameterNameList); string ExportStatusText = CSharpNames.ComposedExportStatus(isOverride, false, true, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {nameString}({ParameterEntityList})"); ICSharpEffectiveBody AsEffectiveBody = Body as ICSharpEffectiveBody; ICSharpClass Owner = ParentFeature.Owner; if (Owner.BaseClass != null) { ICSharpClass ParentClass = Owner.BaseClass; if (ParentClass.ClassConstructorType == CSharpConstructorTypes.OneConstructor) { if (AsEffectiveBody.BodyInstructionList.Count > 0) { /*TODO * ICommandInstruction AsCommandInstruction; * if ((AsCommandInstruction = AsEffectiveBody.BodyInstructionList[0] as ICommandInstruction) != null) * { * if (AsCommandInstruction.SelectedFeature.IsAssigned) * { * ICreationFeature AsCreationFeature; * if ((AsCreationFeature = AsCommandInstruction.SelectedFeature.Item as ICreationFeature) != null) * { * ICommandOverloadType SelectedOverload = AsCommandInstruction.SelectedOverload.Item; * ISealableList<Parameter> SelectedParameterList = SelectedOverload.ParameterTable; * string ArgumentListString = CSharpRootOutput.CSharpArgumentList(Context, SelectedParameterList, AsCommandInstruction.ArgumentList, new List<IQualifiedName>()); * * SkipFirstInstruction = true; * CSharpRootOutput.IncreaseIndent(); * writer.WriteIndentedLine(":" + " " + "base" + "(" + ArgumentListString + ")"); * CSharpRootOutput.DecreaseIndent(); * } * } * } */ } } } }
private void WriteCSharpImplementationPrecursor(ICSharpWriter writer, ICSharpPrecursorBody precursorBody, bool isOverride, string nameString, CSharpExports exportStatus, bool isConstructor, ref bool isFirstFeature, ref bool isMultiline) { CSharpArgument.BuildParameterList(writer, ParameterList, out string ParameterEntityList, out string ParameterNameList); if (isMultiline) { writer.WriteEmptyLine(); } string ExportStatusText = CSharpNames.ComposedExportStatus(true, false, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} void {nameString}({ParameterEntityList})"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); writer.WriteIndentedLine($"base.{nameString}({ParameterNameList});"); writer.DecreaseIndent(); writer.WriteIndentedLine("}"); isMultiline = true; }
private string CSharpTextFunction(ICSharpUsingCollection usingCollection, ICSharpFunctionFeature feature) { string Result; // TODO handle several overloads. Debug.Assert(feature.OverloadList.Count > 0); ICSharpQueryOverload Overload = feature.OverloadList[0] as ICSharpQueryOverload; Debug.Assert(Overload != null); string BaseTypeText; if (BaseType != null) { BaseTypeText = EffectiveBaseType.Type2CSharpString(usingCollection, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.OneWord); } else { BaseTypeText = $"I{CSharpNames.ToCSharpIdentifier(Delegated.Owner.ValidClassName)}"; } string AgentParameters; string ParameterNameListText; if (Overload.ParameterList.Count > 0) { CSharpArgument.BuildParameterList(usingCollection, Overload.ParameterList, out string ParameterListText, out ParameterNameListText); AgentParameters = $"({BaseTypeText} agentBase, {ParameterListText})"; } else { AgentParameters = $"({BaseTypeText} agentBase)"; ParameterNameListText = string.Empty; } Result = $"{AgentParameters} => {{ return agentBase.{CSharpNames.ToCSharpIdentifier(Delegated.Name)}({ParameterNameListText}); }}"; return(Result); }
private void WriteCSharpCustomOperator(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex) { string OperatorText = CSharpNames.ToCSharpIdentifier(Operator.Name); if (LeftExpression.IsSingleResult && RightExpression.IsSingleResult) { string LeftText = SingleResultExpressionText(writer, LeftExpression); ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext(); RightExpression.WriteCSharp(writer, SourceExpressionContext, -1); string RightText = SourceExpressionContext.ReturnValue; expressionContext.SetSingleReturnValue($"{LeftText}.{OperatorText}({RightText})"); } else { Operator.GetOutputFormat(SelectedOverloadType, out int OutgoingParameterCount, out int ReturnValueIndex); string LeftText = SingleResultExpressionText(writer, LeftExpression); CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, ReturnValueIndex, false, out string ArgumentListText, out IList <string> OutgoingResultList); if (ReturnValueIndex >= 0) { string TemporaryResultName = writer.GetTemporaryName(); writer.WriteIndentedLine($"var {TemporaryResultName} = {LeftText}.{OperatorText}({ArgumentListText});"); OutgoingResultList.Insert(ReturnValueIndex, TemporaryResultName); } else { writer.WriteIndentedLine($"{LeftText}.{OperatorText}({ArgumentListText});"); } expressionContext.SetMultipleResult(OutgoingResultList, ReturnValueIndex); } }
/// <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); string CommandText; if (IsCallingNumberFeature) { CommandText = Command.CSharpText(writer, 0); IList <IIdentifier> ValidPath = ((IQualifiedName)Source.Command).ValidPath.Item; IIdentifier FinalFeatureIdentifier = ValidPath[ValidPath.Count - 1]; if (FinalFeatureIdentifier.ValidText.Item == "Increment") { CommandText = CommandText.Substring(0, CommandText.Length - 10); writer.WriteIndentedLine($"{CommandText}++;"); return; } else if (FinalFeatureIdentifier.ValidText.Item == "Decrement") { CommandText = CommandText.Substring(0, CommandText.Length - 10); writer.WriteIndentedLine($"{CommandText}--;"); return; } } bool IsAgent = !(FinalFeature is ICSharpProcedureFeature); if (IsAgent) { IIdentifier AgentIdentifier = (IIdentifier)Source.Command.Path[Source.Command.Path.Count - 1]; string AgentIdentifierText = CSharpNames.ToCSharpIdentifier(AgentIdentifier.ValidText.Item); if (Source.Command.Path.Count > 1) { CommandText = Command.CSharpText(writer, 1); } else { CommandText = "this"; } if (FeatureCall.ArgumentList.Count > 0) { ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext(); string ArgumentListText = CSharpArgument.CSharpArgumentList(writer, ExpressionContext, FeatureCall); writer.WriteIndentedLine($"{AgentIdentifierText}({CommandText}, {ArgumentListText});"); } else { writer.WriteIndentedLine($"{AgentIdentifierText}({CommandText});"); } } else { CommandText = Command.CSharpText(writer, SkipLastInPath ? 1 : 0); ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext(); string ArgumentListText = CSharpArgument.CSharpArgumentList(writer, ExpressionContext, FeatureCall); writer.WriteIndentedLine($"{CommandText}({ArgumentListText});"); } }
/// <summary> /// Writes down the C# overload of a feature. /// </summary> /// <param name="writer">The stream on which to write.</param> /// <param name="featureTextType">The write mode.</param> /// <param name="isOverride">True if the feature is an override.</param> /// <param name="nameString">The composed feature name.</param> /// <param name="exportStatus">The feature export status.</param> /// <param name="isConstructor">True if the feature is a constructor.</param> /// <param name="isFirstFeature">True if the feature is the first in a list.</param> /// <param name="isMultiline">True if there is a separating line above.</param> public void WriteCSharp(ICSharpWriter writer, CSharpFeatureTextTypes featureTextType, bool isOverride, string nameString, CSharpExports exportStatus, bool isConstructor, ref bool isFirstFeature, ref bool isMultiline) { Debug.Assert(WriteDown); IList <ICSharpParameter> SelectedParameterList = ParameterList; IList <ICSharpParameter> SelectedResultList = ResultList; if (isOverride && Precursor != null) { SelectedParameterList = Precursor.ParameterList; SelectedResultList = Precursor.ResultList; } CSharpArgument.BuildParameterList(writer, SelectedParameterList, SelectedResultList, featureTextType, out string ArgumentEntityList, out string ArgumentNameList, out string ResultType); string ExportStatusText; if (featureTextType == CSharpFeatureTextTypes.Implementation) { bool IsHandled = false; switch (Body) { case ICSharpDeferredBody AsDeferredBody: CSharpAssertion.WriteContract(writer, AsDeferredBody.RequireList, AsDeferredBody.EnsureList, CSharpContractLocations.Other, true, ref isFirstFeature, ref isMultiline); ExportStatusText = CSharpNames.ComposedExportStatus(false, true, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {ResultType} {nameString}({ArgumentEntityList});"); isMultiline = false; IsHandled = true; break; case ICSharpEffectiveBody AsEffectiveBody: CSharpAssertion.WriteContract(writer, AsEffectiveBody.RequireList, AsEffectiveBody.EnsureList, CSharpContractLocations.Other, true, ref isFirstFeature, ref isMultiline); CSharpBodyFlags Flags = CSharpBodyFlags.MandatoryCurlyBrackets; string ResultString = string.Empty; List <string> InitialisationStringList = new List <string>(); if (ResultList.Count == 1) { Flags |= CSharpBodyFlags.HasResult; ICSharpParameter Result = ResultList[0]; ResultString = Result.Feature.Type.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None); } else { if (ResultType != "void") { Flags |= CSharpBodyFlags.HasResult; ResultString = ResultType; } foreach (ICSharpParameter Item in ResultList) { string InitValueString; ICSharpType ResultEntityType = Item.Feature.Type; if (ResultEntityType is ICSharpClassType AsClassType) { // TODO: when the type inherit from Enumeration if (AsClassType.Class.Source.ClassGuid == LanguageClasses.AnyOptionalReference.Guid) { InitValueString = "new OptionalReference<>(null)"; // TODO } else if (AsClassType.Class.Source.ClassGuid == LanguageClasses.String.Guid) { InitValueString = "\"\""; } else if (AsClassType.Class.Source.ClassGuid == LanguageClasses.Boolean.Guid) { InitValueString = "false"; } else if (AsClassType.Class.Source.ClassGuid == LanguageClasses.Character.Guid) { InitValueString = "'\0'"; } else if (AsClassType.Class.Source.ClassGuid == LanguageClasses.Number.Guid) { InitValueString = "0"; } else { InitValueString = "null"; } } else { InitValueString = "null"; // TODO : tuples } string InitNameString = CSharpNames.ToCSharpIdentifier(Item.Name); InitialisationStringList.Add($"{InitNameString} = {InitValueString};"); } } ExportStatusText = CSharpNames.ComposedExportStatus(isOverride, false, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {ResultType} {nameString}({ArgumentEntityList})"); AsEffectiveBody.WriteCSharp(writer, Flags, ResultString, false, InitialisationStringList); isMultiline = true; IsHandled = true; break; case ICSharpPrecursorBody AsPrecursorBody: if (isMultiline) { writer.WriteEmptyLine(); } ExportStatusText = CSharpNames.ComposedExportStatus(true, false, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {ResultType} {nameString}({ArgumentEntityList})"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); writer.WriteIndentedLine($"return base.{nameString}({ArgumentNameList});"); writer.DecreaseIndent(); writer.WriteIndentedLine("}"); isMultiline = true; IsHandled = true; break; } Debug.Assert(IsHandled); } else { writer.WriteIndentedLine($"{ResultType} {nameString}({ArgumentEntityList});"); isMultiline = false; } }
/// <summary> /// Gets the source code corresponding to the expression. /// </summary> /// <param name="writer">The stream on which to write.</param> /// <param name="expressionContext">The context.</param> /// <param name="skippedIndex">Index of a destination to skip.</param> public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex) { Debug.Assert(WriteDown); string CoexistingPrecursorName = string.Empty; string CoexistingPrecursorRootName = ParentFeature.CoexistingPrecursorName; if (!string.IsNullOrEmpty(CoexistingPrecursorRootName)) { CoexistingPrecursorName = CSharpNames.ToCSharpIdentifier(CoexistingPrecursorRootName + " " + "Base"); } PrecursorFeature.GetOutputFormat(SelectedOverloadType, out int OutgoingParameterCount, out int ReturnValueIndex); CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, ReturnValueIndex, false, out string ArgumentListText, out IList <string> OutgoingResultList); Debug.Assert(OutgoingParameterCount > 0); bool HasArguments = (ParentFeature is ICSharpFunctionFeature) || FeatureCall.ArgumentList.Count > 0; if (HasArguments) { ArgumentListText = $"({ArgumentListText})"; } if (!string.IsNullOrEmpty(CoexistingPrecursorRootName)) { expressionContext.SetSingleReturnValue($"{CoexistingPrecursorName}{ArgumentListText}"); } else { string FunctionName = CSharpNames.ToCSharpIdentifier(ParentFeature.Name); if (OutgoingParameterCount == 1) { if (ArgumentListText.Length > 0) { expressionContext.SetSingleReturnValue($"base.{FunctionName}{ArgumentListText}"); } else if (SelectedOverloadType != null) { expressionContext.SetSingleReturnValue($"base.{FunctionName}()"); } else { expressionContext.SetSingleReturnValue($"base.{FunctionName}"); } } else { if (ReturnValueIndex >= 0) { string TemporaryResultName = writer.GetTemporaryName(); writer.WriteIndentedLine($"var {TemporaryResultName} = base.{FunctionName}{ArgumentListText};"); OutgoingResultList.Insert(ReturnValueIndex, TemporaryResultName); } else { writer.WriteIndentedLine($"base.{FunctionName}{ArgumentListText};"); } expressionContext.SetMultipleResult(OutgoingResultList, ReturnValueIndex); } } }
/// <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); string EntityString = CSharpNames.ToCSharpIdentifier(CreatedObjectName); string EntityTypeString = EntityType.Type2CSharpString(writer, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None); bool IsAnchoredToCreationType = false; if (EntityType.Source is IAnchoredType AsAnchoredType) { if (AsAnchoredType.AnchorKind == BaseNode.AnchorKinds.Creation) { IsAnchoredToCreationType = true; } } string CreationRoutineString = CSharpNames.ToCSharpIdentifier(CreationRoutineName); ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext(); string ArgumentListText = CSharpArgument.CSharpArgumentList(writer, ExpressionContext, FeatureCall); CSharpConstructorTypes ClassConstructorType = CSharpConstructorTypes.OneConstructor; if (EntityType is ICSharpClassType AsClassType) { ClassConstructorType = AsClassType.Class.ClassConstructorType; if (AsClassType.Class.Source.ClassGuid == LanguageClasses.List.Guid && CreationRoutineString == "MakeEmpty") { ClassConstructorType = CSharpConstructorTypes.NoConstructor; } } bool IsHandled = false; switch (ClassConstructorType) { case CSharpConstructorTypes.NoConstructor: case CSharpConstructorTypes.OneConstructor: if (IsAnchoredToCreationType) { writer.WriteIndentedLine($"{EntityString} = Activator.CreateInstance(typeof({EntityTypeString}).Assembly.FullName, typeof({EntityTypeString}).FullName, {ArgumentListText}).Unwrap() as {EntityTypeString};"); } else { writer.WriteIndentedLine($"{EntityString} = new {EntityTypeString}({ArgumentListText});"); } IsHandled = true; break; case CSharpConstructorTypes.ManyConstructors: if (IsAnchoredToCreationType) { writer.WriteIndentedLine($"{EntityString} = Activator.CreateInstance(typeof({EntityTypeString}).Assembly.FullName, typeof({EntityTypeString}).FullName).Unwrap() as {EntityTypeString};"); writer.WriteIndentedLine($"{EntityString}.{CreationRoutineString}({ArgumentListText});"); } else { writer.WriteIndentedLine($"{EntityString} = new {EntityTypeString}();"); writer.WriteIndentedLine($"{EntityString}.{CreationRoutineString}({ArgumentListText});"); } IsHandled = true; break; } Debug.Assert(IsHandled); }
private void WriteCSharpImplementation(ICSharpWriter writer, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline) { writer.WriteDocumentation(Source); string ResultType = EntityType.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None); CSharpArgument.BuildParameterList(writer, IndexParameterList, out string ParameterEntityList, out string ParameterNameList); string Accessors; if (!IsForcedReadWrite && SetterBody == null) { Accessors = "{ get; }"; } else if (!IsForcedReadWrite && GetterBody == null) { Accessors = "{ set; }"; } else { Accessors = "{ get; set; }"; } bool IsDeferred = false; if (GetterBody != null) { if (GetterBody is ICSharpDeferredBody) { IsDeferred = true; } else { IsDeferred = false; } } else if (SetterBody != null) { if (SetterBody is ICSharpDeferredBody) { IsDeferred = true; } else { IsDeferred = false; } } if (IsDeferred) { if (GetterBody is ICSharpDeferredBody AsDeferredGetterBody) { CSharpAssertion.WriteContract(writer, AsDeferredGetterBody.RequireList, AsDeferredGetterBody.EnsureList, CSharpContractLocations.Getter, false, ref isFirstFeature, ref isMultiline); isMultiline = false; } if (SetterBody is ICSharpDeferredBody AsDeferredSetterBody) { CSharpAssertion.WriteContract(writer, AsDeferredSetterBody.RequireList, AsDeferredSetterBody.EnsureList, CSharpContractLocations.Setter, false, ref isFirstFeature, ref isMultiline); } string ExportStatusText = CSharpNames.ComposedExportStatus(false, true, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {ResultType} this[{ParameterEntityList}] {Accessors}"); isMultiline = false; } else { string ExportStatusText = CSharpNames.ComposedExportStatus(IsOverride, false, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {ResultType} this[{ParameterEntityList}]"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); bool IsPrecursor = false; if (GetterBody != null) { if (GetterBody is ICSharpPrecursorBody) { IsPrecursor = true; } else { IsPrecursor = false; } } else if (SetterBody != null) { if (GetterBody is ICSharpPrecursorBody) { IsPrecursor = true; } else { IsPrecursor = false; } } if (IsPrecursor) { if (GetterBody is ICSharpPrecursorBody AsPrecursorGetterBody) { isMultiline = false; CSharpAssertion.WriteContract(writer, AsPrecursorGetterBody.RequireList, AsPrecursorGetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); writer.WriteIndentedLine("get"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); writer.WriteIndentedLine($"return base[{ParameterEntityList}];"); writer.DecreaseIndent(); writer.WriteIndentedLine("}"); } else if (IsForcedReadWrite) { writer.WriteIndentedLine("get { throw new InvalidOperationException(); }"); } if (SetterBody is ICSharpPrecursorBody AsPrecursorSetterBody) { isMultiline = false; CSharpAssertion.WriteContract(writer, AsPrecursorSetterBody.RequireList, AsPrecursorSetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); writer.WriteIndentedLine("set"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); writer.WriteIndentedLine($"base[{ParameterEntityList}] = value;"); writer.DecreaseIndent(); writer.WriteIndentedLine("}"); } else if (IsForcedReadWrite) { writer.WriteIndentedLine("set { throw new InvalidOperationException(); }"); } } else { if (GetterBody != null) { if (GetterBody is ICSharpEffectiveBody AsEffectiveGetterBody) { isMultiline = false; CSharpAssertion.WriteContract(writer, AsEffectiveGetterBody.RequireList, AsEffectiveGetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); writer.WriteIndentedLine("get"); AsEffectiveGetterBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets | CSharpBodyFlags.HasResult, ResultType, false, new List <string>()); } } else if (IsForcedReadWrite) { writer.WriteIndentedLine("get { throw new InvalidOperationException(); }"); } if (SetterBody != null) { if (SetterBody is ICSharpEffectiveBody AsEffectiveSetterBody) { isMultiline = false; CSharpAssertion.WriteContract(writer, AsEffectiveSetterBody.RequireList, AsEffectiveSetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); writer.WriteIndentedLine("set"); AsEffectiveSetterBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets | CSharpBodyFlags.HasValue, string.Empty, false, new List <string>()); } } else if (IsForcedReadWrite) { writer.WriteIndentedLine("set { throw new InvalidOperationException(); }"); } } writer.DecreaseIndent(); writer.WriteIndentedLine("}"); isMultiline = true; } }