コード例 #1
0
        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})");
            }
        }
コード例 #2
0
        private void WriteCSharpInterface(ICSharpWriter writer, CSharpFeatureTextTypes featureTextType, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline)
        {
            string ResultType   = EntityType.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);
            string PropertyName = CSharpNames.ToCSharpIdentifier(Name);
            string Accessors    = null;

            if (IsForcedReadWrite)
            {
                Accessors = "{ get; set; }";
            }
            else
            {
                switch (Source.PropertyKind)
                {
                case BaseNode.UtilityType.ReadOnly:
                    Accessors = "{ get; }";
                    break;

                case BaseNode.UtilityType.WriteOnly:
                    Accessors = "{ set; }";
                    break;

                case BaseNode.UtilityType.ReadWrite:
                    Accessors = "{ get; set; }";
                    break;
                }
            }

            Debug.Assert(Accessors != null);

            writer.WriteIndentedLine($"{ResultType} {PropertyName} {Accessors}");

            isMultiline = false;
        }
コード例 #3
0
        private void WriteCSharpImplementationEffective(ICSharpWriter writer, ICSharpEffectiveBody effectiveBody, bool isOverride, string nameString, CSharpExports exportStatus, bool isConstructor, ref bool isFirstFeature, ref bool isMultiline)
        {
            CSharpArgument.BuildParameterList(writer, ParameterList, out string ParameterEntityList, out string ParameterNameList);

            CSharpAssertion.WriteContract(writer, effectiveBody.RequireList, effectiveBody.EnsureList, CSharpContractLocations.Other, true, ref isFirstFeature, ref isMultiline);

            bool SkipFirstInstruction = false;

            if (isConstructor)
            {
                WriteCSharpImplementationConstructor(writer, isOverride, nameString, exportStatus, ref isFirstFeature, ref isMultiline, ref SkipFirstInstruction);
            }
            else
            {
                string ExportStatusText = CSharpNames.ComposedExportStatus(isOverride, false, false, exportStatus);

                writer.WriteIndentedLine($"{ExportStatusText} void {nameString}({ParameterEntityList})");
            }

            ICSharpEffectiveBody AsEffectiveBody = Body as ICSharpEffectiveBody;

            AsEffectiveBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets, string.Empty, SkipFirstInstruction, new List <string>());

            isMultiline = true;
        }
コード例 #4
0
        /// <summary>
        /// Builds a list of parameters, with and without their type.
        /// </summary>
        /// <param name="usingCollection">The collection of using directives.</param>
        /// <param name="parameterList">The list of parameters.</param>
        /// <param name="parameterListText">The list of parameters with type upon return.</param>
        /// <param name="parameterNameListText">The list of parameters without type upon return.</param>
        public static void BuildParameterList(ICSharpUsingCollection usingCollection, IList <ICSharpParameter> parameterList, out string parameterListText, out string parameterNameListText)
        {
            parameterListText     = string.Empty;
            parameterNameListText = string.Empty;

            foreach (ICSharpParameter Parameter in parameterList)
            {
                if (parameterListText.Length > 0)
                {
                    parameterListText += ", ";
                }
                if (parameterNameListText.Length > 0)
                {
                    parameterNameListText += ", ";
                }

                string      ParameterName = Parameter.Name;
                ICSharpType ParameterType = Parameter.Feature.Type;

                CSharpTypeFormats ParameterFormat = ParameterType.HasInterfaceText ? CSharpTypeFormats.AsInterface : CSharpTypeFormats.Normal;

                string ParameterText     = ParameterType.Type2CSharpString(usingCollection, ParameterFormat, CSharpNamespaceFormats.None);
                string ParameterNameText = CSharpNames.ToCSharpIdentifier(ParameterName);

                parameterListText     += $"{ParameterText} {ParameterNameText}";
                parameterNameListText += ParameterNameText;
            }
        }
