Beispiel #1
0
        protected void SetupAttributes(BindContext context)
        {
            var attribData = RoslynSymbol.GetAttributes();
            List <Attribute> attributes = new List <Attribute>();

            for (int i = 0; i < attribData.Length; ++i)
            {
                AttributeData attribute = attribData[i];

                // Skip marking attributes as referenced types by using the bind context
                TypeSymbol type = context.CompileContext.GetTypeSymbol(attribute.AttributeClass, context);

                if (!type.IsExtern)
                {
                    continue;
                }

                object[] attributeArgs = new object[attribute.ConstructorArguments.Length];

                for (int j = 0; j < attributeArgs.Length; ++j)
                {
                    object attribValue;

                    var constructorArg = attribute.ConstructorArguments[j];

                    if (constructorArg.Type != null &&
                        constructorArg.Type.TypeKind == TypeKind.Enum)
                    {
                        TypeSymbol typeSymbol = context.GetTypeSymbol(constructorArg.Type);
                        attribValue = Enum.ToObject(typeSymbol.UdonType.SystemType, constructorArg.Value);
                    }
                    else if (constructorArg.Value is ITypeSymbol typeSymbol)
                    {
                        attribValue = context.GetTypeSymbol(typeSymbol).UdonType.SystemType;
                    }
                    else
                    {
                        attribValue = attribute.ConstructorArguments[j].Value;
                    }

                    attributeArgs[j] = attribValue;
                }

                try
                {
                    if (type.IsExtern)
                    {
                        attributes.Add((Attribute)Activator.CreateInstance(type.UdonType.SystemType, attributeArgs));
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            SetAttributes(attributes.ToImmutableArray());
        }
        public void BuildUdonBehaviourInheritanceLookup(IEnumerable <INamedTypeSymbol> rootTypes)
        {
            Dictionary <TypeSymbol, List <TypeSymbol> > inheritedTypeScratch = new Dictionary <TypeSymbol, List <TypeSymbol> >();

            TypeSymbol udonSharpBehaviourType = null;

            foreach (INamedTypeSymbol typeSymbol in rootTypes)
            {
                BindContext bindContext = new BindContext(this, typeSymbol, null);
                if (udonSharpBehaviourType == null)
                {
                    udonSharpBehaviourType = bindContext.GetTypeSymbol(typeof(UdonSharpBehaviour));
                }

                TypeSymbol rootTypeSymbol = bindContext.GetTypeSymbol(typeSymbol);

                TypeSymbol baseType = rootTypeSymbol.BaseType;

                while (baseType != udonSharpBehaviourType)
                {
                    if (!inheritedTypeScratch.TryGetValue(baseType, out List <TypeSymbol> inheritedTypeList))
                    {
                        inheritedTypeList = new List <TypeSymbol>();
                        inheritedTypeScratch.Add(baseType, inheritedTypeList);
                    }

                    inheritedTypeList.Add(rootTypeSymbol);

                    baseType = baseType.BaseType;
                }
            }

            _inheritedTypes = new Dictionary <TypeSymbol, ImmutableArray <TypeSymbol> >();

            foreach (var typeLists in inheritedTypeScratch)
            {
                _inheritedTypes.Add(typeLists.Key, typeLists.Value.ToImmutableArray());
            }
        }
Beispiel #3
0
        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;
        }
Beispiel #4
0
 public override void Bind(BindContext context)
 {
     Type             = context.GetTypeSymbol(RoslynSymbol.Type);
     ContainingSymbol = (MethodSymbol)context.GetSymbol(RoslynSymbol.ContainingSymbol);
 }