コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        /// <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);
                }
            }
        }