comparison libinterp/octave-value/ov-classdef.cc @ 18520: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 00ba456b9aa8
children fe0e34be5576
comparison
equal deleted inserted replaced
18517:e1b9c8277ada 18520:932aca9a7c57
1219 ctx = get_class_context (meth_name, in_constructor); 1219 ctx = get_class_context (meth_name, in_constructor);
1220 1220
1221 if (! error_state && ctx.ok ()) 1221 if (! error_state && ctx.ok ())
1222 { 1222 {
1223 std::string mname = args(0).string_value (); 1223 std::string mname = args(0).string_value ();
1224 std::string pname = args(1).string_value (); 1224 std::string cname = args(1).string_value ();
1225 std::string cname = args(2).string_value (); 1225
1226 1226 cdef_class cls = lookup_class (cname);
1227 std::string cls_name = (pname.empty () ?
1228 cname : pname + "." + cname);
1229 cdef_class cls = lookup_class (cls_name);
1230 1227
1231 if (! error_state) 1228 if (! error_state)
1232 { 1229 {
1233 if (in_constructor) 1230 if (in_constructor)
1234 { 1231 {
1246 ::error ("cannot call superclass constructor with " 1243 ::error ("cannot call superclass constructor with "
1247 "variable `%s'", mname.c_str ()); 1244 "variable `%s'", mname.c_str ());
1248 } 1245 }
1249 else 1246 else
1250 ::error ("`%s' is not a direct superclass of `%s'", 1247 ::error ("`%s' is not a direct superclass of `%s'",
1251 cls_name.c_str (), ctx.get_name ().c_str ()); 1248 cname.c_str (), ctx.get_name ().c_str ());
1252 } 1249 }
1253 else 1250 else
1254 { 1251 {
1255 if (mname == meth_name) 1252 if (mname == meth_name)
1256 { 1253 {
1272 if (meth.ok ()) 1269 if (meth.ok ())
1273 retval = meth.execute (idx, nargout, true, 1270 retval = meth.execute (idx, nargout, true,
1274 meth_name); 1271 meth_name);
1275 else 1272 else
1276 ::error ("no method `%s' found in superclass `%s'", 1273 ::error ("no method `%s' found in superclass `%s'",
1277 meth_name.c_str (), cls_name.c_str ()); 1274 meth_name.c_str (), cname.c_str ());
1278 } 1275 }
1279 else 1276 else
1280 ::error ("`%s' is not a superclass of `%s'", 1277 ::error ("`%s' is not a superclass of `%s'",
1281 cls_name.c_str (), ctx.get_name ().c_str ()); 1278 cname.c_str (), ctx.get_name ().c_str ());
1282 } 1279 }
1283 else 1280 else
1284 ::error ("method name mismatch (`%s' != `%s')", 1281 ::error ("method name mismatch (`%s' != `%s')",
1285 mname.c_str (), meth_name.c_str ()); 1282 mname.c_str (), meth_name.c_str ());
1286 } 1283 }
1967 { 1964 {
1968 octave_value_list args = t.arguments (); 1965 octave_value_list args = t.arguments ();
1969 1966
1970 if (args(0).string_value () == obj_name) 1967 if (args(0).string_value () == obj_name)
1971 { 1968 {
1972 std::string package_name = args(1).string_value (); 1969 std::string class_name = args(1).string_value ();
1973 std::string class_name = args(2).string_value (); 1970
1974 1971 cdef_class cls = lookup_class (class_name, false);
1975 std::string ctor_name = (package_name.empty ()
1976 ? class_name
1977 : package_name + "." + class_name);
1978
1979 cdef_class cls = lookup_class (ctor_name, false);
1980 1972
1981 if (cls.ok ()) 1973 if (cls.ok ())
1982 ctor_list.push_back (cls); 1974 ctor_list.push_back (cls);
1983 } 1975 }
1984 } 1976 }
2700 if (t->superclass_list ()) 2692 if (t->superclass_list ())
2701 { 2693 {
2702 for (tree_classdef_superclass_list::iterator it = t->superclass_list ()->begin (); 2694 for (tree_classdef_superclass_list::iterator it = t->superclass_list ()->begin ();
2703 ! error_state && it != t->superclass_list ()->end (); ++it) 2695 ! error_state && it != t->superclass_list ()->end (); ++it)
2704 { 2696 {
2705 std::string sclass_name = 2697 std::string sclass_name = (*it)->class_name ();
2706 ((*it)->package () ? (*it)->package ()->name () + "." : std::string ())
2707 + (*it)->ident ()->name ();
2708 2698
2709 gnulib::printf ("superclass: %s\n", sclass_name.c_str ()); 2699 gnulib::printf ("superclass: %s\n", sclass_name.c_str ());
2710 2700
2711 cdef_class sclass = lookup_class (sclass_name); 2701 cdef_class sclass = lookup_class (sclass_name);
2712 2702
3870 @end deftypefn") 3860 @end deftypefn")
3871 { 3861 {
3872 octave_value retval; 3862 octave_value retval;
3873 3863
3874 std::cerr << "__meta_class_query__ (" 3864 std::cerr << "__meta_class_query__ ("
3875 << args(0).string_value () << ", " 3865 << args(0).string_value () << ")"
3876 << args(1).string_value () << ")"
3877 << std::endl; 3866 << std::endl;
3878 3867
3879 if (args.length () == 2) 3868 if (args.length () == 1)
3880 { 3869 {
3881 std::string pkg = args(0).string_value (); 3870 std::string cls = args(0).string_value ();
3882 std::string cls = args(1).string_value ();
3883
3884 if (! pkg.empty ())
3885 cls = pkg + "." + cls;
3886 3871
3887 if (! error_state) 3872 if (! error_state)
3888 retval = to_ov (lookup_class (cls)); 3873 retval = to_ov (lookup_class (cls));
3889 else 3874 else
3890 error ("invalid class name, expected a string value"); 3875 error ("invalid class name, expected a string value");