コード例 #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>
        public void WriteCSharpAsConstant(ICSharpWriter writer, ICSharpExpressionContext expressionContext)
        {
            Debug.Assert(WriteDown);
            Debug.Assert(Class.Source.InitializedObjectList.Contains(Source));

            string ClassNameText = CSharpNames.ToCSharpIdentifier(Class.ValidClassName);

            string AssignmentText = string.Empty;

            foreach (ICSharpAssignmentArgument Assignment in AssignmentList)
            {
                ICSharpExpression SourceExpression = Assignment.SourceExpression;
                string            ExpressionText   = SingleResultExpressionText(writer, SourceExpression);

                foreach (string AssignedField in Assignment.ParameterNameList)
                {
                    if (AssignmentText.Length > 0)
                    {
                        AssignmentText += ", ";
                    }

                    string AssignedFieldText = CSharpNames.ToCSharpIdentifier(AssignedField);
                    AssignmentText += $"{AssignedFieldText} = {ExpressionText}";
                }
            }

            expressionContext.SetSingleReturnValue($"new {ClassNameText}() {{ {AssignmentText} }}");
        }
コード例 #6
0
        private static void BuildResultListNoResult(ICSharpUsingCollection usingCollection, IList <ICSharpParameter> resultList, ref string parameterListText, ref string parameterNameListText, out string resultTypeText)
        {
            resultTypeText = "void";

            foreach (ICSharpParameter Result in resultList)
            {
                ICSharpScopeAttributeFeature ResultAttribute = Result.Feature;
                ICSharpType       ParameterType   = ResultAttribute.Type;
                CSharpTypeFormats ParameterFormat = ParameterType.HasInterfaceText ? CSharpTypeFormats.AsInterface : CSharpTypeFormats.Normal;

                string TypeString      = ParameterType.Type2CSharpString(usingCollection, ParameterFormat, CSharpNamespaceFormats.None);
                string AttributeString = CSharpNames.ToCSharpIdentifier(Result.Name);

                if (parameterListText.Length > 0)
                {
                    parameterListText += ", ";
                }
                if (parameterNameListText.Length > 0)
                {
                    parameterNameListText += ", ";
                }

                parameterListText     += $"out {TypeString} {AttributeString}";
                parameterNameListText += $"out {AttributeString}";
            }
        }
コード例 #7
0
        /// <summary>
        /// Get the name of a type.
        /// </summary>
        /// <param name="usingCollection">The collection of using directives.</param>
        /// <param name="cSharpTypeFormat">The type format.</param>
        /// <param name="cSharpNamespaceFormat">The namespace format.</param>
        public override string Type2CSharpString(ICSharpUsingCollection usingCollection, CSharpTypeFormats cSharpTypeFormat, CSharpNamespaceFormats cSharpNamespaceFormat)
        {
            SetUsedInCode();

            string Result;

            if (OriginatingTypedef != null)
            {
                // TODO
                string DelegateName = CSharpNames.ToCSharpIdentifier(OriginatingTypedef.Name);

                Result = PropertyType2CSharpString(DelegateName);
            }
            else
            {
                string BaseTypeText   = BaseType.Type2CSharpString(usingCollection, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);
                string EntityTypeText = EntityType.Type2CSharpString(usingCollection, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);

                Result = $"Func<{BaseTypeText}, {EntityTypeText}>";

                usingCollection.AddUsing(nameof(System));
            }

            return(Result);
        }
コード例 #8
0
        /// <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)
        {
            if (!WriteDown)
            {
                return;
            }

            writer.WriteDocumentation(Source);

            bool ClassHasSingleConstructor = isLocal && Owner.ClassConstructorType == CSharpConstructorTypes.OneConstructor;

            string NameString;

            if (ClassHasSingleConstructor)
            {
                NameString = Owner.BasicClassName2CSharpClassName(writer, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None);
            }
            else
            {
                NameString = CSharpNames.ToCSharpIdentifier(Name);
            }

            foreach (ICSharpCommandOverload Overload in OverloadList)
            {
                Overload.WriteCSharp(writer, featureTextType, IsOverride, NameString, exportStatus, ClassHasSingleConstructor, ref isFirstFeature, ref isMultiline);
            }
        }
コード例 #9
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});");
            }
        }
コード例 #10
0
        /// <summary>
        /// Gets a temporary name from a source name.
        /// </summary>
        /// <param name="sourceName">The source name.</param>
        public string GetTemporaryName(string sourceName)
        {
            string CSharpIdentifier = CSharpNames.ToCSharpIdentifier(sourceName);
            string TemporaryName    = $"temp_{TemporaryVariableIndex}_{CSharpIdentifier}";

            TemporaryVariableIndex++;

            return(TemporaryName);
        }
