Example #1
0
        private void WriteCSharpInterface(ICSharpWriter writer, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline)
        {
            isMultiline = false;

            string ResultType = EntityType.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);

            CSharpArgument.BuildParameterList(writer, IndexParameterList, out string ParameterEntityList, out string ParameterNameList);

            string Accessors = "{ get; }";

            writer.WriteIndentedLine($"{ResultType} this[{ParameterEntityList}] {Accessors}");
        }
Example #2
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; }}");
            }
        }
        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};");
        }
Example #4
0
        private static bool CheckRename(ICSharpClass cSharpClass, IErrorList errorList)
        {
            bool Result = true;

            foreach (IInheritance InheritanceItem in cSharpClass.Source.InheritanceList)
            {
                IClassType ParentType  = InheritanceItem.ResolvedClassParentType.Item;
                IClass     ParentClass = ParentType.BaseClass;

                bool BadRename = false;
                foreach (IRename RenameItem in InheritanceItem.RenameList)
                {
                    string ValidSourceText = RenameItem.ValidSourceText.Item;

                    if (!FeatureName.TableContain(ParentClass.FeatureTable, ValidSourceText, out IFeatureName Key, out IFeatureInstance Instance))
                    {
                        BadRename = true;
                        break;
                    }

                    IClass           SourceClass   = Instance.Owner;
                    ICompiledFeature SourceFeature = Instance.Feature;
                    CSharpExports    ExportStatus  = GetExportStatus(Key, SourceClass, cSharpClass.Source.ExportTable, (IFeature)SourceFeature);
                    if (ExportStatus == CSharpExports.Public && !(SourceFeature is ICreationFeature))
                    {
                        BadRename = true;
                        break;
                    }
                }

                if (BadRename)
                {
                    errorList.AddError(new ErrorInvalidRename(InheritanceItem));
                }

                Result &= !BadRename;
            }

            return(Result);
        }
