示例#1
0
        protected override EP_VP1 Visit(SetProperty node)
        {
            Constant           c, c1;
            FunctionDefinition fd;
            Variable           f;

            EP_Compiler.Merker m;
            EP_Compiler.Scope  sc;
            Call ca;

            if ((f = node.Source as Variable) != null && (m = _compiler.GetMerker(f.Descriptor)).type == EP_Type.REFERENCE)
            {
                sc = m.scope;
            }
            else if (node.Source is This)
            {
                sc = _compiler.cur;
                while (sc.fm.type != EP_Type.CLASS)
                {
                    sc = sc._parent;
                    if (sc == null)
                    {
                        sc = _compiler.cur;
                        break;
                    }
                }
            }
            else
            {
                throw new NotSupportedException(node.Source.ToString() + " as object");
            }
            if ((c = node.FieldName as Constant) == null || c.Value == null || c.Value.ValueType != JSValueType.String)
            {
                throw new NotSupportedException(node.Source.ToString() + "." + node.FieldName.ToString() + " as FieldName");
            }

            if ((ca = node.Value as Call) != null && (f = ca.Children[0] as Variable) != null)
            {
                EP_Type t;
                switch (f.Name)
                {
                case "Boolean":
                    t = EP_Type.PropB1;
                    break;

                case "Int8":
                    t = EP_Type.PropS1;
                    break;

                case "UInt8":
                    t = EP_Type.PropU1;
                    break;

                case "Int16":
                    t = EP_Type.PropS2;
                    break;

                case "UInt16":
                    t = EP_Type.PropU2;
                    break;

                case "Int32":
                    t = EP_Type.PropS4;
                    break;

                default:
                    t = EP_Type.NONE;
                    break;
                }
                if (t == EP_Type.NONE && ca.CallMode == CallMode.Construct)
                {
                    throw new NotSupportedException("enclosed constructor" + node.ToString());
                }
                else
                {
                    if (t == EP_Type.NONE)
                    {
                        t = EP_Type.PropS4;
                    }
                    sc.GetProperty(c.Value.ToString(), t);
                }
            }
            else if ((c1 = node.Value as Constant) != null && c1.Value != null && c1.Value.ValueType == JSValueType.Boolean)
            {
                sc.GetProperty(c.Value.ToString(), EP_Type.PropB1);
            }
            else if ((fd = node.Value as FunctionDefinition) != null)
            {
                m = sc.GetProperty(c.Value.ToString(), EP_Type.FUNCTION);
                DefineFunction(fd, m, sc.memory);
            }
            else
            {
                node.Value.Visit(this);
                sc.GetProperty(c.Value.ToString(), EP_Type.PropS4);
            }
            return(this);
        }