Ejemplo n.º 1
0
        public void constructorTest_withKindAndUri(NamespaceKind kind, string uri)
        {
            var ns = new Namespace(kind, uri);

            Assert.Equal(kind, ns.kind);
            Assert.Equal(uri, ns.uri);
        }
Ejemplo n.º 2
0
 internal void Set(string prefix, string namespaceUri, NamespaceKind kind)
 {
     this.prefix = prefix;
     this.namespaceUri = namespaceUri;
     this.kind = kind;
     this.prevNsIndex = -1;
 }
Ejemplo n.º 3
0
        internal SymbolInfo(
            ISymbol?symbol,
            ImmutableArray <ISymbol> candidateSymbols,
            CandidateReason candidateReason
            ) : this()
        {
            this.Symbol       = symbol;
            _candidateSymbols = candidateSymbols.IsDefault
                ? ImmutableArray.Create <ISymbol>()
                : candidateSymbols;

#if DEBUG
            const NamespaceKind NamespaceKindNamespaceGroup = (NamespaceKind)0;
            Debug.Assert(
                symbol is null ||
                symbol.Kind != SymbolKind.Namespace ||
                ((INamespaceSymbol)symbol).NamespaceKind != NamespaceKindNamespaceGroup
                );
            foreach (var item in _candidateSymbols)
            {
                Debug.Assert(
                    item.Kind != SymbolKind.Namespace ||
                    ((INamespaceSymbol)item).NamespaceKind != NamespaceKindNamespaceGroup
                    );
            }
#endif

            this.CandidateReason = candidateReason;
        }
Ejemplo n.º 4
0
 internal void Set(string prefix, string namespaceUri, NamespaceKind kind)
 {
     this.prefix       = prefix;
     this.namespaceUri = namespaceUri;
     this.kind         = kind;
     this.prevNsIndex  = -1;
 }
Ejemplo n.º 5
0
        private static AbcConstKind ToAbc(NamespaceKind value)
        {
            switch (value)
            {
            case NamespaceKind.Package:
                return(AbcConstKind.PackageNamespace);

            case NamespaceKind.Public:
                return(AbcConstKind.PublicNamespace);

            case NamespaceKind.Protected:
                return(AbcConstKind.ProtectedNamespace);

            case NamespaceKind.Private:
                return(AbcConstKind.PrivateNamespace);

            case NamespaceKind.Internal:
                return(AbcConstKind.InternalNamespace);

            case NamespaceKind.Explicit:
                return(AbcConstKind.ExplicitNamespace);

            case NamespaceKind.StaticProtected:
                return(AbcConstKind.StaticProtectedNamespace);

            default:
                throw new ArgumentOutOfRangeException("value");
            }
        }
Ejemplo n.º 6
0
 public ASNamespace(ASConstantPool pool, FlashReader input)
     : base(pool)
 {
     Kind = (NamespaceKind)input.ReadByte();
     if (!Enum.IsDefined(typeof(NamespaceKind), Kind))
     {
         throw new InvalidCastException($"Invalid namespace kind for value {Kind:0x00}.");
     }
     NameIndex = input.ReadInt30();
 }
