예제 #1
0
 public void Accept(SwitchNode node)
 {
 }
예제 #2
0
        public void Accept(SwitchNode node)
        {
            if (!table.ContainsSymbol((++labelIndex).ToString()))
                table.AddSymbol(labelIndex.ToString());
            int tmp = table.GetSymbol(labelIndex.ToString());
            int endSwitch = nextLabel();

            node.Expression.Visit(this);
            method.Emit(node.SourceLocation, InstructionType.StoreLocal, tmp);
            foreach (var case_ in node.Cases)
            {
                int trueLabel = nextLabel();
                int falseLabel = nextLabel();
                foreach (var expression in case_.Expressions)
                {
                    method.Emit(node.SourceLocation, InstructionType.LoadLocal, tmp);
                    expression.Visit(this);
                    method.Emit(node.SourceLocation, InstructionType.BinaryOperation, (int)case_.Operation);
                    method.Emit(node.SourceLocation, InstructionType.JumpIfTrue, trueLabel);
                }
                method.Emit(node.SourceLocation, InstructionType.Jump, falseLabel);
                method.EmitLabel(node.SourceLocation, trueLabel);
                case_.Body.Visit(this);
                method.Emit(node.SourceLocation, InstructionType.Jump, endSwitch);
                method.EmitLabel(node.SourceLocation, falseLabel);
            }
            node.DefaultCase.Visit(this);
            method.EmitLabel(node.SourceLocation, endSwitch);
        }