Beispiel #1
0
        private DelegateCollection ReadDelegates(XPathNavigator specs)
        {
            DelegateCollection delegates = new DelegateCollection();

            foreach (XPathNavigator node in specs.SelectChildren("function", String.Empty))
            {
                var name = node.GetAttribute("name", String.Empty);

                // Check whether we are adding to an existing delegate or creating a new one.
                Delegate d = null;
                if (delegates.ContainsKey(name))
                {
                    d = delegates[name];
                }
                else
                {
                    d                   = new Delegate();
                    d.Name              = name;
                    d.Version           = node.GetAttribute("version", String.Empty);
                    d.Category          = node.GetAttribute("category", String.Empty);
                    d.DeprecatedVersion = node.GetAttribute("deprecated", String.Empty);
                    d.Deprecated        = !String.IsNullOrEmpty(d.DeprecatedVersion);
                    d.Obsolete          = node.GetAttribute("obsolete", String.Empty);
                }

                foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
                {
                    switch (param.Name)
                    {
                    case "returns":
                        d.ReturnType.CurrentType = param.GetAttribute("type", String.Empty);
                        break;

                    case "param":
                        Parameter p = new Parameter();
                        p.CurrentType = param.GetAttribute("type", String.Empty);
                        p.Name        = param.GetAttribute("name", String.Empty);

                        string element_count = param.GetAttribute("elementcount", String.Empty);
                        if (String.IsNullOrEmpty(element_count))
                        {
                            element_count = param.GetAttribute("count", String.Empty);
                        }
                        if (!String.IsNullOrEmpty(element_count))
                        {
                            p.ElementCount = Int32.Parse(element_count);
                        }

                        p.Flow = Parameter.GetFlowDirection(param.GetAttribute("flow", String.Empty));

                        d.Parameters.Add(p);
                        break;
                    }
                }

                delegates.Add(d);
            }

            return(delegates);
        }
Beispiel #2
0
 /// <summary>
 /// Merges the given enum into the enum list. If an enum of the same name exists,
 /// it merges their respective constants.
 /// </summary>
 /// <param name="enums"></param>
 /// <param name="t"></param>
 internal static void Merge(DelegateCollection delegates, Delegate t)
 {
     if (!delegates.ContainsKey(t.Name))
     {
         delegates.Add(t.Name, t);
     }
 }
Beispiel #3
0
        public override DelegateCollection ReadDelegates(StreamReader specFile)
        {
            DelegateCollection delegates = new DelegateCollection();
            XPathDocument      specs     = new XPathDocument(specFile);
            XPathDocument      overrides = new XPathDocument(new StreamReader(Path.Combine(Settings.InputPath, functionOverridesFile)));

            foreach (XPathNavigator nav in new XPathNavigator[] {
                specs.CreateNavigator().SelectSingleNode("/signatures"),
                overrides.CreateNavigator().SelectSingleNode("/overrides/add")
            })
            {
                if (nav != null)
                {
                    foreach (XPathNavigator node in nav.SelectChildren("function", String.Empty))
                    {
                        Delegate d = new Delegate();
                        d.Name = node.GetAttribute("name", String.Empty);
                        //d.Extension = node.GetAttribute("extension");
                        d.Version  = node.GetAttribute("version", String.Empty);
                        d.Category = node.GetAttribute("category", String.Empty);
                        foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
                        {
                            switch (param.Name)
                            {
                            case "returns":
                                d.ReturnType.CurrentType = param.GetAttribute("type", String.Empty);
                                break;

                            case "param":
                                Parameter p = new Parameter();
                                p.CurrentType = param.GetAttribute("type", String.Empty);
                                p.Name        = param.GetAttribute("name", String.Empty);

                                string element_count = param.GetAttribute("elementcount", String.Empty);
                                if (!String.IsNullOrEmpty(element_count))
                                {
                                    p.ElementCount = Int32.Parse(element_count);
                                }

                                p.Flow = Parameter.GetFlowDirection(param.GetAttribute("flow", String.Empty));

                                d.Parameters.Add(p);
                                break;
                            }
                        }
                        d.Translate(overrides);
                        delegates.Add(d);
                    }
                }
            }

            return(delegates);
        }
