diff options
author | Gaius Mulley <gaiusmod2@gmail.com> | 2023-03-13 23:03:24 +0000 |
---|---|---|
committer | Gaius Mulley <gaiusmod2@gmail.com> | 2023-03-13 23:03:24 +0000 |
commit | 370298f493020eeff48bc2e56463c1097ed67b1d (patch) | |
tree | 5c621f17aea822204f2ba717ebe7a49649848bf8 /gcc/m2/gm2-gcc/m2linemap.cc | |
parent | eb01d03f06cc36efa38ac9f80ad686d368920c41 (diff) | |
download | gcc-370298f493020eeff48bc2e56463c1097ed67b1d.zip gcc-370298f493020eeff48bc2e56463c1097ed67b1d.tar.gz gcc-370298f493020eeff48bc2e56463c1097ed67b1d.tar.bz2 |
PR 109103 Modula2 Missing function internal_error_at
m2expr.cc should call to internal_error_at, but that function
does not exist yet. For symmetry with the other error reporting
functions, it should be added. This patch provides this function
and also corrects obvious bool/int parameter mismatches in
m2options.h and m2expr.h.
gcc/m2/ChangeLog:
PR modula2/109103
* gm2-compiler/M2ALU.def (PushString): New parameter issueError.
* gm2-compiler/M2ALU.mod (PushString): New parameter issueError.
* gm2-compiler/SymbolTable.mod (PushString): New parameter issueError.
* gm2-gcc/m2decl.cc (m2decl_DetermineSizeOfConstant): Pass
location to interpret_m2_integer.
(m2decl_BuildConstLiteralNumber): New parameter issueError.
* gm2-gcc/m2expr.cc (m2expr_IsTrue): Replace int with bool.
(m2expr_IsFalse): Replace int with bool.
(m2expr_AreConstantsEqual): Replace int with bool.
(m2expr_BuildBinaryForeachWordDo): Call m2linemap_internal_error_at.
(append_digit): Ditto.
(m2expr_interpret_integer): Add location parameter.
(append_m2_digit): Call m2linemap_internal_error_at.
(m2expr_interpret_m2_integer): Add location parameter.
(m2expr_GetSizeOf): Replace sizeof with SIZE in error message.
* gm2-gcc/m2expr.h (m2expr_AreRealOrComplexConstantsEqual):
Replace int with bool.
(m2expr_AreConstantsEqual): Ditto.
(m2expr_IsFalse): Ditto.
(m2expr_IsTrue): Ditto.
(m2expr_interpret_integer): Add location parameter.
(m2expr_interpret_m2_integer): Add location parameter.
* gm2-gcc/m2linemap.cc (mformat_value): New function.
(expand_format): New function.
(expand_message): New function.
(gm2_internal_error_at): New function.
(m2linemap_internal_error_at): New function.
* gm2-gcc/m2linemap.h (m2linemap_internal_error_at): New function.
* gm2-gcc/m2options.h (M2Options_SetISO): Replace int with bool.
(M2Options_SetPIM): Ditto.
(M2Options_SetPIM2): Ditto.
(M2Options_SetPIM3): Ditto.
(M2Options_SetPIM4): Ditto.
(M2Options_SetFloatValueCheck): Ditto.
(M2Options_SetWholeValueCheck): Ditto.
(M2Options_GetISO): Ditto.
(M2Options_GetPIM): Ditto.
(M2Options_GetPIM2): Ditto.
(M2Options_GetPIM3): Ditto.
(M2Options_GetPIM4): Ditto.
(M2Options_GetPositiveModFloor): Ditto.
(M2Options_GetFloatValueCheck): Ditto.
(M2Options_GetWholeValueCheck): Ditto.
(M2Options_Setc): Ditto.
(M2Options_Getc): Ditto.
(M2Options_SetPPOnly): Ditto.
(M2Options_GetPPOnly): Ditto.
(M2Options_SetUselist): Ditto.
(M2Options_SetAutoInit): Ditto.
(M2Options_SetPositiveModFloor): Ditto.
(M2Options_SetNilCheck): Ditto.
(M2Options_SetWholeDiv): Ditto.
(M2Options_SetIndex): Ditto.
(M2Options_SetRange): Ditto.
(M2Options_SetReturnCheck): Ditto.
(M2Options_SetCaseCheck): Ditto.
(M2Options_SetCheckAll): Ditto.
(M2Options_SetExceptions): Ditto.
(M2Options_SetStyle): Ditto.
(M2Options_SetPedantic): Ditto.
(M2Options_SetPedanticParamNames): Ditto.
(M2Options_SetPedanticCast): Ditto.
(M2Options_SetExtendedOpaque): Ditto.
(M2Options_SetVerboseUnbounded): Ditto.
(M2Options_SetXCode): Ditto.
(M2Options_SetCompilerDebugging): Ditto.
(M2Options_SetQuadDebugging): Ditto.
(M2Options_SetDebugTraceQuad): Ditto.
(M2Options_SetDebugTraceAPI): Ditto.
(M2Options_SetSources): Ditto.
(M2Options_SetUnboundedByReference): Ditto.
(M2Options_SetDumpSystemExports): Ditto.
(M2Options_SetOptimizing): Ditto.
(M2Options_SetQuiet): Ditto.
(M2Options_SetCC1Quiet): Ditto.
(M2Options_SetCpp): Ditto.
(M2Options_SetSwig): Ditto.
(M2Options_SetWholeProgram): Ditto.
(M2Options_SetDebugFunctionLineNumbers): Ditto.
(M2Options_SetGenerateStatementNote): Ditto.
(M2Options_GetCpp): Ditto.
(M2Options_GetM2g): Ditto.
(M2Options_SetM2g): Ditto.
(M2Options_SetLowerCaseKeywords): Ditto.
(M2Options_SetVerbose): Ditto.
(M2Options_SetUnusedVariableChecking): Ditto.
(M2Options_SetUnusedParameterChecking): Ditto.
(M2Options_SetStrictTypeChecking): Ditto.
(M2Options_SetWall): Ditto.
(M2Options_SetSaveTemps): Ditto.
(M2Options_GetSaveTemps): Ditto.
(M2Options_SetScaffoldStatic): Ditto.
(M2Options_SetScaffoldDynamic): Ditto.
(M2Options_SetScaffoldMain): Ditto.
(M2Options_SetGenModuleList): Ditto.
(M2Options_SetShared): Ditto.
* gm2-libs-ch/M2LINK.c: Ditto.
* gm2-libs-ch/m2rts.h (M2RTS_RequestDependant): Replace
const char * with const void *.
(M2RTS_RegisterModule): Ditto.
(M2RTS_ConstructModules): Ditto.
* gm2-gcc/m2decl.def (DetermineSizeOfConstant): New parameter
issueError.
* gm2-gcc/m2decl.h (DetermineSizeOfConstant): New parameter
issueError.
gcc/testsuite/ChangeLog:
* gm2/pim/fail/largeconst.mod: New test.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Diffstat (limited to 'gcc/m2/gm2-gcc/m2linemap.cc')
-rw-r--r-- | gcc/m2/gm2-gcc/m2linemap.cc | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/gcc/m2/gm2-gcc/m2linemap.cc b/gcc/m2/gm2-gcc/m2linemap.cc index e34477f..9955bd1 100644 --- a/gcc/m2/gm2-gcc/m2linemap.cc +++ b/gcc/m2/gm2-gcc/m2linemap.cc @@ -35,6 +35,8 @@ along with GNU Modula-2; see the file COPYING3. If not see #include "m2type.h" #define m2linemap_c #include "m2linemap.h" +#include "m2color.h" +#include <string> static int inFile = FALSE; @@ -251,6 +253,128 @@ m2linemap_internal_error (const char *message) internal_error ("%s", message); } + +/* Code derived from rust. */ + +static std::string +mformat_value () +{ + return std::string (xstrerror (errno)); +} + + +static std::string +expand_format (const char *fmt) +{ + std::string result; + for (const char *c = fmt; *c; ++c) + { + if (*c != '%') + { + result += *c; + continue; + } + c++; + switch (*c) + { + case '\0': { + // malformed format string + gcc_unreachable (); + } + case '%': { + result += '%'; + break; + } + case 'm': { + result += mformat_value (); + break; + } + case '<': { + result += m2color_open_quote (); + break; + } + case '>': { + result += m2color_close_quote (); + break; + } + case 'q': { + result += m2color_open_quote (); + c++; + if (*c == 'm') + result += mformat_value (); + else + { + result += '%'; + result += *c; + } + result += m2color_close_quote (); + break; + } + default: { + result += '%'; + result += *c; + } + } + } + return result; +} + +static std::string +expand_message (const char *fmt, va_list ap) +{ + char *mbuf = 0; + std::string expanded_fmt = expand_format (fmt); + int nwr = vasprintf (&mbuf, expanded_fmt.c_str (), ap); + if (nwr == -1) + { + // memory allocation failed + error_at (UNKNOWN_LOCATION, + "memory allocation failed in vasprintf"); + gcc_assert (0); + } + std::string rval = std::string (mbuf); + free (mbuf); + return rval; +} + + +static void +gm2_internal_error_at (location_t location, const std::string &errmsg) +{ + expanded_location exp_loc = expand_location (location); + std::string loc_str; + std::string file_str; + + if (exp_loc.file == NULL) + file_str.clear (); + else + file_str = std::string (exp_loc.file); + + if (! file_str.empty ()) + { + loc_str += file_str; + loc_str += ':'; + loc_str += std::to_string (exp_loc.line); + loc_str += ':'; + loc_str += std::to_string (exp_loc.column); + } + if (loc_str.empty ()) + internal_error ("%s", errmsg.c_str ()); + else + internal_error ("at %s, %s", loc_str.c_str (), errmsg.c_str ()); +} + + +void +m2linemap_internal_error_at (location_t location, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + gm2_internal_error_at (location, expand_message (fmt, ap)); + va_end (ap); +} + /* UnknownLocation - return the predefined location representing an unknown location. */ |