コード例 #1
0
ファイル: Abc.cs プロジェクト: nagyist/mkbiltek.flashdevelop
        private void parseTraits(BinaryReader br, Traits t)
        {
            int namecount = readU32(br);

            for (int i = 0; i < namecount; i++)
            {
                QName       name   = (QName)names[readU32(br)];
                byte        tag    = br.ReadByte();
                TraitMember kind   = (TraitMember)((byte)tag & 0xf);
                MemberInfo  member = null;
                switch (kind)
                {
                case TraitMember.Slot:
                case TraitMember.Const:
                case TraitMember.Class:
                    SlotInfo slot = new SlotInfo();
                    member  = slot as MemberInfo;
                    slot.id = readU32(br);
                    t.slots.Add(slot);
                    //t.slots[slot.id] = slot
                    if (kind == TraitMember.Slot || kind == TraitMember.Const)
                    {
                        slot.type = (QName)names[readU32(br)];
                        int index = readU32(br);
                        if (index > 0)
                        {
                            slot.value = getDefaultValue((ConstantKind)br.ReadByte(), index);
                        }
                    }
                    else                         // (kind == TraitMember.Class)
                    {
                        slot.value = classes[readU32(br)];
                    }
                    break;

                case TraitMember.Method:
                case TraitMember.Getter:
                case TraitMember.Setter:
                    int        disp_id = readU32(br);
                    MethodInfo method  = methods[readU32(br)];
                    member = method as MemberInfo;
                    //t.methods[disp_id] = method;
                    t.methods.Add(method);
                    method.id = disp_id;
                    //Console.WriteLine("\t" + kind + " " + name + " " + disp_id + " " + method);
                    break;
                }

                if (member == null)
                {
                    Console.WriteLine("-- Error trait kind " + kind + "\n");
                }
                member.kind = kind;
                member.name = name;
                //t.members[i] = member;
                t.members.Add(member);
                t.names[name] = member;

                Attribute attr = (Attribute)(tag >> 4);
                if ((attr & Attribute.Metadata) > 0)
                {
                    member.metadata = new List <MetaData>();
                    int mdCount = readU32(br);
                    for (int j = 0; j < mdCount; ++j)
                    {
                        member.metadata.Add((MetaData)metadata[readU32(br)]);
                    }
                }
            }
        }
コード例 #2
0
ファイル: Abc.cs プロジェクト: nagyist/mkbiltek.flashdevelop
        private void parseMethodInfos(BinaryReader br)
        {
            long start = br.BaseStream.Position;

            names[0] = new QName(publicNs, "*");
            int method_count = readU32(br);

            methods = new MethodInfo[method_count];

            for (int i = 0; i < method_count; i++)
            {
                MethodInfo m = new MethodInfo();
                methods[i] = m;
                int param_count = readU32(br);
                m.returnType = (QName)names[readU32(br)];
                m.paramTypes = new QName[param_count];
                for (int j = 0; j < param_count; j++)
                {
                    m.paramTypes[j] = (QName)names[readU32(br)];
                }
                m.debugName = (string)strings[readU32(br)];
                m.flags     = (MethodFlags)br.ReadSByte();

                if ((m.flags & MethodFlags.NeedRest) > 0)
                {
                    QName[] temp = m.paramTypes;
                    m.paramTypes = new QName[param_count + 1];
                    temp.CopyTo(m.paramTypes, 0);
                    m.paramTypes[param_count] = new QName("Array");
                }
                if ((m.flags & MethodFlags.HasOptional) > 0)
                {
                    // has_optional
                    int optional_count = readU32(br);
                    if ((m.flags & MethodFlags.NeedRest) > 0)
                    {
                        m.optionalValues = new object[optional_count + 1];
                        m.optionalValues[optional_count] = null;
                    }
                    else
                    {
                        m.optionalValues = new object[optional_count];
                    }
                    for (int k = 0; k < optional_count; k++)
                    {
                        int          index = readU32(br);                   // optional value index
                        ConstantKind kind  = (ConstantKind)br.ReadSByte();  // kind byte for each default value
                        if (index == 0)
                        {
                            // kind is ignored, default value is based on type
                            m.optionalValues[k] = null;
                        }
                        else
                        {
                            m.optionalValues[k] = getDefaultValue(kind, index);
                        }
                    }
                }
                if ((m.flags & MethodFlags.HasParamNames) > 0)
                {
                    // has_paramnames
                    if ((m.flags & MethodFlags.NeedRest) > 0)
                    {
                        m.paramNames = new string[param_count + 1];
                        m.paramNames[param_count] = "...rest";
                    }
                    else
                    {
                        m.paramNames = new string[param_count];
                    }
                    for (int k = 0; k < param_count; k++)                   //++k)
                    {
                        int index = readU32(br);
                        if (index < strings.Length && strings[index] != null)
                        {
                            m.paramNames[k] = (string)strings[index];
                        }
                    }
                }
            }
            //Console.WriteLine("MethodInfo count " +method_count+ " size "+(br.BaseStream.Position-start)+" "+(int)(100*(br.BaseStream.Position-start)/br.BaseStream.Length)+" %");
        }
コード例 #3
0
ファイル: Abc.cs プロジェクト: nagyist/mkbiltek.flashdevelop
 public QName(QName qname)
 {
     this.localName = qname.localName;
 }
