예제 #1
0
        public NamespaceBuilder(string sname, TypeResolveContext ctxt)
        {
            if (sname == null)
            {
                throw new ArgumentNullException("sname");
            }
            if (ctxt == null)
            {
                throw new ArgumentNullException("ctxt");
            }

            this.sname = sname;

            trc = ctxt;
            trc.SetNamespace(RealName);

            Type t = ctxt.Driver.LookupExistingFQN(StructureName);

            if (t != null)
            {
                paramstype = new UserType(t);
                nsparams   = new ExistingNamespaceParams(t);
            }
            else
            {
                paramstype = new UserType(StructureName);
                // will be defined either by parameters {} or at end
                // of parsing the namespace.
                // FIXME: if we have two separate namespace {} sections,
                // I think they will both make their own StructureBuilder
                // instance, and those will clash.
                nsparams = null;
            }
        }
예제 #2
0
        // General

        public override bool Resolve(TypeResolveContext trc, bool errors)
        {
            bool ret = base.Resolve(trc, errors);

            if (bf_ret_class != null)
            {
                // Null if rule doesn't have a build func of its
                // own (eg, it inherits)
                ret |= bf_ret_class.Resolve(trc, errors);

                if (errors && OverrideResultType != null)
                {
                    Console.Error.WriteLine("Can't have a build function and separately " +
                                            "specify a general result type in {0}", ClassName);
                    return(true);
                }
            }

            if (OverrideResultType != null)
            {
                ret |= OverrideResultType.Resolve(trc, errors);
            }

            for (int i = 0; i < arguments.Count; i++)
            {
                ret |= arguments[i].Resolve(trc, errors);
            }

            return(ret);
        }
예제 #3
0
	public NamespaceBuilder (string sname, TypeResolveContext ctxt)
	{
	    if (sname == null)
		throw new ArgumentNullException ("sname");
	    if (ctxt == null)
		throw new ArgumentNullException ("ctxt");

	    this.sname = sname;

	    trc = ctxt;
	    trc.SetNamespace (RealName);

	    Type t = ctxt.Driver.LookupExistingFQN (StructureName);

	    if (t != null) {
		paramstype = new UserType (t);
		nsparams = new ExistingNamespaceParams (t);
	    } else {
		paramstype = new UserType (StructureName);
		// will be defined either by parameters {} or at end
		// of parsing the namespace.
		// FIXME: if we have two separate namespace {} sections,
		// I think they will both make their own StructureBuilder
		// instance, and those will clash.
		nsparams = null; 
	    }
	}
예제 #4
0
파일: UserType.cs 프로젝트: emtees/old-code
	public bool Resolve (TypeResolveContext trc, bool errors)
	{
	    if (resolved)
		return false;

	    if (IsUser) {
	        UserType newval = trc.Resolve ((string) t, errors);

		if (newval == null) {
		    if (errors)
			Console.Error.WriteLine ("Failed to resolve type {0}", t);
		    return true;
		}

		this.t = newval.t;
	    }

	    if (typeargs != null) {
		bool ret = false;

		foreach (UserType ut in typeargs)
		    ret |= ut.Resolve (trc, errors);

		if (ret)
		    return ret;
	    }

	    resolved = true;
	    return false;
	}
예제 #5
0
        public virtual bool Resolve(TypeResolveContext trc, bool errors)
        {
            if (!registered)
            {
                trc.Driver.DefineUserType(FullName, this);
                registered = true;
            }

            if (errors && baseclass == null)
            {
                Console.Error.WriteLine("No base class set for item {0}", this);
                return(true);
            }

            bool ret = baseclass.Resolve(trc, errors);

            if (implements != null)
            {
                foreach (UserType ut in implements)
                {
                    ret |= ut.Resolve(trc, errors);
                }
            }

            return(ret);
        }
예제 #6
0
	public bool Resolve (TypeResolveContext trc, bool errors)
	{
	    if (BaseClass.ResolveExtension ("RTemplate", trc, errors))
		return true;

	    bool? ret = BaseClass.ResolvesAsRule (trc, errors);
	    if (ret == null)
		return true;

	    if ((bool) ret) {
		// We derive from a Rule. Our Template's base class
		// should be the default TargetTemplate. The rule's
		// BaseClass is our BaseClass.
		rb.BaseClass = BaseClass;
		return false;
	    }

	    UserType rule = BaseClass.ResolveBoundRuleType (trc, errors);
	    if (rule == null) {
		Console.Error.WriteLine ("Rule baseclass {0} of {1} is not either a rule " + 
					 "or a rule-bound template", BaseClass, this);
		return true;
	    }

	    rb.BaseClass = rule;
	    tmpl.BaseClass = BaseClass;
	    return false;
	}
