Example #1
0
        protected bool GetNativeExternName(IMethodSymbol method, NativeTarget target, out string name)
        {
            var attribute = GetNativeExternAttribute(method, target);

            if (attribute != null)
            {
                var constant = attribute.ConstructorArguments[1];
                if (constant.Value == null)
                {
                    name = method.Name;
                }
                else
                {
                    name = constant.Value.ToString();
                }
                return(true);
            }
            else if (!IsInternalCall(method))
            {
                throw new NotSupportedException("Unsupported extern method invoke: " + method.FullName());
            }

            name = null;
            return(false);
        }
Example #2
0
 protected AttributeData GetCS2XAttribute(ISymbol symbol, NativeTarget target, string attributeTypeName)
 {
     foreach (var attribute in symbol.GetAttributes())
     {
         var type = attribute.AttributeClass;
         if (type.ContainingNamespace.Name == "CS2X" && type.Name == attributeTypeName)
         {
             if (!attribute.ConstructorArguments.Any(x => ((int)x.Value & 1) == (int)target))
             {
                 throw new NotImplementedException($"NativeTarget not set for '{target}': " + symbol.FullName());
             }
             return(attribute);
         }
     }
     return(null);
 }
Example #3
0
        protected bool GetNativeTypeName(ITypeSymbol type, NativeTarget target, out string name)
        {
            if (GetNativeTypeAttribute(type, target, out var attribute))
            {
                var constant = attribute.ConstructorArguments[1];
                if (constant.Value == null)
                {
                    name = type.Name;
                }
                else
                {
                    name = constant.Value.ToString();
                }
                return(true);
            }

            name = null;
            return(false);
        }
Example #4
0
        protected bool GetNativeExternName(IMethodSymbol method, NativeTarget target, out string name)
        {
            if (GetNativeExternAttribute(method, target, out var nativeExternAttribute))
            {
                var constant = nativeExternAttribute.ConstructorArguments[1];
                if (constant.Value == null)
                {
                    name = method.Name;
                }
                else
                {
                    name = constant.Value.ToString();
                }
                return(true);
            }

            name = null;
            return(false);
        }
Example #5
0
 protected bool GetNativeTypeAttribute(ITypeSymbol type, NativeTarget target, out AttributeData attribute)
 {
     return(GetCS2XAttribute(type, target, "NativeTypeAttribute", out attribute));
 }
Example #6
0
 protected bool GetNativeExternAttribute(IMethodSymbol method, NativeTarget target, out AttributeData attribute)
 {
     return(GetCS2XAttribute(method, target, "NativeExternAttribute", out attribute));
 }
Example #7
0
 protected AttributeData GetNativeTypeAttribute(ITypeSymbol type, NativeTarget target)
 {
     return(GetCS2XAttribute(type, target, "NativeTypeAttribute"));
 }
Example #8
0
 protected AttributeData GetNativeExternAttribute(IMethodSymbol method, NativeTarget target)
 {
     return(GetCS2XAttribute(method, target, "NativeExternAttribute"));
 }
Example #9
0
 public NativeExternAttribute(NativeTarget target, string methodName = null)
 {
     this.target     = target;
     this.methodName = methodName;
 }
Example #10
0
 public NativeTypeAttribute(NativeTarget target, string typeName = null)
 {
     this.target   = target;
     this.typeName = typeName;
 }