sourcepawn/compiler/sc3.c
changeset 286 463d266be91d
parent 164 2d9741b7d92b
child 338 c1f0821e1991
     1.1 --- a/sourcepawn/compiler/sc3.c	Thu Jan 11 08:46:41 2007 +0000
     1.2 +++ b/sourcepawn/compiler/sc3.c	Fri Jan 12 04:11:39 2007 +0000
     1.3 @@ -992,7 +992,7 @@
     1.4      sym=finddepend(sym);
     1.5      assert(sym!=NULL);
     1.6    } /* if */
     1.7 -  return sym->dim.array.length;
     1.8 +  return (sym->dim.array.slength ? sym->dim.array.slength : sym->dim.array.length);
     1.9  }
    1.10  
    1.11  /*  hier14
    1.12 @@ -1559,12 +1559,67 @@
    1.13          if (subsym!=NULL)
    1.14            subsym=finddepend(subsym);
    1.15        } /* for */
    1.16 -      if (level>sym->dim.array.level+1)
    1.17 +	  if (level>sym->dim.array.level+1) {
    1.18          error(28,sym->name);  /* invalid subscript */
    1.19 -      else if (level==sym->dim.array.level+1)
    1.20 +      } else if (level==sym->dim.array.level+1) {
    1.21          lval->constval= (idxsym!=NULL && idxsym->dim.array.length>0) ? idxsym->dim.array.length : 1;
    1.22 -      else
    1.23 +      } else {
    1.24          lval->constval=array_levelsize(sym,level);
    1.25 +      }
    1.26 +      if (lval->constval==0 && strchr((char *)lptr,PREPROC_TERM)==NULL)
    1.27 +        error(224,st);          /* indeterminate array size in "sizeof" expression */
    1.28 +    } /* if */
    1.29 +    ldconst(lval->constval,sPRI);
    1.30 +    while (paranthese--)
    1.31 +      needtoken(')');
    1.32 +    return FALSE;
    1.33 +  case tCELLSOF:
    1.34 +    paranthese=0;
    1.35 +    while (matchtoken('('))
    1.36 +      paranthese++;
    1.37 +    tok=lex(&val,&st);
    1.38 +    if (tok!=tSYMBOL)
    1.39 +      return error(20,st);      /* illegal symbol name */
    1.40 +    sym=findloc(st);
    1.41 +    if (sym==NULL)
    1.42 +      sym=findglb(st,sSTATEVAR);
    1.43 +    if (sym==NULL)
    1.44 +      return error(17,st);      /* undefined symbol */
    1.45 +    if (sym->ident==iCONSTEXPR)
    1.46 +      error(39);                /* constant symbol has no size */
    1.47 +    else if (sym->ident==iFUNCTN || sym->ident==iREFFUNC)
    1.48 +      error(72);                /* "function" symbol has no size */
    1.49 +    else if ((sym->usage & uDEFINE)==0)
    1.50 +      return error(17,st);      /* undefined symbol (symbol is in the table, but it is "used" only) */
    1.51 +    clear_value(lval);
    1.52 +    lval->ident=iCONSTEXPR;
    1.53 +    lval->constval=1;           /* preset */
    1.54 +    if (sym->ident==iARRAY || sym->ident==iREFARRAY) {
    1.55 +      int level;
    1.56 +      symbol *idxsym=NULL;
    1.57 +      symbol *subsym=sym;
    1.58 +      for (level=0; matchtoken('['); level++) {
    1.59 +        idxsym=NULL;
    1.60 +        if (subsym!=NULL && level==subsym->dim.array.level && matchtoken(tSYMBOL)) {
    1.61 +          char *idxname;
    1.62 +          int cmptag=subsym->x.tags.index;
    1.63 +          tokeninfo(&val,&idxname);
    1.64 +          if ((idxsym=findconst(idxname,&cmptag))==NULL)
    1.65 +            error(80,idxname);  /* unknown symbol, or non-constant */
    1.66 +          else if (cmptag>1)
    1.67 +            error(91,idxname);  /* ambiguous constant */
    1.68 +        } /* if */
    1.69 +        needtoken(']');
    1.70 +        if (subsym!=NULL)
    1.71 +          subsym=finddepend(subsym);
    1.72 +      } /* for */
    1.73 +	  if (level>sym->dim.array.level+1) {
    1.74 +        error(28,sym->name);  /* invalid subscript */
    1.75 +      } else if (level==sym->dim.array.level+1) {
    1.76 +        lval->constval= (idxsym!=NULL && idxsym->dim.array.length>0) ? idxsym->dim.array.length : 1;
    1.77 +      } else {
    1.78 +        lval->constval=array_levelsize(sym,level);
    1.79 +      }
    1.80        if (lval->constval==0 && strchr((char *)lptr,PREPROC_TERM)==NULL)
    1.81          error(224,st);          /* indeterminate array size in "sizeof" expression */
    1.82      } /* if */