From 24a6efa28eab84bb01d530d0778788f6637e743b Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Mon, 16 Mar 2020 08:29:21 -0700 Subject: [PATCH 1/3] pulling in changes from PR 358 --- src/QsCompiler/CommandLineTool/LoadContext.cs | 4 +- .../CompilationManager/CompilationUnit.cs | 8 +- .../EditorSupport/SymbolInformation.cs | 11 +- src/QsCompiler/Core/SymbolTable.fs | 30 ++-- src/QsCompiler/Core/TypeTransformation.fs | 3 +- .../Transformations/SearchAndReplace.cs | 139 +++++++++++++----- 6 files changed, 127 insertions(+), 68 deletions(-) diff --git a/src/QsCompiler/CommandLineTool/LoadContext.cs b/src/QsCompiler/CommandLineTool/LoadContext.cs index 1f9284ca54..db5ec2a15e 100644 --- a/src/QsCompiler/CommandLineTool/LoadContext.cs +++ b/src/QsCompiler/CommandLineTool/LoadContext.cs @@ -23,7 +23,7 @@ namespace Microsoft.Quantum.QsCompiler public class LoadContext : AssemblyLoadContext { public readonly string PathToParentAssembly; - private AssemblyDependencyResolver _Resolver; + private readonly AssemblyDependencyResolver _Resolver; private readonly HashSet _FallbackPaths; /// @@ -111,7 +111,7 @@ private Assembly OnResolving(AssemblyLoadContext context, AssemblyName name) return path == null ? null : LoadFromAssemblyPath(path); } - private static ConcurrentBag Loaded = + private static readonly ConcurrentBag Loaded = new ConcurrentBag(); /// diff --git a/src/QsCompiler/CompilationManager/CompilationUnit.cs b/src/QsCompiler/CompilationManager/CompilationUnit.cs index 5c1007a7d3..ae2ce5937d 100644 --- a/src/QsCompiler/CompilationManager/CompilationUnit.cs +++ b/src/QsCompiler/CompilationManager/CompilationUnit.cs @@ -426,7 +426,7 @@ internal void UpdateCallables(IEnumerable updates) header.Location, header.Signature, header.ArgumentTuple, - ImmutableArray.Create(defaultSpec), + ImmutableArray.Create(defaultSpec), header.Documentation, QsComments.Empty ); @@ -551,8 +551,8 @@ public static ImmutableArray NewSyntaxTree( if (types == null) throw new ArgumentNullException(nameof(types)); var emptyLookup = new NonNullable[0].ToLookup(ns => ns, _ => ImmutableArray.Empty); - string QualifiedName(QsQualifiedName fullName) => $"{fullName.Namespace.Value}.{fullName.Name.Value}"; - string ElementName(QsNamespaceElement e) => + static string QualifiedName(QsQualifiedName fullName) => $"{fullName.Namespace.Value}.{fullName.Name.Value}"; + static string ElementName(QsNamespaceElement e) => e is QsNamespaceElement.QsCustomType t ? QualifiedName(t.Item.FullName) : e is QsNamespaceElement.QsCallable c ? QualifiedName(c.Item.FullName) : null; var namespaceElements = callables.Select(c => (c.FullName.Namespace, QsNamespaceElement.NewQsCallable(c))) @@ -679,7 +679,7 @@ LocalDeclarations TryGetLocalDeclarations() } if (parentCallable == null) return LocalDeclarations.Empty; - declarations = declarations ?? TryGetLocalDeclarations(); + declarations ??= TryGetLocalDeclarations(); Tuple AbsolutePosition(QsNullable> relOffset) => relOffset.IsNull diff --git a/src/QsCompiler/CompilationManager/EditorSupport/SymbolInformation.cs b/src/QsCompiler/CompilationManager/EditorSupport/SymbolInformation.cs index f404855810..19a916ddc4 100644 --- a/src/QsCompiler/CompilationManager/EditorSupport/SymbolInformation.cs +++ b/src/QsCompiler/CompilationManager/EditorSupport/SymbolInformation.cs @@ -7,7 +7,6 @@ using System.Linq; using Microsoft.Quantum.QsCompiler.CompilationBuilder.DataStructures; using Microsoft.Quantum.QsCompiler.DataTypes; -using Microsoft.Quantum.QsCompiler.SymbolManagement; using Microsoft.Quantum.QsCompiler.SyntaxProcessing; using Microsoft.Quantum.QsCompiler.SyntaxTokens; using Microsoft.Quantum.QsCompiler.SyntaxTree; @@ -143,10 +142,10 @@ internal static bool TryGetReferences(this CompilationUnit compilation, QsQualif referenceLocations = namespaces.SelectMany(ns => { var locs = IdentifierReferences.Find(fullName, ns, defaultOffset, out var dLoc, limitToSourceFiles); - declLoc = declLoc ?? dLoc; + declLoc ??= dLoc; return locs; }) - .Distinct().Select(AsLocation).ToArray(); // ToArray is needed here to force the execution before checking declLoc + .Select(AsLocation).ToArray(); // ToArray is needed here to force the execution before checking declLoc declarationLocation = declLoc == null ? null : AsLocation(declLoc.Item1, declLoc.Item2.Offset, declLoc.Item2.Range); return true; } @@ -218,8 +217,8 @@ internal static bool TryGetReferences( .SelectMany(spec => spec.Implementation is SpecializationImplementation.Provided impl && spec.Location.IsValue ? IdentifierReferences.Find(definition.Item.Item1, impl.Item2, file.FileName, spec.Location.Item.Offset) - : ImmutableArray.Empty) - .Distinct().Select(AsLocation); + : ImmutableHashSet.Empty) + .Select(AsLocation); } else // the given position corresponds to a variable declared as part of a specialization declaration or implementation { @@ -227,7 +226,7 @@ spec.Implementation is SpecializationImplementation.Provided impl && spec.Locati var statements = implementation.StatementsAfterDeclaration(defStart.Subtract(specPos)); var scope = new QsScope(statements.ToImmutableArray(), locals); var rootOffset = DiagnosticTools.AsTuple(specPos); - referenceLocations = IdentifierReferences.Find(definition.Item.Item1, scope, file.FileName, rootOffset).Distinct().Select(AsLocation); + referenceLocations = IdentifierReferences.Find(definition.Item.Item1, scope, file.FileName, rootOffset).Select(AsLocation); } declarationLocation = AsLocation(file.FileName, definition.Item.Item2, defRange); return true; diff --git a/src/QsCompiler/Core/SymbolTable.fs b/src/QsCompiler/Core/SymbolTable.fs index fa5c8a2803..95b5e727c1 100644 --- a/src/QsCompiler/Core/SymbolTable.fs +++ b/src/QsCompiler/Core/SymbolTable.fs @@ -899,12 +899,9 @@ and NamespaceManager /// Compares the accessibility of the parent declaration with the accessibility of the UDT being referenced. If the /// accessibility of a referenced type is less than the accessibility of the parent, returns a diagnostic using the /// given error code. Otherwise, returns an empty array. - let checkUdtAccessibility code - (parent : NonNullable, parentAccess) - (udt : UserDefinedType, udtAccess) = + let checkUdtAccessibility code (parent : NonNullable, parentAccess) (udt : UserDefinedType, udtAccess) = if parentAccess = DefaultAccess && udtAccess = Internal - then [| QsCompilerDiagnostic.Error (code, [udt.Name.Value; parent.Value]) - (udt.Range.ValueOr QsCompilerDiagnostic.DefaultRange) |] + then [| QsCompilerDiagnostic.Error (code, [udt.Name.Value; parent.Value]) (udt.Range.ValueOr QsCompilerDiagnostic.DefaultRange) |] else [||] @@ -1032,9 +1029,7 @@ and NamespaceManager /// /// May throw an exception if the given parent and/or source file is inconsistent with the defined declarations. /// Throws a NotSupportedException if the QsType to resolve contains a MissingType. - member this.ResolveType (parent : QsQualifiedName, tpNames : ImmutableArray<_>, source : NonNullable) - (qsType : QsType) - : ResolvedType * QsCompilerDiagnostic[] = + member this.ResolveType (parent : QsQualifiedName, tpNames : ImmutableArray<_>, source : NonNullable) (qsType : QsType) = resolveType (parent, tpNames, source) qsType (fun _ -> [||]) /// Resolves the underlying type as well as all named and unnamed items for the given type declaration in the @@ -1048,13 +1043,10 @@ and NamespaceManager /// /// May throw an exception if the given parent and/or source file is inconsistent with the defined types. Throws an /// ArgumentException if the given type tuple is an empty QsTuple. - member private this.ResolveTypeDeclaration (fullName, source, modifiers) typeTuple = + member private this.ResolveTypeDeclaration (fullName : QsQualifiedName, source, modifiers) typeTuple = // Currently, type parameters for UDTs are not supported. - let resolveType qsType = - resolveType - (fullName, ImmutableArray<_>.Empty, source) - qsType - (checkUdtAccessibility ErrorCode.TypeLessAccessibleThanParentType (fullName.Name, modifiers.Access)) + let checkAccessibility = checkUdtAccessibility ErrorCode.TypeLessAccessibleThanParentType (fullName.Name, modifiers.Access) + let resolveType qsType = resolveType (fullName, ImmutableArray<_>.Empty, source) qsType checkAccessibility SymbolResolution.ResolveTypeDeclaration resolveType typeTuple /// Given the namespace and the name of the callable that the given signature belongs to, as well as its kind and @@ -1074,14 +1066,10 @@ and NamespaceManager /// /// May throw an exception if the given parent and/or source file is inconsistent with the defined callables. Throws /// an ArgumentException if the given list of characteristics is empty. - member private this.ResolveCallableSignature (parentKind, parentName, source, access) - (signature, specBundleCharacteristics) = + member private this.ResolveCallableSignature (parentKind, parentName : QsQualifiedName, source, access) (signature, specBundleCharacteristics) = + let checkAccessibility = checkUdtAccessibility ErrorCode.TypeLessAccessibleThanParentCallable (parentName.Name, access) let resolveType tpNames qsType = - let res, errs = - resolveType - (parentName, tpNames, source) - qsType - (checkUdtAccessibility ErrorCode.TypeLessAccessibleThanParentCallable (parentName.Name, access)) + let res, errs = resolveType (parentName, tpNames, source) qsType checkAccessibility if parentKind <> TypeConstructor then res, errs else res.WithoutRangeInfo, errs // strip positional info for auto-generated type constructors SymbolResolution.ResolveCallableSignature (resolveType, specBundleCharacteristics) signature diff --git a/src/QsCompiler/Core/TypeTransformation.fs b/src/QsCompiler/Core/TypeTransformation.fs index 8737747695..5b619f7087 100644 --- a/src/QsCompiler/Core/TypeTransformation.fs +++ b/src/QsCompiler/Core/TypeTransformation.fs @@ -132,4 +132,5 @@ type TypeTransformationBase(options : TransformationOptions) = | ExpressionType.Result -> this.OnResult () | ExpressionType.Pauli -> this.OnPauli () | ExpressionType.Range -> this.OnRange () - ResolvedType.New |> Node.BuildOr t transformed + let ResolvedType t = ResolvedType.New (true, t) + ResolvedType |> Node.BuildOr t transformed diff --git a/src/QsCompiler/Transformations/SearchAndReplace.cs b/src/QsCompiler/Transformations/SearchAndReplace.cs index 9ae03cfbf0..7835648f38 100644 --- a/src/QsCompiler/Transformations/SearchAndReplace.cs +++ b/src/QsCompiler/Transformations/SearchAndReplace.cs @@ -84,7 +84,7 @@ public override int GetHashCode() public class TransformationState { public Tuple, QsLocation> DeclarationLocation { get; internal set; } - public ImmutableList Locations { get; private set; } + public ImmutableHashSet Locations { get; private set; } /// /// Whenever DeclarationOffset is set, the current statement offset is set to this default value. @@ -101,7 +101,7 @@ internal TransformationState(Func trackId, { this.TrackIdentifier = trackId ?? throw new ArgumentNullException(nameof(trackId)); this.RelevantSourseFiles = limitToSourceFiles; - this.Locations = ImmutableList.Empty; + this.Locations = ImmutableHashSet.Empty; this.DefaultOffset = defaultOffset; } @@ -168,7 +168,7 @@ public IdentifierReferences(QsQualifiedName idName, QsLocation defaultOffset, II // static methods for convenience - public static IEnumerable Find(NonNullable idName, QsScope scope, + public static ImmutableHashSet Find(NonNullable idName, QsScope scope, NonNullable sourceFile, Tuple rootLoc) { var finder = new IdentifierReferences(idName, null, ImmutableHashSet.Create(sourceFile)); @@ -178,7 +178,7 @@ public static IEnumerable Find(NonNullable idName, QsScope sco return finder.SharedState.Locations; } - public static IEnumerable Find(QsQualifiedName idName, QsNamespace ns, QsLocation defaultOffset, + public static ImmutableHashSet Find(QsQualifiedName idName, QsNamespace ns, QsLocation defaultOffset, out Tuple, QsLocation> declarationLocation, IImmutableSet> limitToSourceFiles = null) { var finder = new IdentifierReferences(idName, defaultOffset, limitToSourceFiles); @@ -501,18 +501,6 @@ public override QsExpressionKind OnIdentifier(Identifier sym, QsNullable public class RenameReferences : SyntaxTreeTransformation { - /// - /// Creates a new rename references transformation. - /// - /// The mapping from existing names to new names. - public RenameReferences(IImmutableDictionary names) - { - var state = new TransformationState(names); - Types = new TypeTransformation(this, state); - ExpressionKinds = new ExpressionKindTransformation(this, state); - Namespaces = new NamespaceTransformation(this, state); - } - private class TransformationState { private readonly IImmutableDictionary names; @@ -542,32 +530,116 @@ internal UserDefinedType RenameUdt(UserDefinedType udt) } } + + private readonly TransformationState State; + + /// + /// Creates a new rename references transformation. + /// + /// The mapping from existing names to new names. + public RenameReferences(IImmutableDictionary names) + { + State = new TransformationState(names); + Types = new TypeTransformation(this); + ExpressionKinds = new ExpressionKindTransformation(this); + Namespaces = new NamespaceTransformation(this); + } + + + // methods for transformations on headers + + /// + /// Renames references in the callable declaration header, including the name of the callable itself. + /// + /// The callable declaration header in which to rename references. + /// The callable declaration header with renamed references. + public CallableDeclarationHeader OnCallableDeclarationHeader(CallableDeclarationHeader callable) => + new CallableDeclarationHeader( + kind: callable.Kind, + qualifiedName: State.GetNewName(callable.QualifiedName), + attributes: callable.Attributes.Select(Namespaces.OnAttribute).ToImmutableArray(), + modifiers: callable.Modifiers, + sourceFile: callable.SourceFile, + position: callable.Position, + symbolRange: callable.SymbolRange, + argumentTuple: Namespaces.OnArgumentTuple(callable.ArgumentTuple), + signature: Namespaces.OnSignature(callable.Signature), + documentation: Namespaces.OnDocumentation(callable.Documentation)); + + /// + /// Renames references in the specialization declaration header, including the name of the specialization + /// itself. + /// + /// The specialization declaration header in which to rename references. + /// The specialization declaration header with renamed references. + public SpecializationDeclarationHeader OnSpecializationDeclarationHeader( + SpecializationDeclarationHeader specialization) + { + var typeArguments = + specialization.TypeArguments.IsValue + ? QsNullable>.NewValue( + specialization.TypeArguments.Item.Select(Types.OnType).ToImmutableArray()) + : QsNullable>.Null; + return new SpecializationDeclarationHeader( + kind: specialization.Kind, + typeArguments: typeArguments, + information: specialization.Information, + parent: State.GetNewName(specialization.Parent), + attributes: specialization.Attributes.Select(Namespaces.OnAttribute).ToImmutableArray(), + sourceFile: specialization.SourceFile, + position: specialization.Position, + headerRange: specialization.HeaderRange, + documentation: Namespaces.OnDocumentation(specialization.Documentation)); + } + + /// + /// Renames references in the type declaration header, including the name of the type itself. + /// + /// The type declaration header in which to rename references. + /// The type declaration header with renamed references. + public TypeDeclarationHeader OnTypeDeclarationHeader(TypeDeclarationHeader type) + { + return new TypeDeclarationHeader( + qualifiedName: State.GetNewName(type.QualifiedName), + attributes: type.Attributes.Select(Namespaces.OnAttribute).ToImmutableArray(), + modifiers: type.Modifiers, + sourceFile: type.SourceFile, + position: type.Position, + symbolRange: type.SymbolRange, + type: Types.OnType(type.Type), + typeItems: Namespaces.OnTypeItems(type.TypeItems), + documentation: Namespaces.OnDocumentation(type.Documentation)); + } + + + // private helper classes + private class TypeTransformation : Core.TypeTransformation { - private readonly TransformationState state; + private readonly TransformationState State; - public TypeTransformation(RenameReferences parent, TransformationState state) : base(parent) => - this.state = state; + public TypeTransformation(RenameReferences parent) : base(parent) => + this.State = parent.State; public override QsTypeKind OnUserDefinedType(UserDefinedType udt) => - base.OnUserDefinedType(state.RenameUdt(udt)); + QsTypeKind.NewUserDefinedType(State.RenameUdt(udt)); public override QsTypeKind OnTypeParameter(QsTypeParameter tp) => - base.OnTypeParameter(new QsTypeParameter(state.GetNewName(tp.Origin), tp.TypeName, tp.Range)); + QsTypeKind.NewTypeParameter(new QsTypeParameter(State.GetNewName(tp.Origin), tp.TypeName, tp.Range)); } private class ExpressionKindTransformation : Core.ExpressionKindTransformation { - private readonly TransformationState state; + private readonly TransformationState State; - public ExpressionKindTransformation(RenameReferences parent, TransformationState state) : base(parent) => - this.state = state; + public ExpressionKindTransformation(RenameReferences parent) : base(parent) => + this.State = parent.State; public override QsExpressionKind OnIdentifier(Identifier id, QsNullable> typeArgs) { if (id is Identifier.GlobalCallable global) { - id = Identifier.NewGlobalCallable(state.GetNewName(global.Item)); + id = Identifier.NewGlobalCallable(State.GetNewName(global.Item)); } return base.OnIdentifier(id, typeArgs); } @@ -575,29 +647,28 @@ public override QsExpressionKind OnIdentifier(Identifier id, QsNullable - this.state = state; + public NamespaceTransformation(RenameReferences parent) : base(parent) => + this.State = parent.State; public override QsDeclarationAttribute OnAttribute(QsDeclarationAttribute attribute) { var argument = Transformation.Expressions.OnTypedExpression(attribute.Argument); var typeId = attribute.TypeId.IsValue - ? QsNullable.NewValue(state.RenameUdt(attribute.TypeId.Item)) + ? QsNullable.NewValue(State.RenameUdt(attribute.TypeId.Item)) : attribute.TypeId; - return base.OnAttribute( - new QsDeclarationAttribute(typeId, argument, attribute.Offset, attribute.Comments)); + return new QsDeclarationAttribute(typeId, argument, attribute.Offset, attribute.Comments); } public override QsCallable OnCallableDeclaration(QsCallable callable) => - base.OnCallableDeclaration(callable.WithFullName(state.GetNewName)); + base.OnCallableDeclaration(callable.WithFullName(State.GetNewName)); public override QsCustomType OnTypeDeclaration(QsCustomType type) => - base.OnTypeDeclaration(type.WithFullName(state.GetNewName)); + base.OnTypeDeclaration(type.WithFullName(State.GetNewName)); public override QsSpecialization OnSpecializationDeclaration(QsSpecialization spec) => - base.OnSpecializationDeclaration(spec.WithParent(state.GetNewName)); + base.OnSpecializationDeclaration(spec.WithParent(State.GetNewName)); } } From eeb4ce43fcc443ce23ea44e50087ad3eafa6f527 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Mon, 16 Mar 2020 10:47:00 -0700 Subject: [PATCH 2/3] found the issue --- src/QsCompiler/Tests.Compiler/LinkingTests.fs | 28 +++++++------------ .../Transformations/SearchAndReplace.cs | 5 ++-- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/QsCompiler/Tests.Compiler/LinkingTests.fs b/src/QsCompiler/Tests.Compiler/LinkingTests.fs index 56235e36ab..e812561507 100644 --- a/src/QsCompiler/Tests.Compiler/LinkingTests.fs +++ b/src/QsCompiler/Tests.Compiler/LinkingTests.fs @@ -7,6 +7,7 @@ open System open System.Collections.Generic open System.Collections.Immutable open System.IO +open System.Linq open Microsoft.Quantum.QsCompiler open Microsoft.Quantum.QsCompiler.CompilationBuilder open Microsoft.Quantum.QsCompiler.DataTypes @@ -27,21 +28,16 @@ type LinkingTests (output:ITestOutputHelper) = let compilationManager = new CompilationUnitManager(new Action (fun ex -> failwith ex.Message)) - let getTempFile () = - // The file name needs to end in ".qs" so that it isn't ignored by the References.Headers class during the - // internal renaming tests. - Path.GetRandomFileName () + ".qs" |> Path.GetFullPath |> Uri - + // The file name needs to end in ".qs" so that it isn't ignored by the References.Headers class during the internal renaming tests. + let getTempFile () = Path.GetRandomFileName () + ".qs" |> Path.GetFullPath |> Uri let getManager uri content = CompilationUnitManager.InitializeFileManager(uri, content, compilationManager.PublishDiagnostics, compilationManager.LogException) - let defaultOffset = - { - Offset = DiagnosticTools.AsTuple (Position (0, 0)) - Range = QsCompilerDiagnostic.DefaultRange - } - - let qualifiedName ns name = - { + let defaultOffset = { + Offset = DiagnosticTools.AsTuple (Position (0, 0)) + Range = QsCompilerDiagnostic.DefaultRange + } + + let qualifiedName ns name = { Namespace = NonNullable<_>.New ns Name = NonNullable<_>.New name } @@ -59,11 +55,7 @@ type LinkingTests (output:ITestOutputHelper) = let declaration = if obj.ReferenceEquals (references.SharedState.DeclarationLocation, null) then 0 else 1 references.SharedState.Locations.Count + declaration - do - let addOrUpdateSourceFile filePath = - getManager (new Uri(filePath)) (File.ReadAllText filePath) - |> compilationManager.AddOrUpdateSourceFileAsync - |> ignore + do let addOrUpdateSourceFile filePath = getManager (new Uri(filePath)) (File.ReadAllText filePath) |> compilationManager.AddOrUpdateSourceFileAsync |> ignore Path.Combine ("TestCases", "LinkingTests", "Core.qs") |> Path.GetFullPath |> addOrUpdateSourceFile static member private ReadAndChunkSourceFile fileName = diff --git a/src/QsCompiler/Transformations/SearchAndReplace.cs b/src/QsCompiler/Transformations/SearchAndReplace.cs index 7835648f38..8d629913a6 100644 --- a/src/QsCompiler/Transformations/SearchAndReplace.cs +++ b/src/QsCompiler/Transformations/SearchAndReplace.cs @@ -55,8 +55,9 @@ public Location(NonNullable source, Tuple declOffset, QsLocati public bool Equals(Location other) => this.SourceFile.Value == other?.SourceFile.Value - && this.DeclarationOffset == other?.DeclarationOffset - && this.RelativeStatementLocation == other?.RelativeStatementLocation + && this.DeclarationOffset.Equals(other?.DeclarationOffset) + && this.RelativeStatementLocation.Offset.Equals(other?.RelativeStatementLocation.Offset) + && this.RelativeStatementLocation.Range.Equals(other?.RelativeStatementLocation.Range) && this.SymbolRange.Item1.Equals(other?.SymbolRange?.Item1) && this.SymbolRange.Item2.Equals(other?.SymbolRange?.Item2); From 7acc874836576a1a85b30c1ea21db7220a07867f Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Mon, 16 Mar 2020 11:03:27 -0700 Subject: [PATCH 3/3] removing static header methods --- .../Transformations/SearchAndReplace.cs | 66 ------------------- 1 file changed, 66 deletions(-) diff --git a/src/QsCompiler/Transformations/SearchAndReplace.cs b/src/QsCompiler/Transformations/SearchAndReplace.cs index 8d629913a6..d66803179a 100644 --- a/src/QsCompiler/Transformations/SearchAndReplace.cs +++ b/src/QsCompiler/Transformations/SearchAndReplace.cs @@ -547,72 +547,6 @@ public RenameReferences(IImmutableDictionary n } - // methods for transformations on headers - - /// - /// Renames references in the callable declaration header, including the name of the callable itself. - /// - /// The callable declaration header in which to rename references. - /// The callable declaration header with renamed references. - public CallableDeclarationHeader OnCallableDeclarationHeader(CallableDeclarationHeader callable) => - new CallableDeclarationHeader( - kind: callable.Kind, - qualifiedName: State.GetNewName(callable.QualifiedName), - attributes: callable.Attributes.Select(Namespaces.OnAttribute).ToImmutableArray(), - modifiers: callable.Modifiers, - sourceFile: callable.SourceFile, - position: callable.Position, - symbolRange: callable.SymbolRange, - argumentTuple: Namespaces.OnArgumentTuple(callable.ArgumentTuple), - signature: Namespaces.OnSignature(callable.Signature), - documentation: Namespaces.OnDocumentation(callable.Documentation)); - - /// - /// Renames references in the specialization declaration header, including the name of the specialization - /// itself. - /// - /// The specialization declaration header in which to rename references. - /// The specialization declaration header with renamed references. - public SpecializationDeclarationHeader OnSpecializationDeclarationHeader( - SpecializationDeclarationHeader specialization) - { - var typeArguments = - specialization.TypeArguments.IsValue - ? QsNullable>.NewValue( - specialization.TypeArguments.Item.Select(Types.OnType).ToImmutableArray()) - : QsNullable>.Null; - return new SpecializationDeclarationHeader( - kind: specialization.Kind, - typeArguments: typeArguments, - information: specialization.Information, - parent: State.GetNewName(specialization.Parent), - attributes: specialization.Attributes.Select(Namespaces.OnAttribute).ToImmutableArray(), - sourceFile: specialization.SourceFile, - position: specialization.Position, - headerRange: specialization.HeaderRange, - documentation: Namespaces.OnDocumentation(specialization.Documentation)); - } - - /// - /// Renames references in the type declaration header, including the name of the type itself. - /// - /// The type declaration header in which to rename references. - /// The type declaration header with renamed references. - public TypeDeclarationHeader OnTypeDeclarationHeader(TypeDeclarationHeader type) - { - return new TypeDeclarationHeader( - qualifiedName: State.GetNewName(type.QualifiedName), - attributes: type.Attributes.Select(Namespaces.OnAttribute).ToImmutableArray(), - modifiers: type.Modifiers, - sourceFile: type.SourceFile, - position: type.Position, - symbolRange: type.SymbolRange, - type: Types.OnType(type.Type), - typeItems: Namespaces.OnTypeItems(type.TypeItems), - documentation: Namespaces.OnDocumentation(type.Documentation)); - } - - // private helper classes private class TypeTransformation : Core.TypeTransformation