Commit 52b60345 authored by Artem Shinkarov's avatar Artem Shinkarov
Browse files

Merge branch 'adjust-locations'

parents 5d72b610 9571a622
#ifndef _SAC_SERIALIZE_H_
#define _SAC_SERIALIZE_H_
#include <stdlib.h>
#ifndef NULL
#define NULL ((void *)0)
#endif
/* FIXME Why the hell this file is not auto-generated? */
extern void *SHLPmakeNode (int ntype, int lineno, char *sfile, ...);
extern void *SHLPmakeNode (int ntype, char *sfile, size_t lineno, size_t col, ...);
extern void *SHLPfixLink (void *stack, int a, int b, int c);
extern void *COdeserializeConstant (int type, void *shp, int vlen, char *vec);
extern void *SHcreateShape (int dim, ...);
......
......@@ -898,7 +898,7 @@ IDCaddFunConstraint (node *expr)
avis = FindAvisOfLastDefinition (args);
if (avis == NULL) {
CTIwarnLine (NODE_LINE (expr), "illegal requirement ignored!");
CTIwarnLoc (NODE_LOCATION (expr), "illegal requirement ignored!");
res = NULL;
} else {
res = TBmakeAvis (TRAVtmpVarName ("pred"),
......
......@@ -343,16 +343,16 @@ CheckBounds (node *arg_node, shape *max_shp)
tnum = SHgetExtent (max_shp, dim);
if (lbnum < 0) {
NUM_VAL (EXPRS_EXPR (lbe)) = 0;
CTIerrorLine (NODE_LINE (arg_node),
"Lower bound of WL-generator in dim %d below zero: %d", dim,
lbnum);
CTIerrorLoc (NODE_LOCATION (arg_node),
"Lower bound of WL-generator in dim %d below zero: %d", dim,
lbnum);
}
if (ubnum > tnum) {
NUM_VAL (EXPRS_EXPR (ube)) = tnum;
CTIerrorLine (NODE_LINE (arg_node),
"Upper bound of WL-generator in dim %d greater than shape %d: "
"%d",
dim, tnum, ubnum);
CTIerrorLoc (NODE_LOCATION (arg_node),
"Upper bound of WL-generator in dim %d greater than shape %d: "
"%d",
dim, tnum, ubnum);
}
dim++;
......@@ -475,16 +475,16 @@ CropBounds (node *wl, shape *max_shp)
tnum = SHgetExtent (max_shp, dim);
if (lbnum < 0) {
NUM_VAL (EXPRS_EXPR (lbe)) = 0;
CTIerrorLine (NODE_LINE (wl),
"Lower bound of WL-generator in dim %d below zero: %d", dim,
lbnum);
CTIerrorLoc (NODE_LOCATION (wl),
"Lower bound of WL-generator in dim %d below zero: %d", dim,
lbnum);
}
if (ubnum > tnum) {
NUM_VAL (EXPRS_EXPR (ube)) = tnum;
CTIerrorLine (NODE_LINE (wl),
"Upper bound of WL-generator in dim %d greater than shape %d: "
"%d",
dim, tnum, ubnum);
CTIerrorLoc (NODE_LOCATION (wl),
"Upper bound of WL-generator in dim %d greater than shape %d: "
"%d",
dim, tnum, ubnum);
}
dim++;
......
......@@ -114,8 +114,8 @@ ErrorOnSpawnInExport (node *fundef, node *let)
{
DBUG_ENTER ();
CTIerrorLine (NODE_LINE (let), "Spawn found in exported function %s",
FUNDEF_NAME (fundef));
CTIerrorLoc (NODE_LOCATION (let), "Spawn found in exported function %s",
FUNDEF_NAME (fundef));
CTIerrorContinued ("Not allowed, create a wrapper function to resolve this");
DBUG_RETURN ();
......
......@@ -464,21 +464,21 @@ CSGDarg (node *arg_node, info *arg_info)
*/
if (!PolymorphicTypeComplies (ARG_NTYPE (INFO_CURRENT (arg_info)),
ARG_NTYPE (arg_node))) {
CTIerrorLine (NODE_LINE (INFO_CURRENT (arg_info)),
"In definition of %s: type and shape variables cannot be "
"mixed (in arguments %s and %s).",
CTIitemName (INFO_FUNDEF (arg_info)),
ARG_NAME (INFO_CURRENT (arg_info)), ARG_NAME (arg_node));
CTIerrorLoc (NODE_LOCATION (INFO_CURRENT (arg_info)),
"In definition of %s: type and shape variables cannot be "
"mixed (in arguments %s and %s).",
CTIitemName (INFO_FUNDEF (arg_info)),
ARG_NAME (INFO_CURRENT (arg_info)), ARG_NAME (arg_node));
}
break;
case CSGD_checkret:
if (!PolymorphicTypeComplies (RET_TYPE (INFO_CURRENT (arg_info)),
ARG_NTYPE (arg_node))) {
CTIerrorLine (NODE_LINE (INFO_CURRENT (arg_info)),
"In definition of %s: type and shape variables cannot be "
"mixed (in return type %d and argument %s).",
CTIitemName (INFO_FUNDEF (arg_info)), INFO_RETNO (arg_info),
ARG_NAME (arg_node));
CTIerrorLoc (NODE_LOCATION (INFO_CURRENT (arg_info)),
"In definition of %s: type and shape variables cannot be "
"mixed (in return type %d and argument %s).",
CTIitemName (INFO_FUNDEF (arg_info)), INFO_RETNO (arg_info),
ARG_NAME (arg_node));
}
arg_info = AnnotateDefinedVars (RET_TYPE (INFO_CURRENT (arg_info)),
......@@ -487,10 +487,10 @@ CSGDarg (node *arg_node, info *arg_info)
case CSGD_checkcast:
if (!PolymorphicTypeComplies (CAST_NTYPE (INFO_CURRENT (arg_info)),
ARG_NTYPE (arg_node))) {
CTIerrorLine (NODE_LINE (INFO_CURRENT (arg_info)),
"In definition of %s: type and shape variables cannot be "
"mixed (in cast type and argument %s).",
CTIitemName (INFO_FUNDEF (arg_info)), ARG_NAME (arg_node));
CTIerrorLoc (NODE_LOCATION (INFO_CURRENT (arg_info)),
"In definition of %s: type and shape variables cannot be "
"mixed (in cast type and argument %s).",
CTIitemName (INFO_FUNDEF (arg_info)), ARG_NAME (arg_node));
}
arg_info = AnnotateDefinedVars (CAST_NTYPE (INFO_CURRENT (arg_info)),
......@@ -499,12 +499,12 @@ CSGDarg (node *arg_node, info *arg_info)
case CSGD_checkavis:
if (!PolymorphicTypeComplies (AVIS_TYPE (INFO_CURRENT (arg_info)),
ARG_NTYPE (arg_node))) {
CTIerrorLine (NODE_LINE (INFO_CURRENT (arg_info)),
"In definition of %s: type and shape variables cannot be "
"mixed (in declared type of local variable %s and "
"argument %s).",
CTIitemName (INFO_FUNDEF (arg_info)),
AVIS_NAME (INFO_CURRENT (arg_info)), ARG_NAME (arg_node));
CTIerrorLoc (NODE_LOCATION (INFO_CURRENT (arg_info)),
"In definition of %s: type and shape variables cannot be "
"mixed (in declared type of local variable %s and "
"argument %s).",
CTIitemName (INFO_FUNDEF (arg_info)),
AVIS_NAME (INFO_CURRENT (arg_info)), ARG_NAME (arg_node));
}
arg_info = AnnotateDefinedVars (AVIS_TYPE (INFO_CURRENT (arg_info)),
......@@ -588,31 +588,30 @@ CSGDret (node *arg_node, info *arg_info)
}
if (!INFO_OUTERDEFINED (arg_info)) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Type variable in polymorphic return "
"type not bound by any argument (return value %d).",
CTIitemName (INFO_FUNDEF (arg_info)),
INFO_RETNO (arg_info));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Type variable in polymorphic return "
"type not bound by any argument (return value %d).",
CTIitemName (INFO_FUNDEF (arg_info)), INFO_RETNO (arg_info));
}
if (TYisPolyUser (TYgetScalar (RET_TYPE (arg_node)))) {
if (!INFO_INNERDEFINED (arg_info)) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Inner type variable in "
"polymorphic "
"return type not bound by any argument (return value "
"%d).",
CTIitemName (INFO_FUNDEF (arg_info)),
INFO_RETNO (arg_info));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Inner type variable in "
"polymorphic "
"return type not bound by any argument (return value "
"%d).",
CTIitemName (INFO_FUNDEF (arg_info)),
INFO_RETNO (arg_info));
}
if (!INFO_SHAPEDEFINED (arg_info)) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Shape variable in polymorphic "
"return "
"type not bound by any argument (return value %d).",
CTIitemName (INFO_FUNDEF (arg_info)),
INFO_RETNO (arg_info));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Shape variable in polymorphic "
"return "
"type not bound by any argument (return value %d).",
CTIitemName (INFO_FUNDEF (arg_info)),
INFO_RETNO (arg_info));
}
}
......@@ -685,39 +684,39 @@ CSGDcast (node *arg_node, info *arg_info)
}
if (!INFO_OUTERDEFINED (arg_info)) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Type variable in polymorphic cast "
"type not bound by any argument.",
CTIitemName (INFO_FUNDEF (arg_info)));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Type variable in polymorphic cast "
"type not bound by any argument.",
CTIitemName (INFO_FUNDEF (arg_info)));
}
if (TYisPolyUser (TYgetScalar (CAST_NTYPE (arg_node)))) {
if (!INFO_INNERDEFINED (arg_info)) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Inner type variable in polymorphic "
"cast type not bound by any argument.",
CTIitemName (INFO_FUNDEF (arg_info)));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Inner type variable in polymorphic "
"cast type not bound by any argument.",
CTIitemName (INFO_FUNDEF (arg_info)));
}
if (!INFO_SHAPEDEFINED (arg_info)) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Shape variable in polymorphic cast "
"type not bound by any argument.",
CTIitemName (INFO_FUNDEF (arg_info)));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Shape variable in polymorphic cast "
"type not bound by any argument.",
CTIitemName (INFO_FUNDEF (arg_info)));
}
if (TYgetPolyUserDeNest (TYgetScalar (CAST_NTYPE (arg_node)))) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Implicit denesting of polymorphic "
"user type not allowed in cast expressions.",
CTIitemName (INFO_FUNDEF (arg_info)));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Implicit denesting of polymorphic "
"user type not allowed in cast expressions.",
CTIitemName (INFO_FUNDEF (arg_info)));
}
if (TYgetPolyUserReNest (TYgetScalar (CAST_NTYPE (arg_node)))) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Implicit renesting of polymorphic "
"user type not allowed in cast expressions.",
CTIitemName (INFO_FUNDEF (arg_info)));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Implicit renesting of polymorphic "
"user type not allowed in cast expressions.",
CTIitemName (INFO_FUNDEF (arg_info)));
}
}
......@@ -753,43 +752,41 @@ CSGDavis (node *arg_node, info *arg_info)
}
if (!INFO_OUTERDEFINED (arg_info)) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Type variable in polymorphic cast "
"type not bound by any argument.",
CTIitemName (INFO_FUNDEF (arg_info)));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Type variable in polymorphic cast "
"type not bound by any argument.",
CTIitemName (INFO_FUNDEF (arg_info)));
}
if (TYisPolyUser (TYgetScalar (AVIS_TYPE (arg_node)))) {
if (!INFO_INNERDEFINED (arg_info)) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Inner type variable in polymorphic "
"type of local variable %s not bound by any argument.",
CTIitemName (INFO_FUNDEF (arg_info)), AVIS_NAME (arg_node));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Inner type variable in polymorphic "
"type of local variable %s not bound by any argument.",
CTIitemName (INFO_FUNDEF (arg_info)), AVIS_NAME (arg_node));
}
if (!INFO_SHAPEDEFINED (arg_info)) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Shape variable in polymorphic type "
"of local variable %s not bound by any argument.",
CTIitemName (INFO_FUNDEF (arg_info)), AVIS_NAME (arg_node));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Shape variable in polymorphic type "
"of local variable %s not bound by any argument.",
CTIitemName (INFO_FUNDEF (arg_info)), AVIS_NAME (arg_node));
}
if (TYgetPolyUserDeNest (TYgetScalar (AVIS_TYPE (arg_node)))) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Implicit denesting of polymorphic "
"user "
"type not allowed in type declaration of local variable "
"%s.",
CTIitemName (INFO_FUNDEF (arg_info)), AVIS_NAME (arg_node));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Implicit denesting of polymorphic "
"user "
"type not allowed in type declaration of local variable %s.",
CTIitemName (INFO_FUNDEF (arg_info)), AVIS_NAME (arg_node));
}
if (TYgetPolyUserReNest (TYgetScalar (AVIS_TYPE (arg_node)))) {
CTIerrorLine (NODE_LINE (arg_node),
"In definition of %s: Implicit renesting of polymorphic "
"user "
"type not allowed in type declaration of local variable "
"%s.",
CTIitemName (INFO_FUNDEF (arg_info)), AVIS_NAME (arg_node));
CTIerrorLoc (NODE_LOCATION (arg_node),
"In definition of %s: Implicit renesting of polymorphic "
"user "
"type not allowed in type declaration of local variable %s.",
CTIitemName (INFO_FUNDEF (arg_info)), AVIS_NAME (arg_node));
}
}
}
......
......@@ -69,9 +69,9 @@ static char *message_buffer = NULL;
static int message_buffer_size = 0;
static int message_line_length = 76;
static char *abort_message_header = "ABORT: ";
static char *error_message_header = "ERROR: ";
static char *warn_message_header = "WARNING: ";
static char *abort_message_header = "abort: ";
static char *error_message_header = "error: ";
static char *warn_message_header = "warning: ";
static char *state_message_header = "";
static char *note_message_header = " ";
......@@ -80,6 +80,12 @@ static int warnings = 0;
#define MAX_ITEM_NAME_LENGTH 255
int
CTIgetErrorCount (void)
{
return errors;
}
/** <!--********************************************************************-->
*
* @fn void ProcessMessage( char *buffer, int line_length)
......@@ -256,7 +262,7 @@ static void
PrintMessage (const char *header, const char *format, va_list arg_p)
{
char *line;
;
DBUG_ENTER ();
Format2Buffer (format, arg_p);
......@@ -355,10 +361,15 @@ AbortCompilation (void)
CleanUp ();
fprintf (stderr, "\n*** Compilation failed ***\n");
fprintf (stderr, "*** Exit code %d (%s)\n", ecode,
PHIphaseText (global.compiler_phase));
fprintf (stderr, "*** %d Error(s), %d Warning(s)\n\n", errors, warnings);
(void)fprintf (stderr, "compilation failed while %s",
PHIphaseText (global.compiler_phase));
if (errors > 0)
(void)fprintf (stderr, ", %d error(s)", errors);
if (warnings > 0)
(void)fprintf (stderr, ", %d warning(s)", warnings);
(void)fprintf (stderr, ".\n");
exit (ecode);
......@@ -599,7 +610,6 @@ CTIerror (const char *format, ...)
va_start (arg_p, format);
fprintf (stderr, "\n");
PrintMessage (error_message_header, format, arg_p);
va_end (arg_p);
......@@ -630,9 +640,7 @@ CTIerrorLine (int line, const char *format, ...)
va_start (arg_p, format);
fprintf (stderr, "\n");
fprintf (stderr, "%sline %d file: %s\n", error_message_header, line,
global.filename);
fprintf (stderr, "%s %d ", global.filename, line);
PrintMessage (error_message_header, format, arg_p);
va_end (arg_p);
......@@ -642,6 +650,60 @@ CTIerrorLine (int line, const char *format, ...)
DBUG_RETURN ();
}
void
CTIerrorLoc (struct location loc, const char *format, ...)
{
va_list arg_p;
DBUG_ENTER ();
va_start (arg_p, format);
(void)fprintf (stderr, "%s ", loc.fname);
if (loc.line == 0)
(void)fprintf (stderr, "??");
else
(void)fprintf (stderr, "%zd", loc.line);
if (loc.col > 0)
(void)fprintf (stderr, ":%zd ", loc.col);
else
(void)fprintf (stderr, " ");
PrintMessage (error_message_header, format, arg_p);
va_end (arg_p);
errors++;
DBUG_RETURN ();
}
void
CTIwarnLoc (struct location loc, const char *format, ...)
{
va_list arg_p;
DBUG_ENTER ();
va_start (arg_p, format);
(void)fprintf (stderr, "%s ", loc.fname);
if (loc.line == 0)
(void)fprintf (stderr, "??");
else
(void)fprintf (stderr, "%zd", loc.line);
if (loc.col > 0)
(void)fprintf (stderr, ":%zd ", loc.col);
else
(void)fprintf (stderr, " ");
PrintMessage (error_message_header, format, arg_p);
va_end (arg_p);
warnings++;
DBUG_RETURN ();
}
/** <!--********************************************************************-->
*
* @fn void CTIerrorLineVA( int line, const char *format, va_list arg_p)
......@@ -659,9 +721,7 @@ CTIerrorLineVA (int line, const char *format, va_list arg_p)
{
DBUG_ENTER ();
fprintf (stderr, "\n");
fprintf (stderr, "%sline %d file: %s\n", error_message_header, line,
global.filename);
fprintf (stderr, "%s %d ", global.filename, line);
PrintMessage (error_message_header, format, arg_p);
errors++;
......@@ -712,7 +772,7 @@ CTIerrorInternal (const char *format, ...)
DBUG_ENTER ();
fprintf (stderr, "\n%sInternal %s failure\n", error_message_header, global.toolname);
fprintf (stderr, "%sInternal %s failure\n", error_message_header, global.toolname);
va_start (arg_p, format);
PrintMessage (error_message_header, format, arg_p);
......@@ -778,8 +838,6 @@ CTIabortOnBottom (char *err_msg)
line = strtok (NULL, "@");
}
errors++;
AbortCompilation ();
DBUG_RETURN ();
......@@ -805,13 +863,10 @@ CTIabort (const char *format, ...)
va_start (arg_p, format);
fprintf (stderr, "\n");
PrintMessage (abort_message_header, format, arg_p);
va_end (arg_p);
errors++;
AbortCompilation ();
DBUG_RETURN ();
......@@ -838,15 +893,11 @@ CTIabortLine (int line, const char *format, ...)
va_start (arg_p, format);
fprintf (stderr, "\n");
fprintf (stderr, "%sline %d file: %s\n", abort_message_header, line,
global.filename);
fprintf (stderr, "%s %d ", global.filename, line);
PrintMessage (abort_message_header, format, arg_p);
va_end (arg_p);
errors++;
AbortCompilation ();
DBUG_RETURN ();
......@@ -876,7 +927,6 @@ CTIabortOutOfMemory (unsigned int request)
DBUG_ENTER ();
fprintf (stderr,
"\n"
"%sOut of memory:\n"
"%s %u bytes requested\n",
abort_message_header, abort_message_header, request);
......@@ -884,8 +934,6 @@ CTIabortOutOfMemory (unsigned int request)
fprintf (stderr, "%s %u bytes already allocated\n", abort_message_header,
global.current_allocated_mem);
errors++;
AbortCompilation ();
DBUG_RETURN ();
......@@ -932,8 +980,7 @@ CTIwarnLine (int line, const char *format, ...)
if (global.verbose_level >= 1) {
va_start (arg_p, format);
fprintf (stderr, "%sline %d file: %s\n", warn_message_header, line,
global.filename);
fprintf (stderr, "%s %d ", global.filename, line);
PrintMessage (warn_message_header, format, arg_p);
va_end (arg_p);
......@@ -1094,8 +1141,7 @@ CTInoteLine (int line, const char *format, ...)
if (global.verbose_level >= 3) {
va_start (arg_p, format);
fprintf (stderr, "%sline %d file: %s\n", note_message_header, line,
global.filename);
fprintf (stderr, "%s %d ", global.filename, line);
PrintMessage (note_message_header, format, arg_p);
va_end (arg_p);
......
......@@ -12,11 +12,13 @@
#include "types.h"
#include <stdarg.h>
extern int CTIgetErrorCount (void);
extern void CTIexit (int);
extern void CTIinstallInterruptHandlers (void);
extern char *CTIgetErrorMessageVA (int line, const char *file, const char *format,
va_list arg_p);
extern void CTIerror (const char *format, ...);
extern void CTIerrorLoc (struct location loc, const char *format, ...);
extern void CTIerrorLine (int line, const char *format, ...);
extern void CTIerrorContinued (const char *format, ...);
extern void CTIerrorInternal (const char *format, ...);
......@@ -27,6 +29,7 @@ extern void CTIabortLine (int line, const char *format, ...);
extern void CTIabortOutOfMemory (unsigned int request);
extern void CTIabortOnError (void);
extern void CTIwarn (const char *format, ...);
extern void CTIwarnLoc (struct location loc, const char *format, ...);
extern void CTIwarnLine (int line, const char *format, ...);
extern void CTIwarnContinued (const char *format, ...);
extern int CTIgetWarnMessageLineLength (void);
......
......@@ -15,6 +15,19 @@
#include "config.h"
/* The source file of sac program can come from various files due to
recognition of #line directives. Usually massively used by preprocessor.
Every token keeps a pointer to the file name. In order to share file names
we keep a table of file names we've seen so far. The table is just a dynamic
array with size attached.
Currently such a simple format suffises, as the lexer keeps file names in the
hash table, and on exit it dumps the list to this table. We do not search over
this table and we do not support multiple file compilation, which means that one
global table would work. */
GLOBAL (size_t, file_table_size, 0, xfree_dummy, )
GLOBAL (char **, file_table, NULL, xfree_char_ptr_ptr, , global.file_table_size)
/*
* Memory allocation
*/
......
......@@ -135,12 +135,12 @@ CheckImportNameClash (const char *symbol, const char *module, sttable_t *table)
}
static void
CheckLocalNameClash (const char *symbol, sttable_t *table, int lineno)
CheckLocalNameClash (const char *symbol, sttable_t *table, struct location loc)
{