Mercurial > octave-nkf
comparison libinterp/interpfcn/symtab.cc @ 16070:e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
* libinterp/octave-value/ov-class.cc(inferiorto): Use only one call to
set_class_relationship() and properly use the returned value. Rewrite
for clarity (fewer braces, shorter lines).
(superiorto): Rewrite similarly to inferiorto() for clarity.
* libinterp/interpfcn/symtab.cc(symbol_table::set_class_relationship):
Reduce code redundancy using a call to is_superiorto(). Add a comment
to make it clear that a new entry in the precedence table is created
if sup_class is not already there.
(symbol_table::is_superiorto): Rewrite more concisely. Add a comment.
* test/classes/@CPrecedenceTester1, test/classes/@CPrecedenceTester2,
test/classes/@CPrecedenceTester3: New classes for precedence tests.
* test/classes/@Snork/tattack.m: New method for precedence tests.
* test/classes/classes.tst: Add precedence tests.
author | Julien Bect <julien.bect@supelec.fr> |
---|---|
date | Tue, 29 Jan 2013 17:55:53 +0100 |
parents | 049e8bbff782 |
children | 94e95309710c |
comparison
equal
deleted
inserted
replaced
16035:999f8257313b | 16070:e603ce23f20c |
---|---|
1011 | 1011 |
1012 bool | 1012 bool |
1013 symbol_table::set_class_relationship (const std::string& sup_class, | 1013 symbol_table::set_class_relationship (const std::string& sup_class, |
1014 const std::string& inf_class) | 1014 const std::string& inf_class) |
1015 { | 1015 { |
1016 class_precedence_table_const_iterator p | 1016 if (is_superiorto (inf_class, sup_class)) |
1017 = class_precedence_table.find (inf_class); | 1017 return false; |
1018 | 1018 |
1019 if (p != class_precedence_table.end ()) | 1019 // If sup_class doesn't have an entry in the precedence table, |
1020 { | 1020 // this will automatically create it, and associate to it a |
1021 const std::set<std::string>& inferior_classes = p->second; | 1021 // singleton set {inf_class} of inferior classes. |
1022 | |
1023 std::set<std::string>::const_iterator q | |
1024 = inferior_classes.find (sup_class); | |
1025 | |
1026 if (q != inferior_classes.end ()) | |
1027 return false; | |
1028 } | |
1029 | |
1030 class_precedence_table[sup_class].insert (inf_class); | 1022 class_precedence_table[sup_class].insert (inf_class); |
1031 | 1023 |
1032 return true; | 1024 return true; |
1033 } | 1025 } |
1034 | 1026 |
1035 // Has class A been marked as superior to class B? Also returns | 1027 // Has class A been marked as superior to class B? Also returns |
1036 // TRUE if B has been marked as inferior to A, since we only keep | 1028 // TRUE if B has been marked as inferior to A, since we only keep |
1037 // one table, and convert inferiort information to a superiorto | 1029 // one table, and convert inferiorto information to a superiorto |
1038 // relationship. Two calls are required to determine whether there | 1030 // relationship. Two calls are required to determine whether there |
1039 // is no relationship between two classes: | 1031 // is no relationship between two classes: |
1040 // | 1032 // |
1041 // if (symbol_table::is_superiorto (a, b)) | 1033 // if (symbol_table::is_superiorto (a, b)) |
1042 // // A is superior to B, or B has been marked inferior to A. | 1034 // // A is superior to B, or B has been marked inferior to A. |
1046 // // No relation. | 1038 // // No relation. |
1047 | 1039 |
1048 bool | 1040 bool |
1049 symbol_table::is_superiorto (const std::string& a, const std::string& b) | 1041 symbol_table::is_superiorto (const std::string& a, const std::string& b) |
1050 { | 1042 { |
1051 bool retval = false; | 1043 class_precedence_table_const_iterator p = class_precedence_table.find (a); |
1052 | 1044 // If a has no entry in the precedence table, return false |
1053 class_precedence_table_const_iterator p = class_precedence_table.find (a); | 1045 if (p == class_precedence_table.end ()) |
1054 | 1046 return false; |
1055 if (p != class_precedence_table.end ()) | 1047 |
1056 { | 1048 const std::set<std::string>& inferior_classes = p->second; |
1057 const std::set<std::string>& inferior_classes = p->second; | 1049 std::set<std::string>::const_iterator q = inferior_classes.find (b); |
1058 std::set<std::string>::const_iterator q = inferior_classes.find (b); | 1050 return (q != inferior_classes.end ()); |
1059 | |
1060 if (q != inferior_classes.end ()) | |
1061 retval = true; | |
1062 } | |
1063 | |
1064 return retval; | |
1065 } | 1051 } |
1066 | 1052 |
1067 static std::string | 1053 static std::string |
1068 fcn_file_name (const octave_value& fcn) | 1054 fcn_file_name (const octave_value& fcn) |
1069 { | 1055 { |