예제 #7
0
파일: UserType.cs 프로젝트: retahc/old-code
        public bool ResolveExtension(string ext, TypeResolveContext trc, bool errors)
        {
            if (errors && typeargs != null)
            {
                // Don't want to think about how this should be handled.
                throw new InvalidOperationException();
            }

            string exname;

            if (IsUser)
            {
                exname = ((string)t) + ext;
            }
            else
            {
                exname = ((Type)t).FullName + ext;
            }

            UserType exval = trc.Resolve(exname, false);

            if (exval != null)
            {
                this.t   = exval.t;
                resolved = true;
                return(false);
            }

            return(Resolve(trc, errors));
        }
예제 #8
0
	public override bool Resolve (TypeResolveContext trc, bool errors)
	{
	    if (base.Resolve (trc, errors))
		return true;

	    RuleType = rb.ResolveSelfType (trc, errors);
	    return (RuleType == null);
	}
예제 #9
0
	// Setup

	public bool Resolve (TypeResolveContext trc, bool errors)
	{
	    // We need to resolve the rule as a template now, rather
	    // than letting NameLookupContext do it, because NLC will
	    // be operating with an undefined set of 'usings', and
	    // probably won't be able to find the RTemplate associated
	    // with the rule.

	    if (Rule.ResolveExtension ("RTemplate", trc, errors))
		return true;

	    // Now we need to check that, if we have a template that
	    // uses a structure, that our provider can access such 
	    // a structure, so that the template can actually be 
	    // instantiated.
	    //
	    // FIXME: This code is exactly parallel to 
	    // StructureBoundItem.ContextualStructRef.

	    UserType ttmpl = Rule.ResolveUsedStructureType (trc, errors);

	    if (ttmpl == null)
		// Great, it's doesn't use anything, so whatever.
		return false;

	    // XXX shouldn't apply anymore -- unbound providers are now impossible.
	    // Would they have ever been useful?
	    //
	    //if (prov.Structure == null) {
	    //if (errors)
	    //	    Console.Error.WriteLine ("Target {0} in provider {1} references rule {2} that " +
	    //			     "is bound to structure {3}, but the provider is not " +
	    //			     "bound to a structure and so can provide no context",
	    //			     this, prov, Rule, ttmpl);
	    //return true;
	    //}

	    if (ttmpl.Equals (prov.NS.ParamsType))
		// It just depends on our containing structure. No problem.
		return false;

	    foreach (string param in prov.Structure.Parameters) {
		if (prov.Structure[param] != StructureParameterKind.Structure)
		    continue;

		if (ttmpl.Equals (prov.Structure.StructParamType (param)))
		    return false;
	    }

	    if (errors)
		// WORST ERROR MESSAGE EVAR
		Console.Error.WriteLine ("Target {0} in provider {1} references rule {2} that " +
					 "is bound to structure {3}, but the provider's containing " +
					 "structure {4} does not have an argument referencing that structure. " +
					 "You probably need to add another parameter to the containing structure.",
					 this, prov, Rule, ttmpl, prov.Structure);
	    return true;
	}
예제 #10
0
	public override bool Resolve (TypeResolveContext trc, bool errors)
	{
	    bool ret = false;

	    foreach (BGTargetBuilder tb in targs)
		ret |= tb.Resolve (trc, errors);

	    return ret;
	}
예제 #11
0
        public override bool Resolve(TypeResolveContext trc, bool errors)
        {
            if (base.Resolve(trc, errors))
            {
                return(true);
            }

            RuleType = rb.ResolveSelfType(trc, errors);
            return(RuleType == null);
        }
