diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 2006-07-26 19:52:28 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 2006-07-26 19:52:28 +0000 |
| commit | 500d7616fd16005f6f8eea0a061160177160ec34 (patch) | |
| tree | 82b94a770435329debf353ada5176c16d185cbd5 | |
| parent | 9ee02e0f013398536b61f08dd3ced4188cd559bb (diff) | |
Revamp variable tests so that we rarely need to provide "o" and
"w" variables. This eliminates most of the "variable is shadowed"
warnings from GCC we get after creating .cxx files from FLUID.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5266 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | CHANGES | 7 | ||||
| -rw-r--r-- | fluid/Fl_Function_Type.cxx | 7 | ||||
| -rw-r--r-- | fluid/Fl_Group_Type.cxx | 9 | ||||
| -rw-r--r-- | fluid/Fl_Menu_Type.cxx | 6 | ||||
| -rw-r--r-- | fluid/Fl_Type.h | 3 | ||||
| -rw-r--r-- | fluid/Fl_Widget_Type.cxx | 130 | ||||
| -rw-r--r-- | fluid/Fl_Window_Type.cxx | 26 | ||||
| -rw-r--r-- | fluid/Fluid_Image.cxx | 6 | ||||
| -rw-r--r-- | fluid/Fluid_Image.h | 2 | ||||
| -rw-r--r-- | fluid/code.cxx | 12 |
10 files changed, 117 insertions, 91 deletions
@@ -1,8 +1,11 @@ CHANGES IN FLTK 1.1.8 + - FLUID now only writes definitions of "o" and "w" + variables as needed, reducing the number of "variable + is shadowed" warnings from GCC. - Added access to Xft font pointer (STR #1328) - - Fixed endianness in OS X mouse cursor graphics - (STR #1348) + - Fixed endianness in OS X mouse cursor graphics (STR + #1348) - Fixed crash on mixed use of keyboard and mouse for Fl_Menu_Button (STR #1356) - Fixed Fl_Window::visible() and shown() for OS X diff --git a/fluid/Fl_Function_Type.cxx b/fluid/Fl_Function_Type.cxx index 1cf709dea..5167657e5 100644 --- a/fluid/Fl_Function_Type.cxx +++ b/fluid/Fl_Function_Type.cxx @@ -3,7 +3,7 @@ // // C function type code for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2005 by Bill Spitzak and others. +// Copyright 1998-2006 by Bill Spitzak and others. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -334,7 +334,7 @@ void Fl_Function_Type::write_code1() { write_c("%s%s %s {\n", rtype, star, s); } } - if (havewidgets) write_c(" %s* w;\n",subclassname(child)); +// if (havewidgets) write_c(" %s* w;\n",subclassname(child)); indentation += 2; } @@ -1082,9 +1082,8 @@ Fl_Class_Type Fl_Class_type; static Fl_Class_Type *current_class; extern Fl_Widget_Class_Type *current_widget_class; -extern int varused_test; void write_public(int state) { - if ((!current_class && !current_widget_class) || varused_test) return; + if (!current_class && !current_widget_class) return; if (current_class && current_class->write_public_state == state) return; if (current_widget_class && current_widget_class->write_public_state == state) return; if (current_class) current_class->write_public_state = state; diff --git a/fluid/Fl_Group_Type.cxx b/fluid/Fl_Group_Type.cxx index bb5834b0f..9dda8b5a3 100644 --- a/fluid/Fl_Group_Type.cxx +++ b/fluid/Fl_Group_Type.cxx @@ -7,7 +7,7 @@ // the Fl_Tabs widget, with special stuff to select tab items and // insure that only one is visible. // -// Copyright 1998-2005 by Bill Spitzak and others. +// Copyright 1998-2006 by Bill Spitzak and others. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -124,9 +124,12 @@ void Fl_Group_Type::write_code1() { } void Fl_Group_Type::write_code2() { + const char *var = name() ? name() : "o"; write_extra_code(); - write_c("%so->end();\n", indent()); - if (resizable()) write_c("%sFl_Group::current()->resizable(o);\n", indent()); + write_c("%s%s->end();\n", indent(), var); + if (resizable()) { + write_c("%sFl_Group::current()->resizable(%s);\n", indent(), var); + } write_block_close(); } diff --git a/fluid/Fl_Menu_Type.cxx b/fluid/Fl_Menu_Type.cxx index 1e493cc19..17d98f48e 100644 --- a/fluid/Fl_Menu_Type.cxx +++ b/fluid/Fl_Menu_Type.cxx @@ -9,7 +9,7 @@ // This file also contains code to make Fl_Menu_Button, Fl_Menu_Bar, // etc widgets. // -// Copyright 1998-2005 by Bill Spitzak and others. +// Copyright 1998-2006 by Bill Spitzak and others. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -373,7 +373,7 @@ void Fl_Menu_Item_Type::write_code1() { init = 1; write_c("%s{ Fl_Menu_Item* o = &%s[%d];\n", indent(), mname, i); } - image->write_code(); + image->write_code("o"); } for (int n=0; n < NUM_EXTRA_CODE; n++) if (extra_code(n) && !isdeclare(extra_code(n))) { @@ -462,7 +462,7 @@ Fl_Type* Fl_Menu_Type::click_test(int, int) { void Fl_Menu_Type::write_code2() { if (next && next->is_menu_item()) - write_c("%so->menu(%s);\n", indent(), + write_c("%s%s->menu(%s);\n", indent(), name() ? name() : "o", unique_id(this, "menu", name(), label())); Fl_Widget_Type::write_code2(); } diff --git a/fluid/Fl_Type.h b/fluid/Fl_Type.h index a6e9eebb5..7d12832b6 100644 --- a/fluid/Fl_Type.h +++ b/fluid/Fl_Type.h @@ -11,7 +11,8 @@ // instance of this object. It could also have a "copy()" function, // but it was easier to implement this by using the file read/write // that is needed to save the setup anyways. -// Copyright 1998-2005 by Bill Spitzak and others. +// +// Copyright 1998-2006 by Bill Spitzak and others. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx index f4f99d2cf..1cc52a9ec 100644 --- a/fluid/Fl_Widget_Type.cxx +++ b/fluid/Fl_Widget_Type.cxx @@ -1941,8 +1941,6 @@ const char *Fl_Type::callback_name() { return unique_id(this, "cb", name(), label()); } -extern int varused_test, varused; - void Fl_Widget_Type::write_code1() { const char* t = subclassname(this); const char *c = array_name(this); @@ -1960,17 +1958,23 @@ void Fl_Widget_Type::write_code1() { write_h(" static void %s(%s*, %s);\n", cn, t, ut); } // figure out if local variable will be used (prevent compiler warnings): - if (is_parent()) - varused = 1; - else { - varused_test = 1; varused = 0; - write_widget_code(); - varused_test = 0; + int oused = !name(); + int wused = !name() && is_window(); + const char *ptr; + + if (!oused) { for (int n=0; n < NUM_EXTRA_CODE; n++) - if (extra_code(n) && !isdeclare(extra_code(n))) varused = 1; + if (extra_code(n) && !isdeclare(extra_code(n)) && + (ptr = strstr(extra_code(n), "o->")) != NULL && + (ptr == extra_code(n) || + (!isalnum(ptr[-1] & 255) && ptr[-1] != '_'))) { + oused = 1; + break; + } } + write_c(indent()); - if (varused) write_c("{ %s* o = ", t); + if (oused) write_c("{ %s* o = ", t); if (name()) write_c("%s = ", name()); if (is_window()) { // Handle special case where user is faking a Fl_Group type as a window, @@ -2002,10 +2006,12 @@ void Fl_Widget_Type::write_code1() { } } write_c(");\n"); - indentation += 2; - if (is_window()) write_c("%sw = o;\n",indent()); - if (varused) write_widget_code(); + if (oused) + indentation += 2; + + if (wused) write_c("%s%s* w = o;\n",indent(), subclassname(this)); + write_widget_code(); } void Fl_Widget_Type::write_color(const char* field, Fl_Color color) { @@ -2038,18 +2044,21 @@ void Fl_Widget_Type::write_color(const char* field, Fl_Color color) { case FL_DARK_CYAN: color_name = "FL_DARK_CYAN"; break; case FL_WHITE: color_name = "FL_WHITE"; break; } + const char *var = is_class() ? "this" : name() ? name() : "o"; if (color_name) { - write_c("%so->%s(%s);\n", indent(), field, color_name); + write_c("%s%s->%s(%s);\n", indent(), var, field, color_name); } else { - write_c("%so->%s((Fl_Color)%d);\n", indent(), field, color); + write_c("%s%s->%s((Fl_Color)%d);\n", indent(), var, field, color); } } // this is split from write_code1() for Fl_Window_Type: void Fl_Widget_Type::write_widget_code() { Fl_Widget* tplate = ((Fl_Widget_Type*)factory)->o; + const char *var = is_class() ? "this" : name() ? name() : "o"; + if (tooltip() && *tooltip()) { - write_c("%so->tooltip(",indent()); + write_c("%s%s->tooltip(",indent(), var); switch (i18n_type) { case 0 : /* None */ write_cstring(tooltip()); @@ -2070,111 +2079,113 @@ void Fl_Widget_Type::write_widget_code() { } if (is_spinner() && ((Fl_Spinner*)o)->type() != ((Fl_Spinner*)tplate)->type()) - write_c("%so->type(%d);\n", indent(), ((Fl_Spinner*)o)->type()); + write_c("%s%s->type(%d);\n", indent(), var, ((Fl_Spinner*)o)->type()); else if (o->type() != tplate->type() && !is_window()) - write_c("%so->type(%d);\n", indent(), o->type()); + write_c("%s%s->type(%d);\n", indent(), var, o->type()); if (o->box() != tplate->box() || subclass()) - write_c("%so->box(FL_%s);\n", indent(), boxname(o->box())); + write_c("%s%s->box(FL_%s);\n", indent(), var, boxname(o->box())); if (is_button()) { Fl_Button* b = (Fl_Button*)o; - if (b->down_box()) write_c("%so->down_box(FL_%s);\n", indent(), + if (b->down_box()) write_c("%s%s->down_box(FL_%s);\n", indent(), var, boxname(b->down_box())); - if (b->value()) write_c("%so->value(1);\n", indent()); + if (b->value()) write_c("%s%s->value(1);\n", indent(), var); if (b->shortcut()) - write_c("%so->shortcut(0x%x);\n", indent(), b->shortcut()); + write_c("%s%s->shortcut(0x%x);\n", indent(), var, b->shortcut()); } else if (!strcmp(type_name(), "Fl_Input_Choice")) { Fl_Input_Choice* b = (Fl_Input_Choice*)o; - if (b->down_box()) write_c("%so->down_box(FL_%s);\n", indent(), + if (b->down_box()) write_c("%s%s->down_box(FL_%s);\n", indent(), var, boxname(b->down_box())); } else if (is_menu_button()) { Fl_Menu_* b = (Fl_Menu_*)o; - if (b->down_box()) write_c("%so->down_box(FL_%s);\n", indent(), + if (b->down_box()) write_c("%s%s->down_box(FL_%s);\n", indent(), var, boxname(b->down_box())); } if (o->color() != tplate->color() || subclass()) write_color("color", o->color()); if (o->selection_color() != tplate->selection_color() || subclass()) write_color("selection_color", o->selection_color()); - if (image) image->write_code(); - if (inactive) inactive->write_code(1); + if (image) image->write_code(var); + if (inactive) inactive->write_code(var, 1); if (o->labeltype() != tplate->labeltype() || subclass()) - write_c("%so->labeltype(FL_%s);\n", indent(), + write_c("%s%s->labeltype(FL_%s);\n", indent(), var, item_name(labeltypemenu, o->labeltype())); if (o->labelfont() != tplate->labelfont() || subclass()) - write_c("%so->labelfont(%d);\n", indent(), o->labelfont()); + write_c("%s%s->labelfont(%d);\n", indent(), var, o->labelfont()); if (o->labelsize() != tplate->labelsize() || subclass()) - write_c("%so->labelsize(%d);\n", indent(), o->labelsize()); + write_c("%s%s->labelsize(%d);\n", indent(), var, o->labelsize()); if (o->labelcolor() != tplate->labelcolor() || subclass()) write_color("labelcolor", o->labelcolor()); if (is_valuator()) { Fl_Valuator* v = (Fl_Valuator*)o; Fl_Valuator* f = (Fl_Valuator*)(tplate); if (v->minimum()!=f->minimum()) - write_c("%so->minimum(%g);\n", indent(), v->minimum()); + write_c("%s%s->minimum(%g);\n", indent(), var, v->minimum()); if (v->maximum()!=f->maximum()) - write_c("%so->maximum(%g);\n", indent(), v->maximum()); + write_c("%s%s->maximum(%g);\n", indent(), var, v->maximum()); if (v->step()!=f->step()) - write_c("%so->step(%g);\n", indent(), v->step()); + write_c("%s%s->step(%g);\n", indent(), var, v->step()); if (v->value()) { if (is_valuator()==3) { // Fl_Scrollbar::value(double) is nott available - write_c("%so->Fl_Slider::value(%g);\n", indent(), v->value()); + write_c("%s%s->Fl_Slider::value(%g);\n", indent(), var, v->value()); } else { - write_c("%so->value(%g);\n", indent(), v->value()); + write_c("%s%s->value(%g);\n", indent(), var, v->value()); } } if (is_valuator()>=2) { double x = ((Fl_Slider*)v)->slider_size(); double y = ((Fl_Slider*)f)->slider_size(); - if (x != y) write_c("%so->slider_size(%g);\n", indent(), x); + if (x != y) write_c("%s%s->slider_size(%g);\n", indent(), var, x); } } if (is_spinner()) { Fl_Spinner* v = (Fl_Spinner*)o; Fl_Spinner* f = (Fl_Spinner*)(tplate); if (v->minimum()!=f->minimum()) - write_c("%so->minimum(%g);\n", indent(), v->minimum()); + write_c("%s%s->minimum(%g);\n", indent(), var, v->minimum()); if (v->maximum()!=f->maximum()) - write_c("%so->maximum(%g);\n", indent(), v->maximum()); + write_c("%s%s->maximum(%g);\n", indent(), var, v->maximum()); if (v->step()!=f->step()) - write_c("%so->step(%g);\n", indent(), v->step()); + write_c("%s%s->step(%g);\n", indent(), var, v->step()); if (v->value()) - write_c("%so->value(%g);\n", indent(), v->value()); + write_c("%s%s->value(%g);\n", indent(), var, v->value()); } {Fl_Font ff; int fs; Fl_Color fc; if (textstuff(4,ff,fs,fc)) { Fl_Font f; int s; Fl_Color c; textstuff(0,f,s,c); - if (f != ff) write_c("%so->textfont(%d);\n", indent(), f); - if (s != fs) write_c("%so->textsize(%d);\n", indent(), s); - if (c != fc) write_c("%so->textcolor(%d);\n",indent(), c); + if (f != ff) write_c("%s%s->textfont(%d);\n", indent(), var, f); + if (s != fs) write_c("%s%s->textsize(%d);\n", indent(), var, s); + if (c != fc) write_c("%s%s->textcolor(%d);\n",indent(), var, c); }} const char* ud = user_data(); if (class_name(1) && !parent->is_widget()) ud = "this"; if (callback()) { - write_c("%so->callback((Fl_Callback*)%s", indent(), callback_name()); + write_c("%s%s->callback((Fl_Callback*)%s", indent(), var, callback_name()); if (ud) write_c(", (void*)(%s));\n", ud); else write_c(");\n"); } else if (ud) { - write_c("%so->user_data((void*)(%s));\n", indent(), ud); + write_c("%s%s->user_data((void*)(%s));\n", indent(), var, ud); } if (o->align() != tplate->align() || subclass()) { int i = o->align(); - write_c("%so->align(%s", indent(), + write_c("%s%s->align(%s", indent(), var, item_name(alignmenu, i & ~FL_ALIGN_INSIDE)); if (i & FL_ALIGN_INSIDE) write_c("|FL_ALIGN_INSIDE"); write_c(");\n"); } if (o->when() != tplate->when() || subclass()) - write_c("%so->when(%s);\n", indent(),item_name(whensymbolmenu, o->when())); + write_c("%s%s->when(%s);\n", indent(), var, + item_name(whensymbolmenu, o->when())); if (!o->visible() && o->parent()) - write_c("%so->hide();\n", indent()); + write_c("%s%s->hide();\n", indent(), var); if (!o->active()) - write_c("%so->deactivate();\n", indent()); + write_c("%s%s->deactivate();\n", indent(), var); if (!is_group() && resizable()) - write_c("%sFl_Group::current()->resizable(o);\n",indent()); + write_c("%sFl_Group::current()->resizable(%s);\n", indent(), var); if (hotspot()) - write_c("%sw->hotspot(o);\n", indent()); + write_c("%s%s->hotspot(o);\n", indent(), + is_class() ? "this" : name() ? name() : "w"); } void Fl_Widget_Type::write_extra_code() { @@ -2184,8 +2195,23 @@ void Fl_Widget_Type::write_extra_code() { } void Fl_Widget_Type::write_block_close() { - indentation -= 2; - if (is_parent() || varused) write_c("%s}\n", indent()); + int oused = !name(); + const char *ptr; + + if (!oused) { + for (int n=0; n < NUM_EXTRA_CODE; n++) + if (extra_code(n) && !isdeclare(extra_code(n)) && + (ptr = strstr(extra_code(n), "o->")) != NULL && + (ptr == extra_code(n) || + (!isalnum(ptr[-1] & 255) && ptr[-1] != '_'))) { + oused = 1; + break; + } + } + if (oused) { + indentation -= 2; + write_c("%s}\n", indent()); + } } void Fl_Widget_Type::write_code2() { diff --git a/fluid/Fl_Window_Type.cxx b/fluid/Fl_Window_Type.cxx index 7e8e0000b..b9a7f8188 100644 --- a/fluid/Fl_Window_Type.cxx +++ b/fluid/Fl_Window_Type.cxx @@ -7,7 +7,7 @@ // for interacting with the overlay, which allows the user to // select, move, and resize the children widgets. // -// Copyright 1998-2005 by Bill Spitzak and others. +// Copyright 1998-2006 by Bill Spitzak and others. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -1279,23 +1279,27 @@ void Fl_Window_Type::write_code1() { } void Fl_Window_Type::write_code2() { + const char *var = is_class() ? "this" : name() ? name() : "o"; write_extra_code(); - if (modal) write_c("%so->set_modal();\n", indent()); - else if (non_modal) write_c("%so->set_non_modal();\n", indent()); - if (!((Fl_Window*)o)->border()) write_c("%so->clear_border();\n", indent()); + if (modal) write_c("%s%s->set_modal();\n", indent(), var); + else if (non_modal) write_c("%s%s->set_non_modal();\n", indent(), var); + if (!((Fl_Window*)o)->border()) { + write_c("%s%s->clear_border();\n", indent(), var); + } if (xclass) { - write_c("%so->xclass(", indent()); + write_c("%s%s->xclass(", indent(), var); write_cstring(xclass); write_c(");\n"); } if (sr_max_w || sr_max_h) { - write_c("%so->size_range(%d, %d, %d, %d);\n", indent(), sr_min_w, sr_min_h, sr_max_w, sr_max_h); + write_c("%s%s->size_range(%d, %d, %d, %d);\n", indent(), var, + sr_min_w, sr_min_h, sr_max_w, sr_max_h); } else if (sr_min_w || sr_min_h) { - write_c("%so->size_range(%d, %d);\n", indent(), sr_min_w, sr_min_h); + write_c("%s%s->size_range(%d, %d);\n", indent(), var, sr_min_w, sr_min_h); } - write_c("%so->end();\n", indent()); + write_c("%s%s->end();\n", indent(), var); if (((Fl_Window*)o)->resizable() == o) - write_c("%so->resizable(o);\n", indent()); + write_c("%s%s->resizable(o);\n", indent(), var); write_block_close(); } @@ -1435,7 +1439,7 @@ void Fl_Widget_Class_Type::write_code1() { write_c("}\n\n"); write_c("void %s::_%s() {\n", name(), name()); - write_c(" %s *w = this;\n", name()); +// write_c(" %s *w = this;\n", name()); } else { write_h("public:\n"); write_h(" %s(int X, int Y, int W, int H, const char *L = 0);\n", name()); @@ -1447,7 +1451,7 @@ void Fl_Widget_Class_Type::write_code1() { write_c(" : %s(X, Y, W, H, L) {\n", c); } - write_c(" %s *o = this;\n", name()); +// write_c(" %s *o = this;\n", name()); write_widget_code(); } diff --git a/fluid/Fluid_Image.cxx b/fluid/Fluid_Image.cxx index fba6a9f9c..6bfc7ad8a 100644 --- a/fluid/Fluid_Image.cxx +++ b/fluid/Fluid_Image.cxx @@ -3,7 +3,7 @@ // // Pixmap label support for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2005 by Bill Spitzak and others. +// Copyright 1998-2006 by Bill Spitzak and others. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -118,9 +118,9 @@ void Fluid_Image::write_static() { } } -void Fluid_Image::write_code(int inactive) { +void Fluid_Image::write_code(const char *var, int inactive) { if (!img) return; - write_c("%so->%s(%s);\n", indent(), inactive ? "deimage" : "image", + write_c("%s%s->%s(%s);\n", indent(), var, inactive ? "deimage" : "image", unique_id(this, "image", fl_filename_name(name()), 0)); } diff --git a/fluid/Fluid_Image.h b/fluid/Fluid_Image.h index 128c61ffe..0e62c28b7 100644 --- a/fluid/Fluid_Image.h +++ b/fluid/Fluid_Image.h @@ -50,7 +50,7 @@ public: void image(Fl_Widget *); // set the image of this widget void deimage(Fl_Widget *); // set the deimage of this widget void write_static(); - void write_code(int inactive = 0); + void write_code(const char *var, int inactive = 0); const char *name() const {return name_;} }; diff --git a/fluid/code.cxx b/fluid/code.cxx index 25f68fc45..597f77ef3 100644 --- a/fluid/code.cxx +++ b/fluid/code.cxx @@ -3,7 +3,7 @@ // // Code output routines for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2005 by Bill Spitzak and others. +// Copyright 1998-2006 by Bill Spitzak and others. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -153,15 +153,8 @@ int write_declare(const char *format, ...) { //////////////////////////////////////////////////////////////// -// silly thing to prevent declaring unused variables: -// When this symbol is on, all attempts to write code don't write -// anything, but set a variable if it looks like the varaible "o" is used: -int varused_test; -int varused; - // write an array of C characters (adds a null): void write_cstring(const char *w, int length) { - if (varused_test) return; const char *e = w+length; int linelength = 1; putc('\"', code_file); @@ -228,7 +221,6 @@ void write_cstring(const char *w) {write_cstring(w,strlen(w));} // write an array of C binary data (does not add a null): void write_cdata(const char *s, int length) { - if (varused_test) return; const unsigned char *w = (const unsigned char *)s; const unsigned char *e = w+length; int linelength = 1; @@ -246,7 +238,6 @@ void write_cdata(const char *s, int length) { } void write_c(const char* format,...) { - if (varused_test) {varused = 1; return;} va_list args; va_start(args, format); vfprintf(code_file, format, args); @@ -254,7 +245,6 @@ void write_c(const char* format,...) { } void write_h(const char* format,...) { - if (varused_test) return; va_list args; va_start(args, format); vfprintf(header_file, format, args); |
