public override AstNode Visit(GotoCaseStatement node) { // Store the current switch in the node. node.SetSwitch(currentSwitch); // Get the constant expression. Expression constant = node.GetLabel(); // Expand it. CaseLabel targetLabel; if(constant != null) { constant = (Expression)constant.Accept(this); node.SetLabel(constant); // Get the constant value. IChelaType coercionType = currentSwitch.GetCoercionType(); node.SetCoercionType(coercionType); } else { // Make sure the current switch contains a default case. targetLabel = currentSwitch.GetDefaultCase(); if(targetLabel == null) Error(node, "current switch doesn't contain a default case."); node.SetTargetLabel(targetLabel); } return node; }
public override AstNode Visit(GotoCaseStatement node) { // Begin the node. builder.BeginNode(node); // Get the constant expression. Expression constant = node.GetLabel(); // Expand it. if(constant != null) { // Get the constant value. IChelaType coercionType = node.GetCoercionType(); ConstantValue constantValue = (ConstantValue)constant.GetNodeValue(); constantValue = constantValue.Cast(coercionType); // Make sure the case is in the current switch. IDictionary<ConstantValue, CaseLabel> caseDict = node.GetSwitch().CaseDictionary; CaseLabel targetLabel; if(!caseDict.TryGetValue(constantValue, out targetLabel)) Error(node, "current switch doesn't contain a case for [{1}]{0}.", constantValue.ToString(), constantValue.GetHashCode()); node.SetTargetLabel(targetLabel); } // Jump to the target case. CaseLabel targetCase = node.GetTargetLabel(); builder.CreateJmp(targetCase.GetBlock()); // End the node. return builder.EndNode(); }