Example #5
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;
            }

            isMultiline = false;

            if (featureTextType == CSharpFeatureTextTypes.Implementation)
            {
                WriteCSharpImplementation(writer, exportStatus, ref isFirstFeature, ref isMultiline);
            }
        }
        /// <summary>
        /// Writes down the C# overload of a feature.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="featureTextType">The write mode.</param>
        /// <param name="isOverride">True if the feature is an override.</param>
        /// <param name="nameString">The composed feature name.</param>
        /// <param name="exportStatus">The feature export status.</param>
        /// <param name="isConstructor">True if the feature is a constructor.</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 void WriteCSharp(ICSharpWriter writer, CSharpFeatureTextTypes featureTextType, bool isOverride, string nameString, CSharpExports exportStatus, bool isConstructor, ref bool isFirstFeature, ref bool isMultiline)
        {
            Debug.Assert(WriteDown);

            bool IsHandled = false;

            switch (featureTextType)
            {
            case CSharpFeatureTextTypes.Implementation:
                WriteCSharpImplementation(writer, isOverride, nameString, exportStatus, isConstructor, ref isFirstFeature, ref isMultiline);
                IsHandled = true;
                break;

            case CSharpFeatureTextTypes.Interface:
                WriteCSharpInterface(writer, isOverride, nameString, exportStatus, isConstructor, ref isFirstFeature, ref isMultiline);
                IsHandled = true;
                break;
            }

            Debug.Assert(IsHandled);
        }
        private void WriteCSharpWriteOnlyProperty(ICSharpWriter writer, bool isOverride, CSharpExports exportStatus, string propertyName, string resultType, ref bool isFirstFeature, ref bool isMultiline)
        {
            bool IsDeferred  = false;
            bool IsPrecursor = false;

            isFirstFeature = false;

            if (SetterBody != null)
            {
                if (SetterBody is ICSharpDeferredBody)
                {
                    IsDeferred = true;
                }

                if (SetterBody is ICSharpPrecursorBody)
                {
                    IsPrecursor = true;
                }
            }

            if (SetterBody != null)
            {
                if (IsDeferred)
                {
                    ICSharpDeferredBody DeferredSetterBody = SetterBody as ICSharpDeferredBody;
                    Debug.Assert(DeferredSetterBody != null);

                    CSharpAssertion.WriteContract(writer, DeferredSetterBody.RequireList, DeferredSetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline);

                    string ExportStatusText = CSharpNames.ComposedExportStatus(false, true, false, exportStatus);
                    writer.WriteIndentedLine($"{ExportStatusText} {resultType} {propertyName} {{ protected get; set; }}");

                    isMultiline = false;
                }
                else
                {
                    if (isMultiline)
                    {
                        writer.WriteEmptyLine();
                    }

                    string ExportStatusText = CSharpNames.ComposedExportStatus(IsOverride, false, false, exportStatus);
                    writer.WriteIndentedLine($"{ExportStatusText} {resultType} {propertyName}");

                    if (IsPrecursor)
                    {
                        writer.WriteIndentedLine("{");
                        writer.IncreaseIndent();
                        writer.WriteIndentedLine($"set {{ base.{propertyName} = value; }}");
                        writer.DecreaseIndent();
                        writer.WriteIndentedLine("}");
                    }

                    else
                    {
                        writer.WriteIndentedLine("{");
                        writer.IncreaseIndent();
                        writer.WriteIndentedLine($"protected get {{ return _{propertyName}; }}");

                        ICSharpEffectiveBody EffectiveSetterBody = SetterBody as ICSharpEffectiveBody;
                        Debug.Assert(EffectiveSetterBody != null);

                        isMultiline = false;
                        CSharpAssertion.WriteContract(writer, EffectiveSetterBody.RequireList, EffectiveSetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline);

                        writer.WriteIndentedLine("set");
                        EffectiveSetterBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets | CSharpBodyFlags.HasValue, string.Empty, false, new List <string>());

                        writer.DecreaseIndent();
                        writer.WriteIndentedLine("}");
                    }

                    isMultiline = true;
                }
            }

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

                string ExportStatusText = CSharpNames.ComposedExportStatus(IsOverride, false, false, exportStatus);
                writer.WriteIndentedLine($"{ExportStatusText} {resultType} {propertyName} {{ protected get; set; }}");

                isMultiline = false;
            }
        }
        private void WriteCSharpForcedReadWriteProperty(ICSharpWriter writer, bool isOverride, CSharpExports exportStatus, string propertyName, string resultType, ref bool isFirstFeature, ref bool isMultiline)
        {
            bool IsDeferred  = false;
            bool IsPrecursor = false;

            isFirstFeature = false;

            if (GetterBody != null)
            {
                if (GetterBody is ICSharpDeferredBody)
                {
                    IsDeferred = true;
                }

                if (GetterBody is ICSharpPrecursorBody)
                {
                    IsPrecursor = true;
                }
            }

            if (SetterBody != null)
            {
                if (SetterBody is ICSharpDeferredBody)
                {
                    IsDeferred = true;
                }

                if (SetterBody is ICSharpPrecursorBody)
                {
                    IsPrecursor = true;
                }
            }

            if (GetterBody != null || SetterBody != null)
            {
                if (IsDeferred)
                {
                    bool IsGetterMultiline = isMultiline;
                    bool IsSetterMultiline = isMultiline;

                    if (GetterBody != null)
                    {
                        ICSharpDeferredBody DeferredGetterBody = GetterBody as ICSharpDeferredBody;
                        Debug.Assert(DeferredGetterBody != null);

                        CSharpAssertion.WriteContract(writer, DeferredGetterBody.RequireList, DeferredGetterBody.EnsureList, CSharpContractLocations.Getter, false, ref isFirstFeature, ref IsGetterMultiline);
                        IsSetterMultiline = false;
                    }

                    if (SetterBody != null)
                    {
                        ICSharpDeferredBody DeferredSetterBody = SetterBody as ICSharpDeferredBody;
                        Debug.Assert(DeferredSetterBody != null);

                        CSharpAssertion.WriteContract(writer, DeferredSetterBody.RequireList, DeferredSetterBody.EnsureList, CSharpContractLocations.Setter, false, ref isFirstFeature, ref IsSetterMultiline);
                    }

                    string ExportStatusText = CSharpNames.ComposedExportStatus(false, true, false, exportStatus);
                    writer.WriteIndentedLine($"{ExportStatusText} {resultType} {propertyName} {{ get; set; }}");

                    isMultiline = IsGetterMultiline || IsSetterMultiline;
                }
                else
                {
                    if (isMultiline)
                    {
                        writer.WriteEmptyLine();
                    }

                    string ExportStatusText = CSharpNames.ComposedExportStatus(IsOverride, false, false, exportStatus);
                    writer.WriteIndentedLine($"{ExportStatusText} {resultType} {propertyName}");
                    writer.WriteIndentedLine("{");
                    writer.IncreaseIndent();

                    if (IsPrecursor)
                    {
                        if (Source.PropertyKind != BaseNode.UtilityType.WriteOnly)
                        {
                            writer.WriteIndentedLine($"get {{ return base.{propertyName}; }}");
                        }
                        else
                        {
                            writer.WriteIndentedLine($"get {{ throw new InvalidOperationException(); }}");
                        }

                        if (Source.PropertyKind != BaseNode.UtilityType.ReadOnly)
                        {
                            writer.WriteIndentedLine($"set {{ base.{propertyName} = value; }}");
                        }
                        else
                        {
                            writer.WriteIndentedLine($"set {{ throw new InvalidOperationException(); }}");
                        }
                    }
                    else
                    {
                        if (GetterBody != null)
                        {
                            ICSharpEffectiveBody EffectiveGetterBody = GetterBody as ICSharpEffectiveBody;
                            Debug.Assert(EffectiveGetterBody != null);

                            isMultiline = false;
                            CSharpAssertion.WriteContract(writer, EffectiveGetterBody.RequireList, EffectiveGetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline);

                            writer.WriteIndentedLine("get");
                            EffectiveGetterBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets | CSharpBodyFlags.HasResult, resultType, false, new List <string>());
                        }
                        else
                        {
                            writer.WriteIndentedLine($"get {{ throw new InvalidOperationException(); }}");
                        }

                        if (SetterBody != null)
                        {
                            ICSharpEffectiveBody EffectiveSetterBody = SetterBody as ICSharpEffectiveBody;
                            Debug.Assert(EffectiveSetterBody != null);

                            isMultiline = false;
                            CSharpAssertion.WriteContract(writer, EffectiveSetterBody.RequireList, EffectiveSetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline);

                            writer.WriteIndentedLine("set");
                            EffectiveSetterBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets | CSharpBodyFlags.HasValue, string.Empty, false, new List <string>());
                        }
                        else
                        {
                            writer.WriteIndentedLine($"set {{ throw new InvalidOperationException(); }}");
                        }
                    }

                    writer.DecreaseIndent();
                    writer.WriteIndentedLine("}");
                    isMultiline = true;
                }
            }

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

                string ExportStatusText = CSharpNames.ComposedExportStatus(IsOverride, false, false, exportStatus);
                writer.WriteIndentedLine($"{ExportStatusText} {resultType} {propertyName}");
                writer.WriteIndentedLine("{");
                writer.IncreaseIndent();

                if (Source.PropertyKind != BaseNode.UtilityType.WriteOnly)
                {
                    writer.WriteIndentedLine($"get {{ return _{propertyName}; }}");
                }
                else
                {
                    writer.WriteIndentedLine($"get {{ throw new InvalidOperationException(); }}");
                }

                if (Source.PropertyKind != BaseNode.UtilityType.ReadOnly)
                {
                    writer.WriteIndentedLine($"set {{ _{propertyName} = value; }}");
                }
                else
                {
                    writer.WriteIndentedLine($"set {{ throw new InvalidOperationException(); }}");
                }

                writer.DecreaseIndent();
                writer.WriteIndentedLine("}");
                isMultiline = true;
            }
        }
