Do the _xyz thing for vectors in structs.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5736 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2020-07-19 22:39:10 +00:00
parent 8a20cb3a70
commit a3a0e1eae1
2 changed files with 27 additions and 4 deletions

View file

@ -15693,6 +15693,8 @@ QCC_sref_t QCC_PR_ParseInitializerType_Internal(int arraysize, QCC_def_t *basede
break;
if ((type)->params[partnum].isvirtual)
continue; //these are pre-initialised....
if ((type)->params[partnum].optional)
continue; //float parts of a vector.
def.cast = (type)->params[partnum].type;
def.ofs = (type)->params[partnum].ofs;

View file

@ -17,6 +17,7 @@ void QCC_FreeDef(QCC_def_t *def);
extern pbool destfile_explicit;
extern char destfile[1024];
static const QCC_sref_t nullsref = {0};
#define MAXINCLUDEDIRS 8
char qccincludedir[MAXINCLUDEDIRS][256]; //the -src path, for #includes
@ -5821,6 +5822,7 @@ QCC_type_t *QCC_PR_ParseType (int newtype, pbool silentfail)
{
struct QCC_typeparam_s *parms = NULL, *oldparm;
int numparms = 0;
int ofs;
unsigned int arraysize;
char *parmname;
@ -6013,8 +6015,8 @@ QCC_type_t *QCC_PR_ParseType (int newtype, pbool silentfail)
}
}
parms = realloc(parms, sizeof(*parms) * (numparms+1));
oldparm = QCC_PR_FindStructMember(newt, parmname, &parms[numparms].ofs);
parms = realloc(parms, sizeof(*parms) * (numparms+4));
oldparm = QCC_PR_FindStructMember(newt, parmname, &ofs);
if (oldparm && oldparm->arraysize == arraysize && !typecmp_lax(oldparm->type, type))
{
if (!isvirt)
@ -6022,16 +6024,17 @@ QCC_type_t *QCC_PR_ParseType (int newtype, pbool silentfail)
}
else if (structtype == ev_union)
{
parms[numparms].ofs = 0;
ofs = 0;
if (type->size*(arraysize?arraysize:1) > newt->size)
newt->size = type->size*(arraysize?arraysize:1);
}
else
{
parms[numparms].ofs = newt->size;
ofs = newt->size;
newt->size += type->size*(arraysize?arraysize:1);
}
parms[numparms].ofs = ofs;
parms[numparms].arraysize = arraysize;
parms[numparms].out = false;
parms[numparms].optional = false;
@ -6040,6 +6043,24 @@ QCC_type_t *QCC_PR_ParseType (int newtype, pbool silentfail)
parms[numparms].type = type;
parms[numparms].defltvalue = defaultval;
numparms++;
if (type->type == ev_vector && arraysize == 0)
{ //add in vec_x/y/z members too.
int c;
for (c = 0; c < 3; c++)
{
parms[numparms].ofs = ofs + c;
parms[numparms].arraysize = arraysize;
parms[numparms].out = false;
parms[numparms].optional = true;
parms[numparms].isvirtual = isvirt;
parms[numparms].paramname = qccHunkAlloc(strlen(pr_token)+3);
sprintf(parms[numparms].paramname, "%s_%c", parmname, 'x'+c);
parms[numparms].type = type_float;
parms[numparms].defltvalue = nullsref;
numparms++;
}
}
}
if (!numparms)
QCC_PR_ParseError(ERR_NOTANAME, "%s %s has no members", structtype==ev_union?"union":"struct", newt->name);