Merge pull request #964 from Azaezel/alpha41/protoMethods

new method, getMethodSigs. spits out callback proto-functions
This commit is contained in:
Brian Roberts 2023-02-16 08:27:22 -06:00 committed by GitHub
commit 6c8dfdbe4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 0 deletions

View file

@ -1776,6 +1776,45 @@ String Namespace::Entry::getPrototypeString() const
return str.end();
}
String Namespace::Entry::getPrototypeSig() const
{
StringBuilder str;
// Add function name and arguments.
if (mType == ScriptCallbackType)
str.append(cb.mCallbackName);
else
str.append(mFunctionName);
if (mHeader)
{
Vector< String > argList;
sParseList(mHeader->mArgString, argList);
const U32 numArgs = argList.size();
str.append("(%this");
if (numArgs > 0)
str.append(',');
for (U32 i = 0; i < numArgs; ++i)
{
// Add separator if not first arg.
String name;
String type;
if (i > 0)
str.append(',');
str.append('%');
sGetArgNameAndType(argList[i], type, name);
str.append(name);
}
str.append(')');
}
return str.end();
}
//-----------------------------------------------------------------------------
StringTableEntry Namespace::mActivePackages[Namespace::MaxActivePackages];

View file

@ -164,6 +164,10 @@ public:
/// Return a full prototype string for the function including return type, function name,
/// and arguments.
String getPrototypeString() const;
/// Return a minimalized prototype string for the function including return type, function name,
/// and arguments.
String getPrototypeSig() const;
};
Entry* mEntryList;

View file

@ -2655,6 +2655,50 @@ DefineEngineMethod( SimObject, dumpMethods, ArrayObject*, (),,
return dictionary;
}
DefineEngineMethod(SimObject, getMethodSigs, ArrayObject*, (), ,
"List the methods defined on this object.\n\n"
"Each description is a newline-separated vector with the following elements:\n"
"- method prototype string.\n"
"- Documentation string (not including prototype). This takes up the remainder of the vector.\n"
"@return An ArrayObject populated with (name,description) pairs of all methods defined on the object.")
{
Namespace* ns = object->getNamespace();
if (!ns)
return 0;
ArrayObject* dictionary = new ArrayObject();
dictionary->registerObject();
VectorPtr<Namespace::Entry*> vec(__FILE__, __LINE__);
ns->getEntryList(&vec);
for (Vector< Namespace::Entry* >::iterator j = vec.begin(); j != vec.end(); j++)
{
Namespace::Entry* e = *j;
if (e->mType != Namespace::Entry::ScriptCallbackType)
continue;
StringBuilder str;
str.append("function ");
str.append(ns->getName());
str.append("::");
str.append(e->getPrototypeSig());
str.append('\n');
str.append("{");
String docs = e->getDocString();
if (!docs.isEmpty())
{
str.append("\n/*");
str.append(docs);
str.append("\n*/");
}
str.append('\n');
str.append("}");
dictionary->push_back(e->mFunctionName, str.end());
}
return dictionary;
}
//-----------------------------------------------------------------------------
namespace {