예제 #12
0
파일: UserType.cs 프로젝트: retahc/old-code
        public UserType ResolveBoundRuleType(TypeResolveContext trc, bool errors)
        {
            if (!resolved)
            {
                if (errors)
                {
                    throw new InvalidOperationException();
                }
                return(null);
            }

            UserType ret;

            if (IsUser)
            {
                // User type. Use our lookup tables

                RuleTemplateBuilder rtb = trc.Driver.GetUserTypeItem((string)t) as RuleTemplateBuilder;

                if (errors && rtb == null)
                {
                    throw ExHelp.App("Expected a rule template but got {0} for {1}",
                                     trc.Driver.GetUserTypeItem((string)t), this);
                }

                ret = new UserType(rtb.Rule.FullName);
            }
            else
            {
                // System type. Use reflection.

                Type type = (Type)t;

                object[] attrs = type.GetCustomAttributes(typeof(RuleBindingAttribute), false);

                if (errors && attrs.Length == 0)
                {
                    throw ExHelp.App("Expected type {0} to have a RuleBindingAttribute " +
                                     "but it didn't. This type is not allowed to be a rule baseclass.", type);
                }

                ret = new UserType(((RuleBindingAttribute)attrs[0]).RuleType);
            }

            if (ret.Resolve(trc, errors))
            {
                if (errors)
                {
                    throw ExHelp.App("Failed to resolve bound rule type {0}", ret);
                }
                return(null);
            }

            return(ret);
        }
예제 #13
0
        public override bool Resolve(TypeResolveContext trc, bool errors)
        {
            bool ret = false;

            foreach (BGTargetBuilder tb in targs)
            {
                ret |= tb.Resolve(trc, errors);
            }

            return(ret);
        }
예제 #14
0
        // General

        public override bool Resolve(TypeResolveContext trc, bool errors)
        {
            bool ret = base.Resolve(trc, errors);

            foreach (FieldInfo fi in fields)
            {
                ret |= fi.Type.Resolve(trc, errors);
            }

            return(ret);
        }
예제 #15
0
        public UserType ResolveSelfType(TypeResolveContext trc, bool errors)
        {
            UserType ut = new UserType(FullName);

            if (ut.Resolve(trc, errors) && errors)
            {
                throw ExHelp.App("Failed to resolve SelfType of {0}?", this);
            }

            return(ut);
        }
예제 #16
0
        public override bool Resolve(TypeResolveContext trc, bool errors)
        {
            bool res = base.Resolve (trc, errors);

            foreach (StructureElement elt in elts)
            res |= elt.Resolve (trc, errors);
            foreach (UserType ut in structtypes.Values)
            res |= ut.Resolve (trc, errors);

            return res;
        }
예제 #17
0
	public override bool Resolve (TypeResolveContext trc, bool errors)
	{
	    bool ret = base.Resolve (trc, errors);
	    ret |= MatchType.ResolveExtension ("RTemplate", trc, errors);

	    // RegexMatcher will handle distinguishing between when
	    // we return a Rule type and a TargetTemplate type, but we need
	    // to check if we require a binding.

	    bool? foo = MatchType.ResolvesAsRule (trc, errors);

	    if (foo == null)
		// MatchType unresolved, can't say.
		return true;

	    if ((bool) foo) {
		// We point to a Rule, and ResolveUsedStructureType will
		// complain if we call it on MatchType.

		if (UsesStructure)
		    throw ExHelp.App ("Odd, MatcherBuilder {0} is using its structure" +
				      "even though it points to a plain rule {1}", this,
				      MatchType);

		return false;
	    }

	    // We have a template, so see if it uses a structure

	    UserType stype = MatchType.ResolveUsedStructureType (trc, errors);

	    if (errors) {
		if (stype == null && UsesStructure) {
		    // XXX is this actually an error? Shouldn't happen, I think.
		    Console.Error.WriteLine ("Matcher {0} is bound to structure {1} but its " +
					     "associated template {2} is unbound", this, 
					     Params, MatchType);
		    return true;
		} else if (stype != null && !UsesStructure) {
		    UseStructure ();
		} else if (stype != null && !NS.ParamsType.Equals (stype)) {
		    // FIXME: see if Structure has a member of type stype.
		    Console.Error.WriteLine ("Matcher {0} is bound to the structure {1}  but its " +
					     "associated template {2} is bound to {3}", this, 
					     Params, MatchType, stype);
		    return true;
		}
	    }

	    return ret;
	}
예제 #18
0
	public override bool Resolve (TypeResolveContext trc, bool errors)
	{
	    if (base.Resolve (trc, errors))
		return true;

	    UserType t = BaseClass.ResolveUsedStructureType (trc, errors);

	    if (t != null)
		// If our base class needs a structure, we need our
		// structure.
		uses_structure = true;

	    return false;
	}
