/// <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})");
            }
        }
Пример #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);

            CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, skippedIndex, false, out string ArgumentListText, out IList <string> OutgoingResultList);

            expressionContext.SetSingleReturnValue($"base[{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);

            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});");
        }
Пример #5
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);

            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}]");
        }
Пример #6
0
        /// <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);
            }
        }
Пример #8
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);
            }
        }
        /// <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});");
            }
        }
Пример #10
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);
                }
            }
        }
Пример #11
0
        /// <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);
        }