コード例 #1
0
        private Number ComputeSide(ICSharpWriter writer, ICSharpExpression expression)
        {
            string ValueString;

            ICSharpExpressionAsConstant ExpressionAsConstant = expression as ICSharpExpressionAsConstant;

            Debug.Assert(ExpressionAsConstant != null);

            if (ExpressionAsConstant.IsDirectConstant)
            {
                ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();
                expression.WriteCSharp(writer, SourceExpressionContext, -1);

                ValueString = SourceExpressionContext.ReturnValue;
            }
            else
            {
                ICSharpComputableExpression ComputableExpression = ExpressionAsConstant as ICSharpComputableExpression;
                Debug.Assert(ComputableExpression != null);

                ComputableExpression.Compute(writer);
                ValueString = ComputableExpression.ComputedValue;
            }

            FormattedNumber Result = FormattedNumber.Parse(ValueString);

            return(Result.Value);
        }
コード例 #2
0
        private void WriteCSharpSwitch(ICSharpWriter writer)
        {
            ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext(EntityNameList);

            SourceExpression.WriteCSharp(writer, ExpressionContext, -1);

            Debug.Assert(ExpressionContext.FilledDestinationTable.Count == 1);
            string EntityName         = EntityNameList[0].Name;
            string LastExpressionText = ExpressionContext.FilledDestinationTable[EntityName];

            if (LastExpressionText == null)
            {
                LastExpressionText = ExpressionContext.ReturnValue;
            }

            writer.WriteIndentedLine($"switch ({LastExpressionText})");
            writer.WriteIndentedLine("{");
            writer.IncreaseIndent();

            for (int i = 0; i < AttachmentList.Count; i++)
            {
                ICSharpAttachment Attachment = AttachmentList[i];
                Attachment.WriteCSharpCase(writer, EntityName);
            }

            writer.DecreaseIndent();
            writer.WriteIndentedLine("}");
        }
コード例 #3
0
        /// <summary>
        /// Computes the constant value of a nested expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expression">The expression to compute.</param>
        protected static string ComputeNestedExpression(ICSharpWriter writer, ICSharpExpression expression)
        {
            string ValueString;

            ICSharpExpressionAsConstant ExpressionAsConstant = expression as ICSharpExpressionAsConstant;

            Debug.Assert(ExpressionAsConstant != null);

            if (ExpressionAsConstant.IsDirectConstant)
            {
                ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();
                expression.WriteCSharp(writer, SourceExpressionContext, -1);

                ValueString = SourceExpressionContext.ReturnValue;
            }
            else
            {
                ICSharpComputableExpression ComputableExpression = ExpressionAsConstant as ICSharpComputableExpression;
                Debug.Assert(ComputableExpression != null);

                ComputableExpression.Compute(writer);
                ValueString = ComputableExpression.ComputedValue;
            }

            return(ValueString);
        }
コード例 #4
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 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});");
            }
        }
コード例 #5
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();

            BooleanExpression.WriteCSharp(writer, SourceExpressionContext, -1);

            string ExpressionText = SourceExpressionContext.ReturnValue;

            if (BooleanExpression.IsEventExpression)
            {
                if (BooleanExpression.IsComplex)
                {
                    ExpressionText = $"({ExpressionText}).IsSignaled";
                }
                else
                {
                    ExpressionText += ".IsSignaled";
                }
            }

            writer.WriteIndentedLine($"Debug.Assert({ExpressionText});");
            writer.AddUsing("System.Diagnostics");
        }
コード例 #6
0
        private void ComputeConstant(ICSharpWriter writer)
        {
            string ValueString;

            ICSharpExpressionAsConstant ExpressionAsConstant = ConstantExpression as ICSharpExpressionAsConstant;

            Debug.Assert(ExpressionAsConstant != null);

            if (ExpressionAsConstant.IsDirectConstant)
            {
                ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();
                ConstantExpression.WriteCSharp(writer, SourceExpressionContext, -1);

                ValueString = SourceExpressionContext.ReturnValue;
            }
            else
            {
                ICSharpComputableExpression ComputableExpression = ExpressionAsConstant as ICSharpComputableExpression;
                Debug.Assert(ComputableExpression != null);

                ComputableExpression.Compute(writer);
                ValueString = ComputableExpression.ComputedValue;
            }

            ComputedValue = ValueString;
        }
