diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-06-15 18:05:27 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-06-17 17:44:56 -0300 |
commit | a46578e6edbdc6427439830c94f0e29cf6c6a2f1 (patch) | |
tree | a09602c7b7c4fd311c329753656c29cdd6e61038 | |
parent | 98350997b78efbdbe35a56a0700ac16541229c22 (diff) |
Added methods to check if overloads contain any argument with default values.
The hasArgumentWithDefaultValue methods from OverloadData returns
true if any argument in the overloads or in the single function
passed has a default value assigned to it.
A non-static version of this method uses the overloads described
by the OverloadData object.
Also added the method getArgumentsWithDefaultValues(func) to return
a list of the function's arguments that have default values.
-rw-r--r-- | overloaddata.cpp | 45 | ||||
-rw-r--r-- | overloaddata.h | 7 |
2 files changed, 52 insertions, 0 deletions
diff --git a/overloaddata.cpp b/overloaddata.cpp index f4cef778a..36dcb9f43 100644 --- a/overloaddata.cpp +++ b/overloaddata.cpp @@ -741,3 +741,48 @@ QString OverloadData::argumentTypeReplaced() const return m_argTypeReplaced; } +bool OverloadData::hasArgumentWithDefaultValue(const AbstractMetaFunctionList& overloads) +{ + if (OverloadData::getMinMaxArguments(overloads).second == 0) + return false; + foreach (const AbstractMetaFunction* func, overloads) { + if (hasArgumentWithDefaultValue(func)) + return true; + } + return false; +} + +bool OverloadData::hasArgumentWithDefaultValue() const +{ + if (maxArgs() == 0) + return false; + foreach (const AbstractMetaFunction* func, overloads()) { + if (hasArgumentWithDefaultValue(func)) + return true; + } + return false; +} + +bool OverloadData::hasArgumentWithDefaultValue(const AbstractMetaFunction* func) +{ + foreach (const AbstractMetaArgument* arg, func->arguments()) { + if (func->argumentRemoved(arg->argumentIndex() + 1)) + continue; + if (!arg->defaultValueExpression().isEmpty()) + return true; + } + return false; +} + +AbstractMetaArgumentList OverloadData::getArgumentsWithDefaultValues(const AbstractMetaFunction* func) +{ + AbstractMetaArgumentList args; + foreach (AbstractMetaArgument* arg, func->arguments()) { + if (arg->defaultValueExpression().isEmpty() + || func->argumentRemoved(arg->argumentIndex() + 1)) + continue; + args << arg; + } + return args; +} + diff --git a/overloaddata.h b/overloaddata.h index 734ef790b..3e5d0cc6c 100644 --- a/overloaddata.h +++ b/overloaddata.h @@ -111,6 +111,13 @@ public: bool hasArgumentTypeReplace() const; QString argumentTypeReplaced() const; + bool hasArgumentWithDefaultValue() const; + static bool hasArgumentWithDefaultValue(const AbstractMetaFunctionList& overloads); + static bool hasArgumentWithDefaultValue(const AbstractMetaFunction* func); + + /// Returns a list of function arguments which have default values and were not removed. + static AbstractMetaArgumentList getArgumentsWithDefaultValues(const AbstractMetaFunction* func); + private: OverloadData(OverloadData* headOverloadData, const AbstractMetaFunction* func, const AbstractMetaType* argType, int argPos); |