From 23b23f3950556ae79c6ec987cde44c746e05e0c8 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 25 Feb 2006 03:54:30 +0000 Subject: [PATCH] Fix for generating incorrect code for accessing arrays with three or more dimensions. SVN r15 (trunk) --- Makefile | 2 +- acc.c | 2 +- parse.c | 16 ++++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 223d6dc..9f22c16 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ endif CFLAGS = -Os -Wall -W -march=pentium -mtune=athlon-4 -fomit-frame-pointer LDFLAGS = -s -VERNUM = 136 +VERNUM = 137 OBJS = \ acc.o \ diff --git a/acc.c b/acc.c index 099a414..cbe9d21 100644 --- a/acc.c +++ b/acc.c @@ -22,7 +22,7 @@ // MACROS ------------------------------------------------------------------ -#define VERSION_TEXT "1.36" +#define VERSION_TEXT "1.37" #define COPYRIGHT_YEARS_TEXT "1995" // TYPES ------------------------------------------------------------------- diff --git a/parse.c b/parse.c index adf7408..d870d39 100644 --- a/parse.c +++ b/parse.c @@ -882,7 +882,7 @@ static void OuterFunction(void) static void OuterMapVar(boolean local) { symbolNode_t *sym = NULL; - int index; + int index, i; MS_Message(MSG_DEBUG, "---- %s ----\n", local ? "LeadingStaticVarDeclare" : "OuterMapVar"); do @@ -993,8 +993,6 @@ static void OuterMapVar(boolean local) sym->info.array.size = size; if(ndim > 0) { - int i; - sym->info.array.dimensions[ndim-1] = 1; for(i = ndim - 2; i >= 0; --i) { @@ -1002,6 +1000,12 @@ static void OuterMapVar(boolean local) sym->info.array.dimensions[i+1] * dims[i+1]; } } + MS_Message(MSG_DEBUG, " - with multipliers "); + for(i = 0; i < ndim; ++i) + { + MS_Message(MSG_DEBUG, "[%d]", sym->info.array.dimensions[i]); + } + MS_Message(MSG_DEBUG, "\n"); if(tk_Token == TK_ASSIGN) { InitializeArray(sym, dims, size); @@ -3693,12 +3697,12 @@ static void ParseArrayIndices(symbolNode_t *sym, int requiredIndices) } } } - if(i > 0) + EvalExpression(); + if(i < sym->info.array.ndim - 1) { - PC_AppendPushVal(sym->info.array.dimensions[i-1]); + PC_AppendPushVal(sym->info.array.dimensions[i]); PC_AppendCmd(PCD_MULTIPLY); } - EvalExpression(); if(i > 0) { PC_AppendCmd(PCD_ADD);