private List <Parameter> RemoveOperatorParams(Function function) { var functionParams = new List <Parameter>(function.Parameters); if (!function.IsOperator || (Context.Options.GeneratorKind != GeneratorKind.CLI && Context.Options.GeneratorKind != GeneratorKind.CSharp)) { return(functionParams); } // C++ operators in a class have no class param unlike C# // but we need to be able to compare them to free operators. Parameter param = functionParams.Find(p => p.Kind == ParameterKind.Regular); if (param != null) { AST.Type type = param.Type.Desugar(); type = (type.GetFinalPointee() ?? type).Desugar(); Class @class; if (type.TryGetClass(out @class) && function.Namespace == @class) { functionParams.Remove(param); } } return(functionParams); }
private void CheckTypeForSpecialization(AST.Type type) { type = type.Desugar(); ClassTemplateSpecialization specialization; type = type.GetFinalPointee() ?? type; if (!type.TryGetDeclaration(out specialization)) return; if (specialization.Ignore || specialization.TemplatedDecl.TemplatedClass.Ignore || specialization.IsIncomplete || specialization.TemplatedDecl.TemplatedClass.IsIncomplete || specialization is ClassTemplatePartialSpecialization || specialization.Arguments.Any(a => UnsupportedTemplateArgument(specialization, a))) return; TypeMap typeMap; if (Context.TypeMaps.FindTypeMap(specialization, out typeMap)) { var mappedTo = typeMap.CSharpSignatureType(new CSharpTypePrinterContext { Type = type }); mappedTo = mappedTo.Desugar(); mappedTo = (mappedTo.GetFinalPointee() ?? mappedTo); if (mappedTo.IsPrimitiveType() || mappedTo.IsPointerToPrimitiveType() || mappedTo.IsEnum()) return; } HashSet<ClassTemplateSpecialization> list; if (specializations.ContainsKey(specialization.TranslationUnit.Module)) list = specializations[specialization.TranslationUnit.Module]; else specializations[specialization.TranslationUnit.Module] = list = new HashSet<ClassTemplateSpecialization>(); list.Add(specialization); }
private bool CheckDefaultParametersForAmbiguity(Function function, Function overload) { List <Parameter> functionParams = RemoveOperatorParams(function); List <Parameter> overloadParams = RemoveOperatorParams(overload); var commonParameters = Math.Min(functionParams.Count, overloadParams.Count); var i = 0; for (; i < commonParameters; ++i) { AST.Type funcType = functionParams[i].Type.GetMappedType( TypeMaps, Options.GeneratorKind); AST.Type overloadType = overloadParams[i].Type.GetMappedType( TypeMaps, Options.GeneratorKind); AST.Type funcPointee = funcType.GetFinalPointee() ?? funcType; AST.Type overloadPointee = overloadType.GetFinalPointee() ?? overloadType; if (((funcPointee.IsPrimitiveType() || overloadPointee.IsPrimitiveType()) && !funcType.Equals(overloadType)) || !funcPointee.Equals(overloadPointee)) { return(false); } } for (; i < functionParams.Count; ++i) { var funcParam = functionParams[i]; if (!funcParam.HasDefaultValue) { return(false); } } for (; i < overloadParams.Count; ++i) { var overloadParam = overloadParams[i]; if (!overloadParam.HasDefaultValue) { return(false); } } if (functionParams.Count > overloadParams.Count) { overload.ExplicitlyIgnore(); } else { function.ExplicitlyIgnore(); } return(true); }
private bool CheckDefaultParametersForAmbiguity(Function function, Function overload) { var commonParameters = Math.Min(function.Parameters.Count, overload.Parameters.Count); var i = 0; for (; i < commonParameters; ++i) { AST.Type funcType = GetFinalType(function.Parameters[i]); AST.Type overloadType = GetFinalType(overload.Parameters[i]); AST.Type funcPointee = funcType.GetFinalPointee() ?? funcType; AST.Type overloadPointee = overloadType.GetFinalPointee() ?? overloadType; if (((funcPointee.IsPrimitiveType() || overloadPointee.IsPrimitiveType()) && !funcType.Equals(overloadType)) || !funcPointee.Equals(overloadPointee)) { return(false); } } for (; i < function.Parameters.Count; ++i) { var funcParam = function.Parameters[i]; if (!funcParam.HasDefaultValue) { return(false); } } for (; i < overload.Parameters.Count; ++i) { var overloadParam = overload.Parameters[i]; if (!overloadParam.HasDefaultValue) { return(false); } } if (function.Parameters.Count > overload.Parameters.Count) { overload.ExplicitlyIgnore(); } else { function.ExplicitlyIgnore(); } return(true); }