public override void Bind(BindContext context) { if (IsBound) { return; } if (!RoslynSymbol.IsImplicitlyDeclared) { context.CurrentNode = RoslynSymbol.DeclaringSyntaxReferences.First().GetSyntax(); InitializerSyntax = (context.CurrentNode as VariableDeclaratorSyntax)?.Initializer?.Value; } if (!IsExtern && IsStatic && !IsConst) { throw new NotSupportedException("Static fields are not yet supported on user defined types"); } CheckHiddenFields(context); SetupAttributes(context); // Re-get the type symbol to register it as a dependency in the bind context TypeSymbol fieldType = context.GetTypeSymbol(RoslynSymbol.Type); Type fieldSystemType = fieldType.UdonType.SystemType; if (InitializerSyntax != null && (!HasAttribute <CompileInitAttribute>() && fieldSystemType != typeof(VRCUrl) && fieldSystemType != typeof(VRCUrl[]))) { BinderSyntaxVisitor bodyVisitor = new BinderSyntaxVisitor(this, context); InitializerExpression = bodyVisitor.VisitVariableInitializer(InitializerSyntax, fieldType); } _resolved = true; }
public override void Bind(BindContext context) { if (IsBound) { return; } if (!IsUntypedGenericMethod) { foreach (ParameterSymbol param in Parameters) { param.Bind(context); } } if (RoslynSymbol.IsAbstract) { return; } IMethodSymbol methodSymbol = RoslynSymbol; if (methodSymbol.DeclaringSyntaxReferences.IsEmpty) { throw new CompilerException($"Could not find syntax reference for {methodSymbol}"); } SyntaxNode declaringSyntax = methodSymbol.DeclaringSyntaxReferences.First().GetSyntax(); context.CurrentNode = declaringSyntax; CheckHiddenMethods(context); if (OverridenMethod != null) { OverridenMethod.AddOverride(this); } if (methodSymbol.MethodKind != MethodKind.PropertyGet && methodSymbol.MethodKind != MethodKind.PropertySet && ((MethodDeclarationSyntax)methodSymbol.DeclaringSyntaxReferences.First().GetSyntax()).Modifiers.Any(SyntaxKind.PartialKeyword)) { throw new NotSupportedException(LocStr.CE_PartialMethodsNotSupported, methodSymbol.DeclaringSyntaxReferences.FirstOrDefault()); } BinderSyntaxVisitor bodyVisitor = new BinderSyntaxVisitor(this, context); if (declaringSyntax is MethodDeclarationSyntax methodSyntax) { if (methodSyntax.Body != null) { MethodBody = bodyVisitor.Visit(methodSyntax.Body); } else if (methodSyntax.ExpressionBody != null) { MethodBody = bodyVisitor.VisitExpression(methodSyntax.ExpressionBody, ReturnType); } else { throw new CompilerException("No method body or expression body found", methodSyntax.GetLocation()); } } else if (declaringSyntax is AccessorDeclarationSyntax propertySyntax) { if (propertySyntax.Body != null) { MethodBody = bodyVisitor.Visit(propertySyntax.Body); } else if (propertySyntax.ExpressionBody != null) { MethodBody = bodyVisitor.VisitExpression(propertySyntax.ExpressionBody, ReturnType); } else if (methodSymbol.MethodKind == MethodKind.PropertySet) { MethodBody = GeneratePropertyAutoSetter(context, propertySyntax); } else if (methodSymbol.MethodKind == MethodKind.PropertyGet) { MethodBody = GeneratePropertyAutoGetter(context, propertySyntax); } else { throw new CompilerException("No method body or expression body found", propertySyntax.GetLocation()); } } else if (declaringSyntax is ArrowExpressionClauseSyntax arrowExpression) { MethodBody = bodyVisitor.VisitExpression(arrowExpression.Expression, ReturnType); } else { throw new Exception($"Declaring syntax {declaringSyntax.Kind()} was not a method or property"); } SetupAttributes(context); }