コード例 #11
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(Class.Source.InitializedObjectList.Contains(Source));

            string ClassNameText = CSharpNames.ToCSharpIdentifier(Class.ValidClassName);
            int    Index         = Class.Source.InitializedObjectList.IndexOf(Source);

            expressionContext.SetSingleReturnValue($"{ClassNameText}.InitializedObject{Index}");
        }
コード例 #12
0
        /// <summary>
        /// Builds a list of parameters, with and without their type.
        /// </summary>
        /// <param name="usingCollection">The collection of using directives.</param>
        /// <param name="parameterList">The list of parameters.</param>
        /// <param name="resultList">The list of results.</param>
        /// <param name="featureTextType">The write mode.</param>
        /// <param name="parameterListText">The list of parameters with type upon return.</param>
        /// <param name="parameterNameListText">The list of parameters without type upon return.</param>
        /// <param name="resultTypeText">The type text upon return.</param>
        public static void BuildParameterList(ICSharpUsingCollection usingCollection, IList <ICSharpParameter> parameterList, IList <ICSharpParameter> resultList, CSharpFeatureTextTypes featureTextType, out string parameterListText, out string parameterNameListText, out string resultTypeText)
        {
            parameterListText     = string.Empty;
            parameterNameListText = string.Empty;

            foreach (ICSharpParameter Parameter in parameterList)
            {
                if (parameterListText.Length > 0)
                {
                    parameterListText += ", ";
                }
                if (parameterNameListText.Length > 0)
                {
                    parameterNameListText += ", ";
                }

                string      ParameterName = Parameter.Name;
                ICSharpType ParameterType = Parameter.Feature.Type;

                CSharpTypeFormats ParameterFormat = ParameterType.HasInterfaceText ? CSharpTypeFormats.AsInterface : CSharpTypeFormats.Normal;

                string ParameterText     = ParameterType.Type2CSharpString(usingCollection, ParameterFormat, CSharpNamespaceFormats.None);
                string ParameterNameText = CSharpNames.ToCSharpIdentifier(ParameterName);

                parameterListText     += $"{ParameterText} {ParameterNameText}";
                parameterNameListText += ParameterNameText;
            }

            if (resultList.Count == 1)
            {
                BuildResultListSingle(usingCollection, resultList, out resultTypeText);
            }
            else
            {
                int ResultIndex = -1;
                for (int i = 0; i < resultList.Count; i++)
                {
                    ICSharpParameter Result = resultList[i];
                    if (Result.Name == nameof(BaseNode.Keyword.Result))
                    {
                        ResultIndex = i;
                        break;
                    }
                }

                if (ResultIndex < 0)
                {
                    BuildResultListNoResult(usingCollection, resultList, ref parameterListText, ref parameterNameListText, out resultTypeText);
                }
                else
                {
                    BuildResultListWithResult(usingCollection, resultList, ResultIndex, ref parameterListText, ref parameterNameListText, out resultTypeText);
                }
            }
        }
コード例 #13
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);

            // TODO: declare the event

            IIdentifier QueryIdentifierItem       = (IIdentifier)Source.QueryIdentifier;
            string      QueryIdentifierItemString = CSharpNames.ToCSharpIdentifier(QueryIdentifierItem.ValidText.Item);

            writer.WriteIndentedLine($"{QueryIdentifierItemString}.set();");
        }
コード例 #14
0
        private void WriteCSharpImplementationDeferred(ICSharpWriter writer, ICSharpDeferredBody deferredBody, bool isOverride, string nameString, CSharpExports exportStatus, bool isConstructor, ref bool isFirstFeature, ref bool isMultiline)
        {
            CSharpArgument.BuildParameterList(writer, ParameterList, out string ParameterEntityList, out string ParameterNameList);

            CSharpAssertion.WriteContract(writer, deferredBody.RequireList, deferredBody.EnsureList, CSharpContractLocations.Other, true, ref isFirstFeature, ref isMultiline);

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

            writer.WriteIndentedLine($"{ExportStatusText} void {nameString}({ParameterEntityList});");

            isMultiline = false;
        }