Example #9
0
        /// <summary>
        /// Writes down the C# overload of a feature.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="featureTextType">The write mode.</param>
        /// <param name="isOverride">True if the feature is an override.</param>
        /// <param name="nameString">The composed feature name.</param>
        /// <param name="exportStatus">The feature export status.</param>
        /// <param name="isConstructor">True if the feature is a constructor.</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 void WriteCSharp(ICSharpWriter writer, CSharpFeatureTextTypes featureTextType, bool isOverride, string nameString, CSharpExports exportStatus, bool isConstructor, ref bool isFirstFeature, ref bool isMultiline)
        {
            Debug.Assert(WriteDown);

            IList <ICSharpParameter> SelectedParameterList = ParameterList;
            IList <ICSharpParameter> SelectedResultList    = ResultList;

            if (isOverride && Precursor != null)
            {
                SelectedParameterList = Precursor.ParameterList;
                SelectedResultList    = Precursor.ResultList;
            }

            CSharpArgument.BuildParameterList(writer, SelectedParameterList, SelectedResultList, featureTextType, out string ArgumentEntityList, out string ArgumentNameList, out string ResultType);
            string ExportStatusText;

            if (featureTextType == CSharpFeatureTextTypes.Implementation)
            {
                bool IsHandled = false;

                switch (Body)
                {
                case ICSharpDeferredBody AsDeferredBody:
                    CSharpAssertion.WriteContract(writer, AsDeferredBody.RequireList, AsDeferredBody.EnsureList, CSharpContractLocations.Other, true, ref isFirstFeature, ref isMultiline);
                    ExportStatusText = CSharpNames.ComposedExportStatus(false, true, false, exportStatus);
                    writer.WriteIndentedLine($"{ExportStatusText} {ResultType} {nameString}({ArgumentEntityList});");
                    isMultiline = false;
                    IsHandled   = true;
                    break;

                case ICSharpEffectiveBody AsEffectiveBody:
                    CSharpAssertion.WriteContract(writer, AsEffectiveBody.RequireList, AsEffectiveBody.EnsureList, CSharpContractLocations.Other, true, ref isFirstFeature, ref isMultiline);

                    CSharpBodyFlags Flags                    = CSharpBodyFlags.MandatoryCurlyBrackets;
                    string          ResultString             = string.Empty;
                    List <string>   InitialisationStringList = new List <string>();

                    if (ResultList.Count == 1)
                    {
                        Flags |= CSharpBodyFlags.HasResult;
                        ICSharpParameter Result = ResultList[0];
                        ResultString = Result.Feature.Type.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);
                    }
                    else
                    {
                        if (ResultType != "void")
                        {
                            Flags       |= CSharpBodyFlags.HasResult;
                            ResultString = ResultType;
                        }

                        foreach (ICSharpParameter Item in ResultList)
                        {
                            string InitValueString;

                            ICSharpType ResultEntityType = Item.Feature.Type;

                            if (ResultEntityType is ICSharpClassType AsClassType)
                            {
                                // TODO: when the type inherit from Enumeration
                                if (AsClassType.Class.Source.ClassGuid == LanguageClasses.AnyOptionalReference.Guid)
                                {
                                    InitValueString = "new OptionalReference<>(null)";     // TODO
                                }
                                else if (AsClassType.Class.Source.ClassGuid == LanguageClasses.String.Guid)
                                {
                                    InitValueString = "\"\"";
                                }

                                else if (AsClassType.Class.Source.ClassGuid == LanguageClasses.Boolean.Guid)
                                {
                                    InitValueString = "false";
                                }

                                else if (AsClassType.Class.Source.ClassGuid == LanguageClasses.Character.Guid)
                                {
                                    InitValueString = "'\0'";
                                }

                                else if (AsClassType.Class.Source.ClassGuid == LanguageClasses.Number.Guid)
                                {
                                    InitValueString = "0";
                                }

                                else
                                {
                                    InitValueString = "null";
                                }
                            }

                            else
                            {
                                InitValueString = "null";     // TODO : tuples
                            }
                            string InitNameString = CSharpNames.ToCSharpIdentifier(Item.Name);

                            InitialisationStringList.Add($"{InitNameString} = {InitValueString};");
                        }
                    }

                    ExportStatusText = CSharpNames.ComposedExportStatus(isOverride, false, false, exportStatus);
                    writer.WriteIndentedLine($"{ExportStatusText} {ResultType} {nameString}({ArgumentEntityList})");

                    AsEffectiveBody.WriteCSharp(writer, Flags, ResultString, false, InitialisationStringList);
                    isMultiline = true;
                    IsHandled   = true;
                    break;

                case ICSharpPrecursorBody AsPrecursorBody:
                    if (isMultiline)
                    {
                        writer.WriteEmptyLine();
                    }

                    ExportStatusText = CSharpNames.ComposedExportStatus(true, false, false, exportStatus);
                    writer.WriteIndentedLine($"{ExportStatusText} {ResultType} {nameString}({ArgumentEntityList})");
                    writer.WriteIndentedLine("{");
                    writer.IncreaseIndent();
                    writer.WriteIndentedLine($"return base.{nameString}({ArgumentNameList});");
                    writer.DecreaseIndent();
                    writer.WriteIndentedLine("}");
                    isMultiline = true;
                    IsHandled   = true;
                    break;
                }

                Debug.Assert(IsHandled);
            }
            else
            {
                writer.WriteIndentedLine($"{ResultType} {nameString}({ArgumentEntityList});");
                isMultiline = false;
            }
        }
        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;
        }
 /// <summary>
 /// Writes down the C# overload of a feature.
 /// </summary>
 /// <param name="writer">The stream on which to write.</param>
 /// <param name="featureTextType">The write mode.</param>
 /// <param name="isOverride">True if the feature is an override.</param>
 /// <param name="nameString">The composed feature name.</param>
 /// <param name="exportStatus">The feature export status.</param>
 /// <param name="isConstructor">True if the feature is a constructor.</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 void WriteCSharp(ICSharpWriter writer, CSharpFeatureTextTypes featureTextType, bool isOverride, string nameString, CSharpExports exportStatus, bool isConstructor, ref bool isFirstFeature, ref bool isMultiline)
 {
     //TODO
 }
        /// <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);
            }
        }
        private void WriteCSharpInterface(ICSharpWriter writer, 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 (!isConstructor)
            {
                writer.WriteIndentedLine($"void {nameString}({ParameterEntityList});");
                isMultiline = false;
            }
        }
