summaryrefslogtreecommitdiff
path: root/fluid
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2023-12-04 17:42:12 +0100
committerMatthias Melcher <github@matthiasm.com>2023-12-04 17:42:45 +0100
commited910b7368aa8a43dd72262119f14a488e8e7648 (patch)
tree4918d1a38afa1194b53a052fd8205134155b64e5 /fluid
parentcf07fa09dc752d1283c22a2df402e7356b770871 (diff)
FLUID: improves special handling of widget_class members
Diffstat (limited to 'fluid')
-rw-r--r--fluid/Fl_Function_Type.cxx2
-rw-r--r--fluid/code.cxx29
2 files changed, 26 insertions, 5 deletions
diff --git a/fluid/Fl_Function_Type.cxx b/fluid/Fl_Function_Type.cxx
index 852a33c2c..ccb195224 100644
--- a/fluid/Fl_Function_Type.cxx
+++ b/fluid/Fl_Function_Type.cxx
@@ -447,9 +447,9 @@ void Fl_Function_Type::write_code1(Fd_Code_Writer& f) {
const char* k = class_name(0);
if (k) {
+ f.write_public(public_);
if (havechildren)
write_comment_c(f);
- f.write_public(public_);
if (name()[0] == '~')
constructor = 1;
else {
diff --git a/fluid/code.cxx b/fluid/code.cxx
index 192e21149..9f6e30118 100644
--- a/fluid/code.cxx
+++ b/fluid/code.cxx
@@ -662,6 +662,21 @@ void Fd_Code_Writer::write_c_indented(const char *textlines, int inIndent, char
}
}
+/**
+ Return true if the type would be the member of a class.
+ Some types are treated differently if they are inside class. Especially within
+ a Widget Class, children that are widgets are written as part of the
+ constructor whereas functions, declarations, and inline data are seen as
+ members of the class itself.
+ */
+bool is_class_member(Fl_Type *t) {
+ return t->is_a(ID_Function)
+ || t->is_a(ID_Decl)
+ || t->is_a(ID_Data);
+// || t->is_a(ID_Class) // FLUID can't handle a class inside a class
+// || t->is_a(ID_Widget_Class)
+// || t->is_a(ID_DeclBlock) // Declaration blocks are generally not handled well
+}
/**
Recursively dump code, putting children between the two parts of the parent code.
@@ -683,8 +698,12 @@ Fl_Type* Fd_Code_Writer::write_code(Fl_Type* p) {
if (p->is_widget() && p->is_class()) {
// Handle widget classes specially
for (q = p->next; q && q->level > p->level;) {
- if (!q->is_a(ID_Function)) q = write_code(q);
- else {
+ // note: maybe declaration blocks should be handled like comments in the context
+ // note: we don't handle comments before a comment before a member
+ bool comment_before_member = (q->is_a(ID_Comment) && q->next && q->next->level==q->level && is_class_member(q->next));
+ if (!is_class_member(q) && !comment_before_member) {
+ q = write_code(q);
+ } else {
int level = q->level;
do {
q = q->next;
@@ -700,8 +719,10 @@ Fl_Type* Fd_Code_Writer::write_code(Fl_Type* p) {
if (write_sourceview) p->header2_end = (int)ftell(header_file);
for (q = p->next; q && q->level > p->level;) {
- if (q->is_a(ID_Function)) q = write_code(q);
- else {
+ bool comment_before_member = (q->is_a(ID_Comment) && q->next && q->next->level==q->level && is_class_member(q->next));
+ if (is_class_member(q) || comment_before_member) {
+ q = write_code(q);
+ } else {
int level = q->level;
do {
q = q->next;