private static bool HasTypeCycle(ITypeReference type, IFieldDefinition /*?*/ offendingField, Stack <ITypeReference> seenTypes, LanguageSpecificCompilationHelper helper) { if (type.TypeCode != PrimitiveTypeCode.NotPrimitive || !type.ResolvedType.IsStruct) { return(false); } lock (GlobalLock.LockingObject) { if (typesWithKnownLoops.ContainsKey(type)) { return(true); } } if (seenTypes.Contains(type)) { lock (GlobalLock.LockingObject) { if (!typesWithKnownLoops.ContainsKey(type)) { typesWithKnownLoops.Add(type, true); var location = IteratorHelper.First(helper.Compilation.SourceLocationProvider.GetPrimarySourceLocationsFor(type.Locations)); helper.ReportError( new VccErrorMessage(location, Error.ValueTypeLayoutCycle, offendingField.Name.Value, helper.GetTypeName(type.ResolvedType))); } } return(true); } seenTypes.Push(type); bool hasCycle = false; foreach (var field in IteratorHelper.GetFilterEnumerable <ITypeDefinitionMember, IFieldDefinition>(type.ResolvedType.Members)) { if (!field.IsStatic) { hasCycle |= VccStructuredTypeDeclaration.HasTypeCycle(field.Type, field, seenTypes, helper); } } seenTypes.Pop(); return(hasCycle); }
private static bool HasTypeCycle(ITypeReference type, IFieldDefinition/*?*/ offendingField, Stack<ITypeReference> seenTypes, LanguageSpecificCompilationHelper helper) { if (type.TypeCode != PrimitiveTypeCode.NotPrimitive || !type.ResolvedType.IsStruct) return false; lock (GlobalLock.LockingObject) { if (typesWithKnownLoops.ContainsKey(type)) return true; } if (seenTypes.Contains(type)) { lock (GlobalLock.LockingObject) { if (!typesWithKnownLoops.ContainsKey(type)) { typesWithKnownLoops.Add(type, true); var location = IteratorHelper.First(helper.Compilation.SourceLocationProvider.GetPrimarySourceLocationsFor(type.Locations)); helper.ReportError( new VccErrorMessage(location, Error.ValueTypeLayoutCycle, offendingField.Name.Value, helper.GetTypeName(type.ResolvedType))); } } return true; } seenTypes.Push(type); bool hasCycle = false; foreach (var field in IteratorHelper.GetFilterEnumerable<ITypeDefinitionMember, IFieldDefinition>(type.ResolvedType.Members)) { if (!field.IsStatic) { hasCycle |= VccStructuredTypeDeclaration.HasTypeCycle(field.Type, field, seenTypes, helper); } } seenTypes.Pop(); return hasCycle; }
internal static bool HasFieldOfUnspecifiedType(ITypeReference type, IEnumerable <ITypeDefinitionMember> members, LanguageSpecificCompilationHelper helper) { bool errorFound = false; foreach (var member in members) { var field = member as IFieldDefinition; if (field != null && field.Type == helper.Compilation.PlatformType.SystemVoid.ResolvedType) { var fieldDecl = ((Cci.Ast.FieldDefinition)field).Declaration as FieldDefinition; var location = IteratorHelper.First(helper.Compilation.SourceLocationProvider.GetPrimarySourceLocationsFor(type.Locations)); helper.ReportError( new VccErrorMessage(location, Error.IllegalUseOfUndefinedType, field.Name.Value, fieldDecl != null ? fieldDecl.Type.SourceLocation.Source : helper.GetTypeName(field.Type.ResolvedType))); errorFound = true; } } return(errorFound); }
internal static bool HasFieldOfUnspecifiedType(ITypeReference type, IEnumerable<ITypeDefinitionMember> members, LanguageSpecificCompilationHelper helper) { bool errorFound = false; foreach (var member in members) { var field = member as IFieldDefinition; if (field != null && field.Type == helper.Compilation.PlatformType.SystemVoid.ResolvedType) { var fieldDecl = ((Cci.Ast.FieldDefinition) field).Declaration as FieldDefinition; var location = IteratorHelper.First(helper.Compilation.SourceLocationProvider.GetPrimarySourceLocationsFor(type.Locations)); helper.ReportError( new VccErrorMessage(location, Error.IllegalUseOfUndefinedType, field.Name.Value, fieldDecl != null ? fieldDecl.Type.SourceLocation.Source : helper.GetTypeName(field.Type.ResolvedType))); errorFound = true; } } return errorFound; }