mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
MAKE_PROPERTY should ignore setter overloads that take the wrong number of arguments
This commit is contained in:
parent
8d6ad30c07
commit
8a205ac100
@ -504,6 +504,47 @@ get_call_str(const string &container, const vector_string &pexprs) const {
|
||||
return call.str();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FunctionRemap::get_min_num_args
|
||||
// Access: Private
|
||||
// Description: Returns the minimum number of arguments that needs
|
||||
// to be passed to this function.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int FunctionRemap::
|
||||
get_min_num_args() const {
|
||||
int min_num_args = 0;
|
||||
Parameters::const_iterator pi;
|
||||
pi = _parameters.begin();
|
||||
if (_has_this && pi != _parameters.end()) {
|
||||
++pi;
|
||||
}
|
||||
for (; pi != _parameters.end(); ++pi) {
|
||||
ParameterRemap *param = (*pi)._remap;
|
||||
if (param->get_default_value() != (CPPExpression *)NULL) {
|
||||
// We've reached the first parameter that takes a default value.
|
||||
break;
|
||||
} else {
|
||||
++min_num_args;
|
||||
}
|
||||
}
|
||||
return min_num_args;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FunctionRemap::get_max_num_args
|
||||
// Access: Private
|
||||
// Description: Returns the maximum number of arguments that can
|
||||
// be passed to this function.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int FunctionRemap::
|
||||
get_max_num_args() const {
|
||||
int max_num_args = _parameters.size();
|
||||
if (_has_this && _type != FunctionRemap::T_constructor) {
|
||||
--max_num_args;
|
||||
}
|
||||
return max_num_args;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FunctionRemap::get_parameter_expr
|
||||
// Access: Private
|
||||
|
@ -65,6 +65,9 @@ public:
|
||||
|
||||
string get_call_str(const string &container, const vector_string &pexprs) const;
|
||||
|
||||
int get_min_num_args() const;
|
||||
int get_max_num_args() const;
|
||||
|
||||
class Parameter {
|
||||
public:
|
||||
bool _has_name;
|
||||
|
@ -3371,35 +3371,16 @@ write_function_for_name(ostream &out, Object *obj,
|
||||
for (ri = remaps.begin(); ri != remaps.end(); ++ri) {
|
||||
remap = (*ri);
|
||||
if (is_remap_legal(remap)) {
|
||||
int max_num_args = remap->_parameters.size();
|
||||
int min_num_args = remap->get_min_num_args();
|
||||
int max_num_args = remap->get_max_num_args();
|
||||
if (remap->_has_this) {
|
||||
has_this = true;
|
||||
|
||||
if (remap->_type != FunctionRemap::T_constructor) {
|
||||
max_num_args--;
|
||||
}
|
||||
}
|
||||
|
||||
if (!remap->_has_this || remap->_const_method) {
|
||||
all_nonconst = false;
|
||||
}
|
||||
|
||||
int min_num_args = 0;
|
||||
FunctionRemap::Parameters::const_iterator pi;
|
||||
pi = remap->_parameters.begin();
|
||||
if (remap->_has_this && pi != remap->_parameters.end()) {
|
||||
++pi;
|
||||
}
|
||||
for (; pi != remap->_parameters.end(); ++pi) {
|
||||
ParameterRemap *param = (*pi)._remap;
|
||||
if (param->get_default_value() != (CPPExpression *)NULL) {
|
||||
// We've reached the first parameter that takes a default value.
|
||||
break;
|
||||
} else {
|
||||
++min_num_args;
|
||||
}
|
||||
}
|
||||
|
||||
max_required_args = max(max_num_args, max_required_args);
|
||||
|
||||
for (int i = min_num_args; i <= max_num_args; ++i) {
|
||||
@ -3694,18 +3675,8 @@ write_coerce_constructor(ostream &out, Object *obj, bool is_const) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int max_num_args = remap->_parameters.size();
|
||||
int min_num_args = 0;
|
||||
FunctionRemap::Parameters::const_iterator pi;
|
||||
for (pi = remap->_parameters.begin(); pi != remap->_parameters.end(); ++pi) {
|
||||
ParameterRemap *param = (*pi)._remap;
|
||||
if (param->get_default_value() != (CPPExpression *)NULL) {
|
||||
// We've reached the first parameter that takes a default value.
|
||||
break;
|
||||
} else {
|
||||
++min_num_args;
|
||||
}
|
||||
}
|
||||
int min_num_args = remap->get_min_num_args();
|
||||
int max_num_args = remap->get_max_num_args();
|
||||
|
||||
// Coerce constructor should take at least one argument.
|
||||
nassertd(max_num_args > 0) continue;
|
||||
@ -3732,18 +3703,8 @@ write_coerce_constructor(ostream &out, Object *obj, bool is_const) {
|
||||
if (is_remap_legal(remap) && remap->_flags & FunctionRemap::F_coerce_constructor) {
|
||||
nassertd(!remap->_has_this) continue;
|
||||
|
||||
int max_num_args = remap->_parameters.size();
|
||||
int min_num_args = 0;
|
||||
FunctionRemap::Parameters::const_iterator pi;
|
||||
for (pi = remap->_parameters.begin(); pi != remap->_parameters.end(); ++pi) {
|
||||
ParameterRemap *param = (*pi)._remap;
|
||||
if (param->get_default_value() != (CPPExpression *)NULL) {
|
||||
// We've reached the first parameter that takes a default value.
|
||||
break;
|
||||
} else {
|
||||
++min_num_args;
|
||||
}
|
||||
}
|
||||
int min_num_args = remap->get_min_num_args();
|
||||
int max_num_args = remap->get_max_num_args();
|
||||
|
||||
// Coerce constructor should take at least one argument.
|
||||
nassertd(max_num_args > 0) continue;
|
||||
@ -6495,8 +6456,19 @@ write_getset(ostream &out, Object *obj, Property *property) {
|
||||
}
|
||||
|
||||
std::set<FunctionRemap*> remaps;
|
||||
remaps.insert(property->_setter->_remaps.begin(),
|
||||
property->_setter->_remaps.end());
|
||||
|
||||
// Extract only the setters that take one argument.
|
||||
Function::Remaps::iterator it;
|
||||
for (it = property->_setter->_remaps.begin();
|
||||
it != property->_setter->_remaps.end();
|
||||
++it) {
|
||||
FunctionRemap *remap = *it;
|
||||
int min_num_args = remap->get_min_num_args();
|
||||
int max_num_args = remap->get_max_num_args();
|
||||
if (min_num_args <= 1 && max_num_args >= 1) {
|
||||
remaps.insert(remap);
|
||||
}
|
||||
}
|
||||
|
||||
string expected_params;
|
||||
write_function_forset(out, remaps, 1, 1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user