Пример #1
0
        public bool TryMatch(string name, MatcherKind kind, out TargetTemplate tmpl, IWarningLogger log)
        {
            tmpl = null;
            IMatcher which   = null;
            int      quality = 0;

            IEnumerable <IMatcher> mlist = GetMatchers(kind, log);

            if (mlist == null)
            {
                return(true);
            }

            foreach (IMatcher m in mlist)
            {
                int            q;
                TargetTemplate match = m.TryMatch(name, out q);

                if (match == null)
                {
                    continue;
                }

                if (q < quality)
                {
                    continue;
                }

                if (tmpl != null && q == quality)
                {
                    // FIXME: provide a way to specify which one should take priority!
                    string s = String.Format("Two matches succeed with equal quality: " +
                                             "{0} and {1}; going with the first",
                                             which, m);
                    log.Warning(2026, s, name);
                    break;
                }

                which   = m;
                tmpl    = match;
                quality = q;
            }

            return(false);
        }
Пример #2
0
	public bool TryMatch (string name, MatcherKind kind, out TargetTemplate tmpl, IWarningLogger log) 
	{
	    tmpl = null;
	    IMatcher which = null;
	    int quality = 0;
	    
	    IEnumerable<IMatcher> mlist = GetMatchers (kind, log);

	    if (mlist == null)
		return true;

	    foreach (IMatcher m in mlist) {
		int q;
		TargetTemplate match = m.TryMatch (name, out q);

		if (match == null)
		    continue;
		
		if (q < quality)
		    continue;
		
		if (tmpl != null && q == quality) {
		    // FIXME: provide a way to specify which one should take priority!
		    string s = String.Format ("Two matches succeed with equal quality: " + 
		    			      "{0} and {1}; going with the first",
		    			      which, m);
		    log.Warning (2026, s, name);
		    break;
		}
		
		which = m;
		tmpl = match;
		quality = q;
	    }
	    
	    return false;
	}
Пример #3
0
	public abstract bool ResolveName (string name, out TargetTemplate tmpl, IWarningLogger log);
Пример #4
0
 public abstract bool ResolveName(string name, out TargetTemplate tmpl, IWarningLogger log);
Пример #5
0
	// Rule template helpers

	public bool GetTemplateForRule (string ns, Type rtype, out TargetTemplate ttmpl, IWarningLogger log)
	{
	    ttmpl = null;

	    StructureTemplate stmpl = GetNamespaceTemplate (ns, log);

	    if (stmpl == null || !sused[ns]) {
		log.Error (9999, "Trying to use structure template of namespace " +
			   ns + ", but either it wasn't defined or it hasn't been " +
			   "initialized yet.", null);
		return true;
	    }

	    // See if we can find a type that has a StructureBinding to tmpl
	    // and a RuleBinding to rtype.

	    string pns = MBuildPrefix + ns;
	    Type ttype = null, stype = stmpl.GetType ();

	    foreach (Assembly assy in BundleAssemblies) {
		foreach (Type t in assy.GetExportedTypes ()) {
		    if (t.Namespace != pns)
			continue;

		    if (!t.IsSubclassOf (typeof (TargetTemplate)))
			continue;

		    object[] attrs = t.GetCustomAttributes (typeof (StructureBindingAttribute), false);

		    if (attrs.Length == 0)
			continue;

		    StructureBindingAttribute sba = (StructureBindingAttribute) attrs[0];

		    if (sba.StructureType == null)
			continue;

		    if (!sba.StructureType.Equals (stype))
			continue;

		    attrs = t.GetCustomAttributes (typeof (RuleBindingAttribute), false);

		    if (attrs.Length == 0)
			continue;

		    if (!((RuleBindingAttribute) attrs[0]).RuleType.Equals (rtype))
			continue;

		    if (ttype != null) {
			log.Warning (9999, "Two hits for rule template: " + ttype.ToString () +
				     " and " + t.ToString (), rtype.ToString ());
		    }

		    ttype = t;
		}
	    }

	    if (ttype != null)
		ttmpl = (TargetTemplate) Activator.CreateInstance (ttype, stmpl);

	    return false;
	}
Пример #6
0
	public override bool ResolveName (string name, out TargetTemplate tmpl, IWarningLogger log) 
	{
	    tmpl = null;

	    Type t;

	    if (ResolveType (name, out t, log))
		return true;

	    if (t.IsSubclassOf (typeof (Rule))) {
		Type t2 = TemplateForRule (t, log);

		if (t2 == null) {
		    // So yeah this is kinda dumb namespacing.
		    tmpl = new Mono.Build.RuleLib.RegexMatcher.RuleOnlyTemplate (t);
		    return false;
		}

		t = t2;
	    }

	    if (!t.IsSubclassOf (typeof (TargetTemplate))) {
		string s = String.Format ("Type {0} (resolved from {1}) should be a TargetTemplate but isn't",
					  t.FullName, name);
		log.Error (2022, s, null);
		return true;
	    }

	    object o;

	    if (InstantiateBoundType (t, out o, log))
		return true;

	    tmpl = (TargetTemplate) o;
	    return false;
	}
Пример #7
0
        // Rule template helpers

        public bool GetTemplateForRule(string ns, Type rtype, out TargetTemplate ttmpl, IWarningLogger log)
        {
            ttmpl = null;

            StructureTemplate stmpl = GetNamespaceTemplate(ns, log);

            if (stmpl == null || !sused[ns])
            {
                log.Error(9999, "Trying to use structure template of namespace " +
                          ns + ", but either it wasn't defined or it hasn't been " +
                          "initialized yet.", null);
                return(true);
            }

            // See if we can find a type that has a StructureBinding to tmpl
            // and a RuleBinding to rtype.

            string pns = MBuildPrefix + ns;
            Type   ttype = null, stype = stmpl.GetType();

            foreach (Assembly assy in BundleAssemblies)
            {
                foreach (Type t in assy.GetExportedTypes())
                {
                    if (t.Namespace != pns)
                    {
                        continue;
                    }

                    if (!t.IsSubclassOf(typeof(TargetTemplate)))
                    {
                        continue;
                    }

                    object[] attrs = t.GetCustomAttributes(typeof(StructureBindingAttribute), false);

                    if (attrs.Length == 0)
                    {
                        continue;
                    }

                    StructureBindingAttribute sba = (StructureBindingAttribute)attrs[0];

                    if (sba.StructureType == null)
                    {
                        continue;
                    }

                    if (!sba.StructureType.Equals(stype))
                    {
                        continue;
                    }

                    attrs = t.GetCustomAttributes(typeof(RuleBindingAttribute), false);

                    if (attrs.Length == 0)
                    {
                        continue;
                    }

                    if (!((RuleBindingAttribute)attrs[0]).RuleType.Equals(rtype))
                    {
                        continue;
                    }

                    if (ttype != null)
                    {
                        log.Warning(9999, "Two hits for rule template: " + ttype.ToString() +
                                    " and " + t.ToString(), rtype.ToString());
                    }

                    ttype = t;
                }
            }

            if (ttype != null)
            {
                ttmpl = (TargetTemplate)Activator.CreateInstance(ttype, stmpl);
            }

            return(false);
        }