public void SetGenerateTypeOptions( Accessibility accessibility = Accessibility.NotApplicable, TypeKind typeKind = TypeKind.Class, string typeName = null, Project project = null, bool isNewFile = false, string newFileName = null, IList<string> folders = null, string fullFilePath = null, Document existingDocument = null, bool areFoldersValidIdentifiers = true, string defaultNamespace = null, bool isCancelled = false) { Accessibility = accessibility; TypeKind = typeKind; TypeName = typeName; Project = project; IsNewFile = isNewFile; NewFileName = newFileName; Folders = folders; FullFilePath = fullFilePath; ExistingDocument = existingDocument; AreFoldersValidIdentifiers = areFoldersValidIdentifiers; DefaultNamespace = defaultNamespace; IsCancelled = isCancelled; }
internal TypeDesc(string name, string fullName, XmlSchemaType dataType, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags, string formatterName) { this.name = name.Replace('+', '.'); this.fullName = fullName.Replace('+', '.'); this.kind = kind; this.baseTypeDesc = baseTypeDesc; this.flags = flags; this.isXsdType = kind == TypeKind.Primitive; if (this.isXsdType) { this.weight = 1; } else if (kind == TypeKind.Enum) { this.weight = 2; } else if (this.kind == TypeKind.Root) { this.weight = -1; } else { this.weight = (baseTypeDesc == null) ? 0 : (baseTypeDesc.Weight + 1); } this.dataType = dataType; this.formatterName = formatterName; }
public CodeGenerationNamedTypeSymbol( INamedTypeSymbol containingType, IList<AttributeData> attributes, Accessibility declaredAccessibility, DeclarationModifiers modifiers, TypeKind typeKind, string name, IList<ITypeParameterSymbol> typeParameters, INamedTypeSymbol baseType, IList<INamedTypeSymbol> interfaces, SpecialType specialType, IList<ISymbol> members, IList<CodeGenerationAbstractNamedTypeSymbol> typeMembers, INamedTypeSymbol enumUnderlyingType) : base(containingType, attributes, declaredAccessibility, modifiers, name, specialType, typeMembers) { _typeKind = typeKind; _typeParameters = typeParameters ?? SpecializedCollections.EmptyList<ITypeParameterSymbol>(); _baseType = baseType; _interfaces = interfaces ?? SpecializedCollections.EmptyList<INamedTypeSymbol>(); _members = members ?? SpecializedCollections.EmptyList<ISymbol>(); _enumUnderlyingType = enumUnderlyingType; this.OriginalDefinition = this; }
public KindsRestriction(TypeKind[] kinds) { if (kinds == null) throw Error.ArgumentNull("kinds"); this.kinds = kinds; }
internal SynthesizedContainer(MethodSymbol topLevelMethod, string name, TypeKind typeKind) { this.typeKind = typeKind; this.containingSymbol = topLevelMethod.ContainingType; this.name = name; this.TypeMap = TypeMap.Empty.WithAlphaRename(topLevelMethod, this, out this.typeParameters); }
public GenerateTypeOptionsResult( Accessibility accessibility, TypeKind typeKind, string typeName, Project project, bool isNewFile, string newFileName, IList<string> folders, string fullFilePath, Document existingDocument, bool areFoldersValidIdentifiers, bool isCancelled = false) { this.Accessibility = accessibility; this.TypeKind = typeKind; this.TypeName = typeName; this.Project = project; this.IsNewFile = isNewFile; this.NewFileName = newFileName; this.Folders = folders; this.FullFilePath = fullFilePath; this.ExistingDocument = existingDocument; this.AreFoldersValidIdentifiers = areFoldersValidIdentifiers; this.IsCancelled = isCancelled; }
public MockType(string name = "", bool? isReferenceType = false, TypeKind kind = TypeKind.Class) { this.name = name; this.isReferenceType = isReferenceType; this.kind = kind; BaseTypes = new List<IType>(); }
private bool HasKind(TypeKind candidate) { foreach (var kind in kinds) if (kind == candidate) return true; return false; }
public AsyncStateMachine(VariableSlotAllocator variableAllocatorOpt, TypeCompilationState compilationState, MethodSymbol asyncMethod, int asyncMethodOrdinal, TypeKind typeKind) : base(variableAllocatorOpt, compilationState, asyncMethod, asyncMethodOrdinal) { // TODO: report use-site errors on these types _typeKind = typeKind; _interfaces = ImmutableArray.Create(asyncMethod.DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IAsyncStateMachine)); _constructor = new AsyncConstructor(this); }
internal SynthesizedContainer(NamedTypeSymbol containingType, string name, TypeKind typeKind) { this.typeKind = typeKind; this.containingSymbol = containingType; this.name = name; this.TypeMap = TypeMap.Empty; this.typeParameters = ImmutableArray<TypeParameterSymbol>.Empty; }
public TypeSpecifier(string name, TypeKind kind, TypedNodeList typeParameters, Location location) : base(location) { this.name = name; this.kind = kind; this.typeParameters = typeParameters; }
public AsyncStateMachine(MethodSymbol asyncMethod, TypeKind typeKind) : base(GeneratedNames.MakeStateMachineTypeName(asyncMethod.Name, SequenceNumber(asyncMethod)), asyncMethod) { // TODO: report use-site errors on these types this.typeKind = typeKind; this.asyncMethod = asyncMethod; this.interfaces = ImmutableArray.Create(asyncMethod.DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IAsyncStateMachine)); this.constructor = new AsyncConstructor(this); }
public void copy(typeIR b) { this.Count.value = b.Count.value; this.Kind = b.Kind; this.More.ArrayAttr.low = b.More.ArrayAttr.low; this.More.ArrayAttr.top = b.More.ArrayAttr.top; this.More.ArrayAttr.elemTy = b.More.ArrayAttr.elemTy; this.More.ArrayAttr.indexTy = b.More.ArrayAttr.indexTy; this.More.body = b.More.body; }
public TypeDesc(string name, string fullName, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags) { this.name = name.Replace('+', '.'); this.fullName = fullName.Replace('+', '.'); this.kind = kind; if (baseTypeDesc != null) { this.baseTypeDesc = baseTypeDesc; } this.flags = flags; this.isXsdType = kind == TypeKind.Primitive; }
public static string ToString(TypeKind typeKind, object value) { switch (typeKind) { case TypeKind.String: return (string)value; case TypeKind.IgnoreCaseString: return ((IgnoreCaseString)value).Value; case TypeKind.Char: return ((char)value).ToString(); case TypeKind.Decimal: return ((decimal)value).ToInvString(); case TypeKind.Int64: return ((long)value).ToInvString(); case TypeKind.Int32: return ((int)value).ToInvString(); case TypeKind.Int16: return ((short)value).ToInvString(); case TypeKind.SByte: return ((sbyte)value).ToInvString(); case TypeKind.UInt64: return ((ulong)value).ToInvString(); case TypeKind.UInt32: return ((uint)value).ToInvString(); case TypeKind.UInt16: return ((ushort)value).ToInvString(); case TypeKind.Byte: return ((byte)value).ToInvString(); case TypeKind.Double: { bool isLiteral; return ((double)value).ToInvString(out isLiteral); } case TypeKind.Single: { bool isLiteral; return ((float)value).ToInvString(out isLiteral); } case TypeKind.Boolean: return ((bool)value).ToInvString(); case TypeKind.Binary: return ((Binary)value).ToBase64String(); case TypeKind.Guid: return ((Guid)value).ToInvString(); case TypeKind.TimeSpan: return ((TimeSpan)value).ToInvString(); case TypeKind.DateTimeOffset: return ((DateTimeOffset)value).ToInvString(); default: throw new ArgumentException("Invalid type kind: " + typeKind.ToString()); } }
internal ModifiedType(TypeKind kind, Type modifier, Type baseType) : base(kind.Check(kind.IsModifiedType(), "Not a valid modified type kind", "kind")) { if (Kind == TypeKind.ModOpt || Kind == TypeKind.ModReq) { m_modfier = modifier.CheckNotNull("modifier"); } else { m_modfier = modifier.CheckNull("modifier", "A modifier type may only be specified for ModOpt and ModReq types"); } m_baseType = baseType.CheckNotNull("baseType"); }
internal ProjectionCollectionType(TypeKind kind, Type type, ProjectionFactory factory) : base(type, kind, factory) { // Must register before getting key/item types, due to possible cycles // Example: A -> IList<B> -> B -> IList<B> factory.RegisterProjectionType(this); Type keyType, itemType; GetSubtypes(out keyType, out itemType); this.keyType = factory.GetProjectionTypeUnsafe(keyType ); this.itemType = factory.GetProjectionTypeUnsafe(itemType); }
private static IEnumerable<INamedTypeSymbol> Resolve( SymbolKeyReader reader, INamespaceOrTypeSymbol container, string metadataName, int arity, TypeKind typeKind, bool isUnboundGenericType, ImmutableArray<SymbolKeyResolution> typeArguments) { var types = container.GetTypeMembers(GetName(metadataName), arity); var result = InstantiateTypes( reader.Compilation, reader.IgnoreAssemblyKey, types, arity, typeArguments); return isUnboundGenericType ? result.Select(t => t.ConstructUnboundGenericType()) : result; }
public TypeMetadata(string typeName, string @namespace, string csharpName, string scriptName, IReadOnlyList<string> tagNames, bool generate, bool inherit, TypeKind typeKind, bool includeConstructors, IReadOnlyList<TypeOverride> typeOverrides, AstType aliasFor, IEnumerable<Tuple<string, string>> renames, IEnumerable<string> removes, IReadOnlyList<string> addInDerivedTypes, IReadOnlyList<GeneratedEnum> generatedEnums) { TypeName = typeName; Namespace = @namespace; CSharpName = csharpName; ScriptName = scriptName; TagNames = tagNames.AsReadOnlySafe(); Generate = generate && typeKind != TypeKind.Mixin && typeKind != TypeKind.Skip; Inherit = inherit; TypeKind = typeKind; IncludeConstructors = includeConstructors; TypeOverrides = typeOverrides.AsReadOnlySafe(); AliasFor = aliasFor; Renames = new ReadOnlyDictionary<string, string>((renames ?? new Tuple<string, string>[0]).ToDictionary(x => x.Item1, x => x.Item2)); Removes = removes.AsReadOnlySafe(); AddInDerivedTypes = addInDerivedTypes.AsReadOnlySafe(); GeneratedEnums = generatedEnums.AsReadOnlySafe(); }
public CType(TypeKind k, string typeName) { Kind = k; if (k == TypeKind.Unknown) return; if (!string2pt.ContainsKey(typeName)) { IsPrimitive = false; // TODO: Search in structures array and throw if not found! } else { IsPrimitive = true; Prim = string2pt[typeName]; } Name = typeName; }
internal LambdaFrame(MethodSymbol topLevelMethod, MethodSymbol containingMethod, bool isStruct, SyntaxNode scopeSyntaxOpt, DebugId methodId, DebugId closureId) : base(MakeName(scopeSyntaxOpt, methodId, closureId), containingMethod) { _typeKind = isStruct ? TypeKind.Struct : TypeKind.Class; _topLevelMethod = topLevelMethod; _containingMethod = containingMethod; _constructor = isStruct ? null : new LambdaFrameConstructor(this); this.ClosureOrdinal = closureId.Ordinal; // static lambdas technically have the class scope so the scope syntax is null if (scopeSyntaxOpt == null) { _staticConstructor = new SynthesizedStaticConstructor(this); var cacheVariableName = GeneratedNames.MakeCachedFrameInstanceFieldName(); _singletonCache = new SynthesizedLambdaCacheFieldSymbol(this, this, cacheVariableName, topLevelMethod, isReadOnly: true, isStatic: true); } AssertIsClosureScopeSyntax(scopeSyntaxOpt); this.ScopeSyntaxOpt = scopeSyntaxOpt; }
internal VB6UnresolvedTypeDefinition(IUnresolvedFile file, IVbModule module, IVbpProject project) : base(file, null) { this.Module = module; _typeKind = this.Module.ToTypeKind(); this.Accessibility = (_typeKind != TypeKind.Module) ? Accessibility.Public : Accessibility.Private; _events = new List<IUnresolvedEvent>(); _fields = new List<IUnresolvedField>(); _properties = new List<IUnresolvedProperty>(); _methods = new List<IUnresolvedMethod>(); _members = new List<IUnresolvedMember>(); this.DeclaringTypeDefinition = this; this.FullName = GetName(true); this.Name = GetName(false); this.Namespace = "(implicit)"; this.ReflectionName = GetName(true); ProcessModule(); }
public BookmarkedSymbolType(INamedTypeSymbol symbol) { Arity = symbol.Arity; Name = symbol.Name; TypeKind = symbol.TypeKind; }
private static void AnalyzeNamedType(SymbolAnalysisContext context) { if (context.Symbol.IsImplicitlyDeclared) { return; } var symbol = (INamedTypeSymbol)context.Symbol; TypeKind typeKind = symbol.TypeKind; if (typeKind == TypeKind.Class || typeKind == TypeKind.Struct) { if (symbol.IsPubliclyVisible()) { ImmutableArray <INamedTypeSymbol> interfaces = symbol.Interfaces; if (interfaces.Any()) { bool fIComparable = false; bool fIComparableOfT = false; bool fIComparer = false; bool fIComparerOfT = false; bool fIEqualityComparer = false; bool fIEqualityComparerOfT = false; foreach (INamedTypeSymbol interfaceSymbol in interfaces) { switch (interfaceSymbol.MetadataName) { case "IComparable": { if (interfaceSymbol.HasMetadataName(MetadataNames.System_IComparable)) { fIComparable = true; } break; } case "IComparable`1": { if (interfaceSymbol.HasMetadataName(MetadataNames.System_IComparable_T)) { fIComparableOfT = true; } break; } case "IComparer": { if (interfaceSymbol.HasMetadataName(MetadataNames.System_Collections_IComparer)) { fIComparer = true; } break; } case "IComparer`1": { if (interfaceSymbol.HasMetadataName(MetadataNames.System_Collections_Generic_IComparer_T)) { fIComparerOfT = true; } break; } case "IEqualityComparer": { if (interfaceSymbol.HasMetadataName(MetadataNames.System_Collections_IEqualityComparer)) { fIEqualityComparer = true; } break; } case "IEqualityComparer`1": { if (interfaceSymbol.HasMetadataName(MetadataNames.System_Collections_Generic_IEqualityComparer_T)) { fIEqualityComparerOfT = true; } break; } } } if (fIComparableOfT && !fIComparable) { ReportDiagnostic(context, symbol, "IComparable"); } if (fIComparerOfT && !fIComparer) { ReportDiagnostic(context, symbol, "IComparer"); } if (fIEqualityComparerOfT && !fIEqualityComparer) { ReportDiagnostic(context, symbol, "IEqualityComparer"); } } } } }
public MockNamedTypeSymbol(string name, IEnumerable <Symbol> children, TypeKind kind = TypeKind.Class) { this.name = name; this.children = children; this.typeKind = kind; }
public SymbolKindViewModel(TypeKind typeKind, string name, SymbolSpecification specification) { this._typeKind = typeKind; Name = name; IsChecked = specification.ApplicableSymbolKindList.Any(k => k.TypeKind == typeKind); }
public SymbolKindOrTypeKind(TypeKind typeKind) { TypeKind = typeKind; }
internal TypeDesc(string name, string fullName, XmlSchemaType dataType, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags, string formatterName) { _name = name.Replace('+', '.'); _fullName = fullName.Replace('+', '.'); _kind = kind; _baseTypeDesc = baseTypeDesc; _flags = flags; _isXsdType = kind == TypeKind.Primitive; if (_isXsdType) _weight = 1; else if (kind == TypeKind.Enum) _weight = 2; else if (_kind == TypeKind.Root) _weight = -1; else _weight = baseTypeDesc == null ? 0 : baseTypeDesc.Weight + 1; _dataType = dataType; _formatterName = formatterName; }
public static bool IsTypeKind(this ITypeSymbol typeSymbol, TypeKind typeKind1, TypeKind typeKind2, TypeKind typeKind3) { if (typeSymbol == null) { return(false); } TypeKind typeKind = typeSymbol.TypeKind; return(typeKind == typeKind1 || typeKind == typeKind2 || typeKind == typeKind3); }
internal TypeDesc(string name, string fullName, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags) : this(name, fullName, (XmlSchemaType)null, kind, baseTypeDesc, flags, null) { }
static CompletionImage GetCompletionImageForType(TypeKind typeKind, bool isStatic) { switch (typeKind) { case TypeKind.Interface: return imageInterface; case TypeKind.Struct: case TypeKind.Void: return imageStruct; case TypeKind.Delegate: return imageDelegate; case TypeKind.Enum: return imageEnum; case TypeKind.Class: return isStatic ? imageStaticClass : imageClass; case TypeKind.Module: return imageStaticClass; default: return null; } }
public void SetTypeKind(TypeKind kind) { _typeKind = kind; }
public static void AnalyzeBaseList(SyntaxNodeAnalysisContext context) { var baseList = (BaseListSyntax)context.Node; if (baseList.IsParentKind(SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKind.InterfaceDeclaration) && !baseList.ContainsDiagnostics && !baseList.SpanContainsDirectives()) { SeparatedSyntaxList <BaseTypeSyntax> baseTypes = baseList.Types; if (baseTypes.Count > 1) { bool isFirst = true; INamedTypeSymbol typeSymbol = null; var baseClassInfo = default(SymbolInterfaceInfo); List <SymbolInterfaceInfo> baseInterfaceInfos = null; foreach (BaseTypeSyntax baseType in baseTypes) { TypeSyntax type = baseType.Type; if (type?.IsMissing == false) { var baseSymbol = context.SemanticModel.GetSymbol(type, context.CancellationToken) as INamedTypeSymbol; if (baseSymbol != null) { TypeKind typeKind = baseSymbol.TypeKind; ImmutableArray <INamedTypeSymbol> allInterfaces = baseSymbol.AllInterfaces; if (typeKind == TypeKind.Class) { if (!isFirst) { break; } if (allInterfaces.Any()) { baseClassInfo = new SymbolInterfaceInfo(baseType, baseSymbol, allInterfaces); } } else if (typeKind == TypeKind.Interface) { var baseInterfaceInfo = new SymbolInterfaceInfo(baseType, baseSymbol, allInterfaces); if (baseInterfaceInfos == null) { if (allInterfaces.Any()) { baseInterfaceInfos = new List <SymbolInterfaceInfo>() { baseInterfaceInfo } } ; } else { foreach (SymbolInterfaceInfo baseInterfaceInfo2 in baseInterfaceInfos) { Analyze(context, baseInterfaceInfo, baseInterfaceInfo2); Analyze(context, baseInterfaceInfo2, baseInterfaceInfo); } } if (baseClassInfo.IsValid) { if (typeSymbol == null) { typeSymbol = context.SemanticModel.GetDeclaredSymbol((TypeDeclarationSyntax)baseList.Parent, context.CancellationToken); } Analyze(context, baseInterfaceInfo, baseClassInfo, typeSymbol); } } } } if (isFirst) { isFirst = false; } } } } }
public static bool TypeIsOfKind(PLanguageType type, TypeKind kind) { return(type.Canonicalize().TypeKind.Equals(kind)); }
internal static extern CXString clang_getTypeKindSpelling(TypeKind kind);
internal TypeListItem(ProjectId projectId, INamedTypeSymbol typeSymbol, string displayText, string fullNameText, string searchText, bool isHidden) : base(projectId, typeSymbol, displayText, fullNameText, searchText, isHidden) { _typeKind = typeSymbol.TypeKind; }
private OdcmType ResolveType(IEdmSchemaElement realizedSchemaElement, TypeKind kind) { return(ResolveType(realizedSchemaElement.Name, realizedSchemaElement.Namespace, kind)); }
public SymbolKindOrTypeKind(TypeKind typeKind) : this() { SymbolKind = null; TypeKind = typeKind; MethodKind = null; }
private void PopulateTypeKind(TypeKind typeKind, string visualBasicKey) { _typeKindMap.Add(visualBasicKey, typeKind); _visualBasicTypeKindList.Add(visualBasicKey); }
internal static Tuple types(Type type, TypeKind kind, params string[] name) => new Tuple("types", type, kind, name);
public static bool Is(this ITypeSymbol self, TypeKind typeKind) { return(self != null && self.TypeKind == typeKind); }
protected NamedTypeBase(TypeKind kind) : base(kind) { }
public static bool IsTypeKind(this ITypeSymbol typeSymbol, TypeKind typeKind) { return(typeSymbol?.TypeKind == typeKind); }
// process the base list for one part of a partial class, or for the only part of any other type declaration. private Tuple <NamedTypeSymbol, ImmutableArray <NamedTypeSymbol> > MakeOneDeclaredBases(ConsList <TypeSymbol> newBasesBeingResolved, SingleTypeDeclaration decl, DiagnosticBag diagnostics) { BaseListSyntax bases = GetBaseListOpt(decl); if (bases == null) { return(null); } NamedTypeSymbol localBase = null; var localInterfaces = ArrayBuilder <NamedTypeSymbol> .GetInstance(); var baseBinder = this.DeclaringCompilation.GetBinder(bases); // Wrap base binder in a location-specific binder that will avoid generic constraint checks // (to avoid cycles if the constraint types are not bound yet). Instead, constraint checks // are handled by the caller. baseBinder = baseBinder.WithAdditionalFlagsAndContainingMemberOrLambda(BinderFlags.SuppressConstraintChecks, this); int i = -1; foreach (var baseTypeSyntax in bases.Types) { i++; var typeSyntax = baseTypeSyntax.Type; if (typeSyntax.Kind() != SyntaxKind.PredefinedType && !SyntaxFacts.IsName(typeSyntax.Kind())) { diagnostics.Add(ErrorCode.ERR_BadBaseType, typeSyntax.GetLocation()); } var location = new SourceLocation(typeSyntax); TypeSymbol baseType; if (i == 0 && TypeKind == TypeKind.Class) // allow class in the first position { baseType = baseBinder.BindType(typeSyntax, diagnostics, newBasesBeingResolved).Type; SpecialType baseSpecialType = baseType.SpecialType; if (IsRestrictedBaseType(baseSpecialType)) { // check for one of the specific exceptions required for compiling mscorlib if (this.SpecialType == SpecialType.System_Enum && baseSpecialType == SpecialType.System_ValueType || this.SpecialType == SpecialType.System_MulticastDelegate && baseSpecialType == SpecialType.System_Delegate) { // allowed } else if (baseSpecialType == SpecialType.System_Array && this.ContainingAssembly.CorLibrary == this.ContainingAssembly) { // Specific exception for System.ArrayContracts, which is only built when CONTRACTS_FULL is defined. // (See InheritanceResolver::CheckForBaseClassErrors). } else { // '{0}' cannot derive from special class '{1}' diagnostics.Add(ErrorCode.ERR_DeriveFromEnumOrValueType, location, this, baseType); continue; } } if (baseType.IsSealed && !this.IsStatic) // Give precedence to ERR_StaticDerivedFromNonObject { diagnostics.Add(ErrorCode.ERR_CantDeriveFromSealedType, location, this, baseType); continue; } bool baseTypeIsErrorWithoutInterfaceGuess = false; // If baseType is an error symbol and our best guess is that the desired symbol // is an interface, then put baseType in the interfaces list, rather than the // base type slot, to avoid the frustrating scenario where an error message // indicates that the symbol being returned as the base type was elsewhere // interpreted as an interface. if (baseType.TypeKind == TypeKind.Error) { baseTypeIsErrorWithoutInterfaceGuess = true; TypeKind guessTypeKind = baseType.GetNonErrorTypeKindGuess(); if (guessTypeKind == TypeKind.Interface) { //base type is an error *with* a guessed interface baseTypeIsErrorWithoutInterfaceGuess = false; } } if ((baseType.TypeKind == TypeKind.Class || baseType.TypeKind == TypeKind.Delegate || baseType.TypeKind == TypeKind.Struct || baseTypeIsErrorWithoutInterfaceGuess) && ((object)localBase == null)) { localBase = (NamedTypeSymbol)baseType; Debug.Assert((object)localBase != null); if (this.IsStatic && localBase.SpecialType != SpecialType.System_Object) { // Static class '{0}' cannot derive from type '{1}'. Static classes must derive from object. var info = diagnostics.Add(ErrorCode.ERR_StaticDerivedFromNonObject, location, this, localBase); localBase = new ExtendedErrorTypeSymbol(localBase, LookupResultKind.NotReferencable, info); } continue; } } else { baseType = baseBinder.BindType(typeSyntax, diagnostics, newBasesBeingResolved).Type; } switch (baseType.TypeKind) { case TypeKind.Interface: foreach (var t in localInterfaces) { if (t.Equals(baseType, TypeCompareKind.ConsiderEverything)) { diagnostics.Add(ErrorCode.ERR_DuplicateInterfaceInBaseList, location, baseType); } else if (t.Equals(baseType, TypeCompareKind.ObliviousNullableModifierMatchesAny)) { // duplicates with ?/! differences are reported later, we report local differences between oblivious and ?/! here diagnostics.Add(ErrorCode.WRN_DuplicateInterfaceWithNullabilityMismatchInBaseList, location, baseType, this); } } if (this.IsStatic) { // '{0}': static classes cannot implement interfaces diagnostics.Add(ErrorCode.ERR_StaticClassInterfaceImpl, location, this, baseType); } if (this.IsRefLikeType) { // '{0}': ref structs cannot implement interfaces diagnostics.Add(ErrorCode.ERR_RefStructInterfaceImpl, location, this, baseType); } if (baseType.ContainsDynamic()) { diagnostics.Add(ErrorCode.ERR_DeriveFromConstructedDynamic, location, this, baseType); } localInterfaces.Add((NamedTypeSymbol)baseType); continue; case TypeKind.Class: if (TypeKind == TypeKind.Class) { if ((object)localBase == null) { localBase = (NamedTypeSymbol)baseType; diagnostics.Add(ErrorCode.ERR_BaseClassMustBeFirst, location, baseType); continue; } else { diagnostics.Add(ErrorCode.ERR_NoMultipleInheritance, location, this, localBase, baseType); continue; } } goto default; case TypeKind.TypeParameter: diagnostics.Add(ErrorCode.ERR_DerivingFromATyVar, location, baseType); continue; case TypeKind.Error: // put the error type in the interface list so we don't lose track of it localInterfaces.Add((NamedTypeSymbol)baseType); continue; case TypeKind.Dynamic: diagnostics.Add(ErrorCode.ERR_DeriveFromDynamic, location, this); continue; case TypeKind.Submission: throw ExceptionUtilities.UnexpectedValue(baseType.TypeKind); default: diagnostics.Add(ErrorCode.ERR_NonInterfaceInInterfaceList, location, baseType); continue; } } if (this.SpecialType == SpecialType.System_Object && ((object)localBase != null || localInterfaces.Count != 0)) { var name = GetName(bases.Parent); diagnostics.Add(ErrorCode.ERR_ObjectCantHaveBases, new SourceLocation(name)); } return(new Tuple <NamedTypeSymbol, ImmutableArray <NamedTypeSymbol> >(localBase, localInterfaces.ToImmutableAndFree())); }
internal static void types(this TextWriter trapFile, Type type, TypeKind kind, string name) { trapFile.WriteTuple("types", type, (int)kind, name); }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <param name="semanticModel"></param> /// <param name="typeKind"></param> /// <returns></returns> protected override Rosetta.AST.Helpers.BaseTypeReference CreateBaseTypeReferenceHelper(BaseTypeSyntax node, SemanticModel semanticModel, TypeKind typeKind) { return(new Rosetta.ScriptSharp.AST.Helpers.BaseTypeReference(node, semanticModel, typeKind)); }
protected PLanguageType(TypeKind kind) { TypeKind = kind; }
public static async Task <bool> IsValidNewMemberNameAsync(SemanticModel semanticModel, ISymbol symbol, string name, CancellationToken cancellationToken) { if (symbol.Kind == SymbolKind.NamedType) { TypeKind typeKind = ((INamedTypeSymbol)symbol).TypeKind; // If the symbol is a class or struct, the name can't be the same as any of its members. if (typeKind == TypeKind.Class || typeKind == TypeKind.Struct) { var members = (symbol as INamedTypeSymbol)?.GetMembers(name); if (members.HasValue && !members.Value.IsDefaultOrEmpty) { return(false); } } } var containingSymbol = symbol.ContainingSymbol; if (symbol.Kind == SymbolKind.TypeParameter) { // If the symbol is a type parameter, the name can't be the same as any type parameters of the containing type. var parentSymbol = containingSymbol?.ContainingSymbol as INamedTypeSymbol; if (parentSymbol != null && parentSymbol.TypeParameters.Any(t => t.Name == name)) { return(false); } // Move up one level for the next validation step. containingSymbol = containingSymbol?.ContainingSymbol; } var containingNamespaceOrTypeSymbol = containingSymbol as INamespaceOrTypeSymbol; if (containingNamespaceOrTypeSymbol != null) { if (containingNamespaceOrTypeSymbol.Kind == SymbolKind.Namespace) { // Make sure to use the compilation namespace so interfaces in referenced assemblies are considered containingNamespaceOrTypeSymbol = semanticModel.Compilation.GetCompilationNamespace((INamespaceSymbol)containingNamespaceOrTypeSymbol); } else if (containingNamespaceOrTypeSymbol.Kind == SymbolKind.NamedType) { TypeKind typeKind = ((INamedTypeSymbol)containingNamespaceOrTypeSymbol).TypeKind; // If the containing type is a class or struct, the name can't be the same as the name of the containing // type. if ((typeKind == TypeKind.Class || typeKind == TypeKind.Struct) && containingNamespaceOrTypeSymbol.Name == name) { return(false); } } // The name can't be the same as the name of an other member of the same type. At this point no special // consideration is given to overloaded methods. ImmutableArray <ISymbol> siblings = containingNamespaceOrTypeSymbol.GetMembers(name); if (!siblings.IsDefaultOrEmpty) { return(false); } return(true); } else if (containingSymbol.Kind == SymbolKind.Method) { IMethodSymbol methodSymbol = (IMethodSymbol)containingSymbol; if (methodSymbol.Parameters.Any(i => i.Name == name) || methodSymbol.TypeParameters.Any(i => i.Name == name)) { return(false); } IMethodSymbol outermostMethod = methodSymbol; while (outermostMethod.ContainingSymbol.Kind == SymbolKind.Method) { outermostMethod = (IMethodSymbol)outermostMethod.ContainingSymbol; if (outermostMethod.Parameters.Any(i => i.Name == name) || outermostMethod.TypeParameters.Any(i => i.Name == name)) { return(false); } } foreach (var syntaxReference in outermostMethod.DeclaringSyntaxReferences) { SyntaxNode syntaxNode = await syntaxReference.GetSyntaxAsync(cancellationToken).ConfigureAwait(false); LocalNameFinder localNameFinder = new LocalNameFinder(name); localNameFinder.Visit(syntaxNode); if (localNameFinder.Found) { return(false); } } return(true); } else { return(true); } }
private SpecialType(TypeKind kind, string name, bool?isReferenceType) { this.kind = kind; this.name = name; this.isReferenceType = isReferenceType; }
public MockNamedTypeSymbol(string name, IEnumerable <Symbol> children, TypeKind kind = TypeKind.Class) { _name = name; _children = children; _typeKind = kind; }
public VoidTypeInfo(string name, TypeKind kind, BinaryReader reader) : base(name, kind, reader) { }
public SSAType(TypeKind kind) { this.kind = kind; }
internal TypeDesc(Type type, string name, string fullName, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags, TypeDesc arrayElementTypeDesc) : this(name, fullName, null, kind, baseTypeDesc, flags, null) { _arrayElementTypeDesc = arrayElementTypeDesc; _type = type; }
internal IEnumerable <ISymbol> GetMembers(TypeDocumentationParts ignoredParts = TypeDocumentationParts.None) { if (!TypeKind.Is(TypeKind.Enum, TypeKind.Delegate)) { if (IsEnabled(TypeDocumentationParts.Constructors)) { foreach (IMethodSymbol result in GetConstructors()) { yield return(result); } } if (IsEnabled(TypeDocumentationParts.Fields)) { foreach (IFieldSymbol result in GetFields()) { yield return(result); } } if (IsEnabled(TypeDocumentationParts.Indexers)) { foreach (IPropertySymbol result in GetIndexers()) { yield return(result); } } if (IsEnabled(TypeDocumentationParts.Properties)) { foreach (IPropertySymbol result in GetProperties()) { yield return(result); } } if (IsEnabled(TypeDocumentationParts.Methods)) { foreach (IMethodSymbol result in GetMethods()) { yield return(result); } } if (IsEnabled(TypeDocumentationParts.Operators)) { foreach (IMethodSymbol result in GetOperators()) { yield return(result); } } if (IsEnabled(TypeDocumentationParts.Events)) { foreach (IEventSymbol result in GetEvents()) { yield return(result); } } if (IsEnabled(TypeDocumentationParts.ExplicitInterfaceImplementations)) { foreach (ISymbol result in GetExplicitImplementations()) { yield return(result); } } bool IsEnabled(TypeDocumentationParts part) { return((ignoredParts & part) == 0); } } }
static string GetString (TypeKind classType) { string res; if (classTypes.TryGetValue (classType, out res)) return res; return string.Empty; }
/// <summary> /// Attempts to find an <see cref="IGraphType" /> currently associated with the given concrete type. Returns null /// if no <see cref="IGraphType" /> is found. /// </summary> /// <param name="concreteType">The concrete type to search for.</param> /// <param name="kind">The graph type to search for an association of.</param> /// <returns>IGraphType.</returns> public IGraphType FindGraphType(Type concreteType, TypeKind kind) { this.DenySearchForListAndKVP(concreteType); return(_concreteTypes.FindGraphType(concreteType, kind)); }
internal SymbolType(TypeKind typeKind) { m_typeKind = typeKind; m_iaLowerBound = new int[4]; m_iaUpperBound = new int[4]; }
internal async Task TestWithMockedGenerateTypeDialog( string initial, string languageName, string typeName, string expected = null, bool isLine = true, bool isMissing = false, Accessibility accessibility = Accessibility.NotApplicable, TypeKind typeKind = TypeKind.Class, string projectName = null, bool isNewFile = false, string existingFilename = null, IList <string> newFileFolderContainers = null, string fullFilePath = null, string newFileName = null, string assertClassName = null, bool checkIfUsingsIncluded = false, bool checkIfUsingsNotIncluded = false, string expectedTextWithUsings = null, string defaultNamespace = "", bool areFoldersValidIdentifiers = true, GenerateTypeDialogOptions assertGenerateTypeDialogOptions = null, IList <TypeKindOptions> assertTypeKindPresent = null, IList <TypeKindOptions> assertTypeKindAbsent = null, bool isCancelled = false) { using (var testState = await GenerateTypeTestState.CreateAsync(initial, isLine, projectName, typeName, existingFilename, languageName)) { // Initialize the viewModel values testState.TestGenerateTypeOptionsService.SetGenerateTypeOptions( accessibility: accessibility, typeKind: typeKind, typeName: testState.TypeName, project: testState.ProjectToBeModified, isNewFile: isNewFile, newFileName: newFileName, folders: newFileFolderContainers, fullFilePath: fullFilePath, existingDocument: testState.ExistingDocument, areFoldersValidIdentifiers: areFoldersValidIdentifiers, isCancelled: isCancelled); testState.TestProjectManagementService.SetDefaultNamespace( defaultNamespace: defaultNamespace); var diagnosticsAndFixes = await GetDiagnosticAndFixesAsync(testState.Workspace, fixAllActionEquivalenceKey : null, fixProviderData : null); var generateTypeDiagFixes = diagnosticsAndFixes.SingleOrDefault(df => GenerateTypeTestState.FixIds.Contains(df.Item1.Id)); if (isMissing) { Assert.Null(generateTypeDiagFixes); return; } var fixes = generateTypeDiagFixes.Item2.Fixes; Assert.NotNull(fixes); var fixActions = MassageActions(fixes.Select(f => f.Action).ToList()); Assert.NotNull(fixActions); // Since the dialog option is always fed as the last CodeAction var index = fixActions.Count() - 1; var action = fixActions.ElementAt(index); Assert.Equal(action.Title, FeaturesResources.GenerateNewType); var operations = await action.GetOperationsAsync(CancellationToken.None); Tuple <Solution, Solution> oldSolutionAndNewSolution = null; if (!isNewFile) { oldSolutionAndNewSolution = await TestOperationsAsync( testState.Workspace, expected, operations, conflictSpans : null, renameSpans : null, warningSpans : null, compareTokens : false, expectedChangedDocumentId : testState.ExistingDocument.Id); } else { oldSolutionAndNewSolution = await TestAddDocument( testState.Workspace, expected, operations, projectName != null, testState.ProjectToBeModified.Id, newFileFolderContainers, newFileName, compareTokens : false); } if (checkIfUsingsIncluded) { Assert.NotNull(expectedTextWithUsings); await TestOperationsAsync(testState.Workspace, expectedTextWithUsings, operations, conflictSpans : null, renameSpans : null, warningSpans : null, compareTokens : false, expectedChangedDocumentId : testState.InvocationDocument.Id); } if (checkIfUsingsNotIncluded) { var oldSolution = oldSolutionAndNewSolution.Item1; var newSolution = oldSolutionAndNewSolution.Item2; var changedDocumentIds = SolutionUtilities.GetChangedDocuments(oldSolution, newSolution); Assert.False(changedDocumentIds.Contains(testState.InvocationDocument.Id)); } // Added into a different project than the triggering project if (projectName != null) { var appliedChanges = ApplyOperationsAndGetSolution(testState.Workspace, operations); var newSolution = appliedChanges.Item2; var triggeredProject = newSolution.GetProject(testState.TriggeredProject.Id); // Make sure the Project reference is present Assert.True(triggeredProject.ProjectReferences.Any(pr => pr.ProjectId == testState.ProjectToBeModified.Id)); } // Assert Option Calculation if (assertClassName != null) { Assert.True(assertClassName == testState.TestGenerateTypeOptionsService.ClassName); } if (assertGenerateTypeDialogOptions != null || assertTypeKindPresent != null || assertTypeKindAbsent != null) { var generateTypeDialogOptions = testState.TestGenerateTypeOptionsService.GenerateTypeDialogOptions; if (assertGenerateTypeDialogOptions != null) { Assert.True(assertGenerateTypeDialogOptions.IsPublicOnlyAccessibility == generateTypeDialogOptions.IsPublicOnlyAccessibility); Assert.True(assertGenerateTypeDialogOptions.TypeKindOptions == generateTypeDialogOptions.TypeKindOptions); Assert.True(assertGenerateTypeDialogOptions.IsAttribute == generateTypeDialogOptions.IsAttribute); } if (assertTypeKindPresent != null) { foreach (var typeKindPresentEach in assertTypeKindPresent) { Assert.True((typeKindPresentEach & generateTypeDialogOptions.TypeKindOptions) != 0); } } if (assertTypeKindAbsent != null) { foreach (var typeKindPresentEach in assertTypeKindAbsent) { Assert.True((typeKindPresentEach & generateTypeDialogOptions.TypeKindOptions) == 0); } } } } }