public InvocationResolveResult( ResolveResult targetResult, IParameterizedMember member, IType returnType, IList<ResolveResult> arguments) : base(targetResult, member, returnType) { this.Arguments = arguments ?? EmptyList<ResolveResult>.Instance; }
public InvocationResolveResult(ResolveResult targetResult, IParameterizedMember member, IList<ResolveResult> arguments = null, IList<ResolveResult> initializerStatements = null) : base(targetResult, member) { this.Arguments = arguments ?? EmptyList<ResolveResult>.Instance; this.InitializerStatements = initializerStatements ?? EmptyList<ResolveResult>.Instance; }
public static int GetHashCode(ITypeResolveContext context, IParameterizedMember obj) { int hashCode = obj.Parameters.Count; unchecked { foreach (IParameter p in obj.Parameters) { hashCode *= 27; hashCode += p.Type.Resolve(context).GetHashCode(); } } return hashCode; }
public InvocationResolveResult(ResolveResult targetResult, IParameterizedMember member, IList<ResolveResult> arguments = null, IList<ResolveResult> initializerStatements = null, IType returnTypeOverride = null, bool isConditionallyRemoved = false) : base(targetResult, member, returnTypeOverride) { this.Arguments = arguments ?? EmptyList<ResolveResult>.Instance; this.InitializerStatements = initializerStatements ?? EmptyList<ResolveResult>.Instance; this.IsConditionallyRemoved = isConditionallyRemoved; }
public NamedArgumentResolveResult(IParameter parameter, ResolveResult argument, IParameterizedMember member = null) : base(argument.Type) { if (parameter == null) throw new ArgumentNullException("parameter"); if (argument == null) throw new ArgumentNullException("argument"); this.Member = member; this.Parameter = parameter; this.ParameterName = parameter.Name; this.Argument = argument; }
public CSharpInvocationResolveResult( ResolveResult targetResult, IParameterizedMember member, IList<ResolveResult> arguments, OverloadResolutionErrors overloadResolutionErrors = OverloadResolutionErrors.None, bool isExtensionMethodInvocation = false, bool isExpandedForm = false, bool isDelegateInvocation = false, IList<int> argumentToParameterMap = null) : base(targetResult, member, arguments) { this.OverloadResolutionErrors = overloadResolutionErrors; this.IsExtensionMethodInvocation = isExtensionMethodInvocation; this.IsExpandedForm = isExpandedForm; this.IsDelegateInvocation = isDelegateInvocation; this.argumentToParameterMap = argumentToParameterMap; }
public DefaultParameter(IType type, string name, IParameterizedMember owner = null, DomRegion region = default(DomRegion), IList<IAttribute> attributes = null, bool isRef = false, bool isOut = false, bool isParams = false, bool isOptional = false, object defaultValue = null) { if (type == null) throw new ArgumentNullException("type"); if (name == null) throw new ArgumentNullException("name"); this.type = type; this.name = name; this.owner = owner; this.region = region; this.attributes = attributes; this.isRef = isRef; this.isOut = isOut; this.isParams = isParams; this.isOptional = isOptional; this.defaultValue = defaultValue; }
public static bool Compare(ITypeResolveContext context, IParameterizedMember x, IParameterizedMember y) { var px = x.Parameters; var py = y.Parameters; if (px.Count != py.Count) return false; for (int i = 0; i < px.Count; i++) { var a = px[i]; var b = py[i]; if (a == null && b == null) continue; if (a == null || b == null) return false; if (!a.Type.Resolve(context).Equals(b.Type.Resolve(context))) return false; } return true; }
bool HasPredicateVersion(IParameterizedMember member) { if (!IsQueryExtensionClass(member.DeclaringTypeDefinition)) return false; switch (member.Name) { case "Any": case "Count": case "First": case "FirstOrDefault": case "Last": case "LastOrDefault": case "LongCount": case "Single": case "SingleOrDefault": return true; default: return false; } }
public InvocationResolveResult( ResolveResult targetResult, IParameterizedMember member, IType returnType, IList<ResolveResult> arguments, OverloadResolutionErrors overloadResolutionErrors = OverloadResolutionErrors.None, bool isExtensionMethodInvocation = false, bool isExpandedForm = false, bool isLiftedOperatorInvocation = false, bool isDelegateInvocation = false, IList<int> argumentToParameterMap = null) : base(targetResult, member, returnType) { this.OverloadResolutionErrors = overloadResolutionErrors; this.Arguments = arguments ?? EmptyList<ResolveResult>.Instance; this.IsExtensionMethodInvocation = isExtensionMethodInvocation; this.IsExpandedForm = isExpandedForm; this.IsLiftedOperatorInvocation = isLiftedOperatorInvocation; this.IsDelegateInvocation = isDelegateInvocation; this.argumentToParameterMap = argumentToParameterMap; }
public CSharpInvocationResolveResult( ResolveResult targetResult, IParameterizedMember member, IList<ResolveResult> arguments, OverloadResolutionErrors overloadResolutionErrors = OverloadResolutionErrors.None, bool isExtensionMethodInvocation = false, bool isExpandedForm = false, bool isDelegateInvocation = false, IList<int> argumentToParameterMap = null, IList<ResolveResult> initializerStatements = null, IType returnTypeOverride = null, bool isConditionallyRemoved = false ) : base(targetResult, member, arguments, initializerStatements, returnTypeOverride, isConditionallyRemoved) { this.OverloadResolutionErrors = overloadResolutionErrors; this.IsExtensionMethodInvocation = isExtensionMethodInvocation; this.IsExpandedForm = isExpandedForm; this.IsDelegateInvocation = isDelegateInvocation; this.argumentToParameterMap = argumentToParameterMap; }
void CompareMethods(string memberType, AstNodeCollection <ParameterDeclaration> parameters, IParameterizedMember overridenMethod, IParameterizedMember baseMethod) { var parameterEnumerator = parameters.GetEnumerator(); for (int parameterIndex = 0; parameterIndex < overridenMethod.Parameters.Count; parameterIndex++) { parameterEnumerator.MoveNext(); var baseParameter = baseMethod.Parameters [parameterIndex]; var overridenParameter = overridenMethod.Parameters [parameterIndex]; string parameterName = overridenParameter.Name; var parameterDeclaration = parameterEnumerator.Current; if (overridenParameter.IsOptional) { if (!baseParameter.IsOptional) { AddIssue(new CodeIssue(parameterDeclaration, string.Format(ctx.TranslateString("Optional parameter value {0} differs from base " + memberType + " '{1}'"), parameterName, baseMethod.DeclaringType.FullName), ctx.TranslateString("Remove parameter default value"), script => { script.Remove(parameterDeclaration.AssignToken); script.Remove(parameterDeclaration.DefaultExpression); script.FormatText(parameterDeclaration); })); } else if (!object.Equals(overridenParameter.ConstantValue, baseParameter.ConstantValue)) { AddIssue(new CodeIssue(parameterDeclaration, string.Format(ctx.TranslateString("Optional parameter value {0} differs from base " + memberType + " '{1}'"), parameterName, baseMethod.DeclaringType.FullName), string.Format(ctx.TranslateString("Change default value to {0}"), baseParameter.ConstantValue), script => script.Replace(parameterDeclaration.DefaultExpression, CreateDefaultValueExpression(ctx, parameterDeclaration, baseParameter.Type, baseParameter.ConstantValue)))); } } else { if (!baseParameter.IsOptional) { continue; } AddIssue(new CodeIssue(parameterDeclaration, string.Format(ctx.TranslateString("Parameter {0} has default value in base method '{1}'"), parameterName, baseMethod.FullName), string.Format(ctx.TranslateString("Add default value from base '{0}'"), CreateDefaultValueExpression(ctx, parameterDeclaration, baseParameter.Type, baseParameter.ConstantValue)), script => { var newParameter = (ParameterDeclaration)parameterDeclaration.Clone(); newParameter.DefaultExpression = CreateDefaultValueExpression(ctx, parameterDeclaration, baseParameter.Type, baseParameter.ConstantValue); script.Replace(parameterDeclaration, newParameter); } )); } } }
protected SpecializedParameterizedMember(IParameterizedMember memberDefinition) : base(memberDefinition) { }
public LiftedUserDefinedOperator(IMethod nonLiftedMethod) : base(nonLiftedMethod, TypeParameterSubstitution.Identity) { this.nonLiftedOperator = nonLiftedMethod; var substitution = new MakeNullableVisitor(nonLiftedMethod.Compilation); this.Parameters = base.CreateParameters(substitution); // Comparison operators keep the 'bool' return type even when lifted. if (IsComparisonOperator(nonLiftedMethod)) this.ReturnType = nonLiftedMethod.ReturnType; else this.ReturnType = nonLiftedMethod.ReturnType.AcceptVisitor(substitution); }
public LiftedUserDefinedOperator(IMethod nonLiftedMethod) : base(nonLiftedMethod.DeclaringType, (IMethod)nonLiftedMethod.MemberDefinition, EmptyList<IType>.Instance, new MakeNullableVisitor(nonLiftedMethod.Compilation)) { this.nonLiftedOperator = nonLiftedMethod; // Comparison operators keep the 'bool' return type even when lifted. if (IsComparisonOperator(nonLiftedMethod)) this.ReturnType = nonLiftedMethod.ReturnType; }
public XmlNode SelectOverload(XmlNodeList nodes, IParameterizedMember entity) { XmlNode node = null; if (nodes.Count == 1) { node = nodes[0]; } else { var p = entity.Parameters; foreach (XmlNode curNode in nodes) { var paramList = curNode.SelectNodes("Parameters/*"); if (p.Count == 0 && paramList.Count == 0) return curNode; if (p.Count != paramList.Count) continue; bool matched = true; for (int i = 0; i < p.Count; i++) { var idString = GetTypeString(p[i].Type); if (idString != paramList[i].Attributes["Type"].Value) { matched = false; break; } } if (matched) { return curNode; } } } if (node != null) { System.Xml.XmlNode result = node.SelectSingleNode("Docs"); return result; } return null; }
protected abstract string GetParameterString (IParameterizedMember member, IParameter parameter, OutputSettings settings);
/// <summary> /// Gets the ID string (C# 4.0 spec, §A.3.1) for the specified entity. /// </summary> public static string GetIdString(this IEntity entity) { StringBuilder b = new StringBuilder(); switch (entity.SymbolKind) { case SymbolKind.TypeDefinition: b.Append("T:"); AppendTypeName(b, (ITypeDefinition)entity, false); return(b.ToString()); case SymbolKind.Field: b.Append("F:"); break; case SymbolKind.Property: case SymbolKind.Indexer: b.Append("P:"); break; case SymbolKind.Event: b.Append("E:"); break; default: b.Append("M:"); break; } IMember member = (IMember)entity; if (member.DeclaringType != null) { AppendTypeName(b, member.DeclaringType, false); b.Append('.'); } if (member.IsExplicitInterfaceImplementation && member.Name.IndexOf('.') < 0 && member.ExplicitlyImplementedInterfaceMembers.Count() == 1) { AppendTypeName(b, member.ExplicitlyImplementedInterfaceMembers.First().DeclaringType, true); b.Append('#'); } b.Append(member.Name.Replace('.', '#').Replace('<', '{').Replace('>', '}')); IMethod method = member as IMethod; if (method != null && method.TypeParameters.Count > 0) { b.Append("``"); b.Append(method.TypeParameters.Count); } IParameterizedMember parameterizedMember = member as IParameterizedMember; if (parameterizedMember != null && parameterizedMember.Parameters.Count > 0) { b.Append('('); var parameters = parameterizedMember.Parameters; for (int i = 0; i < parameters.Count; i++) { if (i > 0) { b.Append(','); } AppendTypeName(b, parameters[i].Type, false); } b.Append(')'); } if (member.SymbolKind == SymbolKind.Operator && (member.Name == "op_Implicit" || member.Name == "op_Explicit")) { b.Append('~'); AppendTypeName(b, member.ReturnType, false); } return(b.ToString()); }
public static TooltipInformation CreateTooltipInformation (ICompilation compilation, CSharpUnresolvedFile file, TextEditorData textEditorData, MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy formattingPolicy, IParameterizedMember entity, int currentParameter, bool smartWrap) { var tooltipInfo = new TooltipInformation (); var resolver = file.GetResolver (compilation, textEditorData.Caret.Location); var sig = new SignatureMarkupCreator (resolver, formattingPolicy.CreateOptions ()); sig.HighlightParameter = currentParameter; sig.BreakLineAfterReturnType = smartWrap; try { tooltipInfo.SignatureMarkup = sig.GetMarkup (entity); } catch (Exception e) { LoggingService.LogError ("Got exception while creating markup for :" + entity, e); return new TooltipInformation (); } tooltipInfo.SummaryMarkup = AmbienceService.GetSummaryMarkup (entity) ?? ""; if (entity is IMethod) { var method = (IMethod)entity; if (method.IsExtensionMethod) { tooltipInfo.AddCategory (GettextCatalog.GetString ("Extension Method from"), method.DeclaringTypeDefinition.FullName); } } int paramIndex = currentParameter; if (entity is IMethod && ((IMethod)entity).IsExtensionMethod) paramIndex++; paramIndex = Math.Min (entity.Parameters.Count - 1, paramIndex); var curParameter = paramIndex >= 0 && paramIndex < entity.Parameters.Count ? entity.Parameters [paramIndex] : null; if (curParameter != null) { string docText = AmbienceService.GetDocumentation (entity); if (!string.IsNullOrEmpty (docText)) { string text = docText; Regex paramRegex = new Regex ("(\\<param\\s+name\\s*=\\s*\"" + curParameter.Name + "\"\\s*\\>.*?\\</param\\>)", RegexOptions.Compiled); Match match = paramRegex.Match (docText); if (match.Success) { text = AmbienceService.GetDocumentationMarkup (entity, match.Groups [1].Value); if (!string.IsNullOrWhiteSpace (text)) tooltipInfo.AddCategory (GettextCatalog.GetString ("Parameter"), text); } } if (curParameter.Type.Kind == TypeKind.Delegate) tooltipInfo.AddCategory (GettextCatalog.GetString ("Delegate Info"), sig.GetDelegateInfo (curParameter.Type)); } return tooltipInfo; }
public static TooltipInformation CreateTooltipInformation(CSharpCompletionTextEditorExtension ext, ICompilation compilation, CSharpUnresolvedFile file, IParameterizedMember entity, int currentParameter, bool smartWrap) { return(CreateTooltipInformation(compilation, file, ext.TextEditorData, ext.FormattingPolicy, entity, currentParameter, smartWrap)); }
public static TooltipInformation CreateTooltipInformation(ICompilation compilation, CSharpUnresolvedFile file, TextEditorData textEditorData, MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy formattingPolicy, IParameterizedMember entity, int currentParameter, bool smartWrap) { var tooltipInfo = new TooltipInformation(); var resolver = file.GetResolver(compilation, textEditorData.Caret.Location); var sig = new SignatureMarkupCreator(resolver, formattingPolicy.CreateOptions()); sig.HighlightParameter = currentParameter; sig.BreakLineAfterReturnType = smartWrap; try { tooltipInfo.SignatureMarkup = sig.GetMarkup(entity); } catch (Exception e) { LoggingService.LogError("Got exception while creating markup for :" + entity, e); return(new TooltipInformation()); } tooltipInfo.SummaryMarkup = AmbienceService.GetSummaryMarkup(entity) ?? ""; if (entity is IMethod) { var method = (IMethod)entity; if (method.IsExtensionMethod) { tooltipInfo.AddCategory(GettextCatalog.GetString("Extension Method from"), method.DeclaringTypeDefinition.FullName); } } int paramIndex = currentParameter; if (entity is IMethod && ((IMethod)entity).IsExtensionMethod) { paramIndex++; } paramIndex = Math.Min(entity.Parameters.Count - 1, paramIndex); var curParameter = paramIndex >= 0 && paramIndex < entity.Parameters.Count ? entity.Parameters [paramIndex] : null; if (curParameter != null) { string docText = AmbienceService.GetDocumentation(entity); if (!string.IsNullOrEmpty(docText)) { string text = docText; Regex paramRegex = new Regex("(\\<param\\s+name\\s*=\\s*\"" + curParameter.Name + "\"\\s*\\>.*?\\</param\\>)", RegexOptions.Compiled); Match match = paramRegex.Match(docText); if (match.Success) { text = AmbienceService.GetDocumentationMarkup(entity, match.Groups [1].Value); if (!string.IsNullOrWhiteSpace(text)) { tooltipInfo.AddCategory(GettextCatalog.GetString("Parameter"), text); } } } if (curParameter.Type.Kind == TypeKind.Delegate) { tooltipInfo.AddCategory(GettextCatalog.GetString("Delegate Info"), sig.GetDelegateInfo(curParameter.Type)); } } return(tooltipInfo); }
internal static (IType returnType, IParameter[] parameters, ModifiedType returnTypeModifier) DecodeSignature( MetadataModule module, IParameterizedMember owner, MethodSignature <IType> signature, ParameterHandleCollection?parameterHandles, Nullability nullableContext, TypeSystemOptions typeSystemOptions, CustomAttributeHandleCollection?returnTypeAttributes = null) { var metadata = module.metadata; int i = 0; IParameter[] parameters = new IParameter[signature.RequiredParameterCount + (signature.Header.CallingConvention == SignatureCallingConvention.VarArgs ? 1 : 0)]; IType parameterType; if (parameterHandles != null) { foreach (var parameterHandle in parameterHandles) { var par = metadata.GetParameter(parameterHandle); if (par.SequenceNumber == 0) { // "parameter" holds return type attributes. // Note: for properties, the attributes normally stored on a method's return type // are instead stored as normal attributes on the property. // So MetadataProperty provides a non-null value for returnTypeAttributes, // which then should be preferred over the attributes on the accessor's parameters. if (returnTypeAttributes == null) { returnTypeAttributes = par.GetCustomAttributes(); } } else if (par.SequenceNumber > 0 && i < signature.RequiredParameterCount) { // "Successive rows of the Param table that are owned by the same method shall be // ordered by increasing Sequence value - although gaps in the sequence are allowed" Debug.Assert(i < par.SequenceNumber); // Fill gaps in the sequence with non-metadata parameters: while (i < par.SequenceNumber - 1) { parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType( signature.ParameterTypes[i], module.Compilation, null, metadata, typeSystemOptions, nullableContext); parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner, referenceKind: parameterType.Kind == TypeKind.ByReference ? ReferenceKind.Ref : ReferenceKind.None); i++; } parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType( signature.ParameterTypes[i], module.Compilation, par.GetCustomAttributes(), metadata, typeSystemOptions, nullableContext); parameters[i] = new MetadataParameter(module, owner, parameterType, parameterHandle); i++; } } } while (i < signature.RequiredParameterCount) { parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType( signature.ParameterTypes[i], module.Compilation, null, metadata, typeSystemOptions, nullableContext); parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner, referenceKind: parameterType.Kind == TypeKind.ByReference ? ReferenceKind.Ref : ReferenceKind.None); i++; } if (signature.Header.CallingConvention == SignatureCallingConvention.VarArgs) { parameters[i] = new DefaultParameter(SpecialType.ArgList, name: string.Empty, owner); i++; } Debug.Assert(i == parameters.Length); var returnType = ApplyAttributeTypeVisitor.ApplyAttributesToType(signature.ReturnType, module.Compilation, returnTypeAttributes, metadata, typeSystemOptions, nullableContext, isSignatureReturnType: true); return(returnType, parameters, signature.ReturnType as ModifiedType); }
private bool IsStringConcat(IParameterizedMember member) { return(member is IMethod method && method.Name == "Concat" && method.DeclaringType.IsKnownType(KnownTypeCode.String)); }
public ResolveResult ResolveNode(AstNode node, ILog log) { var syntaxTree = node.GetParent <SyntaxTree>(); this.InitResolver(syntaxTree); var result = this.resolver.Resolve(node); if (result is MethodGroupResolveResult && node.Parent != null) { var methodGroupResolveResult = (MethodGroupResolveResult)result; var parentResolveResult = this.ResolveNode(node.Parent, log); var parentInvocation = parentResolveResult as InvocationResolveResult; IParameterizedMember method = methodGroupResolveResult.Methods.LastOrDefault(); bool isInvocation = node.Parent is InvocationExpression && (((InvocationExpression)(node.Parent)).Target == node); if (node is Expression) { var conversion = this.Resolver.GetConversion((Expression)node); if (conversion != null && conversion.IsMethodGroupConversion) { return(new MemberResolveResult(new TypeResolveResult(conversion.Method.DeclaringType), conversion.Method)); } } if (isInvocation && parentInvocation != null) { var or = methodGroupResolveResult.PerformOverloadResolution(this.compilation, parentInvocation.GetArgumentsForCall().ToArray()); if (or.FoundApplicableCandidate) { method = or.BestCandidate; return(new MemberResolveResult(new TypeResolveResult(method.DeclaringType), method)); } } if (parentInvocation != null && method == null) { var typeDef = methodGroupResolveResult.TargetType as DefaultResolvedTypeDefinition; if (typeDef != null) { var methods = typeDef.Methods.Where(m => m.Name == methodGroupResolveResult.MethodName); method = methods.FirstOrDefault(); } } if (method == null) { var extMethods = methodGroupResolveResult.GetEligibleExtensionMethods(false); if (!extMethods.Any()) { extMethods = methodGroupResolveResult.GetExtensionMethods(); } if (!extMethods.Any() || !extMethods.First().Any()) { throw new EmitterException(node, "Cannot find method defintion"); } method = extMethods.First().First(); } if (parentInvocation == null || method.FullName != parentInvocation.Member.FullName) { MemberResolveResult memberResolveResult = new MemberResolveResult(new TypeResolveResult(method.DeclaringType), method); return(memberResolveResult); } return(parentResolveResult); } if ((result == null || result.IsError) && log != null) { if (result is CSharpInvocationResolveResult && ((CSharpInvocationResolveResult)result).OverloadResolutionErrors != OverloadResolutionErrors.None) { return(result); } log.LogWarning(string.Format("Node resolving has failed {0}: {1}", node.StartLocation, node.ToString())); } return(result); }
/// <summary> /// Adds a candidate to overload resolution. /// </summary> /// <param name="member">The candidate member to add.</param> /// <returns>The errors that prevent the member from being applicable, if any. /// Note: this method does not return errors that do not affect applicability.</returns> public OverloadResolutionErrors AddCandidate(IParameterizedMember member) { return(AddCandidate(member, OverloadResolutionErrors.None)); }
public CSharpInsightItem(IParameterizedMember method) { this.Method = method; }
public static TooltipInformation CreateTooltipInformation (CSharpCompletionTextEditorExtension ext, ICompilation compilation, CSharpUnresolvedFile file, IParameterizedMember entity, int currentParameter, bool smartWrap) { return CreateTooltipInformation (compilation, file, ext.TextEditorData, ext.FormattingPolicy, entity, currentParameter, smartWrap); }
public string GetString(IParameterizedMember member, IParameter parameter, OutputFlags flags) { return(GetParameterString(member, parameter, new OutputSettings(flags))); }
public Candidate(IParameterizedMember member, bool isExpanded) { this.Member = member; this.IsExpandedForm = isExpanded; this.ParameterTypes = new IType[member.Parameters.Count]; }
internal static (IType, IParameter[]) DecodeSignature(MetadataModule module, IParameterizedMember owner, MethodSignature <IType> signature, ParameterHandleCollection?parameterHandles) { var metadata = module.metadata; int i = 0; CustomAttributeHandleCollection?returnTypeAttributes = null; IParameter[] parameters = new IParameter[signature.RequiredParameterCount + (signature.Header.CallingConvention == SignatureCallingConvention.VarArgs ? 1 : 0)]; IType parameterType; if (parameterHandles != null) { foreach (var parameterHandle in parameterHandles) { var par = metadata.GetParameter(parameterHandle); if (par.SequenceNumber == 0) { // "parameter" holds return type attributes returnTypeAttributes = par.GetCustomAttributes(); } else if (par.SequenceNumber > 0 && i < signature.RequiredParameterCount) { // "Successive rows of the Param table that are owned by the same method shall be // ordered by increasing Sequence value - although gaps in the sequence are allowed" Debug.Assert(i < par.SequenceNumber); // Fill gaps in the sequence with non-metadata parameters: while (i < par.SequenceNumber - 1) { parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType( signature.ParameterTypes[i], module.Compilation, null, metadata, module.TypeSystemOptions); parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner, isRef: parameterType.Kind == TypeKind.ByReference); i++; } parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType( signature.ParameterTypes[i], module.Compilation, par.GetCustomAttributes(), metadata, module.TypeSystemOptions); parameters[i] = new MetadataParameter(module, owner, parameterType, parameterHandle); i++; } } } while (i < signature.RequiredParameterCount) { parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType( signature.ParameterTypes[i], module.Compilation, null, metadata, module.TypeSystemOptions); parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner, isRef: parameterType.Kind == TypeKind.ByReference); i++; } if (signature.Header.CallingConvention == SignatureCallingConvention.VarArgs) { parameters[i] = new DefaultParameter(SpecialType.ArgList, name: string.Empty, owner); i++; } Debug.Assert(i == parameters.Length); bool isRefReadonly = false; if (signature.ReturnType.Kind == TypeKind.ModReq && signature.ReturnType.SkipModifiers().Kind == TypeKind.ByReference) { isRefReadonly = ((ModifiedType)signature.ReturnType).Modifier.IsKnownType(KnownAttribute.In); } var returnType = ApplyAttributeTypeVisitor.ApplyAttributesToType(signature.ReturnType, module.Compilation, returnTypeAttributes, metadata, module.TypeSystemOptions); return(returnType, parameters); }
public string GetString (IParameterizedMember member, IParameter parameter, OutputFlags flags) { return GetParameterString (member, parameter, new OutputSettings (flags)); }
public OverloadResolutionErrors AddCandidate(IParameterizedMember member) { return AddCandidate(member, OverloadResolutionErrors.None); }
public IParameter ReadParameter(ParameterDefinition parameter, IParameterizedMember parentMember = null) { if (parameter == null) throw new ArgumentNullException("parameter"); var type = ReadTypeReference(parameter.ParameterType, typeAttributes: parameter, entity: parentMember); DefaultParameter p = new DefaultParameter(type, parameter.Name); if (parameter.ParameterType is Mono.Cecil.ByReferenceType) { if (!parameter.IsIn && parameter.IsOut) p.IsOut = true; else p.IsRef = true; } AddAttributes(parameter, p); if (parameter.IsOptional) { p.DefaultValue = ReadConstantValue(new CustomAttributeArgument(parameter.ParameterType, parameter.Constant)); } if (parameter.ParameterType is Mono.Cecil.ArrayType) { foreach (CustomAttribute att in parameter.CustomAttributes) { if (att.AttributeType.FullName == typeof(ParamArrayAttribute).FullName) { p.IsParams = true; break; } } } return p; }
internal void LogCandidateAddingResult(string text, IParameterizedMember method, OverloadResolutionErrors errors) { #if DEBUG Log.WriteLine(string.Format("{0} {1} = {2}{3}", text, method, errors == OverloadResolutionErrors.None ? "Success" : errors.ToString(), this.BestCandidate == method ? " (best candidate so far)" : this.BestCandidateAmbiguousWith == method ? " (ambiguous)" : "" )); #endif }
public CSharpInsightItem(IParameterizedMember method) { this.Method = method; }
protected SpecializedParameterizedMember(IParameterizedMember memberDefinition) : base(memberDefinition) { }
static bool MatchParameters (IParameterizedMember a, IParameterizedMember b) { if (a == null && b == null) return true; if (a == null || b == null) return false; return ParameterListComparer.Instance.Equals (a.Parameters, b.Parameters); }
protected abstract string GetParameterString(IParameterizedMember member, IParameter parameter, OutputSettings settings);
public OverloadResolutionErrors AddCandidate(IParameterizedMember member, OverloadResolutionErrors additionalErrors) { if (member == null) throw new ArgumentNullException("member"); Candidate c = new Candidate(member, false); if (additionalErrors != OverloadResolutionErrors.None) c.AddError(additionalErrors); if (CalculateCandidate(c)) { //candidates.Add(c); } if (this.AllowExpandingParams && member.Parameters.Count > 0 && member.Parameters[member.Parameters.Count - 1].IsParams) { Candidate expandedCandidate = new Candidate(member, true); if (additionalErrors != OverloadResolutionErrors.None) expandedCandidate.AddError(additionalErrors); // consider expanded form only if it isn't obviously wrong if (CalculateCandidate(expandedCandidate)) { //candidates.Add(expandedCandidate); if (expandedCandidate.ErrorCount < c.ErrorCount) return expandedCandidate.Errors; } } return c.Errors; }
protected override string GetParameterString (IParameterizedMember member, IParameter parameter, OutputSettings settings) { if (parameter == null) return ""; var result = new StringBuilder (); if (settings.IncludeParameterName) { if (settings.IncludeModifiers) { if (parameter.IsOut) { result.Append (settings.EmitKeyword ("out")); } if (parameter.IsRef) { result.Append (settings.EmitKeyword ("ref")); } if (parameter.IsParams) { result.Append (settings.EmitKeyword ("params")); } } result.Append (GetTypeReferenceString (parameter.Type, settings)); result.Append (" "); if (settings.HighlightName) { result.Append (settings.EmitName (parameter, settings.Highlight (Format (FilterName (parameter.Name))))); } else { result.Append (settings.EmitName (parameter, Format (FilterName (parameter.Name)))); } } else { result.Append (GetTypeReferenceString (parameter.Type, settings)); } return result.ToString (); }
public Candidate(IParameterizedMember member, bool isExpanded) { this.Member = member; this.IsExpandedForm = isExpanded; IMethod method = member as IMethod; if (method != null && method.TypeParameters.Count > 0) { // For generic methods, go back to the original parameters // (without any type parameter substitution, not even class type parameters) // We'll re-substitute them as part of RunTypeInference(). method = (IMethod)method.MemberDefinition; this.Parameters = method.Parameters; this.TypeParameters = method.TypeParameters; } else { this.Parameters = member.Parameters; } this.ParameterTypes = new IType[this.Parameters.Count]; }
public NamedArgumentResolveResult(IParameter parameter, ResolveResult argument, IParameterizedMember member = null) : base(argument.Type) { if (parameter == null) { throw new ArgumentNullException("parameter"); } if (argument == null) { throw new ArgumentNullException("argument"); } this.Member = member; this.Parameter = parameter; this.ParameterName = parameter.Name; this.Argument = argument; }
/// <summary> /// Gets the ID string (C# 4.0 spec, §A.3.1) for the specified entity. /// </summary> /// <remarks> /// The type resolve context is optional and is not needed for entities loaded from assemblies: /// This method can get the ID string for any type reference produced by the CecilLoader without /// having to resolve the type reference. /// </remarks> public static string GetIDString(IEntity entity, ITypeResolveContext context = null) { StringBuilder b = new StringBuilder(); switch (entity.EntityType) { case EntityType.TypeDefinition: b.Append("T:"); AppendTypeName(b, (ITypeDefinition)entity); return(b.ToString()); case EntityType.Field: b.Append("F:"); break; case EntityType.Property: case EntityType.Indexer: b.Append("P:"); break; case EntityType.Event: b.Append("E:"); break; default: b.Append("M:"); break; } IMember member = (IMember)entity; AppendTypeName(b, member.DeclaringType); b.Append('.'); b.Append(member.Name.Replace('.', '#')); IMethod method = member as IMethod; if (method != null && method.TypeParameters.Count > 0) { b.Append("``"); b.Append(method.TypeParameters.Count); } IParameterizedMember parameterizedMember = member as IParameterizedMember; if (parameterizedMember != null && parameterizedMember.Parameters.Count > 0) { b.Append('('); var parameters = parameterizedMember.Parameters; for (int i = 0; i < parameters.Count; i++) { if (i > 0) { b.Append(','); } AppendTypeName(b, parameters[i].Type, context); } b.Append(')'); } if (member.EntityType == EntityType.Operator && (member.Name == "op_Implicit" || member.Name == "op_Explicit")) { b.Append('~'); AppendTypeName(b, member.ReturnType, context); } return(b.ToString()); }
public InvocationResolveResult(ResolveResult targetResult, IParameterizedMember member, IList <ResolveResult> arguments) : base(targetResult, member) { this.Arguments = arguments ?? EmptyList <ResolveResult> .Instance; }
protected SpecializedParameterizedMember(IType declaringType, IParameterizedMember memberDefinition) : base(declaringType, memberDefinition) { }
IList <ResolveResult> GetArgumentsWithConversions(ResolveResult targetResolveResult, IParameterizedMember bestCandidateForNamedArguments) { var conversions = this.ArgumentConversions; ResolveResult[] args = new ResolveResult[arguments.Length]; for (int i = 0; i < args.Length; i++) { var argument = arguments[i]; if (this.IsExtensionMethodInvocation && i == 0 && targetResolveResult != null) { argument = targetResolveResult; } int parameterIndex = bestCandidate.ArgumentToParameterMap[i]; if (parameterIndex >= 0 && conversions[i] != Conversion.IdentityConversion) { // Wrap argument in ConversionResolveResult IType parameterType = bestCandidate.ParameterTypes[parameterIndex]; if (parameterType.Kind != TypeKind.Unknown) { if (arguments[i].IsCompileTimeConstant && conversions[i] != Conversion.None) { argument = new CSharpResolver(compilation).WithCheckForOverflow(CheckForOverflow).ResolveCast(parameterType, argument); } else { argument = new ConversionResolveResult(parameterType, argument, conversions[i], CheckForOverflow); } } } if (bestCandidateForNamedArguments != null && argumentNames[i] != null) { // Wrap argument in NamedArgumentResolveResult if (parameterIndex >= 0) { argument = new NamedArgumentResolveResult(bestCandidateForNamedArguments.Parameters[parameterIndex], argument, bestCandidateForNamedArguments); } else { argument = new NamedArgumentResolveResult(argumentNames[i], argument); } } args[i] = argument; } return(args); }
public LiftedUserDefinedOperator(IMethod nonLiftedMethod) : base(nonLiftedMethod.DeclaringType, (IMethod)nonLiftedMethod.MemberDefinition, EmptyList<IType>.Instance, new MakeNullableVisitor(nonLiftedMethod.Compilation)) { this.nonLiftedOperator = nonLiftedMethod; }
public NamedArgument(IParameter parameter, Expression argument, IParameterizedMember member = null) : this(parameter.Name, Location.Null, argument) { this.Member = member; this.Parameter = parameter; }