コード例 #7
0
        private void WriteCSharpContinueCondition(ICSharpWriter writer, out string continueExpressionText)
        {
            ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext();

            ContinueCondition.WriteCSharp(writer, ExpressionContext, -1);

            if (ExpressionContext.CompleteDestinationNameList.Count > 1)
            {
                continueExpressionText = string.Empty;

                foreach (string DestinationName in ExpressionContext.CompleteDestinationNameList)
                {
                    if (continueExpressionText.Length > 0)
                    {
                        continueExpressionText += " && ";
                    }

                    continueExpressionText += DestinationName;
                }
            }
            else
            {
                Debug.Assert(ExpressionContext.ReturnValue != null);
                continueExpressionText = ExpressionContext.ReturnValue;
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #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);

            Debug.Assert(TypeList.Count > 0);

            string CloneMethod = Source.Type == BaseNode.CloneType.Shallow ? "CloneShallow" : "Clone";

            ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();

            SourceExpression.WriteCSharp(writer, SourceExpressionContext, -1);

            IList <string> ResultList       = new List <string>();
            int            ReturnValueIndex = SourceExpressionContext.ReturnValueIndex;
            string         ReturnValue      = SourceExpressionContext.ReturnValue;

            if (TypeList.Count == 1)
            {
                ICSharpType ClonedType     = TypeList[0];
                string      SourceTypeText = ClonedType.Type2CSharpString(writer, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None);

                string SourceText = SourceExpressionContext.ReturnValue;
                Debug.Assert(SourceText != null);

                expressionContext.SetSingleReturnValue($"({SourceTypeText})({SourceText}).{CloneMethod}()");
            }
            else
            {
                for (int i = 0; i < SourceExpressionContext.CompleteDestinationNameList.Count; i++)
                {
                    if (i == ReturnValueIndex)
                    {
                        Debug.Assert(ReturnValue != null);
                        ResultList.Add(ReturnValue);
                    }
                    else
                    {
                        ResultList.Add(SourceExpressionContext.CompleteDestinationNameList[i]);
                    }
                }

                Debug.Assert(TypeList.Count == ResultList.Count);

                IList <string> OutgoingResultList = new List <string>();

                for (int i = 0; i < TypeList.Count; i++)
                {
                    ICSharpType ClonedType     = TypeList[i];
                    string      SourceTypeText = ClonedType.Type2CSharpString(writer, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None);
                    string      SourceText     = ResultList[i];

                    OutgoingResultList.Add($"({SourceTypeText})({SourceText}).{CloneMethod}()");
                }

                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 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});");
        }
コード例 #12
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;

            writer.WriteIndentedLine($"switch ({SourceString})");
            writer.WriteIndentedLine("{");
            writer.IncreaseIndent();

            bool WithInserted = false;

            foreach (ICSharpWith Item in WithList)
            {
                if (!WithInserted)
                {
                    WithInserted = true;
                }
                else
                {
                    writer.WriteEmptyLine();
                }

                Item.WriteCSharp(writer);
            }

            if (WithInserted)
            {
                writer.WriteEmptyLine();
            }

            writer.WriteIndentedLine("default:");

            if (ElseInstructions != null)
            {
                ElseInstructions.WriteCSharp(writer, CSharpCurlyBracketsInsertions.Indifferent, false);
                writer.WriteIndentedLine("break;");
            }
            else
            {
                writer.IncreaseIndent();
                writer.WriteIndentedLine("throw new ArgumentOutOfRangeException();");
                writer.DecreaseIndent();
            }

            writer.DecreaseIndent();
            writer.WriteIndentedLine("}");
        }
コード例 #13
0
        private void WriteCSharpImplementation(ICSharpWriter writer, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline)
        {
            writer.WriteDocumentation(Source);

            string TypeString      = Type.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);
            string AttributeString = CSharpNames.ToCSharpIdentifier(Name);

            ICSharpExpressionAsConstant ExpressionAsConstant = ConstantExpression as ICSharpExpressionAsConstant;

            Debug.Assert(ExpressionAsConstant != null);

            string ValueString;

            if (ExpressionAsConstant.IsDirectConstant)
            {
                ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();
                ConstantExpression.WriteCSharp(writer, SourceExpressionContext, -1);

                ValueString = SourceExpressionContext.ReturnValue;
                Debug.Assert(ValueString != null);
            }
            else
            {
                ICSharpComputableExpression CompilableExpression = ConstantExpression as ICSharpComputableExpression;
                Debug.Assert(CompilableExpression != null);

                CompilableExpression.Compute(writer);
                ValueString = CompilableExpression.ComputedValue;
                Debug.Assert(ValueString != null);

                writer.WriteIndentedLine($"// {ValueString} = {ConstantExpression.Source.ExpressionToString}");
            }

            string ExportStatusText = CSharpNames.ComposedExportStatus(false, false, true, exportStatus);

            bool IsReadOnlyObject;

            if (Type is ICSharpClassType AsClassType)
            {
                Guid ClassGuid = AsClassType.Source.BaseClass.ClassGuid;
                IsReadOnlyObject = ClassGuid != LanguageClasses.Number.Guid && ClassGuid != LanguageClasses.Boolean.Guid && ClassGuid != LanguageClasses.String.Guid && ClassGuid != LanguageClasses.Character.Guid;
            }
            else
            {
                IsReadOnlyObject = true;
            }

            string ConstString = IsReadOnlyObject ? "static readonly" : "const";

            writer.WriteIndentedLine($"{ExportStatusText} {ConstString} {TypeString} {AttributeString} = {ValueString};");
        }
