vermaseren / form

The FORM project for symbolic manipulation of very big expressions
GNU General Public License v3.0
1.15k stars 136 forks source link

refactor: Warning function with format #514

Open tueda opened 4 months ago

tueda commented 4 months ago

This is from the discussion in #500.

Currently, we have many warnings that don't use the Warning function:

grep -n 'MesPrint.*Warning' sources/*.c
sources/comexpr.c:1316:                 MesPrint("&Warning: %d elements were overwritten. New definitions will be used",numover);
sources/compcomm.c:838:                                 MesPrint("&Warning: FewerStatistics parameter greater than MaxPatches(=%d). Adjusted to %d"
sources/message.c:793:  if ( AC.WarnFlag ) MesPrint("&Warning: %s",s);
sources/message.c:805:  if ( AC.WarnFlag >= 2 ) MesPrint("&Warning: %s",s);
sources/names.c:1006:                                           MesPrint("&Warning: dimension of %s (%d) out of range"
sources/names.c:1032:                                   MesPrint("&Warning: minimum power of %s corrected to %d"
sources/names.c:1047:                                   MesPrint("&Warning: maximum power of %s corrected to %d"
sources/names.c:1189:                   MesPrint("&Warning: Implicit declaration of %s as a symbol",t);
sources/names.c:1203:                           MesPrint("&Warning: Implicit declaration of %s as a symbol",t);
sources/names.c:1290:                                                   MesPrint("&Warning: dimension of %s (%d) out of range"
sources/names.c:1484:                                           MesPrint("&Warning: dimension of %s (%d) out of range"
sources/names.c:2437:                                   MesPrint("&Warning: dimension of %s (%d) out of range"
sources/normal.c:894:                                                   MesPrint("%w Warning: fraction could not be reconstructed in MakeRational_");
sources/normal.c:995:                                                   MesPrint("%w Warning: fraction could not be reconstructed in MakeRational_");
sources/store.c:426:                                            MesPrint("&Warning: saved expr name over %d char: %s", MAXENAME, AC.exprnames->namebuffer+e[number].name);
sources/store.c:528:                            MesPrint("&Warning: saved expr name over %d char: %s", MAXENAME, AC.exprnames->namebuffer+e->name);
sources/store.c:2939:                                   MesPrint("Warning: Conflicting complexity for %s",AT.WorkPointer);
sources/store.c:2944:                                   MesPrint("Warning: Conflicting root of unity properties for %s",AT.WorkPointer);
sources/store.c:2949:                                           MesPrint("Warning: Conflicting n in n-th root of unity properties for %s",AT.WorkPointer);
sources/store.c:2956:                                   MesPrint("Warning: Conflicting power restrictions for %s",AT.WorkPointer);
sources/store.c:3009:                                   MesPrint("Warning: %s is also a dummy index",(AT.WorkPointer));
sources/store.c:3014:                                   MesPrint("Warning: Conflicting dimensions for %s",(AT.WorkPointer));
sources/store.c:3058:                                   MesPrint("Warning: Conflicting complexity for %s",(AT.WorkPointer));
sources/store.c:3099:                                   MesPrint("Warning: Conflicting complexity for %s",(AT.WorkPointer));
sources/store.c:3103:                                   MesPrint("Warning: Conflicting symmetry properties for %s",(AT.WorkPointer));
sources/store.c:3108:                                   MesPrint("Warning: Conflicting argument restriction properties for %s",(AT.WorkPointer));

Many of them are written as:

if ( AC.WarnFlag ) {
    MesWarning("&Warning: ...", ...);
}

This is probably because of the Warning function does not have a format argument like MesPrint. If Warning has the following prototype:

int Warning(const char *format, ...);

then they can be a bit simplified.

Maybe the same for HighWarning and Error (Error0, Error1, Error2).

The implementation could be full-fledged functions, or simply variadic macros using MesPrint (assuming format is a string literal).