mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
when checking a token, they type of the token must be taken into account.
This commit is contained in:
parent
00e71e3cc5
commit
6247233e0e
3 changed files with 49 additions and 49 deletions
|
@ -357,8 +357,8 @@ void PR_Lex (void);
|
|||
type_t *PR_ParseType (void);
|
||||
char *PR_ParseName (void);
|
||||
|
||||
qboolean PR_Check (char *string);
|
||||
void PR_Expect (char *string);
|
||||
qboolean PR_Check (token_type_t type, char *string);
|
||||
void PR_Expect (token_type_t type, char *string);
|
||||
void PR_ParseError (char *error, ...);
|
||||
|
||||
|
||||
|
|
|
@ -354,7 +354,7 @@ PR_ParseFunctionCall (def_t *func)
|
|||
|
||||
// copy the arguments to the global parameter variables
|
||||
arg = 0;
|
||||
if (!PR_Check (")")) {
|
||||
if (!PR_Check (tt_punct, ")")) {
|
||||
do {
|
||||
if (t->num_parms != -1 && arg >= t->num_parms)
|
||||
PR_ParseError ("too many parameters");
|
||||
|
@ -378,11 +378,11 @@ PR_ParseFunctionCall (def_t *func)
|
|||
def_parms[arg].type = t->parm_types[arg];
|
||||
PR_Statement (&pr_opcodes[OP_STORE_V], e, &def_parms[arg]);
|
||||
arg++;
|
||||
} while (PR_Check (","));
|
||||
} while (PR_Check (tt_punct, ","));
|
||||
|
||||
if (t->num_parms != -1 && arg != t->num_parms)
|
||||
PR_ParseError ("too few parameters");
|
||||
PR_Expect (")");
|
||||
PR_Expect (tt_punct, ")");
|
||||
}
|
||||
|
||||
if (arg > 8)
|
||||
|
@ -428,7 +428,7 @@ PR_Term (void)
|
|||
def_t *e;
|
||||
etype_t t;
|
||||
|
||||
if (PR_Check ("!")) {
|
||||
if (PR_Check (tt_punct, "!")) {
|
||||
e = PR_Expression (NOT_PRIORITY);
|
||||
t = e->type->type;
|
||||
switch (t) {
|
||||
|
@ -448,9 +448,9 @@ PR_Term (void)
|
|||
}
|
||||
}
|
||||
|
||||
if (PR_Check ("(")) {
|
||||
if (PR_Check (tt_punct, "(")) {
|
||||
e = PR_Expression (TOP_PRIORITY);
|
||||
PR_Expect (")");
|
||||
PR_Expect (tt_punct, ")");
|
||||
return e;
|
||||
}
|
||||
|
||||
|
@ -474,7 +474,7 @@ PR_Expression (int priority)
|
|||
e = PR_Expression (priority - 1);
|
||||
|
||||
while (1) {
|
||||
if (priority == 1 && PR_Check ("("))
|
||||
if (priority == 1 && PR_Check (tt_punct, "("))
|
||||
return PR_ParseFunctionCall (e);
|
||||
|
||||
for (op = pr_opcodes; op->name; op++) {
|
||||
|
@ -482,7 +482,7 @@ PR_Expression (int priority)
|
|||
if (op->priority != priority)
|
||||
continue;
|
||||
|
||||
if (!PR_Check (op->name))
|
||||
if (!PR_Check (tt_punct, op->name))
|
||||
continue;
|
||||
|
||||
if (op->right_associative) {
|
||||
|
@ -550,32 +550,32 @@ PR_ParseStatement (void)
|
|||
def_t *e;
|
||||
dstatement_t *patch1, *patch2;
|
||||
|
||||
if (PR_Check ("{")) {
|
||||
if (PR_Check (tt_punct, "{")) {
|
||||
do {
|
||||
PR_ParseStatement ();
|
||||
} while (!PR_Check ("}"));
|
||||
} while (!PR_Check (tt_punct, "}"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (PR_Check ("return")) {
|
||||
if (PR_Check (";")) {
|
||||
if (PR_Check (tt_name, "return")) {
|
||||
if (PR_Check (tt_punct, ";")) {
|
||||
PR_Statement (&pr_opcodes[OP_RETURN], 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
e = PR_Expression (TOP_PRIORITY);
|
||||
|
||||
PR_Expect (";");
|
||||
PR_Expect (tt_punct, ";");
|
||||
PR_Statement (&pr_opcodes[OP_RETURN], e, 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (PR_Check ("while")) {
|
||||
PR_Expect ("(");
|
||||
if (PR_Check (tt_name, "while")) {
|
||||
PR_Expect (tt_punct, "(");
|
||||
patch2 = &statements[numstatements];
|
||||
e = PR_Expression (TOP_PRIORITY);
|
||||
PR_Expect (")");
|
||||
PR_Expect (tt_punct, ")");
|
||||
patch1 = &statements[numstatements];
|
||||
PR_Statement (&pr_opcodes[OP_IFNOT], e, 0);
|
||||
PR_ParseStatement ();
|
||||
|
@ -585,36 +585,36 @@ PR_ParseStatement (void)
|
|||
return;
|
||||
}
|
||||
|
||||
if (PR_Check ("do")) {
|
||||
if (PR_Check (tt_name, "do")) {
|
||||
patch1 = &statements[numstatements];
|
||||
PR_ParseStatement ();
|
||||
PR_Expect ("while");
|
||||
PR_Expect ("(");
|
||||
PR_Expect (tt_name, "while");
|
||||
PR_Expect (tt_punct, "(");
|
||||
e = PR_Expression (TOP_PRIORITY);
|
||||
PR_Expect (")");
|
||||
PR_Expect (";");
|
||||
PR_Expect (tt_punct, ")");
|
||||
PR_Expect (tt_punct, ";");
|
||||
junkdef.ofs = patch1 - &statements[numstatements];
|
||||
PR_Statement (&pr_opcodes[OP_IF], e, &junkdef);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PR_Check ("local")) {
|
||||
if (PR_Check (tt_name, "local")) {
|
||||
PR_ParseDefs ();
|
||||
locals_end = numpr_globals;
|
||||
return;
|
||||
}
|
||||
|
||||
if (PR_Check ("if")) {
|
||||
PR_Expect ("(");
|
||||
if (PR_Check (tt_name, "if")) {
|
||||
PR_Expect (tt_punct, "(");
|
||||
e = PR_Expression (TOP_PRIORITY);
|
||||
PR_Expect (")");
|
||||
PR_Expect (tt_punct, ")");
|
||||
|
||||
patch1 = &statements[numstatements];
|
||||
PR_Statement (&pr_opcodes[OP_IFNOT], e, 0);
|
||||
|
||||
PR_ParseStatement ();
|
||||
|
||||
if (PR_Check ("else")) {
|
||||
if (PR_Check (tt_name, "else")) {
|
||||
patch2 = &statements[numstatements];
|
||||
PR_Statement (&pr_opcodes[OP_GOTO], 0, 0);
|
||||
patch1->b = &statements[numstatements] - patch1;
|
||||
|
@ -628,7 +628,7 @@ PR_ParseStatement (void)
|
|||
}
|
||||
|
||||
PR_Expression (TOP_PRIORITY);
|
||||
PR_Expect (";");
|
||||
PR_Expect (tt_punct, ";");
|
||||
}
|
||||
|
||||
|
||||
|
@ -663,12 +663,12 @@ PR_ParseState (void)
|
|||
|
||||
s1 = PR_ParseImmediate ();
|
||||
|
||||
PR_Expect (",");
|
||||
PR_Expect (tt_punct, ",");
|
||||
|
||||
name = PR_ParseName ();
|
||||
def = PR_GetDef (&type_function, name, 0, true);
|
||||
|
||||
PR_Expect ("]");
|
||||
PR_Expect (tt_punct, "]");
|
||||
|
||||
PR_Statement (&pr_opcodes[OP_STATE], s1, def);
|
||||
}
|
||||
|
@ -688,7 +688,7 @@ PR_ParseImmediateStatements (type_t *type)
|
|||
f = malloc (sizeof (function_t));
|
||||
|
||||
// check for builtin function definition #1, #2, etc
|
||||
if (PR_Check ("#")) {
|
||||
if (PR_Check (tt_punct, "#")) {
|
||||
if (pr_token_type != tt_immediate
|
||||
|| pr_immediate_type != &type_float
|
||||
|| pr_immediate._float != (int) pr_immediate._float) {
|
||||
|
@ -713,13 +713,13 @@ PR_ParseImmediateStatements (type_t *type)
|
|||
f->code = numstatements;
|
||||
|
||||
// check for a state opcode
|
||||
if (PR_Check ("["))
|
||||
if (PR_Check (tt_punct, "["))
|
||||
PR_ParseState ();
|
||||
|
||||
// parse regular statements
|
||||
PR_Expect ("{");
|
||||
PR_Expect (tt_punct, "{");
|
||||
|
||||
while (!PR_Check ("}"))
|
||||
while (!PR_Check (tt_punct, "}"))
|
||||
PR_ParseStatement ();
|
||||
|
||||
// emit an end of statements opcode
|
||||
|
@ -848,7 +848,7 @@ PR_ParseDefs (void)
|
|||
def = PR_GetDef (type, name, pr_scope, true);
|
||||
|
||||
// check for an initialization
|
||||
if (PR_Check ("=")) {
|
||||
if (PR_Check (tt_punct, "=")) {
|
||||
if (def->initialized)
|
||||
PR_ParseError ("%s redeclared", name);
|
||||
|
||||
|
@ -892,9 +892,9 @@ PR_ParseDefs (void)
|
|||
PR_Lex ();
|
||||
}
|
||||
|
||||
} while (PR_Check (","));
|
||||
} while (PR_Check (tt_punct, ","));
|
||||
|
||||
PR_Expect (";");
|
||||
PR_Expect (tt_punct, ";");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -502,9 +502,9 @@ PR_ParseError (char *error, ...)
|
|||
to string
|
||||
*/
|
||||
void
|
||||
PR_Expect (char *string)
|
||||
PR_Expect (token_type_t type, char *string)
|
||||
{
|
||||
if (strcmp (string, pr_token))
|
||||
if (type != pr_token_type || strcmp (string, pr_token))
|
||||
PR_ParseError ("expected %s, found %s", string, pr_token);
|
||||
PR_Lex ();
|
||||
}
|
||||
|
@ -517,9 +517,9 @@ PR_Expect (char *string)
|
|||
Otherwise, return false and do nothing else.
|
||||
*/
|
||||
qboolean
|
||||
PR_Check (char *string)
|
||||
PR_Check (token_type_t type, char *string)
|
||||
{
|
||||
if (strcmp (string, pr_token))
|
||||
if (type != pr_token_type || strcmp (string, pr_token))
|
||||
return false;
|
||||
|
||||
PR_Lex ();
|
||||
|
@ -599,7 +599,7 @@ void
|
|||
PR_SkipToSemicolon (void)
|
||||
{
|
||||
do {
|
||||
if (!pr_bracelevel && PR_Check (";"))
|
||||
if (!pr_bracelevel && PR_Check (tt_punct, ";"))
|
||||
return;
|
||||
PR_Lex ();
|
||||
} while (pr_token[0]); // eof will return a null token
|
||||
|
@ -620,7 +620,7 @@ PR_ParseType (void)
|
|||
type_t *type;
|
||||
char *name;
|
||||
|
||||
if (PR_Check (".")) {
|
||||
if (PR_Check (tt_punct, ".")) {
|
||||
memset (&new, 0, sizeof (new));
|
||||
new.type = ev_field;
|
||||
new.aux_type = PR_ParseType ();
|
||||
|
@ -645,7 +645,7 @@ PR_ParseType (void)
|
|||
}
|
||||
PR_Lex ();
|
||||
|
||||
if (!PR_Check ("("))
|
||||
if (!PR_Check (tt_punct, "("))
|
||||
return type;
|
||||
|
||||
// function type
|
||||
|
@ -653,8 +653,8 @@ PR_ParseType (void)
|
|||
new.type = ev_function;
|
||||
new.aux_type = type; // return type
|
||||
new.num_parms = 0;
|
||||
if (!PR_Check (")")) {
|
||||
if (PR_Check ("...")) {
|
||||
if (!PR_Check (tt_punct, ")")) {
|
||||
if (PR_Check (tt_punct, "...")) {
|
||||
new.num_parms = -1; // variable args
|
||||
} else {
|
||||
do {
|
||||
|
@ -663,10 +663,10 @@ PR_ParseType (void)
|
|||
strcpy (pr_parm_names[new.num_parms], name);
|
||||
new.parm_types[new.num_parms] = type;
|
||||
new.num_parms++;
|
||||
} while (PR_Check (","));
|
||||
} while (PR_Check (tt_punct, ","));
|
||||
}
|
||||
|
||||
PR_Expect (")");
|
||||
PR_Expect (tt_punct, ")");
|
||||
}
|
||||
|
||||
return PR_FindType (&new);
|
||||
|
|
Loading…
Reference in a new issue