Esempio n. 1
0
 public ImportedConstructorMetaObject(Expression objParam, ImportedConstructor runtimeModel)
     : base(objParam, BindingRestrictions.Empty, runtimeModel)
 {
     this.runtimeModel = runtimeModel;
 }
Esempio n. 2
0
        public static bool ImportMissingSymbol2(string name, Package package)
        {
            var members = package.ImportedType.GetMember(name, ImportBindingFlags).Select(x => ResolveGenericMethod(x)).ToArray();

            if (members.Length == 0)
            {
                return(false);
            }

            var importable = !package.RestrictedImport || members[0].GetCustomAttributes(typeof(LispAttribute), true).Length != 0;

            if (!importable)
            {
                return(false);
            }

            var field  = members[0] as FieldInfo;
            var ucName = members[0].Name.LispName().ToUpper();
            var lcName = members[0].Name.LispName();

            if (field != null)
            {
                if (field.IsLiteral || (field.IsStatic && field.IsInitOnly))
                {
                    var sym = package.FindOrCreate(ucName, excludeUseList: true, export: true);
                    sym.ConstantValue = field.GetValue(null);
                }
                return(true);
            }

            if (members[0] is EventInfo)
            {
                var sym = package.FindOrCreate(lcName, excludeUseList: true, export: true);
                sym.ConstantValue = members[0];
                return(true);
            }

            if (members[0] is ConstructorInfo)
            {
                var builtin = new ImportedConstructor(members.Cast <ConstructorInfo>().ToArray());
                var sym     = package.FindOrCreate("new", excludeUseList: true, export: true);
                sym.FunctionValue           = builtin;
                package.ImportedConstructor = builtin;
                return(true);
            }

            if (members[0] is MethodInfo)
            {
                //if ( !name.StartsWith( "get_" ) && !name.StartsWith( "set_" ) )
                {
                    var sym     = package.FindOrCreate(lcName, excludeUseList: true, export: true);
                    var builtin = new ImportedFunction(members[0].Name, members[0].DeclaringType, members.Cast <MethodInfo>().ToArray(), false);
                    sym.FunctionValue = builtin;
                }

                return(true);
            }

            if (members[0] is PropertyInfo)
            {
                var properties = members.Cast <PropertyInfo>().ToArray();
                var getters    = properties.Select(x => x.GetGetMethod()).Where(x => x != null).ToArray();
                var setters    = properties.Select(x => x.GetSetMethod()).Where(x => x != null).ToArray();

                if (getters.Length != 0)
                {
                    var sym     = package.FindOrCreate(lcName, excludeUseList: true, export: true);
                    var builtin = new ImportedFunction(members[0].Name, members[0].DeclaringType, getters, false);
                    sym.FunctionValue = builtin;
                }

                if (setters.Length != 0)
                {
                    // create getter symbol for setf/setq
                    package.FindOrCreate(lcName, excludeUseList: true, export: true);
                    // use set-xxx
                    var sym     = package.FindOrCreate("set-" + lcName, excludeUseList: true, export: true);
                    var builtin = new ImportedFunction(members[0].Name, members[0].DeclaringType, setters, false);
                    sym.FunctionValue = builtin;
                }

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        public static bool ImportMissingSymbol2(string name, Package package)
        {
            var members = package.ImportedType.GetMember(name, ImportBindingFlags).Select(x => ResolveGenericMethod(x)).ToArray();

            if (members.Length == 0)
            {
                return false;
            }

            var importable = !package.RestrictedImport || members[0].GetCustomAttributes(typeof(LispAttribute), true).Length != 0;

            if (!importable)
            {
                return false;
            }

            var field = members[0] as FieldInfo;
            var ucName = members[0].Name.LispName().ToUpper();
            var lcName = members[0].Name.LispName();

            if (field != null)
            {
                if (field.IsLiteral || (field.IsStatic && field.IsInitOnly))
                {
                    var sym = package.FindOrCreate(ucName, excludeUseList: true, export: true);
                    sym.ConstantValue = field.GetValue(null);
                }
                return true;
            }

            if (members[0] is EventInfo)
            {
                var sym = package.FindOrCreate(lcName, excludeUseList: true, export: true);
                sym.ConstantValue = members[0];
                return true;
            }

            if (members[0] is ConstructorInfo)
            {
                var builtin = new ImportedConstructor(members.Cast<ConstructorInfo>().ToArray());
                var sym = package.FindOrCreate("new", excludeUseList: true, export: true);
                sym.FunctionValue = builtin;
                package.ImportedConstructor = builtin;
                return true;
            }

            if (members[0] is MethodInfo)
            {
                //if ( !name.StartsWith( "get_" ) && !name.StartsWith( "set_" ) )
                {
                    var sym = package.FindOrCreate(lcName, excludeUseList: true, export: true);
                    var builtin = new ImportedFunction(members[0].Name, members[0].DeclaringType, members.Cast<MethodInfo>().ToArray(), false);
                    sym.FunctionValue = builtin;
                }

                return true;
            }

            if (members[0] is PropertyInfo)
            {
                var properties = members.Cast<PropertyInfo>().ToArray();
                var getters = properties.Select(x => x.GetGetMethod()).Where(x => x != null).ToArray();
                var setters = properties.Select(x => x.GetSetMethod()).Where(x => x != null).ToArray();

                if (getters.Length != 0)
                {
                    var sym = package.FindOrCreate(lcName, excludeUseList: true, export: true);
                    var builtin = new ImportedFunction(members[0].Name, members[0].DeclaringType, getters, false);
                    sym.FunctionValue = builtin;
                }

                if (setters.Length != 0)
                {
                    // create getter symbol for setf/setq
                    package.FindOrCreate(lcName, excludeUseList: true, export: true);
                    // use set-xxx
                    var sym = package.FindOrCreate("set-" + lcName, excludeUseList: true, export: true);
                    var builtin = new ImportedFunction(members[0].Name, members[0].DeclaringType, setters, false);
                    sym.FunctionValue = builtin;
                }

                return true;
            }

            return false;
        }
Esempio n. 4
0
 public ImportedConstructorMetaObject(Expression objParam, ImportedConstructor runtimeModel)
     : base(objParam, BindingRestrictions.Empty, runtimeModel)
 {
     this.runtimeModel = runtimeModel;
 }
Esempio n. 5
0
        public static bool ImportMembers(MemberInfo[] members, Package package)
        {
            if (members.Length == 0)
            {
                return(false);
            }

            var member     = members[0];
            var importable = !package.RestrictedImport || member.GetCustomAttributes(typeof(LispAttribute), true).Length != 0;

            if (!importable)
            {
                return(false);
            }

            var name   = member.Name;
            var ucName = name.LispName().ToUpper();
            var lcName = name.LispName();

            if (member is FieldInfo)
            {
                var field = member as FieldInfo;
                if (field.IsLiteral || (field.IsStatic && field.IsInitOnly))
                {
                    var sym = package.Create(ucName, ispublic: true);
                    sym.ConstantValue = field.GetValue(null);
                }
                return(true);
            }

            if (member is EventInfo)
            {
                var sym = package.Create(lcName, ispublic: true);
                sym.ConstantValue = member;
                return(true);
            }

            if (member is ConstructorInfo)
            {
                var builtin = new ImportedConstructor(members.Cast <ConstructorInfo>().ToArray());
                var sym     = package.Create("new", ispublic: true);
                sym.FunctionValue = builtin;
                return(true);
            }

            if (member is MethodInfo)
            {
                var sym     = package.Create(lcName, ispublic: true);
                var builtin = new ImportedFunction(name, member.DeclaringType, members.Cast <MethodInfo>().ToArray(), false);
                sym.FunctionValue = builtin;
                return(true);
            }

            if (member is PropertyInfo)
            {
                var properties = members.Cast <PropertyInfo>().ToArray();
                var getters    = properties.Select(x => x.GetGetMethod()).Where(x => x != null).ToArray();
                var setters    = properties.Select(x => x.GetSetMethod()).Where(x => x != null).ToArray();

                if (getters.Length != 0)
                {
                    var sym     = package.Create(lcName, ispublic: true);
                    var builtin = new ImportedFunction(name, member.DeclaringType, getters, false);
                    sym.FunctionValue = builtin;
                }

                if (setters.Length != 0)
                {
                    // create getter symbol for setf/setq
                    package.Create(lcName, ispublic: true);
                    // use set-xxx
                    var sym     = package.Create("set-" + lcName, ispublic: true);
                    var builtin = new ImportedFunction(name, member.DeclaringType, setters, false);
                    sym.FunctionValue = builtin;
                }

                return(true);
            }

            return(false);
        }