/// <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); }
/// <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); }
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); } }
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); }
/// <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> /// <param name="skippedIndex">Index of a destination to skip.</param> /// <param name="isAgentCall">True if the call is for an agent.</param> /// <param name="callText">The string to use for a call upon return.</param> /// <param name="outgoingResultList">The list of results.</param> public static void CSharpArgumentList(ICSharpWriter writer, ICSharpExpressionContext expressionContext, ICSharpFeatureCall featureCall, int skippedIndex, bool isAgentCall, out string callText, out IList <string> outgoingResultList) { /*if (featureCall.Count == 0 && expressionContext.DestinationNameList.Count == 0) * { * callText = string.Empty; * outgoingResultList = new List<string>(); * } * else*/ { callText = null; outgoingResultList = null; switch (featureCall.ArgumentStyle) { case TypeArgumentStyles.None: case TypeArgumentStyles.Positional: CSharpPositionalArgumentList(writer, expressionContext, featureCall, skippedIndex, isAgentCall, out callText, out outgoingResultList); break; case TypeArgumentStyles.Assignment: CSharpAssignmentArgumentList(writer, expressionContext, featureCall, skippedIndex, isAgentCall, out callText, out outgoingResultList); break; } Debug.Assert(callText != null); Debug.Assert(outgoingResultList != null); } }