public VirtualMethodBasedMethodMock(MocklisTypesForSymbols typesForSymbols, INamedTypeSymbol classSymbol, INamedTypeSymbol interfaceSymbol, IMethodSymbol symbol, string mockMemberName) : base(typesForSymbols.WithSubstitutions(classSymbol, symbol), classSymbol, interfaceSymbol, symbol, mockMemberName) { if (symbol.ReturnsByRef) { RefTypeSyntax tmp = F.RefType(typesForSymbols.ParseTypeName(symbol.ReturnType, symbol.ReturnTypeIsNullableOrOblivious())); ReturnType = tmp; ReturnTypeWithoutReadonly = tmp; } else if (symbol.ReturnsByRefReadonly) { RefTypeSyntax tmp = F.RefType(typesForSymbols.ParseTypeName(symbol.ReturnType, symbol.ReturnTypeIsNullableOrOblivious())); ReturnType = tmp.WithReadOnlyKeyword(F.Token(SyntaxKind.ReadOnlyKeyword)); ReturnTypeWithoutReadonly = tmp; } else if (symbol.ReturnsVoid) { ReturnType = F.PredefinedType(F.Token(SyntaxKind.VoidKeyword)); ReturnTypeWithoutReadonly = ReturnType; } else { ReturnType = typesForSymbols.ParseTypeName(symbol.ReturnType, symbol.ReturnTypeIsNullableOrOblivious()); ReturnTypeWithoutReadonly = ReturnType; } ArglistParameterName = FindArglistParameterName(symbol); }
public static TypeSyntax Create(System.Type type) { if (type is null) { return(null); } TypeSyntax value; if (type.IsArray) { value = new ArrayTypeSyntax(Create(type.GetElementType()), type.GetArrayRank()); } else if (type.IsGenericType) { var types = type.GetGenericArguments(); NodeList <TypeSyntax> typeNodes = new NodeList <TypeSyntax>(types.Length); foreach (var arg in types) { typeNodes.Add(Create(arg)); } value = new RefTypeSyntax(type.FullName, typeNodes); } else { value = new RefTypeSyntax(type.FullName); } value.Type = type; return(value); }
public override void VisitRefType(RefTypeSyntax node) { Information.Add(InfoExtractor.Info.TYPE, node); node.Type?.Accept(this); base.VisitRefType(node); }
public static Doc Print(RefTypeSyntax node) { return(Doc.Concat( Token.PrintWithSuffix(node.RefKeyword, " "), Token.PrintWithSuffix(node.ReadOnlyKeyword, " "), Node.Print(node.Type) )); }
private Doc PrintRefTypeSyntax(RefTypeSyntax node) { return(Concat( this.PrintSyntaxToken(node.RefKeyword, " "), this.PrintSyntaxToken(node.ReadOnlyKeyword, " "), this.Print(node.Type) )); }
public override void VisitRefType(RefTypeSyntax node) { if (!PreVisit(node)) { return; } node.Type?.Accept(this); base.VisitRefType(node); PostVisit(node); }
public ParameterDefinition CreateParameterFromSyntax(ParameterSyntax parameterSyntax) { var name = parameterSyntax.Identifier.ValueText; var returnType = parameterSyntax.Type switch { PredefinedTypeSyntax predefinedType => predefinedType.Keyword.ValueText, RefTypeSyntax typeDeclaration => typeDeclaration.RefKeyword.ValueText, _ => throw new NotSupportedException(parameterSyntax.Type?.GetType() + " is not yet implemented") }; var attributes = parameterSyntax.AttributeLists.SelectMany(l => l.Attributes.Select(_attributeDefinitionFactory.CreateAttributeFromSyntax)); return(new ParameterDefinition(name, returnType, attributes.ToArray())); } }
public VirtualMethodBasedIndexerMock(MocklisTypesForSymbols typesForSymbols, INamedTypeSymbol classSymbol, INamedTypeSymbol interfaceSymbol, IPropertySymbol symbol, string mockMemberName) : base(typesForSymbols, classSymbol, interfaceSymbol, symbol, mockMemberName) { ValueTypeSyntax = typesForSymbols.ParseTypeName(symbol.Type, symbol.NullableOrOblivious()); ValueWithReadonlyTypeSyntax = ValueTypeSyntax; if (Symbol.ReturnsByRef || Symbol.ReturnsByRefReadonly) { RefTypeSyntax tmp = F.RefType(ValueTypeSyntax); ValueTypeSyntax = tmp; ValueWithReadonlyTypeSyntax = tmp; if (Symbol.ReturnsByRefReadonly) { ValueWithReadonlyTypeSyntax = tmp.WithReadOnlyKeyword(F.Token(SyntaxKind.ReadOnlyKeyword)); } } }
public static TRoot ReplaceAndTrackType <TRoot>(this TRoot node, TypeSyntax targetType, SyntaxNode sourceType, SemanticModel semanticModel, ICollection <INamedTypeSymbol> discoveredTypes) where TRoot : SyntaxNode { // Skip immediately for function pointers if (sourceType is FunctionPointerTypeSyntax) { return(node.ReplaceNode(targetType, ParseTypeName("void*"))); } // Handle the various possible type kinds ITypeSymbol typeSymbol = sourceType switch { RefTypeSyntax refType => semanticModel.GetTypeInfo(refType.Type).Type !, PointerTypeSyntax pointerType => semanticModel.GetTypeInfo(pointerType.ElementType).Type !, _ => semanticModel.GetTypeInfo(sourceType).Type ! }; // Do nothing if the type is just void if (typeSymbol.SpecialType == SpecialType.System_Void) { return(node); } string typeName = typeSymbol.ToDisplayString(ISymbolExtensions.FullyQualifiedWithoutGlobalFormat); discoveredTypes.Add((INamedTypeSymbol)typeSymbol); if (HlslKnownTypes.TryGetMappedName(typeName, out string?mappedName)) { TypeSyntax newType = ParseTypeName(mappedName !); return(node.ReplaceNode(targetType, newType)); } return(node.ReplaceNode(targetType, ParseTypeName(typeName.Replace(".", "__")))); }
public override void VisitRefType(RefTypeSyntax node) { }
//public override void VisitRefExpression(RefExpressionSyntax node) //{ // base.VisitRefExpression(node); //} public override void VisitRefType(RefTypeSyntax node) { VisitType(node.Type); //base.VisitRefType(node); }
protected MethodDeclarationSyntax ResolveMethod(IMethodInfo method, bool forceInlining = false) { TypeSyntax returnTypeSytax = ResolveType(method.ReturnValue.Type); if (method.ReturnValue.Kind >= ParameterKind.Ref) { RefTypeSyntax refReturnTypeSyntax = RefType(returnTypeSytax); if (method.ReturnValue.Kind is ParameterKind.RefReadonly) { refReturnTypeSyntax = refReturnTypeSyntax.WithReadOnlyKeyword ( Token(SyntaxKind.ReadOnlyKeyword) ); } returnTypeSytax = refReturnTypeSyntax; } MethodDeclarationSyntax result = MethodDeclaration ( returnType: returnTypeSytax, identifier: Identifier(method.Name) ) .WithParameterList ( ParameterList ( parameters: method.Parameters.ToSyntaxList(param => { ParameterSyntax parameter = Parameter ( Identifier(param.Name) ) .WithType ( type: ResolveType(param.Type) ); SyntaxKind?modifier = param.Kind switch { ParameterKind.In => SyntaxKind.InKeyword, ParameterKind.Out => SyntaxKind.OutKeyword, ParameterKind.Ref => SyntaxKind.RefKeyword, ParameterKind.Params => SyntaxKind.ParamsKeyword, _ => null }; if (modifier is not null) { parameter = parameter.WithModifiers ( TokenList(Token(modifier.Value)) ); } return(parameter); }) ) ); if (method is IGenericMethodInfo genericMethod) { result = result.WithTypeParameterList // kulon legyen kulonben lesz egy ures "<>" ( typeParameterList: TypeParameterList ( parameters: genericMethod .GenericArguments .ToSyntaxList ( type => TypeParameter ( ResolveType(type).ToFullString() ) ) ) ); } // // Interface implementaciokat mindig expliciten deklaraljuk // if (method.DeclaringType.IsInterface) { result = result.WithExplicitInterfaceSpecifier ( explicitInterfaceSpecifier: ExplicitInterfaceSpecifier((NameSyntax)ResolveType(method.DeclaringType)) ); } // // Kulonben a lathatosagnak meg kell egyeznie // else { List <SyntaxKind> modifiers = new(); // lehet tobb is ("internal protected" pl) if (method.AccessModifiers.HasFlag(AccessModifiers.Public)) { modifiers.Add(SyntaxKind.PublicKeyword); } if (method.AccessModifiers.HasFlag(AccessModifiers.Protected)) { modifiers.Add(SyntaxKind.ProtectedKeyword); } if (method.AccessModifiers.HasFlag(AccessModifiers.Internal)) { modifiers.Add(SyntaxKind.InternalKeyword); } if (method.AccessModifiers.HasFlag(AccessModifiers.Private)) // private protected { modifiers.Add(SyntaxKind.PrivateKeyword); } result = result.WithModifiers ( TokenList(modifiers.Convert(Token)) ); } if (forceInlining) { result = result.WithAttributeLists ( attributeLists: ResolveMethodImplAttributeToForceInlining() ); } return(result); }
public override void VisitRefType(RefTypeSyntax node) { Log(node, "Unsupported Syntax !"); }
/// <inheritdoc/> public override SyntaxNode?VisitRefType(RefTypeSyntax node) { Diagnostics.Add(RefType, node); return(base.VisitRefType(node)); }
// // Summary: // Called when the visitor visits a RefTypeSyntax node. public virtual void VisitRefType(RefTypeSyntax node);
// 引用类型 public virtual void VisitRefTypeSyntax(RefTypeSyntax value) { DefaultVisit(value); }
public TameRefTypeSyntax(RefTypeSyntax node) { Node = node; AddChildren(); }
public override void VisitRefType(RefTypeSyntax node) { base.VisitRefType(node); }
public override Evaluation VisitRefType(RefTypeSyntax node) { node.Type?.Accept <Evaluation>(this); return(base.VisitRefType(node)); }
public override void VisitRefType(RefTypeSyntax node) { throw new NotImplementedException(); }
/// <inheritdoc/> public override SyntaxNode?VisitRefType(RefTypeSyntax node) { Context.ReportDiagnostic(RefType, node); return(base.VisitRefType(node)); }