コード例 #15
0
        private void WriteCSharpImplementation(ICSharpWriter writer, CSharpExports exportStatus, ref bool isFirstFeature, ref bool isMultiline)
        {
            bool IsEvent = false;

            if (Type is ICSharpClassType AsClassType)
            {
                ICSharpClass Class = AsClassType.Class;
                if (Class.InheritFromDotNetEvent)
                {
                    IsEvent = true;
                }
            }

            writer.WriteDocumentation(Source);

            CSharpAssertion.WriteContract(writer, new List <ICSharpAssertion>(), EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline);

            string TypeString      = Type.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);
            string AttributeString = CSharpNames.ToCSharpIdentifier(Name);
            string ExportString    = CSharpNames.ComposedExportStatus(false, false, true, exportStatus);

            if (IsEvent)
            {
                writer.WriteIndentedLine($"{ExportString} event {TypeString} {AttributeString};");
            }
            else if (Type.GetSingletonString(writer, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None, out string SingletonString))
            {
                writer.WriteIndentedLine($"{ExportString} {TypeString} {AttributeString} {{ get {{ return {SingletonString}; }} }}");
            }
            else if (EnsureList.Count > 0)
            {
                writer.WriteIndentedLine($"{ExportString} {TypeString} {AttributeString} {{ get; private set; }}");
                writer.WriteIndentedLine($"protected void Set_{AttributeString}({TypeString} value)");
                writer.WriteIndentedLine("{");
                writer.IncreaseIndent();

                writer.WriteIndentedLine($"{AttributeString} = value;");

                writer.WriteEmptyLine();
                foreach (ICSharpAssertion Assertion in EnsureList)
                {
                    Assertion.WriteCSharp(writer);
                }

                writer.DecreaseIndent();
                writer.WriteIndentedLine("}");
            }
            else
            {
                writer.WriteIndentedLine($"{ExportString} {TypeString} {AttributeString} {{ get; protected set; }}");
            }
        }
コード例 #16
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};");
        }
コード例 #17
0
        /// <summary>
        /// Gets the source code corresponding to the qualified name.
        /// </summary>
        /// <param name="usingCollection">The collection of using directives.</param>
        /// <param name="skippedAtEnd">Number of identifiers to skip at the end.</param>
        public string CSharpText(ICSharpUsingCollection usingCollection, int skippedAtEnd)
        {
            string Result;
            int    i = 0;

            /*
             * if (Context.AttachmentAliasTable.ContainsKey(ValidPath.Item[i].ValidText.Item))
             * {
             *  Result = Context.AttachmentAliasTable[ValidPath.Item[i].ValidText.Item];
             *  i++;
             * }
             * else*/
            Result = string.Empty;

            for (; i + skippedAtEnd < Source.ValidPath.Item.Count; i++)
            {
                if (Result.Length > 0)
                {
                    Result += ".";
                }

                IIdentifier  Item      = Source.ValidPath.Item[i];
                ICSharpClass ItemClass = i < ClassPath.Count ? ClassPath[i] : null;
                string       ItemText  = Item.ValidText.Item;

                if (i == 0 && usingCollection.AttachmentMap.ContainsKey(Item.ValidText.Item))
                {
                    ItemText = usingCollection.AttachmentMap[ItemText];
                }
                else
                {
                    ItemText = CSharpNames.ToCSharpIdentifier(ItemText);
                }

                if (ItemClass != null)
                {
                    if (ItemClass.IsUnparameterizedSingleton && ItemClass.ValidSourceName != "Microsoft .NET")
                    {
                        string TypeText = ItemClass.Type.Type2CSharpString(usingCollection, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None);
                        ItemText = $"{TypeText}.Singleton";
                    }
                }

                Result += ItemText;
            }

            return(Result);
        }
コード例 #18
0
        /// <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)
        {
            if (!WriteDown)
            {
                return;
            }

            writer.WriteDocumentation(Source);

            string NameString = CSharpNames.ToCSharpIdentifier(Name);

            foreach (ICSharpCommandOverload Overload in OverloadList)
            {
                Overload.WriteCSharp(writer, featureTextType, IsOverride, NameString, exportStatus, false, ref isFirstFeature, ref isMultiline);
            }
        }
コード例 #19
0
        private string CSharpTextProperty(ICSharpUsingCollection usingCollection, ICSharpPropertyFeature feature)
        {
            string Result;

            string BaseTypeText;

            if (BaseType != null)
            {
                BaseTypeText = EffectiveBaseType.Type2CSharpString(usingCollection, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.OneWord);
            }
            else
            {
                BaseTypeText = $"I{CSharpNames.ToCSharpIdentifier(Delegated.Owner.ValidClassName)}";
            }

            Result = $"({BaseTypeText} agentBase) => {{ return agentBase.{CSharpNames.ToCSharpIdentifier(Delegated.Name)}; }}";

            return(Result);
        }
