public override QsExpressionKind <TypedExpression, Identifier, ResolvedType> onIdentifier(Identifier sym, QsNullable <ImmutableArray <ResolvedType> > tArgs) { if (sym is Identifier.GlobalCallable global) { ImmutableConcretion applicableParams = CurrentParamTypes .Where(kvp => kvp.Key.Item1.Equals(global.Item)) .ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value); // Create a new identifier sym = GetConcreteIdentifier(global, applicableParams); tArgs = QsNullable <ImmutableArray <ResolvedType> > .Null; // Remove Type Params used from the CurrentParamTypes foreach (var key in applicableParams.Keys) { CurrentParamTypes.Remove(key); } } else if (sym is Identifier.LocalVariable && tArgs.IsValue && tArgs.Item.Any()) { throw new ArgumentException($"Local variables cannot have type arguments."); } return(base.onIdentifier(sym, tArgs)); }
public override QsExpressionKind <TypedExpression, Identifier, ResolvedType> OnIdentifier(Identifier sym, QsNullable <ImmutableArray <ResolvedType> > tArgs) { if (sym is Identifier.GlobalCallable global) { ImmutableConcretion applicableParams = this.SharedState.CurrentParamTypes .Where(kvp => kvp.Key.Item1.Equals(global.Item)) .ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value); // We want to skip over intrinsic callables. They will not be monomorphized. if (!this.SharedState.IntrinsicCallableSet.Contains(global.Item)) { // Create a new identifier sym = this.SharedState.GetConcreteIdentifier(global, applicableParams); tArgs = QsNullable <ImmutableArray <ResolvedType> > .Null; } // Remove Type Params used from the CurrentParamTypes foreach (var key in applicableParams.Keys) { this.SharedState.CurrentParamTypes.Remove(key); } } else if (sym is Identifier.LocalVariable && tArgs.IsValue && tArgs.Item.Any()) { throw new ArgumentException($"Local variables cannot have type arguments."); } return(base.OnIdentifier(sym, tArgs)); }
public ReplaceTypeParamImplementationsSyntax(ImmutableConcretion typeParams) : base( new ScopeTransformation <ExpressionTransformation <Core.ExpressionKindTransformation, ReplaceTypeParamImplementationsExpressionType> >( new ExpressionTransformation <Core.ExpressionKindTransformation, ReplaceTypeParamImplementationsExpressionType>( ex => new ExpressionKindTransformation <ExpressionTransformation <Core.ExpressionKindTransformation, ReplaceTypeParamImplementationsExpressionType> >(ex as ExpressionTransformation <Core.ExpressionKindTransformation, ReplaceTypeParamImplementationsExpressionType>), ex => new ReplaceTypeParamImplementationsExpressionType(typeParams, ex as ExpressionTransformation <Core.ExpressionKindTransformation, ReplaceTypeParamImplementationsExpressionType>) ))) { }
public override ImmutableConcretion OnTypeParamResolutions(ImmutableConcretion typeParams) { // Merge the type params into the current dictionary foreach (var kvp in typeParams) { SharedState.CurrentParamTypes.Add(kvp.Key, kvp.Value); } return(ImmutableConcretion.Empty); }
public override ImmutableConcretion OnTypeParamResolutions(ImmutableConcretion typeParams) { // Merge the type params into the current dictionary foreach (var kvp in typeParams.Where(kv => !this.SharedState.IntrinsicCallableSet.Contains(kv.Key.Item1))) { this.SharedState.CurrentParamTypes.Add(kvp.Key, kvp.Value); } return(typeParams.Where(kv => this.SharedState.IntrinsicCallableSet.Contains(kv.Key.Item1)).ToImmutableDictionary()); }
private ReplaceTypeParamImplementations(ImmutableConcretion typeParams) : base(new TransformationState(typeParams)) { this.Namespaces = new NamespaceTransformation(this); this.Types = new TypeTransformation(this); }
public TransformationState(ImmutableConcretion typeParams) { this.TypeParams = typeParams; }
private static Identifier GetConcreteIdentifier( Response currentResponse, Stack <Request> requests, List <Response> responses, Identifier.GlobalCallable globalCallable, ImmutableConcretion types) { QsQualifiedName concreteName = globalCallable.Item; var typesHashSet = ImmutableHashSet <KeyValuePair <Tuple <QsQualifiedName, NonNullable <string> >, ResolvedType> > .Empty; if (types != null && !types.IsEmpty) { typesHashSet = types.ToImmutableHashSet(); } string name = null; // Check for recursive call if (currentResponse.OriginalName.Equals(globalCallable.Item) && typesHashSet.SetEquals(currentResponse.TypeResolutions)) { name = currentResponse.ConcreteCallable.FullName.Name.Value; } // Search requests for identifier if (name == null) { name = requests .Where(req => req.OriginalName.Equals(globalCallable.Item) && typesHashSet.SetEquals(req.TypeResolutions)) .Select(req => req.ConcreteName.Name.Value) .FirstOrDefault(); } // Search responses for identifier if (name == null) { name = responses .Where(res => res.OriginalName.Equals(globalCallable.Item) && typesHashSet.SetEquals(res.TypeResolutions)) .Select(res => res.ConcreteCallable.FullName.Name.Value) .FirstOrDefault(); } // If identifier can't be found, make a new request if (name == null) { // If this is not a generic, do not change the name if (!typesHashSet.IsEmpty) { // Create new name concreteName = UniqueVariableNames.PrependGuid(globalCallable.Item); } requests.Push(new Request() { OriginalName = globalCallable.Item, TypeResolutions = types, ConcreteName = concreteName }); } else { // If the identifier was found, update with the name concreteName = new QsQualifiedName(globalCallable.Item.Namespace, NonNullable <string> .New(name)); } return(Identifier.NewGlobalCallable(concreteName)); }
public ReplaceTypeParamImplementationsExpressionType(ImmutableConcretion typeParams, ExpressionTransformation <Core.ExpressionKindTransformation, ReplaceTypeParamImplementationsExpressionType> expr) : base(expr) { TypeParams = typeParams; }