Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/pt-funcall.cc @ 18588:932aca9a7c57
Allow multi-level classdef package.
* lex.h (octave_base_lexer::fq_identifier_contains_keyword,
octave_base_lexer::handle_fq_identifier,
octave_base_lexer::enable_fq_identifier): New methods.
* lex.ll (octave_base_lexer::fq_identifier_contains_keyword,
octave_base_lexer::handle_fq_identifier,
octave_base_lexer::enable_fq_identifier): Likewise.
(FQ_IDENT_START, FQIDENT): New exclusive start condition and regex to
handle fully-qualified identifier.
(superclass reference rule, metaclass query rule): Use FQIDENT.
(octave_base_lexer::handle_superclass_identifier,
octave_base_lexer::handle_meta_identifier): Don't split package name.
* parse.h (octave_base_parser::make_superclass_ref,
octave_base_parser::make_meta_class_query): Remove package_nm argument.
* pt-classdef.h (tree_classdef_superclass::id,
tree_classdef_superclass::pkg): Removed members, replaced by cls_name.
(tree_classdef_superclass::~tree_classdef_superclass): Remove deletion
of removed members.
(tree_classdef_superclass::cls_name): New member.
(tree_classdef_superclass::tree_classdef_superclass): Initialize it.
(tree_classdef_superclass::ident, tree_classdef_superclass::package):
Removed methods.
(tree_classdef_superclass::class_name): New method.
* token.h (token::meta_name_token): Remove enum value.
(token(int, std::string, std::string, std::string, int, int)): Remove
constructor.
(token::superclass_package_name, token::meta_package_name,
token::meta_class_name): Remove methods.
(token::sc::package_nm, token::mc): Remove union members.
* token.cc
(token(int, std::string, std::string, std::string, int, int)): Remove
constructor.
(token::~token): Remove case of meta_name_token.
(token::superclass_package_name, token::meta_package_name,
token::meta_class_name): Remove methods.
* oct-parse.in.yy (FQ_IDENT): New terminal.
(superclass_identifier): Adapt to changes in class token and class
octave_base_parser.
(meta_identifier): Likewise.
(superclass_list): Add mid-rule to enable fully-qualified identifier.
(superclass): Use FQ_IDENT.
(octave_base_parser::make_superclass_ref,
octave_base_parser::make_meta_class_query): Remove package_nm argument.
* ov-classdef.cc (octave_classdef_superclass_ref::do_multi_index_op):
Adapt to removal of package_nm argument.
(F__meta_class_query__): Likewise.
(cdef_class::make_meta_class): Adapt to changes in class
tree_classdef_superclass.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Sat, 22 Feb 2014 19:56:17 -0500 |
parents | 9ca314e79956 |
children | bae00174787c |
rev | line source |
---|---|
15035 | 1 /* |
2 | |
17746
c4f5c781c3ca
maint: Update copyright notices.
John W. Eaton <jwe@octave.org>
parents:
15841
diff
changeset
|
3 Copyright (C) 2012-2013 John W. Eaton |
15035 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 3 of the License, or (at your | |
10 option) any later version. | |
11 | |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with Octave; see the file COPYING. If not, see | |
19 <http://www.gnu.org/licenses/>. | |
20 | |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "ov-fcn.h" | |
28 #include "pt-funcall.h" | |
29 #include "pt-walk.h" | |
30 | |
31 // Function call objects. | |
32 | |
33 void | |
34 tree_funcall::print (std::ostream& os, bool pr_as_read_syntax, | |
35 bool pr_orig_text) | |
36 { | |
37 print_raw (os, pr_as_read_syntax, pr_orig_text); | |
38 } | |
39 | |
40 void | |
41 tree_funcall::print_raw (std::ostream& os, bool pr_as_read_syntax, | |
42 bool pr_orig_text) | |
43 { | |
44 if (pr_orig_text) | |
45 { | |
46 os << original_text (); | |
47 } | |
48 else | |
49 { | |
50 octave_function *fp = fcn.function_value (); | |
51 std::string nm = fp ? fp->name () : std::string ("<invalid-function>"); | |
52 | |
53 os << nm << " ("; | |
54 | |
55 octave_idx_type len = args.length (); | |
56 for (octave_idx_type i = 0; i < len; i++) | |
57 { | |
58 args(i).print_raw (os, pr_as_read_syntax); | |
59 | |
60 if (i < len - 1) | |
61 os << ", "; | |
62 } | |
63 | |
64 os << ")"; | |
65 } | |
66 } | |
67 | |
68 tree_funcall * | |
69 tree_funcall::dup (symbol_table::scope_id, | |
70 symbol_table::context_id context) const | |
71 { | |
72 tree_funcall *new_fc = new tree_funcall (fcn, args, line (), column ()); | |
73 | |
74 new_fc->copy_base (*new_fc); | |
75 | |
76 return new_fc; | |
77 } | |
78 | |
79 void | |
80 tree_funcall::accept (tree_walker& tw) | |
81 { | |
82 tw.visit_funcall (*this); | |
83 } | |
18423
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
84 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
85 octave_value_list |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
86 tree_funcall::rvalue (int nargout) |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
87 { |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
88 octave_value_list retval; |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
89 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
90 retval = feval (fcn.function_value (), args, nargout); |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
91 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
92 if (retval.length () == 1 && retval(0).is_function ()) |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
93 { |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
94 // The return object is a function. We may need to re-index it using the |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
95 // same logic as for identifier. This is primarily used for superclass |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
96 // references in classdef. |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
97 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
98 octave_value val = retval(0); |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
99 octave_function *f = val.function_value (true); |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
100 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
101 if (f && ! (is_postfix_indexed () |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
102 && f->is_postfix_index_handled (postfix_index ()))) |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
103 { |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
104 octave_value_list tmp_args; |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
105 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
106 retval = val.do_multi_index_op (nargout, tmp_args); |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
107 } |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
108 } |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
109 |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
110 return retval; |
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17746
diff
changeset
|
111 } |