comparison src/variables.cc @ 3523:b80bbb43a1a9

[project @ 2000-02-02 10:25:52 by jwe]
author jwe
date Wed, 02 Feb 2000 10:26:25 +0000
parents 78e1e0007f0f
children ab7fa5a8f23f
comparison
equal deleted inserted replaced
3522:bd422cf62f0c 3523:b80bbb43a1a9
86 // Attributes of variables and functions. 86 // Attributes of variables and functions.
87 87
88 // Is this variable a builtin? 88 // Is this variable a builtin?
89 89
90 bool 90 bool
91 is_builtin_variable (const string& name) 91 is_builtin_variable (const std::string& name)
92 { 92 {
93 symbol_record *sr = global_sym_tab->lookup (name); 93 symbol_record *sr = global_sym_tab->lookup (name);
94 return (sr && sr->is_builtin_variable ()); 94 return (sr && sr->is_builtin_variable ());
95 } 95 }
96 96
97 // Is this a text-style function? 97 // Is this a text-style function?
98 98
99 bool 99 bool
100 is_text_function_name (const string& s) 100 is_text_function_name (const std::string& s)
101 { 101 {
102 symbol_record *sr = global_sym_tab->lookup (s); 102 symbol_record *sr = global_sym_tab->lookup (s);
103 return (sr && sr->is_text_function ()); 103 return (sr && sr->is_text_function ());
104 } 104 }
105 105
106 // Is this a built-in function? 106 // Is this a built-in function?
107 107
108 bool 108 bool
109 is_builtin_function_name (const string& s) 109 is_builtin_function_name (const std::string& s)
110 { 110 {
111 symbol_record *sr = global_sym_tab->lookup (s); 111 symbol_record *sr = global_sym_tab->lookup (s);
112 return (sr && sr->is_builtin_function ()); 112 return (sr && sr->is_builtin_function ());
113 } 113 }
114 114
115 // Is this a mapper function? 115 // Is this a mapper function?
116 116
117 bool 117 bool
118 is_mapper_function_name (const string& s) 118 is_mapper_function_name (const std::string& s)
119 { 119 {
120 symbol_record *sr = global_sym_tab->lookup (s); 120 symbol_record *sr = global_sym_tab->lookup (s);
121 return (sr && sr->is_mapper_function ()); 121 return (sr && sr->is_mapper_function ());
122 } 122 }
123 123
124 // Is this function globally in this scope? 124 // Is this function globally in this scope?
125 125
126 bool 126 bool
127 is_globally_visible (const string& name) 127 is_globally_visible (const std::string& name)
128 { 128 {
129 symbol_record *sr = curr_sym_tab->lookup (name); 129 symbol_record *sr = curr_sym_tab->lookup (name);
130 return (sr && sr->is_linked_to_global ()); 130 return (sr && sr->is_linked_to_global ());
131 } 131 }
132 132
133 // Is this octave_value a valid function? 133 // Is this octave_value a valid function?
134 134
135 octave_function * 135 octave_function *
136 is_valid_function (const string& fcn_name, const string& warn_for, bool warn) 136 is_valid_function (const std::string& fcn_name, const std::string& warn_for, bool warn)
137 { 137 {
138 octave_function *ans = 0; 138 octave_function *ans = 0;
139 139
140 symbol_record *sr = 0; 140 symbol_record *sr = 0;
141 141
158 158
159 return ans; 159 return ans;
160 } 160 }
161 161
162 octave_function * 162 octave_function *
163 is_valid_function (const octave_value& arg, const string& warn_for, bool warn) 163 is_valid_function (const octave_value& arg, const std::string& warn_for, bool warn)
164 { 164 {
165 octave_function *ans = 0; 165 octave_function *ans = 0;
166 166
167 string fcn_name; 167 std::string fcn_name;
168 168
169 if (arg.is_string ()) 169 if (arg.is_string ())
170 fcn_name = arg.string_value (); 170 fcn_name = arg.string_value ();
171 171
172 if (! error_state) 172 if (! error_state)
176 176
177 return ans; 177 return ans;
178 } 178 }
179 179
180 octave_function * 180 octave_function *
181 extract_function (const octave_value& arg, const string& warn_for, 181 extract_function (const octave_value& arg, const std::string& warn_for,
182 const string& fname, const string& header, 182 const std::string& fname, const std::string& header,
183 const string& trailer) 183 const std::string& trailer)
184 { 184 {
185 octave_function *retval = 0; 185 octave_function *retval = 0;
186 186
187 retval = is_valid_function (arg, warn_for, 0); 187 retval = is_valid_function (arg, warn_for, 0);
188 188
189 if (! retval) 189 if (! retval)
190 { 190 {
191 string s = arg.string_value (); 191 std::string s = arg.string_value ();
192 192
193 string cmd = header; 193 std::string cmd = header;
194 cmd.append (s); 194 cmd.append (s);
195 cmd.append (trailer); 195 cmd.append (trailer);
196 196
197 if (! error_state) 197 if (! error_state)
198 { 198 {
222 222
223 return retval; 223 return retval;
224 } 224 }
225 225
226 string_vector 226 string_vector
227 get_struct_elts (const string& text) 227 get_struct_elts (const std::string& text)
228 { 228 {
229 int n = 1; 229 int n = 1;
230 230
231 size_t pos = 0; 231 size_t pos = 0;
232 232
259 259
260 return retval; 260 return retval;
261 } 261 }
262 262
263 string_vector 263 string_vector
264 generate_struct_completions (const string& text, string& prefix, string& hint) 264 generate_struct_completions (const std::string& text, std::string& prefix, std::string& hint)
265 { 265 {
266 string_vector names; 266 string_vector names;
267 267
268 size_t pos = text.rfind ('.'); 268 size_t pos = text.rfind ('.');
269 269
270 string id; 270 std::string id;
271 string_vector elts; 271 string_vector elts;
272 272
273 if (pos == NPOS) 273 if (pos == NPOS)
274 { 274 {
275 hint = text; 275 hint = text;
322 322
323 return names; 323 return names;
324 } 324 }
325 325
326 bool 326 bool
327 looks_like_struct (const string& text) 327 looks_like_struct (const std::string& text)
328 { 328 {
329 bool retval = true; 329 bool retval = true;
330 330
331 string_vector elts = get_struct_elts (text); 331 string_vector elts = get_struct_elts (text);
332 332
333 string id = elts[0]; 333 std::string id = elts[0];
334 334
335 symbol_record *sr = curr_sym_tab->lookup (id); 335 symbol_record *sr = curr_sym_tab->lookup (id);
336 336
337 if (! sr) 337 if (! sr)
338 sr = global_sym_tab->lookup (id); 338 sr = global_sym_tab->lookup (id);
389 { 389 {
390 print_usage ("is_global"); 390 print_usage ("is_global");
391 return retval; 391 return retval;
392 } 392 }
393 393
394 string name = args(0).string_value (); 394 std::string name = args(0).string_value ();
395 395
396 if (error_state) 396 if (error_state)
397 { 397 {
398 error ("is_global: expecting string argument"); 398 error ("is_global: expecting std::string argument");
399 return retval; 399 return retval;
400 } 400 }
401 401
402 symbol_record *sr = curr_sym_tab->lookup (name); 402 symbol_record *sr = curr_sym_tab->lookup (name);
403 403
428 { 428 {
429 print_usage ("exist"); 429 print_usage ("exist");
430 return retval; 430 return retval;
431 } 431 }
432 432
433 string name = args(0).string_value (); 433 std::string name = args(0).string_value ();
434 434
435 if (error_state) 435 if (error_state)
436 { 436 {
437 error ("exist: expecting string argument"); 437 error ("exist: expecting std::string argument");
438 return retval; 438 return retval;
439 } 439 }
440 440
441 string struct_elts; 441 std::string struct_elts;
442 string symbol_name = name; 442 std::string symbol_name = name;
443 443
444 size_t pos = name.find ('.'); 444 size_t pos = name.find ('.');
445 445
446 if (pos != NPOS && pos > 0) 446 if (pos != NPOS && pos > 0)
447 { 447 {
473 { 473 {
474 retval = 2.0; 474 retval = 2.0;
475 } 475 }
476 else 476 else
477 { 477 {
478 string path = fcn_file_in_path (name); 478 std::string path = fcn_file_in_path (name);
479 479
480 if (path.length () > 0) 480 if (path.length () > 0)
481 { 481 {
482 retval = 2.0; 482 retval = 2.0;
483 } 483 }
489 { 489 {
490 retval = 3.0; 490 retval = 3.0;
491 } 491 }
492 else 492 else
493 { 493 {
494 string file_name = file_in_path (name, ""); 494 std::string file_name = file_in_path (name, "");
495 495
496 if (! file_name.empty ()) 496 if (! file_name.empty ())
497 { 497 {
498 file_stat fs (file_name); 498 file_stat fs (file_name);
499 499
521 521
522 octave_function *tmp = ans.function_value (true); 522 octave_function *tmp = ans.function_value (true);
523 523
524 if (tmp) 524 if (tmp)
525 { 525 {
526 string ff = tmp->fcn_file_name (); 526 std::string ff = tmp->fcn_file_name ();
527 527
528 if (! (ff.empty () 528 if (! (ff.empty ()
529 || (Vignore_function_time_stamp 529 || (Vignore_function_time_stamp
530 && tmp->is_system_fcn_file ()))) 530 && tmp->is_system_fcn_file ())))
531 { 531 {
532 if (tmp->time_checked () < Vlast_prompt_time) 532 if (tmp->time_checked () < Vlast_prompt_time)
533 { 533 {
534 time_t tp = tmp->time_parsed (); 534 time_t tp = tmp->time_parsed ();
535 535
536 string fname; 536 std::string fname;
537 537
538 if (tmp->is_dld_function ()) 538 if (tmp->is_dld_function ())
539 fname = ff; 539 fname = ff;
540 else 540 else
541 fname = fcn_file_in_path (ff); 541 fname = fcn_file_in_path (ff);
585 // out of date. If a function is available in a file but is not 585 // out of date. If a function is available in a file but is not
586 // currently loaded, this will load it and insert the name in the 586 // currently loaded, this will load it and insert the name in the
587 // current symbol table. 587 // current symbol table.
588 588
589 symbol_record * 589 symbol_record *
590 lookup_by_name (const string& nm, bool exec_script) 590 lookup_by_name (const std::string& nm, bool exec_script)
591 { 591 {
592 symbol_record *sym_rec = curr_sym_tab->lookup (nm, true); 592 symbol_record *sym_rec = curr_sym_tab->lookup (nm, true);
593 593
594 lookup (sym_rec, exec_script); 594 lookup (sym_rec, exec_script);
595 595
596 return sym_rec; 596 return sym_rec;
597 } 597 }
598 598
599 octave_value 599 octave_value
600 get_global_value (const string& nm) 600 get_global_value (const std::string& nm)
601 { 601 {
602 octave_value retval; 602 octave_value retval;
603 603
604 symbol_record *sr = global_sym_tab->lookup (nm); 604 symbol_record *sr = global_sym_tab->lookup (nm);
605 605
617 617
618 return retval; 618 return retval;
619 } 619 }
620 620
621 void 621 void
622 set_global_value (const string& nm, const octave_value& val) 622 set_global_value (const std::string& nm, const octave_value& val)
623 { 623 {
624 symbol_record *sr = global_sym_tab->lookup (nm, true); 624 symbol_record *sr = global_sym_tab->lookup (nm, true);
625 625
626 if (sr) 626 if (sr)
627 sr->define (val); 627 sr->define (val);
632 // Variable values. 632 // Variable values.
633 633
634 // Look for the given name in the global symbol table. If it refers 634 // Look for the given name in the global symbol table. If it refers
635 // to a string, return a new copy. If not, return 0; 635 // to a string, return a new copy. If not, return 0;
636 636
637 string 637 std::string
638 builtin_string_variable (const string& name) 638 builtin_string_variable (const std::string& name)
639 { 639 {
640 symbol_record *sr = global_sym_tab->lookup (name); 640 symbol_record *sr = global_sym_tab->lookup (name);
641 641
642 // It is a prorgramming error to look for builtins that aren't. 642 // It is a prorgramming error to look for builtins that aren't.
643 643
644 assert (sr); 644 assert (sr);
645 645
646 string retval; 646 std::string retval;
647 647
648 octave_value val = sr->def (); 648 octave_value val = sr->def ();
649 649
650 if (! error_state && val.is_string ()) 650 if (! error_state && val.is_string ())
651 retval = val.string_value (); 651 retval = val.string_value ();
656 // Look for the given name in the global symbol table. If it refers 656 // Look for the given name in the global symbol table. If it refers
657 // to a real scalar, place the value in d and return 1. Otherwise, 657 // to a real scalar, place the value in d and return 1. Otherwise,
658 // return 0. 658 // return 0.
659 659
660 int 660 int
661 builtin_real_scalar_variable (const string& name, double& d) 661 builtin_real_scalar_variable (const std::string& name, double& d)
662 { 662 {
663 int status = 0; 663 int status = 0;
664 symbol_record *sr = global_sym_tab->lookup (name); 664 symbol_record *sr = global_sym_tab->lookup (name);
665 665
666 // It is a prorgramming error to look for builtins that aren't. 666 // It is a prorgramming error to look for builtins that aren't.
679 } 679 }
680 680
681 // Look for the given name in the global symbol table. 681 // Look for the given name in the global symbol table.
682 682
683 octave_value 683 octave_value
684 builtin_any_variable (const string& name) 684 builtin_any_variable (const std::string& name)
685 { 685 {
686 symbol_record *sr = global_sym_tab->lookup (name); 686 symbol_record *sr = global_sym_tab->lookup (name);
687 687
688 // It is a prorgramming error to look for builtins that aren't. 688 // It is a prorgramming error to look for builtins that aren't.
689 689
705 { 705 {
706 sr->mark_as_linked_to_global (); 706 sr->mark_as_linked_to_global ();
707 707
708 if (! error_state) 708 if (! error_state)
709 { 709 {
710 string nm = sr->name (); 710 std::string nm = sr->name ();
711 711
712 symbol_record *gsr = global_sym_tab->lookup (nm, true); 712 symbol_record *gsr = global_sym_tab->lookup (nm, true);
713 713
714 // There must be a better way to do this. XXX FIXME XXX 714 // There must be a better way to do this. XXX FIXME XXX
715 715
754 // 754 //
755 // Return without doing anything if there isn't a function with the 755 // Return without doing anything if there isn't a function with the
756 // given name defined in the global symbol table. 756 // given name defined in the global symbol table.
757 757
758 void 758 void
759 force_link_to_function (const string& id_name) 759 force_link_to_function (const std::string& id_name)
760 { 760 {
761 symbol_record *gsr = global_sym_tab->lookup (id_name, true); 761 symbol_record *gsr = global_sym_tab->lookup (id_name, true);
762 if (gsr->is_function ()) 762 if (gsr->is_function ())
763 { 763 {
764 curr_sym_tab->clear (id_name); 764 curr_sym_tab->clear (id_name);
777 777
778 int nargin = args.length (); 778 int nargin = args.length ();
779 779
780 if (nargin == 2) 780 if (nargin == 2)
781 { 781 {
782 string name = args(0).string_value (); 782 std::string name = args(0).string_value ();
783 783
784 if (! error_state) 784 if (! error_state)
785 { 785 {
786 string help = args(1).string_value (); 786 std::string help = args(1).string_value ();
787 787
788 if (! error_state) 788 if (! error_state)
789 { 789 {
790 if (is_builtin_variable (name) 790 if (is_builtin_variable (name)
791 || is_text_function_name (name) 791 || is_text_function_name (name)
818 bool show_builtins = false; 818 bool show_builtins = false;
819 bool show_functions = false; 819 bool show_functions = false;
820 bool show_variables = false; 820 bool show_variables = false;
821 bool show_verbose = false; 821 bool show_verbose = false;
822 822
823 string my_name = argv[0]; 823 std::string my_name = argv[0];
824 824
825 int i; 825 int i;
826 for (i = 1; i < argc; i++) 826 for (i = 1; i < argc; i++)
827 { 827 {
828 if (argv[i] == "-all" || argv[i] == "-a") 828 if (argv[i] == "-all" || argv[i] == "-a")
1012 1012
1013 // How is this different than install_builtin_constant? Are both 1013 // How is this different than install_builtin_constant? Are both
1014 // functions needed? 1014 // functions needed?
1015 1015
1016 void 1016 void
1017 bind_builtin_constant (const string& name, const octave_value& val, 1017 bind_builtin_constant (const std::string& name, const octave_value& val,
1018 bool protect, bool eternal, const string& help) 1018 bool protect, bool eternal, const std::string& help)
1019 { 1019 {
1020 symbol_record *sym_rec = global_sym_tab->lookup (name, true); 1020 symbol_record *sym_rec = global_sym_tab->lookup (name, true);
1021 sym_rec->unprotect (); 1021 sym_rec->unprotect ();
1022 1022
1023 string tmp_help = help.empty () ? sym_rec->help () : help; 1023 std::string tmp_help = help.empty () ? sym_rec->help () : help;
1024 1024
1025 sym_rec->define_builtin_const (val); 1025 sym_rec->define_builtin_const (val);
1026 1026
1027 sym_rec->document (tmp_help); 1027 sym_rec->document (tmp_help);
1028 1028
1038 1038
1039 // How is this different than install_builtin_variable? Are both 1039 // How is this different than install_builtin_variable? Are both
1040 // functions needed? 1040 // functions needed?
1041 1041
1042 void 1042 void
1043 bind_builtin_variable (const string& varname, const octave_value& val, 1043 bind_builtin_variable (const std::string& varname, const octave_value& val,
1044 bool protect, bool eternal, 1044 bool protect, bool eternal,
1045 symbol_record::change_function chg_fcn, 1045 symbol_record::change_function chg_fcn,
1046 const string& help) 1046 const std::string& help)
1047 { 1047 {
1048 symbol_record *sr = global_sym_tab->lookup (varname, true); 1048 symbol_record *sr = global_sym_tab->lookup (varname, true);
1049 1049
1050 // It is a programming error for a builtin symbol to be missing. 1050 // It is a programming error for a builtin symbol to be missing.
1051 // Besides, we just inserted it, so it must be there. 1051 // Besides, we just inserted it, so it must be there.
1177 // pattern matching code if the string doesn't contain any 1177 // pattern matching code if the string doesn't contain any
1178 // globbing patterns. 1178 // globbing patterns.
1179 1179
1180 for (int k = idx; k < argc; k++) 1180 for (int k = idx; k < argc; k++)
1181 { 1181 {
1182 string patstr = argv[k]; 1182 std::string patstr = argv[k];
1183 1183
1184 if (! patstr.empty ()) 1184 if (! patstr.empty ())
1185 { 1185 {
1186 glob_match pattern (patstr); 1186 glob_match pattern (patstr);
1187 1187
1188 int lcount = lvars.length (); 1188 int lcount = lvars.length ();
1189 1189
1190 for (int i = 0; i < lcount; i++) 1190 for (int i = 0; i < lcount; i++)
1191 { 1191 {
1192 string nm = lvars[i]; 1192 std::string nm = lvars[i];
1193 int match = pattern.match (nm); 1193 int match = pattern.match (nm);
1194 if ((exclusive && ! match) || (! exclusive && match)) 1194 if ((exclusive && ! match) || (! exclusive && match))
1195 curr_sym_tab->clear (nm); 1195 curr_sym_tab->clear (nm);
1196 } 1196 }
1197 1197
1198 int gcount = gvars.length (); 1198 int gcount = gvars.length ();
1199 for (int i = 0; i < gcount; i++) 1199 for (int i = 0; i < gcount; i++)
1200 { 1200 {
1201 string nm = gvars[i]; 1201 std::string nm = gvars[i];
1202 int match = pattern.match (nm); 1202 int match = pattern.match (nm);
1203 if ((exclusive && ! match) || (! exclusive && match)) 1203 if ((exclusive && ! match) || (! exclusive && match))
1204 { 1204 {
1205 int count = curr_sym_tab->clear (nm); 1205 int count = curr_sym_tab->clear (nm);
1206 if (count > 0) 1206 if (count > 0)
1209 } 1209 }
1210 1210
1211 int fcount = fcns.length (); 1211 int fcount = fcns.length ();
1212 for (int i = 0; i < fcount; i++) 1212 for (int i = 0; i < fcount; i++)
1213 { 1213 {
1214 string nm = fcns[i]; 1214 std::string nm = fcns[i];
1215 int match = pattern.match (nm); 1215 int match = pattern.match (nm);
1216 if ((exclusive && ! match) || (! exclusive && match)) 1216 if ((exclusive && ! match) || (! exclusive && match))
1217 { 1217 {
1218 curr_sym_tab->clear (nm); 1218 curr_sym_tab->clear (nm);
1219 global_sym_tab->clear (nm, clear_user_functions); 1219 global_sym_tab->clear (nm, clear_user_functions);
1236 1236
1237 int nargin = args.length (); 1237 int nargin = args.length ();
1238 1238
1239 if (nargin == 1) 1239 if (nargin == 1)
1240 { 1240 {
1241 string arg = args(0).string_value (); 1241 std::string arg = args(0).string_value ();
1242 1242
1243 if (arg == "global") 1243 if (arg == "global")
1244 global_sym_tab->print_stats (); 1244 global_sym_tab->print_stats ();
1245 else 1245 else
1246 print_usage ("__dump_symtab_info__"); 1246 print_usage ("__dump_symtab_info__");
1263 1263
1264 int nargin = args.length (); 1264 int nargin = args.length ();
1265 1265
1266 if (nargin == 1) 1266 if (nargin == 1)
1267 { 1267 {
1268 string symbol_name = args(0).string_value (); 1268 std::string symbol_name = args(0).string_value ();
1269 1269
1270 if (! error_state) 1270 if (! error_state)
1271 { 1271 {
1272 symbol_record *sr = curr_sym_tab->lookup (symbol_name); 1272 symbol_record *sr = curr_sym_tab->lookup (symbol_name);
1273 1273
1292 static int 1292 static int
1293 ignore_function_time_stamp (void) 1293 ignore_function_time_stamp (void)
1294 { 1294 {
1295 int pref = 0; 1295 int pref = 0;
1296 1296
1297 string val = builtin_string_variable ("ignore_function_time_stamp"); 1297 std::string val = builtin_string_variable ("ignore_function_time_stamp");
1298 1298
1299 if (! val.empty ()) 1299 if (! val.empty ())
1300 { 1300 {
1301 if (val.compare ("all", 0, 3) == 0) 1301 if (val.compare ("all", 0, 3) == 0)
1302 pref = 2; 1302 pref = 2;