コード例 #20
0
        private void WriteCSharpImplementationConstructor(ICSharpWriter writer, bool isOverride, string nameString, CSharpExports exportStatus, ref bool isFirstFeature, ref bool isMultiline, ref bool skipFirstInstruction)
        {
            CSharpArgument.BuildParameterList(writer, ParameterList, out string ParameterEntityList, out string ParameterNameList);

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

            writer.WriteIndentedLine($"{ExportStatusText} {nameString}({ParameterEntityList})");

            ICSharpEffectiveBody AsEffectiveBody = Body as ICSharpEffectiveBody;
            ICSharpClass         Owner           = ParentFeature.Owner;

            if (Owner.BaseClass != null)
            {
                ICSharpClass ParentClass = Owner.BaseClass;
                if (ParentClass.ClassConstructorType == CSharpConstructorTypes.OneConstructor)
                {
                    if (AsEffectiveBody.BodyInstructionList.Count > 0)
                    {
                        /*TODO
                         * ICommandInstruction AsCommandInstruction;
                         * if ((AsCommandInstruction = AsEffectiveBody.BodyInstructionList[0] as ICommandInstruction) != null)
                         * {
                         *  if (AsCommandInstruction.SelectedFeature.IsAssigned)
                         *  {
                         *      ICreationFeature AsCreationFeature;
                         *      if ((AsCreationFeature = AsCommandInstruction.SelectedFeature.Item as ICreationFeature) != null)
                         *      {
                         *          ICommandOverloadType SelectedOverload = AsCommandInstruction.SelectedOverload.Item;
                         *          ISealableList<Parameter> SelectedParameterList = SelectedOverload.ParameterTable;
                         *          string ArgumentListString = CSharpRootOutput.CSharpArgumentList(Context, SelectedParameterList, AsCommandInstruction.ArgumentList, new List<IQualifiedName>());
                         *
                         *          SkipFirstInstruction = true;
                         *          CSharpRootOutput.IncreaseIndent();
                         *          writer.WriteIndentedLine(":" + " " + "base" + "(" + ArgumentListString + ")");
                         *          CSharpRootOutput.DecreaseIndent();
                         *      }
                         *  }
                         * }
                         */
                    }
                }
            }
        }
コード例 #21
0
        private void WriteCSharpImplementation(ICSharpWriter writer, CSharpFeatureTextTypes featureTextType, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline)
        {
            writer.WriteDocumentation(Source);

            string ResultType   = EntityType.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);
            string PropertyName = CSharpNames.ToCSharpIdentifier(Name);
            bool   IsHandled    = false;

            if (IsForcedReadWrite)
            {
                WriteCSharpForcedReadWriteProperty(writer, IsOverride, exportStatus, PropertyName, ResultType, ref isFirstFeature, ref isMultiline);
                IsHandled = true;
            }
            else
            {
                switch (Source.PropertyKind)
                {
                case BaseNode.UtilityType.ReadOnly:
                    WriteCSharpReadOnlyProperty(writer, IsOverride, exportStatus, PropertyName, ResultType, ref isFirstFeature, ref isMultiline);
                    IsHandled = true;
                    break;

                case BaseNode.UtilityType.WriteOnly:
                    WriteCSharpWriteOnlyProperty(writer, IsOverride, exportStatus, PropertyName, ResultType, ref isFirstFeature, ref isMultiline);
                    IsHandled = true;
                    break;

                case BaseNode.UtilityType.ReadWrite:
                    WriteCSharpReadWriteProperty(writer, IsOverride, exportStatus, PropertyName, ResultType, ref isFirstFeature, ref isMultiline);
                    IsHandled = true;
                    break;
                }
            }

            Debug.Assert(IsHandled);

            if (HasSideBySideAttribute && !Instance.InheritBySideAttribute)
            {
                writer.WriteIndentedLine($"protected {ResultType} _{PropertyName};");

                isMultiline = true;
            }
        }