예제 #19
0
	public override bool Resolve (TypeResolveContext trc, bool errors)
	{
	    if (base.Resolve (trc, errors))
		return true;

	    if (RuleType != null)
		if (RuleType.Resolve (trc, errors))
		    return true;

	    if (BaseClass.Equals (TTType))
		return false;
	    
	    basestruct = BaseClass.ResolveUsedStructureType (trc, errors);
	    return false;
	}
예제 #20
0
        public override bool Resolve(TypeResolveContext trc, bool errors)
        {
            if (base.Resolve(trc, errors))
            {
                return(true);
            }

            UserType t = BaseClass.ResolveUsedStructureType(trc, errors);

            if (t != null)
            {
                // If our base class needs a structure, we need our
                // structure.
                uses_structure = true;
            }

            return(false);
        }
예제 #21
0
파일: UserType.cs 프로젝트: retahc/old-code
        public bool Resolve(TypeResolveContext trc, bool errors)
        {
            if (resolved)
            {
                return(false);
            }

            if (IsUser)
            {
                UserType newval = trc.Resolve((string)t, errors);

                if (newval == null)
                {
                    if (errors)
                    {
                        Console.Error.WriteLine("Failed to resolve type {0}", t);
                    }
                    return(true);
                }

                this.t = newval.t;
            }

            if (typeargs != null)
            {
                bool ret = false;

                foreach (UserType ut in typeargs)
                {
                    ret |= ut.Resolve(trc, errors);
                }

                if (ret)
                {
                    return(ret);
                }
            }

            resolved = true;
            return(false);
        }
예제 #22
0
            public bool Resolve(TypeResolveContext trc, bool errors)
            {
                if (Type.Resolve(trc, errors))
                {
                    return(true);
                }

                arg_class = Type.ResultConversion;

                if (arg_class == null)
                {
                    conv      = RuleArgConversion.None;
                    arg_class = Type;
                }
                else
                {
                    // The arg type is some primitive type (bool, string)
                    // that we must convert from a result wrapper

                    Type type = Type.AsSystem;

                    if (type == null)
                    {
                        throw new Exception("Can't handle convertible user types");
                    }

                    if (type.IsValueType)
                    {
                        conv = RuleArgConversion.ToValueType;
                    }
                    else
                    {
                        conv = RuleArgConversion.ToRefType;
                    }
                }

                return(arg_class.Resolve(trc, errors));
            }
예제 #23
0
파일: UserType.cs 프로젝트: retahc/old-code
        public bool?ResolvesAsRule(TypeResolveContext trc, bool errors)
        {
            if (!resolved)
            {
                if (errors)
                {
                    throw new InvalidOperationException();
                }
                return(null);
            }

            if (IsSystem)
            {
                // System type. Use reflection.
                return(typeof(Rule).IsAssignableFrom((Type)t));
            }

            // User type. Use our lookup tables

            TypeExpressedItem tei = trc.Driver.GetUserTypeItem((string)t);

            return(tei is RuleBuilder || tei is SourcefileRuleBuilder);
        }
예제 #24
0
        public override bool Resolve(TypeResolveContext trc, bool errors)
        {
            if (base.Resolve(trc, errors))
            {
                return(true);
            }

            if (RuleType != null)
            {
                if (RuleType.Resolve(trc, errors))
                {
                    return(true);
                }
            }

            if (BaseClass.Equals(TTType))
            {
                return(false);
            }

            basestruct = BaseClass.ResolveUsedStructureType(trc, errors);
            return(false);
        }
예제 #25
0
        public bool Resolve(TypeResolveContext trc, bool errors)
        {
            if (BaseClass.ResolveExtension("RTemplate", trc, errors))
            {
                return(true);
            }

            bool?ret = BaseClass.ResolvesAsRule(trc, errors);

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

            if ((bool)ret)
            {
                // We derive from a Rule. Our Template's base class
                // should be the default TargetTemplate. The rule's
                // BaseClass is our BaseClass.
                rb.BaseClass = BaseClass;
                return(false);
            }

            UserType rule = BaseClass.ResolveBoundRuleType(trc, errors);

            if (rule == null)
            {
                Console.Error.WriteLine("Rule baseclass {0} of {1} is not either a rule " +
                                        "or a rule-bound template", BaseClass, this);
                return(true);
            }

            rb.BaseClass   = rule;
            tmpl.BaseClass = BaseClass;
            return(false);
        }
