예제 #1
0
        private static Morpheme Analyze(Morpheme last, LogicNode current)
        {
            var name = current.ToString();

            if (last == null)
            {
                foreach (var name_space in name_spaces)
                {
                    if (name_space.name == name)
                    {
                        return(new Morpheme(name, MorphemeAttribute.Namespace, name_space, null, null));
                    }
                }
                last = @this;
            }
            switch (last.attribute)
            {
            case MorphemeAttribute.None: break;

            case MorphemeAttribute.Object:
                var @class__ = last.stmt as Class;
                foreach (var method in @class__.methods)
                {
                    if (method.name == name && (method.atttibute & ElementAtttibute.STATIC) == 0)
                    {
                        return(new Morpheme(name, MorphemeAttribute.Function, method, last.up_list, method.@return));
                    }
                }
                break;

            case MorphemeAttribute.Function:     //TODO
                break;

            case MorphemeAttribute.Class:
                var @class_ = last.stmt as Class;

                foreach (var method in @class_.methods)
                {
                    if (method.name == name)     //&& (method.atttibute & ElementAtttibute.STATIC) != 0)
                    {
                        return(new Morpheme(name, MorphemeAttribute.Function, method, last.up_list, method.@return));
                    }
                }

                foreach (var local in @class_.current_method.locals)
                {
                    if (local.name == name)
                    {
                        return(new Morpheme(name, MorphemeAttribute.Object, local, last.up_list, local.type));
                    }
                }

                //TODO field
                foreach (var variable in @class_.public_field)
                {
                    if (variable.name == name)     //&& (method.atttibute & ElementAtttibute.STATIC) != 0)
                    {
                        return(new Morpheme(name, MorphemeAttribute.Object, variable, last.up_list, variable.type));
                    }
                }

                Error(UnknownField, last.lex_line, last.lex_ch, name);
                break;

            case MorphemeAttribute.Namespace:
                var @namespace = last.stmt as Namespace;
                foreach (var name_space in @namespace.sub_spaces)
                {
                    if (name_space.name == name)
                    {
                        return(new Morpheme(name, MorphemeAttribute.Namespace, name_space, last.up_list, null));
                    }
                }
                foreach (var @class in @namespace.classes)
                {
                    if (@class.name == name)
                    {
                        return(new Morpheme(name, MorphemeAttribute.Class, @class, last.up_list, null));
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            throw new ArgumentOutOfRangeException();
        }