예제 #1
0
        /// <summary>
        /// Finally walk all members of the classes and interfaces. Methods etc. are defined here
        /// </summary>
        public void WalkClassMembers()
        {
            CheckerException exc     = new CheckerException();
            bool             hasMain = false;

            for (int i = 0; i < reorderedTypes.Count; i++)
            {
                TreeNode n = reorderedTypes[i];
                currentType = (UserType)n.Entry.ReflectionObject;
                searchPath  = (List <string>)((TreeNode)n.Parent.Parent).Entry.ReflectionObject;
                this.searchPath.Add(currentType.Namespace);

                foreach (TreeNode n2 in n.Children)
                {
                    try
                    {
                        if (n2.Type == VnvdTreeWalker.FIELD)
                        {
                            n2.EntryType = EntryType.Variable;
                            IdEntry entry = new IdEntry();
                            entry.Node = n2;
                            string ret = n2.GetChild(1).Type == VnvdTreeWalker.FQUALIFIER
                                     ? AbstractHelper.GetFullQualifier(n2.GetChild(1)).ToString()
                                     : n2.GetChild(1).Text;
                            UserField field = DefineField(currentType, n2.GetChild(2).Text, AbstractHelper.GetModifiers(n2.GetChild(0)),
                                                          ret);
                            field.Entry            = entry;
                            entry.ReflectionObject = field;
                            n2.Entry = entry;
                        }
                        else if (n2.Type == VnvdTreeWalker.CONSTRUCTOR)
                        {
                            n2.EntryType = EntryType.Constructor;
                            IdEntry entry = new IdEntry();
                            entry.Node = n2;

                            String[] parNames = AbstractHelper.GetParameterNames(n2.GetChild(2));
                            String[] parTypes = AbstractHelper.GetParameterTypes(n2.GetChild(2));

                            UserConstructor cons = DefineConstructor(currentType, AbstractHelper.GetModifiers(n2.GetChild(0)), parTypes, parNames);
                            cons.Entry             = entry;
                            entry.ReflectionObject = cons;
                            n2.Entry = entry;
                        }
                        else if (n2.Type == VnvdTreeWalker.METHOD)
                        {
                            n2.EntryType = EntryType.Method;
                            IdEntry entry = new IdEntry();
                            entry.Node = n2;

                            String[] parNames = AbstractHelper.GetParameterNames(n2.GetChild(3));
                            String[] parTypes = AbstractHelper.GetParameterTypes(n2.GetChild(3));

                            string ret = n2.GetChild(1).Type == VnvdTreeWalker.FQUALIFIER
                         ? AbstractHelper.GetFullQualifier(n2.GetChild(1)).ToString()
                         : n2.GetChild(1).Text;

                            UserMethod met = DefineMethod(currentType, n2.GetChild(2).Text, AbstractHelper.GetModifiers(n2.GetChild(0)), ret, parTypes, parNames);
                            if (met.Name.Equals(GeneratorManual.MAINMETHOD))
                            {
                                if (hasMain)
                                {
                                    throw new CheckerException(n2, "Duplicate main method.");
                                }
                                hasMain = true;
                            }
                            met.Entry = entry;
                            entry.ReflectionObject = met;
                            n2.Entry = entry;
                        }
                        else if (n2.Type == VnvdTreeWalker.IMETHOD)
                        {
                            n2.EntryType = EntryType.Method;
                            IdEntry entry = new IdEntry();
                            entry.Node = n2;

                            String[] parNames = AbstractHelper.GetParameterNames(n2.GetChild(2));
                            String[] parTypes = AbstractHelper.GetParameterTypes(n2.GetChild(2));

                            string ret = n2.GetChild(0).Type == VnvdTreeWalker.FQUALIFIER
                         ? AbstractHelper.GetFullQualifier(n2.GetChild(0)).ToString()
                         : n2.GetChild(0).Text;

                            UserMethod met = DefineInterfaceMethod(currentType, n2.GetChild(1).Text, ret, parTypes, parNames);
                            met.Entry = entry;
                            entry.ReflectionObject = met;
                            n2.Entry = entry;
                        }
                        else if (n2.Type == VnvdTreeWalker.SCONSTRUCTOR)
                        {
                            n2.EntryType = EntryType.Constructor;
                            IdEntry entry = new IdEntry();
                            entry.Node = n2;
                            UserConstructor cons = currentType.DefineTypeInitializer();
                            cons.Entry             = entry;
                            entry.ReflectionObject = cons;
                            n2.Entry = entry;
                        }
                        else if (n2.Type == VnvdTreeWalker.ENUMOPTION)
                        {
                            n2.EntryType = EntryType.Variable;
                            IdEntry entry = new IdEntry();
                            entry.Node = n2;
                            UserField option = ((UserEnum)currentType).DefineOption(n2.GetChild(0).Text);
                            option.Entry           = entry;
                            entry.ReflectionObject = option;
                            n2.Entry = entry;
                        }
                    }
                    catch (CheckerException ex)
                    {
                        exc.AddError(n2, ex.GetLastError().Second);
                    }
                    catch (InvalidOperationException ex)
                    {
                        exc.AddError(n2, ex.Message);
                    }
                    catch (SymbolTableException ex)
                    {
                        exc.AddError(n2, ex.Message);
                    }
                }

                if (currentType.IsClass && currentType.GetConstructors().Length == 0)
                {
                    UserConstructor uc = DefineConstructor(currentType, new List <string>()
                    {
                        "public"
                    }, new string[] {}, new string[] {});
                    uc.Entry = new IdEntry();
                    uc.Entry.ReflectionObject = uc;
                }

                try
                {
                    if (!currentType.IsInterface)
                    {
                        currentType.CheckInterfaces();
                    }
                }
                catch (CheckerException ex)
                {
                    exc.AddError(n, ex.GetLastError().Second);
                }

                this.searchPath.Remove(currentType.Namespace);
            }

            if (exc.ErrorCount > 0)
            {
                throw exc;
            }
        }