Example #14
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)
 {
     WriteCSharp(writer);
 }
        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;
        }
        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();
                         *      }
                         *  }
                         * }
                         */
                    }
                }
            }
        }
        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;
        }
Example #18
0
        /// <summary>
        /// Returns the text of an export.
        /// </summary>
        /// <param name="isOverride">True if the feature is an override of a parent virtual feature.</param>
        /// <param name="isAbstract">True if the feature is abstract.</param>
        /// <param name="isNonVirtual">True if the feature is NOT virtual.</param>
        /// <param name="exportStatus">The base export status.</param>
        public static string ComposedExportStatus(bool isOverride, bool isAbstract, bool isNonVirtual, CSharpExports exportStatus)
        {
            string Result = null;

            switch (exportStatus)
            {
            case CSharpExports.Private:
                Result = "private";
                break;

            case CSharpExports.Protected:
                Result = "protected" + (isAbstract ? " " + "abstract" : (isOverride ? " " + "override" : (isNonVirtual ? string.Empty : " " + "virtual")));
                break;

            case CSharpExports.Public:
                Result = "public" + (isAbstract ? " " + "abstract" : (isOverride ? " " + "override" : (isNonVirtual ? string.Empty : " " + "virtual")));
                break;
            }

            Debug.Assert(Result != null);

            return(Result);
        }
