Beispiel #1
0
        public static string DecorateNullableName(string nullableTypeName)
        {
            GenericTypeReference typeRef     = (GenericTypeReference)TypeReference.FromString(nullableTypeName);
            TypeReference        wrappedType = typeRef.GenericArguments[0];

            return("Nullable<" + wrappedType.SimpleName + ">");
        }
Beispiel #2
0
        public IEntity ResolveGenericTypeReference(GenericTypeReference gtr, IEntity definition)
        {
            ResolveTypeReferenceCollection(gtr.GenericArguments);
            IType[] typeArguments = gtr.GenericArguments.ToArray(t => TypeSystemServices.GetType(t));

            return(My <GenericsServices> .Instance.ConstructEntity(gtr, definition, typeArguments));
        }
Beispiel #3
0
        private static string DecorateNullableName(string typeName)
        {
            GenericTypeReference typeRef        = (GenericTypeReference)TypeReference.FromString(typeName);
            TypeReference        underlyingType = typeRef.GenericArguments[0];

            return("Nullable<" + underlyingType.SimpleName + ">");
        }
Beispiel #4
0
        public static string GetSimpleNameForNullable(string nullableTypeName)
        {
            GenericTypeReference typeRef     = (GenericTypeReference)TypeReference.FromString(nullableTypeName);
            TypeReference        wrappedType = typeRef.GenericArguments[0];

            return(wrappedType.SimpleName);
        }
Beispiel #5
0
        public static TypeReference EnumerableTypeReferenceFor(TypeReference tr)
        {
            var result = new GenericTypeReference(tr.LexicalInfo, "System.Collections.Generic.IEnumerable");

            result.GenericArguments.Add(tr);
            return(result);
        }
        public void TestGenericName()
        {
            GenericType <int, string> o = new GenericType <int, string>(3, "42");
            Type t = Type.GetType(o.GetType().FullName);

            TypeReference stringName = TypeReference.FromString(typeof(string).AssemblyQualifiedName);

            GenericTypeReference genericTypeName = (GenericTypeReference)TypeReference.FromString(t.AssemblyQualifiedName);

            Assert.AreEqual("Db4objects.Db4o.Tests.SharpenLang.GenericType`2", genericTypeName.SimpleName);
            Assert.AreEqual(2, genericTypeName.GenericArguments.Length);

            Assert.AreEqual(TypeReference.FromString(typeof(int).AssemblyQualifiedName), genericTypeName.GenericArguments[0]);
            Assert.AreEqual(stringName, genericTypeName.GenericArguments[1]);

            Type complexType = typeof(GenericType <string, GenericType <int, string> >);
            GenericTypeReference complexTypeName = (GenericTypeReference)TypeReference.FromString(complexType.AssemblyQualifiedName);

            Assert.AreEqual(genericTypeName.SimpleName, complexTypeName.SimpleName);
            Assert.AreEqual(genericTypeName.AssemblyName.FullName, complexTypeName.AssemblyName.FullName);
            Assert.AreEqual(2, complexTypeName.GenericArguments.Length);
            Assert.AreEqual(stringName, complexTypeName.GenericArguments[0]);
            Assert.AreEqual(genericTypeName, complexTypeName.GenericArguments[1]);

            Assert.AreEqual(typeof(string), TypeReference.FromString("System.String, mscorlib").Resolve());
            Assert.AreEqual(t, TypeReference.FromString("Db4objects.Db4o.Tests.SharpenLang.GenericType`2[[System.Int32, mscorlib],[System.String, mscorlib]], " + GetExecutingAssemblySimpleName()).Resolve());
        }
        public void ResolveSimpleTypeReference(SimpleTypeReference node)
        {
            if (null != node.Entity)
            {
                return;
            }

            IEntity entity = ResolveTypeName(node);

            if (null == entity)
            {
                node.Entity = NameNotType(node, "not found");
                return;
            }

            GenericTypeReference gtr = node as GenericTypeReference;

            if (null != gtr)
            {
                entity = ResolveGenericTypeReference(gtr, entity);
            }

            GenericTypeDefinitionReference gtdr = node as GenericTypeDefinitionReference;

            if (null != gtdr)
            {
                IType type = (IType)entity;
                if (gtdr.GenericPlaceholders != type.GenericInfo.GenericParameters.Length)
                {
                    GenericArgumentsCountMismatch(gtdr, type);
                    return;
                }
            }

            entity = Entities.PreferInternalEntitiesOverExternalOnes(entity);

            if (EntityType.Type != entity.EntityType)
            {
                if (EntityType.Ambiguous == entity.EntityType)
                {
                    entity = AmbiguousReference(node, (Ambiguous)entity);
                }
                else if (EntityType.Error != entity.EntityType)
                {
                    entity = NameNotType(node, entity.ToString());
                }
            }
            else
            {
                node.Name = entity.FullName;
            }

            if (node.IsPointer && EntityType.Type == entity.EntityType)
            {
                entity = ((IType)entity).MakePointerType();
            }

            node.Entity = entity;
        }
 public override void OnGenericTypeReference(GenericTypeReference node)
 {
     if (node.LexicalInfo != null)
     {
         results.MapParsedNode(new MappedTypeReference(results, node));
     }
     base.OnGenericTypeReference(node);
 }
 private string SetFieldType(IType type)
 {
     if (type.IsNullable)
     {
         GenericTypeReference typeRef     = (GenericTypeReference)TypeReference.FromString(type.FullName);
         TypeReference        wrappedType = typeRef.GenericArguments[0];
         return(wrappedType.SimpleName);
     }
     return(type.DisplayName);
 }
