protected void InsertCodeInRunWorkflowMethod(GraphicElement root, StringBuilder code)
        {
            ICSharpClass cls = (ICSharpClass)root;

            string existingCode = String.Empty;

            // TODO: Verify that root.Json["Code"] defines the namespace, class, and stub, or figure out how to include "using" and field initialization and properties such that
            // we can create the namespace, class, and stub for the user.
            if (root.Json.ContainsKey("Code"))
            {
                existingCode = root.Json["Code"];
            }

            //string before = existingCode.LeftOf("void RunWorkflow()");
            //string after = existingCode.RightOf("void RunWorkflow()").RightOfMatching('{', '}');
            //StringBuilder finalCode = new StringBuilder(before);
            StringBuilder finalCode = new StringBuilder();

            finalCode.AppendLine("using System;");
            finalCode.AppendLine("using System.Linq;");
            finalCode.AppendLine();

            finalCode.AppendLine("namespace " + cls.NamespaceName);
            finalCode.AppendLine("{");
            finalCode.AppendLine("    public partial class " + cls.ClassName);
            finalCode.AppendLine("    {");
            finalCode.AppendLine(new String(' ', 8) + "public void " + cls.MethodName + "()");
            finalCode.AppendLine(new String(' ', 8) + "{");
            finalCode.AppendLine(new String(' ', 12) + code.ToString().Trim());
            finalCode.AppendLine(new String(' ', 8) + "}");
            finalCode.AppendLine("    }");
            finalCode.AppendLine("}");
            // finalCode.Append(after);
            root.Json["Code"] = finalCode.ToString();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpFeatureCall"/> class.
        /// </summary>
        /// <param name="context">The creation context.</param>
        /// <param name="source">Details of the feature call.</param>
        public CSharpFeatureCall(ICSharpContext context, IFeatureCall source)
        {
            foreach (IParameter Item in source.ParameterList)
            {
                ICSharpClass     Owner        = context.GetClass(Item.ResolvedParameter.Location.EmbeddingClass);
                ICSharpParameter NewParameter = CSharpParameter.Create(context, Item, Owner);
                ParameterList.Add(NewParameter);
            }

            foreach (IParameter Item in source.ResultList)
            {
                ICSharpClass     Owner        = context.GetClass(Item.ResolvedParameter.Location.EmbeddingClass);
                ICSharpParameter NewParameter = CSharpParameter.Create(context, Item, Owner);
                ResultList.Add(NewParameter);
            }

            foreach (IArgument Item in source.ArgumentList)
            {
                ICSharpArgument NewArgument = CSharpArgument.Create(context, Item);
                ArgumentList.Add(NewArgument);
            }

            Debug.Assert(ParameterList.Count >= ArgumentList.Count);
            Count = ParameterList.Count;

            ArgumentStyle = source.TypeArgumentStyle;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpFeature{T}"/> class.
        /// </summary>
        /// <param name="owner">The class where the feature is declared.</param>
        /// <param name="source">The source Easly feature.</param>
        protected CSharpFeature(ICSharpClass owner, T source)
            : base(source)
        {
            Debug.Assert(source is IScopeAttributeFeature);

            Owner = owner;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpInheritance"/> class.
        /// </summary>
        /// <param name="source">The Easly node from which the C# node is created.</param>
        /// <param name="ancestorClass">The ancestor class.</param>
        protected CSharpInheritance(IInheritance source, ICSharpClass ancestorClass)
            : base(source)
        {
            Debug.Assert(ancestorClass != null);

            AncestorClass = ancestorClass;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpEntityExpression"/> class.
        /// </summary>
        /// <param name="context">The creation context.</param>
        /// <param name="source">The Easly expression from which the C# expression is created.</param>
        protected CSharpEntityExpression(ICSharpContext context, IEntityExpression source)
            : base(context, source)
        {
            if (Source.ResolvedFinalFeature.IsAssigned)
            {
                ICompiledFeature ResolvedFeature = Source.ResolvedFinalFeature.Item;
                if (ResolvedFeature is IScopeAttributeFeature AsScopeAttributeFeature)
                {
                    ICSharpClass Owner = context.GetClass(source.EmbeddingClass);
                    Feature = CSharpScopeAttributeFeature.Create(context, Owner, AsScopeAttributeFeature);
                }
                else
                {
                    Feature = context.GetFeature(Source.ResolvedFinalFeature.Item);
                }
            }

            if (Source.ResolvedFinalDiscrete.IsAssigned)
            {
                ICSharpClass Class = context.GetClass(Source.ResolvedFinalDiscrete.Item.EmbeddingClass);

                foreach (ICSharpDiscrete Item in Class.DiscreteList)
                {
                    if (Item.Source == Source.ResolvedFinalDiscrete.Item)
                    {
                        Debug.Assert(Discrete == null);
                        Discrete = Item;
                    }
                }
            }

            Debug.Assert((Feature != null && Discrete == null) || (Feature == null && Discrete != null));

            Query = CSharpQualifiedName.Create(context, (IQualifiedName)Source.Query, Feature, Discrete, false);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpFeature{T}"/> class.
        /// </summary>
        /// <param name="owner">The class where the feature is declared.</param>
        /// <param name="instance">The source feature instance.</param>
        /// <param name="source">The source Easly feature.</param>
        protected CSharpFeature(ICSharpClass owner, IFeatureInstance instance, T source)
            : base(source)
        {
            Owner    = owner;
            Instance = instance;

            Debug.Assert(Instance.Feature == Source);
        }
Ejemplo n.º 7
0
        private bool GetBaseClass(ICSharpClass cSharpClass, IClassSplitting splitting, IDictionary <IClass, ICSharpClass> classTable, out ICSharpClass result)
        {
            result = null;
            IClass BaseClass = null;

            // If the class inherits from a class that must be a parent, select it as base class.
            foreach (IInheritance InheritanceItem in cSharpClass.Source.InheritanceList)
            {
                IClassType ClassParentType = InheritanceItem.ResolvedClassParentType.Item;
                IClass     ParentClass     = ClassParentType.BaseClass;

                Debug.Assert(ParentClass != null);

                if (splitting.MustInherit.Contains(ParentClass))
                {
                    Debug.Assert(BaseClass == null);
                    BaseClass = ParentClass;
                }
            }

            // No such class. Try classes that don't have to be interface.
            if (BaseClass == null)
            {
                IList <IClass> ParentCandidates = new List <IClass>();

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

                    if (splitting.OtherParents.Contains(ParentClass))
                    {
                        ParentCandidates.Add(ParentClass);
                    }
                }

                if (ParentCandidates.Count > 0)
                {
                    BaseClass = ParentCandidates[0];
                }
            }

            if (BaseClass != null)
            {
                foreach (KeyValuePair <IClass, ICSharpClass> Entry in classTable)
                {
                    ICSharpClass Item = Entry.Value;

                    if (Item.Source == BaseClass)
                    {
                        Debug.Assert(result == null);
                        result = Item;
                    }
                }
            }

            return(result != null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the export status of a feature in the class that implements it.
        /// </summary>
        /// <param name="sourceClass">The class implementing the feature.</param>
        public virtual CSharpExports GetExportStatus(ICSharpClass sourceClass)
        {
            bool IsExportedToClient;

            IFeature AsFeature = Source as IFeature;

            Debug.Assert(AsFeature != null);

            IIdentifier Identifier       = (IIdentifier)AsFeature.ExportIdentifier;
            string      ExportIdentifier = Identifier.ValidText.Item;

            if (ExportIdentifier == "All")
            {
                IsExportedToClient = true;
            }

            else if (ExportIdentifier == "None" || ExportIdentifier == "Self")
            {
                IsExportedToClient = false;
            }

            else
            {
                FeatureName.TableContain(Owner.Source.ExportTable, ExportIdentifier, out IFeatureName ExportName, out ISealableDictionary <string, IClass> ExportList);
                Debug.Assert(ExportList.Count > 0);

                if (ExportList.Count > 1)
                {
                    IsExportedToClient = true;
                }
                else
                {
                    if (ExportList.ContainsKey(sourceClass.ValidClassName))
                    {
                        IsExportedToClient = false; // Export to self = self + descendant = protected
                    }
                    else
                    {
                        IsExportedToClient = true; // export to another = export to all = public
                    }
                }
            }

            if (IsExportedToClient)
            {
                return(CSharpExports.Public);
            }

            else if (AsFeature.Export == BaseNode.ExportStatus.Exported)
            {
                return(CSharpExports.Protected);
            }
            else
            {
                return(CSharpExports.Private);
            }
        }
Ejemplo n.º 9
0
        private static bool CreateFeature(ICSharpClass owner, IFeatureInstance instance, out ICSharpFeature result)
        {
            result = null;
            bool IsHandled = false;

            ICompiledFeature SourceFeature = instance.Feature;

            switch (SourceFeature)
            {
            case IAttributeFeature AsAttributeFeature:
                result    = CSharpAttributeFeature.Create(owner, instance, AsAttributeFeature);
                IsHandled = true;
                break;

            case IConstantFeature AsConstantFeature:
                result    = CSharpConstantFeature.Create(owner, instance, AsConstantFeature);
                IsHandled = true;
                break;

            case ICreationFeature AsCreationFeature:
                result    = CSharpCreationFeature.Create(owner, instance, AsCreationFeature);
                IsHandled = true;
                break;

            case IFunctionFeature AsFunctionFeature:
                result    = CSharpFunctionFeature.Create(owner, instance, AsFunctionFeature);
                IsHandled = true;
                break;

            case IIndexerFeature AsIndexerFeature:
                result    = CSharpIndexerFeature.Create(owner, instance, AsIndexerFeature);
                IsHandled = true;
                break;

            case IProcedureFeature AsProcedureFeature:
                result    = CSharpProcedureFeature.Create(owner, instance, AsProcedureFeature);
                IsHandled = true;
                break;

            case IPropertyFeature AsPropertyFeature:
                result    = CSharpPropertyFeature.Create(owner, instance, AsPropertyFeature);
                IsHandled = true;
                break;

            case IScopeAttributeFeature AsScopeAttributeFeature:
                result    = CSharpScopeAttributeFeature.Create(owner, AsScopeAttributeFeature);
                IsHandled = true;
                break;
            }

            Debug.Assert(IsHandled);

            return(result != null);
        }
Ejemplo n.º 10
0
        private bool CreateClasses(out IDictionary <IClass, ICSharpClass> classTable)
        {
            classTable = null;

            if (!ClassSplitting.Create(Compiler.LoadedRoot.ClassList, ErrorList, out IClassSplitting Splitting))
            {
                return(false);
            }

            classTable = new Dictionary <IClass, ICSharpClass>();

            ICSharpClass ClassAny = CSharpClass.Create(Class.ClassAny);

            classTable.Add(Class.ClassAny, ClassAny);

            ICSharpClass ClassAnyReference = CSharpClass.Create(Class.ClassAnyReference);

            classTable.Add(Class.ClassAnyReference, ClassAnyReference);

            ICSharpClass ClassAnyValue = CSharpClass.Create(Class.ClassAnyValue);

            classTable.Add(Class.ClassAnyValue, ClassAnyValue);

            foreach (IClass Class in Compiler.LoadedRoot.ClassList)
            {
                ICSharpClass NewCSharpClass = CSharpClass.Create(Class);
                classTable.Add(Class, NewCSharpClass);
            }

            foreach (KeyValuePair <IClass, ICSharpClass> Entry in classTable)
            {
                ICSharpClass Class = Entry.Value;

                if (GetBaseClass(Class, Splitting, classTable, out ICSharpClass BaseClass))
                {
                    Class.SetBaseClass(BaseClass);
                }

                Class.SetAncestorClasses(classTable);
            }

            foreach (KeyValuePair <IClass, ICSharpClass> Entry in classTable)
            {
                ICSharpClass Class = Entry.Value;
                CheckRename(Class, ErrorList);
            }
            if (!ErrorList.IsEmpty)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 11
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; }}");
            }
        }
Ejemplo n.º 12
0
        private void CheckSharedName(ICSharpClass cSharpClass, IDictionary <IClass, ICSharpClass> classTable)
        {
            foreach (KeyValuePair <IClass, ICSharpClass> Entry in classTable)
            {
                ICSharpClass OtherClass = Entry.Value;

                if (cSharpClass.ValidClassName == OtherClass.ValidClassName)
                {
                    cSharpClass.SetIsSharedName();
                    break;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpQueryExpression"/> class.
        /// </summary>
        /// <param name="context">The creation context.</param>
        /// <param name="source">The Easly expression from which the C# expression is created.</param>
        protected CSharpQueryExpression(ICSharpContext context, IQueryExpression source)
            : base(context, source)
        {
            FeatureCall = new CSharpFeatureCall(context, source.FeatureCall.Item);

            if (Source.ResolvedFinalFeature.IsAssigned)
            {
                ICompiledFeature ResolvedFeature = Source.ResolvedFinalFeature.Item;
                if (ResolvedFeature is IScopeAttributeFeature AsScopeAttributeFeature)
                {
                    ICSharpClass Owner = context.GetClass(source.EmbeddingClass);
                    Feature = CSharpScopeAttributeFeature.Create(context, Owner, AsScopeAttributeFeature);
                }
                else
                {
                    Feature = context.GetFeature(Source.ResolvedFinalFeature.Item);
                }
            }

            if (Source.ResolvedFinalDiscrete.IsAssigned)
            {
                DiscreteOwner = context.GetClass(Source.ResolvedFinalDiscrete.Item.EmbeddingClass);

                foreach (ICSharpDiscrete Item in DiscreteOwner.DiscreteList)
                {
                    if (Item.Source == Source.ResolvedFinalDiscrete.Item)
                    {
                        Debug.Assert(Discrete == null);
                        Discrete = Item;
                    }
                }
            }

            Debug.Assert((Feature != null && Discrete == null) || (Feature == null && Discrete != null));

            if (Source.SelectedOverloadType.IsAssigned)
            {
                Debug.Assert(Feature != null);

                SelectedOverloadType = CSharpQueryOverloadType.Create(context, Source.SelectedOverloadType.Item, Feature.Owner);
            }
            else
            {
                SelectedOverloadType = null;
            }

            Query = CSharpQualifiedName.Create(context, (IQualifiedName)Source.Query, Feature, Discrete, source.InheritBySideAttribute);
        }
        /// <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);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpProcedureType"/> class.
        /// </summary>
        /// <param name="context">The creation context.</param>
        /// <param name="source">The Easly type from which the C# type is created.</param>
        /// <param name="originatingTypedef">The typedef where this type is declared.</param>
        protected CSharpProcedureType(ICSharpContext context, IProcedureType source, ICSharpTypedef originatingTypedef)
            : base(context, source, originatingTypedef)
        {
            Debug.Assert(source.OverloadList.Count > 0);

            ICSharpClass Owner = context.GetClass(source.EmbeddingClass);

            BaseType = Create(context, source.ResolvedBaseType.Item) as ICSharpTypeWithFeature;
            Debug.Assert(BaseType != null);

            foreach (ICommandOverloadType OverloadType in source.OverloadList)
            {
                ICSharpCommandOverloadType NewOverloadType = CSharpCommandOverloadType.Create(context, OverloadType, Owner);
                OverloadTypeList.Add(NewOverloadType);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpFunctionType"/> class.
        /// </summary>
        /// <param name="context">The creation context.</param>
        /// <param name="source">The Easly type from which the C# type is created.</param>
        protected CSharpFunctionType(ICSharpContext context, IFunctionType source)
            : base(context, source)
        {
            Debug.Assert(source.OverloadList.Count > 0);

            ICSharpClass Owner = source.EmbeddingClass != null?context.GetClass(source.EmbeddingClass) : null;

            BaseType = Create(context, source.ResolvedBaseType.Item) as ICSharpTypeWithFeature;
            Debug.Assert(BaseType != null);

            foreach (IQueryOverloadType OverloadType in source.OverloadList)
            {
                ICSharpQueryOverloadType NewOverloadType = CSharpQueryOverloadType.Create(context, OverloadType, Owner);
                OverloadTypeList.Add(NewOverloadType);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpEffectiveBody"/> class.
        /// </summary>
        /// <param name="context">The creation context.</param>
        /// <param name="parentFeature">The parent feature.</param>
        /// <param name="source">The Easly body from which the C# body is created.</param>
        protected CSharpEffectiveBody(ICSharpContext context, ICSharpFeature parentFeature, IEffectiveBody source)
            : base(context, parentFeature, source)
        {
            foreach (IInstruction Instruction in source.BodyInstructionList)
            {
                ICSharpInstruction NewInstruction = CSharpInstruction.Create(context, parentFeature, Instruction);
                BodyInstructionList.Add(NewInstruction);
            }

            ICSharpClass Owner = parentFeature.Owner;

            foreach (IEntityDeclaration Item in source.EntityDeclarationList)
            {
                ICSharpScopeAttributeFeature NewDeclaration = CSharpScopeAttributeFeature.Create(context, Owner, Item.ValidEntity.Item);
                EntityDeclarationList.Add(NewDeclaration);
            }
        }
        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();
                         *      }
                         *  }
                         * }
                         */
                    }
                }
            }
        }
Ejemplo n.º 19
0
        private static void CreateClassFeatures(ICSharpClass cSharpClass, IList <ICSharpFeature> featureList)
        {
            foreach (KeyValuePair <IFeatureName, IFeatureInstance> Entry in cSharpClass.Source.FeatureTable)
            {
                IFeatureInstance Instance = Entry.Value;
                Debug.Assert(Instance.Feature != null && Instance.Owner != null);

                // Only create features that belong to this class directly, or are not inherited from a base class.
                if (!IsDirectOrNotMainParentFeature(Instance, cSharpClass))
                {
                    continue;
                }

                bool IsCreated = CreateFeature(cSharpClass, Instance, out ICSharpFeature NewFeature);
                Debug.Assert(IsCreated);

                featureList.Add(NewFeature);
            }
        }
Ejemplo n.º 20
0
        private bool CreateFeatures(IDictionary <IClass, ICSharpClass> classTable, out IDictionary <ICompiledFeature, ICSharpFeature> featureTable)
        {
            featureTable = new Dictionary <ICompiledFeature, ICSharpFeature>();

            foreach (KeyValuePair <IClass, ICSharpClass> Entry in classTable)
            {
                ICSharpClass           Class       = Entry.Value;
                IList <ICSharpFeature> FeatureList = new List <ICSharpFeature>();
                CreateClassFeatures(Class, FeatureList);

                foreach (ICSharpFeature Feature in FeatureList)
                {
                    Debug.Assert(!featureTable.ContainsKey(Feature.Source));
                    featureTable.Add(Feature.Source, Feature);
                }
            }

            return(true);
        }
Ejemplo n.º 21
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);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpCommandInstruction"/> class.
        /// </summary>
        /// <param name="context">The creation context.</param>
        /// <param name="parentFeature">The parent feature.</param>
        /// <param name="source">The Easly instruction from which the C# instruction is created.</param>
        protected CSharpCommandInstruction(ICSharpContext context, ICSharpFeature parentFeature, ICommandInstruction source)
            : base(context, parentFeature, source)
        {
            Command     = CSharpQualifiedName.Create(context, (IQualifiedName)source.Command, parentFeature, null, false);
            FeatureCall = new CSharpFeatureCall(context, source.FeatureCall.Item);

            ICompiledFeature SourceFeature = source.SelectedFeature.Item;

            if (SourceFeature is IScopeAttributeFeature AsScopeAttributeFeature)
            {
                FinalFeature = CSharpScopeAttributeFeature.Create(null, AsScopeAttributeFeature);
            }
            else
            {
                FinalFeature = context.GetFeature(SourceFeature);
            }

            ICompiledTypeWithFeature ResolvedBaseType = Source.CommandFinalType.Item.ResolvedBaseType.Item;

            FinalType = CSharpType.Create(context, ResolvedBaseType) as ICSharpTypeWithFeature;
            Debug.Assert(FinalType != null);

            IList <ICSharpClassType> ConformingClassTypeList = FinalType.ConformingClassTypeList;

            bool InheritFromDotNetEvent = false;
            bool IsNumberType           = false;

            foreach (ICSharpClassType Item in ConformingClassTypeList)
            {
                ICSharpClass CallClass = Item.Class;
                InheritFromDotNetEvent |= CallClass.InheritFromDotNetEvent;

                IsNumberType = Item.IsNumberType;
            }

            SkipLastInPath         = InheritFromDotNetEvent;
            IsCallingNumberFeature = IsNumberType;
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CSharpCreationFeature"/> class.
 /// </summary>
 /// <param name="owner">The class where the feature is declared.</param>
 /// <param name="instance">The source feature instance.</param>
 /// <param name="source">The source Easly feature.</param>
 protected CSharpCreationFeature(ICSharpClass owner, IFeatureInstance instance, ICreationFeature source)
     : base(owner, instance, source)
 {
     Name = Source.ValidFeatureName.Item.Name;
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Translates nodes from the compiler to the target language.
        /// </summary>
        public override void Translate()
        {
            ErrorList.ClearErrors();

            if (!CreateClasses(out IDictionary <IClass, ICSharpClass> ClassTable))
            {
                return;
            }

            if (!CreateFeatures(ClassTable, out IDictionary <ICompiledFeature, ICSharpFeature> FeatureTable))
            {
                return;
            }

            ICSharpContext Context = new CSharpContext(ClassTable, FeatureTable);

            foreach (KeyValuePair <IClass, ICSharpClass> ClassEntry in ClassTable)
            {
                ICSharpClass           Class                = ClassEntry.Value;
                IList <ICSharpFeature> ClassFeatureList     = new List <ICSharpFeature>();
                IList <ICSharpFeature> InheritedFeatureList = new List <ICSharpFeature>();

                foreach (KeyValuePair <ICompiledFeature, ICSharpFeature> FeatureEntry in FeatureTable)
                {
                    ICSharpFeature   Feature  = FeatureEntry.Value;
                    IFeatureInstance Instance = Feature.Instance;

                    if (Instance.IsDiscontinued)
                    {
                        continue;
                    }

                    if (FeatureEntry.Value.Owner == Class)
                    {
                        ClassFeatureList.Add(Feature);
                    }
                    else if (!IsDirectOrNotMainParentFeature(Instance, Class))
                    {
                        InheritedFeatureList.Add(Feature);
                    }
                }

                Class.SetFeatureList(Context, ClassFeatureList, InheritedFeatureList);
            }

            foreach (KeyValuePair <ICompiledFeature, ICSharpFeature> Entry in FeatureTable)
            {
                ICSharpFeature Feature = Entry.Value;
                Feature.InitOverloadsAndBodies(Context);
            }

            foreach (KeyValuePair <ICompiledFeature, ICSharpFeature> Entry in FeatureTable)
            {
                ICSharpFeature Feature = Entry.Value;
                Feature.InitHierarchy(Context);
            }

            foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable)
            {
                ICSharpClass Class = Entry.Value;
                CheckSharedName(Class, ClassTable);
            }

            foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable)
            {
                ICSharpClass Class = Entry.Value;
                Class.CheckOverrides();
            }

            foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable)
            {
                ICSharpClass Class = Entry.Value;
                Class.CheckOverrides();
            }

            bool Continue;

            do
            {
                Continue = false;

                foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable)
                {
                    ICSharpClass Class = Entry.Value;
                    Class.CheckForcedReadWrite(FeatureTable, ref Continue);
                }
            }while (Continue);

            foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable)
            {
                ICSharpClass Class = Entry.Value;
                Class.CheckSideBySideAttributes();
            }

            foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable)
            {
                ICSharpClass Class = Entry.Value;
                Class.CheckInheritSideBySideAttributes(FeatureTable);
            }

            foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable)
            {
                ICSharpClass Class = Entry.Value;
                Class.CreateDelegates();
            }

            ICSharpFeature SingledClassFeature = null;

            if (SingledGuid != Guid.Empty || SingledGuid == Guid.Empty)
            {
                foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable)
                {
                    ICSharpClass Class = Entry.Value;
                    if (Class.Source.ClassGuid == SingledGuid || SingledGuid == Guid.Empty || SingledGuid != Guid.Empty)
                    {
                        foreach (ICSharpFeature Feature in Class.FeatureList)
                        {
                            if (Feature is ICSharpFeatureWithName AsWithName && AsWithName.Name == SingledName)
                            {
                                SingledClassFeature = Feature;
                                break;
                            }
                        }
                    }

                    if (SingledClassFeature != null)
                    {
                        break;
                    }
                }
            }

            if (SingledClassFeature == null)
            {
                foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable)
                {
                    ICSharpClass Class = Entry.Value;
                    Class.SetWriteDown();

                    foreach (ICSharpFeature Feature in Class.FeatureList)
                    {
                        Feature.SetWriteDown();
                    }

                    foreach (ICSharpAssertion Invariant in Class.InvariantList)
                    {
                        Invariant.SetWriteDown();
                    }
                }
            }
            else
            {
                SingledClassFeature.SetWriteDown();
            }

            if (!Directory.Exists(OutputRootFolder))
            {
                Directory.CreateDirectory(OutputRootFolder);
            }

            foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable)
            {
                ICSharpClass Class = Entry.Value;
                if (!CSharpClass.IsLanguageClass(Class.Source) && !IsClassFromLibrary(Class.Source))
                {
                    if (Class.WriteDown)
                    {
                        Class.Write(OutputRootFolder, Namespace, SourceFileName, SingledClassFeature);
                    }
                }
            }
        }
