Exemplo n.º 1
0
        public Method GetReference(string name, TypeRef return_type,
                                   Param[] param_list, TypeRef[] param_type_list, Location location)
        {
            string signature = GetSignature(name, return_type, param_type_list);

            if (MethodReferencedEvent != null)
            {
                MethodReferencedEvent(this, new MethodReferencedEventArgs(signature, name,
                                                                          return_type, param_list, table.Contains(signature)));
            }

            MethodTableItem item = table[signature] as MethodTableItem;

            if (item != null)
            {
                item.LocationList.Add(location);
                return(item.Method);
            }

            MethodDef method = parent_class.AddMethod(name, return_type.Type,
                                                      param_list);

            AddReferenced(signature, method, location);

            return(method);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Find the Method for this method on the given type.
        /// </summary>
        internal Method findMethod(string qname, string methodName, string[] paramTypes, string returnType)
        {
            string key    = getMethodKey(qname, methodName, paramTypes);
            Method method = (Method)methods[key];

            if (method == null)
            {
                // this stuff should be the same for both cases
                PERWAPI.Type   rtype = findType(returnType);
                PERWAPI.Type[] pars  = new PERWAPI.Type[paramTypes.Length];
                for (int i = 0; i < paramTypes.Length; i++)
                {
                    pars[i] = findType(paramTypes[i]);
                }

                // check for stubs
                object obj = findType(qname);
                if (obj is ClassDef)
                {
                    // class is an internal stub, so we need to stub this
                    // method out too, which should get flushed out later
                    ClassDef cdef = obj as ClassDef;

                    // TODO - need to fix attrs
                    Param[] mpars = new Param[pars.Length];
                    for (int i = 0; i < mpars.Length; i++)
                    {
                        mpars[i] = new Param(ParamAttr.Default, "v" + i, pars[i]);
                    }

                    // TODO - fix param names
                    // Use Public here for stub - real MethAttr will be set
                    // when method is flushed out
                    method = cdef.AddMethod(MethAttr.Public, ImplAttr.IL, methodName, rtype, mpars);
                }
                else if (obj is ClassRef)
                {
                    // class is external, just get or add ref
                    ClassRef cref = obj as ClassRef;
                    method = cref.GetMethod(methodName, pars, new PERWAPI.Type[0]);
                    if (method == null)
                    {
                        method = cref.AddMethod(methodName, rtype, pars);
                    }
                }
                else
                {
                    throw new System.Exception("Don't know how to handle: " + obj.GetType());
                }

                // make sure we add method to hashtable
                methods[key] = method;
            }

            return(method);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add a "global" method to this module
        /// </summary>
        /// <param name="name">method name</param>
        /// <param name="retType">return type</param>
        /// <param name="pars">method parameters</param>
        /// <returns>a descriptor for this new "global" method</returns>
        public MethodDef AddMethod(string name, Type retType, Param[] pars)
        {
            MethodDef newMeth = defaultClass.AddMethod(name, retType, pars);

            return(newMeth);
        }