diff options
| -rw-r--r-- | CHANGES.txt | 1 | ||||
| -rw-r--r-- | fluid/Fl_Function_Type.cxx | 29 |
2 files changed, 26 insertions, 4 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index a4b66eb10..3788c5947 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -247,6 +247,7 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2022 - Fixed Delete key in Fl_Input deleting entire widgets in Fluid (STR #2841). - Reorganized Fluid Template feature (STR #3336). - Updated Fluid documentation and image (STR #3328). + - FLUID recognizes `override` and `FL_OVERRIDE` keywords (Github #801) - Duplicating Widget Class in Fluid no longer crashes (STR #3445). - Fl_Check_Browser::add(item) now accepts NULL (STR #3498). - Interface to set maximum width of spinner text field (STR #3386). diff --git a/fluid/Fl_Function_Type.cxx b/fluid/Fl_Function_Type.cxx index 91bb3b2c9..59b1f63a4 100644 --- a/fluid/Fl_Function_Type.cxx +++ b/fluid/Fl_Function_Type.cxx @@ -349,6 +349,14 @@ int Fl_Function_Type::is_public() const { return public_; } +static bool fd_isspace(int c) { + return (c>0 && c<128 && isspace(c)); +} + +static bool fd_iskeyword(int c) { + return (c>0 && c<128 && (isalnum(c) || c=='_')); +} + /** Write the code for the source and the header file. This writes the code that goes \b before all children of this class. @@ -436,11 +444,18 @@ void Fl_Function_Type::write_code1(Fd_Code_Writer& f) { f.write_h("%s;\n", s); } // skip all function default param. init in body: + // todo: code duplication, see 40 lines further down int skips=0,skipc=0; int nc=0,plevel=0; + bool arglist_done = false; for (sptr=s,nptr=(char*)name(); *nptr; nc++,nptr++) { + if (arglist_done && fd_isspace(nptr[0])) { + // skip `override` and `FL_OVERRIDE` keywords if they are following the list of arguments + if (strncmp(nptr+1, "override", 8)==0 && !fd_iskeyword(nptr[9])) { nptr += 8; continue; } + else if (strncmp(nptr+1, "FL_OVERRIDE", 11)==0 && !fd_iskeyword(nptr[12])) { nptr += 11; continue; } + } if (!skips && *nptr=='(') plevel++; - else if (!skips && *nptr==')') plevel--; + else if (!skips && *nptr==')') { plevel--; if (plevel==0) arglist_done = true; } if ( *nptr=='"' && !(nc && *(nptr-1)=='\\') ) skips = skips ? 0 : 1; else if(!skips && *nptr=='\'' && !(nc && *(nptr-1)=='\\')) @@ -453,7 +468,7 @@ void Fl_Function_Type::write_code1(Fd_Code_Writer& f) { else if(!skips && *nptr=='\'' && *(nptr-1)!='\\') skipc = skipc ? 0 : 1; if (!skips && !skipc && *nptr=='(') plevel++; - else if (!skips && *nptr==')') plevel--; + else if (!skips && *nptr==')') { plevel--; if (plevel==0) arglist_done = true; } } if (sptr < (s + sizeof(s) - 1)) *sptr++ = *nptr; @@ -482,9 +497,15 @@ void Fl_Function_Type::write_code1(Fd_Code_Writer& f) { char *nptr; int skips=0,skipc=0; int nc=0,plevel=0; + bool arglist_done = false; for (sptr=s,nptr=(char*)name(); *nptr; nc++,nptr++) { + if (arglist_done && fd_isspace(nptr[0])) { + // skip `override` and `FL_OVERRIDE` keywords if they are following the list of arguments + if (strncmp(nptr+1, "override", 8)==0 && !fd_iskeyword(nptr[9])) { nptr += 8; continue; } + else if (strncmp(nptr+1, "FL_OVERRIDE", 11)==0 && !fd_iskeyword(nptr[12])) { nptr += 11; continue; } + } if (!skips && *nptr=='(') plevel++; - else if (!skips && *nptr==')') plevel--; + else if (!skips && *nptr==')') { plevel--; if (plevel==0) arglist_done = true; } if ( *nptr=='"' && !(nc && *(nptr-1)=='\\') ) skips = skips ? 0 : 1; else if(!skips && *nptr=='\'' && !(nc && *(nptr-1)=='\\')) @@ -497,7 +518,7 @@ void Fl_Function_Type::write_code1(Fd_Code_Writer& f) { else if(!skips && *nptr=='\'' && *(nptr-1)!='\\') skipc = skipc ? 0 : 1; if (!skips && !skipc && *nptr=='(') plevel++; - else if (!skips && *nptr==')') plevel--; + else if (!skips && *nptr==')') { plevel--; if (plevel==0) arglist_done = true; } } if (sptr < (s + sizeof(s) - 1)) *sptr++ = *nptr; |
