Exemplo n.º 1
0
		protected override void TranslateSwitchStatementContinuousSafe(List<string> output, SwitchStatementContinuousSafe switchStatement)
		{
			foreach (SwitchStatement.Chunk chunks in switchStatement.OriginalSwitchStatement.Chunks)
			{
				if (chunks.Cases.Length > 1) throw new Exception("Not a continuous switch statement.");
				if (chunks.Cases[0] == null) throw new Exception("Not a safe switch statement.");
			}

			this.TranslateSwitchStatement(output, switchStatement.OriginalSwitchStatement);
		}
Exemplo n.º 2
0
		protected override void TranslateSwitchStatementContinuousSafe(List<string> output, SwitchStatementContinuousSafe switchStatement)
		{
			SwitchStatementContinuousSafe.SearchTree tree = switchStatement.GenerateSearchTree();
			int switchId = this.GetNextInt();
			string varName = "switch_key_" + switchId;
			output.Add(this.CurrentTabIndention);
			output.Add(varName);
			output.Add(" = ");
			this.TranslateExpression(output, switchStatement.Condition);
			output.Add("\r\n");
			this.GenerateSearchTree(output, tree, varName);
		}
Exemplo n.º 3
0
		private void GenerateSearchTree(List<string> output, SwitchStatementContinuousSafe.SearchTree tree, string varName)
		{
			if (tree.Code == null)
			{
				output.Add(this.CurrentTabIndention);
				output.Add("if " + varName + " < " + tree.LessThanThis + ":\r\n");
				this.CurrentIndention++;
				this.GenerateSearchTree(output, tree.Left, varName);
				this.CurrentIndention--;
				output.Add(this.CurrentTabIndention);
				output.Add("else:\r\n");
				this.CurrentIndention++;
				this.GenerateSearchTree(output, tree.Right, varName);
				this.CurrentIndention--;
			}
			else
			{
				this.Translate(output, tree.Code);
			}
		}
Exemplo n.º 4
0
        public SearchTree GenerateSearchTree()
        {
            int[] keys = this.codeByCondition.Keys.ToArray();
            int   min  = keys.First <int>();
            int   max  = keys.First <int>();

            foreach (int key in keys)
            {
                if (key < min)
                {
                    min = key;
                }
                if (key > max)
                {
                    max = key;
                }
            }

            return(SwitchStatementContinuousSafe.GenerateSearchTreeCommon(this.codeByCondition, min, max));
        }
Exemplo n.º 5
0
 public SwitchStatementContinuousSafe.SearchTree GenerateSearchTree()
 {
     return(SwitchStatementContinuousSafe.GenerateSearchTreeCommon(this.codeMapping, 0, this.max));
 }
Exemplo n.º 6
0
		protected abstract void TranslateSwitchStatementContinuousSafe(List<string> output, SwitchStatementContinuousSafe switchStatement);