Commit 46fa16ce authored by johnvg@science.ru.nl's avatar johnvg@science.ru.nl

Merge remote-tracking branch 'origin/master' into itask

parents 8f5cd120 b4e127f5
......@@ -115,7 +115,7 @@ NewTypeNode (Annotation annot, AttributeKind attr, SymbolP symb, TypeArgs args,
node->type_node_arity = arity;
if (arity > MaxNodeArity)
StaticMessage (True, "<type node>", "\"%S\" %s", symb, "Too many arguments (> 32)");
StaticErrorMessage_s_Ss ("<type node>", symb, " Too many arguments (> 32)");
#if 0
node->type_node_state.state_arity = 1;
node->type_node_state.state_kind = OnA;
......@@ -158,7 +158,7 @@ NewNodeByKind (NodeKind nodeKind, SymbolP symb, Args args, int arity)
node->node_arity = arity;
if (arity > MaxNodeArity)
StaticMessage (True, "<node>", "\"%S\" %s", symb, "Too many arguments (> 32)");
StaticErrorMessage_s_Ss ("<node>", symb, " Too many arguments (> 32)");
return (node);
} /* NewNodeByKind */
......
......@@ -72,7 +72,7 @@ static Parameters CalculateOffsetsOfParameters (Parameters params,States results
if (params)
params = CalculateOffsetsOfParameter (params,resultstates[arity],asp_p,bsp_p);
else {
StaticMessage (True,CurrentAltLabel.lab_symbol->sdef_name,ECodeBlock);
StaticMessage_s_s (True,CurrentAltLabel.lab_symbol->sdef_name,ECodeBlock);
break;
}
}
......@@ -118,7 +118,7 @@ static void GenCodeBlock (CodeBlock code, int asp, int bsp, StateS resultstate)
}
if (nextparam)
StaticMessage (True,CurrentAltLabel.lab_symbol->sdef_name, ECodeBlock);
StaticMessage_s_s (True,CurrentAltLabel.lab_symbol->sdef_name, ECodeBlock);
GenParameters (True, code->co_parin, asp, bsp);
GenInstructions (code->co_instr);
......@@ -963,7 +963,7 @@ static void CodeRule (ImpRuleP rule)
CurrentLine=rule->rule_alts->alt_line;
if (FunctionMayFailWarningOrError!=0)
StaticMessage (FunctionMayFailWarningOrError==2, "%S", "function may fail", CurrentSymbol);
StaticMessage_S_s (FunctionMayFailWarningOrError==2, CurrentSymbol, "function may fail");
MatchError (asize,bsize,rule_sdef,root_node_needed,0);
}
......@@ -1183,7 +1183,7 @@ void CodeGeneration (ImpMod imod, char *fname)
ImpRuleS *rule;
if (!OpenABCFile (fname)){
StaticMessage (True, "<open file>","Can't create abc file '%s'",fname);
StaticErrorMessage_s_ss ("<open file>","Can't create abc file: ",fname);
return;
}
......
......@@ -279,7 +279,7 @@ Coercions CoerceStateKind (StateKind dem_state_kind, StateKind off_state_kind)
if (dem_state_kind == OnA)
return AToA;
else
StaticMessage (False, "","parallel annotation in strict context ignored");
StaticMessage_s_s (False, "","parallel annotation in strict context ignored");
return Reduce;
case UnderEval:
if (dem_state_kind == OnA)
......@@ -333,7 +333,7 @@ Coercions CoerceSimpleStateArgument (StateS demstate,StateKind offkind,int ainde
break;
case CyclicSpine:
GenReduceError ();
StaticMessage (False,CurrentAltLabel.lab_symbol->sdef_name,Co_Wspine);
StaticMessage_s_s (False,CurrentAltLabel.lab_symbol->sdef_name,Co_Wspine);
*ontop = False;
break;
default:
......@@ -949,7 +949,7 @@ static void ReduceSemiStrictNodes (const NodeDefs nds,int asp)
GenJsrEval (asp - nd->def_id->nid_a_index);
break;
case Parallel:
StaticMessage (False, "","parallel annotation ignored(?)");
StaticMessage_s_s (False, "","parallel annotation ignored(?)");
break;
}
}
......@@ -3663,7 +3663,7 @@ static void FillNormalNode (Node node,int *asp_p,int *bsp_p,NodeId update_node_i
}
}
} else {
StaticMessage (False,CurrentAltLabel.lab_symbol->sdef_name,Co_Wtype);
StaticMessage_s_s (False,CurrentAltLabel.lab_symbol->sdef_name,Co_Wtype);
GenTypeError();
}
}
......
......@@ -214,7 +214,7 @@ void RedirectResultAndReturn (int asp,int bsp,int source_a_index,int source_b_in
break;
case CyclicSpine:
GenReduceError ();
StaticMessage (False,CurrentAltLabel.lab_symbol->sdef_name,Co_Wspine);
StaticMessage_s_s (False,CurrentAltLabel.lab_symbol->sdef_name,Co_Wspine);
break;
default:
error_in_function ("RedirectResultAndReturn");
......@@ -1027,7 +1027,7 @@ static void CodeNormalRootNode (Node root,NodeId rootid,int asp,int bsp,CodeGenN
case_def_s.sdef_name = rootsymb->symb_string;
if (FunctionMayFailWarningOrError!=0)
StaticMessage (FunctionMayFailWarningOrError==2, "%D", "case may fail", &case_def_s);
StaticMessage_D_s (FunctionMayFailWarningOrError==2, &case_def_s, "case may fail");
if (! (IsOnBStack (resultstate) ||
(IsSimpleState (resultstate) && resultstate.state_kind==StrictRedirection)))
......@@ -1110,7 +1110,7 @@ static void CodeNormalRootNode (Node root,NodeId rootid,int asp,int bsp,CodeGenN
GenRtn (1, 0, OnAState);
}
} else {
StaticMessage (False,CurrentAltLabel.lab_symbol->sdef_name,Co_Wtype);
StaticMessage_s_s (False,CurrentAltLabel.lab_symbol->sdef_name,Co_Wtype);
GenTypeError();
GenRtn (0, 0, OnAState);
}
......
......@@ -275,163 +275,145 @@ static char *FindFormatSpecifier (char * format_string)
for (; *format_string != '\0' && *format_string != '%'; format_string++)
;
return format_string;
}
#ifdef GNU_C
void StaticMessage (Bool error, char *symbol_format1, char *message_format1, ...)
void StaticMessage_D_s (Bool error,struct symbol_def *symb_def_p,char *message)
{
char *format, format_spec;
char symbol_format [256], message_format [256];
if (! (error || DoWarning))
return;
va_list ap;
strcpy (symbol_format, symbol_format1);
strcpy (message_format, message_format1);
FPutS (error ? "Error [" : "Warning [", StdError);
FPutS (CurrentModule, StdError);
if (CurrentLine > 0)
FPrintF (StdError, ",%u", CurrentLine);
FPutC (',', StdError);
PrintSymbolOfIdent (symb_def_p->sdef_name, 0, StdError);
FPutS ("]: ", StdError);
va_start (ap, message_format1);
FPutS (message, StdError);
#else
FPutC ('\n', StdError);
if (error)
CompilerError = True;
}
void StaticMessage (Bool error, char *symbol_format, char *message_format, ...)
void StaticMessage_S_s (Bool error,struct symbol *symbol_p,char *message)
{
char *format, format_spec;
if (! (error || DoWarning))
return;
va_list ap;
va_start (ap, message_format);
FPutS (error ? "Error [" : "Warning [", StdError);
FPutS (CurrentModule, StdError);
if (CurrentLine > 0)
FPrintF (StdError, ",%u", CurrentLine);
FPutC (',', StdError);
PrintSymbol (symbol_p, StdError);
FPutS ("]: ", StdError);
#endif
FPutS (message, StdError);
FPutC ('\n', StdError);
if (error)
CompilerError = True;
}
void StaticMessage_S_Ss (Bool error,struct symbol *symbol_p1,struct symbol *symbol_p2,char *message)
{
if (! (error || DoWarning))
return;
#ifdef MAKE_MPW_TOOL
FPutS ("### ",StdError);
#endif
FPutS (error ? "Error [" : "Warning [", StdError);
FPutS (CurrentModule, StdError);
if (CurrentLine > 0)
FPrintF (StdError, ",%u", CurrentLine);
FPutC (',', StdError);
PrintSymbol (symbol_p1, StdError);
FPutS ("]: ", StdError);
PrintSymbol (symbol_p2, StdError);
FPutS (message, StdError);
FPutC ('\n', StdError);
if (error)
CompilerError = True;
}
void StaticMessage_s_s (Bool error,char *symbol_s,char *message)
{
if (! (error || DoWarning))
return;
FPutS (error ? "Error [" : "Warning [", StdError);
FPutS (CurrentModule, StdError);
if (CurrentLine > 0)
FPrintF (StdError, ",%u", CurrentLine);
FPutC (',', StdError);
FPutS (symbol_s, StdError);
FPutS ("]: ", StdError);
#ifdef MAKE_MPW_TOOL
FPutS ("File ",StdError);
#endif
FPutS (message, StdError);
FPutC ('\n', StdError);
if (error)
CompilerError = True;
}
void StaticErrorMessage_S_ss (struct symbol *symbol_p,char *message1,char *message2)
{
FPutS ("Error [", StdError);
FPutS (CurrentModule, StdError);
if (CurrentLine > 0){
#ifdef MAKE_MPW_TOOL
FPrintF (StdError, "; Line %u", CurrentLine);
#else
if (CurrentLine > 0)
FPrintF (StdError, ",%u", CurrentLine);
#endif
}
FPutC (',', StdError);
PrintSymbol (symbol_p, StdError);
FPutS ("]: ", StdError);
#ifdef MAKE_MPW_TOOL
FPutS ("] ", StdError);
#else
FPutS (message1, StdError);
FPutS (message2, StdError);
FPutC ('\n', StdError);
CompilerError = True;
}
void StaticErrorMessage_s_Ss (char *symbol_s,struct symbol *symbol_p,char *message)
{
FPutS ("Error [", StdError);
FPutS (CurrentModule, StdError);
if (CurrentLine > 0)
FPrintF (StdError, ",%u", CurrentLine);
FPutC (',', StdError);
#endif
FPutS (symbol_s, StdError);
FPutS ("]: ", StdError);
for (format = symbol_format; ;)
{ char *tail_format = FindFormatSpecifier (format);
if (*tail_format == '\0')
{ FPutS (format, StdError);
break;
}
else
{ *tail_format = '\0';
FPutS (format, StdError);
*tail_format = '%';
format_spec = * (++tail_format);
if (format_spec == '\0')
{ FPutC ('%', StdError);
break;
}
else
{ switch (format_spec)
{
case 's':
{ char * message = va_arg (ap, char *);
if (message != NULL)
FPutS (message, StdError);
break;
}
case 'D':
{
SymbDef def = va_arg (ap, SymbDef);
PrintSymbolOfIdent (def->sdef_name, 0, StdError);
break;
}
case 'S':
PrintSymbol (va_arg (ap, Symbol), StdError);
break;
default:
FPutC ('%', StdError);
FPutC (format_spec, StdError);
break;
}
format = ++tail_format;
}
}
}
PrintSymbol (symbol_p, StdError);
FPutS (message, StdError);
#ifdef MAKE_MPW_TOOL
FPutS (": ", StdError);
#else
FPutC ('\n', StdError);
CompilerError = True;
}
void StaticErrorMessage_s_ss (char *symbol_s,char *message1,char *message2)
{
FPutS ("Error [", StdError);
FPutS (CurrentModule, StdError);
if (CurrentLine > 0)
FPrintF (StdError, ",%u", CurrentLine);
FPutC (',', StdError);
FPutS (symbol_s, StdError);
FPutS ("]: ", StdError);
#endif
for (format = message_format; ;)
{ char *tail_format = FindFormatSpecifier (format);
if (*tail_format == '\0')
{ FPutS (format, StdError);
break;
}
else
{ *tail_format = '\0';
FPutS (format, StdError);
*tail_format = '%';
format_spec = * (++tail_format);
if (format_spec == '\0')
{ FPutC ('%', StdError);
break;
}
else
{ switch (format_spec)
{
case 's':
{ char * message = va_arg (ap, char *);
if (message != NULL)
FPutS (message, StdError);
break;
}
case 'd':
{ int nr = va_arg (ap, int);
FPrintF (StdError, "%d", nr);
break;
}
case 'S':
PrintSymbol (va_arg (ap, Symbol), StdError);
break;
default:
FPutC ('%', StdError);
FPutC (format_spec, StdError);
break;
}
format = ++tail_format;
}
}
}
FPutS (message1, StdError);
FPutS (message2, StdError);
FPutC ('\n', StdError);
va_end (ap);
if (error)
CompilerError = True;
CompilerError = True;
}
static char Init[] = "Compiler initialization";
......
......@@ -13,7 +13,13 @@
#define MINIMUM(a,b) (((a)<(b)) ? (a) : (b))
#define MAXIMUM(a,b) (((a)>(b)) ? (a) : (b))
extern void StaticMessage (Bool error, char *symbol_format, char *message_format, ...);
extern void StaticMessage_D_s (Bool error,struct symbol_def *symb_def_p,char *message);
extern void StaticMessage_S_Ss (Bool error,struct symbol *symbol_p1,struct symbol *symbol_p2,char *message);
extern void StaticMessage_S_s (Bool error,struct symbol *symbol_p,char *message);
extern void StaticMessage_s_s (Bool error,char *symbol_s,char *message);
extern void StaticErrorMessage_S_ss (struct symbol *symbol_p,char *message1,char *message2);
extern void StaticErrorMessage_s_Ss (char *symbol_s,struct symbol *symbol_p,char *message);
extern void StaticErrorMessage_s_ss (char *symbol_s,char *message1,char *message2);
struct symbol;
extern void PrintSymbol (struct symbol *symbol,File file);
......
......@@ -128,7 +128,7 @@ void CloseABCFile (char *fname)
CompilerError = True;
CurrentLine = 0;
StaticMessage (True, "<open file>", "Write error (disk full?)");
StaticMessage_s_s (True, "<open file>", "Write error (disk full?)");
}
if (CompilerError)
FDelete (fname);
......
/*
File: pattern_match.c
Author: John van Groningen
*/
#define DEBUG_OUTPUT 0
#if defined (applec) || defined (__MWERKS__) || defined (__MRC__)
# define __ppc__
#endif
#include <stdio.h>
#include "compiledefines.h"
#include "types.t"
#include "syntaxtr.t"
#include "pattern_match.h"
#include "buildtree.h"
#include "comsupport.h"
#include "statesgen.h"
#include "settings.h"
#include "codegen_types.h"
#define for_l(v,l,n) for(v=(l);v!=NULL;v=v->n)
static void error_in_function (char *m)
{
ErrorInCompiler ("",m,"");
}
#if DEBUG_OUTPUT
char *node_id_name (NodeId node_id)
{
static char node_id_name_s[65];
if (node_id->nid_ident!=NULL && node_id->nid_ident->ident_name!=NULL)
return node_id->nid_ident->ident_name;
else {
sprintf (node_id_name_s,"i_%lx",(long)node_id);
return node_id_name_s;
}
}
#endif
static NodeP new_switch_node (NodeIdP node_id,NodeP case_node,StateP state_p,NodeS ***root_l)
{
NodeP switch_node;
switch_node=CompAllocType (NodeS);
switch_node->node_kind=SwitchNode;
switch_node->node_node_id=node_id;
switch_node->node_arity=1;
switch_node->node_arguments=NewArgument (case_node);
switch_node->node_state=*state_p;
#if DEBUG_OUTPUT
printf ("dec %s %d\n",node_id_name (node_id),node_id->nid_refcount);
#endif
--node_id->nid_refcount;
**root_l=switch_node;
*root_l=&case_node->node_arguments->arg_node;
return switch_node;
}
static NodeP new_case_node (SymbolP symbol,int symbol_arity,NodeP node,NodeDefP **def_l
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
,StrictNodeIdP **strict_node_ids_l
#endif
)
{
NodeP case_node;
case_node=CompAllocType (NodeS);
case_node->node_kind=CaseNode;
case_node->node_symbol=symbol;
case_node->node_arity=symbol_arity;
case_node->node_arguments=NewArgument (node);
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
case_node->node_su.su_u.u_case=CompAllocType (CaseNodeContentsS);
case_node->node_strict_node_ids=NULL;
#endif
case_node->node_node_id_ref_counts=NULL;
case_node->node_node_defs=**def_l;
**def_l=NULL;
*def_l=&case_node->node_node_defs;
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
case_node->node_strict_node_ids=**strict_node_ids_l;
**strict_node_ids_l=NULL;
*strict_node_ids_l=&case_node->node_strict_node_ids;
#endif
return case_node;
}
struct root_and_defs_l {
NodeP ** root_l;
NodeDefP ** def_l;
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
StrictNodeIdP **strict_node_ids_l;
NodeDefP ** end_lhs_defs_l;
#endif
};
struct root_and_defs {
NodeP root;
NodeDefP defs;
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
StrictNodeIdP strict_node_ids;
#endif
};
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
static void add_new_lhs_node_id_to_lhs_node_defs (NodeIdP node_id_p,struct root_and_defs_l *root_and_defs_lp)
{
NodeDefP new_node_def_p;
new_node_def_p=CompAllocType (NodeDefS);
new_node_def_p->def_id=node_id_p;
new_node_def_p->def_mark=0;
new_node_def_p->def_node=node_id_p->nid_node;
**root_and_defs_lp->end_lhs_defs_l=new_node_def_p;
*root_and_defs_lp->end_lhs_defs_l=&new_node_def_p->def_next;
}
#endif
static NodeP new_switch_and_case_node (NodeIdP node_id,StateP state_p,SymbolP symbol,int symbol_arity,struct root_and_defs_l *root_and_defs_lp)
{
NodeP case_node_p;
case_node_p=new_case_node (symbol,symbol_arity,**root_and_defs_lp->root_l,root_and_defs_lp->def_l
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
,root_and_defs_lp->strict_node_ids_l
#endif
);
return new_switch_node (node_id,case_node_p,state_p,root_and_defs_lp->root_l);
}
static NodeP new_default_node (NodeP node,NodeDefP node_defs
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
,StrictNodeIdP strict_node_ids
#endif
)
{
NodeP default_node;
default_node=CompAllocType (NodeS);
default_node->node_kind=DefaultNode;
default_node->node_node_defs=node_defs;
default_node->node_arity=1;
default_node->node_arguments=NewArgument (node);
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
default_node->node_su.su_u.u_case=CompAllocType (CaseNodeContentsS);
default_node->node_strict_node_ids=strict_node_ids;
#endif
default_node->node_node_id_ref_counts=NULL;
return default_node;
}
static NodeP new_push_node (Symbol symbol,int arity,ArgP arguments)
{
NodeP push_node;
push_node=CompAllocType (NodeS);
push_node->node_kind=PushNode;
push_node->node_arity=arity;
push_node->node_arguments=arguments;
push_node->node_record_symbol=symbol;
push_node->node_number=0; /* if !=0 then unique */
return push_node;
}
static NodeP new_guard_node (NodeP if_node,NodeP node,NodeDefP node_defs
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
,StrictNodeIdP strict_node_ids
#endif
)
{
NodeP guard_node;
ArgP arg1,arg2;
guard_node=CompAllocType (NodeS);
guard_node->node_kind=GuardNode;
guard_node->node_node_defs=node_defs;
guard_node->node_arity=2;
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
guard_node->node_guard_strict_node_ids=strict_node_ids;
#endif
arg1=NewArgument (if_node);
arg2=NewArgument (node);
guard_node->node_arguments=arg1;
arg1->arg_next=arg2;