Example #19
0
        private void WriteCSharpImplementation(ICSharpWriter writer, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline)
        {
            writer.WriteDocumentation(Source);

            string ResultType = EntityType.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);

            CSharpArgument.BuildParameterList(writer, IndexParameterList, out string ParameterEntityList, out string ParameterNameList);

            string Accessors;

            if (!IsForcedReadWrite && SetterBody == null)
            {
                Accessors = "{ get; }";
            }

            else if (!IsForcedReadWrite && GetterBody == null)
            {
                Accessors = "{ set; }";
            }

            else
            {
                Accessors = "{ get; set; }";
            }

            bool IsDeferred = false;

            if (GetterBody != null)
            {
                if (GetterBody is ICSharpDeferredBody)
                {
                    IsDeferred = true;
                }
                else
                {
                    IsDeferred = false;
                }
            }
            else if (SetterBody != null)
            {
                if (SetterBody is ICSharpDeferredBody)
                {
                    IsDeferred = true;
                }
                else
                {
                    IsDeferred = false;
                }
            }

            if (IsDeferred)
            {
                if (GetterBody is ICSharpDeferredBody AsDeferredGetterBody)
                {
                    CSharpAssertion.WriteContract(writer, AsDeferredGetterBody.RequireList, AsDeferredGetterBody.EnsureList, CSharpContractLocations.Getter, false, ref isFirstFeature, ref isMultiline);
                    isMultiline = false;
                }

                if (SetterBody is ICSharpDeferredBody AsDeferredSetterBody)
                {
                    CSharpAssertion.WriteContract(writer, AsDeferredSetterBody.RequireList, AsDeferredSetterBody.EnsureList, CSharpContractLocations.Setter, false, ref isFirstFeature, ref isMultiline);
                }

                string ExportStatusText = CSharpNames.ComposedExportStatus(false, true, false, exportStatus);
                writer.WriteIndentedLine($"{ExportStatusText} {ResultType} this[{ParameterEntityList}] {Accessors}");

                isMultiline = false;
            }
            else
            {
                string ExportStatusText = CSharpNames.ComposedExportStatus(IsOverride, false, false, exportStatus);

                writer.WriteIndentedLine($"{ExportStatusText} {ResultType} this[{ParameterEntityList}]");
                writer.WriteIndentedLine("{");
                writer.IncreaseIndent();

                bool IsPrecursor = false;
                if (GetterBody != null)
                {
                    if (GetterBody is ICSharpPrecursorBody)
                    {
                        IsPrecursor = true;
                    }
                    else
                    {
                        IsPrecursor = false;
                    }
                }
                else if (SetterBody != null)
                {
                    if (GetterBody is ICSharpPrecursorBody)
                    {
                        IsPrecursor = true;
                    }
                    else
                    {
                        IsPrecursor = false;
                    }
                }

                if (IsPrecursor)
                {
                    if (GetterBody is ICSharpPrecursorBody AsPrecursorGetterBody)
                    {
                        isMultiline = false;

                        CSharpAssertion.WriteContract(writer, AsPrecursorGetterBody.RequireList, AsPrecursorGetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline);
                        writer.WriteIndentedLine("get");
                        writer.WriteIndentedLine("{");
                        writer.IncreaseIndent();
                        writer.WriteIndentedLine($"return base[{ParameterEntityList}];");
                        writer.DecreaseIndent();
                        writer.WriteIndentedLine("}");
                    }
                    else if (IsForcedReadWrite)
                    {
                        writer.WriteIndentedLine("get { throw new InvalidOperationException(); }");
                    }

                    if (SetterBody is ICSharpPrecursorBody AsPrecursorSetterBody)
                    {
                        isMultiline = false;

                        CSharpAssertion.WriteContract(writer, AsPrecursorSetterBody.RequireList, AsPrecursorSetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline);
                        writer.WriteIndentedLine("set");
                        writer.WriteIndentedLine("{");
                        writer.IncreaseIndent();
                        writer.WriteIndentedLine($"base[{ParameterEntityList}] = value;");
                        writer.DecreaseIndent();
                        writer.WriteIndentedLine("}");
                    }

                    else if (IsForcedReadWrite)
                    {
                        writer.WriteIndentedLine("set { throw new InvalidOperationException(); }");
                    }
                }
                else
                {
                    if (GetterBody != null)
                    {
                        if (GetterBody is ICSharpEffectiveBody AsEffectiveGetterBody)
                        {
                            isMultiline = false;

                            CSharpAssertion.WriteContract(writer, AsEffectiveGetterBody.RequireList, AsEffectiveGetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline);
                            writer.WriteIndentedLine("get");
                            AsEffectiveGetterBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets | CSharpBodyFlags.HasResult, ResultType, false, new List <string>());
                        }
                    }
                    else if (IsForcedReadWrite)
                    {
                        writer.WriteIndentedLine("get { throw new InvalidOperationException(); }");
                    }

                    if (SetterBody != null)
                    {
                        if (SetterBody is ICSharpEffectiveBody AsEffectiveSetterBody)
                        {
                            isMultiline = false;

                            CSharpAssertion.WriteContract(writer, AsEffectiveSetterBody.RequireList, AsEffectiveSetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline);
                            writer.WriteIndentedLine("set");
                            AsEffectiveSetterBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets | CSharpBodyFlags.HasValue, string.Empty, false, new List <string>());
                        }
                    }
                    else if (IsForcedReadWrite)
                    {
                        writer.WriteIndentedLine("set { throw new InvalidOperationException(); }");
                    }
                }

                writer.DecreaseIndent();
                writer.WriteIndentedLine("}");

                isMultiline = true;
            }
        }
 /// <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 abstract void WriteCSharp(ICSharpWriter writer, CSharpFeatureTextTypes featureTextType, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline);
        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;
            }
        }