Beispiel #4
0
 // Merges the given delegate into the delegate list.
 internal static void Merge(DelegateCollection delegates, Delegate t)
 {
     delegates.Add(t.Name, t);
 }
 // Merges the given delegate into the delegate list.
 internal static void Merge(DelegateCollection delegates, Delegate t)
 {
     delegates.Add(t.Name, t);
 }
Beispiel #6
0
        private DelegateCollection ReadDelegates(XPathNavigator specs, string apiversion)
        {
            DelegateCollection delegates = new DelegateCollection();
            var extensions = new List <string>();

            string path = "function";

            foreach (XPathNavigator node in specs.SelectChildren(path, String.Empty))
            {
                var name    = node.GetAttribute("name", String.Empty).Trim();
                var version = node.GetAttribute("version", String.Empty).Trim();

                // Ignore functions that have a higher version number than
                // our current apiversion. Extensions do not have a version,
                // so we add them anyway (which is desirable).
                if (!String.IsNullOrEmpty(version) && !String.IsNullOrEmpty(apiversion) &&
                    Decimal.Parse(version, CultureInfo.InvariantCulture) > Decimal.Parse(apiversion, CultureInfo.InvariantCulture))
                {
                    continue;
                }

                // Check whether we are adding to an existing delegate or creating a new one.
                var d = new Delegate
                {
                    Name              = name,
                    EntryPoint        = name,
                    Version           = node.GetAttribute("version", String.Empty).Trim(),
                    Category          = node.GetAttribute("category", String.Empty).Trim(),
                    DeprecatedVersion = node.GetAttribute("deprecated", String.Empty).Trim(),
                    Deprecated        = !String.IsNullOrEmpty(node.GetAttribute("deprecated", String.Empty)),
                    Extension         = node.GetAttribute("extension", String.Empty).Trim() ?? "Core",
                    Obsolete          = node.GetAttribute("obsolete", String.Empty).Trim()
                };
                if (!extensions.Contains(d.Extension))
                {
                    extensions.Add(d.Extension);
                }

                foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
                {
                    switch (param.Name)
                    {
                    case "returns":
                        d.ReturnType.CurrentType = param.GetAttribute("type", String.Empty).Trim();
                        break;

                    case "param":
                        Parameter p = new Parameter();
                        p.CurrentType = param.GetAttribute("type", String.Empty).Trim();
                        p.Name        = param.GetAttribute("name", String.Empty).Trim();

                        p.ComputeSize = param.GetAttribute("count", String.Empty).Trim();

                        int elementCount;
                        if (Int32.TryParse(p.ComputeSize, out elementCount))
                        {
                            p.ElementCount = elementCount;
                        }

                        p.Flow = Parameter.GetFlowDirection(param.GetAttribute("flow", String.Empty).Trim());

                        d.Parameters.Add(p);
                        break;
                    }
                }

                delegates.Add(d);
            }

            Utilities.AddExtensions(extensions);
            return(delegates);
        }
Beispiel #7
0
 /// <summary>
 /// Merges the given enum into the enum list. If an enum of the same name exists,
 /// it merges their respective constants.
 /// </summary>
 /// <param name="enums"></param>
 /// <param name="t"></param>
 internal static void Merge(DelegateCollection delegates, Delegate t)
 {
     if (!delegates.ContainsKey(t.Name))
     {
         delegates.Add(t.Name, t);
     }
 }