예제 #26
0
	    public bool Resolve (TypeResolveContext trc, bool errors)
	    {
		if (Type.Resolve (trc, errors))
		    return true;

		arg_class = Type.ResultConversion;

		if (arg_class == null) {
		    conv = RuleArgConversion.None;
		    arg_class = Type;
		} else {
		    // The arg type is some primitive type (bool, string)
		    // that we must convert from a result wrapper

		    Type type = Type.AsSystem;

		    if (type == null)
			throw new Exception ("Can't handle convertible user types");

		    if (type.IsValueType)
			conv = RuleArgConversion.ToValueType;
		    else
			conv = RuleArgConversion.ToRefType;
		}

		return arg_class.Resolve (trc, errors);
	    }
예제 #27
0
 public abstract bool Resolve(TypeResolveContext trc, bool errors);
예제 #28
0
	public override bool Resolve (TypeResolveContext trc, bool errors)
	{
	    return base.Resolve (trc, errors) | ResultType.Resolve (trc, errors);
	}
예제 #29
0
	// General

	public override bool Resolve (TypeResolveContext trc, bool errors)
	{
	    bool ret = base.Resolve (trc, errors);

	    if (bf_ret_class != null) {
		// Null if rule doesn't have a build func of its
		// own (eg, it inherits)
		ret |= bf_ret_class.Resolve (trc, errors);

		if (errors && OverrideResultType != null) {
		    Console.Error.WriteLine ("Can't have a build function and separately " + 
					     "specify a general result type in {0}", ClassName);
		    return true;
		}
	    }

	    if (OverrideResultType != null)
		ret |= OverrideResultType.Resolve (trc, errors);

	    for (int i = 0; i < arguments.Count; i++)
		ret |= arguments[i].Resolve (trc, errors);

	    return ret;
	}
예제 #30
0
	public UserType ResolveSelfType (TypeResolveContext trc, bool errors)
	{
	    UserType ut = new UserType (FullName);

	    if (ut.Resolve (trc, errors) && errors)
		throw ExHelp.App ("Failed to resolve SelfType of {0}?", this);

	    return ut;
	}
예제 #31
0
파일: UserType.cs 프로젝트: emtees/old-code
	public UserType ResolveBoundRuleType (TypeResolveContext trc, bool errors)
	{
	    if (!resolved) {
		if (errors)
		    throw new InvalidOperationException ();
		return null;
	    }

	    UserType ret;

	    if (IsUser) {
		// User type. Use our lookup tables

		RuleTemplateBuilder rtb = trc.Driver.GetUserTypeItem ((string) t) as RuleTemplateBuilder;

		if (errors && rtb == null)
		    throw ExHelp.App ("Expected a rule template but got {0} for {1}",
				      trc.Driver.GetUserTypeItem ((string) t), this);

		ret = new UserType (rtb.Rule.FullName);
	    } else {
		// System type. Use reflection.

		Type type = (Type) t;

		object[] attrs = type.GetCustomAttributes (typeof (RuleBindingAttribute), false);

		if (errors && attrs.Length == 0)
		    throw ExHelp.App ("Expected type {0} to have a RuleBindingAttribute " +
				      "but it didn't. This type is not allowed to be a rule baseclass.", type);

		ret = new UserType (((RuleBindingAttribute) attrs[0]).RuleType);
	    }

	    if (ret.Resolve (trc, errors)) {
		if (errors)
		    throw ExHelp.App ("Failed to resolve bound rule type {0}", ret);
		return null;
	    }

	    return ret;
	}
예제 #32
0
	// General

	public override bool Resolve (TypeResolveContext trc, bool errors)
	{
	    bool ret = base.Resolve (trc, errors);

	    foreach (FieldInfo fi in fields)
		ret |= fi.Type.Resolve (trc, errors);

	    return ret;
	}
