changeset 15895:ce8ad12ce8a0 classdef

Force classdef name to match filename. * libinterp/parse-tree/oct-parse.yy (make_classdef): Fail if the class name does not match the filename. (rule classdef): abort parsing if make_classdef fails.
author Michael Goffioul <michael.goffioul@gmail.com>
date Thu, 03 Jan 2013 21:01:07 -0500
parents 1ca9beb2a194
children 57be060d7672
files libinterp/parse-tree/oct-parse.yy
diffstat 1 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.yy	Thu Jan 03 13:36:55 2013 -0500
+++ b/libinterp/parse-tree/oct-parse.yy	Thu Jan 03 21:01:07 2013 -0500
@@ -1589,7 +1589,8 @@
 classdef        : classdef_beg stash_comment opt_attr_list identifier opt_superclass_list opt_sep class_body opt_sep END
                   {
                     lexer_flags.parsing_classdef = false;
-                    $$ = make_classdef ($1, $3, $4, $5, $7, $9, $2);
+                    if (! ($$ = make_classdef ($1, $3, $4, $5, $7, $9, $2)))
+                      ABORT_PARSE;
                   }
                 ;
 
@@ -3450,6 +3451,21 @@
 {
   tree_classdef *retval = 0;
 
+  std::string cls_name = id->name ();
+
+  std::string nm = curr_fcn_file_name;
+
+  size_t pos = nm.find_last_of (file_ops::dir_sep_chars ());
+
+  if (pos != std::string::npos)
+    nm = curr_fcn_file_name.substr (pos+1);
+
+  if (nm != cls_name)
+    {
+      yyerror ("invalid classdef definition, the class name must match the file name");
+      return retval;
+    }
+
   if (end_token_ok (end_tok, token::classdef_end))
     {
       octave_comment_list *tc = octave_comment_buffer::get_comment ();