Esempio n. 1
0
 public AbcMultiname BuildMemberType(IType type)
 {
     Build(type);
     if (type.Data == null)
     {
         throw new InvalidOperationException(string.Format("Type {0} is not defined", type.FullName));
     }
     return(Abc.GetTypeName(type, true));
 }
Esempio n. 2
0
        public AbcMethod ToStringInterfaceImpl(IType type, bool cast)
        {
            if (type == null)
            {
                return(null);
            }

            const bool me = false;

            if (cast)
            {
                var AS = ToStringInterfaceImpl(type, false);
                return(Impl(type, AS, GetCastMethodName(type, me)));
            }

            var instance = _generator.TypeBuilder.BuildInstance(SystemTypes.String);
            var name     = GetAsMethodName(type, me);

            return(instance.DefineMethod(
                       Sig.@static(name, AvmTypeCode.Object, AvmTypeCode.Object, "value"),
                       code =>
            {
                const int value = 1;

                code.BeginAsMethod();

                code.Try();

                code.If(
                    () =>
                {
                    code.GetLocal(value);
                    //code.PushString("String");
                    //code.PushQName(code[AvmTypeCode.String]);
                    //code.Add(InstructionCode.Istypelate);
                    code.Is(AvmTypeCode.String);
                    return code.IfTrue();
                },
                    () =>
                {
                    code.GetLocal(value);
                    code.ReturnValue();
                },
                    () =>
                {
                    if (type.IsIEnumerableInstance())
                    {
                        var elemType = type.GetTypeArgument(0);

                        //check array
                        code.GetLocal(value);
                        var notArray = code.IfNotArray();

                        code.HasElemType(elemType, value);

                        var notArgArray = code.IfFalse();
                        code.GetLocal(value);
                        code.ReturnValue();

                        var label = code.Label();
                        notArgArray.BranchTarget = label;
                        notArray.BranchTarget = label;
                    }

                    code.GetLocal(value);
                    code.As(Abc.GetTypeName(type, false));
                    code.ReturnValue();
                }
                    );

                code.CatchReturnNull();
            }));
        }