Example #1
0
        public int Compare(object a, object b)
        {
            GlTypeMapEntry tmea = a as GlTypeMapEntry;
            GlTypeMapEntry tmeb = b as GlTypeMapEntry;

            return(tmeb.Rank - tmea.Rank);
        }
Example #2
0
    // note: this always uses the CLS type
    public string TypeForRetVal(string intype)
    {
        ArrayList entries = typeHash[intype] as ArrayList;

        if (entries == null)
        {
            Console.WriteLine("TypeForRetVal: type '{0}' not found in map!", intype);
            throw new Exception();
        }

        // simple mapping?
        if (entries.Count == 1)
        {
            GlTypeMapEntry tme = entries[0] as GlTypeMapEntry;
            if (tme.Rank == 0)
            {
                return(tme.type);
            }
        }

        // or not.
        foreach (GlTypeMapEntry tme in entries)
        {
            if (tme.if_return == 1)
            {
                return(tme.type);
            }

            if ((tme.if_out == 0 || tme.if_out == -1) &&
                (tme.if_array == 0 || tme.if_array == -1))
            {
                return(tme.type);
            }
        }

        Console.WriteLine("TypeForRetVal: No match found for '{0}'", intype);
        throw new Exception();
    }
Example #3
0
    public void LoadFrom(string file)
    {
        XmlDocument tdoc = new XmlDocument();

        tdoc.Load(file);

        XmlNodeList nl      = tdoc.GetElementsByTagName("typemap");
        XmlNode     typemap = nl[0];


        foreach (XmlNode typenode in typemap.ChildNodes)
        {
            if (typenode.NodeType != XmlNodeType.Element)
            {
                continue;
            }

            if (typenode.Name == "type")
            {
                XmlAttribute nameattr = typenode.Attributes["name"];
                if (nameattr == null)
                {
                    Console.WriteLine("Warning: <type> in typemap with no name attribute");
                    continue;
                }

                string typename = nameattr.Value;

                if (typeHash[typename] != null)
                {
                    Console.WriteLine("Warning: type '{0}' mapped multiple times", typename);
                    continue;
                }

                foreach (XmlNode mapnode in typenode.ChildNodes)
                {
                    if (mapnode.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    if (mapnode.Name == "mapto")
                    {
                        // skip non-c# mappings
                        if (mapnode.Attributes["language"].Value != "c#")
                        {
                            continue;
                        }

                        GlTypeMapEntry tme = new GlTypeMapEntry();
                        if (mapnode.Attributes["type"] != null)
                        {
                            tme.type = mapnode.Attributes["type"].Value;
                        }
                        if (mapnode.Attributes["if_return"] != null)
                        {
                            tme.if_return = Convert.ToInt32(mapnode.Attributes["if_return"].Value);
                        }
                        if (mapnode.Attributes["if_out"] != null)
                        {
                            tme.if_out = Convert.ToInt32(mapnode.Attributes["if_out"].Value);
                        }
                        if (mapnode.Attributes["if_array"] != null)
                        {
                            tme.if_array = Convert.ToInt32(mapnode.Attributes["if_array"].Value);
                        }
                        if (mapnode.Attributes["as_array"] != null)
                        {
                            tme.as_array = Convert.ToInt32(mapnode.Attributes["as_array"].Value);
                        }
                        if (mapnode.Attributes["is_generic"] != null)
                        {
                            tme.is_generic = Convert.ToInt32(mapnode.Attributes["is_generic"].Value);
                        }
                        if (mapnode.Attributes["nonclstype"] != null)
                        {
                            tme.nonclstype = mapnode.Attributes["nonclstype"].Value;
                        }

                        ArrayList entries = typeHash[typename] as ArrayList;
                        if (entries == null)
                        {
                            entries            = new ArrayList();
                            typeHash[typename] = entries;
                        }

                        entries.Add(tme);
                    }
                }
            }
            else if (typenode.Name == "typealias")
            {
                string name  = typenode.Attributes["name"].Value;
                string mapto = typenode.Attributes["mapto"].Value;

                ArrayList entries = typeHash[mapto] as ArrayList;
                if (entries == null)
                {
                    Console.WriteLine("Warning: typealias entry for '{0}' seen before mapto type '{1}'!", name, mapto);
                    continue;
                }

                if (typeHash[name] != null)
                {
                    Console.WriteLine("Warning: type '{0}' mapped multiple times", name);
                    continue;
                }

                typeHash[name] = typeHash[mapto];
            }
        }
    }