private static void FindTypeUsageErrors(IEnumerable<IType> types, IMetadataImporter metadataImporter, HashSet<ITypeDefinition> usedUnusableTypes, HashSet<ITypeDefinition> mutableValueTypesBoundToTypeArguments) {
			foreach (var t in types) {
				if (t is ITypeDefinition) {
					if (metadataImporter.GetTypeSemantics((ITypeDefinition)t).Type == TypeScriptSemantics.ImplType.NotUsableFromScript)
						usedUnusableTypes.Add((ITypeDefinition)t);
				}
				else if (t is ParameterizedType) {
					var pt = (ParameterizedType)t;
					foreach (var ta in pt.TypeArguments) {
						if (ta.Kind == TypeKind.Struct && metadataImporter.GetTypeSemantics(ta.GetDefinition()).Type == TypeScriptSemantics.ImplType.MutableValueType)
							mutableValueTypesBoundToTypeArguments.Add(ta.GetDefinition());
					}
					FindTypeUsageErrors(new[] { pt.GetDefinition() }.Concat(pt.TypeArguments), metadataImporter, usedUnusableTypes, mutableValueTypesBoundToTypeArguments);
				}
			}
		}
Beispiel #2
0
		private static void FindUsedUnusableTypes(IEnumerable<IType> types, IMetadataImporter metadataImporter, HashSet<ITypeDefinition> result) {
			foreach (var t in types) {
				if (t is ITypeDefinition) {
					if (metadataImporter.GetTypeSemantics((ITypeDefinition)t).Type == TypeScriptSemantics.ImplType.NotUsableFromScript)
						result.Add((ITypeDefinition)t);
				}
				else if (t is ParameterizedType) {
					var pt = (ParameterizedType)t;
					FindUsedUnusableTypes(new[] { pt.GetDefinition() }.Concat(pt.TypeArguments), metadataImporter, result);
				}
			}
		}
		public static UnusableTypesResult FindGenericInstantiationErrors(IEnumerable<IType> typeArguments, IMetadataImporter metadataImporter) {
			if (!(typeArguments is ICollection<IType>))
				typeArguments = typeArguments.ToList();

			var usedUnusableTypes = new HashSet<ITypeDefinition>();
			var mutableValueTypesBoundToTypeArguments = new HashSet<ITypeDefinition>();

			foreach (var ta in typeArguments) {
				if (ta.Kind == TypeKind.Struct && metadataImporter.GetTypeSemantics(ta.GetDefinition()).Type == TypeScriptSemantics.ImplType.MutableValueType)
					mutableValueTypesBoundToTypeArguments.Add(ta.GetDefinition());
			}

			FindTypeUsageErrors(typeArguments, metadataImporter, usedUnusableTypes, mutableValueTypesBoundToTypeArguments);
			return new UnusableTypesResult(usedUnusableTypes.Count > 0 ? usedUnusableTypes.ToList<IType>() : (IList<IType>)EmptyList<IType>.Instance, mutableValueTypesBoundToTypeArguments.Count > 0 ? mutableValueTypesBoundToTypeArguments.ToList<IType>() : (IList<IType>)EmptyList<IType>.Instance);
		}
Beispiel #4
0
        public static UnusableTypesResult FindGenericInstantiationErrors(IEnumerable <IType> typeArguments, IMetadataImporter metadataImporter)
        {
            if (!(typeArguments is ICollection <IType>))
            {
                typeArguments = typeArguments.ToList();
            }

            var usedUnusableTypes = new HashSet <ITypeDefinition>();
            var mutableValueTypesBoundToTypeArguments = new HashSet <ITypeDefinition>();

            foreach (var ta in typeArguments)
            {
                if (ta.Kind == TypeKind.Struct && metadataImporter.GetTypeSemantics(ta.GetDefinition()).Type == TypeScriptSemantics.ImplType.MutableValueType)
                {
                    mutableValueTypesBoundToTypeArguments.Add(ta.GetDefinition());
                }
            }

            FindTypeUsageErrors(typeArguments, metadataImporter, usedUnusableTypes, mutableValueTypesBoundToTypeArguments);
            return(new UnusableTypesResult(usedUnusableTypes.Count > 0 ? usedUnusableTypes.ToList <IType>() : (IList <IType>)EmptyList <IType> .Instance, mutableValueTypesBoundToTypeArguments.Count > 0 ? mutableValueTypesBoundToTypeArguments.ToList <IType>() : (IList <IType>)EmptyList <IType> .Instance));
        }
