Adds support for astypedef exports.

This commit is contained in:
Deukhoofd 2021-10-23 14:12:22 +02:00
parent 7f39d5f849
commit f9c8efb9b1
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 119 additions and 31 deletions

View File

@ -14,4 +14,4 @@ add_definitions(-DLEVEL_U8)
SET(_LINKS Arbutils CreatureLib pkmnLib)
target_link_libraries(PkmnLibTools PUBLIC ${_LINKS})
target_compile_options(PkmnLibTools PRIVATE -Wall -Wextra -Werror)
target_compile_options(PkmnLibTools PRIVATE -Wall -Wextra -Werror)

View File

@ -42,9 +42,10 @@ function(include_pkmnlib)
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/include/PkmnLib)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/include
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/CreatureLib/include
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/Angelscript/src/AngelscriptProj/angelscript/include
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/CreatureLib/bin/Arbutils/include)
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/src/pkmnlib/extern/AngelscriptDebuggerServer/extern/asio-1.18.2/include
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/CreatureLib/include
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/Angelscript/src/AngelscriptProj/angelscript/include
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/CreatureLib/bin/Arbutils/include)
endfunction()

View File

@ -1,19 +0,0 @@
from conans import ConanFile, CMake
from conans.errors import ConanInvalidConfiguration
class PkmnLibConan(ConanFile):
name = "PkmnLibTools"
license = "TODO"
url = "https://git.p-epsilon.com/Deukhoofd/PkmnLib"
description = ""
settings = "os", "compiler", "build_type"
generators = "cmake"
exports_sources = "*"
compiler = "clang"
def requirements(self):
self.requires("Arbutils/latest@epsilon/master")
self.requires("CreatureLib/latest@epsilon/master")
self.requires("PkmnLib/latest@epsilon/master")
self.requires("AngelScript/2.35@AngelScript/Deukhoofd")

View File

@ -10,7 +10,83 @@ static bool replace(std::string& str, const std::string& from, const std::string
return true;
}
static void PrintObjectType(asITypeInfo* type, const std::filesystem::path& dir){
static void PrintObjectTypeDef(asITypeInfo* type, const std::filesystem::path& dir) {
auto name = std::string(type->GetName());
if (name == "string" || name == "array")
return;
std::fstream fs;
fs.open((dir / name).concat(".astypedef"), std::fstream::out);
if ((type->GetFlags() & asOBJ_VALUE) != 0 && (type->GetFlags() & asOBJ_ASHANDLE) == 0){
fs << "valuetype";
}
else{
fs << "type";
}
fs << " " << type->GetName();
if ((type->GetFlags() & asOBJ_TEMPLATE) != 0) {
fs << "<";
for (asUINT i = 0; i < type->GetSubTypeCount(); ++i) {
if (i != 0) {
fs << ", ";
}
fs << type->GetSubType(i)->GetName();
}
fs << ">";
}
fs << " {" << std::endl;
auto behaviourCount = type->GetBehaviourCount();
for (asUINT j = 0; j < behaviourCount; j++) {
if (name == "ref")
break;
if (name == "dictionaryValue")
break;
asEBehaviours behaviourType;
auto behaviour = type->GetBehaviourByIndex(j, &behaviourType);
if (behaviourType > 4) {
continue;
}
auto decl = std::string(behaviour->GetDeclaration(false, false, true));
if (behaviourType == asBEHAVE_CONSTRUCT || behaviourType == asBEHAVE_FACTORY) {
replace(decl, type->GetName(), "void f");
}
if (behaviourType == asBEHAVE_DESTRUCT) {
replace(decl, std::string("~") + type->GetName(), "void f");
}
if (behaviourType == asBEHAVE_LIST_CONSTRUCT || behaviourType == asBEHAVE_LIST_FACTORY) {
replace(decl, "$list", "f");
}
fs << " behave " << behaviourType << " " << decl << ";" << std::endl;
}
auto propertyCount = type->GetMethodCount();
for (asUINT j = 0; j < propertyCount; j++) {
auto method = type->GetMethodByIndex(j);
if (method->IsProperty()) {
auto name = std::string(method->GetName());
auto decl = std::string(method->GetDeclaration(false, true, false));
auto realName = name.substr(4);
replace(decl, name, realName);
replace(decl, "() const", " { get const; }");
replace(decl, "()", " { get; }");
fs << " " << decl << ";" << std::endl;
} else {
auto name = std::string(method->GetName());
auto decl = std::string(method->GetDeclaration(false, true, true));
replace(decl, "&in", " &in");
replace(decl, "&out", " &out");
replace(decl, "ref", "ref@");
fs << " " << decl << ";" << std::endl;
}
}
fs << "}" << std::endl;
fs.close();
}
static void PrintScriptObject(asITypeInfo* type, const std::filesystem::path& dir) {
auto name = std::string(type->GetName());
if (name == "string" || name == "array" || name == "ref")
return;
@ -45,8 +121,19 @@ static void PrintObjectType(asITypeInfo* type, const std::filesystem::path& dir)
replace(decl, "&in", " &in");
replace(decl, "&out", " &out");
fs << "\t" << decl;
if (isAbstract)
fs << "{};" << std::endl;
if (isAbstract){
if (method->GetReturnTypeId() == 0){
fs << "{};" << std::endl;
}
else{
if (method->GetReturnTypeId() == asTYPEID_BOOL){
fs << "{ return false; };" << std::endl;
}
else{
fs << "{ return 0; };" << std::endl;
}
}
}
else
fs << ";" << std::endl;
}
@ -65,23 +152,30 @@ void ScriptHeadersExporter::Export(const std::string& outPath) {
std::filesystem::path dir(outPath);
for (asUINT i = 0; i < typesCount; i++) {
auto type = engine->GetObjectTypeByIndex(i);
PrintObjectType(type, dir);
if ((type->GetTypeId() & asTYPEID_SCRIPTOBJECT) != 0) {
PrintScriptObject(type, dir);
} else {
PrintObjectTypeDef(type, dir);
}
}
auto moduleTypesCount = module->GetObjectTypeCount();
for (asUINT i = 0; i < moduleTypesCount; i++) {
auto type = module->GetObjectTypeByIndex(i);
PrintObjectType(type, dir);
if ((type->GetTypeId() & asTYPEID_SCRIPTOBJECT) != 0) {
PrintScriptObject(type, dir);
} else {
PrintObjectTypeDef(type, dir);
}
}
auto enumCount = engine->GetEnumCount();
for (asUINT i = 0; i < enumCount; i++) {
auto en = engine->GetEnumByIndex(i);
auto name = en->GetName();
std::fstream fs;
fs.open((dir / name).concat(".as"), std::fstream::out);
fs.open((dir / name).concat(".astypedef"), std::fstream::out);
fs << "shared enum " << en->GetName() << " {" << std::endl;
fs << "enum " << en->GetName() << " {" << std::endl;
auto valueCount = en->GetEnumValueCount();
for (asUINT j = 0; j < valueCount; j++) {
int val;
@ -91,4 +185,16 @@ void ScriptHeadersExporter::Export(const std::string& outPath) {
fs << "}" << std::endl;
fs.close();
}
auto globalFuncs = engine->GetGlobalFunctionCount();
if (globalFuncs > 0){
std::fstream fs;
fs.open((dir / "globals").concat(".astypedef"), std::fstream::out);
for (asUINT i = 0; i < globalFuncs; ++i) {
auto func = engine->GetGlobalFunctionByIndex(i);
fs << "func " << func->GetDeclaration(false, false, true) << ";" << std::endl;
}
}
}