private void VisitTryBlock(try_block tryblock)
 {
     VisitStatement(tryblock.try_statements);
     if (CanWriteObject(tryblock.finally_statements))
         VisitStatement(tryblock.finally_statements);
     bw.Write(tryblock.filters.Count);
     foreach (exception_filter ef in tryblock.filters)
     {
         if (CanWriteObject(ef.filter_type))
             WriteTypeReference(ef.filter_type);
         if (CanWriteObject(ef.exception_var))
             VisitLocalBlockVariableReference(ef.exception_var);
         VisitStatement(ef.exception_handler);
         WriteDebugInfo(ef.location);
     }
 }
Beispiel #2
0
 private void VisitTryBlock(try_block stmt)
 {
     VisitStatement(stmt.try_statements);
     for (int i = 0; i < stmt.filters.Count; i++)
     {
         if(stmt.filters[i].exception_var!=null)
            IncreaseNumUseVar(stmt.filters[i].exception_var);
         VisitStatement(stmt.finally_statements);
     }
 }
 public override void visit(SyntaxTree.try_stmt _try_stmt)
 {
     context.enter_code_block_without_bind();
     context.enter_exception_handlers();
     statement_node try_statements = convert_strong(_try_stmt.stmt_list);
     context.leave_code_block();
     location loc = get_location(_try_stmt);
     exception_filters_list efl = new exception_filters_list();
     SyntaxTree.try_handler_except try_hand_except = _try_stmt.handler as SyntaxTree.try_handler_except;
     if (try_hand_except != null)
     {
         if (try_hand_except.except_block.handlers != null)
         {
             int hand_count = try_hand_except.except_block.handlers.handlers.Count;
             for (int i = 0; i < hand_count; i++)
             {
                 SyntaxTree.exception_handler eh = try_hand_except.except_block.handlers.handlers[i];
                 type_node filter_type = convert_strong(eh.type_name);
                 if (!SemanticRules.GenerateNativeCode && !(filter_type.is_generic_parameter ||
                     filter_type == SystemLibrary.SystemLibrary.exception_base_type ||
                     type_table.is_derived(SystemLibrary.SystemLibrary.exception_base_type, filter_type)))
                 {
                     AddError(get_location(eh.type_name), "EXCEPTION_TYPE_MUST_BE_SYSTEM_EXCEPTION_OR_DERIVED_FROM_EXCEPTION");
                 }
                 current_catch_excep = new int_const_node(2,null);//create_constructor_call(filter_type, new expressions_list(), null);
                 local_block_variable_reference lvr = null;
                 
                 context.enter_code_block_without_bind();
                 if (eh.variable != null)
                 {
                 	
                 	context.check_name_redefinition = false;
                 	
                 	local_block_variable lbv = context.add_var_definition(eh.variable.name, get_location(eh.variable), filter_type, SemanticTree.polymorphic_state.ps_common) as local_block_variable;
                     context.check_name_redefinition = true;
                 	lvr = new local_block_variable_reference(lbv, lbv.loc);
                 }
                 statement_node stm = convert_strong(eh.statements);
                 context.leave_code_block();
                 
                 /*if (eh.variable != null)
                 {
                     context.leave_scope();
                 }*/
                 exception_filter ef = new exception_filter(filter_type, lvr, stm, get_location(eh));
                 efl.AddElement(ef);
                 current_catch_excep = null;
             }
         }
         else
         {
             context.enter_code_block_without_bind();
             exception_filter ef = new exception_filter(null, null, convert_strong(try_hand_except.except_block.stmt_list), get_location(try_hand_except.except_block.stmt_list));
             context.leave_code_block();
             efl.AddElement(ef);
         }
         if (try_hand_except.except_block.else_stmt_list != null)
         {
             context.enter_code_block_without_bind();
             statement_node else_stm = convert_strong(try_hand_except.except_block.else_stmt_list);
             context.leave_code_block();
             type_node ftype = SystemLibrary.SystemLibrary.object_type;
             exception_filter else_ef = new exception_filter(ftype, null, else_stm, else_stm.location);
             efl.AddElement(else_ef);
         }
     }
     else
     {
     	type_node filter_type = compiled_type_node.get_type_node(NetHelper.NetHelper.FindType(compiler_string_consts.ExceptionName));
     	expression_node current_catch_excep = create_constructor_call(filter_type, new expressions_list(), null);
         local_block_variable_reference lvr = null;
         local_block_variable tmp_var = context.add_var_definition(context.BuildName("$try_temp" + UniqueNumStr()), null, SystemLibrary.SystemLibrary.bool_type, null) as local_block_variable;
         statements_list stm = new statements_list(null);
         SyntaxTree.try_handler_finally try_hndlr_finally = _try_stmt.handler as SyntaxTree.try_handler_finally;
         context.enter_code_block_without_bind();
         statement_node finally_stmt = convert_strong(try_hndlr_finally.stmt_list);
         context.leave_code_block();
         stm.statements.AddElement(finally_stmt);
         basic_function_call bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_not as basic_function_node,null);
         bfc.parameters.AddElement(new local_block_variable_reference(tmp_var,null));
         stm.statements.AddElement(new if_node(bfc,new rethrow_statement_node(null),null,null));
     	exception_filter ef = new exception_filter(filter_type, lvr, stm, null);
         efl.AddElement(ef);
         bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_assign as basic_function_node,null);
         bfc.parameters.AddElement(new local_block_variable_reference(tmp_var,null));
         bfc.parameters.AddElement(new bool_const_node(true,null));
         
         (try_statements as statements_list).statements.AddElement(bfc);
         (try_statements as statements_list).statements.AddElement(new throw_statement_node(current_catch_excep,null));
         return_value(new try_block(try_statements, null, efl, loc));
         context.leave_exception_handlers();
         return;
     }
     statement_node finally_st = null;
     SyntaxTree.try_handler_finally try_handler_finally = _try_stmt.handler as SyntaxTree.try_handler_finally;
     if (try_handler_finally != null)
     {
         context.enter_code_block_without_bind();
         finally_st = convert_strong(try_handler_finally.stmt_list);
         context.leave_code_block();
     }
     try_block tb = new try_block(try_statements, finally_st, efl, loc);
     context.leave_exception_handlers();
     return_value(tb);
 }