Mercurial > octave
comparison libinterp/corefcn/symtab.h @ 21574:ae4d7dfea337
maint: merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 01 Apr 2016 12:57:49 -0400 |
parents | dfce76507f4b f3f8e1d3e399 |
children | b571fc85953f |
comparison
equal
deleted
inserted
replaced
21571:feac06371be1 | 21574:ae4d7dfea337 |
---|---|
46 class | 46 class |
47 OCTINTERP_API | 47 OCTINTERP_API |
48 symbol_table | 48 symbol_table |
49 { | 49 { |
50 public: | 50 public: |
51 | |
52 static octave_value dummy_octave_value; | |
51 | 53 |
52 typedef int scope_id; | 54 typedef int scope_id; |
53 typedef size_t context_id; | 55 typedef size_t context_id; |
54 | 56 |
55 class | 57 class |
260 return (p == symbol_table::global_table.end ()) | 262 return (p == symbol_table::global_table.end ()) |
261 ? symbol_table::global_table[name] : p->second; | 263 ? symbol_table::global_table[name] : p->second; |
262 } | 264 } |
263 else if (is_persistent ()) | 265 else if (is_persistent ()) |
264 { | 266 { |
265 static octave_value foobar; | |
266 | |
267 symbol_table *inst | 267 symbol_table *inst |
268 = symbol_table::get_instance (symbol_table::current_scope ()); | 268 = symbol_table::get_instance (symbol_table::current_scope ()); |
269 | 269 |
270 return inst ? inst->do_persistent_varref (name) : foobar; | 270 return inst ? inst->do_persistent_varref (name) : dummy_octave_value; |
271 } | 271 } |
272 else | 272 else |
273 { | 273 { |
274 if (context == xdefault_context) | 274 if (context == xdefault_context) |
275 context = active_context (); | 275 context = active_context (); |
652 symbol_record_rep *rep; | 652 symbol_record_rep *rep; |
653 | 653 |
654 symbol_record (symbol_record_rep *new_rep) : rep (new_rep) { } | 654 symbol_record (symbol_record_rep *new_rep) : rep (new_rep) { } |
655 }; | 655 }; |
656 | 656 |
657 static symbol_record dummy_symbol_record; | |
658 | |
657 // Always access a symbol from the current scope. | 659 // Always access a symbol from the current scope. |
658 // Useful for scripts, as they may be executed in more than one scope. | 660 // Useful for scripts, as they may be executed in more than one scope. |
659 class | 661 class |
660 symbol_reference | 662 symbol_reference |
661 { | 663 { |
1308 | 1310 |
1309 // Insert a new name in the table. | 1311 // Insert a new name in the table. |
1310 static symbol_record& insert (const std::string& name, | 1312 static symbol_record& insert (const std::string& name, |
1311 scope_id scope = xcurrent_scope) | 1313 scope_id scope = xcurrent_scope) |
1312 { | 1314 { |
1313 static symbol_record foobar; | |
1314 | |
1315 symbol_table *inst = get_instance (scope); | 1315 symbol_table *inst = get_instance (scope); |
1316 | 1316 |
1317 return inst ? inst->do_insert (name) : foobar; | 1317 return inst ? inst->do_insert (name) : symbol_table::dummy_symbol_record; |
1318 } | 1318 } |
1319 | 1319 |
1320 static void rename (const std::string& old_name, | 1320 static void rename (const std::string& old_name, |
1321 const std::string& new_name, | 1321 const std::string& new_name, |
1322 scope_id scope = xcurrent_scope) | 1322 scope_id scope = xcurrent_scope) |
1331 const octave_value& value = octave_value (), | 1331 const octave_value& value = octave_value (), |
1332 scope_id scope = xcurrent_scope, | 1332 scope_id scope = xcurrent_scope, |
1333 context_id context = xdefault_context, | 1333 context_id context = xdefault_context, |
1334 bool force_add = false) | 1334 bool force_add = false) |
1335 { | 1335 { |
1336 static octave_value foobar; | |
1337 | |
1338 symbol_table *inst = get_instance (scope); | 1336 symbol_table *inst = get_instance (scope); |
1339 | 1337 |
1340 if (inst) | 1338 if (inst) |
1341 inst->do_assign (name, value, context, force_add); | 1339 inst->do_assign (name, value, context, force_add); |
1342 } | 1340 } |
1344 OCTAVE_DEPRECATED ("use 'assign' instead") | 1342 OCTAVE_DEPRECATED ("use 'assign' instead") |
1345 static octave_value& | 1343 static octave_value& |
1346 varref (const std::string& name, scope_id scope = xcurrent_scope, | 1344 varref (const std::string& name, scope_id scope = xcurrent_scope, |
1347 context_id context = xdefault_context, bool force_add = false) | 1345 context_id context = xdefault_context, bool force_add = false) |
1348 { | 1346 { |
1349 static octave_value foobar; | |
1350 | |
1351 symbol_table *inst = get_instance (scope); | 1347 symbol_table *inst = get_instance (scope); |
1352 | 1348 |
1353 return inst ? inst->do_varref (name, context, force_add) : foobar; | 1349 return inst ? inst->do_varref (name, context, force_add) : dummy_octave_value; |
1354 } | 1350 } |
1355 | 1351 |
1356 // Convenience function to simplify | 1352 // Convenience function to simplify |
1357 // octave_user_function::bind_automatic_vars | 1353 // octave_user_function::bind_automatic_vars |
1358 | 1354 |
1367 OCTAVE_DEPRECATED ("use 'force_assign' instead") | 1363 OCTAVE_DEPRECATED ("use 'force_assign' instead") |
1368 static octave_value& | 1364 static octave_value& |
1369 force_varref (const std::string& name, scope_id scope = xcurrent_scope, | 1365 force_varref (const std::string& name, scope_id scope = xcurrent_scope, |
1370 context_id context = xdefault_context) | 1366 context_id context = xdefault_context) |
1371 { | 1367 { |
1372 static octave_value foobar; | |
1373 | |
1374 symbol_table *inst = get_instance (scope); | 1368 symbol_table *inst = get_instance (scope); |
1375 | 1369 |
1376 return inst ? inst->do_varref (name, context, true) : foobar; | 1370 return inst ? inst->do_varref (name, context, true) : dummy_octave_value; |
1377 } | 1371 } |
1378 | 1372 |
1379 static octave_value varval (const std::string& name, | 1373 static octave_value varval (const std::string& name, |
1380 scope_id scope = xcurrent_scope, | 1374 scope_id scope = xcurrent_scope, |
1381 context_id context = xdefault_context) | 1375 context_id context = xdefault_context) |
1425 | 1419 |
1426 OCTAVE_DEPRECATED ("use 'top_level_assign' instead") | 1420 OCTAVE_DEPRECATED ("use 'top_level_assign' instead") |
1427 static octave_value& | 1421 static octave_value& |
1428 top_level_varref (const std::string& name) | 1422 top_level_varref (const std::string& name) |
1429 { | 1423 { |
1430 static octave_value foobar; | |
1431 | |
1432 symbol_table *inst = get_instance (top_scope ()); | 1424 symbol_table *inst = get_instance (top_scope ()); |
1433 | 1425 |
1434 return inst ? inst->do_varref (name, 0, true) : foobar; | 1426 return inst ? inst->do_varref (name, 0, true) : dummy_octave_value; |
1435 } | 1427 } |
1436 | 1428 |
1437 static octave_value | 1429 static octave_value |
1438 top_level_varval (const std::string& name) | 1430 top_level_varval (const std::string& name) |
1439 { | 1431 { |
1452 | 1444 |
1453 OCTAVE_DEPRECATED ("use 'persistent_assign' instead") | 1445 OCTAVE_DEPRECATED ("use 'persistent_assign' instead") |
1454 static octave_value& | 1446 static octave_value& |
1455 persistent_varref (const std::string& name) | 1447 persistent_varref (const std::string& name) |
1456 { | 1448 { |
1457 static octave_value foobar; | |
1458 | |
1459 symbol_table *inst = get_instance (xcurrent_scope); | 1449 symbol_table *inst = get_instance (xcurrent_scope); |
1460 | 1450 |
1461 return inst ? inst->do_persistent_varref (name) : foobar; | 1451 return inst ? inst->do_persistent_varref (name) : dummy_octave_value; |
1462 } | 1452 } |
1463 | 1453 |
1464 static octave_value persistent_varval (const std::string& name) | 1454 static octave_value persistent_varval (const std::string& name) |
1465 { | 1455 { |
1466 symbol_table *inst = get_instance (xcurrent_scope); | 1456 symbol_table *inst = get_instance (xcurrent_scope); |