Ejemplo n.º 1
0
        /// <summary>
        /// Imports given namespace.
        /// </summary>
        /// <param name="ns">namespace to import.</param>
        /// <returns>imported namespace.</returns>
        public override AbcNamespace Import(AbcNamespace ns)
        {
            if (ns == null)
            {
                return(null);
            }
            if (ns.IsAny)
            {
                return(this[0]);
            }
            if (IsDefined(ns))
            {
                return(ns);
            }

            var    name = ns.Name;
            var    kind = ns.Kind;
            string key  = name.MakeKey(kind);
            var    ns2  = this[key];

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

            name = _abc.ImportConst(name);
            ns   = new AbcNamespace(name, kind, key);
            Add(ns);
            return(ns);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Imports given namespace set.
        /// </summary>
        /// <param name="nss">namespace set to import.</param>
        /// <returns>imported namespace set.</returns>
        public override AbcNamespaceSet Import(AbcNamespaceSet nss)
        {
            if (nss == null)
            {
                return(null);
            }
            if (IsDefined(nss))
            {
                return(nss);
            }

            string key = nss.Key;
            var    set = this[key];

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

            int n          = nss.Count;
            var namespaces = new AbcNamespace[n];

            for (int i = 0; i < n; ++i)
            {
                namespaces[i] = _abc.ImportConst(nss[i]);
            }

            set = new AbcNamespaceSet(namespaces, key);
            Add(set);

            return(set);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Translates exception indecies to instruction offsets.
        /// </summary>
        internal void ResolveExceptionOffsets(AbcFile abc)
        {
            if (abc == null)
            {
                throw new ArgumentNullException("abc");
            }
            var code = IL;

            foreach (var e in Exceptions)
            {
                e.From         = code[e.From].Offset;
                e.To           = code[e.To].Offset;
                e.Target       = code[e.Target].Offset;
                e.Type         = abc.ImportConst(e.Type);
                e.VariableName = abc.ImportConst(e.VariableName);
            }
        }
Ejemplo n.º 4
0
        private AbcMultiname ImportCore(AbcMultiname item)
        {
            var kind = item.Kind;

            switch (kind)
            {
            //no data
            case AbcConstKind.RTQNameL:
            case AbcConstKind.RTQNameLA:
                return(Define(kind));
            }

            string key     = item.Key;
            var    curItem = this[key];

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

            switch (kind)
            {
            //U30 ns_index
            //U30 name_index
            case AbcConstKind.QName:
            case AbcConstKind.QNameA:
            {
                var name    = _abc.ImportConst(item.Name);
                var ns      = _abc.ImportConst(item.Namespace);
                var newItem = new AbcMultiname(kind, ns, name)
                {
                    Key = key
                };
                Add(newItem);
                return(newItem);
            }

            //U30 name_index
            case AbcConstKind.RTQName:
            case AbcConstKind.RTQNameA:
            {
                var name    = _abc.ImportConst(item.Name);
                var newItem = new AbcMultiname(kind, name)
                {
                    Key = key
                };
                Add(newItem);
                return(newItem);
            }

            //U30 name_index
            //U30 ns_set_index
            case AbcConstKind.Multiname:
            case AbcConstKind.MultinameA:
            {
                if (item.NamespaceSet.Count == 1)
                {
                    return(ImportQName(item.NamespaceSet[0], item.Name, kind == AbcConstKind.MultinameA));
                }

                var name    = _abc.ImportConst(item.Name);
                var nss     = _abc.ImportConst(item.NamespaceSet);
                var newItem = new AbcMultiname(kind, nss, name)
                {
                    Key = key
                };
                Add(newItem);
                return(newItem);
            }

            //U30 ns_set_index
            case AbcConstKind.MultinameL:
            case AbcConstKind.MultinameLA:
            {
                var nss     = _abc.ImportConst(item.NamespaceSet);
                var newItem = new AbcMultiname(kind, nss)
                {
                    Key = key
                };
                Add(newItem);
                return(newItem);
            }

            case AbcConstKind.TypeName:
            {
                var type  = Import(item.Type);
                var param = Import(item.TypeParameter);

                var newItem = new AbcMultiname(type, param)
                {
                    Key = key
                };
                Add(newItem);
                return(newItem);
            }

            default:
                return(item);
            }
        }