| 4411 | } |
| 4412 | |
| 4413 | void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, asCByteCode *bc) |
| 4414 | { |
| 4415 | *hasReturn = false; |
| 4416 | |
| 4417 | // TODO: inheritance: Must guarantee that all options in the switch case call a constructor, or that none call it. |
| 4418 | |
| 4419 | // Reserve label for break statements |
| 4420 | int breakLabel = nextLabel++; |
| 4421 | breakLabels.PushLast(breakLabel); |
| 4422 | |
| 4423 | // Add a variable scope that will be used by CompileBreak |
| 4424 | // to know where to stop deallocating variables |
| 4425 | AddVariableScope(true, false); |
| 4426 | |
| 4427 | //--------------------------- |
| 4428 | // Compile the switch expression |
| 4429 | //------------------------------- |
| 4430 | |
| 4431 | // Compile the switch expression |
| 4432 | asCExprContext expr(engine); |
| 4433 | CompileAssignment(snode->firstChild, &expr); |
| 4434 | |
| 4435 | // Verify that the expression is a primitive type |
| 4436 | if( !expr.type.dataType.IsIntegerType() && !expr.type.dataType.IsUnsignedType() ) |
| 4437 | { |
| 4438 | Error(TXT_SWITCH_MUST_BE_INTEGRAL, snode->firstChild); |
| 4439 | return; |
| 4440 | } |
| 4441 | |
| 4442 | if( ProcessPropertyGetAccessor(&expr, snode) < 0 ) |
| 4443 | return; |
| 4444 | |
| 4445 | // TODO: Need to support 64bit integers |
| 4446 | // Convert the expression to a 32bit variable |
| 4447 | asCDataType to; |
| 4448 | if( expr.type.dataType.IsIntegerType() ) |
| 4449 | to.SetTokenType(ttInt); |
| 4450 | else if( expr.type.dataType.IsUnsignedType() ) |
| 4451 | to.SetTokenType(ttUInt); |
| 4452 | |
| 4453 | // Make sure the value is in a variable |
| 4454 | if( expr.type.dataType.IsReference() ) |
| 4455 | ConvertToVariable(&expr); |
| 4456 | |
| 4457 | ImplicitConversion(&expr, to, snode->firstChild, asIC_IMPLICIT_CONV, true); |
| 4458 | |
| 4459 | ConvertToVariable(&expr); |
| 4460 | int offset = expr.type.stackOffset; |
| 4461 | |
| 4462 | ProcessDeferredParams(&expr); |
| 4463 | |
| 4464 | //------------------------------- |
| 4465 | // Determine case values and labels |
| 4466 | //-------------------------------- |
| 4467 | |
| 4468 | // Remember the first label so that we can later pass the |
| 4469 | // correct label to each CompileCase() |
| 4470 | int firstCaseLabel = nextLabel; |
nothing calls this directly
no test coverage detected