Mercurial > hg > octave-nkf
changeset 16211:3449bf257514 classdef
maint: fix botched merge of default to classdef
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 07 Mar 2013 10:23:02 -0500 |
parents | a8f9eb92fa6e |
children | d2b268936783 |
files | libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll libinterp/parse-tree/oct-parse.in.yy libinterp/parse-tree/parse.h |
diffstat | 4 files changed, 63 insertions(+), 361 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h +++ b/libinterp/parse-tree/lex.h @@ -169,7 +169,9 @@ looking_at_matrix_or_assign_lhs (false), looking_for_object_index (false), looking_at_indirect_ref (false), parsing_class_method (false), - maybe_classdef_get_set_method (false), parsing_classdef (false), + parsing_classdef (false), maybe_classdef_get_set_method (false), + parsing_classdef_get_method (false), + parsing_classdef_set_method (false), quote_is_transpose (false), force_script (false), reading_fcn_file (false), reading_script_file (false), reading_classdef_file (false), @@ -197,16 +199,9 @@ // matrix definition. bool convert_spaces_to_comma; -<<<<<<< local - void prep_for_classdef_file (void); -======= // gag. stupid kludge so that [[1,2][3,4]] will work. bool do_comma_insert; ->>>>>>> other -<<<<<<< local - int octave_read (char *buf, unsigned int max_size); -======= // true means we are at the beginning of a statement, where a // command name is possible. bool at_beginning_of_statement; @@ -242,13 +237,19 @@ // true means we are parsing a class method in function or classdef file. bool parsing_class_method; + // true means we are parsing a classdef file + bool parsing_classdef; + // true means we are parsing a class method declaration line in a // classdef file and can accept a property get or set method name. // for example, "get.propertyname" is recognized as a function name. bool maybe_classdef_get_set_method; - // true means we are parsing a classdef file - bool parsing_classdef; + // TRUE means we are parsing a classdef get.method. + bool parsing_classdef_get_method; + + // TRUE means we are parsing a classdef set.method. + bool parsing_classdef_set_method; // return transpose or start a string? bool quote_is_transpose; @@ -403,7 +404,6 @@ int read (char *buf, unsigned int max_size); int handle_end_of_input (void); ->>>>>>> other char *flex_yytext (void); @@ -515,94 +515,10 @@ return input_source () == "file"; } -<<<<<<< local - // TRUE means we're parsing the parameter list for a function. - bool looking_at_parameter_list; - - // TRUE means we're parsing a declaration list (global or - // persistent). - bool looking_at_decl_list; - - // TRUE means we are looking at the initializer expression for a - // parameter list element. - bool looking_at_initializer_expression; - - // TRUE means we're parsing a matrix or the left hand side of - // multi-value assignment statement. - bool looking_at_matrix_or_assign_lhs; - - // Object index not possible until we've seen something. - bool looking_for_object_index; - - // TRUE means we're looking at an indirect reference to a - // structure element. - bool looking_at_indirect_ref; - - // TRUE means we are parsing a class method in function or classdef file. - bool parsing_class_method; - - // TRUE means we are parsing a class method declaration line in a - // classdef file and can accept a property get or set method name. - // For example, "get.PropertyName" is recognized as a function name. - bool maybe_classdef_get_set_method; - - // TRUE means we are parsing a classdef file - bool parsing_classdef; - - // TRUE means we are parsing a classdef get.method. - bool parsing_classdef_get_method; - - // TRUE means we are parsing a classdef set.method. - bool parsing_classdef_set_method; - - // Return transpose or start a string? - bool quote_is_transpose; - - // The current input line number. - int input_line_number; - - // The column of the current token. - int current_input_column; - - // Square bracket level count. - int bracketflag; - - // Curly brace level count. - int braceflag; - - // TRUE means we're in the middle of defining a loop. - int looping; - - // Nonzero means we're in the middle of defining a function. - int defining_func; - - // Nonzero means we are parsing a function handle. - int looking_at_function_handle; - - // Nestng level for blcok comments. - int block_comment_nesting_level; - - // If the front of the list is TRUE, the closest paren, brace, or - // bracket nesting is an index for an object. - std::list<bool> looking_at_object_index; - - // If the top of the stack is TRUE, then we've already seen the name - // of the current function. Should only matter if - // current_function_level > 0 - std::stack<bool> parsed_function_name; - - // Set of identifiers that might be local variable names. - std::set<std::string> pending_local_variables; - - // Is the closest nesting level a square bracket, squiggly brace or - // a paren? - bbp_nesting_level nesting_level; -======= bool input_from_eval_string (void) const { return input_source () == "eval_string"; } ->>>>>>> other // For unwind protect. static void cleanup (octave_lexer *lexer) { delete lexer; }
--- a/libinterp/parse-tree/lex.ll +++ b/libinterp/parse-tree/lex.ll @@ -46,13 +46,7 @@ %s COMMAND_START %s MATRIX_START -<<<<<<< local -%x SCRIPT_FILE_BEGIN -%x FUNCTION_FILE_BEGIN -%x CLASSDEF_FILE_BEGIN -======= %x INPUT_FILE_BEGIN ->>>>>>> other %{ @@ -278,14 +272,6 @@ DISPLAY_TOK_AND_RETURN (INPUT_FILE); } -<CLASSDEF_FILE_BEGIN>. { - LEXER_DEBUG ("<CLASSDEF_FILE_BEGIN>."); - - BEGIN (INITIAL); - curr_lexer->xunput (yytext[0], yytext); - COUNT_TOK_AND_RETURN (CLASSDEF_FILE); - } - %{ // Help and other command-style functions. %} @@ -1335,8 +1321,10 @@ looking_for_object_index = false; looking_at_indirect_ref = false; parsing_class_method = false; + parsing_classdef = false; maybe_classdef_get_set_method = false; - parsing_classdef = false; + parsing_classdef_get_method = false; + parsing_classdef_set_method = false; quote_is_transpose = false; force_script = false; reading_fcn_file = false; @@ -1480,39 +1468,12 @@ { OCTAVE_YYG; - reading_script_file = true; - BEGIN (INPUT_FILE_BEGIN); } int octave_lexer::read (char *buf, unsigned max_size) { -<<<<<<< local - OCTAVE_YYG; - - BEGIN (FUNCTION_FILE_BEGIN); -} - -void -lexical_feedback::prep_for_classdef_file (void) -{ - OCTAVE_YYG; - - BEGIN (CLASSDEF_FILE_BEGIN); -} - -int -lexical_feedback::octave_read (char *buf, unsigned max_size) -{ - static const char * const eol = "\n"; - static std::string input_buf; - static const char *pos = 0; - static size_t chars_left = 0; - static bool eof = false; - -======= ->>>>>>> other int status = 0; if (input_buf.empty ()) @@ -3765,13 +3726,7 @@ case LEXICAL_ERROR: std::cerr << "LEXICAL_ERROR\n\n"; break; case FCN: std::cerr << "FCN\n"; break; case CLOSE_BRACE: std::cerr << "CLOSE_BRACE\n"; break; -<<<<<<< local - case SCRIPT_FILE: std::cerr << "SCRIPT_FILE\n"; break; - case FUNCTION_FILE: std::cerr << "FUNCTION_FILE\n"; break; - case CLASSDEF_FILE: std::cerr << "CLASSDEF_FILE\n"; break; -======= case INPUT_FILE: std::cerr << "INPUT_FILE\n"; break; ->>>>>>> other case SUPERCLASSREF: std::cerr << "SUPERCLASSREF\n"; break; case METAQUERY: std::cerr << "METAQUERY\n"; break; case GET: std::cerr << "GET\n"; break; @@ -3817,10 +3772,6 @@ std::cerr << "INPUT_FILE_BEGIN" << std::endl; break; - case CLASSDEF_FILE_BEGIN: - std::cerr << "CLASSDEF_FILE_BEGIN" << std::endl; - break; - default: std::cerr << "UNKNOWN START STATE!" << std::endl; break;
--- a/libinterp/parse-tree/oct-parse.in.yy +++ b/libinterp/parse-tree/oct-parse.in.yy @@ -255,24 +255,14 @@ // Other tokens. %token END_OF_INPUT LEXICAL_ERROR -<<<<<<< local -%token FCN SCRIPT_FILE CLASSDEF_FILE FUNCTION_FILE -======= -%token FCN INPUT_FILE CLASSDEF ->>>>>>> other +%token FCN INPUT_FILE // %token VARARGIN VARARGOUT %token CLOSE_BRACE // Nonterminals we construct. -<<<<<<< local %type <comment_type> stash_comment function_beg %type <tok_type> classdef_beg -%type <sep_type> sep_no_nl opt_sep_no_nl sep opt_sep opt_comma -======= -%type <comment_type> stash_comment function_beg classdef_beg -%type <comment_type> properties_beg methods_beg events_beg enum_beg %type <sep_type> sep_no_nl opt_sep_no_nl nl opt_nl sep opt_sep opt_comma ->>>>>>> other %type <tree_type> input %type <tree_constant_type> string constant magic_colon %type <tree_anon_fcn_handle_type> anon_fcn_handle @@ -292,16 +282,10 @@ %type <tree_parameter_list_type> param_list param_list1 param_list2 %type <tree_parameter_list_type> return_list return_list1 %type <tree_command_type> command select_command loop_command -<<<<<<< local %type <tree_command_type> jump_command except_command %type <tree_function_def_type> function %type <tree_classdef_type> classdef -%type <tree_command_type> script_file classdef_file -%type <tree_command_type> function_file function_list -======= -%type <tree_command_type> jump_command except_command function -%type <tree_command_type> file classdef ->>>>>>> other +%type <tree_command_type> file %type <tree_if_command_type> if_command %type <tree_if_clause_type> elseif_clause else_clause %type <tree_if_command_list_type> if_cmd_list1 if_cmd_list @@ -363,13 +347,6 @@ promptflag = 1; YYACCEPT; } -<<<<<<< local - | function_file - { YYACCEPT; } - | classdef_file - { YYACCEPT; } -======= ->>>>>>> other | simple_list parse_error { ABORT_PARSE; } | parse_error @@ -464,9 +441,9 @@ std::string package_nm = $1->superclass_package_name (); std::string class_nm = $1->superclass_class_name (); - $$ = curr_parser->make_superclass_ref - (method_nm, package_nm, class_nm, - $1->line (), $1->column ()); + $$ = curr_parser.make_superclass_ref + (method_nm, package_nm, class_nm, + $1->line (), $1->column ()); } ; @@ -475,9 +452,9 @@ std::string package_nm = $1->meta_package_name (); std::string class_nm = $1->meta_class_name (); - $$ = curr_parser->make_meta_class_query - (package_nm, class_nm, - $1->line (), $1->column ()); + $$ = curr_parser.make_meta_class_query + (package_nm, class_nm, + $1->line (), $1->column ()); } ; @@ -1189,6 +1166,13 @@ $$ = 0; } + | INPUT_FILE opt_nl classdef opt_sep END_OF_INPUT + { + if (curr_lexer->reading_classdef_file) + curr_parser.classdef_object = $3; + + $$ = 0; + } ; // =================== @@ -1302,26 +1286,15 @@ } ; -// ============= -// Classdef file -// ============= - -classdef_file : CLASSDEF_FILE classdef opt_sep END_OF_INPUT - { - curr_parser->classdef_object = $2; - $$ = 0; - } - ; - // ======== // Classdef // ======== classdef_beg : CLASSDEF { - if (! reading_classdef_file) + if (! curr_lexer->reading_classdef_file) { - curr_parser->bison_error ("classdef must appear inside a file containing only a class definition"); + curr_parser.bison_error ("classdef must appear inside a file containing only a class definition"); YYABORT; } @@ -1333,14 +1306,7 @@ classdef : classdef_beg stash_comment opt_attr_list identifier opt_superclass_list opt_sep class_body opt_sep END { curr_lexer->parsing_classdef = false; -<<<<<<< local - if (! ($$ = curr_parser->make_classdef ($1, $3, $4, $5, $7, $9, $2))) -======= - - if (curr_parser.end_token_ok ($1, token::classdef_end)) - $$ = curr_parser.make_end ("endclassdef", $1->line (), $1->column ()); - else ->>>>>>> other + if (! ($$ = curr_parser.make_classdef ($1, $3, $4, $5, $7, $9, $2))) ABORT_PARSE; } ; @@ -1426,8 +1392,8 @@ properties_block : PROPERTIES stash_comment opt_attr_list opt_sep property_list opt_sep END { - if (! ($$ = curr_parser->make_classdef_properties_block - ($1, $3, $5, $7, $2))) + if (! ($$ = curr_parser.make_classdef_properties_block + ($1, $3, $5, $7, $2))) ABORT_PARSE; } ; @@ -1453,8 +1419,8 @@ methods_block : METHODS stash_comment opt_attr_list opt_sep methods_list opt_sep END { - if (! ($$ = curr_parser->make_classdef_methods_block - ($1, $3, $5, $7, $2))) + if (! ($$ = curr_parser.make_classdef_methods_block + ($1, $3, $5, $7, $2))) ABORT_PARSE; } ; @@ -1481,8 +1447,8 @@ events_block : EVENTS stash_comment opt_attr_list opt_sep events_list opt_sep END { - if (! ($$ = curr_parser->make_classdef_events_block - ($1, $3, $5, $7, $2))) + if (! ($$ = curr_parser.make_classdef_events_block + ($1, $3, $5, $7, $2))) ABORT_PARSE; } ; @@ -1502,8 +1468,8 @@ enum_block : ENUMERATION stash_comment opt_attr_list opt_sep enum_list opt_sep END { - if (! ($$ = curr_parser->make_classdef_enum_block - ($1, $3, $5, $7, $2))) + if (! ($$ = curr_parser.make_classdef_enum_block + ($1, $3, $5, $7, $2))) ABORT_PARSE; } ; @@ -3006,12 +2972,12 @@ std::string cls_name = id->name (); - std::string nm = curr_fcn_file_name; + std::string nm = curr_lexer->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); + nm = curr_lexer->fcn_file_name.substr (pos+1); if (nm != cls_name) { @@ -3482,171 +3448,46 @@ // octave_parser constructor sets this for us. frame.protect_var (CURR_LEXER); -<<<<<<< local - octave_parser *curr_parser = new octave_parser (); - frame.add_fcn (octave_parser::cleanup, curr_parser); -======= octave_parser curr_parser (ffile); ->>>>>>> other - -<<<<<<< local - curr_parser->curr_class_name = dispatch_type; - curr_parser->autoloading = autoload; - curr_parser->fcn_file_from_relative_lookup = relative_lookup; -======= + curr_parser.curr_class_name = dispatch_type; curr_parser.autoloading = autoload; curr_parser.fcn_file_from_relative_lookup = relative_lookup; ->>>>>>> other - -<<<<<<< local - std::string help_txt - = gobble_leading_white_space - (ffile, eof, - curr_parser->curr_lexer->input_line_number, - curr_parser->curr_lexer->current_input_column); -======= + // Do this with an unwind-protect cleanup function so that // the forced variables will be unmarked in the event of an // interrupt. symbol_table::scope_id scope = symbol_table::top_scope (); frame.add_fcn (symbol_table::unmark_forced_variables, scope); ->>>>>>> other - -<<<<<<< local - if (! help_txt.empty ()) - help_buf.push (help_txt); -======= + curr_parser.curr_lexer->force_script = force_script; curr_parser.curr_lexer->prep_for_file (); curr_parser.curr_lexer->parsing_class_method = ! dispatch_type.empty (); ->>>>>>> other - -<<<<<<< local - if (! eof) - { - std::string file_type; -======= + curr_parser.curr_lexer->fcn_file_name = file; curr_parser.curr_lexer->fcn_file_full_name = full_file; ->>>>>>> other - -<<<<<<< local - frame.protect_var (get_input_from_eval_string); - frame.protect_var (reading_fcn_file); - frame.protect_var (reading_script_file); - frame.protect_var (reading_classdef_file); - frame.protect_var (Vecho_executing_commands); -======= + int status = curr_parser.run (); ->>>>>>> other - -<<<<<<< local - get_input_from_eval_string = false; -======= + fcn_ptr = curr_parser.primary_fcn_ptr; ->>>>>>> other - -<<<<<<< local - if (! force_script && looking_at_function_keyword (ffile)) - { - file_type = "function"; - - Vecho_executing_commands = ECHO_OFF; - - reading_classdef_file = false; - reading_fcn_file = true; - reading_script_file = false; - } - else if (! force_script && looking_at_classdef_keyword (ffile)) - { - file_type = "classdef"; - - Vecho_executing_commands = ECHO_OFF; - - reading_classdef_file = true; - reading_fcn_file = false; - reading_script_file = false; - } - else + + if (status == 0) + { + if (curr_parser.curr_lexer->reading_classdef_file + && curr_parser.classdef_object) { - file_type = "script"; - - Vecho_executing_commands = ECHO_OFF; - - reading_classdef_file = false; - reading_fcn_file = false; - reading_script_file = true; - } - - // Do this with an unwind-protect cleanup function so that - // the forced variables will be unmarked in the event of an - // interrupt. - symbol_table::scope_id scope = symbol_table::top_scope (); - frame.add_fcn (symbol_table::unmark_forced_variables, scope); - - if (! help_txt.empty ()) - help_buf.push (help_txt); - - if (reading_script_file) - curr_parser->curr_lexer->prep_for_script_file (); - else if (reading_classdef_file) - curr_parser->curr_lexer->prep_for_classdef_file (); - else - curr_parser->curr_lexer->prep_for_function_file (); - - curr_parser->curr_lexer->parsing_class_method = ! dispatch_type.empty (); - - frame.protect_var (global_command); - - global_command = 0; - - int status = curr_parser->run (); - - // Use an unwind-protect cleanup function so that the - // global_command list will be deleted in the event of an - // interrupt. - - frame.add_fcn (cleanup_statement_list, &global_command); - - fcn_ptr = curr_parser->primary_fcn_ptr; - - if (status == 0) - { - if (reading_classdef_file && curr_parser->classdef_object) - { - // Convert parse tree for classdef object to - // meta.class info (and stash it in the symbol - // table?). Return pointer to constructor? - - if (fcn_ptr) - panic_impossible (); - - fcn_ptr = curr_parser->classdef_object->make_meta_class (); - } - } - else - { - error ("parse error while reading %s file %s", - file_type.c_str(), ff.c_str ()); + // Convert parse tree for classdef object to + // meta.class info (and stash it in the symbol + // table?). Return pointer to constructor? + + if (fcn_ptr) + panic_impossible (); + + fcn_ptr = curr_parser.classdef_object->make_meta_class (); } } else - { - int l = curr_parser->curr_lexer->input_line_number; - int c = curr_parser->curr_lexer->current_input_column; - - tree_statement *end_of_script - = curr_parser->make_end ("endscript", l, c); - - curr_parser->make_script (0, end_of_script); - - fcn_ptr = curr_parser->primary_fcn_ptr; - } -======= - if (status != 0) error ("parse error while reading file %s", full_file.c_str ()); ->>>>>>> other } else if (require_file) error ("no such file, '%s'", full_file.c_str ());
--- a/libinterp/parse-tree/parse.h +++ b/libinterp/parse-tree/parse.h @@ -151,12 +151,8 @@ parsing_subfunctions (false), max_fcn_depth (0), curr_fcn_depth (0), primary_fcn_scope (-1), curr_class_name (), function_scopes (), primary_fcn_ptr (0), -<<<<<<< local - classdef_object (0), curr_lexer (new lexical_feedback ()) -======= - stmt_list (0), + classdef_object (0), stmt_list (0), curr_lexer (new octave_lexer ()), parser_state (0) ->>>>>>> other { init (); } @@ -456,13 +452,11 @@ // Pointer to the primary user function or user script function. octave_function *primary_fcn_ptr; -<<<<<<< local // Pointer to the classdef object we just parsed, if any. tree_classdef *classdef_object; -======= + // Result of parsing input. tree_statement_list *stmt_list; ->>>>>>> other // State of the lexer. octave_lexer *curr_lexer;