Пример #1
0
        public void WriteTraitsInfo(TraitsInfo value)
        {
            WriteU30(value.Name.Index);
            WriteByte((Byte)((Byte)(value.Attributes) << 4 | (Byte)value.Kind));

            switch (value.Kind)
            {
            case TraitKind.Slot:
            case TraitKind.Const:
                TraitField traitField = value.TraitField;
                WriteU30(traitField.SlotId);
                WriteU30(traitField.TypeName == null ? 0 : traitField.TypeName.Index);
                WriteU30(traitField.ValueIndex);
                if (traitField.ValueIndex > 0)
                {
                    WriteByte((Byte)traitField.ValueKind);
                }
                break;

            case TraitKind.Method:
                TraitMethod traitMethod = value.TraitMethod;
                WriteU30(traitMethod.DispId);
                WriteU30(traitMethod.Method.Index);
                break;

            case TraitKind.Getter:
                TraitGetter traitGetter = value.Trait as TraitGetter;
                WriteU30(traitGetter.DispId);
                WriteU30(traitGetter.Method.Index);
                break;

            case TraitKind.Setter:
                TraitSetter traitSetter = value.Trait as TraitSetter;
                WriteU30(traitSetter.DispId);
                WriteU30(traitSetter.Method.Index);
                break;

            case TraitKind.Class:
                TraitClass traitClass = value.Trait as TraitClass;
                WriteU30(traitClass.SlotId);
                WriteU30(traitClass.Class.Index);
                break;

            case TraitKind.Function:
                TraitFunction traitFunction = value.Trait as TraitFunction;
                WriteU30(traitFunction.SlotId);
                WriteU30(traitFunction.Function.Index);
                break;



            default:
                throw new ArgumentOutOfRangeException();
            }

            if (value.Attributes.HasFlag(TraitAttributes.Metadata))
            {
                WriteU30Array(value.MetadataArray, true);
            }
        }
Пример #2
0
        public ClassInfo ReadClassInfo(Abc abc, uint index)
        {
            ClassInfo result = new ClassInfo(index);

            result.StaticInitializer = abc.MethodArray[ReadU30()];
            TraitsInfo[] traits = new TraitsInfo[ReadU30()];
            for (uint i = 0; i < traits.Length; i++)
            {
                traits[i] = ReadTraitsInfo(abc);
            }
            result.TraitsArray = new TraitsArray(traits.ToList());
            return(result);
        }
Пример #3
0
        public InstanceInfo ReadInstanceInfo(Abc abc, uint index)
        {
            InstanceInfo result = new InstanceInfo(index);

            result.Name      = abc.ConstantPool.GetMultinameAt(ReadU30());
            result.Supername = abc.ConstantPool.GetMultinameAt(ReadU30());

            result.Flags = (InstanceFlags)ReadByte();
            if (result.Flags.HasFlag(InstanceFlags.ProtectedNs))
            {
                result.ProtectedNamespace = abc.ConstantPool.GetNamespaceAt(ReadU30());
            }
            result.InterfaceArray      = ReadU30Array(ReadU30());
            result.InstanceInitializer = abc.MethodArray[ReadU30()];
            TraitsInfo[] traits = new TraitsInfo[ReadU30()];
            for (uint i = 0; i < traits.Length; i++)
            {
                traits[i] = ReadTraitsInfo(abc);
            }
            result.TraitsArray = new TraitsArray(traits.ToList());
            return(result);
        }
Пример #4
0
        public bool IsMatch(TraitsInfo info)
        {
            if (info.Kind == Kind)
            {
                switch (Kind)
                {
                case TraitKind.Slot:
                case TraitKind.Const:
                    if (TypeName == info.TraitField.GetTypeName())
                    {
                        return(true);
                    }
                    break;

                case TraitKind.Method:
                    if (TypeName == info.TraitMethod.Method.GetReturnTypeName())
                    {
                        return(true);
                    }
                    break;

                case TraitKind.Getter:
                    return(true);

                case TraitKind.Setter:
                    return(true);

                case TraitKind.Class:
                    return(true);

                case TraitKind.Function:
                    return(true);
                }
            }

            return(false);
        }
Пример #5
0
        public MethodBodyInfo ReadMethodBodyInfo(Abc abc, uint index)
        {
            MethodBodyInfo result = new MethodBodyInfo(index);

            result.Method         = abc.MethodArray[ReadU30()];
            result.MaxStack       = ReadU30();
            result.LocalCount     = ReadU30();
            result.MinScopeDepth  = ReadU30();
            result.MaxScopeDepth  = ReadU30();
            result.Code           = ReadBytes((int)ReadU30());
            result.ExceptionArray = new ExceptionInfo[ReadU30()];
            for (int i = 0; i < result.ExceptionArray.Length; i++)
            {
                result.ExceptionArray[i] = ReadExceptionInfo();
            }

            TraitsInfo[] traits = new TraitsInfo[ReadU30()];
            for (int i = 0; i < traits.Length; i++)
            {
                traits[i] = ReadTraitsInfo(abc);
            }
            result.TraitsArray = new TraitsArray(traits);
            return(result);
        }
Пример #6
0
        public TraitsInfo ReadTraitsInfo(Abc abc)
        {
            TraitsInfo result = new TraitsInfo();

            result.Name = abc.ConstantPool.GetMultinameAt(ReadU30());
            byte kindAndAttribute = ReadByte();

            result.Kind       = (TraitKind)(kindAndAttribute & 0xf);
            result.Attributes = (TraitAttributes)(kindAndAttribute >> 4);

            switch (result.Kind)
            {
            case TraitKind.Slot:
            case TraitKind.Const:
                var traitField = new TraitField();
                traitField.SlotId     = ReadU30();
                traitField.TypeName   = abc.ConstantPool.GetMultinameAt(ReadU30());
                traitField.ValueIndex = ReadU30();
                if (traitField.ValueIndex > 0)
                {
                    traitField.ValueKind = (ValueKind)ReadByte();
                }
                result.Trait = traitField;
                break;

            case TraitKind.Method:
                var traitMethod = new TraitMethod();
                traitMethod.DispId = ReadU30();
                traitMethod.Method = abc.MethodArray[ReadU30()];
                result.Trait       = traitMethod;
                break;

            case TraitKind.Getter:
                var traitGetter = new TraitGetter();
                traitGetter.DispId = ReadU30();
                traitGetter.Method = abc.MethodArray[ReadU30()];
                result.Trait       = traitGetter;
                break;

            case TraitKind.Setter:
                var traitSetter = new TraitSetter();
                traitSetter.DispId = ReadU30();
                traitSetter.Method = abc.MethodArray[ReadU30()];
                result.Trait       = traitSetter;
                break;

            case TraitKind.Class:
                var traitClass = new TraitClass();
                traitClass.SlotId = ReadU30();
                traitClass.Class  = abc.AbcClassArray[ReadU30()].ClassInfo;
                result.Trait      = traitClass;
                break;

            case TraitKind.Function:
                var traitFunction = new TraitFunction();
                traitFunction.SlotId   = ReadU30();
                traitFunction.Function = abc.MethodArray[ReadU30()];
                result.Trait           = traitFunction;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            if (result.Attributes.HasFlag(TraitAttributes.Metadata))
            {
                result.MetadataArray = ReadU30Array(ReadU30());
            }
            return(result);
        }