mirror of
https://github.com/ZDoom/acc.git
synced 2024-11-15 08:51:53 +00:00
- Better error message for trying to cram too many values into an array.
- Fixed: Array initialization in ACC was incorrect for partial initializers, especially with higher dimensions. SVN r2416 (trunk)
This commit is contained in:
parent
0138415af5
commit
e810579a68
2 changed files with 21 additions and 13 deletions
33
parse.c
33
parse.c
|
@ -12,6 +12,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
|
@ -3886,12 +3887,13 @@ static void ParseArrayIndices(symbolNode_t *sym, int requiredIndices)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int *ProcessArrayLevel(int level, int *entry, int ndim,
|
static void ProcessArrayLevel(int level, int *entry, 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 i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < dims[level-1]; ++i)
|
for(i = 0; ; ++i)
|
||||||
{
|
{
|
||||||
if(tk_Token == TK_COMMA)
|
if(tk_Token == TK_COMMA)
|
||||||
{
|
{
|
||||||
|
@ -3901,14 +3903,7 @@ static int *ProcessArrayLevel(int level, int *entry, int ndim,
|
||||||
else if(tk_Token == TK_RBRACE)
|
else if(tk_Token == TK_RBRACE)
|
||||||
{
|
{
|
||||||
TK_NextToken();
|
TK_NextToken();
|
||||||
if(level > 1)
|
return;
|
||||||
{
|
|
||||||
return entry + muls[level-2] - i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return entry + (muls[0]*dims[0]) - i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -3923,15 +3918,28 @@ static int *ProcessArrayLevel(int level, int *entry, int ndim,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*entry++ = EvalConstExpression();
|
int val;
|
||||||
|
|
||||||
|
if (i >= dims[level - 1] && !warned_too_many)
|
||||||
|
{
|
||||||
|
warned_too_many = YES;
|
||||||
|
ERR_Error(ERR_TOO_MANY_ARRAY_INIT, YES);
|
||||||
|
}
|
||||||
|
val = EvalConstExpression();
|
||||||
ArrayHasStrings |= pa_ConstExprIsString;
|
ArrayHasStrings |= pa_ConstExprIsString;
|
||||||
|
if (i < dims[level - 1])
|
||||||
|
{
|
||||||
|
entry[i] = val;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TK_TokenMustBe(TK_LBRACE, ERR_MISSING_LBRACE_ARR);
|
TK_TokenMustBe(TK_LBRACE, ERR_MISSING_LBRACE_ARR);
|
||||||
TK_NextToken();
|
TK_NextToken();
|
||||||
entry = ProcessArrayLevel(level+1, entry, ndim, dims, muls, name);
|
ProcessArrayLevel(level+1, entry, ndim, dims, muls, name);
|
||||||
|
assert(level > 0);
|
||||||
|
entry += muls[level-1];
|
||||||
}
|
}
|
||||||
if(i < dims[level-1]-1)
|
if(i < dims[level-1]-1)
|
||||||
{
|
{
|
||||||
|
@ -3956,7 +3964,6 @@ static int *ProcessArrayLevel(int level, int *entry, int ndim,
|
||||||
}
|
}
|
||||||
TK_TokenMustBe(TK_RBRACE, ERR_MISSING_RBRACE_ARR);
|
TK_TokenMustBe(TK_RBRACE, ERR_MISSING_RBRACE_ARR);
|
||||||
TK_NextToken();
|
TK_NextToken();
|
||||||
return entry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
1
pcode.c
1
pcode.c
|
@ -830,6 +830,7 @@ static void CloseNew(void)
|
||||||
PC_Append("AINI", 4);
|
PC_Append("AINI", 4);
|
||||||
PC_AppendInt(ArraySizes[i]*4+4);
|
PC_AppendInt(ArraySizes[i]*4+4);
|
||||||
PC_AppendInt((U_INT)i);
|
PC_AppendInt((U_INT)i);
|
||||||
|
MS_Message(MSG_DEBUG, "Writing array initializers for array %d (size %d)\n", i, ArraySizes[i]);
|
||||||
for(j = 0; j < ArraySizes[i]; ++j)
|
for(j = 0; j < ArraySizes[i]; ++j)
|
||||||
{
|
{
|
||||||
PC_AppendInt((U_INT)ArrayInits[i][j]);
|
PC_AppendInt((U_INT)ArrayInits[i][j]);
|
||||||
|
|
Loading…
Reference in a new issue