summaryrefslogtreecommitdiff
path: root/fluid/nodes/Function_Node.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'fluid/nodes/Function_Node.cxx')
-rw-r--r--fluid/nodes/Function_Node.cxx206
1 files changed, 130 insertions, 76 deletions
diff --git a/fluid/nodes/Function_Node.cxx b/fluid/nodes/Function_Node.cxx
index 27e8c83de..de3706eb3 100644
--- a/fluid/nodes/Function_Node.cxx
+++ b/fluid/nodes/Function_Node.cxx
@@ -185,6 +185,18 @@ const char *c_check(const char *c, int type) {
or C++ function.
*/
+Function_Node::Function_Node() {
+ return_type_ = 0;
+ public_ = 0;
+ declare_c_ = 0;
+ constructor = 0;
+ havewidgets = 0;
+}
+
+Function_Node::~Function_Node() {
+ if (return_type_) free((void*)return_type_);
+}
+
/// Prototype for a function to be used by the factory.
Function_Node Function_Node::prototype;
@@ -204,7 +216,7 @@ Node *Function_Node::make(Strategy strategy) {
}
Function_Node *o = new Function_Node();
o->name("make_window()");
- o->return_type_.clear();
+ if (o->return_type_) { free((void*)o->return_type_); o->return_type_ = 0; }
o->add(anchor, strategy);
o->factory = this;
o->public_ = 1;
@@ -225,7 +237,7 @@ void Function_Node::write_properties(fld::io::Project_Writer &f) {
case 2: f.write_string("protected"); break;
}
if (declare_c_) f.write_string("C");
- if (!return_type().empty()) {
+ if (return_type()[0]) {
f.write_string("return_type");
f.write_word(return_type());
}
@@ -335,36 +347,41 @@ void Function_Node::write_code1(fld::io::Code_Writer& f) {
if (havechildren)
f.write_c("int main(int argc, char **argv) {\n");
} else {
- std::string rtype = return_type();
- std::string star = "";
+ char rtype[256];
+ const char *star = "";
+ const char *rt = return_type();
+ strncpy(rtype, rt ? rt : "", sizeof(rtype)-1);
+ rtype[sizeof(rtype)-1] = '\0';
// from matt: let the user type "static " at the start of type
// in order to declare a static method;
int is_static = 0;
int is_virtual = 0;
- if (!rtype.empty()) {
- if (rtype == "static") {
+ if (rtype[0]) {
+ if (strcmp(rtype, "static") == 0) {
is_static = 1;
- rtype.clear();
- } else if (rtype.compare(0, 7, "static ")==0) {
+ rtype[0] = '\0';
+ } else if (strncmp(rtype, "static ", 7)==0) {
is_static = 1;
- rtype.erase(0, 7);
+ memmove(rtype, rtype+7, strlen(rtype)-6);
}
}
- if (!rtype.empty()) {
- if (rtype == "virtual") {
+ if (rtype[0]) {
+ if (strcmp(rtype, "virtual") == 0) {
is_virtual = 1;
- rtype.clear();
- } else if (rtype.compare(0, 8, "virtual ")==0) {
+ rtype[0] = '\0';
+ } else if (strncmp(rtype, "virtual ", 8)==0) {
is_virtual = 1;
- rtype.erase(0, 8);
+ memmove(rtype, rtype+8, strlen(rtype)-7);
}
}
- if (rtype.empty()) {
+ if (!rtype[0]) {
if (havewidgets) {
- rtype = subclassname(child);
+ const char *scn = subclassname(child);
+ strncpy(rtype, scn ? scn : "", sizeof(rtype)-1);
+ rtype[sizeof(rtype)-1] = '\0';
star = "*";
} else {
- rtype = "void";
+ strcpy(rtype, "void");
}
}
@@ -383,9 +400,9 @@ void Function_Node::write_code1(fld::io::Code_Writer& f) {
if (is_static) f.write_h("static ");
if (is_virtual) f.write_h("virtual ");
if (!constructor) {
- f.write_h("%s%s ", rtype.c_str(), star.c_str());
+ f.write_h("%s%s ", rtype, star);
if (havechildren)
- f.write_c("%s%s ", rtype.c_str(), star.c_str());
+ f.write_c("%s%s ", rtype, star);
}
// if this is a subclass, only f.write_h() the part before the ':'
@@ -416,9 +433,9 @@ void Function_Node::write_code1(fld::io::Code_Writer& f) {
write_comment_c(f);
if (public_==1) {
if (declare_c_)
- f.write_h("extern \"C\" { %s%s %s; }\n", rtype.c_str(), star.c_str(), name());
+ f.write_h("extern \"C\" { %s%s %s; }\n", rtype, star, name());
else
- f.write_h("%s%s %s;\n", rtype.c_str(), star.c_str(), name());
+ f.write_h("%s%s %s;\n", rtype, star, name());
} else if (public_==2) {
// write neither the prototype nor static, the function may be declared elsewhere
} else {
@@ -430,7 +447,7 @@ void Function_Node::write_code1(fld::io::Code_Writer& f) {
char s[1024];
if (havechildren) {
clean_function_for_implementation(s, name());
- f.write_c("%s%s %s {\n", rtype.c_str(), star.c_str(), s);
+ f.write_c("%s%s %s {\n", rtype, star, s);
}
}
}
@@ -459,7 +476,7 @@ void Function_Node::write_code2(fld::io::Code_Writer& f) {
f.write_c("%s%s->show(argc, argv);\n", f.indent(1), var);
if (havechildren)
f.write_c("%sreturn Fl::run();\n", f.indent(1));
- } else if (havewidgets && !constructor && return_type().empty()) {
+ } else if (havewidgets && !constructor && !return_type()[0]) {
f.write_c("%sreturn %s;\n", f.indent(1), var);
}
if (havechildren)
@@ -474,11 +491,11 @@ void Function_Node::write_code2(fld::io::Code_Writer& f) {
\return 1 if they match, 0 if not
*/
int Function_Node::has_signature(const char *rtype, const char *sig) const {
- if (rtype && return_type().empty())
+ if (rtype && !return_type()[0])
return 0;
if (!name())
return 0;
- if ( (rtype==0 || (return_type() == rtype)) && fl_filename_match(name(), sig)) {
+ if ( (rtype==0 || strcmp(return_type(), rtype)==0) && fl_filename_match(name(), sig)) {
return 1;
}
return 0;
@@ -615,6 +632,14 @@ int Code_Node::handle_editor_changes() {
\todo this node could support multiple lines of code for each block.
*/
+CodeBlock_Node::CodeBlock_Node() {
+ end_code_ = 0;
+}
+
+CodeBlock_Node::~CodeBlock_Node() {
+ if (end_code_) free((void*)end_code_);
+}
+
/// Prototype for a block of code to be used by the factory.
CodeBlock_Node CodeBlock_Node::prototype;
@@ -640,7 +665,7 @@ Node *CodeBlock_Node::make(Strategy strategy) {
}
CodeBlock_Node *o = new CodeBlock_Node();
o->name("if (test())");
- o->end_code_.clear();
+ if (o->end_code_) { free((void*)o->end_code_); o->end_code_ = 0; }
o->add(anchor, strategy);
o->factory = this;
return o;
@@ -653,7 +678,7 @@ Node *CodeBlock_Node::make(Strategy strategy) {
*/
void CodeBlock_Node::write_properties(fld::io::Project_Writer &f) {
Node::write_properties(f);
- if (!end_code().empty()) {
+ if (end_code()[0]) {
f.write_string("after");
f.write_word(end_code());
}
@@ -691,8 +716,8 @@ void CodeBlock_Node::write_code1(fld::io::Code_Writer& f) {
*/
void CodeBlock_Node::write_code2(fld::io::Code_Writer& f) {
f.indentation--;
- if (!end_code().empty())
- f.write_c("%s} %s\n", f.indent(), end_code().c_str());
+ if (end_code()[0])
+ f.write_c("%s} %s\n", f.indent(), end_code());
else
f.write_c("%s}\n", f.indent());
}
@@ -870,6 +895,15 @@ void Decl_Node::write_code1(fld::io::Code_Writer& f) {
code. This can be used to store images inline in the source code,
*/
+Data_Node::Data_Node() {
+ filename_ = 0;
+ output_format_ = 0;
+}
+
+Data_Node::~Data_Node() {
+ if (filename_) free((void*)filename_);
+}
+
/// Prototype for a data node to be used by the factory.
Data_Node Data_Node::prototype;
@@ -890,7 +924,7 @@ Node *Data_Node::make(Strategy strategy) {
Data_Node *o = new Data_Node();
o->public_ = 1;
o->static_ = 1;
- o->filename_.clear();
+ if (o->filename_) { free((void*)o->filename_); o->filename_ = 0; }
o->output_format_ = 0;
o->name("myInlineData");
o->add(anchor, strategy);
@@ -905,7 +939,7 @@ Node *Data_Node::make(Strategy strategy) {
*/
void Data_Node::write_properties(fld::io::Project_Writer &f) {
Decl_Node::write_properties(f);
- if (!filename().empty()) {
+ if (filename()[0]) {
f.write_string("filename");
f.write_word(filename());
}
@@ -953,14 +987,14 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) {
const char *message = 0;
const char *c = name();
if (!c) return;
- std::string fn = filename();
+ const char *fn = filename();
char *data = 0;
int nData = -1;
int uncompressedDataSize = 0;
// path should be set correctly already
- if (!filename().empty() && !f.write_codeview) {
+ if (fn && fn[0] && !f.write_codeview) {
Fluid.proj.enter_project_dir();
- FILE *f = fl_fopen(filename().c_str(), "rb");
+ FILE *f = fl_fopen(fn, "rb");
Fluid.proj.leave_project_dir();
if (!f) {
message = "Can't include data from file. Can't open";
@@ -984,7 +1018,7 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) {
fclose(f);
}
} else {
- if (filename().empty())
+ if (!fn || !fn[0])
fn = "<no filename>";
}
if (is_in_class()) {
@@ -994,13 +1028,13 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) {
write_comment_c(f);
if (output_format_ == 1) {
f.write_h("%sstatic const char *%s;\n", f.indent(1), c);
- f.write_c("const char *%s::%s = /* text inlined from %s */\n", class_name(1), c, fn.c_str());
+ f.write_c("const char *%s::%s = /* text inlined from %s */\n", class_name(1), c, fn);
} else {
f.write_h_once("#include <string>");
f.write_h("%sstatic const std::string %s;\n", f.indent(1), c);
- f.write_c("const std::string %s::%s = /* text inlined from %s */\n", class_name(1), c, fn.c_str());
+ f.write_c("const std::string %s::%s = /* text inlined from %s */\n", class_name(1), c, fn);
}
- if (message) f.write_c("#error %s %s\n", message, fn.c_str());
+ if (message) f.write_c("#error %s %s\n", message, fn);
f.write_cstring(data, nData);
} else if ((output_format_ == 2) || (output_format_ == 5)) {
f.write_h("%sstatic int %s_size;\n", f.indent(1), c);
@@ -1009,28 +1043,28 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) {
f.write_c("int %s::%s_size = %d;\n", class_name(1), c, uncompressedDataSize);
if (output_format_ == 2) {
f.write_h("%sstatic unsigned char %s[%d];\n", f.indent(1), c, nData);
- f.write_c("unsigned char %s::%s[%d] = /* data compressed and inlined from %s */\n", class_name(1), c, nData, fn.c_str());
+ f.write_c("unsigned char %s::%s[%d] = /* data compressed and inlined from %s */\n", class_name(1), c, nData, fn);
} else {
f.write_h_once("#include <stdint.h>");
f.write_h_once("#include <vector>");
f.write_h("%sstatic std::vector<uint8_t> %s;\n", f.indent(1), c);
- f.write_c("std::vector<uint8_t> %s::%s = /* data compressed and inlined from %s */\n", class_name(1), c, fn.c_str());
+ f.write_c("std::vector<uint8_t> %s::%s = /* data compressed and inlined from %s */\n", class_name(1), c, fn);
}
- if (message) f.write_c("#error %s %s\n", message, fn.c_str());
+ if (message) f.write_c("#error %s %s\n", message, fn);
f.write_cdata(data, nData);
} else {
f.write_c("\n");
write_comment_c(f);
if (output_format_ == 0) {
f.write_h("%sstatic unsigned char %s[%d];\n", f.indent(1), c, nData);
- f.write_c("unsigned char %s::%s[%d] = /* data inlined from %s */\n", class_name(1), c, nData, fn.c_str());
+ f.write_c("unsigned char %s::%s[%d] = /* data inlined from %s */\n", class_name(1), c, nData, fn);
} else {
f.write_h_once("#include <stdint.h>");
f.write_h_once("#include <vector>");
f.write_h("%sstatic std::vector<uint8_t> %s;\n", f.indent(1), c);
- f.write_c("std::vector<uint8_t> %s::%s = /* data inlined from %s */\n", class_name(1), c, fn.c_str());
+ f.write_c("std::vector<uint8_t> %s::%s = /* data inlined from %s */\n", class_name(1), c, fn);
}
- if (message) f.write_c("#error %s %s\n", message, fn.c_str());
+ if (message) f.write_c("#error %s %s\n", message, fn);
f.write_cdata(data, nData);
}
f.write_c(";\n");
@@ -1043,13 +1077,13 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) {
write_comment_c(f);
if (output_format_ == 1) {
f.write_h("extern const char *%s;\n", c);
- f.write_c("const char *%s = /* text inlined from %s */\n", c, fn.c_str());
+ f.write_c("const char *%s = /* text inlined from %s */\n", c, fn);
} else {
f.write_h_once("#include <string>");
f.write_h("extern const std::string %s;\n", c);
- f.write_c("const std::string %s = /* text inlined from %s */\n", c, fn.c_str());
+ f.write_c("const std::string %s = /* text inlined from %s */\n", c, fn);
}
- if (message) f.write_c("#error %s %s\n", message, fn.c_str());
+ if (message) f.write_c("#error %s %s\n", message, fn);
f.write_cstring(data, nData);
} else if ((output_format_ == 2) || (output_format_ == 5)) {
f.write_h("extern int %s_size;\n", c);
@@ -1058,34 +1092,34 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) {
f.write_c("int %s_size = %d;\n", c, uncompressedDataSize);
if (output_format_ == 2) {
f.write_h("extern unsigned char %s[%d];\n", c, nData);
- f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn.c_str());
+ f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn);
} else {
f.write_h_once("#include <stdint.h>");
f.write_h_once("#include <vector>");
f.write_h("extern std::vector<uint8_t> %s;\n", c);
- f.write_c("std::vector<uint8_t> %s = /* data compressed and inlined from %s */\n", c, fn.c_str());
+ f.write_c("std::vector<uint8_t> %s = /* data compressed and inlined from %s */\n", c, fn);
}
- if (message) f.write_c("#error %s %s\n", message, fn.c_str());
+ if (message) f.write_c("#error %s %s\n", message, fn);
f.write_cdata(data, nData);
} else {
f.write_c("\n");
write_comment_c(f);
if (output_format_ == 0) {
f.write_h("extern unsigned char %s[%d];\n", c, nData);
- f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn.c_str());
+ f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn);
} else {
f.write_h_once("#include <stdint.h>");
f.write_h_once("#include <vector>");
f.write_h("extern std::vector<uint8_t> %s;\n", c);
- f.write_c("std::vector<uint8_t> %s = /* data inlined from %s */\n", c, fn.c_str());
+ f.write_c("std::vector<uint8_t> %s = /* data inlined from %s */\n", c, fn);
}
- if (message) f.write_c("#error %s %s\n", message, fn.c_str());
+ if (message) f.write_c("#error %s %s\n", message, fn);
f.write_cdata(data, nData);
}
f.write_c(";\n");
} else {
write_comment_h(f);
- f.write_h("#error Unsupported declaration loading inline data %s\n", fn.c_str());
+ f.write_h("#error Unsupported declaration loading inline data %s\n", fn);
if (output_format_ == 1)
f.write_h("const char *%s = \"abc...\";\n", c);
else
@@ -1097,39 +1131,39 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) {
if ((output_format_ == 1) || (output_format_ == 4)) {
if (output_format_ == 1) {
if (static_) f.write_c("static ");
- f.write_c("const char *%s = /* text inlined from %s */\n", c, fn.c_str());
+ f.write_c("const char *%s = /* text inlined from %s */\n", c, fn);
} else {
f.write_c_once("#include <string>");
if (static_) f.write_c("static ");
- f.write_c("const std::string %s = /* text inlined from %s */\n", c, fn.c_str());
+ f.write_c("const std::string %s = /* text inlined from %s */\n", c, fn);
}
- if (message) f.write_c("#error %s %s\n", message, fn.c_str());
+ if (message) f.write_c("#error %s %s\n", message, fn);
f.write_cstring(data, nData);
} else if ((output_format_ == 2) || (output_format_ == 5)) {
if (static_) f.write_c("static ");
f.write_c("int %s_size = %d;\n", c, uncompressedDataSize);
if (output_format_ == 2) {
if (static_) f.write_c("static ");
- f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn.c_str());
+ f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn);
} else {
f.write_c_once("#include <stdint.h>");
f.write_c_once("#include <vector>");
if (static_) f.write_c("static ");
- f.write_c("std::vector<uint8_t> %s = /* data compressed and inlined from %s */\n", c, fn.c_str());
+ f.write_c("std::vector<uint8_t> %s = /* data compressed and inlined from %s */\n", c, fn);
}
- if (message) f.write_c("#error %s %s\n", message, fn.c_str());
+ if (message) f.write_c("#error %s %s\n", message, fn);
f.write_cdata(data, nData);
} else {
if (output_format_ == 0) {
if (static_) f.write_c("static ");
- f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn.c_str());
+ f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn);
} else {
f.write_c_once("#include <stdint.h>");
f.write_c_once("#include <vector>");
if (static_) f.write_c("static ");
- f.write_c("std::vector<uint8_t> %s = /* data inlined from %s */\n", c, fn.c_str());
+ f.write_c("std::vector<uint8_t> %s = /* data inlined from %s */\n", c, fn);
}
- if (message) f.write_c("#error %s %s\n", message, fn.c_str());
+ if (message) f.write_c("#error %s %s\n", message, fn);
f.write_cdata(data, nData);
}
f.write_c(";\n");
@@ -1139,9 +1173,9 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) {
// giving the error: (Fluid.batch_mode && !write_codeview) ???
if (message && !f.write_codeview) {
if (Fluid.batch_mode)
- fprintf(stderr, "FLUID ERROR: %s %s\n", message, fn.c_str());
+ fprintf(stderr, "FLUID ERROR: %s %s\n", message, fn);
else
- fl_alert("%s\n%s\n", message, fn.c_str());
+ fl_alert("%s\n%s\n", message, fn);
}
if (data) free(data);
}
@@ -1157,6 +1191,15 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) {
is written to the source file, and to the header file, if declared public.
*/
+DeclBlock_Node::DeclBlock_Node() {
+ end_code_ = 0;
+ write_map_ = CODE_IN_SOURCE;
+}
+
+DeclBlock_Node::~DeclBlock_Node() {
+ if (end_code_) free((void*)end_code_);
+}
+
/// Prototype for a declaration block to be used by the factory.
DeclBlock_Node DeclBlock_Node::prototype;
@@ -1247,11 +1290,11 @@ void DeclBlock_Node::write_static(fld::io::Code_Writer& f) {
Write the \b after static code to the source file, and to the header file if declared public.
*/
void DeclBlock_Node::write_static_after(fld::io::Code_Writer& f) {
- if (!end_code().empty()) {
+ if (end_code()[0]) {
if (write_map_ & STATIC_IN_HEADER)
- f.write_h("%s\n", end_code().c_str());
+ f.write_h("%s\n", end_code());
if (write_map_ & STATIC_IN_SOURCE)
- f.write_c("%s\n", end_code().c_str());
+ f.write_c("%s\n", end_code());
}
}
@@ -1273,11 +1316,11 @@ void DeclBlock_Node::write_code1(fld::io::Code_Writer& f) {
Write the \b after code to the source file, and to the header file if declared public.
*/
void DeclBlock_Node::write_code2(fld::io::Code_Writer& f) {
- if (!end_code().empty()) {
+ if (end_code()[0]) {
if (write_map_ & CODE_IN_HEADER)
- f.write_h("%s\n", end_code().c_str());
+ f.write_h("%s\n", end_code());
if (write_map_ & CODE_IN_SOURCE)
- f.write_c("%s\n", end_code().c_str());
+ f.write_c("%s\n", end_code());
}
}
@@ -1424,6 +1467,17 @@ void Comment_Node::write_code1(fld::io::Code_Writer& f) {
Manage a class declaration and implementation.
*/
+Class_Node::Class_Node() {
+ base_class_ = 0;
+ prefix_ = 0;
+ public_ = 1;
+}
+
+Class_Node::~Class_Node() {
+ if (base_class_) free((void*)base_class_);
+ if (prefix_) free((void*)prefix_);
+}
+
/// Prototype for a class node to be used by the factory.
Class_Node Class_Node::prototype;
@@ -1465,7 +1519,7 @@ Node *Class_Node::make(Strategy strategy) {
*/
void Class_Node::write_properties(fld::io::Project_Writer &f) {
Node::write_properties(f);
- if (!base_class().empty()) {
+ if (base_class()[0]) {
f.write_string(":");
f.write_word(base_class());
}
@@ -1506,12 +1560,12 @@ void Class_Node::write_code1(fld::io::Code_Writer& f) {
write_public_state = 0;
f.write_h("\n");
write_comment_h(f);
- if (!prefix().empty())
- f.write_h("class %s %s ", prefix().c_str(), name());
+ if (prefix()[0])
+ f.write_h("class %s %s ", prefix(), name());
else
f.write_h("class %s ", name());
- if (!base_class().empty()) {
- f.write_h(": %s ", base_class().c_str());
+ if (base_class()[0]) {
+ f.write_h(": %s ", base_class());
}
f.write_h("{\n");
}