예제 #1
0
        // key: Enum name
        // value: Dictionary:
        //	key: enum element name
        //	value: enum element value
        internal Dictionary <string, EnumDescription> ParseFieldMappings(TextReader source, string [] enumFlags, int filter_version, IList <KeyValuePair <string, string> > remove_nodes)
        {
            var enums = new Dictionary <string, EnumDescription> ();

            if (source == null)
            {
                return(enums);
            }
            bool transient = false;

            string          s;
            string          last_enum       = null;
            EnumDescription enumDescription = null;

            while ((s = source.ReadLine()) != null)
            {
                try {
                    if (string.IsNullOrEmpty(s) || s.StartsWith("//"))
                    {
                        continue;
                    }
                    if (s == "- ENTER TRANSIENT MODE -")
                    {
                        transient = true;
                        continue;
                    }

                    string[] pieces = s.Split(',');

                    string verstr    = pieces[0].Trim();
                    string enu       = pieces[1].Trim();
                    string member    = pieces[2].Trim();
                    string java_name = pieces[3].Trim();
                    string value     = pieces[4].Trim();

                    if (filter_version > 0 && filter_version < int.Parse(verstr))
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(java_name.Trim()))
                    {
                        remove_nodes.Add(new KeyValuePair <string, string> (java_name.Trim(), transient ? enu : null));
                    }

                    // This is a line that only deletes a const, not maps it to an enum
                    if (string.IsNullOrEmpty(enu))
                    {
                        continue;
                    }

                    // If this is a new enum, add the old one and reset things
                    if (last_enum != enu)
                    {
                        if (last_enum != null)
                        {
                            enums.Add(last_enum, enumDescription);
                        }

                        last_enum       = enu;
                        enumDescription = new EnumDescription()
                        {
                            FieldsRemoved = !transient
                        };
                    }

                    if (pieces.Length > 5)
                    {
                        enumDescription.BitField = pieces [5].Trim() == "Flags";
                    }

                    if (enumFlags != null && enumFlags.Contains(enu))
                    {
                        enumDescription.BitField = true;
                    }

                    // Add this member to the enum
                    enumDescription.Members.Add(member, value);
                    enumDescription.JniNames.Add(member, java_name);
                } catch (Exception ex) {
                    Report.Error(Report.ErrorEnumMapping + 0, "ERROR at parsing enum " + s, ex);
                    throw;
                }
            }

            // Make sure the last enum gets added to the list
            if (last_enum != null)
            {
                enums.Add(last_enum, enumDescription);
            }

            return(enums);
        }