Mercurial > octave-nkf
comparison src/error.cc @ 11058:3329616444f0
replace Octave_map in debug.cc and error.cc
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 30 Sep 2010 08:27:56 +0200 |
parents | 4ab04ea74b08 |
children | fd0a3ac60b0e |
comparison
equal
deleted
inserted
replaced
11057:4d9f310b32bb | 11058:3329616444f0 |
---|---|
70 // TRUE means that Octave will print no warnings, but lastwarn will be | 70 // TRUE means that Octave will print no warnings, but lastwarn will be |
71 //updated | 71 //updated |
72 static bool Vquiet_warning = false; | 72 static bool Vquiet_warning = false; |
73 | 73 |
74 // A structure containing (most of) the current state of warnings. | 74 // A structure containing (most of) the current state of warnings. |
75 static Octave_map warning_options; | 75 static octave_map warning_options; |
76 | 76 |
77 // The text of the last error message. | 77 // The text of the last error message. |
78 static std::string Vlast_error_message; | 78 static std::string Vlast_error_message; |
79 | 79 |
80 // The text of the last warning message. | 80 // The text of the last warning message. |
133 } | 133 } |
134 | 134 |
135 static void | 135 static void |
136 initialize_warning_options (const std::string& state) | 136 initialize_warning_options (const std::string& state) |
137 { | 137 { |
138 warning_options.clear (); | 138 octave_scalar_map initw; |
139 | 139 |
140 warning_options.assign ("identifier", "all"); | 140 initw.setfield ("identifier", "all"); |
141 warning_options.assign ("state", state); | 141 initw.setfield ("state", state); |
142 | |
143 warning_options = initw; | |
142 } | 144 } |
143 | 145 |
144 static octave_map | 146 static octave_map |
145 initialize_last_error_stack (void) | 147 initialize_last_error_stack (void) |
146 { | 148 { |
433 static void | 435 static void |
434 pr_where (const char *who) | 436 pr_where (const char *who) |
435 { | 437 { |
436 octave_idx_type curr_frame = -1; | 438 octave_idx_type curr_frame = -1; |
437 | 439 |
438 Octave_map stk = octave_call_stack::backtrace (0, curr_frame); | 440 octave_map stk = octave_call_stack::backtrace (0, curr_frame); |
439 | 441 |
440 octave_idx_type nframes_to_display = stk.numel (); | 442 octave_idx_type nframes_to_display = stk.numel (); |
441 | 443 |
442 if (nframes_to_display > 0) | 444 if (nframes_to_display > 0) |
443 { | 445 { |
1061 } | 1063 } |
1062 else if (nargin == 1 && args(0).is_map ()) | 1064 else if (nargin == 1 && args(0).is_map ()) |
1063 { | 1065 { |
1064 octave_value_list tmp; | 1066 octave_value_list tmp; |
1065 | 1067 |
1066 Octave_map m = args(0).map_value (); | 1068 octave_scalar_map m = args(0).scalar_map_value (); |
1067 | 1069 |
1068 if (m.numel () == 1) | 1070 if (m.contains ("message")) |
1069 { | 1071 { |
1070 if (m.contains ("message")) | 1072 octave_value c = m.getfield ("message"); |
1071 { | 1073 |
1072 Cell c = m.contents ("message"); | 1074 if (c.is_string ()) |
1073 | 1075 nargs(0) = c.string_value (); |
1074 if (! c.is_empty () && c(0).is_string ()) | |
1075 nargs(0) = c(0).string_value (); | |
1076 } | |
1077 | |
1078 if (m.contains ("identifier")) | |
1079 { | |
1080 Cell c = m.contents ("identifier"); | |
1081 | |
1082 if (! c.is_empty () && c(0).is_string ()) | |
1083 id = c(0).string_value (); | |
1084 } | |
1085 | |
1086 // FIXME -- also need to handle "stack" field in error | |
1087 // structure, but that will require some more significant | |
1088 // surgery on handle_message, error_with_id, etc. | |
1089 } | 1076 } |
1077 | |
1078 if (m.contains ("identifier")) | |
1079 { | |
1080 octave_value c = m.getfield ("identifier"); | |
1081 | |
1082 if (c.is_string ()) | |
1083 id = c.string_value (); | |
1084 } | |
1085 | |
1086 // FIXME -- also need to handle "stack" field in error | |
1087 // structure, but that will require some more significant | |
1088 // surgery on handle_message, error_with_id, etc. | |
1090 } | 1089 } |
1091 | 1090 |
1092 handle_message (error_with_id, id.c_str (), "unspecified error", nargs); | 1091 handle_message (error_with_id, id.c_str (), "unspecified error", nargs); |
1093 } | 1092 } |
1094 | 1093 |
1142 if (argc == 3) | 1141 if (argc == 3) |
1143 arg2 = argv(2); | 1142 arg2 = argv(2); |
1144 | 1143 |
1145 if (arg1 == "on" || arg1 == "off" || arg1 == "error") | 1144 if (arg1 == "on" || arg1 == "off" || arg1 == "error") |
1146 { | 1145 { |
1147 Octave_map old_warning_options = warning_options; | 1146 octave_map old_warning_options = warning_options; |
1148 | 1147 |
1149 if (arg2 == "all") | 1148 if (arg2 == "all") |
1150 { | 1149 { |
1151 Octave_map tmp; | 1150 octave_map tmp; |
1152 | 1151 |
1153 Cell id (1, 1); | 1152 Cell id (1, 1); |
1154 Cell st (1, 1); | 1153 Cell st (1, 1); |
1155 | 1154 |
1156 id(0) = arg2; | 1155 id(0) = arg2; |
1291 if (arg2 == "all") | 1290 if (arg2 == "all") |
1292 retval = warning_options; | 1291 retval = warning_options; |
1293 else if (arg2 == "backtrace" || arg2 == "debug" | 1292 else if (arg2 == "backtrace" || arg2 == "debug" |
1294 || arg2 == "verbose" || arg2 == "quiet") | 1293 || arg2 == "verbose" || arg2 == "quiet") |
1295 { | 1294 { |
1296 Octave_map tmp; | 1295 octave_scalar_map tmp; |
1297 tmp.assign ("identifier", arg2); | 1296 tmp.assign ("identifier", arg2); |
1298 if (arg2 == "backtrace") | 1297 if (arg2 == "backtrace") |
1299 tmp.assign ("state", Vbacktrace_on_warning ? "on" : "off"); | 1298 tmp.assign ("state", Vbacktrace_on_warning ? "on" : "off"); |
1300 else if (arg2 == "debug") | 1299 else if (arg2 == "debug") |
1301 tmp.assign ("state", Vdebug_on_warning ? "on" : "off"); | 1300 tmp.assign ("state", Vdebug_on_warning ? "on" : "off"); |
1343 } | 1342 } |
1344 } | 1343 } |
1345 | 1344 |
1346 if (found) | 1345 if (found) |
1347 { | 1346 { |
1348 Octave_map tmp; | 1347 octave_scalar_map tmp; |
1349 | 1348 |
1350 tmp.assign ("identifier", arg2); | 1349 tmp.assign ("identifier", arg2); |
1351 tmp.assign ("state", val); | 1350 tmp.assign ("state", val); |
1352 | 1351 |
1353 retval = tmp; | 1352 retval = tmp; |
1368 } | 1367 } |
1369 else if (argc == 2) | 1368 else if (argc == 2) |
1370 { | 1369 { |
1371 octave_value arg = args(0); | 1370 octave_value arg = args(0); |
1372 | 1371 |
1373 Octave_map old_warning_options = warning_options; | 1372 octave_map old_warning_options = warning_options; |
1374 | 1373 |
1375 if (arg.is_map ()) | 1374 if (arg.is_map ()) |
1376 { | 1375 { |
1377 Octave_map m = arg.map_value (); | 1376 octave_map m = arg.map_value (); |
1378 | 1377 |
1379 if (m.contains ("identifier") && m.contains ("state")) | 1378 if (m.contains ("identifier") && m.contains ("state")) |
1380 warning_options = m; | 1379 warning_options = m; |
1381 else | 1380 else |
1382 error ("warning: expecting structure with fields `identifier' and `state'"); | 1381 error ("warning: expecting structure with fields `identifier' and `state'"); |
1530 frame.protect_var (error_state); | 1529 frame.protect_var (error_state); |
1531 error_state = 0; | 1530 error_state = 0; |
1532 | 1531 |
1533 if (nargin < 2) | 1532 if (nargin < 2) |
1534 { | 1533 { |
1535 Octave_map err; | 1534 octave_scalar_map err; |
1536 | 1535 |
1537 err.assign ("message", Vlast_error_message); | 1536 err.assign ("message", Vlast_error_message); |
1538 err.assign ("identifier", Vlast_error_id); | 1537 err.assign ("identifier", Vlast_error_id); |
1539 | 1538 |
1540 err.assign ("stack", octave_value (Vlast_error_stack)); | 1539 err.assign ("stack", octave_value (Vlast_error_stack)); |
1553 else | 1552 else |
1554 error("lasterror: unrecognized string argument"); | 1553 error("lasterror: unrecognized string argument"); |
1555 } | 1554 } |
1556 else if (args(0).is_map ()) | 1555 else if (args(0).is_map ()) |
1557 { | 1556 { |
1558 Octave_map new_err = args(0).map_value (); | 1557 octave_scalar_map new_err = args(0).scalar_map_value (); |
1559 std::string new_error_message; | 1558 std::string new_error_message; |
1560 std::string new_error_id; | 1559 std::string new_error_id; |
1561 std::string new_error_file; | 1560 std::string new_error_file; |
1562 std::string new_error_name; | 1561 std::string new_error_name; |
1563 int new_error_line = -1; | 1562 int new_error_line = -1; |
1564 int new_error_column = -1; | 1563 int new_error_column = -1; |
1565 | 1564 |
1566 if (! error_state && new_err.contains ("message")) | 1565 if (! error_state && new_err.contains ("message")) |
1567 { | 1566 { |
1568 const std::string tmp = | 1567 const std::string tmp = |
1569 new_err.contents("message")(0).string_value (); | 1568 new_err.getfield("message").string_value (); |
1570 new_error_message = tmp; | 1569 new_error_message = tmp; |
1571 } | 1570 } |
1572 | 1571 |
1573 if (! error_state && new_err.contains ("identifier")) | 1572 if (! error_state && new_err.contains ("identifier")) |
1574 { | 1573 { |
1575 const std::string tmp = | 1574 const std::string tmp = |
1576 new_err.contents("identifier")(0).string_value (); | 1575 new_err.getfield("identifier").string_value (); |
1577 new_error_id = tmp; | 1576 new_error_id = tmp; |
1578 } | 1577 } |
1579 | 1578 |
1580 if (! error_state && new_err.contains ("stack")) | 1579 if (! error_state && new_err.contains ("stack")) |
1581 { | 1580 { |
1582 Octave_map new_err_stack = | 1581 octave_scalar_map new_err_stack = |
1583 new_err.contents("identifier")(0).map_value (); | 1582 new_err.getfield("identifier").scalar_map_value (); |
1584 | 1583 |
1585 if (! error_state && new_err_stack.contains ("file")) | 1584 if (! error_state && new_err_stack.contains ("file")) |
1586 { | 1585 { |
1587 const std::string tmp = | 1586 const std::string tmp = |
1588 new_err_stack.contents("file")(0).string_value (); | 1587 new_err_stack.getfield("file").string_value (); |
1589 new_error_file = tmp; | 1588 new_error_file = tmp; |
1590 } | 1589 } |
1591 | 1590 |
1592 if (! error_state && new_err_stack.contains ("name")) | 1591 if (! error_state && new_err_stack.contains ("name")) |
1593 { | 1592 { |
1594 const std::string tmp = | 1593 const std::string tmp = |
1595 new_err_stack.contents("name")(0).string_value (); | 1594 new_err_stack.getfield("name").string_value (); |
1596 new_error_name = tmp; | 1595 new_error_name = tmp; |
1597 } | 1596 } |
1598 | 1597 |
1599 if (! error_state && new_err_stack.contains ("line")) | 1598 if (! error_state && new_err_stack.contains ("line")) |
1600 { | 1599 { |
1601 const int tmp = | 1600 const int tmp = |
1602 new_err_stack.contents("line")(0).nint_value (); | 1601 new_err_stack.getfield("line").nint_value (); |
1603 new_error_line = tmp; | 1602 new_error_line = tmp; |
1604 } | 1603 } |
1605 | 1604 |
1606 if (! error_state && new_err_stack.contains ("column")) | 1605 if (! error_state && new_err_stack.contains ("column")) |
1607 { | 1606 { |
1608 const int tmp = | 1607 const int tmp = |
1609 new_err_stack.contents("column")(0).nint_value (); | 1608 new_err_stack.getfield("column").nint_value (); |
1610 new_error_column = tmp; | 1609 new_error_column = tmp; |
1611 } | 1610 } |
1612 } | 1611 } |
1613 | 1612 |
1614 if (! error_state) | 1613 if (! error_state) |