Example #22
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);
            }
        }
        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;
        }
        /// <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;
            }

            bool IsHandled = false;

            switch (featureTextType)
            {
            case CSharpFeatureTextTypes.Implementation:
                WriteCSharpImplementation(writer, featureTextType, exportStatus, isLocal, ref isFirstFeature, ref isMultiline);
                IsHandled = true;
                break;

            case CSharpFeatureTextTypes.Interface:
                WriteCSharpInterface(writer, featureTextType, exportStatus, isLocal, ref isFirstFeature, ref isMultiline);
                IsHandled = true;
                break;
            }

            Debug.Assert(IsHandled);
        }
        private void WriteCSharpImplementation(ICSharpWriter writer, bool isOverride, string nameString, CSharpExports exportStatus, bool isConstructor, ref bool isFirstFeature, ref bool isMultiline)
        {
            bool IsHandled = false;

            switch (Body)
            {
            case ICSharpDeferredBody AsDeferredBody:
                WriteCSharpImplementationDeferred(writer, AsDeferredBody, isOverride, nameString, exportStatus, isConstructor, ref isFirstFeature, ref isMultiline);
                IsHandled = true;
                break;

            case ICSharpEffectiveBody AsEffectiveBody:
                WriteCSharpImplementationEffective(writer, AsEffectiveBody, isOverride, nameString, exportStatus, isConstructor, ref isFirstFeature, ref isMultiline);
                IsHandled = true;
                break;

            case ICSharpPrecursorBody AsPrecursorBody:
                WriteCSharpImplementationPrecursor(writer, AsPrecursorBody, isOverride, nameString, exportStatus, isConstructor, ref isFirstFeature, ref isMultiline);
                IsHandled = true;
                break;
            }

            Debug.Assert(IsHandled);
        }