Ejemplo n.º 1
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);
                    }
                }
            }
        }