private XElement LoadChildNamespace2(NamespaceSymbol n) { XElement elem = new XElement((n.Name.Length == 0 ? "Global" : n.Name)); var children = n.GetMembers(); n = null; var types = new List<NamedTypeSymbol>(); var namespaces = new List<NamespaceSymbol>(); foreach (var c in children) { NamedTypeSymbol t = c as NamedTypeSymbol; if (t != null) { types.Add(t); } else { namespaces.Add(((NamespaceSymbol)c)); } } var childrenTypes = types.OrderBy(t => t, new NameAndArityComparer()); elem.Add(from t in childrenTypes select LoadChildType(t)); var childrenNS = namespaces.OrderBy((child) => child.Name, StringComparer.OrdinalIgnoreCase); elem.Add(from c in childrenNS select LoadChildNamespace2(c)); return elem; }
public TypeDocumentationCommentTests() { _compilation = CreateCompilationWithMscorlibAndDocumentationComments(@"enum Color { Red, Blue, Green } namespace Acme { interface IProcess {...} struct ValueType {...} class Widget: IProcess { /// <summary> /// Hello! Nested Class. /// </summary> public class NestedClass {...} public interface IMenuItem {...} public delegate void Del(int i); public enum Direction { North, South, East, West } } class MyList<T> { class Helper<U,V> {...} } }"); _acmeNamespace = (NamespaceSymbol)_compilation.GlobalNamespace.GetMembers("Acme").Single(); _widgetClass = _acmeNamespace.GetTypeMembers("Widget").Single(); }
public MissingNamespaceSymbol(NamespaceSymbol containingNamespace, string name) { Debug.Assert((object)containingNamespace != null); Debug.Assert(name != null); _containingSymbol = containingNamespace; _name = name; }
public override void VisitNamespace(NamespaceSymbol symbol) { _cancellationToken.ThrowIfCancellationRequested(); foreach (var s in symbol.GetMembers()) { s.Accept(this); } }
public RetargetingNamespaceSymbol(RetargetingModuleSymbol retargetingModule, NamespaceSymbol underlyingNamespace) { Debug.Assert((object)retargetingModule != null); Debug.Assert((object)underlyingNamespace != null); Debug.Assert(!(underlyingNamespace is RetargetingNamespaceSymbol)); this.retargetingModule = retargetingModule; this.underlyingNamespace = underlyingNamespace; }
internal EENamedTypeSymbol( NamespaceSymbol container, NamedTypeSymbol baseType, CSharpSyntaxNode syntax, MethodSymbol currentFrame, string typeName, string methodName, CompilationContext context, GenerateMethodBody generateMethodBody) : this(container, baseType, syntax, currentFrame, typeName, (m, t) => ImmutableArray.Create<MethodSymbol>(context.CreateMethod(t, methodName, syntax, generateMethodBody))) { }
public EventDocumentationCommentTests() { compilation = CreateCompilationWithMscorlib(@"namespace Acme { class Widget: IProcess { public event System.Action E; public event System.Action F { add { } remove { } } } } "); acmeNamespace = (NamespaceSymbol)compilation.GlobalNamespace.GetMember<NamespaceSymbol>("Acme"); widgetClass = acmeNamespace.GetMember<NamedTypeSymbol>("Widget"); }
public DestructorDocumentationCommentTests() { _compilation = CreateCompilationWithMscorlibAndDocumentationComments(@"namespace Acme { class Widget: IProcess { /// <summary>Destructor Documentation</summary> ~Widget() {...} } } "); _acmeNamespace = (NamespaceSymbol)_compilation.GlobalNamespace.GetMembers("Acme").Single(); _widgetClass = _acmeNamespace.GetTypeMembers("Widget").Single(); }
// Constructor. Use static Create method to create instances. private MergedNamespaceSymbol(NamespaceExtent extent, NamespaceSymbol containingNamespace, ImmutableArray<NamespaceSymbol> namespacesToMerge, string nameOpt) { this.extent = extent; this.namespacesToMerge = namespacesToMerge; this.containingNamespace = containingNamespace; this.cachedLookup = new CachingDictionary<string, Symbol>(SlowGetChildrenOfName, SlowGetChildNames, EqualityComparer<string>.Default); this.nameOpt = nameOpt; #if DEBUG // We shouldn't merged namespaces that are already merged. foreach (NamespaceSymbol ns in namespacesToMerge) { Debug.Assert(ns.ConstituentNamespaces.Length == 1); } #endif }
public PropertyDocumentationCommentTests() { compilation = CreateCompilationWithMscorlib(@"namespace Acme { class Widget: IProcess { public int Width { get { } set { } } public int this[int i] { get { } set { } } public int this[string s, int i] { get { } set { } } } } "); acmeNamespace = (NamespaceSymbol)compilation.GlobalNamespace.GetMembers("Acme").Single(); widgetClass = acmeNamespace.GetTypeMembers("Widget").Single(); }
internal static XElement LoadChildNamespace(NamespaceSymbol n) { XElement elem = new XElement((n.Name.Length == 0 ? "Global" : n.Name)); var childrenTypes = n.GetTypeMembers().OrderBy((t) => t, new NameAndArityComparer()); elem.Add(from t in childrenTypes select LoadChildType(t)); var childrenNS = n.GetMembers(). OfType<NamespaceSymbol>(). OrderBy(child => child.Name, StringComparer.OrdinalIgnoreCase); elem.Add(from c in childrenNS select LoadChildNamespace(c)); return elem; }
public MethodDocumentationCommentTests() { _compilation = CreateCompilationWithMscorlibAndDocumentationComments(@"namespace Acme { struct ValueType { public void M(int i) { } public static explicit operator ValueType (byte value) { return default(ValueType); } } class Widget: IProcess { public class NestedClass { public void M(int i) { } } /// <summary>M0 Summary.</summary> public static void M0() { } public void M1(char c, out float f, ref ValueType v) { } public void M2(short[] x1, int[,] x2, long[][] x3) { } public void M3(long[][] x3, Widget[][,,] x4) { } public unsafe void M4(char *pc, Color **pf) { } public unsafe void M5(void *pv, double *[][,] pd) { } public void M6(int i, params object[] args) { } } class MyList<T> { public void Test(T t) { } public void Zip(MyList<T> other) { } public void ReallyZip(MyList<MyList<T>> other) { } } class UseList { public void Process(MyList<int> list) { } public MyList<T> GetValues<T>(T inputValue) { return null; } } } "); _acmeNamespace = (NamespaceSymbol)_compilation.GlobalNamespace.GetMembers("Acme").Single(); _widgetClass = _acmeNamespace.GetTypeMembers("Widget").Single(); }
internal EENamedTypeSymbol( NamespaceSymbol container, NamedTypeSymbol baseType, CSharpSyntaxNode syntax, MethodSymbol currentFrame, string typeName, Func<MethodSymbol, EENamedTypeSymbol, ImmutableArray<MethodSymbol>> getMethods, ImmutableArray<TypeParameterSymbol> sourceTypeParameters, Func<NamedTypeSymbol, EENamedTypeSymbol, ImmutableArray<TypeParameterSymbol>> getTypeParameters) { _container = container; _baseType = baseType; _syntax = syntax; _name = typeName; this.SourceTypeParameters = sourceTypeParameters; _typeParameters = getTypeParameters(currentFrame.ContainingType, this); VerifyTypeParameters(this, _typeParameters); _methods = getMethods(currentFrame, this); }
internal EENamedTypeSymbol( NamespaceSymbol container, NamedTypeSymbol baseType, CSharpSyntaxNode syntax, MethodSymbol currentFrame, string typeName, Func<MethodSymbol, EENamedTypeSymbol, ImmutableArray<MethodSymbol>> getMethods) { _container = container; _baseType = baseType; _syntax = syntax; _name = typeName; // What we want is to map all original type parameters to the corresponding new type parameters // (since the old ones have the wrong owners). Unfortunately, we have a circular dependency: // 1) Each new type parameter requires the entire map in order to be able to construct its constraint list. // 2) The map cannot be constructed until all new type parameters exist. // Our solution is to pass each new type parameter a lazy reference to the type map. We then // initialize the map as soon as the new type parameters are available - and before they are // handed out - so that there is never a period where they can require the type map and find // it uninitialized. var sourceType = currentFrame.ContainingType; this.SourceTypeParameters = sourceType.GetAllTypeParameters(); TypeMap typeMap = null; var getTypeMap = new Func<TypeMap>(() => typeMap); _typeParameters = this.SourceTypeParameters.SelectAsArray( (tp, i, arg) => (TypeParameterSymbol)new EETypeParameterSymbol(this, tp, i, getTypeMap), (object)null); typeMap = new TypeMap(this.SourceTypeParameters, _typeParameters); VerifyTypeParameters(this, _typeParameters); this.SubstitutedSourceType = typeMap.SubstituteNamedType(sourceType); TypeParameterChecker.Check(this.SubstitutedSourceType, _typeParameters); _methods = getMethods(currentFrame, this); }
public FieldDocumentationCommentTests() { _compilation = CreateCompilationWithMscorlibAndDocumentationComments(@" namespace Acme { struct ValueType { /// <summary>Summary for total fields.</summary> private int total1, total2; } class Widget: IProcess { public class NestedClass { private int value; } private string message; private static Color defaultColor; private const double PI = 3.14159; protected readonly double monthlyAverage; private long[] array1; private Widget[,] array2; private unsafe int *pCount; private unsafe float **ppValues; } enum E { /// <summary>Enum field</summary> A = 1 } } "); _acmeNamespace = (NamespaceSymbol)_compilation.GlobalNamespace.GetMembers("Acme").Single(); _widgetClass = _acmeNamespace.GetTypeMembers("Widget").Single(); _enumSymbol = _acmeNamespace.GetTypeMembers("E").Single(); _valueType = _acmeNamespace.GetTypeMembers("ValueType").Single(); }
public ConstructorDocumentationCommentTests() { compilation = CreateCompilationWithMscorlibAndDocumentationComments(@"namespace Acme { class Widget: IProcess { /// <summary>Static Constructor</summary> static Widget() {...} /** <summary>Instance Constructor</summary> */ public Widget() {...} /// <summary> /// Parameterized Constructor /// </summary> /// <param name=""s"">s, the string argument</param> public Widget(string s) {...} } } "); acmeNamespace = (NamespaceSymbol)compilation.GlobalNamespace.GetMembers("Acme").Single(); widgetClass = acmeNamespace.GetTypeMembers("Widget").Single(); }
/// <summary> /// Create a possibly merged namespace symbol. If only a single namespace is passed it, it /// is just returned directly. If two or more namespaces are passed in, then a new merged /// namespace is created with the given extent and container. /// </summary> /// <param name="extent">The namespace extent to use, IF a merged namespace is created.</param> /// <param name="containingNamespace">The containing namespace to used, IF a merged /// namespace is created.</param> /// <param name="namespacesToMerge">One or more namespaces to merged. If just one, then it /// is returned. The merged namespace symbol may hold onto the array.</param> /// <param name="nameOpt">An optional name to give the resulting namespace.</param> /// <returns>A namespace symbol representing the merged namespace.</returns> internal static NamespaceSymbol Create( NamespaceExtent extent, NamespaceSymbol containingNamespace, ImmutableArray<NamespaceSymbol> namespacesToMerge, string nameOpt = null) { // Currently, if we are just merging 1 namespace, we just return the namespace itself. // This is by far the most efficient, because it means that we don't create merged // namespaces (which have a fair amount of memory overhead) unless there is actual // merging going on. However, it means that the child namespace of a Compilation extent // namespace may be a Module extent namespace, and the containing of that module extent // namespace will be another module extent namespace. This is basically no different // than type members of namespaces, so it shouldn't be TOO unexpected. // EDMAURER if the caller is supplying a name, then produce the merged namespace with // the new name even if only a single namespace was provided. This behavior was introduced // to support nice extern alias error reporting. Debug.Assert(namespacesToMerge.Length != 0); return (namespacesToMerge.Length == 1 && nameOpt == null) ? namespacesToMerge[0] : new MergedNamespaceSymbol(extent, containingNamespace, namespacesToMerge, nameOpt); }
private Cci.IAssemblyReference TryGetAssemblyScope(NamespaceSymbol @namespace, Emit.PEModuleBuilder moduleBuilder, DiagnosticBag diagnostics) { AssemblySymbol containingAssembly = @namespace.ContainingAssembly; if ((object)containingAssembly != null && (object)containingAssembly != moduleBuilder.CommonCompilation.Assembly) { var referenceManager = ((CSharpCompilation)moduleBuilder.CommonCompilation).GetBoundReferenceManager(); for (int i = 0; i < referenceManager.ReferencedAssemblies.Length; i++) { if ((object)referenceManager.ReferencedAssemblies[i] == containingAssembly) { if (!referenceManager.DeclarationsAccessibleWithoutAlias(i)) { return moduleBuilder.Translate(containingAssembly, diagnostics); } } } } return null; }
/// <summary> /// Write header, descend into members, and write footer. /// </summary> public override void VisitNamespace(NamespaceSymbol symbol) { _cancellationToken.ThrowIfCancellationRequested(); if (symbol.IsGlobalNamespace) { Debug.Assert(_assemblyName != null); WriteLine("<?xml version=\"1.0\"?>"); WriteLine("<doc>"); Indent(); if (!_compilation.Options.OutputKind.IsNetModule()) { WriteLine("<assembly>"); Indent(); WriteLine("<name>{0}</name>", _assemblyName); Unindent(); WriteLine("</assembly>"); } WriteLine("<members>"); Indent(); } Debug.Assert(!_isForSingleSymbol); foreach (var s in symbol.GetMembers()) { _cancellationToken.ThrowIfCancellationRequested(); s.Accept(this); } if (symbol.IsGlobalNamespace) { Unindent(); WriteLine("</members>"); Unindent(); WriteLine("</doc>"); } }
private static NamespaceSymbol BindNamespace(string namespaceName, NamespaceSymbol globalNamespace) { var namespaceSymbol = globalNamespace; foreach (var name in namespaceName.Split('.')) { var members = namespaceSymbol.GetMembers(name); namespaceSymbol = members.Length == 1 ? members[0] as NamespaceSymbol : null; if ((object)namespaceSymbol == null) { break; } } return namespaceSymbol; }
public virtual void VisitNamespace(NamespaceSymbol symbol) { DefaultVisit(symbol); }
internal NamespaceSymbol Get_System_Runtime_CompilerServices_NamespaceSymbol(NamespaceSymbol systemNamespace) { var runtimeNS = systemNamespace.GetMember<NamespaceSymbol>("Runtime"); return runtimeNS.GetMember<NamespaceSymbol>("CompilerServices"); }
private static Binder CreateBinderChain( CSharpCompilation compilation, PEModuleSymbol module, NamespaceSymbol @namespace, ImmutableArray<ImmutableArray<ImportRecord>> importRecordGroups) { var stack = ArrayBuilder<string>.GetInstance(); while ((object)@namespace != null) { stack.Push(@namespace.Name); @namespace = @namespace.ContainingNamespace; } Binder binder = new BuckStopsHereBinder(compilation); var hasImports = !importRecordGroups.IsDefaultOrEmpty; var numImportStringGroups = hasImports ? importRecordGroups.Length : 0; var currentStringGroup = numImportStringGroups - 1; // PERF: We used to call compilation.GetCompilationNamespace on every iteration, // but that involved walking up to the global namespace, which we have to do // anyway. Instead, we'll inline the functionality into our own walk of the // namespace chain. @namespace = compilation.GlobalNamespace; while (stack.Count > 0) { var namespaceName = stack.Pop(); if (namespaceName.Length > 0) { // We're re-getting the namespace, rather than using the one containing // the current frame method, because we want the merged namespace. @namespace = @namespace.GetNestedNamespace(namespaceName); Debug.Assert((object)@namespace != null, $"We worked backwards from symbols to names, but no symbol exists for name '{namespaceName}'"); } else { Debug.Assert((object)@namespace == (object)compilation.GlobalNamespace); } Imports imports = null; if (hasImports) { if (currentStringGroup < 0) { Debug.WriteLine($"No import string group for namespace '{@namespace}'"); break; } var importsBinder = new InContainerBinder(@namespace, binder); imports = BuildImports(compilation, module, importRecordGroups[currentStringGroup], importsBinder); currentStringGroup--; } binder = new InContainerBinder(@namespace, binder, imports); } stack.Free(); if (currentStringGroup >= 0) { // CONSIDER: We could lump these into the outermost namespace. It's probably not worthwhile since // the usings are already for the wrong method. Debug.WriteLine($"Found {currentStringGroup + 1} import string groups without corresponding namespaces"); } return binder; }
public BoundNamespaceExpression(CSharpSyntaxNode syntax, NamespaceSymbol namespaceSymbol) : this(syntax, namespaceSymbol, null) { }
public BoundNamespaceExpression Update(NamespaceSymbol namespaceSymbol) { return Update(namespaceSymbol, this.AliasOpt); }
public BoundNamespaceExpression(CSharpSyntaxNode syntax, NamespaceSymbol namespaceSymbol, bool hasErrors = false) : this(syntax, namespaceSymbol, null, hasErrors) { }
public void SetContainer(Symbol container) { this.container = (NamespaceSymbol)container; }
private static bool NamespaceContainsExplicitDefinitionOfNoPiaLocalTypes(NamespaceSymbol ns) { foreach (Symbol s in ns.GetMembersUnordered()) { switch (s.Kind) { case SymbolKind.Namespace: if (NamespaceContainsExplicitDefinitionOfNoPiaLocalTypes((NamespaceSymbol)s)) { return true; } break; case SymbolKind.NamedType: if (((NamedTypeSymbol)s).IsExplicitDefinitionOfNoPiaLocalType) { return true; } break; } } return false; }
private static IEnumerable<string> EnumerateNamespaces(NamespaceSymbol @namespace, string baseName) { foreach (var child in @namespace.GetNamespaceMembers()) { var childName = string.IsNullOrEmpty(baseName) ? child.Name : (baseName + "." + child.Name); yield return childName; foreach (var result in EnumerateNamespaces(child, childName)) { yield return result; } } }
internal static AliasSymbol CreateGlobalNamespaceAlias(NamespaceSymbol globalNamespace, Binder globalNamespaceBinder) { SyntaxToken aliasName = SyntaxFactory.Identifier(SyntaxFactory.TriviaList(), SyntaxKind.GlobalKeyword, "global", "global", SyntaxFactory.TriviaList()); return(new AliasSymbol(globalNamespaceBinder, globalNamespace, aliasName, ImmutableArray <Location> .Empty)); }
internal bool GetExternAliasTarget(string aliasName, out NamespaceSymbol @namespace) { if (externAliasTargets == null) { Interlocked.CompareExchange(ref this.externAliasTargets, new ConcurrentDictionary<string, NamespaceSymbol>(), null); } else if (externAliasTargets.TryGetValue(aliasName, out @namespace)) { return !(@namespace is MissingNamespaceSymbol); } ArrayBuilder<NamespaceSymbol> builder = null; foreach (var referencedAssembly in GetBoundReferenceManager().ReferencedAssembliesMap.Values) { if (referencedAssembly.Aliases.Contains(aliasName)) { builder = builder ?? ArrayBuilder<NamespaceSymbol>.GetInstance(); builder.Add(referencedAssembly.Symbol.GlobalNamespace); } } bool foundNamespace = builder != null; // We want to cache failures as well as successes so that subsequent incorrect extern aliases with the // same alias will have the same target. @namespace = foundNamespace ? MergedNamespaceSymbol.Create(new NamespaceExtent(this), namespacesToMerge: builder.ToImmutableAndFree(), containingNamespace: null, nameOpt: null) : new MissingNamespaceSymbol(new MissingModuleSymbol(new MissingAssemblySymbol(new AssemblyIdentity(System.Guid.NewGuid().ToString())), ordinal: -1)); // Use GetOrAdd in case another thread beat us to the punch (i.e. should return the same object for the same alias, every time). @namespace = externAliasTargets.GetOrAdd(aliasName, @namespace); Debug.Assert(foundNamespace == !(@namespace is MissingNamespaceSymbol)); return foundNamespace; }
// For the purposes of SemanticModel, it is convenient to have an AliasSymbol for the "global" namespace that "global::" binds // to. This alias symbol is returned only when binding "global::" (special case code). internal static AliasSymbol CreateGlobalNamespaceAlias(NamespaceSymbol globalNamespace) { return(new AliasSymbolFromResolvedTarget(globalNamespace, "global", globalNamespace, ImmutableArray <Location> .Empty, isExtern: false)); }