private ProtoCore.AST.AssociativeAST.VarDeclNode ParseArgumentDeclaration(string parameterName, Type parameterType)
        {
            ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = new ProtoCore.AST.AssociativeAST.VarDeclNode();
            varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.kMemStack;
            varDeclNode.access    = ProtoCore.DSASM.AccessSpecifier.kPublic;

            ProtoCore.AST.AssociativeAST.IdentifierNode identifierNode = new ProtoCore.AST.AssociativeAST.IdentifierNode
            {
                Value    = parameterName,
                Name     = parameterName,
                datatype = new ProtoCore.Type()
                {
                    Name        = "var",
                    IsIndexable = false,
                    rank        = 0,
                    UID         = (int)ProtoCore.PrimitiveType.kTypeVar
                }
            };
            //Lets emit native DS type object
            ProtoCore.Type argtype = CLRModuleType.GetProtoCoreType(parameterType, Module);

            varDeclNode.NameNode     = identifierNode;
            varDeclNode.ArgumentType = argtype;
            return(varDeclNode);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="protoCoreType"></param>
        private static void GetProtoCoreType(Type type, ref ProtoCore.Type protoCoreType)
        {
            FFIObjectMarshler marshaler;

            if (type.IsArray)
            {
                Type elemType = type.GetElementType();
                GetProtoCoreType(elemType, ref protoCoreType);
                protoCoreType.rank       += type.GetArrayRank(); //set the rank.
                protoCoreType.IsIndexable = true;
            }
            else if (type.IsInterface && (typeof(ICollection).IsAssignableFrom(type) || typeof(IEnumerable).IsAssignableFrom(type)))
            {
                protoCoreType.rank       += 1;
                protoCoreType.IsIndexable = true;
            }
            else if (type.IsGenericType && (typeof(ICollection).IsAssignableFrom(type) || typeof(IEnumerable).IsAssignableFrom(type)))
            {
                Type[] args  = type.GetGenericArguments();
                int    nArgs = args.Length;
                if (nArgs != 1)
                {
                    protoCoreType.Name = GetTypeName(type);
                    protoCoreType.UID  = (int)ProtoCore.PrimitiveType.kTypePointer;
                    return;
                }
                Type elemType = args[0];
                //TODO: Ideally we shouldn't be calling this method on CLRModuleType,
                //but we want to import this elemType, hence we do this.
                protoCoreType             = CLRModuleType.GetProtoCoreType(elemType, null);
                protoCoreType.rank       += 1;
                protoCoreType.IsIndexable = true;
            }
            else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                protoCoreType = CLRModuleType.GetProtoCoreType(Nullable.GetUnderlyingType(type), null);
            }
            else if (type == typeof(object))
            {
                protoCoreType = PrimitiveMarshler.CreateType(ProtoCore.PrimitiveType.kTypeVar);
            }
            else if (type == typeof(void))
            {
                protoCoreType = PrimitiveMarshler.CreateType(ProtoCore.PrimitiveType.kTypeVoid);
            }
            else if (protoCoreType.UID == (int)ProtoCore.PrimitiveType.kTypePointer)
            {
                protoCoreType.Name = GetTypeName(type);
            }
            else if (mPrimitiveMarshalers.TryGetValue(type, out marshaler))
            {
                protoCoreType = marshaler.GetMarshaledType(type);
            }
            else
            {
                protoCoreType.Name = GetTypeName(type);
                protoCoreType.UID  = (int)ProtoCore.PrimitiveType.kTypePointer;
            }
        }
Esempio n. 3
0
        private ProtoCore.AST.AssociativeAST.AssociativeNode ParseMethod(MethodInfo method)
        {
            ProtoCore.Type retype       = CLRModuleType.GetProtoCoreType(method.ReturnType, Module);
            bool           propaccessor = isPropertyAccessor(method);
            bool           isOperator   = isOverloadedOperator(method);

            FFIMethodAttributes mattrs = new FFIMethodAttributes(method);

            if (method.IsStatic &&
                method.DeclaringType == method.ReturnType &&
                !propaccessor &&
                !isOperator)
            {
                //case for named constructor. Must return a pointer type
                if (!Object.Equals(method.ReturnType, CLRType))
                {
                    throw new InvalidOperationException("Unexpected type for constructor {0D28FC00-F8F4-4049-AD1F-BBC34A68073F}");
                }

                retype = ProtoCoreType;
                ConstructorDefinitionNode node = ParsedNamedConstructor(method, method.Name, retype);
                node.MethodAttributes = mattrs;
                return(node);
            }

            //Need to hide property accessor from design script users, prefix with %
            string prefix = (isOperator || propaccessor) ? "%" : "";
            var    func   = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();

            if (isOperator)
            {
                func.Name = string.Format("{0}{1}", prefix, GetDSOperatorName(method.Name));
            }
            else
            {
                func.Name = string.Format("{0}{1}", prefix, method.Name);
            }
            func.Pattern   = null;
            func.Signature = ParseArgumentSignature(method);

            if ((retype.IsIndexable && mattrs.AllowRankReduction) ||
                (typeof(object).Equals(method.ReturnType)))
            {
                retype.rank = Constants.kArbitraryRank;
            }
            func.ReturnType       = retype;
            func.FunctionBody     = null;
            func.access           = ProtoCore.Compiler.AccessSpecifier.kPublic;
            func.IsDNI            = false;
            func.IsExternLib      = true;
            func.ExternLibName    = Module.Name;
            func.IsStatic         = method.IsStatic;
            func.MethodAttributes = mattrs;

            return(func);
        }
