/// <summary> /// Combine all the different clauses for a set of overloaded functions into a OverloadedFunctionDefinition (which can be further transformed presently) /// </summary> /// <param name="functionSignature">the common signature on which this overload group is based</param> /// <param name="functionDefinitions">the original functions</param> /// <returns></returns> private IFunctionDefinition TransformOverloadGroup(IFunctionSignature functionSignature, List <IFunctionDefinition> functionDefinitions) { var orderedFuns = functionDefinitions.OrderBy(fd => fd.Line).ToList(); var firstClause = orderedFuns.First(); var result = new OverloadedFunctionDefinition(orderedFuns, functionSignature) .CameFromSameSourceLocation(firstClause) .HasSameParentAs(functionDefinitions.First()); result.Name = firstClause.Name; result.ReturnType = firstClause.ReturnType; result.Typename = firstClause.Typename; var ctx = functionDefinitions.Last(); var paramDecls = new List <IParameterListItem>(); if (ctx.ParameterDeclarations?.ParameterDeclarations.Any() ?? false) { foreach (var pd in ctx.ParameterDeclarations.ParameterDeclarations) { paramDecls.Add(new ParameterDeclaration(new Identifier(pd.ParameterName.Value), pd.TypeName, null)); } } result.ParameterDeclarations = new ParameterDeclarationList(paramDecls); return(result); }
public bool Add(IFunctionSignature function) { var name = GetOverloadName(function.Name, function.ArgTypes.Length); if (_functions.ContainsKey(name)) { return(false); } _functions.Add(name, function); if (!_overloads.ContainsKey(function.Name)) { _overloads.Add(function.Name, new List <IFunctionSignature>()); } _overloads[function.Name].Add(function); return(true); }
public static bool AreEqual(IFunctionSignature x, IFunctionSignature y) { if ((x == null && y != null) || (x != null && y == null)) { return(false); } var returnTypesMatch = Equals(x.ReturnType, y.ReturnType); if (x.FormalParameterTypes.Length != y.FormalParameterTypes.Length) { return(false); } var paramTypesMatch = true; for (var i = 0; i < x.FormalParameterTypes.Length; i++) { paramTypesMatch &= Equals(x.FormalParameterTypes[i], y.FormalParameterTypes[i]); } var nameMatches = x.Name == y.Name; var tidMatches = Equals(x.TypeId, y.TypeId); if ((x.GenericTypeParameters == null && y.GenericTypeParameters != null) || (x.GenericTypeParameters != null && y.GenericTypeParameters == null)) { return(false); } if (x.GenericTypeParameters != null && y.GenericTypeParameters != null && x.GenericTypeParameters.Length != y.GenericTypeParameters.Length) { return(false); } var genericTypeParamsMatch = true; for (var i = 0; x.GenericTypeParameters != null && i < x.GenericTypeParameters.Length; i++) { paramTypesMatch &= Equals(x.GenericTypeParameters[i], y.GenericTypeParameters[i]); } return(returnTypesMatch && paramTypesMatch && nameMatches && tidMatches && genericTypeParamsMatch); }
public static Exception InvalidOutputType(IFunctionSignature function, Interval interval) => new FunParseException(551, $"'{function.ReturnType}' is not supported as output parameter of {function.Name}()", interval);
public FunctionalVariableCallInfo(IFunctionSignature signature, StateRefTo[] referenceToGenericArguments) { Signature = signature; ReferenceToGenericArguments = referenceToGenericArguments; }
public static ITicNodeState GetTicFunType(this IFunctionSignature functionBase) => StateFun.Of( functionBase.ArgTypes.SelectToArray(a => a.ConvertToTiType()), functionBase.ReturnType.ConvertToTiType());