Beispiel #8
0
        private DelegateCollection ReadDelegates(XPathNavigator specs)
        {
            DelegateCollection delegates = new DelegateCollection();

            foreach (XPathNavigator node in specs.SelectChildren("function", String.Empty))
            {
                var name = node.GetAttribute("name", String.Empty);

                // Check whether we are adding to an existing delegate or creating a new one.
                Delegate d = null;
                if (delegates.ContainsKey(name))
                {
                    d = delegates[name];
                }
                else
                {
                    d = new Delegate();
                    d.Name = name;
                    d.Version = node.GetAttribute("version", String.Empty);
                    d.Category = node.GetAttribute("category", String.Empty);
                    d.DeprecatedVersion = node.GetAttribute("deprecated", String.Empty);
                    d.Deprecated = !String.IsNullOrEmpty(d.DeprecatedVersion);
                }

                foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
                {
                    switch (param.Name)
                    {
                        case "returns":
                            d.ReturnType.CurrentType = param.GetAttribute("type", String.Empty);
                            break;

                        case "param":
                            Parameter p = new Parameter();
                            p.CurrentType = param.GetAttribute("type", String.Empty);
                            p.Name = param.GetAttribute("name", String.Empty);

                            string element_count = param.GetAttribute("elementcount", String.Empty);
                            if (String.IsNullOrEmpty(element_count))
                                element_count = param.GetAttribute("count", String.Empty);
                            if (!String.IsNullOrEmpty(element_count))
                                p.ElementCount = Int32.Parse(element_count);

                            p.Flow = Parameter.GetFlowDirection(param.GetAttribute("flow", String.Empty));

                            d.Parameters.Add(p);
                            break;
                    }
                }

                delegates.Add(d);
            }

            return delegates;
        }
Beispiel #9
0
        public virtual DelegateCollection ReadDelegates(StreamReader specFile)
        {
            Console.WriteLine("Reading function specs.");

            DelegateCollection delegates = new DelegateCollection();

            XPathDocument function_overrides = new XPathDocument(Path.Combine(Settings.InputPath, functionOverridesFile));

            do
            {
                string line = NextValidLine(specFile);
                if (String.IsNullOrEmpty(line))
                    break;

                while (line.Contains("(") && !specFile.EndOfStream)
                {
                    // Get next OpenGL function

                    Delegate d = new Delegate();

                    // Get function name:
                    d.Name = line.Split(Utilities.Separators, StringSplitOptions.RemoveEmptyEntries)[0];

                    do
                    {
                        // Get function parameters and return value

                        line = specFile.ReadLine();
                        List<string> words = new List<string>(
                            line.Replace('\t', ' ').Split(Utilities.Separators, StringSplitOptions.RemoveEmptyEntries)
                        );

                        if (words.Count == 0)
                            break;

                        // Identify line:
                        switch (words[0])
                        {
                            case "return":  // Line denotes return value
                                d.ReturnType.CurrentType = words[1];
                                break;

                            case "param":   // Line denotes parameter
                                Parameter p = new Parameter();

                                p.Name = Utilities.Keywords.Contains(words[1]) ? "@" + words[1] : words[1];
                                p.CurrentType = words[2];
                                p.Pointer += words[4].Contains("array") ? 1 : 0;
                                p.Pointer += words[4].Contains("reference") ? 1 : 0;
                                if (p.Pointer != 0 && words.Count > 5 && words[5].Contains("[1]"))
                                    p.ElementCount = 1;
                                p.Flow = words[3] == "in" ? FlowDirection.In : FlowDirection.Out;

                                d.Parameters.Add(p);
                                break;

                            // GetTexParameterIivEXT and GetTexParameterIuivEXT define two(!) versions (why?)
                            case "version": // Line denotes function version (i.e. 1.0, 1.2, 1.5)
                                d.Version = words[1];
                                break;

                            case "category":
                                d.Category = words[1];
                                break;
                        }
                    }
                    while (!specFile.EndOfStream);

                    d.Translate(function_overrides);

                    delegates.Add(d);
                }
            }
            while (!specFile.EndOfStream);

            return delegates;
        }
