2001-02-24 06:58:54 +00:00
|
|
|
/*
|
|
|
|
pr_lex.c
|
|
|
|
|
|
|
|
Lexical parser for GameC
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 2001 Jeff Teunissen <deek@dusknet.dhs.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2001-12-08 20:40:50 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
2001-02-24 06:58:54 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2001-10-24 22:50:06 +00:00
|
|
|
#include <QF/sys.h>
|
2001-02-24 06:58:54 +00:00
|
|
|
|
|
|
|
#include "qfcc.h"
|
|
|
|
|
2001-12-06 19:49:40 +00:00
|
|
|
int pr_source_line;
|
2001-02-24 06:58:54 +00:00
|
|
|
|
2001-12-06 19:49:40 +00:00
|
|
|
char pr_parm_names[MAX_PARMS][MAX_NAME];
|
2001-08-10 18:42:13 +00:00
|
|
|
|
2001-12-06 19:49:40 +00:00
|
|
|
char *pr_file_p;
|
|
|
|
char *pr_line_start; // start of current source line
|
2001-02-24 06:58:54 +00:00
|
|
|
|
2001-12-06 19:49:40 +00:00
|
|
|
int pr_bracelevel;
|
2001-02-24 06:58:54 +00:00
|
|
|
|
2001-12-06 19:49:40 +00:00
|
|
|
char pr_token[2048];
|
|
|
|
int pr_token_len;
|
|
|
|
type_t *pr_immediate_type;
|
|
|
|
eval_t pr_immediate;
|
2001-02-24 06:58:54 +00:00
|
|
|
|
2001-12-06 19:49:40 +00:00
|
|
|
char pr_immediate_string[2048];
|
2001-02-24 06:58:54 +00:00
|
|
|
|
2001-12-06 19:49:40 +00:00
|
|
|
int pr_error_count;
|
2001-02-24 06:58:54 +00:00
|
|
|
|
|
|
|
// simple types. function types are dynamically allocated
|
2001-12-06 19:49:40 +00:00
|
|
|
type_t type_void = { ev_void, &def_void };
|
|
|
|
type_t type_string = { ev_string, &def_string };
|
|
|
|
type_t type_float = { ev_float, &def_float };
|
|
|
|
type_t type_vector = { ev_vector, &def_vector };
|
|
|
|
type_t type_entity = { ev_entity, &def_entity };
|
|
|
|
type_t type_field = { ev_field, &def_field };
|
|
|
|
|
2001-02-24 06:58:54 +00:00
|
|
|
// type_function is a void() function used for state defs
|
2001-12-06 19:49:40 +00:00
|
|
|
type_t type_function = { ev_func, &def_function, NULL, &type_void };
|
|
|
|
type_t type_pointer = { ev_pointer, &def_pointer };
|
|
|
|
type_t type_quaternion = { ev_quaternion, &def_quaternion };
|
|
|
|
type_t type_integer = { ev_integer, &def_integer };
|
|
|
|
type_t type_uinteger = { ev_uinteger, &def_uinteger };
|
2001-12-07 20:10:30 +00:00
|
|
|
type_t type_short = { ev_short, &def_short };
|
2001-12-08 08:19:48 +00:00
|
|
|
type_t type_struct = { ev_struct, &def_struct };
|
2001-12-06 19:49:40 +00:00
|
|
|
|
|
|
|
type_t type_floatfield = { ev_field, &def_field, NULL, &type_float };
|
|
|
|
|
|
|
|
def_t def_void = { &type_void, "temp" };
|
|
|
|
def_t def_string = { &type_string, "temp" };
|
|
|
|
def_t def_float = { &type_float, "temp" };
|
|
|
|
def_t def_vector = { &type_vector, "temp" };
|
|
|
|
def_t def_entity = { &type_entity, "temp" };
|
|
|
|
def_t def_field = { &type_field, "temp" };
|
|
|
|
def_t def_function = { &type_function, "temp" };
|
|
|
|
def_t def_pointer = { &type_pointer, "temp" };
|
|
|
|
def_t def_quaternion = { &type_quaternion, "temp" };
|
|
|
|
def_t def_integer = { &type_integer, "temp" };
|
|
|
|
def_t def_uinteger = { &type_uinteger, "temp" };
|
2001-12-07 20:10:30 +00:00
|
|
|
def_t def_short = { &type_short, "temp" };
|
2001-12-08 08:19:48 +00:00
|
|
|
def_t def_struct = { &type_struct, "temp" };
|
2001-12-06 19:49:40 +00:00
|
|
|
|
|
|
|
def_t def_ret, def_parms[MAX_PARMS];
|
|
|
|
|
|
|
|
def_t *def_for_type[8] = {
|
2001-02-24 06:58:54 +00:00
|
|
|
&def_void, &def_string, &def_float, &def_vector,
|
|
|
|
&def_entity, &def_field, &def_function, &def_pointer
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
PR_FindType
|
|
|
|
|
|
|
|
Returns a preexisting complex type that matches the parm, or allocates
|
|
|
|
a new one and copies it out.
|
|
|
|
*/
|
|
|
|
type_t *
|
|
|
|
PR_FindType (type_t *type)
|
|
|
|
{
|
2001-12-06 19:49:40 +00:00
|
|
|
def_t *def;
|
|
|
|
type_t *check;
|
|
|
|
int i;
|
2001-06-19 16:01:38 +00:00
|
|
|
|
2001-02-24 06:58:54 +00:00
|
|
|
for (check = pr.types; check; check = check->next) {
|
|
|
|
if (check->type != type->type
|
|
|
|
|| check->aux_type != type->aux_type
|
|
|
|
|| check->num_parms != type->num_parms)
|
|
|
|
continue;
|
|
|
|
|
2001-06-19 07:28:50 +00:00
|
|
|
if (check->type != ev_func)
|
|
|
|
return check;
|
|
|
|
|
|
|
|
if (check->num_parms == -1)
|
|
|
|
return check;
|
|
|
|
|
2001-02-24 06:58:54 +00:00
|
|
|
for (i = 0; i < type->num_parms; i++)
|
|
|
|
if (check->parm_types[i] != type->parm_types[i])
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == type->num_parms)
|
|
|
|
return check;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocate a new one
|
|
|
|
check = malloc (sizeof (*check));
|
2001-10-24 22:50:06 +00:00
|
|
|
if (!check)
|
|
|
|
Sys_Error ("PR_FindType: Memory Allocation Failure\n");
|
2001-02-24 06:58:54 +00:00
|
|
|
*check = *type;
|
|
|
|
check->next = pr.types;
|
|
|
|
pr.types = check;
|
|
|
|
|
|
|
|
// allocate a generic def for the type, so fields can reference it
|
|
|
|
def = malloc (sizeof (def_t));
|
2001-12-08 08:19:48 +00:00
|
|
|
if (!def)
|
2001-10-24 22:50:06 +00:00
|
|
|
Sys_Error ("PR_FindType: Memory Allocation Failure\n");
|
2001-02-24 06:58:54 +00:00
|
|
|
def->name = "COMPLEX TYPE";
|
|
|
|
def->type = check;
|
|
|
|
check->def = def;
|
|
|
|
return check;
|
|
|
|
}
|