changeset 18895:da6ffbf75edf

Simplify exist() code for recognizing command line functions. * variables.cc (symbol_exist): Short-circuit out quickly if search type is builtin and no builtin is found. Use the fact that all other cases have been checked by the end of the function to make the test for a command line function short. * variables.cc (Fexist): Expand %!tests.
author Rik <rik@octave.org>
date Wed, 25 Jun 2014 14:48:39 -0700
parents a1dde4d4c45c
children 6825522c25e4
files libinterp/corefcn/variables.cc
diffstat 1 files changed, 10 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/variables.cc	Wed Jun 25 14:03:20 2014 -0700
+++ b/libinterp/corefcn/variables.cc	Wed Jun 25 14:48:39 2014 -0700
@@ -421,6 +421,9 @@
       if ((search_any || search_builtin)
           && val.is_builtin_function ())
         return 5;
+
+      if (search_builtin)
+        return 0;
     }
 
   if (search_any || search_file || search_dir)
@@ -474,21 +477,9 @@
         return 0;
     }
 
-  if (val.is_defined ())
-    {
-      if ((search_any || search_file)
-          && (val.is_user_function () || val.is_dld_function ()))
-        {
-          octave_function *f = val.function_value (true);
-          std::string s = f ? f->fcn_file_name () : std::string ();
-
-          // FIXME: I believe that by this point in the code the only
-          //        return value is 103.  User functions should have
-          //        been located above.  Maybe replace entire if block
-          //        code with "return 103;"
-          return s.empty () ? 103 : (val.is_user_function () ? 2 : 3);
-        }
-    }
+  // Command line function which Matlab does not support
+  if (search_any && val.is_defined () && val.is_user_function ())
+    return 103;
 
   return 0;
 }
@@ -610,6 +601,8 @@
 
 %!assert (exist ("colon"), 2)
 %!assert (exist ("colon.m"), 2)
+%!assert (exist ("colon", "file"), 2)
+%!assert (exist ("colon", "dir"), 0)
 
 %!testif HAVE_CHOLMOD
 %! assert (exist ("chol"), 3);
@@ -618,6 +611,8 @@
 %! assert (exist ("chol", "builtin"), 0);
 
 %!assert (exist ("sin"), 5)
+%!assert (exist ("sin", "builtin"), 5)
+%!assert (exist ("sin", "file"), 0)
 
 %!assert (exist (dirtmp), 7)
 %!assert (exist (dirtmp, "dir"), 7)