Beispiel #10
0
        public virtual DelegateCollection ReadDelegates(StreamReader specFile)
        {
            Console.WriteLine("Reading function specs.");

            //List<Bind.Structures.Delegate> delegates = new List<Bind.Structures.Delegate>();
            DelegateCollection delegates = new DelegateCollection();

            do
            {
                string line = NextValidLine(specFile);
                if (String.IsNullOrEmpty(line))
                    break;

                while (line.Contains("(") && !specFile.EndOfStream)
                {
                    // Get next OpenGL function

                    Bind.Structures.Delegate d = new Bind.Structures.Delegate();

                    // Get function name:
                    d.Name = line.Split(Utilities.Separators, StringSplitOptions.RemoveEmptyEntries)[0];

                    //if (d.Name.Contains("QueryHyperpipeBestAttribSGIX"))
                    //{
                    //}

                    do
                    {
                        // Get function parameters and return value

                        line = specFile.ReadLine();
                        List<string> words = new List<string>(
                            line.Replace('\t', ' ').Split(Utilities.Separators, StringSplitOptions.RemoveEmptyEntries)
                        );

                        if (words.Count == 0)
                            break;

                        // Identify line:
                        switch (words[0])
                        {
                            case "return":  // Line denotes return value
                                d.ReturnType.CurrentType = words[1];
                                break;

                            case "param":   // Line denotes parameter
                                Parameter p = new Parameter();

                                p.Name = Utilities.Keywords.Contains(words[1]) ? "@" + words[1] : words[1];
                                p.CurrentType = words[2];
                                p.Pointer = words[4].Contains("array") ? true : words[4].Contains("reference") ? true : false;
                                p.Flow = words[3] == "in" ? Parameter.FlowDirection.In : Parameter.FlowDirection.Out;
 
                                d.Parameters.Add(p);
                                break;

                            // Version directive is not used. GetTexParameterIivEXT and GetTexParameterIuivEXT define two(!) versions (why?)
                            //case "version": // Line denotes function version (i.e. 1.0, 1.2, 1.5)
                            //    d.UserData.Add("version", words[1]);
                            //    break;

                            case "category":
                                d.Category = words[1];
                                break;
                        }
                    }
                    while (!specFile.EndOfStream);

                    d.Translate();

                    delegates.Add(d);
                }
            }
            while (!specFile.EndOfStream);

            return delegates;
        }
