-Block declare_local_variables (FullNamedExpression type, List<object> variable_declarators, Location loc)
-{
- Block implicit_block;
-
- //
- // If we are doing interactive editing, we want variable declarations
- // that are in the top block to be added instead to the class as
- // static variables
- //
- if (RootContext.StatementMode){
- bool hoist = true;
-
- for (Block b = current_block; b != null; b = b.Parent){
- if (b is ExplicitBlock && !(b is ToplevelBlock)){
- // There has been an explicit block, we cant add to the class
- hoist = false;
- break;
- }
- }
- if (hoist){
- //
- // We can use "current_block" since we know there are no explicit blocks
- //
- foreach (VariableDeclaration decl in variable_declarators){
- // We can not use the super-handy f.Initializer, because
- // multiple lines would force code to be executed out of sync
- var init = decl.GetInitializer (type);
- if (init != null){
- string id = "$" + decl.identifier;
- LocalInfo vi = current_block.AddVariable (type, id, decl.Location);
-
- // Avoid warning about this variable not being used.
- vi.Used = true;
-
- LocalVariableReference var;
- var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, vi, decl.Location);
- Assign assign = new SimpleAssign (var, init, decl.Location);
- current_block.AddStatement (new StatementExpression (assign));
- assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
- current_block.AddStatement (new StatementExpression (assign));
- } else {
- Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
- new MemberName (decl.identifier, loc), null);
- current_container.AddField (f);
-
- // Register the field to be visible later as a global variable
- Evaluator.QueueField (f);
- }
- }
-
- return current_block;
- }
- }
-
- //
- // We use the `Used' property to check whether statements
- // have been added to the current block. If so, we need
- // to create another block to contain the new declaration
- // otherwise, as an optimization, we use the same block to
- // add the declaration.
- //
- // FIXME: A further optimization is to check if the statements
- // that were added were added as part of the initialization
- // below. In which case, no other statements have been executed
- // and we might be able to reduce the number of blocks for
- // situations like this:
- //
- // int j = 1; int k = j + 1;
- //
- if (current_block.Used)
- implicit_block = new Block (current_block, loc, lexer.Location);
- else
- implicit_block = current_block;
-
- foreach (VariableDeclaration decl in variable_declarators){
-
- if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
- if (decl.HasInitializer){
- Assign assign;
-
- var lvr = new LocalVariableReference (implicit_block, decl.identifier, loc);
-
- assign = new SimpleAssign (lvr, decl.GetInitializer (type), decl.Location);
-
- implicit_block.AddStatement (new StatementExpression (assign));
- }
- }
- }
-
- return implicit_block;
-}
-
-Block declare_local_constants (FullNamedExpression type, List<object> declarators)