Ejemplo n.º 1
0
        private static void DefineDebugCollectionView(AbcGenerator generator, AbcInstance instance)
        {
            var name = generator.Abc.DefineName(QName.Global(DebugPropertyPrefix + "collection$view"));

            if (instance.FindSuperTrait(name, AbcTraitKind.Getter) != null)
            {
                return;
            }

            if (IsDictionary(generator, instance.Type))
            {
                instance.DefineMethod(
                    Sig.get(DebugPropertyPrefix + "dictionary$marker", AvmTypeCode.Boolean),
                    code =>
                {
                    code.PushNativeBool(true);
                    code.ReturnValue();
                });
            }

            instance.DefineMethod(
                Sig.get(name, AvmTypeCode.Array),
                code =>
            {
                var m = generator.Corlib.GetMethod(CompilerMethodId.ToArray);
                code.Getlex(m);
                code.LoadThis();
                code.Call(m);
                code.ReturnValue();
            });
        }
Ejemplo n.º 2
0
        private static AbcMethod GetHashCodeDic(AbcGenerator generator)
        {
            var instance = generator.RuntimeImpl.Instance;

            var dicType = generator.Abc.DefineName(QName.Package("flash.utils", "Dictionary"));
            var dic     = instance.DefineStaticSlot("hcdic$", dicType);

            return(instance.DefineMethod(
                       Sig.@static("get_hashcode_dic", dicType),
                       code =>
            {
                code.LoadThis();
                code.GetProperty(dic);
                var br = code.IfNotNull();

                code.LoadThis();
                code.CreateInstance(dicType);
                code.SetProperty(dic);

                br.BranchTarget = code.Label();
                code.LoadThis();
                code.GetProperty(dic);
                code.ReturnValue();
            }));
        }
Ejemplo n.º 3
0
 private static bool IsCollection(AbcGenerator generator, IType type)
 {
     if (type == null)
     {
         return(false);
     }
     if (type.TypeKind != TypeKind.Class)
     {
         return(false);
     }
     if (type.Is(SystemTypeCode.String))
     {
         return(false);
     }
     if (type.Is(SystemTypeCode.Array))
     {
         return(false);
     }
     if (type.Implements(generator.Corlib.GetType(CorlibTypeId.IEnumerable)))
     {
         //TODO: Do extra filter
         return(true);
     }
     return(false);
 }
Ejemplo n.º 4
0
        private static bool DefineDebuggerDisplay(AbcGenerator generator, IType type, AbcInstance instance, ICustomAttribute attr)
        {
            if (attr.Arguments.Count != 1)
            {
                return(false);
            }
            var display = attr.Arguments[0].Value as string;

            if (string.IsNullOrEmpty(display))
            {
                return(false);
            }
            if (!display.CheckFormatBraceBalance())
            {
                CompilerReport.Add(Warnings.InvalidDebuggerDisplayString, display);
                return(false);
            }

            var name = generator.Abc.DefineName(QName.Global(DebugPropertyPrefix + "display$exp"));

            //TODO: Parse display string to build string
            var m = instance.DefineMethod(
                Sig.get(name, AvmTypeCode.String),
                code =>
            {
                code.PushString(display);
                code.ReturnValue();
            });

            m.Trait.IsVirtual  = !type.IsSealed;
            m.Trait.IsOverride = instance.FindSuperTrait(name, AbcTraitKind.Getter) != null;

            return(true);
        }
Ejemplo n.º 5
0
        public static AbcMethod StaticCopy(AbcGenerator generator, IType type)
        {
            if (!type.SupportsCopyMethods())
            {
                return(null);
            }
            var instance = generator.TypeBuilder.BuildInstance(type);

            return(StaticCopy(instance));
        }
Ejemplo n.º 6
0
 private static bool IsDictionary(AbcGenerator generator, IType type)
 {
     if (type == null)
     {
         return(false);
     }
     if (type.TypeKind != TypeKind.Class)
     {
         return(false);
     }
     return(type.Implements(generator.Corlib.GetType(CorlibTypeId.IDictionary)));
 }
Ejemplo n.º 7
0
        void GenerateApplicationFrame()
        {
            Swf.FrameCount++;

            var g = new AbcGenerator {
                SwfCompiler = this
            };
            var abc = g.Generate(AppAssembly);

            if (IsSwc)
            {
                var symTable = new SwfTagSymbolClass();

                CreateScripts(abc, symTable);

                if (symTable.Symbols.Count > 0)
                {
                    Swf.Tags.Add(symTable);
                }
            }
            else
            {
                var rootName = IsFlexApplication ? _flexAppType.FullName : g.RootSprite.Instance.FullName;

                //label should be the same as root name
                Swf.SetFrameLabel(rootName);

                if (g.IsNUnit)
                {
                    GenerateHtmlWrapper = false;
                }

                var symTable = new SwfTagSymbolClass();
                //see http://bugs.adobe.com/jira/browse/ASC-3235
                AddAbcTag(abc);
                Assets.ImportLateAssets();
                Assets.FlushAssets(symTable);

                //NOTE: In MX application root sprite is autogenerated subclass of mx.managers.SystemManager.
                if (!IsFlexApplication)
                {
                    //define symbol for root sprite
                    symTable.AddSymbol(0, rootName);
                }

                if (symTable.Symbols.Count > 0)
                {
                    Swf.Tags.Add(symTable);
                }
            }

            Swf.ShowFrame();
        }
