Update some AS stuff

This commit is contained in:
Aang23 2025-08-12 19:30:15 +02:00
parent 4f600e3d6f
commit 26d514baea
8 changed files with 598 additions and 112 deletions

View file

@ -152,9 +152,11 @@ void CScriptBuilder::ClearAll()
currentNamespace = "";
foundDeclarations.clear();
typeMetadataMap.clear();
funcMetadataMap.clear();
varMetadataMap.clear();
classMetadataMap.clear();
#endif
}
@ -395,16 +397,26 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length
// Check if namespace so the metadata for members can be gathered
if( token == "namespace" )
{
// Get the identifier after "namespace"
// Get the scope after "namespace". It can be composed of multiple nested namespaces, e.g. A::B::C
// Keep track of the number of nested namespace scopes are declared for each block
int nestedNamespaces = 0;
do
{
pos += len;
t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len);
} while(t == asTC_COMMENT || t == asTC_WHITESPACE);
do
{
pos += len;
t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len);
} while (t == asTC_COMMENT || t == asTC_WHITESPACE);
if( currentNamespace != "" )
currentNamespace += "::";
currentNamespace += modifiedScript.substr(pos,len);
if (t == asTC_IDENTIFIER)
{
if (currentNamespace != "")
currentNamespace += "::";
currentNamespace += modifiedScript.substr(pos, len);
nestedNamespaces++;
}
} while (t == asTC_IDENTIFIER || (t == asTC_KEYWORD && modifiedScript.substr(pos, len) == "::"));
currentNamespaceStack.push_back(nestedNamespaces);
// Search until first { is encountered
while( pos < modifiedScript.length() )
@ -428,14 +440,20 @@ int CScriptBuilder::ProcessScriptSection(const char *script, unsigned int length
// Check if end of namespace
if( currentNamespace != "" && token == "}" )
{
size_t found = currentNamespace.rfind( "::" );
if( found != string::npos )
assert(currentNamespaceStack.size() > 0);
int nestedNamespaces = currentNamespaceStack[currentNamespaceStack.size()-1];
currentNamespaceStack.pop_back();
while (nestedNamespaces-- > 0)
{
currentNamespace.erase( found );
}
else
{
currentNamespace = "";
size_t found = currentNamespace.rfind("::");
if (found != string::npos)
{
currentNamespace.erase(found);
}
else
{
currentNamespace = "";
}
}
pos += len;
continue;
@ -1043,7 +1061,9 @@ int CScriptBuilder::ExtractDeclaration(int pos, string &name, string &declaratio
}
else if( t == asTC_IDENTIFIER )
{
name = token;
// If a parenthesis is already found then the name is already known so it must not be overwritten
if( !hasParenthesis )
name = token;
}
// Skip trailing decorators