- Fixed: Local array initializers didn't work for multi-dimensional arrays.

This commit is contained in:
Braden Obrzut 2015-03-26 18:10:56 -04:00
parent 918a247c0d
commit a4326c85a3

13
parse.c
View file

@ -147,7 +147,7 @@ static void ParseArrayDims(int *size, int *ndim, int dims[MAX_ARRAY_DIMS]);
static void SymToArray(int symtype, symbolNode_t *sym, int index, int ndim, int size, int dims[MAX_ARRAY_DIMS]); static void SymToArray(int symtype, symbolNode_t *sym, int index, int ndim, int size, int dims[MAX_ARRAY_DIMS]);
static void ParseArrayIndices(symbolNode_t *sym, int requiredIndices); static void ParseArrayIndices(symbolNode_t *sym, int requiredIndices);
static void InitializeArray(symbolNode_t *sym, int dims[MAX_ARRAY_DIMS], int size); static void InitializeArray(symbolNode_t *sym, int dims[MAX_ARRAY_DIMS], int size);
static void InitializeScriptArray(symbolNode_t *sym, int dims[MAX_ARRAY_DIMS], int size); static void InitializeScriptArray(symbolNode_t *sym, int dims[MAX_ARRAY_DIMS]);
static symbolNode_t *DemandSymbol(char *name); static symbolNode_t *DemandSymbol(char *name);
static symbolNode_t *SpeculateSymbol(char *name, boolean hasReturn); static symbolNode_t *SpeculateSymbol(char *name, boolean hasReturn);
static symbolNode_t *SpeculateFunction(const char *name, boolean hasReturn); static symbolNode_t *SpeculateFunction(const char *name, boolean hasReturn);
@ -1516,7 +1516,7 @@ static void LeadingVarDeclare(void)
SymToArray(SY_SCRIPTARRAY, sym, ScriptArrayCount++, size, ndim, dims); SymToArray(SY_SCRIPTARRAY, sym, ScriptArrayCount++, size, ndim, dims);
if(tk_Token == TK_ASSIGN) if(tk_Token == TK_ASSIGN)
{ {
InitializeScriptArray(sym, dims, size); InitializeScriptArray(sym, dims);
} }
} }
} }
@ -4323,12 +4323,11 @@ static void InitializeArray(symbolNode_t *sym, int dims[MAX_ARRAY_DIMS], int siz
// //
//========================================================================== //==========================================================================
static void ProcessScriptArrayLevel(int level, symbolNode_t *sym, int ndim, static void ProcessScriptArrayLevel(int level, int loc, symbolNode_t *sym, int ndim,
int dims[MAX_ARRAY_DIMS], int muls[MAX_ARRAY_DIMS], char *name) int dims[MAX_ARRAY_DIMS], int muls[MAX_ARRAY_DIMS], char *name)
{ {
int warned_too_many = NO; int warned_too_many = NO;
int i; int i;
int loc = 0;
for(i = 0; ; ++i) for(i = 0; ; ++i)
{ {
@ -4379,7 +4378,7 @@ static void ProcessScriptArrayLevel(int level, symbolNode_t *sym, int ndim,
} }
TK_TokenMustBe(TK_LBRACE, ERR_MISSING_LBRACE_ARR); TK_TokenMustBe(TK_LBRACE, ERR_MISSING_LBRACE_ARR);
TK_NextToken(); TK_NextToken();
ProcessScriptArrayLevel(level+1, sym, ndim, dims, muls, name); ProcessScriptArrayLevel(level+1, loc, sym, ndim, dims, muls, name);
assert(level > 0); assert(level > 0);
loc += muls[level-1]; loc += muls[level-1];
} }
@ -4414,12 +4413,12 @@ static void ProcessScriptArrayLevel(int level, symbolNode_t *sym, int ndim,
// //
//========================================================================== //==========================================================================
static void InitializeScriptArray(symbolNode_t *sym, int dims[MAX_ARRAY_DIMS], int size) static void InitializeScriptArray(symbolNode_t *sym, int dims[MAX_ARRAY_DIMS])
{ {
TK_NextTokenMustBe(TK_LBRACE, ERR_MISSING_LBRACE_ARR); TK_NextTokenMustBe(TK_LBRACE, ERR_MISSING_LBRACE_ARR);
TK_NextToken(); TK_NextToken();
ArrayHasStrings = NO; ArrayHasStrings = NO;
ProcessScriptArrayLevel(1, sym, sym->info.array.ndim, dims, ProcessScriptArrayLevel(1, 0, sym, sym->info.array.ndim, dims,
sym->info.array.dimensions, sym->name); sym->info.array.dimensions, sym->name);
} }