예제 #33
0
파일: UserType.cs 프로젝트: emtees/old-code
	public UserType ResolveUsedStructureType (TypeResolveContext trc, bool errors)
	{
	    if (!resolved) {
		if (errors)
		    throw new InvalidOperationException ();
		return null;
	    }

	    UserType ret;

	    if (IsUser) {
		// User type. Use our lookup tables

		StructureBoundItem sbi = trc.Driver.GetUserTypeItem ((string) t) as StructureBoundItem;

		if (sbi == null) {
		    if (errors)
			throw ExHelp.App ("Expected structure bound item but got {0} for {1}",
					  trc.Driver.GetUserTypeItem ((string) t), this);
		    return null;
		}

		if (!sbi.UsesStructure)
		    return null;

		ret = sbi.NS.ParamsType;
	    } else {
		// System type. Use reflection.

		Type type = (Type) t;

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

		if (attrs.Length == 0)
		    throw ExHelp.App ("Expected type {0} to have a StructureBindingAttribute " +
				      "but it didn't", type);

		StructureBindingAttribute attr = (StructureBindingAttribute) attrs[0];

		if (!attr.UsesStructure)
		    return null;

		ret = new UserType (attr.StructureType);
	    }

	    if (ret.Resolve (trc, errors)) {
		if (errors)
		    throw ExHelp.App ("Failed to resolve bound structure type {0}", ret);
		return null;
	    }

	    return ret;
	}
예제 #34
0
파일: UserType.cs 프로젝트: emtees/old-code
	public bool ResolveExtension (string ext, TypeResolveContext trc, bool errors)
	{
	    if (errors && typeargs != null)
		// Don't want to think about how this should be handled.
		throw new InvalidOperationException ();

	    string exname;

	    if (IsUser)
		exname = ((string) t) + ext;
	    else
		exname = ((Type) t).FullName + ext;

	    UserType exval = trc.Resolve (exname, false);
	    if (exval != null) {
		this.t = exval.t;
		resolved = true;
		return false;
	    }

	    return Resolve (trc, errors);
	}
예제 #35
0
        public override bool Resolve(TypeResolveContext trc, bool errors)
        {
            bool ret = base.Resolve(trc, errors);

            ret |= MatchType.ResolveExtension("RTemplate", trc, errors);

            // RegexMatcher will handle distinguishing between when
            // we return a Rule type and a TargetTemplate type, but we need
            // to check if we require a binding.

            bool?foo = MatchType.ResolvesAsRule(trc, errors);

            if (foo == null)
            {
                // MatchType unresolved, can't say.
                return(true);
            }

            if ((bool)foo)
            {
                // We point to a Rule, and ResolveUsedStructureType will
                // complain if we call it on MatchType.

                if (UsesStructure)
                {
                    throw ExHelp.App("Odd, MatcherBuilder {0} is using its structure" +
                                     "even though it points to a plain rule {1}", this,
                                     MatchType);
                }

                return(false);
            }

            // We have a template, so see if it uses a structure

            UserType stype = MatchType.ResolveUsedStructureType(trc, errors);

            if (errors)
            {
                if (stype == null && UsesStructure)
                {
                    // XXX is this actually an error? Shouldn't happen, I think.
                    Console.Error.WriteLine("Matcher {0} is bound to structure {1} but its " +
                                            "associated template {2} is unbound", this,
                                            Params, MatchType);
                    return(true);
                }
                else if (stype != null && !UsesStructure)
                {
                    UseStructure();
                }
                else if (stype != null && !NS.ParamsType.Equals(stype))
                {
                    // FIXME: see if Structure has a member of type stype.
                    Console.Error.WriteLine("Matcher {0} is bound to the structure {1}  but its " +
                                            "associated template {2} is bound to {3}", this,
                                            Params, MatchType, stype);
                    return(true);
                }
            }

            return(ret);
        }
예제 #36
0
	public virtual bool Resolve (TypeResolveContext trc, bool errors)
	{
	    if (!registered) {
		trc.Driver.DefineUserType (FullName, this);
		registered = true;
	    }

	    if (errors && baseclass == null) {
		Console.Error.WriteLine ("No base class set for item {0}", this);
		return true;
	    }
		
	    bool ret = baseclass.Resolve (trc, errors);

	    if (implements != null) {
		foreach (UserType ut in implements)
		    ret |= ut.Resolve (trc, errors);
	    }

	    return ret;
	}