コード例 #22
0
        /// <summary>
        /// Gets the source code corresponding to the qualified name setter.
        /// </summary>
        /// <param name="usingCollection">The collection of using directives.</param>
        public string CSharpSetter(ICSharpUsingCollection usingCollection)
        {
            string StartText;

            if (Source.ValidPath.Item.Count > 1)
            {
                StartText  = CSharpText(usingCollection, 1);
                StartText += ".";
            }
            else
            {
                StartText = string.Empty;
            }

            IIdentifier Item       = Source.ValidPath.Item[0];
            string      ItemText   = CSharpNames.ToCSharpIdentifier(Item.ValidText.Item);
            string      SetterText = $"{StartText}Set_{ItemText}";

            return(SetterText);
        }
コード例 #23
0
        private void WriteCSharpImplementationPrecursor(ICSharpWriter writer, ICSharpPrecursorBody precursorBody, bool isOverride, string nameString, CSharpExports exportStatus, bool isConstructor, ref bool isFirstFeature, ref bool isMultiline)
        {
            CSharpArgument.BuildParameterList(writer, ParameterList, out string ParameterEntityList, out string ParameterNameList);

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

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

            writer.WriteIndentedLine($"{ExportStatusText} void {nameString}({ParameterEntityList})");
            writer.WriteIndentedLine("{");
            writer.IncreaseIndent();
            writer.WriteIndentedLine($"base.{nameString}({ParameterNameList});");
            writer.DecreaseIndent();
            writer.WriteIndentedLine("}");

            isMultiline = true;
        }
コード例 #24
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 TypeText;
            string ClassName;
            string ConstantName;

            if (Feature != null)
            {
                TypeText = string.Empty;

                if (Class.ValidSourceName == "Microsoft .NET")
                {
                    ClassName    = CSharpNames.ToDotNetIdentifier(Class.ValidClassName);
                    ConstantName = CSharpNames.ToDotNetIdentifier(Feature.Name);
                }
                else
                {
                    ClassName    = CSharpNames.ToCSharpIdentifier(Class.ValidClassName);
                    ConstantName = CSharpNames.ToCSharpIdentifier(Feature.Name);
                }
            }
            else
            {
                TypeText = "(int)";

                if (Class.HasDiscreteWithUnkownValue)
                {
                    ClassName = CSharpNames.ToCSharpIdentifier(Class.ValidClassName) + "_Enum";
                }
                else
                {
                    ClassName = CSharpNames.ToCSharpIdentifier(Class.ValidClassName);
                }

                ConstantName = CSharpNames.ToCSharpIdentifier(Discrete.Name);
            }

            expressionContext.SetSingleReturnValue($"{TypeText}{ClassName}.{ConstantName}");
        }
コード例 #25
0
        private string CSharpTextFunction(ICSharpUsingCollection usingCollection, ICSharpFunctionFeature feature)
        {
            string Result;

            // TODO handle several overloads.

            Debug.Assert(feature.OverloadList.Count > 0);
            ICSharpQueryOverload Overload = feature.OverloadList[0] as ICSharpQueryOverload;

            Debug.Assert(Overload != null);

            string BaseTypeText;

            if (BaseType != null)
            {
                BaseTypeText = EffectiveBaseType.Type2CSharpString(usingCollection, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.OneWord);
            }
            else
            {
                BaseTypeText = $"I{CSharpNames.ToCSharpIdentifier(Delegated.Owner.ValidClassName)}";
            }

            string AgentParameters;
            string ParameterNameListText;

            if (Overload.ParameterList.Count > 0)
            {
                CSharpArgument.BuildParameterList(usingCollection, Overload.ParameterList, out string ParameterListText, out ParameterNameListText);
                AgentParameters = $"({BaseTypeText} agentBase, {ParameterListText})";
            }
            else
            {
                AgentParameters       = $"({BaseTypeText} agentBase)";
                ParameterNameListText = string.Empty;
            }

            Result = $"{AgentParameters} => {{ return agentBase.{CSharpNames.ToCSharpIdentifier(Delegated.Name)}({ParameterNameListText}); }}";

            return(Result);
        }
コード例 #26
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};");
        }
コード例 #27
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);
            }
        }
