private static void CSharpAssignmentResultList(ICSharpWriter writer, ICSharpExpressionContext expressionContext, ICSharpFeatureCall featureCall, int skippedIndex, bool isAgentCall, ref string callText, out IList <string> outgoingResultList) { IList <ICSharpParameter> ResultList = featureCall.ResultList; outgoingResultList = new List <string>(); for (int i = 0; i < ResultList.Count; i++) { if (i == skippedIndex) { continue; } if (!isAgentCall && callText.Length > 0) { callText += ", "; } ICSharpVariableContext Destination = i < expressionContext.DestinationNameList.Count ? expressionContext.DestinationNameList[i] : null; string ResultText; if (Destination == null || !Destination.IsDeclared) { Debug.Assert(i < ResultList.Count); ICSharpParameter callTextParameter = ResultList[i]; string TempTypeText = callTextParameter.Feature.Type.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None); string TempText; if (Destination != null) { TempText = Destination.Name; } else { TempText = ResultList[i].Name; } TempText = writer.GetTemporaryName(TempText); if (!isAgentCall) { callText += $"out {TempTypeText} {TempText}"; } ResultText = TempText; } else { string DestinationText = Destination.Name; if (!isAgentCall) { callText += $"out {DestinationText}"; } ResultText = DestinationText; } outgoingResultList.Add(ResultText); } }
/// <summary> /// Writes down the body source code. /// </summary> /// <param name="writer">The stream on which to write down.</param> /// <param name="flags">Some flags.</param> /// <param name="resultType">Type of the result, if any.</param> /// <param name="skipFirstInstruction">Skip the first instruction.</param> /// <param name="initialisationStringList">List of initializations.</param> public virtual void WriteCSharp(ICSharpWriter writer, CSharpBodyFlags flags, string resultType, bool skipFirstInstruction, IList <string> initialisationStringList) { Debug.Assert(WriteDown); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); IList <ICSharpAssertion> EffectiveRequireList = RequireList; IList <ICSharpAssertion> EffectiveEnsureList = EnsureList; switch (ParentFeature) { case ICSharpFunctionFeature AsFunctionFeature: if (AsFunctionFeature.OriginalPrecursor != null) { ICSharpQueryOverload ParentOverload = null; foreach (ICSharpQueryOverload Overload in AsFunctionFeature.OverloadList) { if (Overload.Body == this) { ParentOverload = Overload; break; } } Debug.Assert(ParentOverload != null); ICSharpQueryOverload ParentPrecursorOverload = ParentOverload.Precursor; if (ParentPrecursorOverload != null) { ICSharpBody PrecursorBody = ParentPrecursorOverload.Body; if (RequireList.Count == 0 && PrecursorBody.RequireList.Count > 0) { EffectiveRequireList = PrecursorBody.RequireList; } if (EnsureList.Count == 0 && PrecursorBody.EnsureList.Count > 0) { EffectiveEnsureList = PrecursorBody.EnsureList; } } } break; case ICSharpProcedureFeature AsProcedureFeature: if (AsProcedureFeature.OriginalPrecursor != null) { ICSharpCommandOverload ParentOverload = null; foreach (ICSharpCommandOverload Overload in AsProcedureFeature.OverloadList) { if (Overload.Body == this) { ParentOverload = Overload; break; } } Debug.Assert(ParentOverload != null); ICSharpCommandOverload ParentPrecursorOverload = ParentOverload.Precursor; if (ParentPrecursorOverload != null) { ICSharpBody PrecursorBody = ParentPrecursorOverload.Body; if (RequireList.Count == 0 && PrecursorBody.RequireList.Count > 0) { EffectiveRequireList = PrecursorBody.RequireList; } if (EnsureList.Count == 0 && PrecursorBody.EnsureList.Count > 0) { EffectiveEnsureList = PrecursorBody.EnsureList; } } } break; case ICSharpPropertyFeature AsPropertyFeature: if (AsPropertyFeature.OriginalPrecursor != null) { ICSharpBody PrecursorBody = null; if (this == AsPropertyFeature.GetterBody) { PrecursorBody = AsPropertyFeature.OriginalPrecursor.GetterBody; } else if (this == AsPropertyFeature.SetterBody) { PrecursorBody = AsPropertyFeature.OriginalPrecursor.SetterBody; } if (PrecursorBody != null) { if (RequireList.Count == 0 && PrecursorBody.RequireList.Count > 0) { EffectiveRequireList = PrecursorBody.RequireList; } if (EnsureList.Count == 0 && PrecursorBody.EnsureList.Count > 0) { EffectiveEnsureList = PrecursorBody.EnsureList; } } } break; case ICSharpIndexerFeature AsIndexerFeature: if (AsIndexerFeature.OriginalPrecursor != null) { ICSharpBody PrecursorBody = null; if (this == AsIndexerFeature.GetterBody) { PrecursorBody = AsIndexerFeature.OriginalPrecursor.GetterBody; } else if (this == AsIndexerFeature.SetterBody) { PrecursorBody = AsIndexerFeature.OriginalPrecursor.SetterBody; } if (PrecursorBody != null) { if (RequireList.Count == 0 && PrecursorBody.RequireList.Count > 0) { EffectiveRequireList = PrecursorBody.RequireList; } if (EnsureList.Count == 0 && PrecursorBody.EnsureList.Count > 0) { EffectiveEnsureList = PrecursorBody.EnsureList; } } } break; } foreach (ICSharpAssertion Assertion in EffectiveRequireList) { Assertion.WriteCSharp(writer); } if (EffectiveRequireList.Count > 0) { writer.WriteEmptyLine(); } /*TODO * List<AttachmentAlias> AttachmentVariableTable = new List<AttachmentAlias>(); * foreach (IInstruction Item in BodyInstructionList) * Item.AddAttachmentVariables(Context, AttachmentVariableTable); */ if (flags.HasFlag(CSharpBodyFlags.HasResult)) { writer.WriteIndentedLine($"{resultType} Result = default;"); } foreach (ICSharpScopeAttributeFeature Item in EntityDeclarationList) { Item.WriteCSharp(writer); } /*TODO * foreach (AttachmentAlias AliasItem in AttachmentVariableTable) * { * string AttachedVariableName = AliasItem.EntityName; * string AttachmentTypeString = CSharpTypes.Type2CSharpString(AliasItem.EntityType, Context, AliasItem.AttachmentFormat, CSharpNamespaceFormats.None); * * writer.WriteIndentedLine(AttachmentTypeString + " " + AttachedVariableName + ";"); * Context.AttachmentVariableTable.Add(AliasItem); * } */ if (flags.HasFlag(CSharpBodyFlags.HasResult) || EntityDeclarationList.Count > 0 /* || AttachmentVariableTable.Count > 0*/) { writer.WriteEmptyLine(); } foreach (string s in initialisationStringList) { writer.WriteIndentedLine(s); } if (initialisationStringList.Count > 0) { writer.WriteEmptyLine(); } for (int i = 0; i < BodyInstructionList.Count; i++) { if (i == 0 && skipFirstInstruction) { continue; } ICSharpInstruction Item = BodyInstructionList[i]; Item.WriteCSharp(writer); } if (EffectiveEnsureList.Count > 0) { writer.WriteEmptyLine(); foreach (ICSharpAssertion Assertion in EffectiveEnsureList) { Assertion.WriteCSharp(writer); } if (flags.HasFlag(CSharpBodyFlags.HasResult)) { writer.WriteEmptyLine(); } } // TODO: ExceptionHandlerList if (ParentFeature.Owner.HasCheckInvariant) { writer.WriteEmptyLine(); writer.WriteIndentedLine("CheckInvariant();"); } if (flags.HasFlag(CSharpBodyFlags.HasResult)) { writer.WriteIndentedLine("return Result;"); } /*TODO * foreach (AttachmentAlias AliasItem in AttachmentVariableTable) * Context.AttachmentVariableTable.Remove(AliasItem); */ writer.DecreaseIndent(); writer.WriteIndentedLine("}"); }
private void ComputeCustomOperator(ICSharpWriter writer) { ComputedValue = CSharpQueryExpression.ComputeQueryResult(writer, Operator, FeatureCall); }
/// <summary> /// Writes down the C# feature. /// </summary> /// <param name="writer">The stream on which to write.</param> /// <param name="featureTextType">The write mode.</param> /// <param name="exportStatus">The feature export status.</param> /// <param name="isLocal">True if the feature is local to the class.</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 abstract void WriteCSharp(ICSharpWriter writer, CSharpFeatureTextTypes featureTextType, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline);
/// <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 ComputeNumberOperator(ICSharpWriter writer) { Number LeftNumber = ComputeSide(writer, LeftExpression); Number RightNumber = ComputeSide(writer, LeftExpression); int IntValue; bool IsHandled = false; switch (Operator.Name) { case "≥": ComputedValue = ToComputedValue(LeftNumber > RightNumber || LeftNumber.Equals(RightNumber)); IsHandled = true; break; case "≤": ComputedValue = ToComputedValue(LeftNumber < RightNumber || LeftNumber.Equals(RightNumber)); IsHandled = true; break; case ">": ComputedValue = ToComputedValue(LeftNumber > RightNumber); IsHandled = true; break; case "<": ComputedValue = ToComputedValue(LeftNumber < RightNumber); IsHandled = true; break; /* TODO: make up our mind: 'shift right' or '>>' ?! * * case "shift right": * ComputedValue = ToComputedValue(LeftNumber.ShiftRight(RightNumber)); * break; * case "shift left": * ComputedValue = ToComputedValue(LeftNumber.ShiftLeft(RightNumber)); * break; */ case ">>": RightNumber.TryParseInt(out IntValue); ComputedValue = ToComputedValue(LeftNumber >> IntValue); IsHandled = true; break; case "<<": RightNumber.TryParseInt(out IntValue); ComputedValue = ToComputedValue(LeftNumber << IntValue); IsHandled = true; break; case "modulo": ComputedValue = ToComputedValue(LeftNumber.Remainder(RightNumber)); IsHandled = true; break; case "bitwise and": ComputedValue = ToComputedValue(LeftNumber.BitwiseAnd(RightNumber)); IsHandled = true; break; case "bitwise or": ComputedValue = ToComputedValue(LeftNumber.BitwiseOr(RightNumber)); IsHandled = true; break; case "bitwise xor": ComputedValue = ToComputedValue(LeftNumber.BitwiseXor(RightNumber)); IsHandled = true; break; case "+": ComputedValue = ToComputedValue(LeftNumber + RightNumber); IsHandled = true; break; case "-": ComputedValue = ToComputedValue(LeftNumber - RightNumber); IsHandled = true; break; case "*": ComputedValue = ToComputedValue(LeftNumber * RightNumber); IsHandled = true; break; case "/": ComputedValue = ToComputedValue(LeftNumber / RightNumber); IsHandled = true; break; } Debug.Assert(IsHandled); }
/// <summary> /// Runs the compiler to compute the value as a string. /// </summary> /// <param name="writer">The stream on which to write.</param> public void Compute(ICSharpWriter writer) { string ResultValue = ComputeNestedExpression(writer, SourceExpression); ComputedValue = ResultValue; }
/// <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 }
/// <summary> /// Computes the result of a call with constant arguments. /// </summary> /// <param name="writer">The stream on which to write.</param> /// <param name="feature">The feature called.</param> /// <param name="featureCall">Arguments of the call.</param> public static string ComputeQueryResult(ICSharpWriter writer, ICSharpFeatureWithName feature, ICSharpFeatureCall featureCall) { string FeatureArguments = string.Empty; foreach (ICSharpArgument Argument in featureCall.ArgumentList) { ICSharpExpression SourceExpression = Argument.SourceExpression; string SourceExpressionValue = ComputeNestedExpression(writer, SourceExpression); if (FeatureArguments.Length > 0) { FeatureArguments += ", "; } FeatureArguments += SourceExpressionValue; } string FeatureName = feature != null ? feature.Name : null; string GuidText = feature.Owner.Source.ClassGuid.ToString(); Assembly CurrentAssembly = Assembly.GetExecutingAssembly(); string ExeFolder = Path.GetDirectoryName(CurrentAssembly.Location); string ErrorFileName = Path.Combine(writer.OutputFolder, "Temp", "error.txt"); string OutputFolder = Path.Combine(writer.OutputFolder, "Temp"); if (Directory.Exists(OutputFolder)) { try { Directory.Delete(OutputFolder, true); } catch { } } try { Directory.CreateDirectory(OutputFolder); } catch { } StartProcess(Path.Combine(ExeFolder, "Compiler.exe"), $"BaseNode \"{writer.SourceFileName}\" \"{ErrorFileName}\" \"{OutputFolder}\" NV {GuidText} {FeatureName}", false, out Process Compiler); Compiler.WaitForExit(); string SpecialFileName = Path.Combine(OutputFolder, "SpecialMain.cs"); using (FileStream fs = new FileStream(SpecialFileName, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine("namespace BaseNode"); sw.WriteLine("{"); sw.WriteLine(" public static class SpecialMain"); sw.WriteLine(" {"); sw.WriteLine(" public static string Main()"); sw.WriteLine(" {"); sw.WriteLine($" var Source = new {CSharpNames.ToCSharpIdentifier(feature.Owner.ValidClassName)}();"); sw.WriteLine($" object Result = Source.{CSharpNames.ToCSharpIdentifier(FeatureName)}({FeatureArguments});"); sw.WriteLine(" return Result.ToString();"); sw.WriteLine(" }"); sw.WriteLine(" }"); sw.WriteLine("}"); } } StartProcess(@"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe", $"\"{OutputFolder}/CSharpProject.sln\"", false, out Process Builder); Builder.WaitForExit(); try { File.Copy($"{OutputFolder}/bin/Debug/CSharpProject.dll", Path.Combine(ExeFolder, "CSharpProject.dll"), true); } catch { //TODO Failed to compute return("TODO"); } StartProcess(Path.Combine(ExeFolder, "ConstantComputation.exe"), null, true, out Process ConstantComputation); string Line = string.Empty; while (!ConstantComputation.StandardOutput.EndOfStream) { Line = ConstantComputation.StandardOutput.ReadLine(); } return(Line); }
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; } }
private void ComputeFeature(ICSharpWriter writer) { ComputedValue = ComputeQueryResult(writer, Feature as ICSharpFeatureWithName, FeatureCall); }
/// <summary> /// Writes down the C# scope. /// </summary> /// <param name="writer">The stream on which to write.</param> /// <param name="curlyBracketsInsertion">The mode to use to write the C# scope..</param> /// <param name="endWithBreak">Add a break instruction at the end.</param> public virtual void WriteCSharp(ICSharpWriter writer, CSharpCurlyBracketsInsertions curlyBracketsInsertion, bool endWithBreak) { Debug.Assert(WriteDown); bool UseCurlyBrackets = false; if (curlyBracketsInsertion.HasFlag(CSharpCurlyBracketsInsertions.Mandatory)) { UseCurlyBrackets = true; } /* * List<AttachmentAlias> AttachmentVariableTable = new List<AttachmentAlias>(); * foreach (IInstruction Item in InstructionList) * Item.AddAttachmentVariables(Context, AttachmentVariableTable); */ if (EntityDeclarationList.Count > 0 /* || AttachmentVariableTable.Count > 0*/ || InstructionList.Count != 1) { UseCurlyBrackets = true; } if (curlyBracketsInsertion.HasFlag(CSharpCurlyBracketsInsertions.AlreadyInserted)) { UseCurlyBrackets = false; } if (UseCurlyBrackets) { writer.WriteIndentedLine("{"); } writer.IncreaseIndent(); foreach (ICSharpScopeAttributeFeature Item in EntityDeclarationList) { Item.WriteCSharp(writer); } /* * foreach (AttachmentAlias AliasItem in AttachmentVariableTable) * { * string AttachedVariableName = AliasItem.EntityName; * string AttachmentTypeString = CSharpTypes.Type2CSharpString(AliasItem.EntityType, Context, AliasItem.AttachmentFormat, CSharpNamespaceFormats.None); * * writer.WriteIndentedLine(AttachmentTypeString + " " + AttachedVariableName + ";"); * Context.AttachmentVariableTable.Add(AliasItem); * } */ if (EntityDeclarationList.Count > 0 /* || AttachmentVariableTable.Count > 0*/) { writer.WriteEmptyLine(); } foreach (ICSharpInstruction Item in InstructionList) { Item.WriteCSharp(writer); } if (endWithBreak) { writer.WriteIndentedLine("break;"); } /* * foreach (AttachmentAlias AliasItem in AttachmentVariableTable) * Context.AttachmentVariableTable.Remove(AliasItem); */ writer.DecreaseIndent(); if (UseCurlyBrackets) { writer.WriteIndentedLine("}"); } }
/// <summary> /// Gets the source code of arguments of a feature call. /// </summary> /// <param name="writer">The stream on which to write.</param> /// <param name="expressionContext">The context.</param> /// <param name="featureCall">Details of the call.</param> public static string CSharpArgumentList(ICSharpWriter writer, ICSharpExpressionContext expressionContext, ICSharpFeatureCall featureCall) { CSharpArgumentList(writer, expressionContext, featureCall, -1, false, out string callText, out IList <string> OutgoingResultList); return(callText); }
/// <summary> /// Writes down the C# instruction. /// </summary> /// <param name="writer">The stream on which to write.</param> public abstract void WriteCSharp(ICSharpWriter writer);
/// <summary> /// Runs the compiler to compute the value as a string. /// </summary> /// <param name="writer">The stream on which to write.</param> public void Compute(ICSharpWriter writer) { string IndexedValue = ComputeNestedExpression(writer, IndexedExpression); //TODO }
/// <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); bool UseCurlyBrackets = false; /*TODO * List<AttachmentAlias> AttachmentVariableTable = new List<AttachmentAlias>(); * foreach (IInstruction Item in InitInstructionList) * Item.AddAttachmentVariables(Context, AttachmentVariableTable); * foreach (IInstruction Item in LoopInstructionList) * Item.AddAttachmentVariables(Context, AttachmentVariableTable); * foreach (IInstruction Item in IterationInstructionList) * Item.AddAttachmentVariables(Context, AttachmentVariableTable); */ if (EntityDeclarationList.Count > 0 /* || AttachmentVariableTable.Count > 0*/ || InitInstructionList.Count > 1) { UseCurlyBrackets = true; } if (UseCurlyBrackets) { writer.WriteIndentedLine("{"); writer.IncreaseIndent(); } foreach (ICSharpScopeAttributeFeature Item in EntityDeclarationList) { Item.WriteCSharp(writer); } if (Source.Variant.IsAssigned) { writer.WriteIndentedLine("double LoopVariant = double.NaN;"); } /* * foreach (AttachmentAlias AliasItem in AttachmentVariableTable) * { * string AttachedVariableName = AliasItem.EntityName; * string AttachmentTypeString = CSharpTypes.Type2CSharpString(AliasItem.EntityType, Context, AliasItem.AttachmentFormat, CSharpNamespaceFormats.None); * * writer.WriteIndentedLine(AttachmentTypeString + " " + AttachedVariableName + ";"); * Context.AttachmentVariableTable.Add(AliasItem); * }*/ if (EntityDeclarationList.Count > 0 /* || AttachmentVariableTable.Count > 0*/) { writer.WriteEmptyLine(); } foreach (ICSharpInstruction Item in InitInstructionList) { Item.WriteCSharp(writer); } WriteCSharpInvariant(writer); if (InvariantList.Count > 0) { writer.WriteEmptyLine(); } ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext(); WhileCondition.WriteCSharp(writer, SourceExpressionContext, -1); string WhileString = SourceExpressionContext.ReturnValue; writer.WriteIndentedLine($"while ({WhileString})"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); foreach (ICSharpInstruction Item in LoopInstructionList) { Item.WriteCSharp(writer); } if (LoopInstructionList.Count > 0 && IterationInstructionList.Count > 0) { writer.WriteEmptyLine(); } foreach (ICSharpInstruction Item in IterationInstructionList) { Item.WriteCSharp(writer); } if (VariantExpression != null) { ICSharpExpressionContext VariantExpressionContext = new CSharpExpressionContext(); VariantExpression.WriteCSharp(writer, VariantExpressionContext, -1); string ExpressionText = VariantExpressionContext.ReturnValue; writer.WriteIndentedLine($"double NewVariantResult = {ExpressionText};"); writer.WriteIndentedLine("if (NewVariantResult >= LoopVariant)// Takes advantage of the fact that 'x >= NaN' is always false"); writer.IncreaseIndent(); writer.WriteIndentedLine("throw new InvalidOperationException();"); writer.DecreaseIndent(); writer.WriteIndentedLine("LoopVariant = NewVariantResult;"); } WriteCSharpInvariant(writer); writer.DecreaseIndent(); writer.WriteIndentedLine("}"); /* * foreach (AttachmentAlias AliasItem in AttachmentVariableTable) * Context.AttachmentVariableTable.Remove(AliasItem); */ if (UseCurlyBrackets) { writer.DecreaseIndent(); writer.WriteIndentedLine("}"); } }
/// <summary> /// Writes down the C# feature. /// </summary> /// <param name="writer">The stream on which to write.</param> /// <param name="featureTextType">The write mode.</param> /// <param name="exportStatus">The feature export status.</param> /// <param name="isLocal">True if the feature is local to the class.</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 override void WriteCSharp(ICSharpWriter writer, CSharpFeatureTextTypes featureTextType, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline) { WriteCSharp(writer); }
/// <summary> /// Writes down the C# continuation instructions. /// </summary> /// <param name="writer">The stream on which to write.</param> public virtual void WriteCSharpInstructions(ICSharpWriter writer) { Instructions.WriteCSharp(writer, CSharpCurlyBracketsInsertions.Mandatory, 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 LeftText; ICSharpExpressionContext LeftSourceExpressionContext = new CSharpExpressionContext(); LeftExpression.WriteCSharp(writer, LeftSourceExpressionContext, -1); if (LeftSourceExpressionContext.ReturnValue != null) { string Result = LeftSourceExpressionContext.ReturnValue; if (LeftExpression.IsComplex) { Result = $"({Result})"; } LeftText = Result; } else { //TODO LeftText = "TODO"; } string RightText; ICSharpExpressionContext RightSourceExpressionContext = new CSharpExpressionContext(); RightExpression.WriteCSharp(writer, RightSourceExpressionContext, -1); if (RightSourceExpressionContext.ReturnValue != null) { string Result = RightSourceExpressionContext.ReturnValue; if (RightExpression.IsComplex) { Result = $"({Result})"; } RightText = Result; } else { //TODO RightText = "TODO"; } string EqualitySign = null; switch (Source.Comparison) { case BaseNode.ComparisonType.Equal: EqualitySign = "=="; break; case BaseNode.ComparisonType.Different: EqualitySign = "!="; break; } Debug.Assert(EqualitySign != null); expressionContext.SetSingleReturnValue($"{LeftText} {EqualitySign} {RightText}"); }
/// <summary> /// Runs the compiler to compute the value as a string. /// </summary> /// <param name="writer">The stream on which to write.</param> public void Compute(ICSharpWriter writer) { bool RightValue = ComputeBooleanSideExpression(writer, RightExpression); ComputedValue = ToComputedValue(!RightValue); }
/// <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 ContinueExpressionText; for (int i = 0; i < ContinuationList.Count; i++) { ICSharpContinuation Item = ContinuationList[i]; if (i > 0) { writer.WriteEmptyLine(); } WriteCSharpContinueCondition(writer, out ContinueExpressionText); writer.WriteIndentedLine($"if ({ContinueExpressionText})"); Item.WriteCSharpInstructions(writer); int CleanupInstructionCount = 0; for (int j = i; j > 0; j--) { ICSharpContinuation PreviousItem = ContinuationList[j - 1]; CleanupInstructionCount += PreviousItem.CleanupList.Count; } if (CleanupInstructionCount > 0) { writer.WriteIndentedLine("else"); if (CleanupInstructionCount > 1) { writer.WriteIndentedLine("{"); } writer.IncreaseIndent(); for (int j = i; j > 0; j--) { if (j < i) { writer.WriteEmptyLine(); } ICSharpContinuation PreviousItem = ContinuationList[j - 1]; PreviousItem.WriteCSharpCleanupInstructions(writer); } writer.DecreaseIndent(); if (CleanupInstructionCount > 1) { writer.WriteIndentedLine("}"); } } } if (ElseInstructions != null) { writer.WriteEmptyLine(); WriteCSharpContinueCondition(writer, out ContinueExpressionText); writer.WriteIndentedLine($"if (!({ContinueExpressionText}))"); ElseInstructions.WriteCSharp(writer, CSharpCurlyBracketsInsertions.Mandatory, 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); BooleanExpression.WriteCSharp(writer, expressionContext, skippedIndex); }
/// <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) { //TODO }
/// <summary> /// Runs the compiler to compute the value as a string. /// </summary> /// <param name="writer">The stream on which to write.</param> public void Compute(ICSharpWriter writer) { //TODO use the precusor instead ComputedValue = CSharpQueryExpression.ComputeQueryResult(writer, ParentFeature, FeatureCall); }
private void WriteCSharpWriteOnlyProperty(ICSharpWriter writer, bool isOverride, CSharpExports exportStatus, string propertyName, string resultType, ref bool isFirstFeature, ref bool isMultiline) { bool IsDeferred = false; bool IsPrecursor = false; isFirstFeature = false; if (SetterBody != null) { if (SetterBody is ICSharpDeferredBody) { IsDeferred = true; } if (SetterBody is ICSharpPrecursorBody) { IsPrecursor = true; } } if (SetterBody != null) { if (IsDeferred) { ICSharpDeferredBody DeferredSetterBody = SetterBody as ICSharpDeferredBody; Debug.Assert(DeferredSetterBody != null); CSharpAssertion.WriteContract(writer, DeferredSetterBody.RequireList, DeferredSetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); string ExportStatusText = CSharpNames.ComposedExportStatus(false, true, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {resultType} {propertyName} {{ protected get; set; }}"); isMultiline = false; } else { if (isMultiline) { writer.WriteEmptyLine(); } string ExportStatusText = CSharpNames.ComposedExportStatus(IsOverride, false, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {resultType} {propertyName}"); if (IsPrecursor) { writer.WriteIndentedLine("{"); writer.IncreaseIndent(); writer.WriteIndentedLine($"set {{ base.{propertyName} = value; }}"); writer.DecreaseIndent(); writer.WriteIndentedLine("}"); } else { writer.WriteIndentedLine("{"); writer.IncreaseIndent(); writer.WriteIndentedLine($"protected get {{ return _{propertyName}; }}"); ICSharpEffectiveBody EffectiveSetterBody = SetterBody as ICSharpEffectiveBody; Debug.Assert(EffectiveSetterBody != null); isMultiline = false; CSharpAssertion.WriteContract(writer, EffectiveSetterBody.RequireList, EffectiveSetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); writer.WriteIndentedLine("set"); EffectiveSetterBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets | CSharpBodyFlags.HasValue, string.Empty, false, new List <string>()); writer.DecreaseIndent(); writer.WriteIndentedLine("}"); } isMultiline = true; } } else { if (isMultiline) { writer.WriteEmptyLine(); } string ExportStatusText = CSharpNames.ComposedExportStatus(IsOverride, false, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {resultType} {propertyName} {{ protected get; set; }}"); isMultiline = false; } }
/// <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); List <ICSharpVariableContext> DestinationNameList = new List <ICSharpVariableContext>(); IDictionary <string, ICSharpQualifiedName> DestinationTable = new Dictionary <string, ICSharpQualifiedName>(); foreach (ICSharpQualifiedName Destination in DestinationList) { ICSharpVariableContext DestinationContext; if (Destination.IsSimple) { string DestinationName = CSharpNames.ToCSharpIdentifier(Destination.SimpleName); if (writer.AttachmentMap.ContainsKey(DestinationName)) { DestinationName = writer.AttachmentMap[DestinationName]; } DestinationContext = new CSharpVariableContext(DestinationName); } else { string DestinationName = writer.GetTemporaryName(); DestinationContext = new CSharpVariableContext(DestinationName, isDeclared: false); DestinationTable.Add(DestinationName, Destination); } DestinationNameList.Add(DestinationContext); } ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext(DestinationNameList); SourceExpression.WriteCSharp(writer, ExpressionContext, -1); IDictionary <string, string> FilledDestinationTable = ExpressionContext.FilledDestinationTable; for (int i = 0; i < DestinationList.Count; i++) { ICSharpQualifiedName Destination = DestinationList[i]; string Name = DestinationNameList[i].Name; Debug.Assert(FilledDestinationTable.ContainsKey(Name)); string ResultText = FilledDestinationTable[Name]; if (ResultText == null) { ResultText = ExpressionContext.ReturnValue; } if (Destination.IsAttributeWithContract) { string SetterText = Destination.CSharpSetter(writer); writer.WriteIndentedLine($"{SetterText}({ResultText});"); } else if (DestinationTable.ContainsKey(Name)) { string DestinationName = DestinationTable[Name].CSharpText(writer, 0); writer.WriteIndentedLine($"{DestinationName} = {ResultText};"); } else if (ResultText != Name) { writer.WriteIndentedLine($"{Name} = {ResultText};"); } } }
private void WriteCSharpForcedReadWriteProperty(ICSharpWriter writer, bool isOverride, CSharpExports exportStatus, string propertyName, string resultType, ref bool isFirstFeature, ref bool isMultiline) { bool IsDeferred = false; bool IsPrecursor = false; isFirstFeature = false; if (GetterBody != null) { if (GetterBody is ICSharpDeferredBody) { IsDeferred = true; } if (GetterBody is ICSharpPrecursorBody) { IsPrecursor = true; } } if (SetterBody != null) { if (SetterBody is ICSharpDeferredBody) { IsDeferred = true; } if (SetterBody is ICSharpPrecursorBody) { IsPrecursor = true; } } if (GetterBody != null || SetterBody != null) { if (IsDeferred) { bool IsGetterMultiline = isMultiline; bool IsSetterMultiline = isMultiline; if (GetterBody != null) { ICSharpDeferredBody DeferredGetterBody = GetterBody as ICSharpDeferredBody; Debug.Assert(DeferredGetterBody != null); CSharpAssertion.WriteContract(writer, DeferredGetterBody.RequireList, DeferredGetterBody.EnsureList, CSharpContractLocations.Getter, false, ref isFirstFeature, ref IsGetterMultiline); IsSetterMultiline = false; } if (SetterBody != null) { ICSharpDeferredBody DeferredSetterBody = SetterBody as ICSharpDeferredBody; Debug.Assert(DeferredSetterBody != null); CSharpAssertion.WriteContract(writer, DeferredSetterBody.RequireList, DeferredSetterBody.EnsureList, CSharpContractLocations.Setter, false, ref isFirstFeature, ref IsSetterMultiline); } string ExportStatusText = CSharpNames.ComposedExportStatus(false, true, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {resultType} {propertyName} {{ get; set; }}"); isMultiline = IsGetterMultiline || IsSetterMultiline; } else { if (isMultiline) { writer.WriteEmptyLine(); } string ExportStatusText = CSharpNames.ComposedExportStatus(IsOverride, false, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {resultType} {propertyName}"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); if (IsPrecursor) { if (Source.PropertyKind != BaseNode.UtilityType.WriteOnly) { writer.WriteIndentedLine($"get {{ return base.{propertyName}; }}"); } else { writer.WriteIndentedLine($"get {{ throw new InvalidOperationException(); }}"); } if (Source.PropertyKind != BaseNode.UtilityType.ReadOnly) { writer.WriteIndentedLine($"set {{ base.{propertyName} = value; }}"); } else { writer.WriteIndentedLine($"set {{ throw new InvalidOperationException(); }}"); } } else { if (GetterBody != null) { ICSharpEffectiveBody EffectiveGetterBody = GetterBody as ICSharpEffectiveBody; Debug.Assert(EffectiveGetterBody != null); isMultiline = false; CSharpAssertion.WriteContract(writer, EffectiveGetterBody.RequireList, EffectiveGetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); writer.WriteIndentedLine("get"); EffectiveGetterBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets | CSharpBodyFlags.HasResult, resultType, false, new List <string>()); } else { writer.WriteIndentedLine($"get {{ throw new InvalidOperationException(); }}"); } if (SetterBody != null) { ICSharpEffectiveBody EffectiveSetterBody = SetterBody as ICSharpEffectiveBody; Debug.Assert(EffectiveSetterBody != null); isMultiline = false; CSharpAssertion.WriteContract(writer, EffectiveSetterBody.RequireList, EffectiveSetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); writer.WriteIndentedLine("set"); EffectiveSetterBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets | CSharpBodyFlags.HasValue, string.Empty, false, new List <string>()); } else { writer.WriteIndentedLine($"set {{ throw new InvalidOperationException(); }}"); } } writer.DecreaseIndent(); writer.WriteIndentedLine("}"); isMultiline = true; } } else { if (isMultiline) { writer.WriteEmptyLine(); } string ExportStatusText = CSharpNames.ComposedExportStatus(IsOverride, false, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {resultType} {propertyName}"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); if (Source.PropertyKind != BaseNode.UtilityType.WriteOnly) { writer.WriteIndentedLine($"get {{ return _{propertyName}; }}"); } else { writer.WriteIndentedLine($"get {{ throw new InvalidOperationException(); }}"); } if (Source.PropertyKind != BaseNode.UtilityType.ReadOnly) { writer.WriteIndentedLine($"set {{ _{propertyName} = value; }}"); } else { writer.WriteIndentedLine($"set {{ throw new InvalidOperationException(); }}"); } writer.DecreaseIndent(); writer.WriteIndentedLine("}"); 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); expressionContext.SetSingleReturnValue(Source.ValidText.Item); }
public Transpiler(IParser parser, ICSharpWriter writer) { this.parser = parser; this.writer = writer; declaredVariables = new List <string>(); }