Beispiel #11
0
        public override DelegateCollection ReadDelegates(StreamReader specFile)
        {
            DelegateCollection delegates = new DelegateCollection();
            XPathDocument specs = new XPathDocument(specFile);
            XPathDocument overrides = new XPathDocument(new StreamReader(Path.Combine(Settings.InputPath, functionOverridesFile)));

            foreach (XPathNavigator nav in new XPathNavigator[] {
                specs.CreateNavigator().SelectSingleNode("/signatures"),
                overrides.CreateNavigator().SelectSingleNode("/overrides/add") })
            {
                if (nav != null)
                {
                    foreach (XPathNavigator node in nav.SelectChildren("function", String.Empty))
                    {
                        var name = node.GetAttribute("name", String.Empty);
                        
                        // Check whether we are adding to an existing delegate or creating a new one.
                        Delegate d = null;
                        if (delegates.ContainsKey(name))
                        {
                            d = delegates[name];
                        }
                        else
                        {
                            d = new Delegate();
                            d.Name = name;
                            d.Version = node.GetAttribute("version", String.Empty);
                            d.Category = node.GetAttribute("category", String.Empty);
                        }

                        foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
                        {
                            switch (param.Name)
                            {
                                case "returns":
                                    d.ReturnType.CurrentType = param.GetAttribute("type", String.Empty);
                                    break;

                                case "param":
                                    Parameter p = new Parameter();
                                    p.CurrentType = param.GetAttribute("type", String.Empty);
                                    p.Name = param.GetAttribute("name", String.Empty);

                                    string element_count = param.GetAttribute("elementcount", String.Empty);
                                    if (!String.IsNullOrEmpty(element_count))
                                        p.ElementCount = Int32.Parse(element_count);

                                    p.Flow = Parameter.GetFlowDirection(param.GetAttribute("flow", String.Empty));

                                    d.Parameters.Add(p);
                                    break;
                            }
                        }
                        d.Translate(overrides);
                        delegates.Add(d);
                    }
                }
            }

            return delegates;
        }
        public FunctionCollection Process(EnumProcessor enum_processor, DocProcessor doc_processor,
            DelegateCollection delegates, EnumCollection enums, string apiname, string apiversion)
        {
            Console.WriteLine("Processing delegates.");
            var nav = new XPathDocument(Overrides).CreateNavigator();
            foreach (var version in apiversion.Split('|'))
            {
                // Translate each delegate:
                // 1st using the <replace> elements in overrides.xml
                // 2nd using the hardcoded rules in FuncProcessor (e.g. char* -> string)
                foreach (var signatures in delegates.Values)
                {
                    foreach (var d in signatures)
                    {
                        var replace = GetFuncOverride(nav, d, apiname, apiversion);
                        TranslateExtension(d);
                        TranslateReturnType(d, replace, nav, enum_processor, enums, apiname, version);
                        TranslateParameters(d, replace, nav, enum_processor, enums, apiname, version);
                        TranslateAttributes(d, replace, nav, apiname, version);
                    }
                }

                // Create overloads for backwards compatibility,
                // by resolving <overload> elements
                var overload_list = new List<Delegate>();
                foreach (var d in delegates.Values.Select(v => v.First()))
                {
                    var overload_elements = GetFuncOverload(nav, d, apiname, apiversion);
                    foreach (XPathNavigator overload_element in overload_elements)
                    {
                        var overload = new Delegate(d);
                        TranslateReturnType(overload, overload_element, nav, enum_processor, enums, apiname, version);
                        TranslateParameters(overload, overload_element, nav, enum_processor, enums, apiname, version);
                        TranslateAttributes(overload, overload_element, nav, apiname, version);
                        overload_list.Add(overload);
                    }
                }
                foreach (var overload in overload_list)
                {
                    delegates.Add(overload);
                }
            }

            Console.WriteLine("Generating wrappers.");
            var wrappers = CreateWrappers(delegates, enums);

            Console.WriteLine("Generating convenience overloads.");
            wrappers.AddRange(CreateConvenienceOverloads(wrappers));

            Console.WriteLine("Generating CLS compliant overloads.");
            wrappers = CreateCLSCompliantWrappers(wrappers, enums);

            Console.WriteLine("Removing non-CLS compliant duplicates.");
            wrappers = MarkCLSCompliance(wrappers);

            Console.WriteLine("Removing overloaded delegates.");
            RemoveOverloadedDelegates(delegates, wrappers);

            Console.WriteLine("Generating address table.");
            GenerateAddressTable(delegates);

            Console.WriteLine("Generating documentation.");
            GenerateDocumentation(wrappers, enum_processor, doc_processor);

            return wrappers;
        }
Beispiel #13
0
        public virtual DelegateCollection ReadDelegates(StreamReader specFile)
        {
            Console.WriteLine("Reading function specs.");

            DelegateCollection delegates = new DelegateCollection();

            XPathDocument function_overrides = new XPathDocument(Path.Combine(Settings.InputPath, functionOverridesFile));

            do
            {
                string line = NextValidLine(specFile);
                if (String.IsNullOrEmpty(line))
                {
                    break;
                }

                while (line.Contains("(") && !specFile.EndOfStream)
                {
                    // Get next OpenGL function

                    Delegate d = new Delegate();

                    // Get function name:
                    d.Name = line.Split(Utilities.Separators, StringSplitOptions.RemoveEmptyEntries)[0];

                    do
                    {
                        // Get function parameters and return value

                        line = specFile.ReadLine();
                        List <string> words = new List <string>(
                            line.Replace('\t', ' ').Split(Utilities.Separators, StringSplitOptions.RemoveEmptyEntries)
                            );

                        if (words.Count == 0)
                        {
                            break;
                        }

                        // Identify line:
                        switch (words[0])
                        {
                        case "return":      // Line denotes return value
                            d.ReturnType.CurrentType = words[1];
                            break;

                        case "param":       // Line denotes parameter
                            Parameter p = new Parameter();

                            p.Name        = Utilities.Keywords.Contains(words[1]) ? "@" + words[1] : words[1];
                            p.CurrentType = words[2];
                            p.Pointer    += words[4].Contains("array") ? 1 : 0;
                            p.Pointer    += words[4].Contains("reference") ? 1 : 0;
                            if (p.Pointer != 0 && words.Count > 5 && words[5].Contains("[1]"))
                            {
                                p.ElementCount = 1;
                            }
                            p.Flow = words[3] == "in" ? FlowDirection.In : FlowDirection.Out;

                            d.Parameters.Add(p);
                            break;

                        // GetTexParameterIivEXT and GetTexParameterIuivEXT define two(!) versions (why?)
                        case "version":     // Line denotes function version (i.e. 1.0, 1.2, 1.5)
                            d.Version = words[1];
                            break;

                        case "category":
                            d.Category = words[1];
                            break;
                        }
                    }while (!specFile.EndOfStream);

                    d.Translate(function_overrides);

                    delegates.Add(d);
                }
            }while (!specFile.EndOfStream);

            return(delegates);
        }