コード例 #4
0
ファイル: Abc.cs プロジェクト: nagyist/mkbiltek.flashdevelop
        private void parseCpool(BinaryReader br)
        {
            long start = br.BaseStream.Position;
            int  n;

            // ints
            n    = readU32(br);
            ints = new int[n];
            if (n > 0)
            {
                ints[0] = 0;
            }
            for (int i = 1; i < n; i++)
            {
                ints[i] = readU32(br);
            }

            // uints
            n     = readU32(br);
            uints = new uint[n];
            if (n > 0)
            {
                uints[0] = 0;
            }
            for (int i = 1; i < n; i++)
            {
                uints[i] = (uint)readU32(br);
            }

            // doubles
            n       = readU32(br);
            doubles = new double[n];
            if (n > 0)
            {
                doubles[0] = double.NaN;
            }
            for (int i = 1; i < n; i++)
            {
                doubles[i] = br.ReadDouble();
            }

            // sb.append("Cpool numbers size "+(data.position-start)+" "+int(100*(data.position-start)/data.length)+" %")
            //Console.WriteLine("Cpool numbers size " + (br.BaseStream.Position - start) + " " + (int)(100 * (br.BaseStream.Position - start) / br.BaseStream.Length) + " %");
            start = br.BaseStream.Position;

            // strings
            n       = readU32(br);
            strings = new string[n];
            if (n > 0)
            {
                strings[0] = "";
            }
            for (int i = 1; i < n; i++)
            {
                strings[i] = readUTFBytes(br); //br.ReadString()
            }
            // sb.append("Cpool strings count "+ n +" size "+(data.position-start)+" "+int(100*(data.position-start)/data.length)+" %")
            //Console.WriteLine("Cpool strings count " + n + " size " + (br.BaseStream.Position - start) + " " + (int)(100 * (br.BaseStream.Position - start) / br.BaseStream.Length) + " %");
            start = br.BaseStream.Position;

            // namespaces
            n          = readU32(br);
            namespaces = new Namespace[n];
            if (n > 0)
            {
                namespaces[0] = publicNs;
            }
            for (int i = 1; i < n; i++)
            {
                switch ((ConstantKind)br.ReadSByte())
                {
                case ConstantKind.Namespace:
                case ConstantKind.PackageNs:
                case ConstantKind.PackageInternalNs:
                case ConstantKind.ProtectedNs:
                case ConstantKind.StaticProtectedNs:
                case ConstantKind.StaticProtectedNs2:
                    namespaces[i] = new Namespace((string)strings[readU32(br)]);
                    // todo mark kind of namespace.
                    break;

                case ConstantKind.PrivateNs:
                    readU32(br);
                    namespaces[i] = new Namespace(null, "private");
                    break;
                }
            }

            //Console.WriteLine("Cpool namespaces count "+ n +" size "+(br.BaseStream.Position-start)+" "+(int)(100*(br.BaseStream.Position-start)/br.BaseStream.Length)+" %");
            start = br.BaseStream.Position;

            // namespace sets
            n      = readU32(br);
            nssets = new Namespace[n][];
            if (n > 0)
            {
                nssets[0] = null;
            }
            for (int i = 1; i < n; i++)
            {
                int         count = readU32(br);
                Namespace[] nsset = new Namespace[count];
                nssets[i] = nsset;
                for (int j = 0; j < count; j++)
                {
                    nsset[j] = (Namespace)namespaces[readU32(br)];
                }
            }

            //Console.WriteLine("Cpool nssets count "+ n +" size "+(br.BaseStream.Position-start)+" "+(int)(100*(br.BaseStream.Position-start)/br.BaseStream.Length)+" %");
            start = br.BaseStream.Position;

            // multinames
            n     = readU32(br);
            names = new QName[n];
            if (n > 0)
            {
                names[0] = null;
            }
            namespaces[0] = anyNs;
            strings[0]    = "*";
            for (int i = 1; i < n; i++)
            {
                switch ((ConstantKind)br.ReadSByte())
                {
                case ConstantKind.Qname:
                case ConstantKind.QnameA:
                    names[i] = new QName((Namespace)namespaces[readU32(br)], (string)strings[readU32(br)]);
                    break;

                case ConstantKind.RTQname:
                case ConstantKind.RTQnameA:
                    names[i] = new QName((string)strings[readU32(br)]);
                    break;

                case ConstantKind.RTQnameL:
                case ConstantKind.RTQnameLA:
                    names[i] = null;
                    break;

                case ConstantKind.NameL:
                case ConstantKind.NameLA:
                    names[i] = new QName(new Namespace(""), null);
                    break;

                case ConstantKind.Multiname:
                case ConstantKind.MultinameA:
                    string localName = (string)strings[readU32(br)];
                    names[i] = new Multiname((Namespace[])nssets[readU32(br)], localName);
                    break;

                case ConstantKind.MultinameL:
                case ConstantKind.MultinameLA:
                    names[i] = new Multiname((Namespace[])nssets[readU32(br)], null);
                    break;

                case ConstantKind.TypeName:
                    QName   name       = (QName)names[readU32(br)] ?? new QName("Vector");
                    int     count      = readU32(br);
                    QName[] parameters = new QName[count];
                    for (int j = 0; j < count; ++j)
                    {
                        int idx = readU32(br);
                        parameters[j] = (QName)names[idx] ?? new QName("*");
                    }
                    names[i] = new ParameterizedQName(name, parameters);
                    break;

                default:
                    br.BaseStream.Position--;
                    Console.WriteLine("-- Error: Invalid constant kind [" + br.ReadSByte() + "]");
                    break;
                }
            }

            //Console.WriteLine("Cpool names count " + n + " size " + (br.BaseStream.Position - start) + " " + (int)(100 * (br.BaseStream.Position - start) / br.BaseStream.Length) + " %");

            namespaces[0] = publicNs;
            strings[0]    = "*";
        }
コード例 #5
0
ファイル: Abc.cs プロジェクト: nagyist/mkbiltek.flashdevelop
 public ParameterizedQName(QName name, QName[] parameters)
     : base(name.localName)
 {
     this.parameters = parameters;
 }