コード例 #14
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 DestinationString = Source.Destination.ToString();

            ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();

            SourceExpression.WriteCSharp(writer, SourceExpressionContext, -1);

            string SourceString = SourceExpressionContext.ReturnValue;

            writer.WriteIndentedLine($"{DestinationString} = {SourceString};");
        }
コード例 #15
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}]");
        }
コード例 #16
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};");
        }
コード例 #17
0
        /// <summary>
        /// Gets the return value of an expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expression">The expression.</param>
        public static string SingleResultExpressionText(ICSharpWriter writer, ICSharpExpression expression)
        {
            ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();

            expression.WriteCSharp(writer, SourceExpressionContext, -1);

            Debug.Assert(SourceExpressionContext.ReturnValue != null);
            string Result = SourceExpressionContext.ReturnValue;

            if (expression.IsComplex)
            {
                Result = $"({Result})";
            }

            return(Result);
        }
コード例 #18
0
        /// <summary>
        /// Writes down the C# assertion.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        public virtual void WriteCSharp(ICSharpWriter writer)
        {
            Debug.Assert(WriteDown);

            ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();

            BooleanExpression.WriteCSharp(writer, SourceExpressionContext, -1);

            string AssertionString = SourceExpressionContext.ReturnValue;

            Debug.Assert(AssertionString != null);

            string TagString = string.IsNullOrEmpty(Tag) ? string.Empty : $" // {Tag}";

            writer.WriteIndentedLine($"Debug.Assert({AssertionString});{TagString}");

            writer.AddUsing("System.Diagnostics");
        }
コード例 #19
0
        private void WriteCSharpIf(ICSharpWriter writer)
        {
            ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext();

            SourceExpression.WriteCSharp(writer, ExpressionContext, -1);

            for (int i = 0; i < AttachmentList.Count; i++)
            {
                ICSharpAttachment Attachment = AttachmentList[i];
                Attachment.WriteCSharpIf(writer, i, EntityNameList, ExpressionContext);
            }

            if (ElseInstructions != null)
            {
                writer.WriteIndentedLine("else");
                ElseInstructions.WriteCSharp(writer, CSharpCurlyBracketsInsertions.Mandatory, false);
            }
        }
コード例 #20
0
        /// <summary>
        /// Writes down the C# conditional instructions.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="isElseIf">True if the conditional is not the first.</param>
        public virtual void WriteCSharp(ICSharpWriter writer, bool isElseIf)
        {
            Debug.Assert(WriteDown);

            ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext();

            BooleanExpression.WriteCSharp(writer, ExpressionContext, -1);

            string ExpressionString = ExpressionContext.ReturnValue;

            Debug.Assert(ExpressionString != null);

            if (BooleanExpression.IsEventExpression)
            {
                if (BooleanExpression.IsComplex)
                {
                    ExpressionString = $"({ExpressionString}).IsSignaled";
                }
                else
                {
                    ExpressionString += ".IsSignaled";
                }
            }

            string Condition;

            if (isElseIf)
            {
                Condition = "else if";
            }
            else
            {
                Condition = "if";
            }

            Condition += $" ({ExpressionString})";
            writer.WriteIndentedLine(Condition);

            Instructions.WriteCSharp(writer, CSharpCurlyBracketsInsertions.Mandatory, false);
        }
コード例 #21
0
        /// <summary>
        /// Writes down the C# feature.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        public void WriteCSharp(ICSharpWriter writer)
        {
            Debug.Assert(WriteDown);

            string NameString       = CSharpNames.ToCSharpIdentifier(Name);
            string TypeString       = Type.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);
            string DefaultValueText = string.Empty;

            if (DefaultValue != null)
            {
                ICSharpExpressionContext ExpressionContext = new CSharpExpressionContext();
                DefaultValue.WriteCSharp(writer, ExpressionContext, -1);

                DefaultValueText = ExpressionContext.ReturnValue;

                if (DefaultValue.IsComplex)
                {
                    DefaultValueText = $"({DefaultValueText})";
                }
            }

            if (DefaultValueText.Length == 0)
            {
                if (Type.GetSingletonString(writer, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None, out string SingletonString))
                {
                    DefaultValueText = SingletonString;
                }
            }

            if (DefaultValueText.Length == 0)
            {
                DefaultValueText = "default";
            }

            DefaultValueText = $" = {DefaultValueText}";

            writer.WriteIndentedLine($"{TypeString} {NameString}{DefaultValueText};");
        }
コード例 #22
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);
            }
        }
コード例 #23
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);

            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("}");
            }
        }
コード例 #24
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();

            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
        }
コード例 #25
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 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});");
            }
        }
コード例 #26
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);

            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};");
                }
            }
        }
コード例 #27
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);
        }
コード例 #28
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 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}");
        }