# HG changeset patch # User Michael Goffioul # Date 1357264867 18000 # Node ID ce8ad12ce8a0e0dd0c8880946399a8c24b35c5a6 # Parent 1ca9beb2a1943b0cfd90bdb1b6c58004d41f9e98 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. diff -r 1ca9beb2a194 -r ce8ad12ce8a0 libinterp/parse-tree/oct-parse.yy --- 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 ();