C# 'out' or 'ref' removal improvements in director typemaps.

- Add support to DOH Replace for not replacing inside C comments
- Fix removing 'out' or 'ref' when these are present in C comments
  in cstype typemaps.

Closes #1628
This commit is contained in:
William S Fulton 2019-11-26 19:39:28 +00:00
commit 18b2dcd222
5 changed files with 126 additions and 13 deletions

View file

@ -595,6 +595,13 @@ static char *end_quote(char *s) {
}
}
static char *end_comment(char *s) {
char *substring = strstr(s, "*/");
if (substring)
++substring;
return substring;
}
static char *match_simple(char *base, char *s, char *token, int tokenlen) {
(void) base;
(void) tokenlen;
@ -677,6 +684,7 @@ static int replace_simple(String *str, char *token, char *rep, int flags, int co
int ic;
int rcount = 0;
int noquote = 0;
int nocomment = 0;
char *c, *s, *t, *first;
char *q, *q2;
char *base;
@ -698,6 +706,11 @@ static int replace_simple(String *str, char *token, char *rep, int flags, int co
if (flags & DOH_REPLACE_NOQUOTE)
noquote = 1;
if (flags & DOH_REPLACE_NOCOMMENT)
nocomment = 1;
assert(!(noquote && nocomment)); /* quote and comment combination not implemented */
/* If we are not replacing inside quotes, we need to do a little extra work */
if (noquote) {
q = strpbrk(base, "\"\'");
@ -723,6 +736,31 @@ static int replace_simple(String *str, char *token, char *rep, int flags, int co
}
}
/* If we are not replacing inside comments, we need to do a little extra work */
if (nocomment) {
q = strstr(base, "/*");
if (!q) {
nocomment = 0; /* Well, no comments to worry about. Oh well */
} else {
while (q && (q < s)) {
/* First match was found inside a comment. Try to find another match */
q2 = end_comment(q);
if (!q2) {
return 0;
}
if (q2 > s) {
/* Find next match */
s = (*match) (base, q2 + 1, token, tokenlen);
}
if (!s)
return 0; /* Oh well, no matches */
q = strstr(q2 + 1, "/*");
if (!q)
nocomment = 0; /* No more comments */
}
}
}
first = s;
replen = (int)strlen(rep);
@ -768,6 +806,28 @@ static int replace_simple(String *str, char *token, char *rep, int flags, int co
}
}
}
if (nocomment) {
q = strstr(s, "/*");
if (!q) {
nocomment = 0;
} else {
while (q && (q < c)) {
/* First match was found inside a comment. Try to find another match */
q2 = end_comment(q);
if (!q2) {
c = 0;
break;
}
if (q2 > c)
c = (*match) (base, q2 + 1, token, tokenlen);
if (!c)
break;
q = strstr(q2 + 1, "/*");
if (!q)
nocomment = 0; /* No more comments */
}
}
}
if (delta) {
if (c) {
memmove(t, s, c - s);
@ -823,6 +883,29 @@ static int replace_simple(String *str, char *token, char *rep, int flags, int co
}
}
}
if (nocomment) {
q = strstr(s, "/*");
if (!q) {
break;
} else {
while (q && (q < c)) {
/* First match was found inside a comment. Try to find another match */
q2 = end_comment(q);
if (!q2) {
c = 0;
break;
}
if (q2 > c) {
c = (*match) (base, q2 + 1, token, tokenlen);
if (!c)
break;
}
q = strstr(q2 + 1, "/*");
if (!q)
nocomment = 0;
}
}
}
if (c) {
rcount++;
ic--;
@ -875,6 +958,29 @@ static int replace_simple(String *str, char *token, char *rep, int flags, int co
}
}
}
if (nocomment) {
q = strstr(s, "/*");
if (!q) {
nocomment = 0;
} else {
while (q && (q < c)) {
/* First match was found inside a comment. Try to find another match */
q2 = end_comment(q);
if (!q2) {
c = 0;
break;
}
if (q2 > c) {
c = (*match) (base, q2 + 1, token, tokenlen);
if (!c)
break;
}
q = strstr(q2 + 1, "/*");
if (!q)
nocomment = 0; /* No more comments */
}
}
}
if (i < (rcount - 1)) {
memcpy(t, s, c - s);
t += (c - s);