Пример #1
0
        private void SimplifyModeUsage(
            NvdlNoCancelAction nca, NvdlCompileContext ctx)
        {
            NvdlModeUsage usage = nca.ModeUsage;

            if (usage.NestedMode != null && ctx.GetCompiledMode(usage) == null)
            {
                SimpleMode sm = new SimpleMode(String.Empty,
                                               usage.NestedMode, ctx);
                ctx.AddCompiledMode(usage, sm);
            }
            foreach (NvdlContext c in usage.Contexts)
            {
                if (c.NestedMode != null)
                {
                    SimpleMode sm = new SimpleMode(
                        String.Empty, c.NestedMode, ctx);
                    ctx.AddCompiledMode(c, sm);
                }
            }
        }
Пример #2
0
        private void SimplifyPhase1(NvdlCompileContext ctx)
        {
            NvdlRules rules = ctx.Rules;
            // 6.4.1 : just ignore "Foreign" property.
            // 6.4.2 : already ignored on reading nvdl.
            // 6.4.3 : done in SOM
            // 6.4.4 : FIXME: must be done.
            // 6.4.5 : FIXME: considered in compiler.
            // 6.4.6 : FIXME: considered in compiler.
            // 6.4.7 : FIXME: considered in compiler.

            // 6.4.8 : here
            NvdlModeList list      = rules.Modes;
            NvdlMode     startMode = null;

            if (rules.Modes.Count > 0)
            {
                if (rules.Rules.Count > 0)
                {
                    throw new NvdlCompileException("Modes and rules cannot coexist in 'rules' element.", rules);
                }
                else if (rules.StartMode == null)
                {
                    throw new NvdlCompileException("startMode is missing in 'rules' element when modes are specified.", rules);
                }
                foreach (NvdlMode m in rules.Modes)
                {
                    if (m.Name == rules.StartMode)
                    {
                        startMode = m;
                        break;
                    }
                }
                if (startMode == null)
                {
                    throw new NvdlCompileException("Matching 'mode' element specified by 'startMode' does not exist.", rules);
                }
            }
            else
            {
                if (rules.Rules.Count == 0)
                {
                    throw new NvdlCompileException("Neither modes nor rules exists in 'rules' element.", rules);
                }
                list                   = new NvdlModeList();
                startMode              = new NvdlMode();
                startMode.SourceUri    = rules.SourceUri;
                startMode.LineNumber   = rules.LineNumber;
                startMode.LinePosition = rules.LinePosition;
                startMode.Name         = "(startMode)";
                list.Add(startMode);
                foreach (NvdlRule rule in rules.Rules)
                {
                    startMode.Rules.Add(rule);
                }
            }

            // 6.4.9 : done in SimpleMode.ctor() and
            // SimpleRule.ctor(), using ctx.CompiledModes.
            foreach (NvdlMode m in list)
            {
                SimpleMode sm = new SimpleMode(m, ctx);
                ctx.AddCompiledMode(sm.Name, sm);
                if (m == startMode)
                {
                    this.startMode = sm;
                }
            }

            // 6.4.10 : done in SimpleRule.Simplify

            ArrayList tl = new ArrayList();

            for (int i = 0; i < rules.Triggers.Count; i++)
            {
                tl.Add(new SimpleTrigger(rules.Triggers [i]));
            }
            triggers = (SimpleTrigger [])tl.ToArray(
                typeof(SimpleTrigger));

            modes = (SimpleMode [])
                    new ArrayList(ctx.GetCompiledModes())
                    .ToArray(typeof(SimpleMode));
        }
Пример #3
0
		private void SimplifyPhase1 (NvdlCompileContext ctx)
		{
			NvdlRules rules = ctx.Rules;
			// 6.4.1 : just ignore "Foreign" property.
			// 6.4.2 : already ignored on reading nvdl.
			// 6.4.3 : done in SOM
			// 6.4.4 : FIXME: must be done.
			// 6.4.5 : FIXME: considered in compiler.
			// 6.4.6 : FIXME: considered in compiler.
			// 6.4.7 : FIXME: considered in compiler.

			// 6.4.8 : here
			NvdlModeList list = rules.Modes;
			NvdlMode startMode = null;

			if (rules.Modes.Count > 0) {
				if (rules.Rules.Count > 0)
					throw new NvdlCompileException ("Modes and rules cannot coexist in 'rules' element.", rules);
				else if (rules.StartMode == null)
					throw new NvdlCompileException ("startMode is missing in 'rules' element when modes are specified.", rules);
				foreach (NvdlMode m in rules.Modes) {
					if (m.Name == rules.StartMode) {
						startMode = m;
						break;
					}
				}
				if (startMode == null)
					throw new NvdlCompileException ("Matching 'mode' element specified by 'startMode' does not exist.", rules);
			} else {
				if (rules.Rules.Count == 0)
					throw new NvdlCompileException ("Neither modes nor rules exists in 'rules' element.", rules);
				list = new NvdlModeList ();
				startMode = new NvdlMode ();
				startMode.SourceUri = rules.SourceUri;
				startMode.LineNumber = rules.LineNumber;
				startMode.LinePosition = rules.LinePosition;
				startMode.Name = "(startMode)";
				list.Add (startMode);
				foreach (NvdlRule rule in rules.Rules)
					startMode.Rules.Add (rule);
			}

			// 6.4.9 : done in SimpleMode.ctor() and
			// SimpleRule.ctor(), using ctx.CompiledModes.
			foreach (NvdlMode m in list) {
				SimpleMode sm = new SimpleMode (m, ctx);
				ctx.AddCompiledMode (sm.Name, sm);
				if (m == startMode)
					this.startMode = sm;
			}

			// 6.4.10 : done in SimpleRule.Simplify

			ArrayList tl = new ArrayList ();
			for (int i = 0; i < rules.Triggers.Count; i++)
				tl.Add (new SimpleTrigger (rules.Triggers [i]));
			triggers = (SimpleTrigger []) tl.ToArray (
				typeof (SimpleTrigger));

			modes = (SimpleMode [])
				new ArrayList (ctx.GetCompiledModes ())
				.ToArray (typeof (SimpleMode));
		}
Пример #4
0
		private void SimplifyModeUsage (
			NvdlNoCancelAction nca, NvdlCompileContext ctx)
		{
			NvdlModeUsage usage = nca.ModeUsage;
			if (usage.NestedMode != null && ctx.GetCompiledMode (usage) == null) {
				SimpleMode sm = new SimpleMode (String.Empty,
					usage.NestedMode, ctx);
				ctx.AddCompiledMode (usage, sm);
			}
			foreach (NvdlContext c in usage.Contexts) {
				if (c.NestedMode != null) {
					SimpleMode sm = new SimpleMode (
						String.Empty, c.NestedMode, ctx);
					ctx.AddCompiledMode (c, sm);
				}
			}
		}