2001-06-12 21:06:28 +00:00
|
|
|
%{
|
2001-09-28 07:09:38 +00:00
|
|
|
/*
|
2002-11-06 16:32:28 +00:00
|
|
|
qc-lex.l
|
2001-09-28 07:09:38 +00:00
|
|
|
|
2002-11-06 16:32:28 +00:00
|
|
|
lexer for quakec
|
2001-09-28 07:09:38 +00:00
|
|
|
|
2002-11-06 16:32:28 +00:00
|
|
|
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
|
2001-09-28 07:09:38 +00:00
|
|
|
|
2002-11-06 16:32:28 +00:00
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2001/06/12
|
2001-09-28 07:09:38 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
2002-06-01 04:41:25 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-14 20:18:29 +00:00
|
|
|
|
2002-06-01 04:41:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2002-06-27 22:48:28 +00:00
|
|
|
#include <QF/dstring.h>
|
2001-06-13 07:16:39 +00:00
|
|
|
#include <QF/hash.h>
|
2001-10-24 22:50:06 +00:00
|
|
|
#include <QF/sys.h>
|
2002-06-27 22:48:28 +00:00
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "tools/qfcc/include/class.h"
|
|
|
|
#include "tools/qfcc/include/debug.h"
|
|
|
|
#include "tools/qfcc/include/diagnostic.h"
|
|
|
|
#include "tools/qfcc/include/expr.h"
|
|
|
|
#include "tools/qfcc/include/grab.h"
|
|
|
|
#include "tools/qfcc/include/options.h"
|
|
|
|
#include "tools/qfcc/include/pragma.h"
|
|
|
|
#include "tools/qfcc/include/qfcc.h"
|
|
|
|
#include "tools/qfcc/include/shared.h"
|
|
|
|
#include "tools/qfcc/include/strpool.h"
|
|
|
|
#include "tools/qfcc/include/struct.h"
|
|
|
|
#include "tools/qfcc/include/symtab.h"
|
|
|
|
#include "tools/qfcc/include/type.h"
|
|
|
|
#include "tools/qfcc/include/value.h"
|
|
|
|
|
|
|
|
#include "tools/qfcc/source/qc-parse.h"
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2003-04-16 19:41:52 +00:00
|
|
|
#ifndef YY_PROTO
|
|
|
|
# define YY_PROTO(x) x
|
|
|
|
#else
|
|
|
|
# define YY_FLEX_REALLOC_HACK
|
|
|
|
#endif
|
|
|
|
|
2001-06-12 21:06:28 +00:00
|
|
|
#define YY_NO_UNPUT
|
2003-01-06 18:28:13 +00:00
|
|
|
#define YY_DECL int yylex YY_PROTO(( void ))
|
|
|
|
YY_DECL;
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2018-10-09 03:35:01 +00:00
|
|
|
int yyget_lineno (void) __attribute__((pure));
|
|
|
|
int yyget_leng (void) __attribute__((pure));
|
|
|
|
int yywrap (void) __attribute__((const));
|
|
|
|
char *yyget_text (void) __attribute__((pure));
|
|
|
|
int yyget_debug (void) __attribute__((pure));
|
|
|
|
FILE *yyget_in (void) __attribute__((pure));
|
|
|
|
FILE *yyget_out (void) __attribute__((pure));
|
2003-04-16 19:41:52 +00:00
|
|
|
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
static int keyword_or_id (const char *token);
|
|
|
|
static expr_t *parse_float_vector (const char *token, int width);
|
|
|
|
static expr_t *parse_int_vector (const char *token, int width);
|
2001-06-25 22:11:20 +00:00
|
|
|
|
2012-10-26 07:01:41 +00:00
|
|
|
extern QC_YYSTYPE qc_yylval;
|
2001-06-13 07:16:39 +00:00
|
|
|
|
2001-06-12 21:06:28 +00:00
|
|
|
%}
|
|
|
|
|
2011-01-14 03:10:28 +00:00
|
|
|
s [ \t]
|
|
|
|
m [\-+]
|
|
|
|
D [0-9]
|
2013-01-04 10:32:04 +00:00
|
|
|
B [01]
|
2011-01-14 03:10:28 +00:00
|
|
|
X [0-9a-fA-F]
|
|
|
|
ID [a-zA-Z_][a-zA-Z_0-9]*
|
|
|
|
FLOAT ({D}+|{D}*\.{D}+|{D}+\.{D}*)([eE]{m}?{D}+)?
|
2020-02-14 11:08:59 +00:00
|
|
|
FLOATf {FLOAT}[fF]
|
|
|
|
FLOATd {FLOAT}[dD]
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
FCOMP {m}?{FLOAT}
|
|
|
|
FD [fFdD]
|
2013-01-04 10:32:04 +00:00
|
|
|
INT ({D}+|0[xX]{X}+|0[bB]{B})
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
ICOMP {m}?{INT}
|
|
|
|
UL ([uU]?([lL][lL]?)?)
|
|
|
|
ULFD ({UL}|{FD})
|
2011-01-14 03:10:28 +00:00
|
|
|
RANGE \.\.
|
|
|
|
ELLIPSIS \.\.\.
|
|
|
|
FRAMEID {ID}(\.{ID})*
|
2012-11-22 11:42:00 +00:00
|
|
|
PRAGMAID {ID}(-{ID})*
|
2011-01-17 13:33:33 +00:00
|
|
|
STRING \"(\\.|[^"\\])*\"
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2012-12-13 11:17:28 +00:00
|
|
|
%x GRAB_FRAME GRAB_OTHER GRAB_WRITE COMMENT PRAGMA
|
2001-06-13 18:35:41 +00:00
|
|
|
|
2001-06-12 21:06:28 +00:00
|
|
|
%%
|
2011-01-06 07:30:25 +00:00
|
|
|
grab_frame = GRAB_FRAME;
|
|
|
|
grab_other = GRAB_OTHER;
|
2012-11-21 11:50:45 +00:00
|
|
|
grab_write = GRAB_WRITE;
|
2011-01-06 07:30:25 +00:00
|
|
|
|
|
|
|
"/*" { BEGIN (COMMENT); }
|
|
|
|
<COMMENT>"/*" { warning (0, "nested /* in comment"); }
|
|
|
|
<COMMENT>"*/" { BEGIN (INITIAL); }
|
|
|
|
<COMMENT>\r*\n { pr.source_line++; }
|
|
|
|
<COMMENT>. /* nothing to do */
|
|
|
|
<COMMENT><<EOF>> { error (0, "EOF in comment"); return 0; }
|
2007-03-30 09:02:36 +00:00
|
|
|
"//".* /* nothing to do */
|
2001-06-13 07:16:39 +00:00
|
|
|
|
2011-01-14 03:10:28 +00:00
|
|
|
^#{s}+{D}+{s}+\"(\.|[^"\n])*\".*$ { line_info (yytext + 1); }
|
|
|
|
^#line{s}+{D}+{s}+\"(\.|[^"\n])*\".*$ { line_info (yytext + 5); }
|
2007-04-06 05:52:20 +00:00
|
|
|
|
2012-11-22 11:42:00 +00:00
|
|
|
^{s}*#{s}*pragma{s}+ { BEGIN (PRAGMA); }
|
2007-04-06 05:52:20 +00:00
|
|
|
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
{INT}+{UL}? {
|
2010-12-23 10:32:28 +00:00
|
|
|
const char *c = yytext + yyleng - 1;
|
2022-04-29 06:38:55 +00:00
|
|
|
pr_long_t i;
|
2013-01-04 10:32:04 +00:00
|
|
|
|
|
|
|
if (yytext[0] == '0' && tolower (yytext[1] == 'b'))
|
|
|
|
i = strtol (yytext + 2, 0, 2);
|
|
|
|
else
|
|
|
|
i = strtol (yytext, 0, 0);
|
2022-04-29 06:38:55 +00:00
|
|
|
if (tolower (*c) == 'u') {
|
|
|
|
if (tolower (c[1]) == 'l') {
|
|
|
|
qc_yylval.expr = new_ulong_expr (i);
|
|
|
|
} else {
|
|
|
|
qc_yylval.expr = new_uint_expr (i);
|
|
|
|
}
|
2022-04-29 06:27:12 +00:00
|
|
|
} else {
|
2022-04-29 06:38:55 +00:00
|
|
|
if (tolower (c[1]) == 'l') {
|
|
|
|
qc_yylval.expr = new_long_expr (i);
|
|
|
|
} else {
|
|
|
|
qc_yylval.expr = new_int_expr (i);
|
|
|
|
qc_yylval.expr->implicit = 1;
|
|
|
|
}
|
2022-04-29 06:27:12 +00:00
|
|
|
}
|
2012-12-18 04:59:45 +00:00
|
|
|
return VALUE;
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2011-01-14 03:10:28 +00:00
|
|
|
{FLOAT} {
|
2020-02-14 11:08:59 +00:00
|
|
|
// advanced code defaults to double, but traditional
|
|
|
|
// and extended code defaults to float
|
|
|
|
if (options.traditional < 1) {
|
|
|
|
double d = strtod (yytext, 0);
|
|
|
|
qc_yylval.expr = new_double_expr (d);
|
2020-02-23 13:28:54 +00:00
|
|
|
qc_yylval.expr->implicit = 1;
|
2020-02-14 11:08:59 +00:00
|
|
|
} else {
|
|
|
|
float f = strtof (yytext, 0);
|
|
|
|
qc_yylval.expr = new_float_expr (f);
|
|
|
|
}
|
|
|
|
return VALUE;
|
|
|
|
}
|
|
|
|
{FLOATf} {
|
2011-01-14 03:10:28 +00:00
|
|
|
float f = strtof (yytext, 0);
|
2012-10-26 07:01:41 +00:00
|
|
|
qc_yylval.expr = new_float_expr (f);
|
2012-12-18 04:59:45 +00:00
|
|
|
return VALUE;
|
2002-10-26 03:23:19 +00:00
|
|
|
}
|
2020-02-14 11:08:59 +00:00
|
|
|
{FLOATd} {
|
|
|
|
// advanced code defaults to double, but traditional
|
|
|
|
// and extended code defaults to float
|
|
|
|
if (options.traditional < 1) {
|
|
|
|
double d = strtod (yytext, 0);
|
|
|
|
qc_yylval.expr = new_double_expr (d);
|
|
|
|
} else {
|
|
|
|
float f = strtof (yytext, 0);
|
|
|
|
qc_yylval.expr = new_float_expr (f);
|
|
|
|
warning (0, "truncating double constant to float");
|
|
|
|
}
|
|
|
|
return VALUE;
|
|
|
|
}
|
2002-10-26 03:23:19 +00:00
|
|
|
|
2011-01-14 03:10:28 +00:00
|
|
|
{ID} {
|
|
|
|
int tok = keyword_or_id(yytext);
|
|
|
|
return tok;
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
@{ID} {
|
2011-01-14 03:10:28 +00:00
|
|
|
int tok = keyword_or_id(yytext);
|
2002-05-07 16:55:54 +00:00
|
|
|
if (tok == '@')
|
|
|
|
REJECT;
|
|
|
|
return tok;
|
|
|
|
}
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2011-01-17 13:33:33 +00:00
|
|
|
{STRING} {
|
2011-01-14 03:10:28 +00:00
|
|
|
const char *s = make_string (yytext, 0);
|
2012-10-26 07:01:41 +00:00
|
|
|
qc_yylval.expr = new_string_expr (s);
|
2011-01-17 13:33:33 +00:00
|
|
|
return STRING;
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
2011-01-17 13:33:33 +00:00
|
|
|
@ return '@';
|
2001-06-13 07:16:39 +00:00
|
|
|
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
'{s}*{ICOMP}{s}+{ICOMP}{s}*'{ULFD}? {
|
|
|
|
qc_yylval.expr = parse_int_vector (yytext, 2);
|
2012-12-18 04:59:45 +00:00
|
|
|
return VALUE;
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
|
|
|
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
'{s}*{ICOMP}{s}+{ICOMP}{s}+{ICOMP}{s}*'{ULFD}? {
|
|
|
|
qc_yylval.expr = parse_int_vector (yytext, 3);
|
|
|
|
return VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
'{s}*{ICOMP}{s}+{ICOMP}{s}+{ICOMP}{s}+{ICOMP}{s}*'{ULFD}? {
|
|
|
|
qc_yylval.expr = parse_int_vector (yytext, 4);
|
|
|
|
return VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
'{s}*{FCOMP}{s}+{FCOMP}{s}*'{FD}? {
|
|
|
|
qc_yylval.expr = parse_float_vector (yytext, 2);
|
|
|
|
return VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
'{s}*{FCOMP}{s}+{FCOMP}{s}+{FCOMP}{s}*'{FD}? {
|
|
|
|
qc_yylval.expr = parse_float_vector (yytext, 3);
|
|
|
|
return VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
'{s}*{FCOMP}{s}+{FCOMP}{s}+{FCOMP}{s}+{FCOMP}{s}*'{FD}? {
|
|
|
|
qc_yylval.expr = parse_float_vector (yytext, 4);
|
2012-12-18 04:59:45 +00:00
|
|
|
return VALUE;
|
2002-01-04 08:45:24 +00:00
|
|
|
}
|
|
|
|
|
2002-01-04 17:13:13 +00:00
|
|
|
'(\\[^xX0-7\r\n]|[^'\r\n]|\\[xX][0-9A-Fa-f]+|\\[0-7]+)*' {
|
2007-03-31 15:27:36 +00:00
|
|
|
const char *str = make_string (yytext, 0);
|
2002-01-04 08:45:24 +00:00
|
|
|
|
|
|
|
if (str[1])
|
|
|
|
warning (0, "multibyte char constant");
|
2022-01-18 04:21:06 +00:00
|
|
|
qc_yylval.expr = new_int_expr (*str);
|
2012-12-18 04:59:45 +00:00
|
|
|
return VALUE;
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
|
|
|
|
2001-08-20 06:22:28 +00:00
|
|
|
[+\-*/&|^%]= {
|
2012-10-26 07:01:41 +00:00
|
|
|
qc_yylval.op = yytext[0];
|
2001-08-20 06:22:28 +00:00
|
|
|
return ASX;
|
|
|
|
}
|
|
|
|
|
2020-02-16 02:57:58 +00:00
|
|
|
"%%=" {
|
|
|
|
qc_yylval.op = MOD;
|
|
|
|
return ASX;
|
|
|
|
}
|
|
|
|
|
2001-08-20 06:22:28 +00:00
|
|
|
"<<=" {
|
2012-10-26 07:01:41 +00:00
|
|
|
qc_yylval.op = SHL;
|
2001-08-20 06:22:28 +00:00
|
|
|
return ASX;
|
|
|
|
}
|
|
|
|
|
|
|
|
">>=" {
|
2012-10-26 07:01:41 +00:00
|
|
|
qc_yylval.op = SHR;
|
2001-08-20 06:22:28 +00:00
|
|
|
return ASX;
|
|
|
|
}
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
[!(){}.*/&|^~+\-=\[\];,#%?:] {
|
2012-10-26 07:01:41 +00:00
|
|
|
qc_yylval.pointer = 0; // ensure pointer vals are null
|
2002-05-01 21:35:39 +00:00
|
|
|
return yytext[0];
|
|
|
|
}
|
2001-06-13 07:16:39 +00:00
|
|
|
|
2020-02-16 02:57:58 +00:00
|
|
|
"%%" {
|
|
|
|
qc_yylval.pointer = 0; // ensure pointer vals are null
|
|
|
|
return MOD;
|
|
|
|
}
|
|
|
|
|
2011-01-14 03:10:28 +00:00
|
|
|
{ELLIPSIS} return ELLIPSIS;
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2011-01-14 03:10:28 +00:00
|
|
|
"<<" return SHL;
|
|
|
|
">>" return SHR;
|
2001-08-10 16:17:00 +00:00
|
|
|
|
2011-01-14 03:10:28 +00:00
|
|
|
"&&" return AND;
|
|
|
|
"||" return OR;
|
|
|
|
"==" return EQ;
|
|
|
|
"!=" return NE;
|
|
|
|
"<=" return LE;
|
|
|
|
">=" return GE;
|
|
|
|
"<" return LT;
|
|
|
|
">" return GT;
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2001-08-20 06:22:28 +00:00
|
|
|
"++" {
|
2012-10-26 07:01:41 +00:00
|
|
|
qc_yylval.op = '+';
|
2001-08-20 06:22:28 +00:00
|
|
|
return INCOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
"--" {
|
2012-10-26 07:01:41 +00:00
|
|
|
qc_yylval.op = '-';
|
2001-08-20 06:22:28 +00:00
|
|
|
return INCOP;
|
|
|
|
}
|
|
|
|
|
2007-04-06 08:19:58 +00:00
|
|
|
"$"{s}*{FRAMEID} {
|
2007-04-06 05:52:20 +00:00
|
|
|
int ret = do_grab (yytext);
|
2011-01-06 07:30:25 +00:00
|
|
|
if (ret >= 0) {
|
2022-01-18 04:21:06 +00:00
|
|
|
qc_yylval.expr = new_int_expr (ret);
|
2012-12-18 04:59:45 +00:00
|
|
|
return VALUE;
|
2011-01-06 07:30:25 +00:00
|
|
|
} else {
|
2001-06-13 18:35:41 +00:00
|
|
|
BEGIN (-ret);
|
2011-01-06 07:30:25 +00:00
|
|
|
}
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2011-01-06 07:30:25 +00:00
|
|
|
<GRAB_FRAME>{FRAMEID} add_frame_macro (yytext);
|
|
|
|
<GRAB_OTHER>[^\r\n]* /* skip */
|
2012-11-21 11:50:45 +00:00
|
|
|
<GRAB_WRITE>{STRING} {
|
|
|
|
const char *s = make_string (yytext, 0);
|
|
|
|
write_frame_macros (s);
|
|
|
|
BEGIN (GRAB_OTHER); // ignore rest of line
|
|
|
|
}
|
2020-02-15 10:41:20 +00:00
|
|
|
<PRAGMA>{ID} { pragma_add_arg (yytext); }
|
2022-02-06 11:05:35 +00:00
|
|
|
<PRAGMA>@{ID} { pragma_add_arg (yytext); }
|
2001-06-13 18:35:41 +00:00
|
|
|
|
2002-01-04 18:27:01 +00:00
|
|
|
<*>\r*\n {
|
2020-02-15 10:41:20 +00:00
|
|
|
if (YY_START == PRAGMA) {
|
|
|
|
pragma_process ();
|
|
|
|
}
|
2002-07-03 21:32:03 +00:00
|
|
|
pr.source_line++;
|
2001-06-13 18:35:41 +00:00
|
|
|
BEGIN (INITIAL);
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2001-06-13 18:35:41 +00:00
|
|
|
<*>{s}* /* skip */
|
2001-06-13 07:16:39 +00:00
|
|
|
|
2001-06-28 21:26:40 +00:00
|
|
|
<*>. error (0, "all your typo are belong to us");
|
2001-06-12 21:06:28 +00:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
int
|
|
|
|
yywrap (void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2001-06-13 07:16:39 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2011-01-17 13:33:33 +00:00
|
|
|
const char *name;
|
|
|
|
int value;
|
|
|
|
type_t *type;
|
2001-06-13 07:16:39 +00:00
|
|
|
} keyword_t;
|
|
|
|
|
2022-02-03 15:25:31 +00:00
|
|
|
// These keywords are part of the Ruamoko language and require the QuakeForge
|
|
|
|
// Ruamoko VM.
|
|
|
|
static keyword_t rua_keywords[] = {
|
|
|
|
#define VEC_TYPE(type_name, base_type) { #type_name, TYPE, &type_##type_name },
|
|
|
|
#include "tools/qfcc/include/vec_types.h"
|
|
|
|
};
|
|
|
|
|
2012-12-22 07:31:14 +00:00
|
|
|
// These keywords are all part of the Ruamoko (Objective-QC) language.
|
|
|
|
// The first time any one of them is encountered, the class system will be
|
|
|
|
// initialized.
|
|
|
|
// If not compiling for the QuakeForge VM, or if Ruamoko has been disabled,
|
|
|
|
// then they will be unavailable as keywords.
|
|
|
|
static keyword_t obj_keywords[] = {
|
|
|
|
{"id", OBJECT, &type_id },
|
|
|
|
{"Class", TYPE, &type_Class },
|
2020-03-27 06:33:53 +00:00
|
|
|
{"Method", TYPE, &type_method },
|
|
|
|
{"Super", TYPE, &type_super },
|
2012-12-22 07:31:14 +00:00
|
|
|
{"SEL", TYPE, &type_SEL },
|
|
|
|
{"IMP", TYPE, &type_IMP },
|
|
|
|
|
|
|
|
{"@class", CLASS },
|
|
|
|
{"@defs", DEFS },
|
|
|
|
{"@encode", ENCODE },
|
|
|
|
{"@end", END },
|
|
|
|
{"@implementation", IMPLEMENTATION },
|
|
|
|
{"@interface", INTERFACE },
|
|
|
|
{"@private", PRIVATE },
|
|
|
|
{"@protected", PROTECTED },
|
|
|
|
{"@protocol", PROTOCOL },
|
|
|
|
{"@public", PUBLIC },
|
|
|
|
{"@reference", REFERENCE },
|
|
|
|
{"@selector", SELECTOR },
|
|
|
|
{"@self", SELF },
|
|
|
|
{"@this", THIS },
|
|
|
|
|
|
|
|
// This is a hack to trigger the initialization of the class
|
|
|
|
// sytem if it is seen before any other Objective-QC symbol. Otherwise,
|
|
|
|
// it is just an identifier, though it does reference a built-in type
|
|
|
|
// created by the class system.
|
|
|
|
{"obj_module", 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
// These keywords are extensions to QC and thus available only in advanced
|
|
|
|
// or extended code. However, if they are preceeded by an @ (eg, @for), then
|
|
|
|
// they are always available. This is to prevent them from causing trouble
|
|
|
|
// for traditional code that might use these words as identifiers, but still
|
|
|
|
// make the language features available to traditional code.
|
|
|
|
static keyword_t at_keywords[] = {
|
|
|
|
{"for", FOR },
|
2020-03-11 03:53:40 +00:00
|
|
|
{"goto", GOTO },
|
2012-12-22 07:31:14 +00:00
|
|
|
{"break", BREAK },
|
|
|
|
{"continue", CONTINUE},
|
|
|
|
{"switch", SWITCH },
|
|
|
|
{"case", CASE },
|
|
|
|
{"default", DEFAULT },
|
|
|
|
{"nil", NIL },
|
|
|
|
{"struct", STRUCT },
|
|
|
|
{"union", STRUCT },
|
|
|
|
{"enum", ENUM },
|
|
|
|
{"typedef", TYPEDEF },
|
|
|
|
{"extern", EXTERN },
|
|
|
|
{"static", STATIC },
|
|
|
|
{"sizeof", SIZEOF },
|
2012-12-20 01:02:00 +00:00
|
|
|
{"not", NOT },
|
2012-12-22 07:31:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// These keywords require the QuakeForge VM to be of any use. ie, they cannot
|
|
|
|
// be supported (sanely) by v6 progs.
|
|
|
|
static keyword_t qf_keywords[] = {
|
|
|
|
{"quaternion", TYPE, &type_quaternion},
|
2020-02-14 07:38:37 +00:00
|
|
|
{"double", TYPE, &type_double},
|
2022-01-18 04:21:06 +00:00
|
|
|
{"int", TYPE, &type_int },
|
2022-01-19 09:08:58 +00:00
|
|
|
{"unsigned", UNSIGNED, 0 },
|
|
|
|
{"signed", SIGNED, 0 },
|
|
|
|
{"long", LONG, 0 },
|
|
|
|
{"short", SHORT, 0 },
|
2012-12-22 07:31:14 +00:00
|
|
|
|
2022-01-18 13:34:52 +00:00
|
|
|
{"@function", TYPE, &type_func },
|
2012-12-22 07:31:14 +00:00
|
|
|
{"@args", ARGS, 0 },
|
|
|
|
{"@va_list", TYPE, &type_va_list },
|
|
|
|
{"@param", TYPE, &type_param },
|
2022-02-05 09:58:42 +00:00
|
|
|
{"@return", AT_RETURN, 0 },
|
2022-01-30 05:14:15 +00:00
|
|
|
|
|
|
|
{"@cross", CROSS, 0 },
|
|
|
|
{"@dot", DOT, 0 },
|
2022-11-15 15:06:21 +00:00
|
|
|
{"@hadamard", HADAMARD, 0 },
|
2012-12-22 07:31:14 +00:00
|
|
|
};
|
|
|
|
|
2022-02-02 14:51:37 +00:00
|
|
|
// These keywors are always available. Other than the @ keywords, they
|
2012-12-22 07:31:14 +00:00
|
|
|
// form traditional QuakeC.
|
2001-06-13 07:16:39 +00:00
|
|
|
static keyword_t keywords[] = {
|
2012-12-22 07:31:14 +00:00
|
|
|
{"void", TYPE, &type_void },
|
|
|
|
{"float", TYPE, &type_float },
|
|
|
|
{"string", TYPE, &type_string},
|
|
|
|
{"vector", TYPE, &type_vector},
|
|
|
|
{"entity", TYPE, &type_entity},
|
|
|
|
{"local", LOCAL, 0 },
|
|
|
|
{"return", RETURN, 0 },
|
|
|
|
{"while", WHILE, 0 },
|
|
|
|
{"do", DO, 0 },
|
|
|
|
{"if", IF, 0 },
|
|
|
|
{"else", ELSE, 0 },
|
|
|
|
{"@system", SYSTEM, 0 },
|
|
|
|
{"@overload", OVERLOAD, 0 },
|
2022-02-02 14:51:37 +00:00
|
|
|
{"@attribute", ATTRIBUTE, 0 },
|
2001-06-13 07:16:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *
|
2012-07-18 13:34:37 +00:00
|
|
|
keyword_get_key (const void *kw, void *unused)
|
2001-06-13 07:16:39 +00:00
|
|
|
{
|
|
|
|
return ((keyword_t*)kw)->name;
|
|
|
|
}
|
|
|
|
|
2012-12-22 07:31:14 +00:00
|
|
|
static int
|
|
|
|
process_keyword (keyword_t *keyword, const char *token)
|
|
|
|
{
|
|
|
|
if (keyword->value == STRUCT) {
|
|
|
|
qc_yylval.op = token[0];
|
|
|
|
} else if (keyword->value == OBJECT) {
|
|
|
|
symbol_t *sym;
|
|
|
|
|
|
|
|
sym = symtab_lookup (current_symtab, token);
|
|
|
|
qc_yylval.symbol = sym;
|
2022-01-19 12:32:01 +00:00
|
|
|
// the global id symbol is always just a name so attempts to redefine
|
|
|
|
// it globally can be caught and treated as an error, but it needs to
|
|
|
|
// be redefinable when in an enclosing scope.
|
|
|
|
if (sym->sy_type == sy_name) {
|
|
|
|
// this is the global id (object)
|
|
|
|
return OBJECT;
|
|
|
|
} else if (sym->sy_type == sy_type) {
|
|
|
|
// id has been redeclared via a typedef
|
|
|
|
return TYPE_NAME;
|
|
|
|
}
|
|
|
|
// id has been redelcared as a variable (hopefully)
|
|
|
|
return NAME;
|
2012-12-22 07:31:14 +00:00
|
|
|
} else {
|
|
|
|
qc_yylval.type = keyword->type;
|
|
|
|
}
|
|
|
|
return keyword->value;
|
|
|
|
}
|
|
|
|
|
2011-01-06 07:30:25 +00:00
|
|
|
static int
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
keyword_or_id (const char *token)
|
2001-06-13 07:16:39 +00:00
|
|
|
{
|
|
|
|
static hashtab_t *keyword_tab;
|
2012-12-22 07:31:14 +00:00
|
|
|
static hashtab_t *qf_keyword_tab;
|
|
|
|
static hashtab_t *at_keyword_tab;
|
|
|
|
static hashtab_t *obj_keyword_tab;
|
2022-02-03 15:25:31 +00:00
|
|
|
static hashtab_t *rua_keyword_tab;
|
2012-12-22 07:31:14 +00:00
|
|
|
|
|
|
|
keyword_t *keyword = 0;
|
2011-01-17 13:33:33 +00:00
|
|
|
symbol_t *sym;
|
2001-06-13 07:16:39 +00:00
|
|
|
|
2001-12-08 08:19:48 +00:00
|
|
|
if (!keyword_tab) {
|
2007-04-06 05:52:20 +00:00
|
|
|
size_t i;
|
2012-12-22 07:31:14 +00:00
|
|
|
|
2020-03-25 06:43:16 +00:00
|
|
|
keyword_tab = Hash_NewTable (253, keyword_get_key, 0, 0, 0);
|
|
|
|
qf_keyword_tab = Hash_NewTable (253, keyword_get_key, 0, 0, 0);
|
|
|
|
at_keyword_tab = Hash_NewTable (253, keyword_get_key, 0, 0, 0);
|
|
|
|
obj_keyword_tab = Hash_NewTable (253, keyword_get_key, 0, 0, 0);
|
2022-02-03 15:25:31 +00:00
|
|
|
rua_keyword_tab = Hash_NewTable (253, keyword_get_key, 0, 0, 0);
|
2012-12-22 07:31:14 +00:00
|
|
|
|
|
|
|
#define NUMKEYS(_k) (sizeof (_k) / sizeof (_k[0]))
|
|
|
|
|
|
|
|
for (i = 0; i < NUMKEYS(keywords); i++)
|
|
|
|
Hash_Add (keyword_tab, &keywords[i]);
|
|
|
|
for (i = 0; i < NUMKEYS(qf_keywords); i++)
|
|
|
|
Hash_Add (qf_keyword_tab, &qf_keywords[i]);
|
|
|
|
for (i = 0; i < NUMKEYS(at_keywords); i++)
|
|
|
|
Hash_Add (at_keyword_tab, &at_keywords[i]);
|
|
|
|
for (i = 0; i < NUMKEYS(obj_keywords); i++)
|
|
|
|
Hash_Add (obj_keyword_tab, &obj_keywords[i]);
|
2022-02-03 15:25:31 +00:00
|
|
|
for (i = 0; i < NUMKEYS(rua_keywords); i++)
|
|
|
|
Hash_Add (rua_keyword_tab, &rua_keywords[i]);
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
2012-12-22 07:31:14 +00:00
|
|
|
if (options.traditional < 1) {
|
2022-02-03 15:25:31 +00:00
|
|
|
if (options.code.progsversion == PROG_VERSION) {
|
|
|
|
keyword = Hash_Find (rua_keyword_tab, token);
|
|
|
|
}
|
|
|
|
if (!keyword) {
|
|
|
|
keyword = Hash_Find (obj_keyword_tab, token);
|
|
|
|
if (keyword) {
|
|
|
|
if (!obj_initialized)
|
|
|
|
class_init ();
|
|
|
|
}
|
2011-01-17 13:33:33 +00:00
|
|
|
}
|
2012-12-22 07:31:14 +00:00
|
|
|
if (!keyword)
|
|
|
|
keyword = Hash_Find (qf_keyword_tab, token);
|
|
|
|
}
|
|
|
|
if (!keyword && options.traditional < 2)
|
|
|
|
keyword = Hash_Find (at_keyword_tab, token);
|
|
|
|
if (!keyword && token[0] == '@') {
|
|
|
|
keyword = Hash_Find (at_keyword_tab, token + 1);
|
|
|
|
if (keyword)
|
|
|
|
token += 1;
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
2012-12-22 07:31:14 +00:00
|
|
|
if (!keyword)
|
|
|
|
keyword = Hash_Find (keyword_tab, token);
|
|
|
|
if (keyword && keyword->value)
|
|
|
|
return process_keyword (keyword, token);
|
2002-05-07 16:55:54 +00:00
|
|
|
if (token[0] == '@') {
|
|
|
|
return '@';
|
|
|
|
}
|
2011-01-17 13:33:33 +00:00
|
|
|
sym = symtab_lookup (current_symtab, token);
|
|
|
|
if (!sym)
|
|
|
|
sym = new_symbol (token);
|
2012-10-26 07:01:41 +00:00
|
|
|
qc_yylval.symbol = sym;
|
2011-01-17 13:33:33 +00:00
|
|
|
if (sym->sy_type == sy_type)
|
2004-11-02 07:02:00 +00:00
|
|
|
return TYPE_NAME;
|
2011-02-13 07:05:09 +00:00
|
|
|
if (sym->sy_type == sy_class)
|
2011-01-17 13:33:33 +00:00
|
|
|
return CLASS_NAME;
|
2001-06-13 07:16:39 +00:00
|
|
|
return NAME;
|
|
|
|
}
|
|
|
|
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
static expr_t *
|
|
|
|
parse_int_vector (const char *token, int width)
|
|
|
|
{
|
|
|
|
char t1 = 0, t2 = 0;
|
|
|
|
type_t *type = 0;
|
|
|
|
|
|
|
|
union {
|
|
|
|
pr_long_t l[4];
|
|
|
|
pr_type_t t[PR_SIZEOF (dvec4)];
|
|
|
|
} long_data = {};
|
|
|
|
pr_type_t *data = __builtin_choose_expr (
|
2022-05-22 01:45:48 +00:00
|
|
|
sizeof (pr_long_t) == sizeof (int64_t), long_data.t, (void) 0);
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
|
|
|
|
switch (width) {
|
|
|
|
case 4:
|
2022-05-22 01:45:48 +00:00
|
|
|
sscanf (token, "' %"SCNi64" %"SCNi64" %"SCNi64" %"SCNi64" '%c%c",
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
&long_data.l[0], &long_data.l[1],
|
|
|
|
&long_data.l[2], &long_data.l[3], &t1, &t2);
|
|
|
|
break;
|
|
|
|
case 3:
|
2022-05-22 01:45:48 +00:00
|
|
|
sscanf (token, "' %"SCNi64" %"SCNi64" %"SCNi64" '%c%c",
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
&long_data.l[0], &long_data.l[1],
|
|
|
|
&long_data.l[2], &t1, &t2);
|
|
|
|
break;
|
|
|
|
case 2:
|
2022-05-22 01:45:48 +00:00
|
|
|
sscanf (token, "' %"SCNi64" %"SCNi64" '%c%c",
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
&long_data.l[0], &long_data.l[1], &t1, &t2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
t1 = tolower (t1);
|
|
|
|
t2 = tolower (t2);
|
2022-11-12 11:04:19 +00:00
|
|
|
if (options.code.progsversion < PROG_VERSION) {
|
|
|
|
if (!t1) {
|
|
|
|
t1 = 'f';
|
|
|
|
}
|
|
|
|
}
|
2022-08-17 07:23:33 +00:00
|
|
|
expr_t *expr = 0;
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
switch (t1) {
|
|
|
|
case 'u':
|
|
|
|
if (t2 == 'l') {
|
|
|
|
type = &type_ulong;
|
2022-08-17 07:23:33 +00:00
|
|
|
type = vector_type (type, width);
|
|
|
|
expr = new_value_expr (new_type_value (type, data));
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
} else {
|
|
|
|
type = &type_uint;
|
2022-08-17 07:23:33 +00:00
|
|
|
union {
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
pr_uint_t u[4];
|
|
|
|
pr_type_t t[PR_SIZEOF (ivec4)];
|
|
|
|
} uint_data = {
|
|
|
|
.u = {
|
|
|
|
long_data.l[0],
|
|
|
|
long_data.l[1],
|
|
|
|
long_data.l[2],
|
|
|
|
long_data.l[3],
|
|
|
|
}
|
|
|
|
};
|
2022-08-17 07:23:33 +00:00
|
|
|
data = uint_data.t;
|
|
|
|
type = vector_type (type, width);
|
|
|
|
expr = new_value_expr (new_type_value (type, data));
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
type = &type_long;
|
2022-08-17 07:23:33 +00:00
|
|
|
type = vector_type (type, width);
|
|
|
|
expr = new_value_expr (new_type_value (type, data));
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
type = &type_float;
|
2022-08-17 07:23:33 +00:00
|
|
|
union {
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
pr_float_t f[4];
|
|
|
|
pr_type_t t[PR_SIZEOF (vec4)];
|
|
|
|
} float_data = {
|
|
|
|
.f = {
|
|
|
|
long_data.l[0],
|
|
|
|
long_data.l[1],
|
|
|
|
long_data.l[2],
|
|
|
|
long_data.l[3],
|
|
|
|
}
|
|
|
|
};
|
2022-08-17 07:23:33 +00:00
|
|
|
data = float_data.t;
|
|
|
|
type = vector_type (type, width);
|
|
|
|
expr = new_value_expr (new_type_value (type, data));
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
type = &type_double;
|
2022-08-17 07:23:33 +00:00
|
|
|
union {
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
pr_double_t d[4];
|
|
|
|
pr_type_t t[PR_SIZEOF (dvec4)];
|
|
|
|
} double_data = {
|
|
|
|
.d = {
|
|
|
|
long_data.l[0],
|
|
|
|
long_data.l[1],
|
|
|
|
long_data.l[2],
|
|
|
|
long_data.l[3],
|
|
|
|
}
|
|
|
|
};
|
2022-08-17 07:23:33 +00:00
|
|
|
data = double_data.t;
|
|
|
|
type = vector_type (type, width);
|
|
|
|
expr = new_value_expr (new_type_value (type, data));
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
type = &type_int;
|
2022-08-17 07:23:33 +00:00
|
|
|
union {
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
pr_int_t i[4];
|
|
|
|
pr_type_t t[PR_SIZEOF (ivec4)];
|
|
|
|
} int_data = {
|
|
|
|
.i = {
|
|
|
|
long_data.l[0],
|
|
|
|
long_data.l[1],
|
|
|
|
long_data.l[2],
|
|
|
|
long_data.l[3],
|
|
|
|
}
|
|
|
|
};
|
2022-08-17 07:23:33 +00:00
|
|
|
data = int_data.t;
|
|
|
|
type = vector_type (type, width);
|
|
|
|
expr = new_value_expr (new_type_value (type, data));
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
expr->implicit = !t1;
|
|
|
|
return expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static expr_t *
|
|
|
|
parse_float_vector (const char *token, int width)
|
|
|
|
{
|
|
|
|
char t = 0;
|
|
|
|
type_t *type = 0;
|
|
|
|
|
|
|
|
union {
|
|
|
|
pr_double_t d[4];
|
|
|
|
pr_type_t t[PR_SIZEOF (dvec4)];
|
|
|
|
} double_data = {};
|
|
|
|
pr_type_t *data = __builtin_choose_expr (
|
|
|
|
sizeof (pr_double_t) == sizeof (double), double_data.t, (void) 0);
|
|
|
|
|
|
|
|
switch (width) {
|
|
|
|
case 4:
|
|
|
|
sscanf (token, "' %lf %lf %lf %lf '%c",
|
|
|
|
&double_data.d[0], &double_data.d[1],
|
|
|
|
&double_data.d[2], &double_data.d[3], &t);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
sscanf (token, "' %lf %lf %lf '%c",
|
|
|
|
&double_data.d[0], &double_data.d[1],
|
|
|
|
&double_data.d[1], &t);
|
|
|
|
type = (t == 'f' || t == 'F') ? &type_vec3 : &type_dvec3;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
sscanf (token, "' %lf %lf '%c",
|
|
|
|
&double_data.d[0], &double_data.d[1], &t);
|
|
|
|
type = (t == 'f' || t == 'F') ? &type_vec2 : &type_dvec2;
|
|
|
|
break;
|
|
|
|
}
|
2022-11-12 11:04:19 +00:00
|
|
|
if (options.code.progsversion < PROG_VERSION) {
|
|
|
|
if (!t) {
|
|
|
|
t = 'f';
|
|
|
|
}
|
|
|
|
}
|
[qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 02:49:45 +00:00
|
|
|
if (t == 'f' || t == 'F') {
|
|
|
|
volatile union {
|
|
|
|
pr_float_t f[4];
|
|
|
|
pr_type_t t[PR_SIZEOF (vec4)];
|
|
|
|
} float_data = {
|
|
|
|
.f = {
|
|
|
|
double_data.d[0],
|
|
|
|
double_data.d[1],
|
|
|
|
double_data.d[2],
|
|
|
|
double_data.d[3],
|
|
|
|
}
|
|
|
|
};
|
|
|
|
data = (pr_type_t *) float_data.t;
|
|
|
|
type = &type_float;
|
|
|
|
} else {
|
|
|
|
type = &type_double;
|
|
|
|
}
|
|
|
|
type = vector_type (type, width);
|
|
|
|
expr_t *expr = new_value_expr (new_type_value (type, data));
|
|
|
|
expr->implicit = !t;
|
|
|
|
return expr;
|
|
|
|
}
|
|
|
|
|
2003-04-16 19:41:52 +00:00
|
|
|
#ifdef YY_FLEX_REALLOC_HACK
|
2008-07-19 05:40:57 +00:00
|
|
|
static __attribute__ ((used)) void *(*const yy_flex_realloc_hack)(void *,yy_size_t) = yy_flex_realloc;
|
2003-04-17 00:25:55 +00:00
|
|
|
#else
|
2016-10-24 15:10:30 +00:00
|
|
|
#ifdef yyunput
|
2008-07-19 05:40:57 +00:00
|
|
|
static __attribute__ ((used)) void (*yyunput_hack)(int, char*) = yyunput;
|
2016-10-24 15:10:30 +00:00
|
|
|
#endif
|
2008-07-19 05:40:57 +00:00
|
|
|
static __attribute__ ((used)) int (*input_hack)(void) = input;
|
2003-04-17 00:14:13 +00:00
|
|
|
#endif
|