示例#1
0
 /// <summary>
 /// Imports given constant.
 /// </summary>
 /// <param name="c">constant to import.</param>
 /// <returns>imported constant.</returns>
 public AbcConst <T> Import(AbcConst <T> c)
 {
     if (IsDefined(c))
     {
         return(c);
     }
     return(Define(c.Value));
 }
示例#2
0
 public AbcNamespace this[AbcConst <string> name, AbcConstKind kind]
 {
     get
     {
         string key = name.MakeKey(kind);
         return(this[key]);
     }
 }
示例#3
0
 internal AbcInstance ImportInstance(AbcConst <string> name)
 {
     if (name == null || string.IsNullOrEmpty(name.Value))
     {
         return(null);
     }
     return(ImportInstance(name.Value));
 }
示例#4
0
 public AbcNamespace(AbcConst <string> name, AbcConstKind kind, string key)
 {
     if (!kind.IsNamespace())
     {
         throw new ArgumentException("Invalid namespace kind");
     }
     Name  = name;
     _kind = kind;
     _key  = key;
 }
示例#5
0
        private AbcConst <string> DefineStringOrNull(string value)
        {
            AbcConst <string> c = null;

            if (!string.IsNullOrEmpty(value))
            {
                c = DefineString(value);
            }
            return(c);
        }
示例#6
0
        /// <summary>
        /// Defines namespace with given name.
        /// </summary>
        /// <param name="kind">kind of namespace to define.</param>
        /// <param name="name">name of namespace to define.</param>
        /// <returns></returns>
        public AbcNamespace DefineNamespace(AbcConstKind kind, AbcConst <string> name)
        {
            string key = name.MakeKey(kind);
            var    ns  = Namespaces[key];

            if (ns != null)
            {
                return(ns);
            }
            ns = new AbcNamespace(name, kind, key);
            Namespaces.Add(ns);
            return(ns);
        }
示例#7
0
        /// <summary>
        /// Imports given constant.
        /// </summary>
        /// <typeparam name="T">type of constant. Can be int,uint,double,string</typeparam>
        /// <param name="c">constant to import.</param>
        /// <returns>imported constant.</returns>
        public AbcConst <T> ImportConst <T>(AbcConst <T> c)
        {
            if (c == null)
            {
                return(null);
            }
            var pool = GetConstPool(c.Kind);

            if (pool != null)
            {
                return(((AbcConstPool <T>)pool).Import(c));
            }
            return(c);
        }
示例#8
0
        public AbcConst <T> Add(T value)
        {
            int index = _list.Count;
            var c     = new AbcConst <T>(value)
            {
                Index = index
            };

            if (index != 0)
            {
                _index.Add(value, index);
            }
            _list.Add(c);
            return(c);
        }
示例#9
0
        public AbcMultiname DefineMultiname(AbcConstKind kind, AbcNamespaceSet nss, AbcConst <string> name)
        {
            string key = AbcMultiname.KeyOf(kind, nss, name);
            var    mn  = Multinames[key];

            if (mn != null)
            {
                return(mn);
            }
            mn = new AbcMultiname(kind, nss, name)
            {
                Key = key
            };
            Multinames.Add(mn);
            return(mn);
        }
示例#10
0
        private AbcConst <string> ImportType(AbcConst <string> name, out AbcInstance type)
        {
            type = null;
            if (name == null)
            {
                return(null);
            }

            if (IsImportTypeExternally)
            {
                return(ImportConst(name));
            }

            type = ImportInstance(name);

            return(ImportConst(name));
        }
