Ejemplo n.º 1
0
        private bool TryFindTypeCore(string name, out NativeType type, out bool loadedFromNextLookup)
        {
            if (_storage.TryGetType(name, out type))
            {
                loadedFromNextLookup = false;
                return(true);
            }

            if (_nextSymbolLookup.TryGetType(name, out type))
            {
                loadedFromNextLookup = true;
                return(true);
            }

            NativeBuiltinType bt = null;

            if (NativeBuiltinType.TryConvertToBuiltinType(name, out bt))
            {
                loadedFromNextLookup = false;
                type = bt;
                return(true);
            }

            loadedFromNextLookup = false;
            return(false);
        }
Ejemplo n.º 2
0
        public void Unknown1()
        {
            NativeBuiltinType nt = new NativeBuiltinType("foo");

            Assert.Equal(BuiltinType.NativeUnknown, nt.BuiltinType);
            Assert.Equal("unknown", nt.Name);
            Assert.Equal("unknown", nt.DisplayName);
        }
Ejemplo n.º 3
0
        public void FindAllRelationships1()
        {
            NativeBuiltinType               ns   = new NativeBuiltinType(BuiltinType.NativeByte);
            NativeSymbolIterator            it   = new NativeSymbolIterator();
            List <NativeSymbolRelationship> list = it.FindAllNativeSymbolRelationships(ns);

            Assert.Equal(1, list.Count);
            EnsureIsSymbol(ns, list);
        }
Ejemplo n.º 4
0
        public void FindAllNativeSymbols1()
        {
            NativeBuiltinType    child = new NativeBuiltinType(BuiltinType.NativeByte);
            NativePointer        par   = new NativePointer(child);
            NativeSymbolIterator it    = new NativeSymbolIterator();
            List <NativeSymbol>  list  = it.FindAllNativeSymbols(par);

            Assert.True(list.Contains(child));
            Assert.True(list.Contains(par));
        }
Ejemplo n.º 5
0
 public void EnsureTypeKeywordToBuiltin()
 {
     foreach (TokenType cur in EnumUtil.GetAllValues <TokenType>())
     {
         if (TokenHelper.IsTypeKeyword(cur))
         {
             NativeBuiltinType bt = null;
             Assert.True(NativeBuiltinType.TryConvertToBuiltinType(cur, out bt));
         }
     }
 }
        public void TopLevel1()
        {
            NativeBuiltinType nt1 = new NativeBuiltinType(BuiltinType.NativeByte);
            NativeBuiltinType nt2 = new NativeBuiltinType(BuiltinType.NativeByte);

            NativeTypeEqualityComparer eq = NativeTypeEqualityComparer.TopLevel;

            Assert.True(eq.Equals1(nt1, nt2));

            nt2 = new NativeBuiltinType(BuiltinType.NativeInt32);
            Assert.False(eq.Equals1(nt1, nt2));
        }
Ejemplo n.º 7
0
        public void FindAllRelationships2()
        {
            NativeBuiltinType               child = new NativeBuiltinType(BuiltinType.NativeByte);
            NativePointer                   par   = new NativePointer(child);
            NativeSymbolIterator            it    = new NativeSymbolIterator();
            List <NativeSymbolRelationship> list  = it.FindAllNativeSymbolRelationships(par);

            Assert.Equal(2, list.Count);
            EnsureIsSymbol(par, list);
            EnsureIsSymbol(child, list);
            EnsureIsParent(par, list);
        }
Ejemplo n.º 8
0
 public void TestAll()
 {
     foreach (BuiltinType bt in System.Enum.GetValues(typeof(BuiltinType)))
     {
         if (bt != BuiltinType.NativeUnknown)
         {
             NativeBuiltinType nt = new NativeBuiltinType(bt);
             Assert.Equal(nt.Name, NativeBuiltinType.BuiltinTypeToName(bt));
             Assert.Equal(bt, nt.BuiltinType);
             Assert.NotNull(nt.ManagedType);
             Assert.NotEqual(0, Convert.ToInt32(nt.UnmanagedType));
         }
     }
 }
        private bool EqualsSpecializedCore(NativeSpecializedType left, NativeSpecializedType right)
        {
            switch (left.Kind)
            {
            case NativeSymbolKind.BitVectorType:
                NativeBitVector bt1 = (NativeBitVector)left;
                NativeBitVector bt2 = (NativeBitVector)right;
                return(bt1.Size == bt2.Size);

            case NativeSymbolKind.BuiltinType:
                NativeBuiltinType b1 = (NativeBuiltinType)left;
                NativeBuiltinType b2 = (NativeBuiltinType)right;
                return(b1.BuiltinType == b2.BuiltinType);

            default:
                return(false);
            }
        }