Beispiel #14
0
        DelegateCollection ReadDelegates(XPathNavigator specs, string apiversion)
        {
            DelegateCollection delegates = new DelegateCollection();
            var extensions = new List<string>();

            string path = "function";
            foreach (XPathNavigator node in specs.SelectChildren(path, String.Empty))
            {
                var name = node.GetAttribute("name", String.Empty).Trim();
                var version = node.GetAttribute("version", String.Empty).Trim();

                // Ignore functions that have a higher version number than
                // our current apiversion. Extensions do not have a version,
                // so we add them anyway (which is desirable).
                if (!String.IsNullOrEmpty(version) && !String.IsNullOrEmpty(apiversion) &&
                    Decimal.Parse(version) > Decimal.Parse(apiversion))
                    continue;

                // Check whether we are adding to an existing delegate or creating a new one.
                var d = new Delegate
                {
                    Name = name,
                    EntryPoint = name,
                    Version = node.GetAttribute("version", String.Empty).Trim(),
                    Category = node.GetAttribute("category", String.Empty).Trim(),
                    DeprecatedVersion = node.GetAttribute("deprecated", String.Empty).Trim(),
                    Deprecated = !String.IsNullOrEmpty(node.GetAttribute("deprecated", String.Empty)),
                    Extension = node.GetAttribute("extension", String.Empty).Trim() ?? "Core",
                    Obsolete = node.GetAttribute("obsolete", String.Empty).Trim()
                };
                if (!extensions.Contains(d.Extension))
                    extensions.Add(d.Extension);

                foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
                {
                    switch (param.Name)
                    {
                        case "returns":
                            d.ReturnType.CurrentType = param.GetAttribute("type", String.Empty).Trim();
                            break;

                        case "param":
                            Parameter p = new Parameter();
                            p.CurrentType = param.GetAttribute("type", String.Empty).Trim();
                            p.Name = param.GetAttribute("name", String.Empty).Trim();

                            string element_count = param.GetAttribute("elementcount", String.Empty).Trim();
                            if (String.IsNullOrEmpty(element_count))
                            {
                                element_count = param.GetAttribute("count", String.Empty).Trim();
                                if (!String.IsNullOrEmpty(element_count))
                                {
                                    int count;
                                    if (Int32.TryParse(element_count, out count))
                                    {
                                        p.ElementCount = count;
                                    }
                                }
                            }

                            p.Flow = Parameter.GetFlowDirection(param.GetAttribute("flow", String.Empty).Trim());

                            d.Parameters.Add(p);
                            break;
                    }
                }

                delegates.Add(d);
            }

            Utilities.InitExtensions(extensions);
            return delegates;
        }
