Fixed some problems, and improved range-checking
This commit is contained in:
parent
98e6c244da
commit
d80b501829
|
@ -1 +1 @@
|
|||
static char Version[] = "ACK Modula-2 compiler Version 0.22";
|
||||
static char Version[] = "ACK Modula-2 compiler Version 0.23";
|
||||
|
|
|
@ -232,17 +232,16 @@ AddCases(sh, node, lbl)
|
|||
{
|
||||
/* Add case labels to the case label list
|
||||
*/
|
||||
register arith v1, v2;
|
||||
|
||||
if (node->nd_class == Link) {
|
||||
if (node->nd_symb == UPTO) {
|
||||
assert(node->nd_left->nd_class == Value);
|
||||
assert(node->nd_right->nd_class == Value);
|
||||
|
||||
v2 = node->nd_right->nd_INT;
|
||||
node->nd_type = node->nd_left->nd_type;
|
||||
for (v1 = node->nd_left->nd_INT; v1 <= v2; v1++) {
|
||||
node->nd_INT = v1;
|
||||
for (node->nd_INT = node->nd_left->nd_INT;
|
||||
node->nd_INT != node->nd_right->nd_INT;
|
||||
node->nd_INT++) {
|
||||
if (! AddOneCase(sh, node, lbl)) return 0;
|
||||
}
|
||||
return 1;
|
||||
|
|
|
@ -536,6 +536,7 @@ CodeStd(nd)
|
|||
size = left->nd_type->tp_size;
|
||||
if (size < word_size) size = word_size;
|
||||
CodePExpr(left);
|
||||
CodeCoercion(left->nd_type, tp);
|
||||
if (arg) {
|
||||
CodePExpr(arg->nd_left);
|
||||
CodeCoercion(arg->nd_left->nd_type, tp);
|
||||
|
|
|
@ -403,12 +403,21 @@ CaseLabels(t_type **ptp; register t_node **pnd;)
|
|||
nd = *pnd;
|
||||
}
|
||||
[
|
||||
UPTO { *pnd = dot2node(Link,nd,NULLNODE); }
|
||||
UPTO { *pnd = nd = dot2node(Link,nd,NULLNODE);
|
||||
nd->nd_type = nd->nd_left->nd_type;
|
||||
}
|
||||
ConstExpression(&(*pnd)->nd_right)
|
||||
{ if (!ChkCompat(&((*pnd)->nd_right), nd->nd_type,
|
||||
"case label")) {
|
||||
nd->nd_type = error_type;
|
||||
}
|
||||
else if (! chk_bounds(nd->nd_left->nd_INT,
|
||||
nd->nd_right->nd_INT,
|
||||
BaseType(nd->nd_type)->tp_fund)) {
|
||||
node_error(nd,
|
||||
"lower bound exceeds upper bound in case label range");
|
||||
}
|
||||
|
||||
}
|
||||
]?
|
||||
{
|
||||
|
|
|
@ -98,10 +98,9 @@ struct def { /* list of definitions for a name */
|
|||
#define D_ERROR 0x4000 /* a compiler generated definition for an
|
||||
undefined variable
|
||||
*/
|
||||
#define D_IMP_BY_EXP 0x8000 /* imported definition by export */
|
||||
#define D_VALUE (D_PROCEDURE|D_VARIABLE|D_FIELD|D_ENUM|D_CONST|D_PROCHEAD)
|
||||
#define D_ISTYPE (D_HIDDEN|D_TYPE|D_FTYPE)
|
||||
#define D_IMPORTED (D_IMPORT|D_IMP_BY_EXP)
|
||||
#define D_IMPORTED (D_IMPORT)
|
||||
#define is_type(dfx) ((dfx)->df_kind & D_ISTYPE)
|
||||
unsigned short df_flags;
|
||||
#define D_NOREG 0x01 /* set if it may not reside in a register */
|
||||
|
@ -115,6 +114,7 @@ struct def { /* list of definitions for a name */
|
|||
#define D_FOREIGN 0x100 /* set for foreign language modules */
|
||||
#define D_ADDRGIVEN 0x200 /* set if address given for variable */
|
||||
#define D_FORLOOP 0x400 /* set if busy in for-loop */
|
||||
#define D_IMP_BY_EXP 0x800 /* imported definition by export */
|
||||
struct type *df_type;
|
||||
union {
|
||||
struct module df_module;
|
||||
|
|
|
@ -232,15 +232,15 @@ EnterParamList(ppr, Idlist, type, VARp, off)
|
|||
FreeNode(Idlist);
|
||||
}
|
||||
|
||||
STATIC
|
||||
DoImport(df, scope, kind)
|
||||
STATIC t_def *
|
||||
DoImport(df, scope)
|
||||
register t_def *df;
|
||||
t_scope *scope;
|
||||
{
|
||||
/* Definition "df" is imported to scope "scope".
|
||||
Handle the case that it is an enumeration type or a module.
|
||||
*/
|
||||
register t_def *idef = define(df->df_idf, scope, kind);
|
||||
register t_def *idef = define(df->df_idf, scope, D_IMPORT);
|
||||
|
||||
idef->imp_def = df;
|
||||
|
||||
|
@ -252,7 +252,7 @@ DoImport(df, scope, kind)
|
|||
/* Also import all enumeration literals
|
||||
*/
|
||||
for (df = df->df_type->enm_enums; df; df = df->enm_next) {
|
||||
register t_def *df1 = define(df->df_idf, scope, kind);
|
||||
register t_def *df1 = define(df->df_idf, scope, D_IMPORT);
|
||||
|
||||
df1->imp_def = df;
|
||||
df1->df_flags |= D_USED;/* don't complain when these
|
||||
|
@ -268,14 +268,14 @@ DoImport(df, scope, kind)
|
|||
if (df->mod_vis == CurrVis) {
|
||||
error("cannot import current module \"%s\"",
|
||||
df->df_idf->id_text);
|
||||
return;
|
||||
return idef;
|
||||
}
|
||||
for (df = df->mod_vis->sc_scope->sc_def;
|
||||
df;
|
||||
df = df->df_nextinscope) {
|
||||
if (df->df_flags & D_EXPORTED) {
|
||||
register t_def *df1 =
|
||||
define(df->df_idf, scope, kind);
|
||||
define(df->df_idf, scope, D_IMPORT);
|
||||
|
||||
df1->imp_def = df;
|
||||
df1->df_flags |= D_USED;
|
||||
|
@ -284,6 +284,7 @@ DoImport(df, scope, kind)
|
|||
}
|
||||
idef->df_flags |= D_USED; /* don't complain ... */
|
||||
}
|
||||
return idef;
|
||||
}
|
||||
|
||||
STATIC t_scopelist *
|
||||
|
@ -371,7 +372,8 @@ EnterExportList(Idlist, qualified)
|
|||
while (df1) {
|
||||
if ((df1->df_kind & D_IMPORTED) &&
|
||||
df1->imp_def == CurrentScope->sc_definedby) {
|
||||
DoImport(df, df1->df_scope, D_IMP_BY_EXP);
|
||||
DoImport(df, df1->df_scope)->df_flags |=
|
||||
D_IMP_BY_EXP;
|
||||
}
|
||||
df1 = df1->df_next;
|
||||
}
|
||||
|
@ -393,7 +395,8 @@ EnterExportList(Idlist, qualified)
|
|||
}
|
||||
if (df1->df_kind == D_PROCHEAD &&
|
||||
df2->df_kind == D_PROCEDURE) {
|
||||
df1->df_kind = D_IMP_BY_EXP;
|
||||
df1->df_kind = D_IMPORT;
|
||||
df1->df_flags |= D_IMP_BY_EXP;
|
||||
df1->imp_def = df;
|
||||
continue;
|
||||
}
|
||||
|
@ -405,7 +408,8 @@ EnterExportList(Idlist, qualified)
|
|||
}
|
||||
}
|
||||
|
||||
DoImport(df, enclosing(CurrVis)->sc_scope, D_IMP_BY_EXP);
|
||||
DoImport(df, enclosing(CurrVis)->sc_scope)->df_flags |=
|
||||
D_IMP_BY_EXP;
|
||||
}
|
||||
}
|
||||
FreeNode(Idlist);
|
||||
|
@ -468,7 +472,7 @@ node_error(FromId,"identifier \"%s\" does not represent a module",module_name);
|
|||
module_name);
|
||||
df->df_flags |= D_QEXPORTED;
|
||||
}
|
||||
DoImport(df, CurrentScope, D_IMPORT);
|
||||
DoImport(df, CurrentScope);
|
||||
}
|
||||
|
||||
if (!forwflag) FreeNode(FromId);
|
||||
|
@ -486,7 +490,7 @@ EnterGlobalImportList(idlist)
|
|||
f = file_info;
|
||||
|
||||
for (; idlist; idlist = idlist->nd_left) {
|
||||
DoImport(GetDefinitionModule(idlist->nd_IDF, 1), CurrentScope, D_IMPORT);
|
||||
DoImport(GetDefinitionModule(idlist->nd_IDF, 1), CurrentScope);
|
||||
file_info = f;
|
||||
}
|
||||
}
|
||||
|
@ -499,6 +503,6 @@ EnterImportList(idlist)
|
|||
t_scope *sc = enclosing(CurrVis)->sc_scope;
|
||||
|
||||
for (; idlist; idlist = idlist->nd_left) {
|
||||
DoImport(ForwDef(idlist, sc), CurrentScope, D_IMPORT);
|
||||
DoImport(ForwDef(idlist, sc), CurrentScope);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -411,7 +411,11 @@ genrck(tp)
|
|||
*/
|
||||
arith lb, ub;
|
||||
register label ol;
|
||||
arith size = tp->tp_size;
|
||||
extern char *long2str();
|
||||
register t_type *btp = BaseType(tp);
|
||||
|
||||
if (size < word_size) size = word_size;
|
||||
getbounds(tp, &lb, &ub);
|
||||
|
||||
if (tp->tp_fund == T_SUBRANGE) {
|
||||
|
@ -424,11 +428,17 @@ genrck(tp)
|
|||
}
|
||||
if (!ol) {
|
||||
C_df_dlb(ol = data_label);
|
||||
C_rom_cst(lb);
|
||||
C_rom_cst(ub);
|
||||
C_rom_icon(long2str((long)lb,10), size);
|
||||
C_rom_icon(long2str((long)ub,10), size);
|
||||
}
|
||||
c_lae_dlb(ol);
|
||||
C_rck(word_size);
|
||||
if (size <= word_size) {
|
||||
C_cal(btp->tp_fund == T_INTEGER ? "rcki" : "rcku");
|
||||
}
|
||||
else {
|
||||
C_cal(btp->tp_fund == T_INTEGER ? "rckil" : "rckul");
|
||||
}
|
||||
C_asp(pointer_size);
|
||||
}
|
||||
|
||||
getbounds(tp, plo, phi)
|
||||
|
|
|
@ -860,7 +860,8 @@ UseWarnings(df)
|
|||
register t_def *df1 = df->imp_def;
|
||||
|
||||
df1->df_flags |= df->df_flags & (D_USED|D_DEFINED);
|
||||
if (df->df_kind == D_IMPORT) {
|
||||
if (df->df_kind == D_IMPORT &&
|
||||
!(df->df_flags & D_IMP_BY_EXP)) {
|
||||
if (! (df->df_flags & (D_USED | D_DEFINED))) {
|
||||
node_warning(
|
||||
df->df_scope->sc_end,
|
||||
|
|
Loading…
Reference in a new issue