public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) { IReturnType type = ResolveType(unaryOperatorExpression.Expression); if (type == null) { return(null); } switch (unaryOperatorExpression.Op) { case UnaryOperatorType.AddressOf: return(CreateResolveResult(new PointerReturnType(type))); case UnaryOperatorType.Dereference: PointerReturnType prt = type.CastToDecoratingReturnType <PointerReturnType>(); if (prt != null) { return(CreateResolveResult(prt.BaseType)); } else { return(null); } default: return(CreateResolveResult(type)); } }
public void PointerTypeTest() { IClass c = mscorlib.GetClass("System.IntPtr", 1); IMethod toPointer = c.Methods.First(p => p.Name == "ToPointer"); Assert.AreEqual("System.Void*", toPointer.ReturnType.DotNetName); PointerReturnType prt = toPointer.ReturnType.CastToDecoratingReturnType <PointerReturnType>(); Assert.AreEqual("System.Void", prt.BaseType.FullyQualifiedName); }
protected override ResolveResult Resolve(ExpressionResult expressionResult, int caretLineNumber, int caretColumn, string fileName, string fileContent) { ResolveResult rr = base.Resolve(expressionResult, caretLineNumber, caretColumn, fileName, fileContent); if (rr != null && rr.ResolvedType != null) { PointerReturnType prt = rr.ResolvedType.CastToDecoratingReturnType <PointerReturnType>(); if (prt != null) { return(new ResolveResult(rr.CallingClass, rr.CallingMember, prt.BaseType)); } } return(null); }
public override ResolveResult Resolve(ITextEditor editor, ExpressionResult expressionResult) { ResolveResult rr = base.Resolve(editor, expressionResult); if (rr != null && rr.ResolvedType != null) { PointerReturnType prt = rr.ResolvedType.CastToDecoratingReturnType <PointerReturnType>(); if (prt != null) { return(new ResolveResult(rr.CallingClass, rr.CallingMember, prt.BaseType)); } } return(null); }
public override object VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data) { ResolveResult targetRR = Resolve(pointerReferenceExpression.TargetObject); if (targetRR == null || targetRR.ResolvedType == null) { return(null); } PointerReturnType type = targetRR.ResolvedType.CastToDecoratingReturnType <PointerReturnType>(); if (type != null) { return(resolver.ResolveMember(type.BaseType, pointerReferenceExpression.MemberName, pointerReferenceExpression.TypeArguments, NRefactoryResolver.IsInvoked(pointerReferenceExpression), true, null )); } return(null); }
public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) { IReturnType type = ResolveType(unaryOperatorExpression.Expression); if (type == null) { return(null); } switch (unaryOperatorExpression.Op) { case UnaryOperatorType.AddressOf: return(CreateResolveResult(new PointerReturnType(type))); case UnaryOperatorType.Dereference: PointerReturnType prt = type.CastToDecoratingReturnType <PointerReturnType>(); if (prt != null) { return(CreateResolveResult(prt.BaseType)); } else { return(null); } case UnaryOperatorType.Await: var crt = type.CastToConstructedReturnType(); if (crt != null && crt.Name == "Task" && crt.TypeArguments.Count == 1) { return(CreateResolveResult(crt.TypeArguments[0])); } else { return(null); } default: return(CreateResolveResult(type)); } }
public static TypeReference ConvertType(IReturnType returnType, ClassFinder context) { if (returnType == null) { return(TypeReference.Null); } if (returnType is NullReturnType) { return(TypeReference.Null); } ArrayReturnType arrayReturnType = returnType.CastToArrayReturnType(); if (arrayReturnType != null) { TypeReference typeRef = ConvertType(arrayReturnType.ArrayElementType, context); int[] rank = typeRef.RankSpecifier ?? new int[0]; Array.Resize(ref rank, rank.Length + 1); rank[rank.Length - 1] = arrayReturnType.ArrayDimensions - 1; typeRef.RankSpecifier = rank; return(typeRef); } PointerReturnType pointerReturnType = returnType.CastToDecoratingReturnType <PointerReturnType>(); if (pointerReturnType != null) { TypeReference typeRef = ConvertType(pointerReturnType.BaseType, context); typeRef.PointerNestingLevel++; return(typeRef); } IList <IReturnType> typeArguments = EmptyList <IReturnType> .Instance; if (returnType.IsConstructedReturnType) { typeArguments = returnType.CastToConstructedReturnType().TypeArguments; } IClass c = returnType.GetUnderlyingClass(); if (c != null) { return(CreateTypeReference(c, typeArguments, context)); } else { TypeReference typeRef; if (IsPrimitiveType(returnType)) { typeRef = new TypeReference(returnType.FullyQualifiedName, true); } else if (context != null && CanUseShortTypeName(returnType, context)) { typeRef = new TypeReference(returnType.Name); } else { string fullName = returnType.FullyQualifiedName; if (string.IsNullOrEmpty(fullName)) { fullName = returnType.Name; } typeRef = new TypeReference(fullName); } foreach (IReturnType typeArgument in typeArguments) { typeRef.GenericTypes.Add(ConvertType(typeArgument, context)); } return(typeRef); } }
public static IReturnType CreateReturnType(TypeReference reference, IClass callingClass, IMember callingMember, int caretLine, int caretColumn, IProjectContent projectContent, ReturnTypeOptions options) { if (reference == null) return null; if (reference.IsNull) return null; if (reference is InnerClassTypeReference) { reference = ((InnerClassTypeReference)reference).CombineToNormalTypeReference(); } bool useLazyReturnType = (options & ReturnTypeOptions.Lazy) == ReturnTypeOptions.Lazy; bool isBaseTypeReference = (options & ReturnTypeOptions.BaseTypeReference) == ReturnTypeOptions.BaseTypeReference; LanguageProperties languageProperties = projectContent.Language; IReturnType t = null; if (callingClass != null && !reference.IsGlobal) { foreach (ITypeParameter tp in callingClass.TypeParameters) { if (languageProperties.NameComparer.Equals(tp.Name, reference.Type)) { t = new GenericReturnType(tp); break; } } IMethod callingMethod = callingMember as IMethod; if (t == null && callingMethod != null) { foreach (ITypeParameter tp in callingMethod.TypeParameters) { if (languageProperties.NameComparer.Equals(tp.Name, reference.Type)) { t = new GenericReturnType(tp); break; } } } } if (t == null) { int typeParameterCount = reference.GenericTypes.Count; if (reference.IsKeyword) { // keyword-type like void, int, string etc. IClass c = projectContent.GetClass(reference.Type, typeParameterCount); if (c != null) t = c.DefaultReturnType; else t = new GetClassReturnType(projectContent, reference.Type, typeParameterCount); } else { if (useLazyReturnType || isBaseTypeReference) { if (reference.IsGlobal) { t = new GetClassReturnType(projectContent, reference.Type, typeParameterCount); } else if (callingClass != null) { SearchClassReturnType scrt = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn, reference.Type, typeParameterCount); if (isBaseTypeReference) scrt.LookForInnerClassesInDeclaringClass = false; t = scrt; } } else { IClass c; if (reference.IsGlobal) { c = projectContent.GetClass(reference.Type, typeParameterCount); t = (c != null) ? c.DefaultReturnType : null; } else if (callingClass != null) { t = projectContent.SearchType(new SearchTypeRequest(reference.Type, typeParameterCount, callingClass, caretLine, caretColumn)).Result; } if (t == null) { return null; } } } } if (reference.GenericTypes.Count > 0) { IReturnType[] para = new IReturnType[reference.GenericTypes.Count]; for (int i = 0; i < reference.GenericTypes.Count; ++i) { para[i] = CreateReturnType(reference.GenericTypes[i], callingClass, callingMember, caretLine, caretColumn, projectContent, options); } t = new ConstructedReturnType(t, para); } for (int i = 0; i < reference.PointerNestingLevel; i++) { t = new PointerReturnType(t); } return WrapArray(projectContent, t, reference); }
public static IReturnType CreateReturnType(TypeReference reference, IClass callingClass, IMember callingMember, int caretLine, int caretColumn, IProjectContent projectContent, ReturnTypeOptions options) { if (reference == null) { return(null); } if (reference.IsNull) { return(null); } if (reference is InnerClassTypeReference) { reference = ((InnerClassTypeReference)reference).CombineToNormalTypeReference(); } bool useLazyReturnType = (options & ReturnTypeOptions.Lazy) == ReturnTypeOptions.Lazy; bool isBaseTypeReference = (options & ReturnTypeOptions.BaseTypeReference) == ReturnTypeOptions.BaseTypeReference; LanguageProperties languageProperties = projectContent.Language; IReturnType t = null; if (callingClass != null && !reference.IsGlobal) { foreach (ITypeParameter tp in callingClass.TypeParameters) { if (languageProperties.NameComparer.Equals(tp.Name, reference.Type)) { t = new GenericReturnType(tp); break; } } IMethod callingMethod = callingMember as IMethod; if (t == null && callingMethod != null) { foreach (ITypeParameter tp in callingMethod.TypeParameters) { if (languageProperties.NameComparer.Equals(tp.Name, reference.Type)) { t = new GenericReturnType(tp); break; } } } } if (t == null && reference.Type == "dynamic") { t = new DynamicReturnType(projectContent); } if (t == null) { int typeParameterCount = reference.GenericTypes.Count; if (reference.IsKeyword) { // keyword-type like void, int, string etc. IClass c = projectContent.GetClass(reference.Type, typeParameterCount); if (c != null) { t = c.DefaultReturnType; } else { t = new GetClassReturnType(projectContent, reference.Type, typeParameterCount); } } else { if (useLazyReturnType || isBaseTypeReference) { if (reference.IsGlobal) { t = new GetClassReturnType(projectContent, reference.Type, typeParameterCount); } else if (callingClass != null) { SearchClassReturnType scrt = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn, reference.Type, typeParameterCount); if (isBaseTypeReference) { scrt.LookForInnerClassesInDeclaringClass = false; } t = scrt; } } else { IClass c; if (reference.IsGlobal) { c = projectContent.GetClass(reference.Type, typeParameterCount); t = (c != null) ? c.DefaultReturnType : null; } else if (callingClass != null) { t = projectContent.SearchType(new SearchTypeRequest(reference.Type, typeParameterCount, callingClass, caretLine, caretColumn)).Result; } if (t == null) { return(null); } } } } if (reference.GenericTypes.Count > 0) { IReturnType[] para = new IReturnType[reference.GenericTypes.Count]; for (int i = 0; i < reference.GenericTypes.Count; ++i) { para[i] = CreateReturnType(reference.GenericTypes[i], callingClass, callingMember, caretLine, caretColumn, projectContent, options); } t = new ConstructedReturnType(t, para); } for (int i = 0; i < reference.PointerNestingLevel; i++) { t = new PointerReturnType(t); } return(WrapArray(projectContent, t, reference)); }