Ejemplo n.º 25
0
        private static bool IsDirectOrNotMainParentFeature(IFeatureInstance instance, ICSharpClass cSharpClass)
        {
            IClass Owner = instance.Owner;

            // Feature directly implemented in the class?
            if (Owner == cSharpClass.Source)
            {
                return(true);
            }

            while (cSharpClass.BaseClass != null)
            {
                cSharpClass = cSharpClass.BaseClass;

                // Feature implemented in one of the base classes?
                if (Owner == cSharpClass.Source)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CSharpTypedef"/> class.
 /// </summary>
 /// <param name="context">The creation context.</param>
 /// <param name="source">The Easly node from which the C# node is created.</param>
 /// <param name="embeddingClass">The class where the C# node is created.</param>
 protected CSharpTypedef(ICSharpContext context, ITypedef source, ICSharpClass embeddingClass)
     : base(source)
 {
     Name = ((IName)source.EntityName).ValidText.Item;
     Type = CSharpType.Create(context, source.ResolvedDefinedType.Item);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Create a new C# inheritance.
 /// </summary>
 /// <param name="source">The Easly node from which the C# node is created.</param>
 /// <param name="ancestorClass">The ancestor class.</param>
 public static ICSharpInheritance Create(IInheritance source, ICSharpClass ancestorClass)
 {
     return(new CSharpInheritance(source, ancestorClass));
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CSharpQueryOverload"/> class.
        /// </summary>
        /// <param name="context">The creation context.</param>
        /// <param name="source">The Easly node from which the C# node is created.</param>
        /// <param name="parentFeature">The parent feature.</param>
        /// <param name="owner">The class where the overload is declared.</param>
        protected CSharpQueryOverload(ICSharpContext context, IQueryOverload source, ICSharpFeature parentFeature, ICSharpClass owner)
            : base(source)
        {
            ParentFeature = parentFeature;

            foreach (IParameter Parameter in source.ParameterTable)
            {
                ICSharpParameter NewParameter = CSharpParameter.Create(context, Parameter, owner);
                ParameterList.Add(NewParameter);
            }

            foreach (IParameter Result in source.ResultTable)
            {
                ICSharpParameter NewResult = CSharpParameter.Create(context, Result, owner);
                ResultList.Add(NewResult);
            }

            Body = CSharpBody.Create(context, parentFeature, source.ResolvedBody.Item);
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Create a new C# overload.
 /// </summary>
 /// <param name="context">The creation context.</param>
 /// <param name="source">The Easly node from which the C# node is created.</param>
 /// <param name="parentFeature">The parent feature.</param>
 /// <param name="owner">The class where the overload is declared.</param>
 public static ICSharpQueryOverload Create(ICSharpContext context, IQueryOverload source, ICSharpFeature parentFeature, ICSharpClass owner)
 {
     return(new CSharpQueryOverload(context, source, parentFeature, owner));
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Create a new C# constructor.
 /// </summary>
 /// <param name="owner">The class where the feature is declared.</param>
 /// <param name="instance">The source feature instance.</param>
 /// <param name="source">The source Easly feature.</param>
 public static ICSharpCreationFeature Create(ICSharpClass owner, IFeatureInstance instance, ICreationFeature source)
 {
     return(new CSharpCreationFeature(owner, instance, source));
 }