示例#11
0
        public void Read(SwfReader reader)
        {
            int paramCount = (int)reader.ReadUIntEncoded();

            ReturnType = reader.ReadMultiname(); //ret_type

            //U30 param_types[param_count]
            for (int i = 0; i < paramCount; ++i)
            {
                var type = reader.ReadMultiname();
                _params.Add(new AbcParameter {
                    Type = type
                });
            }

            _name = reader.ReadAbcString(); //name_index
            Flags = (AbcMethodFlags)reader.ReadUInt8();

            if ((Flags & AbcMethodFlags.HasOptional) != 0)
            {
                int optionalCount      = (int)reader.ReadUIntEncoded();
                int firstOptionalParam = paramCount - optionalCount;
                for (int i = 0; i < optionalCount; ++i)
                {
                    int valueIndex = (int)reader.ReadUIntEncoded();
                    var valueKind  = (AbcConstKind)reader.ReadUInt8();
                    var p          = _params[firstOptionalParam + i];
                    p.Value      = reader.ABC.GetConstant(valueKind, valueIndex);
                    p.IsOptional = true;
                }
            }

            if ((Flags & AbcMethodFlags.HasParamNames) != 0)
            {
                for (int i = 0; i < paramCount; ++i)
                {
                    _params[i].Name = reader.ReadAbcString();
                }
            }
        }
示例#12
0
        private AbcMultiname ImportQName(AbcNamespace ns, AbcConst <string> name, bool isAttribute)
        {
            var    kind = isAttribute ? AbcConstKind.QNameA : AbcConstKind.QName;
            string key  = AbcMultiname.KeyOf(kind, ns, name);

            var mn = this[key];

            if (mn != null)
            {
                return(mn);
            }

            name = _abc.ImportConst(name);
            ns   = _abc.ImportConst(ns);

            mn = new AbcMultiname(kind, ns, name)
            {
                Key = key
            };

            Add(mn);
            return(mn);
        }
示例#13
0
 public static string KeyOf(AbcConstKind kind, AbcNamespaceSet nss, AbcConst <string> name)
 {
     return("{" + nss.Key + "}." + name.Value + (int)kind);
 }
示例#14
0
 public static string KeyOf(AbcConstKind kind, AbcNamespace ns, AbcConst <string> name)
 {
     return(ns.Key + "." + name.Value + (int)kind);
 }
示例#15
0
 /// <summary>
 /// Defines protected namespace with given name.
 /// </summary>
 /// <param name="name">name of namespace to define.</param>
 /// <returns></returns>
 public AbcNamespace DefineProtectedNamespace(AbcConst <string> name)
 {
     return(DefineNamespace(AbcConstKind.ProtectedNamespace, name));
 }
示例#16
0
 public void Add(AbcConst <string> key, AbcConst <string> value)
 {
     _keys.Add(key);
     _values.Add(value);
 }
示例#17
0
 public AbcParameter(AbcMultiname type, AbcConst <string> name)
 {
     Type = type;
     Name = name;
 }
示例#18
0
 public AbcNamespace(AbcConst <string> name, AbcConstKind kind)
     : this(name, kind, name.MakeKey(kind))
 {
 }
示例#19
0
 /// <summary>
 /// Defines internal namespace with given name.
 /// </summary>
 /// <param name="name">name of namespace to define.</param>
 /// <returns></returns>
 public AbcNamespace DefineInternalNamespace(AbcConst <string> name)
 {
     return(DefineNamespace(AbcConstKind.InternalNamespace, name));
 }
示例#20
0
 /// <summary>
 /// Defines package namespace with given name.
 /// </summary>
 /// <param name="name">name of namespace to define.</param>
 /// <returns></returns>
 public AbcNamespace DefinePackage(AbcConst <string> name)
 {
     return(DefineNamespace(AbcConstKind.PackageNamespace, name));
 }
示例#21
0
 public AbcMultiname(AbcConstKind kind, AbcNamespaceSet nss, AbcConst <string> name)
 {
     Kind         = kind;
     NamespaceSet = nss;
     Name         = name;
 }
示例#22
0
 public AbcMultiname(AbcConstKind kind, AbcConst <string> name)
 {
     Kind = kind;
     Name = name;
 }
示例#23
0
 public void AddParam(AbcMultiname type, AbcConst <string> name)
 {
     Parameters.Add(new AbcParameter(type, name));
 }