Beispiel #15
0
        public FunctionCollection Process(EnumProcessor enum_processor, DelegateCollection delegates, EnumCollection enums,
                                          string apiname, string apiversion)
        {
            Console.WriteLine("Processing delegates.");
            var nav = new XPathDocument(Overrides).CreateNavigator();

            foreach (var version in apiversion.Split('|'))
            {
                // Translate each delegate:
                // 1st using the <replace> elements in overrides.xml
                // 2nd using the hardcoded rules in FuncProcessor (e.g. char* -> string)
                foreach (var signatures in delegates.Values)
                {
                    foreach (var d in signatures)
                    {
                        var replace = GetFuncOverride(nav, d, apiname, apiversion);

                        TranslateExtension(d);
                        TranslateReturnType(d, replace, nav, enum_processor, enums, apiname, version);
                        TranslateParameters(d, replace, nav, enum_processor, enums, apiname, version);
                        TranslateAttributes(d, replace, nav, apiname, version);
                    }
                }

                // Create overloads for backwards compatibility,
                // by resolving <overload> elements
                var overload_list = new List <Delegate>();
                foreach (var d in delegates.Values.Select(v => v.First()))
                {
                    var overload_elements = GetFuncOverload(nav, d, apiname, apiversion);
                    foreach (XPathNavigator overload_element in overload_elements)
                    {
                        var overload = new Delegate(d);
                        TranslateReturnType(overload, overload_element, nav, enum_processor, enums, apiname, version);
                        TranslateParameters(overload, overload_element, nav, enum_processor, enums, apiname, version);
                        TranslateAttributes(overload, overload_element, nav, apiname, version);
                        overload_list.Add(overload);
                    }
                }
                foreach (var overload in overload_list)
                {
                    delegates.Add(overload);
                }
            }

            Console.WriteLine("Generating convenience overloads.");
            delegates.AddRange(CreateConvenienceOverloads(delegates));

            Console.WriteLine("Generating wrappers.");
            var wrappers = CreateWrappers(delegates, enums);

            Console.WriteLine("Generating CLS compliant overloads.");
            wrappers = CreateCLSCompliantWrappers(wrappers, enums);

            Console.WriteLine("Removing non-CLS compliant duplicates.");
            wrappers = MarkCLSCompliance(wrappers);

            Console.WriteLine("Removing overloaded delegates.");
            RemoveOverloadedDelegates(delegates, wrappers);

            return(wrappers);
        }
Beispiel #16
0
        public virtual DelegateCollection ReadDelegates(StreamReader specFile)
        {
            Console.WriteLine("Reading function specs.");

            //List<Bind.Structures.Delegate> delegates = new List<Bind.Structures.Delegate>();
            DelegateCollection delegates = new DelegateCollection();

            do
            {
                string line = NextValidLine(specFile);
                if (String.IsNullOrEmpty(line))
                {
                    break;
                }

                while (line.Contains("(") && !specFile.EndOfStream)
                {
                    // Get next OpenGL function

                    Bind.Structures.Delegate d = new Bind.Structures.Delegate();

                    // Get function name:
                    d.Name = line.Split(Utilities.Separators, StringSplitOptions.RemoveEmptyEntries)[0];

                    //if (d.Name.Contains("QueryHyperpipeBestAttribSGIX"))
                    //{
                    //}

                    do
                    {
                        // Get function parameters and return value

                        line = specFile.ReadLine();
                        List <string> words = new List <string>(
                            line.Replace('\t', ' ').Split(Utilities.Separators, StringSplitOptions.RemoveEmptyEntries)
                            );

                        if (words.Count == 0)
                        {
                            break;
                        }

                        // Identify line:
                        switch (words[0])
                        {
                        case "return":      // Line denotes return value
                            d.ReturnType.CurrentType = words[1];
                            break;

                        case "param":       // Line denotes parameter
                            Parameter p = new Parameter();

                            p.Name        = Utilities.Keywords.Contains(words[1]) ? "@" + words[1] : words[1];
                            p.CurrentType = words[2];
                            p.Pointer     = words[4].Contains("array") ? true : words[4].Contains("reference") ? true : false;
                            p.Flow        = words[3] == "in" ? Parameter.FlowDirection.In : Parameter.FlowDirection.Out;

                            d.Parameters.Add(p);
                            break;

                        // Version directive is not used. GetTexParameterIivEXT and GetTexParameterIuivEXT define two(!) versions (why?)
                        //case "version": // Line denotes function version (i.e. 1.0, 1.2, 1.5)
                        //    d.UserData.Add("version", words[1]);
                        //    break;

                        case "category":
                            d.Category = words[1];
                            break;
                        }
                    }while (!specFile.EndOfStream);

                    d.Translate();

                    delegates.Add(d);
                }
            }while (!specFile.EndOfStream);

            return(delegates);
        }