Esempio n. 4
0
        private ProtoCore.AST.AssociativeAST.VarDeclNode ParseArgumentDeclaration(string parameterName, Type parameterType)
        {
            ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = new ProtoCore.AST.AssociativeAST.VarDeclNode();
            varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.kMemStack;
            varDeclNode.access    = ProtoCore.Compiler.AccessSpecifier.kPublic;

            ProtoCore.AST.AssociativeAST.IdentifierNode identifierNode = new ProtoCore.AST.AssociativeAST.IdentifierNode
            {
                Value    = parameterName,
                Name     = parameterName,
                datatype = ProtoCore.TypeSystem.BuildPrimitiveTypeObject(ProtoCore.PrimitiveType.kTypeVar, 0)
            };
            //Lets emit native DS type object
            ProtoCore.Type argtype = CLRModuleType.GetProtoCoreType(parameterType, Module);

            varDeclNode.NameNode     = identifierNode;
            varDeclNode.ArgumentType = argtype;
            return(varDeclNode);
        }
        private ProtoCore.AST.AssociativeAST.FunctionDefinitionNode ParseFieldAccessor(FieldInfo f)
        {
            if (null == f || !IsBrowsable(f))
            {
                return(null);
            }

            ProtoCore.AST.AssociativeAST.FunctionDefinitionNode func = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
            func.Name          = string.Format("%get_{0}", f.Name);
            func.Pattern       = null;
            func.Singnature    = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode();
            func.ReturnType    = CLRModuleType.GetProtoCoreType(f.FieldType, Module);
            func.FunctionBody  = null;
            func.access        = ProtoCore.DSASM.AccessSpecifier.kPublic;
            func.IsDNI         = false;
            func.IsExternLib   = true;
            func.ExternLibName = Module.Name;
            func.IsStatic      = f.IsStatic;

            return(func);
        }
        private ProtoCore.AST.AssociativeAST.AssociativeNode ParseMethod(MethodInfo method)
        {
            ProtoCore.Type retype       = CLRModuleType.GetProtoCoreType(method.ReturnType, Module);
            bool           propaccessor = isPropertyAccessor(method);

            if (method.IsStatic && method.DeclaringType == method.ReturnType && !propaccessor)
            {
                //case for named constructor. Must return a pointer type
                if (!Object.Equals(method.ReturnType, CLRType))
                {
                    throw new InvalidOperationException("Unexpected type for constructor {0D28FC00-F8F4-4049-AD1F-BBC34A68073F}");
                }

                retype = ProtoCoreType;
                return(ParsedNamedConstructor(method, method.Name, retype));
            }

            //Need to hide property accessor from design script users, prefix with %
            string prefix = propaccessor ? "%" : "";

            ProtoCore.AST.AssociativeAST.FunctionDefinitionNode func = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
            func.Name       = string.Format("{0}{1}", prefix, method.Name);
            func.Pattern    = null;
            func.Singnature = ParseArgumentSignature(method);
            if (retype.IsIndexable && AllowsRankReduction(method))
            {
                retype.rank = -1;
            }
            func.ReturnType    = retype;
            func.FunctionBody  = null;
            func.access        = ProtoCore.DSASM.AccessSpecifier.kPublic;
            func.IsDNI         = false;
            func.IsExternLib   = true;
            func.ExternLibName = Module.Name;
            func.IsStatic      = method.IsStatic;

            return(func);
        }
 private ProtoCore.Type[] GetArgumentTypes(FFIMemberInfo member)
 {
     return(member.GetParameters().Select(
                pi => CLRModuleType.GetProtoCoreType(pi.ParameterType, Module)
                ).ToArray());
 }
Esempio n. 8
0
 private ProtoCore.Type[] GetArgumentTypes()
 {
     return(ReflectionInfo.GetParameters().Select(
                pi => CLRModuleType.GetProtoCoreType(pi.Info.ParameterType, Module)).ToArray());
 }
        //this is incomplete todo: implement
        public override List <FFIFunctionPointer> GetFunctionPointers(string className, string name)
        {
            CLRModuleType type = null;

            if (mTypes.TryGetValue(className, out type))
            {
                return(type.GetFunctionPointers(name));
            }

            if (name == ProtoCore.DSDefinitions.Keyword.Dispose)
            {
                List <FFIFunctionPointer> pointers = new List <FFIFunctionPointer>();
                pointers.Add(new DisposeFunctionPointer(this, CLRModuleType.DisposeMethod, CLRModuleType.GetProtoCoreType(CLRModuleType.DisposeMethod.ReturnType, this)));
                return(pointers);
            }

            throw new KeyNotFoundException(string.Format("Function definition for {0}.{1}, not found", className, name));
        }