Beispiel #5
0
 private IEnumerable <JsStatement> GetStaticInitCode(IEnumerable <JsType> types)
 {
     return(GetStaticInitializationOrder(OrderByNamespace(types.OfType <JsClass>(), c => _metadataImporter.GetTypeSemantics(c.CSharpTypeDefinition).Name), 1)
            .SelectMany(_emulator.GetStaticInitStatements));
 }
 public static bool IsReflectable(IMember member, IMetadataImporter metadataImporter)
 {
     return(member.Attributes.Any(a => a.AttributeType.FullName == typeof(ReflectableAttribute).FullName || metadataImporter.GetTypeSemantics(a.AttributeType.GetDefinition()).Type == TypeScriptSemantics.ImplType.NormalType));
 }
		public static IEnumerable<IAttribute> GetScriptableAttributes(IEnumerable<IAttribute> attributes, IMetadataImporter metadataImporter) {
			return attributes.Where(a => !a.IsConditionallyRemoved && metadataImporter.GetTypeSemantics(a.AttributeType.GetDefinition()).Type != TypeScriptSemantics.ImplType.NotUsableFromScript);
		}
		public static bool IsReflectable(IMember member, IMetadataImporter metadataImporter) {
			var ra = AttributeReader.ReadAttribute<ReflectableAttribute>(member);
			if (ra != null)
				return ra.Reflectable;
			if (member.Attributes.Any(a => metadataImporter.GetTypeSemantics(a.AttributeType.GetDefinition()).Type != TypeScriptSemantics.ImplType.NotUsableFromScript))
				return true;	// Any scriptable attribute will cause reflectability (unless [Reflectable(false)] was specified.

			if (member.DeclaringType.Kind != TypeKind.Anonymous) {
				var tdr = AttributeReader.ReadAttribute<DefaultMemberReflectabilityAttribute>(member.DeclaringTypeDefinition);
				if (tdr != null) {
					return IsMemberReflectable(member, tdr.DefaultReflectability);
				}

				var adr = AttributeReader.ReadAttribute<DefaultMemberReflectabilityAttribute>(member.ParentAssembly.AssemblyAttributes);
				if (adr != null) {
					return IsMemberReflectable(member, adr.DefaultReflectability);
				}
			}

			return false;
		}
		public static bool IsJsGeneric(ITypeDefinition type, IMetadataImporter metadataImporter) {
			return type.TypeParameterCount > 0 && !metadataImporter.GetTypeSemantics(type).IgnoreGenericArguments;
		}
		private static List<JsObjectLiteralProperty> GetCommonMemberInfoProperties(IMember m, ICompilation compilation, IMetadataImporter metadataImporter, INamer namer, IRuntimeLibrary runtimeLibrary, IErrorReporter errorReporter, Func<IType, JsExpression> instantiateType, bool includeDeclaringType) {
			var result = new List<JsObjectLiteralProperty>();
			var attr = m.Attributes.Where(a => !a.IsConditionallyRemoved && metadataImporter.GetTypeSemantics(a.AttributeType.GetDefinition()).Type == TypeScriptSemantics.ImplType.NormalType).ToList();
			if (attr.Count > 0)
				result.Add(new JsObjectLiteralProperty("attr", JsExpression.ArrayLiteral(attr.Select(a => ConstructAttribute(a, m.DeclaringTypeDefinition, compilation, metadataImporter, namer, runtimeLibrary, errorReporter)))));
			if (includeDeclaringType)
				result.Add(new JsObjectLiteralProperty("typeDef", instantiateType(m.DeclaringType)));

			result.Add(new JsObjectLiteralProperty("name", JsExpression.String(m.Name)));
			return result;
		}
Beispiel #11
0
 public static bool IsMutableValueType(IType type, IMetadataImporter metadataImporter)
 {
     return(type.Kind == TypeKind.Struct && metadataImporter.GetTypeSemantics(type.GetDefinition()).Type == TypeScriptSemantics.ImplType.MutableValueType);
 }
 public virtual TypeScriptSemantics GetTypeSemantics(ITypeDefinition typeDefinition)
 {
     return(_prev.GetTypeSemantics(typeDefinition));
 }
Beispiel #13
0
		public static JsExpression ResolveTypeParameter(ITypeParameter tp, ITypeDefinition currentType, IMethod currentMethod, IMetadataImporter metadataImporter, IErrorReporter errorReporter, INamer namer) {
			bool unusable = false;
			switch (tp.OwnerType) {
				case EntityType.TypeDefinition:
					unusable = metadataImporter.GetTypeSemantics(currentType).IgnoreGenericArguments;
					break;
				case EntityType.Method: {
					var sem = metadataImporter.GetMethodSemantics(currentMethod);
					unusable = sem.Type != MethodScriptSemantics.ImplType.InlineCode && metadataImporter.GetMethodSemantics(currentMethod).IgnoreGenericArguments;
					break;
				}
				default:
					errorReporter.InternalError("Invalid owner " + tp.OwnerType + " for type parameter " + tp);
					return JsExpression.Null;
			}
			if (unusable) {
				errorReporter.Message(Messages._7536, tp.Name, tp.OwnerType == EntityType.TypeDefinition ? "type" : "method", tp.OwnerType == EntityType.TypeDefinition ? currentType.FullName : currentMethod.FullName);
				return JsExpression.Null;
			}
			return JsExpression.Identifier(namer.GetTypeParameterName(tp));
		}
 public static bool IsJsGeneric(ITypeDefinition type, IMetadataImporter metadataImporter)
 {
     return(type.TypeParameterCount > 0 && !metadataImporter.GetTypeSemantics(type).IgnoreGenericArguments);
 }
		public static bool IsReflectable(IMember member, IMetadataImporter metadataImporter) {
			return member.Attributes.Any(a => a.AttributeType.FullName == typeof(ReflectableAttribute).FullName || metadataImporter.GetTypeSemantics(a.AttributeType.GetDefinition()).Type == TypeScriptSemantics.ImplType.NormalType);
		}
 public static IEnumerable <IAttribute> GetScriptableAttributes(IEnumerable <IAttribute> attributes, IMetadataImporter metadataImporter)
 {
     return(attributes.Where(a => !a.IsConditionallyRemoved && metadataImporter.GetTypeSemantics(a.AttributeType.GetDefinition()).Type != TypeScriptSemantics.ImplType.NotUsableFromScript));
 }
Beispiel #17
0
		public static bool IsMutableValueType(IType type, IMetadataImporter metadataImporter) {
			return type.Kind == TypeKind.Struct && metadataImporter.GetTypeSemantics(type.GetDefinition()).Type == TypeScriptSemantics.ImplType.MutableValueType;
		}