aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-11-06 10:37:03 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2009-11-06 13:35:19 -0300
commit3a300338545442396f95d930afa11a7635df0bd6 (patch)
treee0730bab0df17d82093a7ebde5ccce6b49250556
parentf69bf045ad195efe9725c2c6a483a1473cd9ce43 (diff)
added the method OverloadData::findNextArgWithDefault() which returns
the nearest occurrence of an argument with a default value. this could be used when the overload has only one signature and some of the arguments ahead could have default values leading to more than one way of calling the method.
-rw-r--r--overloaddata.cpp19
-rw-r--r--overloaddata.h2
2 files changed, 21 insertions, 0 deletions
diff --git a/overloaddata.cpp b/overloaddata.cpp
index 48e7e27ce..c9e5b5b44 100644
--- a/overloaddata.cpp
+++ b/overloaddata.cpp
@@ -188,6 +188,25 @@ bool OverloadData::nextArgumentHasDefaultValue() const
return false;
}
+static OverloadData* _findNextArgWithDefault(OverloadData* overloadData)
+{
+ if (overloadData->hasDefaultValue())
+ return overloadData;
+
+ OverloadData* result = 0;
+ foreach (OverloadData* odata, overloadData->nextOverloadData()) {
+ OverloadData* tmp = _findNextArgWithDefault(odata);
+ if (!result || (tmp && result->argPos() > tmp->argPos()))
+ result = tmp;
+ }
+ return result;
+}
+
+OverloadData* OverloadData::findNextArgWithDefault()
+{
+ return _findNextArgWithDefault(this);
+}
+
bool OverloadData::isFinalOccurrence(const AbstractMetaFunction* func) const
{
foreach (const OverloadData* pd, m_nextOverloadData) {
diff --git a/overloaddata.h b/overloaddata.h
index 5fd6ff547..f80ce84df 100644
--- a/overloaddata.h
+++ b/overloaddata.h
@@ -50,6 +50,8 @@ public:
bool isHeadOverloadData() const { return this == m_headOverloadData; }
bool hasDefaultValue() const;
bool nextArgumentHasDefaultValue() const;
+ /// Returns the nearest occurrence, including this instance, of an argument with a default value.
+ OverloadData* findNextArgWithDefault();
bool isFinalOccurrence(const AbstractMetaFunction* func) const;
QList<const AbstractMetaFunction*> overloads() const { return m_overloads; }