public override void Populate() { Context.Emit(Tuples.types(this, Kinds.TypeKind.DYNAMIC, "dynamic")); Context.Emit(Tuples.type_location(this, Location)); Context.Emit(Tuples.has_modifiers(this, Modifier.Create(Context, "public"))); Context.Emit(Tuples.parent_namespace(this, Namespace.Create(Context, Context.Compilation.GlobalNamespace))); }
public override void Populate(TextWriter trapFile) { trapFile.types(this, Kinds.TypeKind.DYNAMIC, "dynamic"); trapFile.type_location(this, Location); trapFile.has_modifiers(this, Modifier.Create(Context, "public")); trapFile.parent_namespace(this, Namespace.Create(Context, Context.Compilation.GlobalNamespace)); }
public static void ExtractModifiers(Context cx, TextWriter trapFile, IEntity key, ISymbol symbol) { HasAccessibility(cx, trapFile, key, symbol.DeclaredAccessibility); if (symbol.Kind == SymbolKind.ErrorType) { trapFile.has_modifiers(key, Modifier.Create(cx, Accessibility.Public)); } if (symbol.IsAbstract && (symbol.Kind != SymbolKind.NamedType || ((INamedTypeSymbol)symbol).TypeKind != TypeKind.Interface)) { HasModifier(cx, trapFile, key, "abstract"); } if (symbol.IsSealed) { HasModifier(cx, trapFile, key, "sealed"); } var fromSource = symbol.DeclaringSyntaxReferences.Length > 0; if (symbol.IsStatic && !(symbol.Kind == SymbolKind.Field && ((IFieldSymbol)symbol).IsConst && !fromSource)) { HasModifier(cx, trapFile, key, "static"); } if (symbol.IsVirtual) { HasModifier(cx, trapFile, key, "virtual"); } if (symbol.Kind == SymbolKind.Field && ((IFieldSymbol)symbol).IsReadOnly) { HasModifier(cx, trapFile, key, "readonly"); } if (symbol.IsOverride) { HasModifier(cx, trapFile, key, "override"); } if (symbol.Kind == SymbolKind.Method && ((IMethodSymbol)symbol).IsAsync) { HasModifier(cx, trapFile, key, "async"); } if (symbol.IsExtern) { HasModifier(cx, trapFile, key, "extern"); } foreach (var modifier in symbol.GetSourceLevelModifiers()) { HasModifier(cx, trapFile, key, modifier); } if (symbol.Kind == SymbolKind.NamedType) { var nt = symbol as INamedTypeSymbol; if (nt is null) { throw new InternalError(symbol, "Symbol kind is inconsistent with its type"); } if (nt.IsRecord) { HasModifier(cx, trapFile, key, "record"); } if (nt.TypeKind == TypeKind.Struct) { if (nt.IsReadOnly) { HasModifier(cx, trapFile, key, "readonly"); } if (nt.IsRefLikeType) { HasModifier(cx, trapFile, key, "ref"); } } } }
public static void HasModifier(Context cx, TextWriter trapFile, IEntity target, string modifier) { trapFile.has_modifiers(target, Modifier.Create(cx, modifier)); }
public static void HasModifier(Context cx, IEntity target, string modifier) { cx.Emit(Tuples.has_modifiers(target, Modifier.Create(cx, modifier))); }
public static void ExtractModifiers(Context cx, IEntity key, ISymbol symbol) { bool interfaceDefinition = symbol.ContainingType != null && symbol.ContainingType.Kind == SymbolKind.NamedType && symbol.ContainingType.TypeKind == TypeKind.Interface; Modifier.HasAccessibility(cx, key, symbol.DeclaredAccessibility); if (symbol.Kind == SymbolKind.ErrorType) { cx.Emit(Tuples.has_modifiers(key, Modifier.Create(cx, Accessibility.Public))); } if (symbol.IsAbstract && (symbol.Kind != SymbolKind.NamedType || ((INamedTypeSymbol)symbol).TypeKind != TypeKind.Interface) && !interfaceDefinition) { Modifier.HasModifier(cx, key, "abstract"); } if (symbol.IsSealed) { HasModifier(cx, key, "sealed"); } bool fromSource = symbol.DeclaringSyntaxReferences.Length > 0; if (symbol.IsStatic && !(symbol.Kind == SymbolKind.Field && ((IFieldSymbol)symbol).IsConst && !fromSource)) { HasModifier(cx, key, "static"); } if (symbol.IsVirtual) { HasModifier(cx, key, "virtual"); } // For some reason, method in interfaces are "virtual", not "abstract" if (symbol.IsAbstract && interfaceDefinition) { HasModifier(cx, key, "virtual"); } if (symbol.Kind == SymbolKind.Field && ((IFieldSymbol)symbol).IsReadOnly) { HasModifier(cx, key, "readonly"); } if (symbol.IsOverride) { HasModifier(cx, key, "override"); } if (symbol.Kind == SymbolKind.Method && ((IMethodSymbol)symbol).IsAsync) { HasModifier(cx, key, "async"); } if (symbol.IsExtern) { HasModifier(cx, key, "extern"); } foreach (var modifier in symbol.GetSourceLevelModifiers()) { HasModifier(cx, key, modifier); } if (symbol.Kind == SymbolKind.NamedType) { INamedTypeSymbol nt = symbol as INamedTypeSymbol; if (nt is null) { throw new InternalError(symbol, "Symbol kind is inconsistent with its type"); } if (nt.TypeKind == TypeKind.Struct) { if (nt.IsReadOnly) { HasModifier(cx, key, "readonly"); } if (nt.IsRefLikeType) { HasModifier(cx, key, "ref"); } } } }
public static void ExtractModifiers(Context cx, IEntity key, ISymbol symbol) { bool interfaceDefinition = symbol.ContainingType != null && symbol.ContainingType.Kind == SymbolKind.NamedType && symbol.ContainingType.TypeKind == TypeKind.Interface; Modifier.HasAccessibility(cx, key, symbol.DeclaredAccessibility); if (symbol.Kind == SymbolKind.ErrorType) { cx.Emit(Tuples.has_modifiers(key, Modifier.Create(cx, Accessibility.Public))); } if (symbol.IsAbstract && (symbol.Kind != SymbolKind.NamedType || ((INamedTypeSymbol)symbol).TypeKind != TypeKind.Interface) && !interfaceDefinition) { Modifier.HasModifier(cx, key, "abstract"); } if (symbol.IsSealed) { HasModifier(cx, key, "sealed"); } bool fromSource = symbol.DeclaringSyntaxReferences.Length > 0; if (symbol.IsStatic && !(symbol.Kind == SymbolKind.Field && ((IFieldSymbol)symbol).IsConst && !fromSource)) { HasModifier(cx, key, "static"); } if (symbol.IsVirtual) { HasModifier(cx, key, "virtual"); } // For some reason, method in interfaces are "virtual", not "abstract" if (symbol.IsAbstract && interfaceDefinition) { HasModifier(cx, key, "virtual"); } if (symbol.Kind == SymbolKind.Field && ((IFieldSymbol)symbol).IsReadOnly) { HasModifier(cx, key, "readonly"); } if (symbol.IsOverride) { HasModifier(cx, key, "override"); } if (symbol.Kind == SymbolKind.Method && ((IMethodSymbol)symbol).IsAsync) { HasModifier(cx, key, "async"); } if (symbol.IsExtern) { HasModifier(cx, key, "extern"); } foreach (var modifier in symbol.GetSourceLevelModifiers()) { HasModifier(cx, key, modifier); } if (symbol.Kind == SymbolKind.NamedType) { INamedTypeSymbol nt = symbol as INamedTypeSymbol; if (nt.TypeKind == TypeKind.Struct) { // Sadly, these properties are internal so cannot be accessed directly. // This seems to be a deficiency in the model. var readonlyProperty = nt.GetType().GetProperty("IsReadOnly", BindingFlags.NonPublic | BindingFlags.Instance); var isByRefProperty = nt.GetType().GetProperty("IsByRefLikeType", BindingFlags.NonPublic | BindingFlags.Instance); bool isReadOnly = (bool)readonlyProperty.GetValue(nt); bool isByRefLikeType = (bool)isByRefProperty.GetValue(nt); if (isReadOnly) { HasModifier(cx, key, "readonly"); } if (isByRefLikeType) { HasModifier(cx, key, "ref"); } } } }