// // (c) 2009, Sigbjorn Finne // using System; using System.Collections; using System.Text.RegularExpressions; namespace HsWrap { public class Blacklist { protected System.Collections.Hashtable m_knownTypes; protected System.Collections.ArrayList m_ignorePats; protected System.Collections.ArrayList m_typePath; protected String m_prefix; public Blacklist() { m_knownTypes = new System.Collections.Hashtable(); m_ignorePats = new System.Collections.ArrayList(); m_typePath = new System.Collections.ArrayList(); m_prefix = "NET."; m_typePath.Add(""); } public String ClassPrefix { get { return m_prefix; } set { m_prefix = value; } } public void AddTypePath(String s) { m_typePath.Add(s); } public void AddIgnorePattern(String p) { String p1 = p; if ( p.StartsWith(m_prefix) ) { p1 = p.Substring(m_prefix.Length); } m_ignorePats.Add(p1); } public void AddType(String t, bool ignoreIt) { String p1 = t; if ( t.StartsWith(m_prefix) ) { p1 = t.Substring(m_prefix.Length); } if ( !m_knownTypes.Contains(p1) ) { m_knownTypes.Add(p1,ignoreIt); } } public void IgnoreType(String t) { AddType(t,false); } public void AllowType(String t) { AddType(t,true); } // // Returns 'true' iff it's already known or it can be // reached along the type search path. // public bool IsTypeKnown(String t) { if ( m_knownTypes.Contains(t) ) { return true; } if ( t.StartsWith(m_prefix) && m_knownTypes.Contains(t.Substring(m_prefix.Length)) ) { return true; } String fn = t.Replace('.','\\') + ".hs"; foreach (String s in m_typePath) { String f = (s == "" ? fn : ( s.EndsWith("\\") ? (s + fn) : s + "\\" + fn)); if ( Config.FileExists(f) ) { return true; } } return false; } public bool DoesTypeExist(String t) { if ( t.StartsWith(m_prefix) ) { t = t.Substring(m_prefix.Length); } String fn = t.Replace('.','\\') + ".hs"; if (Config.FileExists(fn) ) { return true; } foreach (String s in m_typePath) { String f = (s == "" ? fn : ( s.EndsWith("\\") ? (s + fn) : s + "\\" + fn)); if ( Config.FileExists(f) ) { return true; } } return false; } public bool IsTypeOfInterest(String t) { return IsTypeOfInterest(t,true); } public bool IsTypeOfInterest(String t, bool addIt) { String ty = t; if ( t.StartsWith(m_prefix) ) { ty = t.Substring(m_prefix.Length); } if ( m_knownTypes.Contains(ty) ) { return (bool)(m_knownTypes[ty]); } foreach (String s in m_ignorePats) { Regex r = new Regex(s); // ToDo: stored the compiled Regex? if ( r.IsMatch(ty) ) { if (addIt) { AddType(ty,false); } return false; } } return true; } public void ShowKnownTypes() { foreach(DictionaryEntry kv in m_knownTypes) { Console.WriteLine("{0}", kv.Key); } } }; }