Beispiel #10
0
        private IType[] ResolveGenericArguments(GenericTypeReference node)
        {
            IType[] arguments = new IType[node.GenericArguments.Count];

            for (int i = 0; i < arguments.Length; ++i)
            {
                ResolveTypeReference(node.GenericArguments[i]);
                arguments[i] = (IType)node.GenericArguments[i].Entity;
            }

            return(arguments);
        }
Beispiel #11
0
        public void ResolveSimpleTypeReference(SimpleTypeReference node)
        {
            if (null != node.Entity)
            {
                return;
            }

            IEntity entity = ResolveTypeName(node);

            if (null == entity)
            {
                node.Entity = NameNotType(node);
                return;
            }
            if (EntityType.Type != entity.EntityType)
            {
                if (EntityType.Ambiguous == entity.EntityType)
                {
                    entity = AmbiguousReference(node, (Ambiguous)entity);
                }
                else
                {
                    entity = NameNotType(node);
                }
            }
            else
            {
#if NET_2_0
                GenericTypeReference gtr = node as GenericTypeReference;
                if (null != gtr)
                {
                    entity = MakeGenericType(gtr, (IType)entity);
                }

                GenericTypeDefinitionReference gtdr = node as GenericTypeDefinitionReference;
                if (null != gtdr)
                {
                    IType type = (IType)entity;
                    if (gtdr.GenericPlaceholders != type.GenericTypeDefinitionInfo.GenericParameters.Length)
                    {
                        entity = GenericArgumentsCountMismatch(gtdr, type);
                    }
                }
#endif

                node.Name = entity.FullName;
            }

            node.Entity = entity;
        }
Beispiel #12
0
        private static void SetFieldType(TreeGridNode node, IType type)
        {
            if (type.IsNullable)
            {
                GenericTypeReference typeRef     = (GenericTypeReference)TypeReference.FromString(type.FullName);
                TypeReference        wrappedType = typeRef.GenericArguments[0];
                node.Cells[2].Value = wrappedType.SimpleName;
            }
            else
            {
                node.Cells[2].Value = type.DisplayName;
            }

            node.Cells[2].Tag = type;
        }
