Esempio n. 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());
        }
Esempio n. 2
0
        public virtual void Emit(EmitContext context)
        {
            EmitContext.MethodLinkage linkage = context.GetMethodLinkage(this, false);

            context.Module.AddCommentTag("");
            context.Module.AddCommentTag(RoslynSymbol.ToDisplayString().Replace("\n", "").Replace("\r", ""));
            context.Module.AddCommentTag("");
            context.Module.LabelJump(linkage.MethodLabel);

            using (context.OpenBlockScope())
            {
                if (MethodBody is BoundExpression bodyExpression)
                {
                    context.EmitReturn(bodyExpression);
                }
                else
                {
                    context.Emit(MethodBody);
                    context.EmitReturn();
                }

                context.FlattenTableCounters();
            }
        }
Esempio n. 3
0
 // This may get more descriptive info in the future
 public override string ToString()
 {
     return(RoslynSymbol.ToString());
 }
Esempio n. 4
0
 protected bool Equals(Symbol other)
 {
     return(RoslynSymbol.Equals(other.RoslynSymbol));
 }
Esempio n. 5
0
 // UdonSharp symbols will always have a Roslyn analogue symbol that refers to exactly the same data, the only difference is that UdonSharp symbols will annotate more information and track dependencies more explicitly
 // So we just use the root symbol hash code and equals here
 // This is not needed most of the time since you must retrieve the symbols from the Roslyn symbols in most contexts that matter for comparison. The retrieval mechanisms already guarantee that there is one UdonSharp symbol for a given Roslyn symbol
 public override int GetHashCode()
 {
     return(RoslynSymbol.GetHashCode());
 }