summaryrefslogtreecommitdiff
path: root/fluid
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2023-10-19 12:13:46 +0200
committerMatthias Melcher <github@matthiasm.com>2023-10-19 12:13:46 +0200
commitca7844cf94ad5ba892fe8b162a86b25c9ba6a172 (patch)
tree93286a71bae0ef9c947540bb95dec7428b1fdcde /fluid
parentff7958e57a1b4e163fb05015dea7ba35e09055ee (diff)
FLUID now recognizes `override` and `FL_OVERRIDE` keywords (#801)
Diffstat (limited to 'fluid')
-rw-r--r--fluid/Fl_Function_Type.cxx29
1 files changed, 25 insertions, 4 deletions
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;