From 2d362c445c79825cc62bcf4622b48cd19b6c1a31 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 17 Apr 2024 18:17:08 +0900 Subject: [PATCH] [qfcc] Move keyword and directive structs The end goal is to share the tokenisation between the C-like languages, and maybe even Pascal. --- tools/qfcc/include/rua-lang.h | 13 ++++++++ tools/qfcc/source/glsl-parse.y | 11 ------- tools/qfcc/source/qc-lex.l | 11 ------- tools/qfcc/source/qp-lex.l | 58 +++++++++++++++------------------- 4 files changed, 39 insertions(+), 54 deletions(-) diff --git a/tools/qfcc/include/rua-lang.h b/tools/qfcc/include/rua-lang.h index f03de98fb..f7bc6c669 100644 --- a/tools/qfcc/include/rua-lang.h +++ b/tools/qfcc/include/rua-lang.h @@ -30,6 +30,19 @@ #include "QF/dstring.h" +#include "specifier.h" + +typedef struct keyword_s { + const char *name; + int value; + specifier_t spec; +} keyword_t; + +typedef struct directive_s { + const char *name; + int value; +} directive_t; + typedef struct rua_loc_s { int line, column; int last_line, last_column; diff --git a/tools/qfcc/source/glsl-parse.y b/tools/qfcc/source/glsl-parse.y index 2cad72112..1b561b734 100644 --- a/tools/qfcc/source/glsl-parse.y +++ b/tools/qfcc/source/glsl-parse.y @@ -1548,17 +1548,6 @@ identifier %% -typedef struct keyword_s { - const char *name; - int value; - specifier_t spec; -} keyword_t; - -typedef struct directive_s { - const char *name; - int value; -} directive_t; - static __attribute__((used)) keyword_t glsl_keywords[] = { {"const", 0}, {"uniform", 0}, diff --git a/tools/qfcc/source/qc-lex.l b/tools/qfcc/source/qc-lex.l index 4a17412e3..fa9a5567b 100644 --- a/tools/qfcc/source/qc-lex.l +++ b/tools/qfcc/source/qc-lex.l @@ -371,17 +371,6 @@ pp_vnumber '({s}*{m}?{pp_number}){2,4}{s}*'{ULFD}? #define ARRCOUNT(_k) (sizeof (_k) / sizeof (_k[0])) -typedef struct keyword_s { - const char *name; - int value; - specifier_t spec; -} keyword_t; - -typedef struct directive_s { - const char *name; - int value; -} directive_t; - // preprocessor directives in ruamoko and quakec static directive_t rua_directives[] = { {"include", PRE_INCLUDE}, diff --git a/tools/qfcc/source/qp-lex.l b/tools/qfcc/source/qp-lex.l index 7751755ca..458c33c8c 100644 --- a/tools/qfcc/source/qp-lex.l +++ b/tools/qfcc/source/qp-lex.l @@ -210,40 +210,34 @@ FRAMEID {ID}(\.{ID})* %% -typedef struct { - const char *name; - int value; - type_t *type; -} keyword_t; - static keyword_t keywords[] = { - {"real", TYPE, &type_float}, - {"string", TYPE, &type_string}, - {"vector", TYPE, &type_vector}, - {"entity", TYPE, &type_entity}, - {"quaternion", TYPE, &type_quaternion}, - {"integer", TYPE, &type_int}, + {"real", TYPE, .spec = { .type = &type_float } }, + {"string", TYPE, .spec = { .type = &type_string } }, + {"vector", TYPE, .spec = { .type = &type_vector } }, + {"entity", TYPE, .spec = { .type = &type_entity } }, + {"quaternion", TYPE, .spec = { .type = &type_quaternion } }, + {"integer", TYPE, .spec = { .type = &type_int } }, - {"program", PROGRAM, 0}, - {"var", VAR, 0}, - {"array", ARRAY, 0}, - {"of", OF, 0}, - {"function", FUNCTION, 0}, - {"procedure", PROCEDURE, 0}, - {"begin", PBEGIN, 0}, - {"end", END, 0}, - {"if", IF, 0}, - {"then", THEN, 0}, - {"else", ELSE, 0}, - {"while", WHILE, 0}, - {"do", DO, 0}, - {"or", ADDOP, 0}, - {"div", MULOP, 0}, - {"mod", MULOP, 0}, - {"and", MULOP, 0}, - {"not", NOT, 0}, + {"program", PROGRAM, .spec = {} }, + {"var", VAR, .spec = {} }, + {"array", ARRAY, .spec = {} }, + {"of", OF, .spec = {} }, + {"function", FUNCTION, .spec = {} }, + {"procedure", PROCEDURE, .spec = {} }, + {"begin", PBEGIN, .spec = {} }, + {"end", END, .spec = {} }, + {"if", IF, .spec = {} }, + {"then", THEN, .spec = {} }, + {"else", ELSE, .spec = {} }, + {"while", WHILE, .spec = {} }, + {"do", DO, .spec = {} }, + {"or", ADDOP, .spec = {} }, + {"div", MULOP, .spec = {} }, + {"mod", MULOP, .spec = {} }, + {"and", MULOP, .spec = {} }, + {"not", NOT, .spec = {} }, - {"return", RETURN, 0}, + {"return", RETURN, .spec = {} }, }; static const char * @@ -270,7 +264,7 @@ keyword_or_id (YYSTYPE *lval, const char *token) if (keyword->value == ADDOP || keyword->value == MULOP) { lval->op = token[0]; } else { - lval->type = keyword->type; + lval->type = keyword->spec.type; } return keyword->value; }