Beispiel #13
0
        private IEntity MakeGenericType(GenericTypeReference node, IType entity)
        {
            if (entity.GenericTypeDefinitionInfo == null)
            {
                _context.Errors.Add(CompilerErrorFactory.NotAGenericDefinition(node, node.Name));
                return(TypeSystemServices.ErrorEntity);
            }

            if (entity.GenericTypeDefinitionInfo.GenericParameters.Length != node.GenericArguments.Count)
            {
                return(GenericArgumentsCountMismatch(node, entity));
            }

            IType[] arguments = ResolveGenericArguments(node);
            return(entity.GenericTypeDefinitionInfo.MakeGenericType(arguments));
        }
        internal void Ensure(CompilerContext context, Method method)
        {
            if (method.Parameters.Count != this.Parameters.Count)
            {
                context.Errors.Add(CompilerErrorFactory.MethodArgumentCount(method, method.Name, this.Parameters.Count));
                return;
            }

            //ensure return type
            if (method.ReturnType == null)
            {
                method.ReturnType = new SimpleTypeReference(ReturnType.FullName);
            }

            //ensure parameter types
            for (var i = 0; i < this.Parameters.Count; i++)
            {
                var paramtTypeRef = method.Parameters[i].Type;

                if (paramtTypeRef == null)
                {
                    var           ensuredType = this.Parameters[i].Type;
                    TypeReference typeRef     = null;

                    if (ensuredType.IsGenericType)
                    {
                        var args = new SimpleTypeReference(ensuredType.GenericTypeArguments[0].Name);

                        var name = ensuredType.Name;
                        var tick = name.IndexOf('`');

                        name = name.Substring(0, tick);

                        typeRef = new GenericTypeReference(name, args);
                    }
                    else
                    {
                        typeRef = new SimpleTypeReference(ensuredType.FullName);
                    }

                    method.Parameters[i].Type = typeRef;
                }
            }
        }
Beispiel #15
0
        public void MergeIgnoresMatchingBaseTypes()
        {
            var foo      = new SimpleTypeReference("Foo");
            var bar      = new SimpleTypeReference("Bar");
            var fooOfBar = new GenericTypeReference("Foo", bar);
            var barOfFoo = new GenericTypeReference("Bar", foo);

            var subject = new ClassDefinition();

            subject.BaseTypes.Add(bar);
            subject.BaseTypes.Add(fooOfBar);

            var node = new ClassDefinition();

            node.BaseTypes.Add(foo);
            node.BaseTypes.Add(bar.CloneNode());
            node.BaseTypes.Add(fooOfBar.CloneNode());
            node.BaseTypes.Add(barOfFoo);

            subject.Merge(node);

            Assert.AreEqual(new[] { bar, fooOfBar, foo, barOfFoo }, subject.BaseTypes.ToArray());
        }
Beispiel #16
0
 override public void OnGenericTypeReference(GenericTypeReference node)
 {
     OnSimpleTypeReference(node);
     WriteGenericArguments(node.GenericArguments);
 }
Beispiel #17
0
        public IType ResolveGenericTypeReference(GenericTypeReference gtr, IEntity definition)
        {
            ResolveTypeReferenceCollection(gtr.GenericArguments);

            return((IType)_context.TypeSystemServices.GenericsServices.ConstructEntity(definition, gtr, gtr.GenericArguments));
        }
Beispiel #18
0
 override public void OnGenericTypeReference(GenericTypeReference node)
 {
     CheckName(node, node.Name);
 }
Beispiel #19
0
 override public void LeaveGenericTypeReference(GenericTypeReference node)
 {
     OnTypeReference(node);
 }
Beispiel #20
0
 override public void OnGenericTypeReference(GenericTypeReference node)
 {
     NameResolutionService.ResolveSimpleTypeReference(node);
 }
Beispiel #21
0
 public override void OnGenericTypeReference(GenericTypeReference node)
 {
     base.OnGenericTypeReference(node);
     OnTypeReference(node);
 }
Beispiel #22
0
 public override void OnGenericTypeReference(GenericTypeReference node)
 {
     AddAsSeen(node.Entity);
     base.OnGenericTypeReference(node);
 }
 public override void OnGenericTypeReference(GenericTypeReference node)
 {
     throw new NotImplementedException();
     IL_0006 :;
 }