mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-25 21:21:14 +00:00
[qfcc] Use macro magic for the symbol type enum
I found that I'd missed an update or two of the names array.
This commit is contained in:
parent
b1f4fc3131
commit
f7f2790937
7 changed files with 66 additions and 29 deletions
|
@ -51,7 +51,6 @@ typedef enum {
|
||||||
#include "tools/qfcc/include/expr_names.h"
|
#include "tools/qfcc/include/expr_names.h"
|
||||||
ex_count, ///< number of valid expression types
|
ex_count, ///< number of valid expression types
|
||||||
} expr_type;
|
} expr_type;
|
||||||
#undef EX_EXPR
|
|
||||||
|
|
||||||
/** Binary and unary expressions.
|
/** Binary and unary expressions.
|
||||||
|
|
||||||
|
|
|
@ -70,4 +70,6 @@ EX_EXPR(multivec) ///< geometric algebra multivector (::ex_multivec_t)
|
||||||
EX_EXPR(list) ///< non-invasive list of expressions (::ex_list_t)
|
EX_EXPR(list) ///< non-invasive list of expressions (::ex_list_t)
|
||||||
EX_EXPR(type) ///< type expression for generics
|
EX_EXPR(type) ///< type expression for generics
|
||||||
|
|
||||||
|
#undef EX_EXPR
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
52
tools/qfcc/include/sy_type_names.h
Normal file
52
tools/qfcc/include/sy_type_names.h
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
sy_type_names.h
|
||||||
|
|
||||||
|
Symbol type names
|
||||||
|
|
||||||
|
Copyright (C) 2011 Bill Currie <bill@taniwha.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
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** \defgroup qfcc_symtab_sy_type_names Symbol Types
|
||||||
|
\ingroup qfcc_symtab
|
||||||
|
*/
|
||||||
|
///@{
|
||||||
|
|
||||||
|
#ifndef SY_TYPE
|
||||||
|
#define SY_TYPE(type)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SY_TYPE(name) ///< just a name (referent tbd)
|
||||||
|
SY_TYPE(var) ///< symbol refers to a variable
|
||||||
|
SY_TYPE(const) ///< symbol refers to a constant
|
||||||
|
SY_TYPE(type) ///< symbol refers to a type
|
||||||
|
SY_TYPE(type_param) ///< symbol refers to a generic type parameter
|
||||||
|
SY_TYPE(expr) ///< symbol refers to an expression
|
||||||
|
SY_TYPE(func) ///< symbol refers to a function
|
||||||
|
SY_TYPE(class) ///< symbol refers to a class
|
||||||
|
SY_TYPE(convert) ///< symbol refers to a conversion function
|
||||||
|
SY_TYPE(macro) ///< symbol refers to a macro definition
|
||||||
|
SY_TYPE(namespace) ///< symbol refers to a namespace definition
|
||||||
|
SY_TYPE(list)
|
||||||
|
|
||||||
|
#undef SY_TYPE
|
||||||
|
|
||||||
|
///@}
|
|
@ -48,19 +48,10 @@ typedef enum vis_e {
|
||||||
vis_anonymous,
|
vis_anonymous,
|
||||||
} vis_t;
|
} vis_t;
|
||||||
|
|
||||||
typedef enum {
|
#define SY_TYPE(type) sy_##type,
|
||||||
sy_name, ///< just a name (referent tbd)
|
typedef enum : unsigned {
|
||||||
sy_var, ///< symbol refers to a variable
|
#include "tools/qfcc/include/sy_type_names.h"
|
||||||
sy_const, ///< symbol refers to a constant
|
sy_num_types ///< number of symtab types
|
||||||
sy_type, ///< symbol refers to a type
|
|
||||||
sy_type_param, ///< symbol refers to a generic type parameter
|
|
||||||
sy_expr, ///< symbol refers to an expression
|
|
||||||
sy_func, ///< symbol refers to a function
|
|
||||||
sy_class, ///< symbol refers to a class
|
|
||||||
sy_convert, ///< symbol refers to a conversion function
|
|
||||||
sy_macro, ///< symbol refers to a macro definition
|
|
||||||
sy_namespace, ///< symbol refers to a namespace definition
|
|
||||||
sy_list,
|
|
||||||
} sy_type_e;
|
} sy_type_e;
|
||||||
|
|
||||||
typedef struct symconv_s {
|
typedef struct symconv_s {
|
||||||
|
|
|
@ -62,7 +62,6 @@ const char *expr_names[] =
|
||||||
#include "tools/qfcc/include/expr_names.h"
|
#include "tools/qfcc/include/expr_names.h"
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
#undef EX_EXPR
|
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
get_op_string (int op)
|
get_op_string (int op)
|
||||||
|
|
|
@ -109,6 +109,7 @@ is_lvalue (const expr_t *expr)
|
||||||
case sy_macro:
|
case sy_macro:
|
||||||
case sy_namespace:
|
case sy_namespace:
|
||||||
case sy_list:
|
case sy_list:
|
||||||
|
case sy_num_types:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -52,26 +52,19 @@
|
||||||
ALLOC_STATE (symtab_t, symtabs);
|
ALLOC_STATE (symtab_t, symtabs);
|
||||||
ALLOC_STATE (symbol_t, symbols);
|
ALLOC_STATE (symbol_t, symbols);
|
||||||
|
|
||||||
static const char * const sy_type_names[] = {
|
#define SY_TYPE(type) #type,
|
||||||
"sy_name",
|
static const char * const sy_type_names[sy_num_types] = {
|
||||||
"sy_var",
|
#include "tools/qfcc/include/sy_type_names.h"
|
||||||
"sy_const",
|
|
||||||
"sy_type",
|
|
||||||
"sy_type_param",
|
|
||||||
"sy_expr",
|
|
||||||
"sy_func",
|
|
||||||
"sy_class",
|
|
||||||
"sy_convert",
|
|
||||||
"sy_macro",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
symtype_str (sy_type_e type)
|
symtype_str (sy_type_e type)
|
||||||
{
|
{
|
||||||
if (type > sy_convert)
|
if (type < sy_num_types) {
|
||||||
return "<invalid sy_type>";
|
|
||||||
return sy_type_names[type];
|
return sy_type_names[type];
|
||||||
}
|
}
|
||||||
|
return "<invalid sy_type>";
|
||||||
|
}
|
||||||
|
|
||||||
symbol_t *
|
symbol_t *
|
||||||
new_symbol (const char *name)
|
new_symbol (const char *name)
|
||||||
|
|
Loading…
Reference in a new issue