Ejemplo n.º 10
0
        public CodeTypeReference GenerateSpecializedTypeReferenceImpl(NativeSpecializedType specialNt, ref string comment)
        {
            ThrowIfNull(specialNt);

            switch (specialNt.Kind)
            {
            case NativeSymbolKind.BitVectorType:
                NativeBitVector bitNt = (NativeBitVector)specialNt;
                comment = string.Format("bitvector : {0}", bitNt.Size);
                return(new CodeTypeReference(GetManagedNameForBitVector(bitNt)));

            case NativeSymbolKind.BuiltinType:
                NativeBuiltinType builtNt = (NativeBuiltinType)specialNt;
                Type realType             = builtNt.ManagedType;
                comment += builtNt.DisplayName;
                return(new CodeTypeReference(realType));

            default:
                Contract.ThrowInvalidEnumValue(specialNt.Kind);
                return(null);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Generate the NativeMember
        /// </summary>
        /// <param name="nt"></param>
        /// <param name="ctd"></param>
        /// <remarks></remarks>
        private CodeMemberField GenerateContainerMember(NativeMember nt, CodeTypeDeclaration ctd)
        {
            ThrowIfNull(nt);
            ThrowIfNull(ctd);
            ThrowIfTrue(nt.NativeType.Kind == NativeSymbolKind.BitVectorType);
            // Bitvector instances should be handled seperately

            // Generate the type reference and comment
            string          comment = string.Empty;
            CodeMemberField member  = new CodeMemberField();

            member.Name       = nt.Name;
            member.Type       = GenerateTypeReferenceImpl(nt.NativeType, ref comment);
            member.Attributes = MemberAttributes.Public;
            member.Comments.Add(new CodeCommentStatement(comment, true));
            member.UserData.Add(TransformConstants.Member, nt);
            ctd.Members.Add(member);

            // If this is an array then add the appropriate marshal directive if it's an inline array
            NativeArray ntArray = nt.NativeType as NativeArray;

            if (ntArray != null && ntArray.ElementCount > 0)
            {
                // Add the struct layout attribute
                CodeTypeReference        attrRef = new CodeTypeReference(typeof(MarshalAsAttribute));
                CodeAttributeDeclaration attr    = new CodeAttributeDeclaration(attrRef);

                // ByValArray
                CodeAttributeArgument asArg = new CodeAttributeArgument();
                asArg.Name  = string.Empty;
                asArg.Value = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(UnmanagedType)), "ByValArray");
                attr.Arguments.Add(asArg);

                // SizeConst arg
                CodeAttributeArgument sizeArg = new CodeAttributeArgument();
                sizeArg.Name  = "SizeConst";
                sizeArg.Value = new CodePrimitiveExpression(ntArray.ElementCount);
                attr.Arguments.Add(sizeArg);

                // ArraySubType
                NativeType            elemType   = ntArray.RealTypeDigged;
                CodeAttributeArgument subTypeArg = new CodeAttributeArgument();
                subTypeArg.Name = "ArraySubType";
                if (elemType.Kind == NativeSymbolKind.BuiltinType)
                {
                    // Builtin types know their size in bytes
                    NativeBuiltinType elemBt = (NativeBuiltinType)elemType;
                    subTypeArg.Value = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(UnmanagedType)), elemBt.UnmanagedType.ToString());
                }
                else if (elemType.Kind == NativeSymbolKind.PointerType || elemType.Kind == NativeSymbolKind.ArrayType)
                {
                    // Marshal pointers as system ints
                    subTypeArg.Value = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(UnmanagedType)), "SysUInt");
                }
                else
                {
                    subTypeArg.Value = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(UnmanagedType)), "Struct");
                }
                attr.Arguments.Add(subTypeArg);

                member.CustomAttributes.Add(attr);
            }

            return(member);
        }