2 * Infix operator stuff -- modified from LML
8 #include "hsparser.tab.h"
19 } infixtab[MAX_INFIX];
21 static int ninfix = 0;
24 makeinfix(opid, fixity, precedence, modid, imported,
25 withas, impmodid, impasid, withqual,
26 withspec, withhiding, importspec)
28 int fixity, precedence;
29 long imported, withas, withqual, withspec, withhiding;
30 id modid, impmodid, impasid;
33 ToDo: Throw away infix operator if hidden by importspec!
37 char *op = id_to_string(opid);
38 char *mod = id_to_string(imported ? (withas ? impasid : impmodid) : modid);
39 short thismod = ! imported;
40 short unqualok = ! (imported && withqual);
42 for(i=0; i < ninfix; ++i)
44 if(strcmp(op,infixtab[i].iop)==0 &&
45 strcmp(mod,infixtab[i].imod)==0 &&
46 unqualok==infixtab[i].unqualok)
48 /* Allow duplicate definitions if they are identical */
49 if (infixtab[i].ifixity==fixity &&
50 infixtab[i].iprecedence==precedence)
55 /* Allow local definition to override an import */
56 else if(thismod && !infixtab[i].thismod)
63 char errbuf[ERR_BUF_SIZE];
64 sprintf(errbuf,"%s.%s %s already declared to be %s %d\n",
65 mod, op, unqualok ? "(unqualified)" : "(qualified)",
66 infixstr(infixtab[i].ifixity),
67 infixtab[i].iprecedence);
73 if (ninfix >= MAX_INFIX) {
74 char errbuf[ERR_BUF_SIZE];
75 sprintf(errbuf,"Too many Infix identifiers (> %d)",MAX_INFIX);
80 fprintf(stderr,"makeinfix: %s.%s, fixity=%d prec=%d\n",mod,op,infixint(fixity),precedence);
82 infixtab[ninfix].imod = mod;
83 infixtab[ninfix].iop = op;
84 infixtab[ninfix].thismod = thismod;
85 infixtab[ninfix].unqualok = unqualok;
86 infixtab[ninfix].ifixity = fixity;
87 infixtab[ninfix].iprecedence = precedence;
96 struct infix *found = NULL;
97 char *op = qid_to_string(name);
98 char *mod = qid_to_mod(name);
99 short unqual = mod == NULL;
101 for(i = 0; i < ninfix; i++)
103 if(strcmp(op,infixtab[i].iop)==0 &&
104 ( (unqual && infixtab[i].unqualok) ||
105 (!unqual && strcmp(mod,infixtab[i].imod)==0)
113 else if (found && ! found->thismod && infixtab[i].thismod)
115 /* new find for this module; overrides */
118 else if (found && found->thismod && ! infixtab[i].thismod)
120 /* prev find for this module */
122 else if (found->ifixity == infixtab[i].ifixity &&
123 found->iprecedence == infixtab[i].iprecedence)
125 /* finds are identical */
129 char errbuf[ERR_BUF_SIZE];
130 sprintf(errbuf,"conflicting infix declarations for %s.%s\n %s.%s %s (%s,%d) and %s.%s %s (%s,%d)\n",
131 qid_to_pmod(name), op,
132 found->imod, found->iop, found->unqualok ? "(unqualified)" : "(qualified)",
133 infixstr(found->ifixity),found->iprecedence,
134 infixtab[i].imod, infixtab[i].iop, infixtab[i].unqualok ? "(unqualified)" : "(qualified)",
135 infixstr(infixtab[i].ifixity),infixtab[i].iprecedence);
143 fprintf(stderr,"infixlookup: %s.%s = fixity=%d prec=%d\n",qid_to_pmod(name),op,infixint(pfixity(found)),pprecedence(found));
153 return(ip == NULL? INFIXL: ip->ifixity);
160 return(ip == NULL? 9: ip->iprecedence);
178 hsperror("infixstr");
197 hsperror("infixint");