Ejemplo n.º 8
0
        private static void DefineDebuggerDisplay(AbcGenerator generator, IType type, AbcInstance instance)
        {
            if (type.IsInterface)
            {
                return;
            }
            if (type.Is(SystemTypeCode.Object))
            {
                return;
            }
            if (type.Is(SystemTypeCode.String))
            {
                return;
            }
            if (type.Is(SystemTypeCode.Array))
            {
                return;
            }

            //MSDN: DebuggerDisplay attribute takes precedence over the ToString() override
            var attr = type.FindAttribute(Attrs.DebuggerDisplay);

            if (attr != null)
            {
                if (DefineDebuggerDisplay(generator, type, instance, attr))
                {
                    return;
                }
            }

            //Use ToString
            var toString = type.Methods.Find(Const.Object.MethodToString, 0);

            if (toString != null)
            {
                var tostr = generator.MethodBuilder.BuildAbcMethod(toString);

                var name = generator.Abc.DefineName(QName.Global(DebugPropertyPrefix + "display"));

                var m = instance.DefineMethod(
                    Sig.get(name, AvmTypeCode.String),
                    code =>
                {
                    code.LoadThis();                         // this might be redundant --olegz
                    code.Call(tostr);
                    code.ReturnValue();
                });

                // as soon the method will be overridden in descendants we have to mark it as virtual (case 147084)
                m.Trait.IsVirtual  = !type.IsSealed;
                m.Trait.IsOverride = instance.FindSuperTrait(name, AbcTraitKind.Getter) != null;
            }
        }
Ejemplo n.º 9
0
        public static void Build(AbcGenerator generator, IType type, AbcInstance instance)
        {
            if (!GlobalSettings.EmitDebugInfo)
            {
                return;
            }
            if (!GlobalSettings.EmitDebugDisplay)
            {
                return;
            }

            DefineDebuggerDisplay(generator, type, instance);

            if (IsCollection(generator, type))
            {
                DefineDebugCollectionView(generator, instance);
            }
        }
Ejemplo n.º 10
0
        public static AbcMethod CalcHashCode(AbcGenerator generator)
        {
            var instance = generator.RuntimeImpl.Instance;

            return(instance.DefineMethod(
                       Sig.@static("get_hash_code", AvmTypeCode.Int32, AvmTypeCode.Object),
                       code =>
            {
                var getDic = GetHashCodeDic(generator);

                const int varKey = 1;
                const int varDic = 2;
                const int varHC = 3;

                code.PushInt(0);
                code.SetLocal(varHC);

                code.LoadThis();
                code.Call(getDic);
                code.SetLocal(varDic);

                code.GetLocal(varDic);
                code.GetLocal(varKey);
                code.GetNativeArrayItem();                         //[]
                code.CoerceInt32();
                code.SetLocal(varHC);

                code.GetLocal(varHC);
                code.PushInt(0);
                var br = code.IfNotEquals();

                code.GetLocal(varDic);
                code.GetLocal(varKey);
                code.CallStatic(generator.Corlib.GetMethod(ObjectMethodId.NewHashCode));
                code.SetLocal(varHC);
                code.GetLocal(varHC);
                code.SetNativeArrayItem();                         //dic[key] = value

                br.BranchTarget = code.Label();
                code.GetLocal(varHC);
                code.ReturnValue();
            }));
        }
Ejemplo n.º 11
0
        public CodeProviderImpl(AbcGenerator gen, AbcMethod abcMethod)
        {
            _generator = gen;
            _abc       = gen.Abc;
            _method    = abcMethod.Method;
            _body      = abcMethod.Body;
            _declType  = _method.DeclaringType;

            _asStatic = _method.AsStaticCall();

            //This code enshures initial capacity for local registers
            _body.LocalCount = _method.Parameters.Count + 1;
            var body = _method.Body;

            if (body == null)
            {
                throw new InvalidOperationException("method has no body");
            }

            if (HasPseudoThis)
            {
                _body.LocalCount++;
            }

            int n = VarCount;

            if (n == 0)
            {
                //NOTE: AVM constraint for LocalCount
                //if (local_count < info->param_count+1)
                //{
                // must have enough locals to hold all parameters including this
                //toplevel->throwVerifyError(kCorruptABCError);
                //}
                _body.LocalCount++;
            }
            else
            {
                _body.LocalCount += n;
            }
        }
Ejemplo n.º 12
0
 public StaticCtorsImpl(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 13
0
 public PtrManager(AbcGenerator generator)
 {
     _generator = generator;
     _slotPtrs  = new SlotPointers(generator);
 }
Ejemplo n.º 14
0
 public NUnitRunner(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 15
0
 public ArrayTypeImpl(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 16
0
 public FlexAppBuilder(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 17
0
 public ObjectTypeImpl(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 18
0
 public EmbeddedAssetBuilder(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 19
0
 public OperatorBuilder(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 20
0
 public ScriptBuilder(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 21
0
 public AssemblyTypeImpl(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 22
0
 public DelegatesImpl(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 23
0
 public StringPrototypeImpl(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 24
0
 public FieldBuilder(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 25
0
 public BoxingImpl(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 26
0
 public TypeBuilder(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 27
0
 public ReflectionImpl(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 28
0
 public EnvironmentTypeImpl(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 29
0
 public ElemPtr(AbcGenerator generator)
 {
     _generator = generator;
 }
Ejemplo n.º 30
0
 public ConsoleTypeImpl(AbcGenerator generator)
 {
     _generator = generator;
 }