should work now

This commit is contained in:
Nishi 2026-04-20 05:29:42 +09:00
commit 2514a1b2fc
Signed by: nishi
GPG key ID: 27EF69B208EB9343
25 changed files with 325 additions and 6 deletions

View file

@ -268,15 +268,124 @@ static std::string scan_widget_handler_source(xl_node_t* node, std::string widge
return widget_handler_source(widget, xl_get_attribute(node, "name"));
}
static std::string widget_function_header(xl_node_t* node, std::string indent, std::string prefix = "", int func = 1, xl_node_t** pret = NULL, xl_node_t** pargs = NULL) {
std::stringstream strm;
xl_node_t* child;
xl_node_t* ret = NULL;
xl_node_t* args = NULL;
int c = 0;
if(node->type != XL_NODE_NODE) return "";
for(child = node->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
if(strcmp(child->name, "return") == 0) {
for(ret = child->first_child; ret != NULL; ret = ret->next) {
if(ret->type == XL_NODE_NODE) break;
}
} else if(strcmp(child->name, "arguments") == 0) {
args = child->first_child;
}
}
if(pret != NULL) *pret = ret;
if(pargs != NULL) *pargs = args;
strm << indent;
if(ret == NULL) {
strm << "void ";
} else {
strm << get_ctype(xml_to_type(ret)) + " ";
}
strm << prefix + std::string(xl_get_attribute(node, "name")) + "(";
c = 0;
for(child = args; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
if(c > 0) strm << ", ";
strm << get_ctype(xml_to_type(child));
c++;
}
strm << ")";
if(func) strm << ";";
strm << std::endl;
return strm.str();
}
static std::string widget_function_source(xl_node_t* node, std::string widget) {
std::stringstream strm;
xl_node_t* child;
std::string rettype = "";
xl_node_t* ret = NULL;
xl_node_t* args = NULL;
typeinfo retti;
strm << widget_function_header(node, "", "MwCXX::" + widget + "::", 0, &ret, &args) + " {" << std::endl;
if(ret != NULL) {
retti = xml_to_type(ret);
rettype = get_ctype(retti, 0, 0);
if(rettype == "MwCXX::String") rettype = "char*";
if(retti.pointer) rettype += "*";
}
if(rettype != "") {
strm << " " + rettype + " out;" << std::endl;
strm << std::endl;
}
strm << " MwVaWidgetExecute(this->widget, \"mw" + widget + std::string(xl_get_attribute(node, "name")) + "\", ";
if(rettype == "") {
strm << "NULL";
} else {
strm << "&out";
}
for(child = args; child != NULL; child = child->next) {
typeinfo ti = xml_to_type(child);
if(ti.type == "string") {
strm << "," << std::endl;
strm << "#ifdef MWCXX_USE_C_STRING" << std::endl;
strm << " " + ti.name << std::endl;
strm << "#else" << std::endl;
strm << " " + ti.name + ".c_str()" << std::endl;
strm << "#endif" << std::endl;
} else {
strm << ", " + ti.name;
}
}
strm << " );" << std::endl;
if(rettype != "") {
strm << std::endl;
if(retti.type == "string") {
strm << "#ifdef MWCXX_USE_C_STRING" << std::endl;
strm << " return out;" << std::endl;
strm << "#else" << std::endl;
strm << " return MwCXX::String(out);" << std::endl;
strm << "#endif" << std::endl;
} else {
strm << " return out;" << std::endl;
}
}
strm << "}" << std::endl;
strm << std::endl;
return strm.str();
}
static void scan_widget(xl_node_t* node) {
std::string name;
xl_node_t** p_nodes;
xl_node_t** h_nodes;
xl_node_t** f_nodes;
if(node->type != XL_NODE_NODE) return;
p_nodes = xl_get_path(node, "properties");
h_nodes = xl_get_path(node, "handlers");
f_nodes = xl_get_path(node, "functions");
name = xl_get_attribute(node, "name");
@ -343,6 +452,21 @@ static void scan_widget(xl_node_t* node) {
<< r;
}
if(f_nodes != NULL) {
std::string r;
r = "";
for(int i = 0; f_nodes[i] != NULL; i++) {
for(xl_node_t* child = f_nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
r += widget_function_header(child, "\t\t");
}
}
if(r != "") OFS << std::endl
<< r;
}
OFS << " };" << std::endl;
OFS << "}; // namespace MwCXX" << std::endl;
@ -423,11 +547,23 @@ static void scan_widget(xl_node_t* node) {
}
}
OFS << "}" << std::endl;
OFS << std::endl;
if(f_nodes != NULL) {
for(int i = 0; f_nodes[i] != NULL; i++) {
for(xl_node_t* child = f_nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
OFS << widget_function_source(child, name);
}
}
}
#undef OFS
if(p_nodes != NULL) free(p_nodes);
if(h_nodes != NULL) free(h_nodes);
if(f_nodes != NULL) free(f_nodes);
files["objs"] << " src/widget/" + lowercase(name) + ".o";
}