Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvander committed Jul 5, 2014
1 parent 0e4b913 commit 680a8e0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions sourcepawn/compiler/sc.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ typedef struct svalue_s {
#define DECLFLAG_ENUMROOT 0x08 // Multi-dimensional arrays should have an enumroot.
#define DECLFLAG_MAYBE_FUNCTION 0x10 // Might be a named function.
#define DECLFLAG_DYNAMIC_ARRAYS 0x20 // Dynamic arrays are allowed.
#define DECLFLAG_OLD 0x40 // Known old-style declaration.
#define DECLMASK_NAMED_DECL (DECLFLAG_ARGUMENT | DECLFLAG_VARIABLE | DECLFLAG_MAYBE_FUNCTION)

typedef struct {
Expand Down
32 changes: 28 additions & 4 deletions sourcepawn/compiler/sc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -1478,8 +1478,12 @@ static void dodecl(const token_t *tok)
int fpublic = (tok->id == tPUBLIC);
int fstock = (tok->id == tSTOCK);
int fstatic = (tok->id == tSTATIC);

int flags = DECLFLAG_MAYBE_FUNCTION | DECLFLAG_VARIABLE | DECLFLAG_ENUMROOT;
if (tok->id == tNEW)
flags |= DECLFLAG_OLD;

parse_decl(&decl, DECLFLAG_MAYBE_FUNCTION|DECLFLAG_VARIABLE|DECLFLAG_ENUMROOT);
parse_decl(&decl, flags);

if (!decl.opertok && (tok->id == tNEW || decl.has_postdims || !lexpeek('('))) {
if (tok->id == tNEW && decl.is_new)
Expand Down Expand Up @@ -2119,7 +2123,9 @@ static void declloc(int tokid)
int fstatic = (tokid == tSTATIC);
declinfo_t decl;

const int declflags = DECLFLAG_VARIABLE | DECLFLAG_ENUMROOT | DECLFLAG_DYNAMIC_ARRAYS;
int declflags = DECLFLAG_VARIABLE | DECLFLAG_ENUMROOT | DECLFLAG_DYNAMIC_ARRAYS;
if (tokid == tNEW || tokid == tDECL)
declflags |= DECLFLAG_OLD;

parse_decl(&decl, declflags);

Expand Down Expand Up @@ -3286,6 +3292,19 @@ static int parse_old_decl(declinfo_t *decl, int flags)
if (decl->opertok == 0)
strcpy(decl->name, "<unknown>");
} else {
if (!lexpeek(tSYMBOL)) {
switch (lextok(&tok)) {
case tOBJECT:
case tCHAR:
case tVOID:
case tINT:
error(143);
break;
default:
lexpush();
break;
}
}
if (expecttoken(tSYMBOL, &tok))
strcpy(decl->name, tok.str);
else
Expand Down Expand Up @@ -3400,6 +3419,11 @@ int parse_decl(declinfo_t *decl, int flags)
if (matchtoken(tCONST))
decl->type.usage |= uCONST;

// Sometimes we know ahead of time whether the declaration will be old, for
// example, if preceded by tNEW or tDECL.
if (flags & DECLFLAG_OLD)
return parse_old_decl(decl, flags);

// If parsing an argument, there are two simple checks for whether this is a
// new or old-style declaration.
if ((flags & DECLFLAG_ARGUMENT) && (lexpeek('&') || lexpeek('{')))
Expand Down Expand Up @@ -6480,7 +6504,7 @@ static void statement(int *lastindent,int allow_decl)
lexpush();
autozero = TRUE;
lastst = tNEW;
declloc(tNEW);
declloc(tok);
return;
}
}
Expand Down Expand Up @@ -6939,7 +6963,7 @@ static int dofor(void)
*/
nestlevel++;
autozero=1;
declloc(tFOR); /* declare local variable */
declloc(tok.id); /* declare local variable */
break;
default:
lexpush();
Expand Down

0 comments on commit 680a8e0

Please sign in to comment.