예제 #37
0
파일: UserType.cs 프로젝트: retahc/old-code
        public UserType ResolveUsedStructureType(TypeResolveContext trc, bool errors)
        {
            if (!resolved)
            {
                if (errors)
                {
                    throw new InvalidOperationException();
                }
                return(null);
            }

            UserType ret;

            if (IsUser)
            {
                // User type. Use our lookup tables

                StructureBoundItem sbi = trc.Driver.GetUserTypeItem((string)t) as StructureBoundItem;

                if (sbi == null)
                {
                    if (errors)
                    {
                        throw ExHelp.App("Expected structure bound item but got {0} for {1}",
                                         trc.Driver.GetUserTypeItem((string)t), this);
                    }
                    return(null);
                }

                if (!sbi.UsesStructure)
                {
                    return(null);
                }

                ret = sbi.NS.ParamsType;
            }
            else
            {
                // System type. Use reflection.

                Type type = (Type)t;

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

                if (attrs.Length == 0)
                {
                    throw ExHelp.App("Expected type {0} to have a StructureBindingAttribute " +
                                     "but it didn't", type);
                }

                StructureBindingAttribute attr = (StructureBindingAttribute)attrs[0];

                if (!attr.UsesStructure)
                {
                    return(null);
                }

                ret = new UserType(attr.StructureType);
            }

            if (ret.Resolve(trc, errors))
            {
                if (errors)
                {
                    throw ExHelp.App("Failed to resolve bound structure type {0}", ret);
                }
                return(null);
            }

            return(ret);
        }
예제 #38
0
        // Setup

        public bool Resolve(TypeResolveContext trc, bool errors)
        {
            // We need to resolve the rule as a template now, rather
            // than letting NameLookupContext do it, because NLC will
            // be operating with an undefined set of 'usings', and
            // probably won't be able to find the RTemplate associated
            // with the rule.

            if (Rule.ResolveExtension("RTemplate", trc, errors))
            {
                return(true);
            }

            // Now we need to check that, if we have a template that
            // uses a structure, that our provider can access such
            // a structure, so that the template can actually be
            // instantiated.
            //
            // FIXME: This code is exactly parallel to
            // StructureBoundItem.ContextualStructRef.

            UserType ttmpl = Rule.ResolveUsedStructureType(trc, errors);

            if (ttmpl == null)
            {
                // Great, it's doesn't use anything, so whatever.
                return(false);
            }

            // XXX shouldn't apply anymore -- unbound providers are now impossible.
            // Would they have ever been useful?
            //
            //if (prov.Structure == null) {
            //if (errors)
            //	    Console.Error.WriteLine ("Target {0} in provider {1} references rule {2} that " +
            //			     "is bound to structure {3}, but the provider is not " +
            //			     "bound to a structure and so can provide no context",
            //			     this, prov, Rule, ttmpl);
            //return true;
            //}

            if (ttmpl.Equals(prov.NS.ParamsType))
            {
                // It just depends on our containing structure. No problem.
                return(false);
            }

            foreach (string param in prov.Structure.Parameters)
            {
                if (prov.Structure[param] != StructureParameterKind.Structure)
                {
                    continue;
                }

                if (ttmpl.Equals(prov.Structure.StructParamType(param)))
                {
                    return(false);
                }
            }

            if (errors)
            {
                // WORST ERROR MESSAGE EVAR
                Console.Error.WriteLine("Target {0} in provider {1} references rule {2} that " +
                                        "is bound to structure {3}, but the provider's containing " +
                                        "structure {4} does not have an argument referencing that structure. " +
                                        "You probably need to add another parameter to the containing structure.",
                                        this, prov, Rule, ttmpl, prov.Structure);
            }
            return(true);
        }
예제 #39
0
 public override bool Resolve(TypeResolveContext trc, bool errors)
 {
     return(base.Resolve(trc, errors) | ResultType.Resolve(trc, errors));
 }
예제 #40
0
파일: UserType.cs 프로젝트: emtees/old-code
	public bool? ResolvesAsRule (TypeResolveContext trc, bool errors)
	{
	    if (!resolved) {
		if (errors)
		    throw new InvalidOperationException ();
		return null;
	    }

	    if (IsSystem)
		// System type. Use reflection.
		return typeof (Rule).IsAssignableFrom ((Type) t);

	    // User type. Use our lookup tables

	    TypeExpressedItem tei = trc.Driver.GetUserTypeItem ((string) t);
	    return (tei is RuleBuilder || tei is SourcefileRuleBuilder);
	}
예제 #41
0
	public abstract bool Resolve (TypeResolveContext trc, bool errors);
예제 #42
0
	public override bool Resolve (TypeResolveContext trc, bool errors)
	{
	    bool res = base.Resolve (trc, errors);

	    foreach (StructureElement elt in elts)
		res |= elt.Resolve (trc, errors);
	    foreach (UserType ut in structtypes.Values)
		res |= ut.Resolve (trc, errors);

	    return res;
	}