Ejemplo n.º 7
0
        internal SymbolInfo(ISymbol symbol, ISymbol[] candidateSymbols, CandidateReason candidateReason)
            : this()
        {
            this.Symbol       = symbol;
            _candidateSymbols = candidateSymbols == null ? new ISymbol[0] : candidateSymbols;

#if DEBUG
            const NamespaceKind NamespaceKindNamespaceGroup = (NamespaceKind)0;
            Debug.Assert((object)symbol == null || symbol.Kind != SymbolKind.Namespace || ((INamespaceSymbol)symbol).NamespaceKind != NamespaceKindNamespaceGroup);
            foreach (var item in _candidateSymbols)
            {
                Debug.Assert(item.Kind != SymbolKind.Namespace || ((INamespaceSymbol)item).NamespaceKind != NamespaceKindNamespaceGroup);
            }
#endif

            this.CandidateReason = candidateReason;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Immutable namespace object. Please consider using AbcCode.CreateNamespace, which will
        /// keep things in their right place.
        /// </summary>
        /// <param name="kind">The kind of namespace</param>
        /// <param name="name">The namespace name. If this contains a prefix, it will be stripped off,
        /// e.g. myfile_fla:MainTimeline will become MainTimeline</param>
        /// <param name="prefix">A new prefix for the name</param>
        internal Namespace(NamespaceKind kind, string name, string prefix)
        {
            this.Kind = kind;
            if (prefix == null)
            {
                this.Name = name;
            }
            else
            {
                int pos = name.IndexOf(':');
                if (pos >= 0)
                {
                    name = name.Substring(pos);
                }

                this.Name = prefix + name;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Immutable namespace object. Please consider using AbcCode.CreateNamespace, which will
        /// keep things in their right place.
        /// </summary>
        /// <param name="kind">The kind of namespace</param>
        /// <param name="name">The namespace name. If this contains a prefix, it will be stripped off,
        /// e.g. myfile_fla:MainTimeline will become MainTimeline</param>
        /// <param name="prefix">A new prefix for the name</param>
        internal Namespace(NamespaceKind kind, string name, string prefix)
        {
            this.Kind = kind;
            if (prefix == null)
            {
                this.Name = name;
            }
            else
            {
                int pos = name.IndexOf(':');
                if (pos >= 0)
                {
                    name = name.Substring(pos);
                }

                this.Name = prefix + name;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a new non-private namespace with the given type and name.
        /// </summary>
        ///
        /// <param name="kind">
        /// The kind of namespace to create. This cannot be
        /// <see cref="NamespaceKind.PRIVATE" qualifyHint="true"/>. (To create a private namespace, use
        /// the <see cref="Namespace.createPrivate()" qualifyHint="true"/> method), or
        /// <see cref="NamespaceKind.ANY" qualifyHint="true"/> (which is reserved for the "any"
        /// namespace).
        /// </param>
        /// <param name="uri">The name or URI of the namespace.</param>
        ///
        /// <exception cref="AVM2Exception">
        /// <list type="bullet">
        /// <item>
        /// <description>ArgumentError #10013: The <paramref name="kind"/> argument is
        /// <see cref="NamespaceKind.PRIVATE" qualifyHint="true"/>.</description>
        /// </item>
        /// <item>
        /// <description>ArgumentError #10014: The <paramref name="kind"/> argument is
        /// <see cref="NamespaceKind.ANY" qualifyHint="true"/>.</description>
        /// </item>
        /// <item>
        /// <description>ArgumentError #10016: The <paramref name="kind"/> argument is not a valid value of the
        /// <see cref="NamespaceKind"/> enumeration.</description>
        /// </item>
        /// <item><description>ArgumentError #10017: The <paramref name="uri"/> argument is null.</description></item>
        /// </list>
        /// </exception>
        public Namespace(NamespaceKind kind, string uri)
        {
            if (kind == NamespaceKind.PRIVATE)
            {
                throw ErrorHelper.createError(ErrorCode.MARIANA__NAMESPACE_CTOR_PRIVATE);
            }
            if (kind == NamespaceKind.ANY)
            {
                throw ErrorHelper.createError(ErrorCode.MARIANA__NAMESPACE_CTOR_ANY);
            }
            if ((uint)kind > (uint)NamespaceKind.PRIVATE)
            {
                throw ErrorHelper.createError(ErrorCode.MARIANA__INVALID_NS_CATEGORY, (int)kind);
            }
            if (uri == null)
            {
                throw ErrorHelper.createError(ErrorCode.MARIANA__NAMESPACE_NULL_NAME);
            }

            this.uri         = uri;
            this.m_kindAndId = (uint)kind;
        }
        public string CSharpName(MetaNamespace mnamespace, NamespaceKind kind = NamespaceKind.Public, bool fullName = false)
        {
            if (mnamespace == null)
            {
                return(string.Empty);
            }
            if (!fullName)
            {
                return(mnamespace.Name);
            }
            string        result    = string.Empty;
            MetaNamespace currentNs = mnamespace;

            while (currentNs != null)
            {
                if (!string.IsNullOrEmpty(currentNs.Name))
                {
                    if (!string.IsNullOrEmpty(result))
                    {
                        result = "." + result;
                    }
                    result = currentNs.Name + result;
                }
                currentNs = currentNs.Namespace;
            }
            switch (kind)
            {
            case NamespaceKind.Internal:
                result = result + ".Internal";
                break;

            default:
                break;
            }
            return(result);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Create a NamespaceExtent that represents a given Compilation.
 /// </summary>
 internal NamespaceExtent(CSharpCompilation compilation)
 {
     this.kind = NamespaceKind.Compilation;
     this.symbolOrCompilation = compilation;
 }
Ejemplo n.º 13
0
        public void HandleKindHidesSpecialStringAndNamespaces()
        {
            foreach (uint virtualBit in new[] { 0U, TokenTypeIds.VirtualTokenMask })
            {
                uint invalidStringTypeCount    = 0;
                uint invalidNamespaceTypeCount = 0;

                for (uint i = 0; i <= sbyte.MaxValue; i++)
                {
                    Handle handle = new Handle(virtualBit | i << TokenTypeIds.RowIdBitCount);
                    Assert.True(handle.IsNil ^ handle.IsVirtual);
                    Assert.Equal(virtualBit != 0, handle.IsVirtual);
                    Assert.Equal(handle.TokenType, i << TokenTypeIds.RowIdBitCount);

                    switch (i)
                    {
                    // String and namespace have two extra bits to represent their kind that are hidden from the handle type
                    case (uint)HandleKind.String:
                    case (uint)HandleKind.String + 1:
                    case (uint)HandleKind.String + 2:
                    case (uint)HandleKind.String + 3:
                        Assert.Equal(HandleKind.String, handle.Kind);

                        StringKind   stringType = (StringKind)(i - (int)HandleKind.String);
                        StringHandle stringHandle;
                        try
                        {
                            stringHandle = (StringHandle)handle;
                        }
                        catch (InvalidCastException)
                        {
                            Assert.True(handle.TokenType > TokenTypeIds.MaxString);
                            invalidStringTypeCount++;
                            break;
                        }
                        Assert.Equal(stringType, stringHandle.StringKind);
                        break;

                    case (uint)HandleKind.NamespaceDefinition:
                    case (uint)HandleKind.NamespaceDefinition + 1:
                    case (uint)HandleKind.NamespaceDefinition + 2:
                    case (uint)HandleKind.NamespaceDefinition + 3:
                        Assert.Equal(HandleKind.NamespaceDefinition, handle.Kind);

                        NamespaceKind             namespaceType = (NamespaceKind)(i - (int)HandleKind.NamespaceDefinition);
                        NamespaceDefinitionHandle namespaceHandle;
                        try
                        {
                            namespaceHandle = (NamespaceDefinitionHandle)handle;
                        }
                        catch (InvalidCastException)
                        {
                            Assert.True(handle.TokenType > TokenTypeIds.MaxNamespace);
                            invalidNamespaceTypeCount++;
                            break;
                        }
                        Assert.Equal(namespaceType, namespaceHandle.NamespaceKind);
                        break;

                    // all other types surface token type directly.
                    default:
                        Assert.Equal((uint)handle.Kind, i);
                        break;
                    }
                }
                Assert.Equal((uint)((TokenTypeIds.String | TokenTypeIds.StringOrNamespaceKindMask) - TokenTypeIds.MaxString) >> TokenTypeIds.RowIdBitCount, invalidStringTypeCount);
                Assert.Equal((uint)((TokenTypeIds.Namespace | TokenTypeIds.StringOrNamespaceKindMask) - TokenTypeIds.MaxNamespace) >> TokenTypeIds.RowIdBitCount, invalidNamespaceTypeCount);
            }
        }
Ejemplo n.º 14
0
        internal void constructorTest_withInvalidKind(NamespaceKind kind, string uri, ErrorCode errCode)
        {
            var exc = Assert.Throws <AVM2Exception>(() => new Namespace(kind, uri));

            Assert.Equal(errCode, (ErrorCode)((ASError)exc.thrownValue).errorID);
        }
Ejemplo n.º 15
0
 public QNameAttribute(string ns, string name, NamespaceKind kind)
 {
     Value = new QName(name, new Namespace(ns, kind));
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Create a NamespaceExtent that represents a given Compilation.
 /// </summary>
 internal NamespaceExtent(LanguageCompilation compilation)
 {
     _kind = NamespaceKind.Compilation;
     _symbolOrCompilation = compilation;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Returns true if the namespace set contains a namespace of the given kind.
 /// </summary>
 /// <param name="kind">The namespace kind to check.</param>
 /// <returns>True if the namespace set contains a namespace of the kind
 /// <paramref name="kind"/>, otherwise false.</returns>
 public bool contains(NamespaceKind kind) => (m_flags & (1 << (int)kind)) != 0;
Ejemplo n.º 18
0
 /// <summary>
 /// 
 /// </summary>
 public Namespace_info()
 {
     _Kind = NamespaceKind.Namespace;
     _Name = 0;
 }
Ejemplo n.º 19
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="source"></param>
        public void Parse(Stream source)
        {
            BinaryReader br = new BinaryReader(source);
            byte kindId = br.ReadByte();

            if (!Enum.IsDefined(typeof(NamespaceKind), kindId))
            {
                AbcFormatException fe = new AbcFormatException("Namespace kind 0x" + kindId.ToString("X2") + " is undefined");
                Log.Error(this, fe);
                throw fe;
            }

            _Kind = (NamespaceKind)kindId;
            _Name = VariableLengthInteger.ReadU30(source);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Create a NamespaceExtent that represents a given ModuleSymbol.
 /// </summary>
 internal NamespaceExtent(ModuleSymbol module)
 {
     this.kind = NamespaceKind.Module;
     this.symbolOrCompilation = module;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Create a NamespaceExtent that represents a given AssemblySymbol.
 /// </summary>
 internal NamespaceExtent(AssemblySymbol assembly)
 {
     this.kind = NamespaceKind.Assembly;
     this.symbolOrCompilation = assembly;
 }
Ejemplo n.º 22
0
 public Namespace(string name, NamespaceKind kind)
 {
     Name = name ?? "";
     Kind = kind;
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Immutable namespace object. Please consider using AbcCode.CreateNamespace, which will
 /// keep things in their right place.
 /// </summary>
 /// <param name="kind">The kind of namespace</param>
 /// <param name="name">The namespace name</param>
 internal Namespace(NamespaceKind kind, string name)
     : this(kind, name, null)
 {
 }
 private void AddNamespace(string prefix, string ns, NamespaceKind kind)
 {
     int length = ++this.nsTop;
     if (length == this.nsStack.Length)
     {
         Namespace[] destinationArray = new Namespace[length * 2];
         Array.Copy(this.nsStack, destinationArray, length);
         this.nsStack = destinationArray;
     }
     this.nsStack[length].Set(prefix, ns, kind);
     if (this.useNsHashtable)
     {
         this.AddToNamespaceHashtable(this.nsTop);
     }
     else if (this.nsTop == 0x10)
     {
         this.nsHashtable = new Dictionary<string, int>(this.hasher);
         for (int i = 0; i <= this.nsTop; i++)
         {
             this.AddToNamespaceHashtable(i);
         }
         this.useNsHashtable = true;
     }
 }
Ejemplo n.º 25
0
        private void AddNamespace(string prefix, string ns, NamespaceKind kind)
        {
            int top = ++_nsTop;
            if (top == _nsStack.Length)
            {
                Namespace[] newStack = new Namespace[top * 2];
                Array.Copy(_nsStack, 0, newStack, 0, top);
                _nsStack = newStack;
            }
            _nsStack[top].Set(prefix, ns, kind);

            if (_useNsHashtable)
            {
                // add last
                AddToNamespaceHashtable(_nsTop);
            }
            else if (_nsTop == MaxNamespacesWalkCount)
            {
                // add all
                _nsHashtable = new Dictionary<string, int>(_hasher);
                for (int i = 0; i <= _nsTop; i++)
                {
                    AddToNamespaceHashtable(i);
                }
                _useNsHashtable = true;
            }
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Immutable namespace object. Please consider using AbcCode.CreateNamespace, which will
 /// keep things in their right place.
 /// </summary>
 /// <param name="kind">The kind of namespace</param>
 /// <param name="name">The namespace name</param>
 internal Namespace(NamespaceKind kind, string name) : this(kind, name, null)
 {
 }
Ejemplo n.º 27
0
 internal void constructorTest_withKindAndNullUri(NamespaceKind kind, string uri)
 {
     AssertHelper.throwsErrorWithCode(ErrorCode.MARIANA__NAMESPACE_NULL_NAME, () => new Namespace(kind, uri));
 }
Ejemplo n.º 28
0
 public NamespaceInfo(NamespaceKind kind, StringInfo name)
 {
     Kind = kind;
     Name = name;
 }