Ejemplo n.º 1
0
		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);
				}
			}
		}
Ejemplo n.º 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);
				}
			}
		}
Ejemplo n.º 3
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);
		}
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 6
0
 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));
 }
Ejemplo n.º 7
0
		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);
		}
Ejemplo n.º 8
0
		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;
		}
Ejemplo n.º 9
0
		public static bool IsJsGeneric(ITypeDefinition type, IMetadataImporter metadataImporter) {
			return type.TypeParameterCount > 0 && !metadataImporter.GetTypeSemantics(type).IgnoreGenericArguments;
		}
Ejemplo n.º 10
0
		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;
		}
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
		}
Ejemplo n.º 14
0
 public static bool IsJsGeneric(ITypeDefinition type, IMetadataImporter metadataImporter)
 {
     return(type.TypeParameterCount > 0 && !metadataImporter.GetTypeSemantics(type).IgnoreGenericArguments);
 }
Ejemplo n.º 15
0
		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);
		}
Ejemplo n.º 16
0
 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));
 }
Ejemplo n.º 17
0
		public static bool IsMutableValueType(IType type, IMetadataImporter metadataImporter) {
			return type.Kind == TypeKind.Struct && metadataImporter.GetTypeSemantics(type.GetDefinition()).Type == TypeScriptSemantics.ImplType.MutableValueType;
		}