Break, continue, and goto statements 


Мы поможем в написании ваших работ!



ЗНАЕТЕ ЛИ ВЫ?

Break, continue, and goto statements



The definite assignment state of v on the control flow transfer caused by a break, continue, or goto statement is the same as the definite assignment state of v at the beginning of the statement.

Throw statements

For a statement stmt of the form

throw expr;

The definite assignment state of v at the beginning of expr is the same as the definite assignment state of v at the beginning of stmt.

Return statements

For a statement stmt of the form

return expr;

· The definite assignment state of v at the beginning of expr is the same as the definite assignment state of v at the beginning of stmt.

· If v is an output parameter, then it must be definitely assigned either:

o after expr

o or at the end of the finally block of a try-finally or try-catch-finally that encloses the return statement.

For a statement stmt of the form:

return;

· If v is an output parameter, then it must be definitely assigned either:

o before stmt

o or at the end of the finally block of a try-finally or try-catch-finally that encloses the return statement.

Try-catch statements

For a statement stmt of the form:

try try-block
catch(...) catch-block-1
...
catch(...) catch-block-n

· The definite assignment state of v at the beginning of try-block is the same as the definite assignment state of v at the beginning of stmt.

· The definite assignment state of v at the beginning of catch-block-i (for any i) is the same as the definite assignment state of v at the beginning of stmt.

· The definite assignment state of v at the end-point of stmt is definitely assigned if (and only if) v is definitely assigned at the end-point of try-block and every catch-block-i (for every i from 1 to n).

Try-finally statements

For a try statement stmt of the form:

try try-block finally finally-block

· The definite assignment state of v at the beginning of try-block is the same as the definite assignment state of v at the beginning of stmt.

· The definite assignment state of v at the beginning of finally-block is the same as the definite assignment state of v at the beginning of stmt.

· The definite assignment state of v at the end-point of stmt is definitely assigned if (and only if) at least one of the following is true:

o v is definitely assigned at the end-point of try-block

o v is definitely assigned at the end-point of finally-block

If a control flow transfer (for example, a goto statement) is made that begins within try-block, and ends outside of try-block, then v is also considered definitely assigned on that control flow transfer if v is definitely assigned at the end-point of finally-block. (This is not an only if—if v is definitely assigned for another reason on this control flow transfer, then it is still considered definitely assigned.)

Try-catch-finally statements

Definite assignment analysis for a try-catch-finally statement of the form:

try try-block
catch(...) catch-block-1
...
catch(...) catch-block-n
finally finally-block

is done as if the statement were a try-finally statement enclosing a try-catch statement:

try {
try try-block
catch(...) catch-block-1
...
catch(...) catch-block-n
}
finally finally-block

The following example demonstrates how the different blocks of a try statement (§8.10) affect definite assignment.

class A
{
static void F() {
int i, j;
try {
goto LABEL;
// neither i nor j definitely assigned
i = 1;
// i definitely assigned
}

catch {
// neither i nor j definitely assigned
i = 3;
// i definitely assigned
}

finally {
// neither i nor j definitely assigned
j = 5;
// j definitely assigned
}
// i and j definitely assigned
LABEL:;
// j definitely assigned

}
}

Foreach statements

For a foreach statement stmt of the form:

foreach (type identifier in expr) embedded-statement

· The definite assignment state of v at the beginning of expr is the same as the state of v at the beginning of stmt.

· The definite assignment state of v on the control flow transfer to embedded-statement or to the end point of stmt is the same as the state of v at the end of expr.

Using statements

For a using statement stmt of the form:

using (resource-acquisition) embedded-statement

· The definite assignment state of v at the beginning of resource-acquisition is the same as the state of v at the beginning of stmt.

· The definite assignment state of v on the control flow transfer to embedded-statement is the same as the state of v at the end of resource-acquisition.

Lock statements

For a lock statement stmt of the form:

lock (expr) embedded-statement

· The definite assignment state of v at the beginning of expr is the same as the state of v at the beginning of stmt.

· The definite assignment state of v on the control flow transfer to embedded-statement is the same as the state of v at the end of expr.

Yield statements

For a yield return statement stmt of the form:

yield return expr;

· The definite assignment state of v at the beginning of expr is the same as the state of v at the beginning of stmt.

· The definite assignment state of v at the end of stmt is the same as the state of v at the end of expr.

A yield break statement has no effect on the definite assignment state.

General rules for simple expressions

The following rule applies to these kinds of expressions: literals (§7.6.1), simple names (§7.6.2), member access expressions (§7.6.4), non-indexed base access expressions (§7.6.8), typeof expressions (§7.6.11), and default value expressions (§7.6.13).

· The definite assignment state of v at the end of such an expression is the same as the definite assignment state of v at the beginning of the expression.

General rules for expressions with embedded expressions

The following rules apply to these kinds of expressions: parenthesized expressions (§7.6.3), element access expressions (§7.6.6), base access expressions with indexing (§7.6.8), increment and decrement expressions (§7.6.9, §7.7.5), cast expressions (§7.7.6), unary +, -, ~, * expressions, binary +, -, *, /, %, <<, >>, <, <=, >, >=, ==,!=, is, as, &, |, ^ expressions (§7.8, §7.9, §7.10, §7.11), compound assignment expressions (§7.17.2), checked and unchecked expressions (§7.6.12), plus array and delegate creation expressions (§7.6.10).

Each of these expressions has one or more sub-expressions that are unconditionally evaluated in a fixed order. For example, the binary % operator evaluates the left hand side of the operator, then the right hand side. An indexing operation evaluates the indexed expression, and then evaluates each of the index expressions, in order from left to right. For an expression expr, which has sub-expressions expr1, expr2,..., exprn, evaluated in that order:

· The definite assignment state of v at the beginning of expr1 is the same as the definite assignment state at the beginning of expr.

· The definite assignment state of v at the beginning of expri (i greater than one) is the same as the definite assignment state at the end of expri-1.

· The definite assignment state of v at the end of expr is the same as the definite assignment state at the end of exprn.

Invocation expressions and object creation expressions

For an invocation expression expr of the form:

primary-expression (arg1, arg2, …, argn)

or an object creation expression of the form:

new type (arg1, arg2, …, argn)

· For an invocation expression, the definite assignment state of v before primary-expression is the same as the state of v before expr.

· For an invocation expression, the definite assignment state of v before arg1 is the same as the state of v after primary-expression.

· For an object creation expression, the definite assignment state of v before arg1 is the same as the state of v before expr.

· For each argument argi, the definite assignment state of v after argi is determined by the normal expression rules, ignoring any ref or out modifiers.

· For each argument argi for any i greater than one, the definite assignment state of v before argi is the same as the state of v after argi-1.

· If the variable v is passed as an out argument (i.e., an argument of the form “out v”) in any of the arguments, then the state of v after expr is definitely assigned. Otherwise; the state of v after expr is the same as the state of v after argn.

· For array initializers (§7.6.10.4), object initializers (§7.6.10.2), collection initializers (§7.6.10.3) and anonymous object initializers (§7.6.10.6), the definite assignment state is determined by the expansion that these constructs are defined in terms of.



Поделиться:


Последнее изменение этой страницы: 2016-08-10; просмотров: 256; Нарушение авторского права страницы; Мы поможем в написании вашей работы!

infopedia.su Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Обратная связь - 3.139.107.241 (0.01 с.)