コード例 #28
0
        /// <summary>
        /// Get the name of a type.
        /// </summary>
        /// <param name="usingCollection">The collection of using directives.</param>
        /// <param name="cSharpTypeFormat">The type format.</param>
        /// <param name="cSharpNamespaceFormat">The namespace format.</param>
        public override string Type2CSharpString(ICSharpUsingCollection usingCollection, CSharpTypeFormats cSharpTypeFormat, CSharpNamespaceFormats cSharpNamespaceFormat)
        {
            SetUsedInCode();

            string Result;

            // TODO: detect delegate call parameters to select the proper overload

            if (OriginatingTypedef != null)
            {
                string DelegateName = CSharpNames.ToCSharpIdentifier(OriginatingTypedef.Name);

                Result = CommandOverloadType2CSharpString(DelegateName, Source.OverloadList[0]);
            }
            else
            {
                ICSharpCommandOverloadType OverloadType = OverloadTypeList[0];

                string ActionArgumentText = BaseType.Type2CSharpString(usingCollection, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);

                foreach (ICSharpParameter Parameter in OverloadType.ParameterList)
                {
                    ICSharpType       ParameterType   = Parameter.Feature.Type;
                    CSharpTypeFormats ParameterFormat = ParameterType.HasInterfaceText ? CSharpTypeFormats.AsInterface : CSharpTypeFormats.Normal;
                    string            ParameterText   = ParameterType.Type2CSharpString(usingCollection, ParameterFormat, CSharpNamespaceFormats.None);

                    ActionArgumentText += $", {ParameterText}";
                }

                Result = $"Action<{ActionArgumentText}>";

                usingCollection.AddUsing(nameof(System));
            }

            return(Result);
        }
コード例 #29
0
        private static void BuildResultListWithResult(ICSharpUsingCollection usingCollection, IList <ICSharpParameter> resultList, int resultIndex, ref string parameterListText, ref string parameterNameListText, out string resultTypeText)
        {
            resultTypeText = null;

            for (int i = 0; i < resultList.Count; i++)
            {
                ICSharpParameter             Result          = resultList[i];
                ICSharpScopeAttributeFeature ResultAttribute = Result.Feature;
                ICSharpType       ParameterType   = ResultAttribute.Type;
                CSharpTypeFormats ParameterFormat = ParameterType.HasInterfaceText ? CSharpTypeFormats.AsInterface : CSharpTypeFormats.Normal;

                string TypeString      = ParameterType.Type2CSharpString(usingCollection, ParameterFormat, CSharpNamespaceFormats.None);
                string AttributeString = CSharpNames.ToCSharpIdentifier(Result.Name);

                if (i == resultIndex)
                {
                    resultTypeText = TypeString;
                }
                else
                {
                    if (parameterListText.Length > 0)
                    {
                        parameterListText += ", ";
                    }
                    if (parameterNameListText.Length > 0)
                    {
                        parameterNameListText += ", ";
                    }

                    parameterListText     += $"out {TypeString} {AttributeString}";
                    parameterNameListText += $"out {AttributeString}";
                }
            }

            Debug.Assert(resultTypeText != null);
        }
コード例 #30
0
        /// <summary>
        /// Writes down the C# conditional instructions.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        public virtual void WriteCSharp(ICSharpWriter writer)
        {
            Debug.Assert(WriteDown);

            foreach (ILanguageConstant Constant in ConstantList)
            {
                bool IsHandled = false;

                switch (Constant)
                {
                case INumberLanguageConstant AsManifestConstant:
                    Number AsNumber = AsManifestConstant.Value;
                    if (AsNumber.TryParseInt(out int IntValue))
                    {
                        writer.WriteIndentedLine($"case {IntValue}:");
                        IsHandled = true;
                    }
                    break;

                case IDiscreteLanguageConstant AsDiscreteConstant:
                    IDiscrete    DiscreteItem        = AsDiscreteConstant.Discrete;
                    IName        ClassEntityName     = (IName)DiscreteItem.EmbeddingClass.EntityName;
                    string       ClassName           = CSharpNames.ToCSharpIdentifier(ClassEntityName.ValidText.Item);
                    IFeatureName DiscreteFeatureName = DiscreteItem.ValidDiscreteName.Item;
                    string       DiscreteName        = CSharpNames.ToCSharpIdentifier(DiscreteFeatureName.Name);

                    writer.WriteIndentedLine($"case {ClassName}.{DiscreteName}:");
                    IsHandled = true;
                    break;
                }

                Debug.Assert(IsHandled);
            }

            Instructions.WriteCSharp(writer, CSharpCurlyBracketsInsertions.Indifferent, true);
        }