public static void SetTypeAttributes(Type type, FFIClassAttributes attributes) { lock (mTypeAttributeMaps) { mTypeAttributeMaps[type] = attributes; } }
private ClassDeclNode ParseEnumType(Type type, string alias) { //TODO: For now Enum can't be suppressed. Validity.Assert(type.IsEnum, "Non enum type is being imported as enum!!"); string classname = alias; if (classname == null | classname == string.Empty) { classname = CLRObjectMarshler.GetTypeName(type); } ProtoCore.AST.AssociativeAST.ClassDeclNode classnode = CreateEmptyClassNode(classname); classnode.ExternLibName = Module.Name; classnode.className = classname; classnode.Name = type.Name; FieldInfo[] fields = type.GetFields(); foreach (var f in fields) { if (f.FieldType != type) { continue; } VarDeclNode variable = ParseFieldDeclaration(f); if (null == variable) { continue; } variable.IsStatic = true; classnode.varlist.Add(variable); FunctionDefinitionNode func = ParseFieldAccessor(f); if (null != func) { func.IsStatic = true; RegisterFunctionPointer(func.Name, f, null, func.ReturnType); classnode.funclist.Add(func); } } //Get all the attributes on this type and set it to the classnode. FFIClassAttributes cattrs = new FFIClassAttributes(type); classnode.ClassAttributes = cattrs; SetTypeAttributes(type, cattrs); return(classnode); }
public FFIMethodAttributes(MethodInfo method) { if (method == null) { throw new ArgumentException("method"); } FFIClassAttributes baseAttributes = null; Type type = method.DeclaringType; if (!CLRModuleType.TryGetTypeAttributes(type, out baseAttributes)) { baseAttributes = new FFIClassAttributes(type); CLRModuleType.SetTypeAttributes(type, baseAttributes); } if (null != baseAttributes) { HiddenInLibrary = baseAttributes.HiddenInLibrary; } attributes = method.GetCustomAttributes(false).Cast <Attribute>().ToArray(); foreach (var attr in attributes) { if (attr is AllowRankReductionAttribute) { AllowRankReduction = true; } else if (attr is RuntimeRequirementAttribute) { RequireTracing = (attr as RuntimeRequirementAttribute).RequireTracing; } else if (attr is MultiReturnAttribute) { var multiReturnAttr = (attr as MultiReturnAttribute); returnKeys = multiReturnAttr.ReturnKeys.ToList(); } else if (attr is IsVisibleInDynamoLibraryAttribute) { var visibleInLibraryAttr = attr as IsVisibleInDynamoLibraryAttribute; HiddenInLibrary = (visibleInLibraryAttr.Visible == false); } } }
private ClassDeclNode ParseSystemType(Type type, string alias) { Validity.Assert(!SupressesImport(type), "Supressed type is being imported!!"); string classname = alias; if (classname == null | classname == string.Empty) classname = CLRObjectMarshler.GetTypeName(type); ProtoCore.AST.AssociativeAST.ClassDeclNode classnode = CreateEmptyClassNode(classname); classnode.ExternLibName = Module.Name; classnode.className = classname; classnode.Name = type.Name; Type baseType = GetBaseType(type); if (baseType != null && !CLRObjectMarshler.IsMarshaledAsNativeType(baseType)) { string baseTypeName = CLRObjectMarshler.GetTypeName(baseType); classnode.superClass = new List<string>(); classnode.superClass.Add(baseTypeName); //Make sure that base class is imported properly. CLRModuleType.GetInstance(baseType, Module, string.Empty); } // There is no static class in runtime. static class is simply // marked as sealed and abstract. bool isStaticClass = type.IsSealed && type.IsAbstract; if (!isStaticClass) { // If all methods are static, it doesn't make sense to expose // constructor. ConstructorInfo[] ctors = type.GetConstructors(); foreach (var c in ctors) { if (c.IsPublic && !c.IsGenericMethod && !SupressesImport(c)) { ConstructorDefinitionNode node = ParseConstructor(c, type); classnode.funclist.Add(node); List<ProtoCore.Type> argTypes = GetArgumentTypes(node); RegisterFunctionPointer(node.Name, c, argTypes, node.ReturnType); } } } BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static; bool isDerivedClass = (classnode.superClass != null) && classnode.superClass.Count > 0; if (isDerivedClass) //has base class flags |= BindingFlags.DeclaredOnly; //for derived class, parse only class declared methods. bool isDisposable = typeof(IDisposable).IsAssignableFrom(type); MethodInfo[] methods = type.GetMethods(flags); bool hasDisposeMethod = false; foreach (var m in methods) { if (SupressesImport(m)) continue; if (isStaticClass && m.GetBaseDefinition().DeclaringType == baseType && baseType == typeof(object)) continue; //Don't include overriden methods or generic methods if (m.IsPublic && !m.IsGenericMethod && m == m.GetBaseDefinition()) { AssociativeNode node = ParseAndRegisterFunctionPointer(isDisposable, ref hasDisposeMethod, m); classnode.funclist.Add(node); } else if (!hasDisposeMethod && isDisposable && baseType == typeof(Object) && isDisposeMethod(m)) { AssociativeNode node = ParseAndRegisterFunctionPointer(isDisposable, ref hasDisposeMethod, m); classnode.funclist.Add(node); } } if (!hasDisposeMethod && !isDisposable) { AssociativeNode node = ParseAndRegisterFunctionPointer(true, ref hasDisposeMethod, mDisposeMethod); classnode.funclist.Add(node); } FieldInfo[] fields = type.GetFields(); foreach (var f in fields) { if (SupressesImport(f)) continue; //Supress if defined in super-type if (isDerivedClass) { FieldInfo[] supertypeFields = baseType.GetFields(); if (supertypeFields.Any(superF => superF.Name == f.Name)) { continue; } } VarDeclNode variable = ParseFieldDeclaration(f); if (null == variable) continue; classnode.varlist.Add(variable); FunctionDefinitionNode func = ParseFieldAccessor(f); if (null != func) RegisterFunctionPointer(func.Name, f, null, func.ReturnType); } PropertyInfo[] properties = type.GetProperties(flags); foreach (var p in properties) { AssociativeNode node = ParseProperty(p); if(null != node) classnode.varlist.Add(node); } FFIClassAttributes cattrs = new FFIClassAttributes(type); classnode.ClassAttributes = cattrs; SetTypeAttributes(type, cattrs); return classnode; }
private ClassDeclNode ParseEnumType(Type type, string alias) { //TODO: For now Enum can't be suppressed. Validity.Assert(type.IsEnum, "Non enum type is being imported as enum!!"); string classname = alias; if (classname == null | classname == string.Empty) classname = CLRObjectMarshler.GetTypeName(type); ProtoCore.AST.AssociativeAST.ClassDeclNode classnode = CreateEmptyClassNode(classname); classnode.ExternLibName = Module.Name; classnode.className = classname; classnode.Name = type.Name; FieldInfo[] fields = type.GetFields(); foreach (var f in fields) { if (f.FieldType != type) continue; VarDeclNode variable = ParseFieldDeclaration(f); if (null == variable) continue; variable.IsStatic = true; classnode.varlist.Add(variable); FunctionDefinitionNode func = ParseFieldAccessor(f); if (null != func) { func.IsStatic = true; RegisterFunctionPointer(func.Name, f, null, func.ReturnType); classnode.funclist.Add(func); } } //Get all the attributes on this type and set it to the classnode. FFIClassAttributes cattrs = new FFIClassAttributes(type); classnode.ClassAttributes = cattrs; SetTypeAttributes(type, cattrs); return classnode; }
public static bool TryGetTypeAttributes(Type type, out FFIClassAttributes attributes) { return mTypeAttributeMaps.TryGetValue(type, out attributes); }
public FFIMethodAttributes(MethodInfo method) { if (method == null) throw new ArgumentException("method"); FFIClassAttributes baseAttributes = null; Type type = method.DeclaringType; if (!CLRModuleType.TryGetTypeAttributes(type, out baseAttributes)) { baseAttributes = new FFIClassAttributes(type); CLRModuleType.SetTypeAttributes(type, baseAttributes); } if (null != baseAttributes) { HiddenInLibrary = baseAttributes.HiddenInLibrary; } attributes = method.GetCustomAttributes(false).Cast<Attribute>().ToArray(); foreach (var attr in attributes) { if (attr is AllowRankReductionAttribute) { AllowRankReduction = true; } else if (attr is RuntimeRequirementAttribute) { RequireTracing = (attr as RuntimeRequirementAttribute).RequireTracing; } else if (attr is MultiReturnAttribute) { var multiReturnAttr = (attr as MultiReturnAttribute); returnKeys = multiReturnAttr.ReturnKeys.ToList(); } else if (attr is IsVisibleInDynamoLibraryAttribute) { var visibleInLibraryAttr = attr as IsVisibleInDynamoLibraryAttribute; HiddenInLibrary = (visibleInLibraryAttr.Visible == false); } } }
private ClassDeclNode ParseSystemType(Type type, string alias) { Validity.Assert(!SupressesImport(type), "Supressed type is being imported!!"); string classname = alias; if (classname == null | classname == string.Empty) { classname = CLRObjectMarshler.GetTypeName(type); } ProtoCore.AST.AssociativeAST.ClassDeclNode classnode = CreateEmptyClassNode(classname); classnode.ExternLibName = Module.Name; classnode.className = classname; classnode.Name = type.Name; Type baseType = GetBaseType(type); if (baseType != null && !CLRObjectMarshler.IsMarshaledAsNativeType(baseType)) { string baseTypeName = CLRObjectMarshler.GetTypeName(baseType); classnode.superClass = new List <string>(); classnode.superClass.Add(baseTypeName); //Make sure that base class is imported properly. CLRModuleType.GetInstance(baseType, Module, string.Empty); } // There is no static class in runtime. static class is simply // marked as sealed and abstract. bool isStaticClass = type.IsSealed && type.IsAbstract; if (!isStaticClass) { // If all methods are static, it doesn't make sense to expose // constructor. ConstructorInfo[] ctors = type.GetConstructors(); foreach (var c in ctors) { if (c.IsPublic && !c.IsGenericMethod && !SupressesImport(c)) { ConstructorDefinitionNode node = ParseConstructor(c, type); classnode.funclist.Add(node); List <ProtoCore.Type> argTypes = GetArgumentTypes(node); RegisterFunctionPointer(node.Name, c, argTypes, node.ReturnType); } } } BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static; bool isDerivedClass = (classnode.superClass != null) && classnode.superClass.Count > 0; if (isDerivedClass) //has base class { flags |= BindingFlags.DeclaredOnly; //for derived class, parse only class declared methods. } bool isDisposable = typeof(IDisposable).IsAssignableFrom(type); MethodInfo[] methods = type.GetMethods(flags); bool hasDisposeMethod = false; foreach (var m in methods) { if (SupressesImport(m)) { continue; } if (isStaticClass && m.GetBaseDefinition().DeclaringType == baseType && baseType == typeof(object)) { continue; } //Don't include overriden methods or generic methods if (m.IsPublic && !m.IsGenericMethod && m == m.GetBaseDefinition()) { AssociativeNode node = ParseAndRegisterFunctionPointer(isDisposable, ref hasDisposeMethod, m); classnode.funclist.Add(node); } else if (!hasDisposeMethod && isDisposable && baseType == typeof(Object) && isDisposeMethod(m)) { AssociativeNode node = ParseAndRegisterFunctionPointer(isDisposable, ref hasDisposeMethod, m); classnode.funclist.Add(node); } } if (!hasDisposeMethod && !isDisposable) { AssociativeNode node = ParseAndRegisterFunctionPointer(true, ref hasDisposeMethod, mDisposeMethod); classnode.funclist.Add(node); } FieldInfo[] fields = type.GetFields(); foreach (var f in fields) { if (SupressesImport(f)) { continue; } //Supress if defined in super-type if (isDerivedClass) { FieldInfo[] supertypeFields = baseType.GetFields(); if (supertypeFields.Any(superF => superF.Name == f.Name)) { continue; } } VarDeclNode variable = ParseFieldDeclaration(f); if (null == variable) { continue; } classnode.varlist.Add(variable); FunctionDefinitionNode func = ParseFieldAccessor(f); if (null != func) { RegisterFunctionPointer(func.Name, f, null, func.ReturnType); } } PropertyInfo[] properties = type.GetProperties(flags); foreach (var p in properties) { AssociativeNode node = ParseProperty(p); if (null != node) { classnode.varlist.Add(node); } } FFIClassAttributes cattrs = new FFIClassAttributes(type); classnode.ClassAttributes = cattrs; SetTypeAttributes(type, cattrs); return(classnode); }
public static bool TryGetTypeAttributes(Type type, out FFIClassAttributes attributes) { return(mTypeAttributeMaps.TryGetValue(type, out attributes)); }
public FFIMethodAttributes(MethodInfo method, Dictionary<MethodInfo, Attribute[]> getterAttributes) { if (method == null) throw new ArgumentNullException("method"); FFIClassAttributes baseAttributes = null; Type type = method.DeclaringType; if (!CLRModuleType.TryGetTypeAttributes(type, out baseAttributes)) { baseAttributes = new FFIClassAttributes(type); CLRModuleType.SetTypeAttributes(type, baseAttributes); } if (null != baseAttributes) { HiddenInLibrary = baseAttributes.HiddenInLibrary; } Attribute[] atts = null; if (getterAttributes.TryGetValue(method, out atts)) { attributes = atts; } else { attributes = method.GetCustomAttributes(false).Cast<Attribute>().ToArray(); } foreach (var attr in attributes) { if (attr is AllowRankReductionAttribute) { AllowRankReduction = true; } else if (attr is RuntimeRequirementAttribute) { RequireTracing = (attr as RuntimeRequirementAttribute).RequireTracing; } else if (attr is MultiReturnAttribute) { var multiReturnAttr = (attr as MultiReturnAttribute); returnKeys = multiReturnAttr.ReturnKeys.ToList(); } else if (attr is IsVisibleInDynamoLibraryAttribute) { var visibleInLibraryAttr = attr as IsVisibleInDynamoLibraryAttribute; HiddenInLibrary = (visibleInLibraryAttr.Visible == false); } else if (attr is ObsoleteAttribute) { HiddenInLibrary = true; ObsoleteMessage = (attr as ObsoleteAttribute).Message; if (string.IsNullOrEmpty(ObsoleteMessage)) ObsoleteMessage = "Obsolete"; } else if (attr is CanUpdatePeriodicallyAttribute) { CanUpdatePeriodically = (attr as CanUpdatePeriodicallyAttribute).CanUpdatePeriodically; } } }