1 // 2 // aegis - project change supervisor 3 // Copyright (C) 1996, 1999, 2003-2008 Peter Miller 4 // 5 // This program is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program. If not, see 17 // <http://www.gnu.org/licenses/>. 18 // 19 20 #include <libaegis/aer/stmt/throw.h> 21 #include <libaegis/aer/value/error.h> 22 #include <libaegis/aer/value/string.h> 23 #include <common/str.h> 24 #include <libaegis/sub.h> 25 #include <common/trace.h> 26 27 ~rpt_stmt_throw()28rpt_stmt_throw::~rpt_stmt_throw() 29 { 30 } 31 32 rpt_stmt_throw(const rpt_expr::pointer & a_ep)33rpt_stmt_throw::rpt_stmt_throw(const rpt_expr::pointer &a_ep) : 34 ep(a_ep) 35 { 36 } 37 38 39 rpt_stmt::pointer create(const rpt_expr::pointer & a_ep)40rpt_stmt_throw::create(const rpt_expr::pointer &a_ep) 41 { 42 return pointer(new rpt_stmt_throw(a_ep)); 43 } 44 45 46 void run(rpt_stmt_result_ty * rp) const47rpt_stmt_throw::run(rpt_stmt_result_ty *rp) 48 const 49 { 50 trace(("throw::run()\n{\n")); 51 rpt_value::pointer vp = ep->evaluate(true, true); 52 if (vp->is_an_error()) 53 { 54 rp->status = rpt_stmt_status_error; 55 rp->thrown = vp; 56 trace(("}\n")); 57 return; 58 } 59 60 rpt_value::pointer vp2 = rpt_value::stringize(vp); 61 rpt_value_string *vp2sp = dynamic_cast<rpt_value_string *>(vp2.get()); 62 if (!vp2sp) 63 { 64 sub_context_ty sc; 65 sc.var_set_charstar("Name", vp2->name()); 66 nstring s 67 ( 68 sc.subst_intl 69 ( 70 i18n("throw statement requires string argument (not $name)") 71 ) 72 ); 73 rp->status = rpt_stmt_status_error; 74 rp->thrown = rpt_value_error::create(ep->get_pos(), s); 75 trace(("}\n")); 76 return; 77 } 78 79 rp->status = rpt_stmt_status_error; 80 rp->thrown = rpt_value_error::create(ep->get_pos(), vp2sp->query()); 81 trace(("}\n")); 82 } 83