2010-05-10 11:44:09 -07:00
|
|
|
%{
|
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2010-08-12 10:07:29 -07:00
|
|
|
#include <string.h>
|
2010-05-13 09:36:23 -07:00
|
|
|
#include <assert.h>
|
2010-08-14 16:01:24 +01:00
|
|
|
#include <inttypes.h>
|
2010-05-10 11:44:09 -07:00
|
|
|
|
2010-05-10 13:17:25 -07:00
|
|
|
#include "glcpp.h"
|
2010-08-23 17:51:42 +08:00
|
|
|
#include "main/core.h" /* for struct gl_extensions */
|
2014-01-26 18:06:18 -08:00
|
|
|
#include "main/mtypes.h" /* for gl_api enum */
|
2010-05-10 13:17:25 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
yyerror(YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
|
2010-05-10 11:44:09 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_define_object_macro(glcpp_parser_t *parser,
|
|
|
|
|
YYLTYPE *loc,
|
|
|
|
|
const char *macro,
|
|
|
|
|
token_list_t *replacements);
|
2010-05-13 09:36:23 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_define_function_macro(glcpp_parser_t *parser,
|
|
|
|
|
YYLTYPE *loc,
|
|
|
|
|
const char *macro,
|
|
|
|
|
string_list_t *parameters,
|
|
|
|
|
token_list_t *replacements);
|
2010-05-13 09:36:23 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static string_list_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_string_list_create(glcpp_parser_t *parser);
|
2010-05-12 12:17:10 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static void
|
2016-10-07 04:49:13 +02:00
|
|
|
_string_list_append_item(glcpp_parser_t *parser, string_list_t *list,
|
|
|
|
|
const char *str);
|
2010-05-13 09:36:23 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static int
|
2016-03-31 16:49:59 +11:00
|
|
|
_string_list_contains(string_list_t *list, const char *member, int *index);
|
2010-05-13 12:56:42 -07:00
|
|
|
|
2014-06-25 13:41:47 -07:00
|
|
|
static const char *
|
2016-03-31 16:49:59 +11:00
|
|
|
_string_list_has_duplicate(string_list_t *list);
|
2014-06-25 13:41:47 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static int
|
2016-03-31 16:49:59 +11:00
|
|
|
_string_list_length(string_list_t *list);
|
2010-05-13 12:56:42 -07:00
|
|
|
|
2010-08-17 23:20:58 -07:00
|
|
|
static int
|
2016-03-31 16:49:59 +11:00
|
|
|
_string_list_equal(string_list_t *a, string_list_t *b);
|
2010-08-17 23:20:58 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static argument_list_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_argument_list_create(glcpp_parser_t *parser);
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static void
|
2016-10-07 04:49:13 +02:00
|
|
|
_argument_list_append(glcpp_parser_t *parser, argument_list_t *list,
|
|
|
|
|
token_list_t *argument);
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static int
|
2016-03-31 16:49:59 +11:00
|
|
|
_argument_list_length(argument_list_t *list);
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static token_list_t *
|
2016-03-31 16:49:59 +11:00
|
|
|
_argument_list_member_at(argument_list_t *list, int index);
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static token_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_create_str(glcpp_parser_t *parser, int type, char *str);
|
2010-05-25 14:52:43 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static token_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_create_ival(glcpp_parser_t *parser, int type, int ival);
|
2010-05-25 14:52:43 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static token_list_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_create(glcpp_parser_t *parser);
|
2010-05-19 13:54:37 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static void
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_append(glcpp_parser_t *parser, token_list_t *list, token_t *token);
|
2010-05-19 13:54:37 -07:00
|
|
|
|
2010-05-25 18:39:43 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_token_list_append_list(token_list_t *list, token_list_t *tail);
|
2010-05-19 13:54:37 -07:00
|
|
|
|
2010-08-17 23:20:58 -07:00
|
|
|
static int
|
2016-03-31 16:49:59 +11:00
|
|
|
_token_list_equal_ignoring_space(token_list_t *a, token_list_t *b);
|
2010-08-17 23:20:58 -07:00
|
|
|
|
2011-04-14 15:35:41 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_parser_active_list_push(glcpp_parser_t *parser, const char *identifier,
|
|
|
|
|
token_node_t *marker);
|
2010-06-02 15:32:03 -07:00
|
|
|
|
2011-04-14 15:35:41 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_parser_active_list_pop(glcpp_parser_t *parser);
|
2010-06-02 15:32:03 -07:00
|
|
|
|
2011-04-14 15:35:41 -07:00
|
|
|
static int
|
2016-03-31 16:49:59 +11:00
|
|
|
_parser_active_list_contains(glcpp_parser_t *parser, const char *identifier);
|
2010-06-02 15:32:03 -07:00
|
|
|
|
2014-07-02 12:52:33 -07:00
|
|
|
typedef enum {
|
2016-03-31 16:49:59 +11:00
|
|
|
EXPANSION_MODE_IGNORE_DEFINED,
|
|
|
|
|
EXPANSION_MODE_EVALUATE_DEFINED
|
2014-07-02 12:52:33 -07:00
|
|
|
} expansion_mode_t;
|
|
|
|
|
|
2012-06-09 16:29:38 -07:00
|
|
|
/* Expand list, and begin lexing from the result (after first
|
|
|
|
|
* prefixing a token of type 'head_token_type').
|
|
|
|
|
*/
|
2010-08-04 16:10:03 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_expand_and_lex_from(glcpp_parser_t *parser, int head_token_type,
|
|
|
|
|
token_list_t *list, expansion_mode_t mode);
|
2010-08-04 16:10:03 -07:00
|
|
|
|
2012-06-09 16:29:38 -07:00
|
|
|
/* Perform macro expansion in-place on the given list. */
|
2010-05-25 18:39:43 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_expand_token_list(glcpp_parser_t *parser, token_list_t *list,
|
|
|
|
|
expansion_mode_t mode);
|
2010-05-25 14:52:43 -07:00
|
|
|
|
2010-05-26 08:05:19 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_print_expanded_token_list(glcpp_parser_t *parser,
|
|
|
|
|
token_list_t *list);
|
2010-05-26 08:05:19 -07:00
|
|
|
|
2010-05-20 22:27:07 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_skip_stack_push_if(glcpp_parser_t *parser, YYLTYPE *loc,
|
|
|
|
|
int condition);
|
2010-05-20 22:27:07 -07:00
|
|
|
|
|
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_skip_stack_change_if(glcpp_parser_t *parser, YYLTYPE *loc,
|
|
|
|
|
const char *type, int condition);
|
2010-05-25 14:42:00 -07:00
|
|
|
|
2010-05-20 22:27:07 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_skip_stack_pop(glcpp_parser_t *parser, YYLTYPE *loc);
|
2010-05-20 22:27:07 -07:00
|
|
|
|
2012-08-02 13:06:45 -07:00
|
|
|
static void
|
|
|
|
|
_glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t version,
|
2014-01-17 14:22:49 -08:00
|
|
|
const char *ident, bool explicitly_set);
|
2012-08-02 13:06:45 -07:00
|
|
|
|
2010-05-19 10:01:29 -07:00
|
|
|
static int
|
2016-03-31 16:49:59 +11:00
|
|
|
glcpp_parser_lex(YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser);
|
2010-05-19 10:01:29 -07:00
|
|
|
|
2010-05-26 11:15:21 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
glcpp_parser_lex_from(glcpp_parser_t *parser, token_list_t *list);
|
2010-05-26 11:15:21 -07:00
|
|
|
|
2010-07-28 16:58:39 -07:00
|
|
|
static void
|
|
|
|
|
add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
|
|
|
|
|
|
2010-05-10 11:44:09 -07:00
|
|
|
%}
|
|
|
|
|
|
2010-06-16 16:26:28 -07:00
|
|
|
%pure-parser
|
2010-06-17 13:07:13 -07:00
|
|
|
%error-verbose
|
2010-08-10 16:58:28 -07:00
|
|
|
|
2010-06-16 16:35:57 -07:00
|
|
|
%locations
|
2010-08-10 16:58:28 -07:00
|
|
|
%initial-action {
|
2016-03-31 16:49:59 +11:00
|
|
|
@$.first_line = 1;
|
|
|
|
|
@$.first_column = 1;
|
|
|
|
|
@$.last_line = 1;
|
|
|
|
|
@$.last_column = 1;
|
|
|
|
|
@$.source = 0;
|
2010-08-10 16:58:28 -07:00
|
|
|
}
|
2010-06-16 16:26:28 -07:00
|
|
|
|
2010-05-10 16:16:06 -07:00
|
|
|
%parse-param {glcpp_parser_t *parser}
|
2010-05-19 10:05:40 -07:00
|
|
|
%lex-param {glcpp_parser_t *parser}
|
2010-05-10 11:52:29 -07:00
|
|
|
|
2010-07-28 11:10:52 -07:00
|
|
|
%expect 0
|
2014-06-25 11:59:55 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
/* We use HASH_TOKEN, DEFINE_TOKEN and VERSION_TOKEN (as opposed to
|
2014-06-25 13:55:18 -07:00
|
|
|
* HASH, DEFINE, and VERSION) to avoid conflicts with other symbols,
|
|
|
|
|
* (such as the <HASH> and <DEFINE> start conditions in the lexer). */
|
2014-07-03 14:16:07 -07:00
|
|
|
%token DEFINED ELIF_EXPANDED HASH_TOKEN DEFINE_TOKEN FUNC_IDENTIFIER OBJ_IDENTIFIER ELIF ELSE ENDIF ERROR_TOKEN IF IFDEF IFNDEF LINE PRAGMA UNDEF VERSION_TOKEN GARBAGE IDENTIFIER IF_EXPANDED INTEGER INTEGER_STRING LINE_EXPANDED NEWLINE OTHER PLACEHOLDER SPACE PLUS_PLUS MINUS_MINUS
|
2010-05-26 09:32:12 -07:00
|
|
|
%token PASTE
|
2016-11-08 11:06:05 -08:00
|
|
|
%type <ival> INTEGER operator SPACE integer_constant version_constant
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
%type <expression_value> expression
|
2014-07-29 16:56:06 -06:00
|
|
|
%type <str> IDENTIFIER FUNC_IDENTIFIER OBJ_IDENTIFIER INTEGER_STRING OTHER ERROR_TOKEN PRAGMA
|
2010-05-25 16:28:26 -07:00
|
|
|
%type <string_list> identifier_list
|
2014-07-02 12:52:33 -07:00
|
|
|
%type <token> preprocessing_token
|
|
|
|
|
%type <token_list> pp_tokens replacement_list text_line
|
2010-05-26 09:32:12 -07:00
|
|
|
%left OR
|
|
|
|
|
%left AND
|
|
|
|
|
%left '|'
|
|
|
|
|
%left '^'
|
|
|
|
|
%left '&'
|
|
|
|
|
%left EQUAL NOT_EQUAL
|
|
|
|
|
%left '<' '>' LESS_OR_EQUAL GREATER_OR_EQUAL
|
|
|
|
|
%left LEFT_SHIFT RIGHT_SHIFT
|
|
|
|
|
%left '+' '-'
|
|
|
|
|
%left '*' '/' '%'
|
|
|
|
|
%right UNARY
|
2010-05-25 13:09:03 -07:00
|
|
|
|
2014-06-25 11:46:49 -07:00
|
|
|
%debug
|
|
|
|
|
|
2010-05-10 11:44:09 -07:00
|
|
|
%%
|
|
|
|
|
|
2010-05-12 12:17:10 -07:00
|
|
|
input:
|
2010-05-25 13:09:03 -07:00
|
|
|
/* empty */
|
2010-05-26 11:15:21 -07:00
|
|
|
| input line
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
line:
|
glsl/glcpp: Correctly parse directives with intervening comments
It's legal (though highly bizarre) for a pre-processor directive to look like
this:
# /* why? */ define FOO bar
This behavior comes about since the specification defines separate logical
phases in a precise order, and comment-removal occurs in a phase before the
identification of directives.
Our implementation does not use an actual separate phase for comment removal,
so some extra care is necessary to correctly parse this. What we want is for
'#' to introduce a directive iff it is the first token on a line, (ignoring
whitespace and comments). Previously, we had a lexical rule that worked only
for whitespace (not comments) with the following regular expression to find a
directive-introducing '#' at the beginning of a line:
HASH ^{HSPACE}*#{HSPACE}*
In this commit, we switch to instead use a simple literal match of '#' to
return a HASH_TOKEN token and add a new <HASH> start condition for whenever
the HASH_TOKEN is the first non-space token of a line. This requires the
addition of the new bit of state: first_non_space_token_this_line.
This approach has a couple of implications on the glcpp parser:
1. The parser now sees two separate tokens, (such as HASH_TOKEN and
HASH_DEFINE) where it previously saw one token (HASH_DEFINE) for
the sequence "#define". This is a straightforward change throughout
the grammar.
2. The parser may now see a SPACE token before the HASH_TOKEN token of
a directive. Previously the lexical regular expression for {HASH}
would eat up the space and there would be no SPACE token.
This second implication is a bit of a nuisance for the parser. It causes a
SPACE token to appear in a production of the grammar with the following two
definitions of a control_line:
control_line
SPACE control_line
This is really ugly, since normally a space would simply be a token
separator, so it wouldn't appear in the tokens of a production. This leads to
a further problem with interleaved spaces and comments:
/* ... */ /* ... */ #define /* ..*/
For this, we must not return several consecutive SPACE tokens, or else we would need an arbitrary number of new productions:
SPACE SPACE control_line
SPACE SPACE SPACE control_line
ad nauseam
To avoid this problem, in this commit we also change the lexer to emit only a
single SPACE token for any series of consecutive spaces, (whether from actual
whitespace or comments). For this compression, we add a new bit of parser
state: last_token_was_space. And we also update the expected results of all
necessary test cases for the new compression of space tokens.
Fortunately, the compression of spaces should not lead to any semantic changes
in terms of what the eventual GLSL compiler sees.
So there's a lot happening in this commit, (particularly for such a tiny
feature). But fortunately, the lexer itself is looking cleaner than ever. The
only ugly bit is all the state updating, but it is at least isolated to a
single shared function.
Of course, a new "make check" test is added for the new feature, (directives
with comments and whitespace interleaved in many combinations).
And this commit fixes the following Khronos GLES3 CTS tests:
function_definition_with_comments_vertex
function_definition_with_comments_fragment
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-06-25 12:20:22 -07:00
|
|
|
control_line
|
|
|
|
|
| SPACE control_line
|
2010-05-25 14:52:43 -07:00
|
|
|
| text_line {
|
2010-06-01 11:20:18 -07:00
|
|
|
_glcpp_parser_print_expanded_token_list (parser, $1);
|
2012-02-09 20:33:44 -08:00
|
|
|
ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n");
|
2010-05-25 14:52:43 -07:00
|
|
|
}
|
2010-05-26 11:15:21 -07:00
|
|
|
| expanded_line
|
2010-05-12 13:11:50 -07:00
|
|
|
;
|
|
|
|
|
|
2010-05-26 11:15:21 -07:00
|
|
|
expanded_line:
|
|
|
|
|
IF_EXPANDED expression NEWLINE {
|
2014-06-13 15:16:05 -07:00
|
|
|
if (parser->is_gles && $2.undefined_macro)
|
|
|
|
|
glcpp_error(& @1, parser, "undefined macro %s in expression (illegal in GLES)", $2.undefined_macro);
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
_glcpp_parser_skip_stack_push_if (parser, & @1, $2.value);
|
2010-05-26 11:15:21 -07:00
|
|
|
}
|
|
|
|
|
| ELIF_EXPANDED expression NEWLINE {
|
2014-06-13 15:16:05 -07:00
|
|
|
if (parser->is_gles && $2.undefined_macro)
|
|
|
|
|
glcpp_error(& @1, parser, "undefined macro %s in expression (illegal in GLES)", $2.undefined_macro);
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
_glcpp_parser_skip_stack_change_if (parser, & @1, "elif", $2.value);
|
2010-05-26 11:15:21 -07:00
|
|
|
}
|
2012-06-09 16:31:06 -07:00
|
|
|
| LINE_EXPANDED integer_constant NEWLINE {
|
|
|
|
|
parser->has_new_line_number = 1;
|
|
|
|
|
parser->new_line_number = $2;
|
|
|
|
|
ralloc_asprintf_rewrite_tail (&parser->output,
|
|
|
|
|
&parser->output_length,
|
2012-07-28 13:04:53 -07:00
|
|
|
"#line %" PRIiMAX "\n",
|
2012-06-09 16:31:06 -07:00
|
|
|
$2);
|
|
|
|
|
}
|
|
|
|
|
| LINE_EXPANDED integer_constant integer_constant NEWLINE {
|
|
|
|
|
parser->has_new_line_number = 1;
|
|
|
|
|
parser->new_line_number = $2;
|
|
|
|
|
parser->has_new_source_number = 1;
|
|
|
|
|
parser->new_source_number = $3;
|
|
|
|
|
ralloc_asprintf_rewrite_tail (&parser->output,
|
|
|
|
|
&parser->output_length,
|
2012-07-28 13:04:53 -07:00
|
|
|
"#line %" PRIiMAX " %" PRIiMAX "\n",
|
2012-06-09 16:31:06 -07:00
|
|
|
$2, $3);
|
|
|
|
|
}
|
2010-05-26 11:15:21 -07:00
|
|
|
;
|
|
|
|
|
|
2014-01-17 14:22:49 -08:00
|
|
|
define:
|
|
|
|
|
OBJ_IDENTIFIER replacement_list NEWLINE {
|
|
|
|
|
_define_object_macro (parser, & @1, $1, $2);
|
2010-05-25 15:24:59 -07:00
|
|
|
}
|
2014-01-17 14:22:49 -08:00
|
|
|
| FUNC_IDENTIFIER '(' ')' replacement_list NEWLINE {
|
|
|
|
|
_define_function_macro (parser, & @1, $1, NULL, $4);
|
2010-05-25 16:28:26 -07:00
|
|
|
}
|
2014-01-17 14:22:49 -08:00
|
|
|
| FUNC_IDENTIFIER '(' identifier_list ')' replacement_list NEWLINE {
|
|
|
|
|
_define_function_macro (parser, & @1, $1, $3, $5);
|
2010-05-25 16:28:26 -07:00
|
|
|
}
|
2014-01-17 14:22:49 -08:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
control_line:
|
glsl/glcpp: Correctly parse directives with intervening comments
It's legal (though highly bizarre) for a pre-processor directive to look like
this:
# /* why? */ define FOO bar
This behavior comes about since the specification defines separate logical
phases in a precise order, and comment-removal occurs in a phase before the
identification of directives.
Our implementation does not use an actual separate phase for comment removal,
so some extra care is necessary to correctly parse this. What we want is for
'#' to introduce a directive iff it is the first token on a line, (ignoring
whitespace and comments). Previously, we had a lexical rule that worked only
for whitespace (not comments) with the following regular expression to find a
directive-introducing '#' at the beginning of a line:
HASH ^{HSPACE}*#{HSPACE}*
In this commit, we switch to instead use a simple literal match of '#' to
return a HASH_TOKEN token and add a new <HASH> start condition for whenever
the HASH_TOKEN is the first non-space token of a line. This requires the
addition of the new bit of state: first_non_space_token_this_line.
This approach has a couple of implications on the glcpp parser:
1. The parser now sees two separate tokens, (such as HASH_TOKEN and
HASH_DEFINE) where it previously saw one token (HASH_DEFINE) for
the sequence "#define". This is a straightforward change throughout
the grammar.
2. The parser may now see a SPACE token before the HASH_TOKEN token of
a directive. Previously the lexical regular expression for {HASH}
would eat up the space and there would be no SPACE token.
This second implication is a bit of a nuisance for the parser. It causes a
SPACE token to appear in a production of the grammar with the following two
definitions of a control_line:
control_line
SPACE control_line
This is really ugly, since normally a space would simply be a token
separator, so it wouldn't appear in the tokens of a production. This leads to
a further problem with interleaved spaces and comments:
/* ... */ /* ... */ #define /* ..*/
For this, we must not return several consecutive SPACE tokens, or else we would need an arbitrary number of new productions:
SPACE SPACE control_line
SPACE SPACE SPACE control_line
ad nauseam
To avoid this problem, in this commit we also change the lexer to emit only a
single SPACE token for any series of consecutive spaces, (whether from actual
whitespace or comments). For this compression, we add a new bit of parser
state: last_token_was_space. And we also update the expected results of all
necessary test cases for the new compression of space tokens.
Fortunately, the compression of spaces should not lead to any semantic changes
in terms of what the eventual GLSL compiler sees.
So there's a lot happening in this commit, (particularly for such a tiny
feature). But fortunately, the lexer itself is looking cleaner than ever. The
only ugly bit is all the state updating, but it is at least isolated to a
single shared function.
Of course, a new "make check" test is added for the new feature, (directives
with comments and whitespace interleaved in many combinations).
And this commit fixes the following Khronos GLES3 CTS tests:
function_definition_with_comments_vertex
function_definition_with_comments_fragment
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-06-25 12:20:22 -07:00
|
|
|
control_line_success {
|
|
|
|
|
ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n");
|
|
|
|
|
}
|
|
|
|
|
| control_line_error
|
2016-03-04 18:47:39 -08:00
|
|
|
| HASH_TOKEN LINE pp_tokens NEWLINE {
|
glsl/glcpp: Correctly parse directives with intervening comments
It's legal (though highly bizarre) for a pre-processor directive to look like
this:
# /* why? */ define FOO bar
This behavior comes about since the specification defines separate logical
phases in a precise order, and comment-removal occurs in a phase before the
identification of directives.
Our implementation does not use an actual separate phase for comment removal,
so some extra care is necessary to correctly parse this. What we want is for
'#' to introduce a directive iff it is the first token on a line, (ignoring
whitespace and comments). Previously, we had a lexical rule that worked only
for whitespace (not comments) with the following regular expression to find a
directive-introducing '#' at the beginning of a line:
HASH ^{HSPACE}*#{HSPACE}*
In this commit, we switch to instead use a simple literal match of '#' to
return a HASH_TOKEN token and add a new <HASH> start condition for whenever
the HASH_TOKEN is the first non-space token of a line. This requires the
addition of the new bit of state: first_non_space_token_this_line.
This approach has a couple of implications on the glcpp parser:
1. The parser now sees two separate tokens, (such as HASH_TOKEN and
HASH_DEFINE) where it previously saw one token (HASH_DEFINE) for
the sequence "#define". This is a straightforward change throughout
the grammar.
2. The parser may now see a SPACE token before the HASH_TOKEN token of
a directive. Previously the lexical regular expression for {HASH}
would eat up the space and there would be no SPACE token.
This second implication is a bit of a nuisance for the parser. It causes a
SPACE token to appear in a production of the grammar with the following two
definitions of a control_line:
control_line
SPACE control_line
This is really ugly, since normally a space would simply be a token
separator, so it wouldn't appear in the tokens of a production. This leads to
a further problem with interleaved spaces and comments:
/* ... */ /* ... */ #define /* ..*/
For this, we must not return several consecutive SPACE tokens, or else we would need an arbitrary number of new productions:
SPACE SPACE control_line
SPACE SPACE SPACE control_line
ad nauseam
To avoid this problem, in this commit we also change the lexer to emit only a
single SPACE token for any series of consecutive spaces, (whether from actual
whitespace or comments). For this compression, we add a new bit of parser
state: last_token_was_space. And we also update the expected results of all
necessary test cases for the new compression of space tokens.
Fortunately, the compression of spaces should not lead to any semantic changes
in terms of what the eventual GLSL compiler sees.
So there's a lot happening in this commit, (particularly for such a tiny
feature). But fortunately, the lexer itself is looking cleaner than ever. The
only ugly bit is all the state updating, but it is at least isolated to a
single shared function.
Of course, a new "make check" test is added for the new feature, (directives
with comments and whitespace interleaved in many combinations).
And this commit fixes the following Khronos GLES3 CTS tests:
function_definition_with_comments_vertex
function_definition_with_comments_fragment
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-06-25 12:20:22 -07:00
|
|
|
|
|
|
|
|
if (parser->skip_stack == NULL ||
|
|
|
|
|
parser->skip_stack->type == SKIP_NO_SKIP)
|
|
|
|
|
{
|
|
|
|
|
_glcpp_parser_expand_and_lex_from (parser,
|
2016-03-04 18:47:39 -08:00
|
|
|
LINE_EXPANDED, $3,
|
2014-07-02 12:52:33 -07:00
|
|
|
EXPANSION_MODE_IGNORE_DEFINED);
|
glsl/glcpp: Correctly parse directives with intervening comments
It's legal (though highly bizarre) for a pre-processor directive to look like
this:
# /* why? */ define FOO bar
This behavior comes about since the specification defines separate logical
phases in a precise order, and comment-removal occurs in a phase before the
identification of directives.
Our implementation does not use an actual separate phase for comment removal,
so some extra care is necessary to correctly parse this. What we want is for
'#' to introduce a directive iff it is the first token on a line, (ignoring
whitespace and comments). Previously, we had a lexical rule that worked only
for whitespace (not comments) with the following regular expression to find a
directive-introducing '#' at the beginning of a line:
HASH ^{HSPACE}*#{HSPACE}*
In this commit, we switch to instead use a simple literal match of '#' to
return a HASH_TOKEN token and add a new <HASH> start condition for whenever
the HASH_TOKEN is the first non-space token of a line. This requires the
addition of the new bit of state: first_non_space_token_this_line.
This approach has a couple of implications on the glcpp parser:
1. The parser now sees two separate tokens, (such as HASH_TOKEN and
HASH_DEFINE) where it previously saw one token (HASH_DEFINE) for
the sequence "#define". This is a straightforward change throughout
the grammar.
2. The parser may now see a SPACE token before the HASH_TOKEN token of
a directive. Previously the lexical regular expression for {HASH}
would eat up the space and there would be no SPACE token.
This second implication is a bit of a nuisance for the parser. It causes a
SPACE token to appear in a production of the grammar with the following two
definitions of a control_line:
control_line
SPACE control_line
This is really ugly, since normally a space would simply be a token
separator, so it wouldn't appear in the tokens of a production. This leads to
a further problem with interleaved spaces and comments:
/* ... */ /* ... */ #define /* ..*/
For this, we must not return several consecutive SPACE tokens, or else we would need an arbitrary number of new productions:
SPACE SPACE control_line
SPACE SPACE SPACE control_line
ad nauseam
To avoid this problem, in this commit we also change the lexer to emit only a
single SPACE token for any series of consecutive spaces, (whether from actual
whitespace or comments). For this compression, we add a new bit of parser
state: last_token_was_space. And we also update the expected results of all
necessary test cases for the new compression of space tokens.
Fortunately, the compression of spaces should not lead to any semantic changes
in terms of what the eventual GLSL compiler sees.
So there's a lot happening in this commit, (particularly for such a tiny
feature). But fortunately, the lexer itself is looking cleaner than ever. The
only ugly bit is all the state updating, but it is at least isolated to a
single shared function.
Of course, a new "make check" test is added for the new feature, (directives
with comments and whitespace interleaved in many combinations).
And this commit fixes the following Khronos GLES3 CTS tests:
function_definition_with_comments_vertex
function_definition_with_comments_fragment
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-06-25 12:20:22 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
control_line_success:
|
2016-03-04 18:52:47 -08:00
|
|
|
HASH_TOKEN DEFINE_TOKEN define
|
2016-03-04 18:47:39 -08:00
|
|
|
| HASH_TOKEN UNDEF IDENTIFIER NEWLINE {
|
2016-08-18 21:59:19 +02:00
|
|
|
struct hash_entry *entry;
|
2016-08-09 14:32:24 -07:00
|
|
|
|
|
|
|
|
/* Section 3.4 (Preprocessor) of the GLSL ES 3.00 spec says:
|
|
|
|
|
*
|
|
|
|
|
* It is an error to undefine or to redefine a built-in
|
|
|
|
|
* (pre-defined) macro name.
|
|
|
|
|
*
|
2017-05-01 16:35:34 -07:00
|
|
|
* The GLSL ES 1.00 spec does not contain this text, but
|
|
|
|
|
* dEQP's preprocess test in GLES2 checks for it.
|
2016-08-09 14:32:24 -07:00
|
|
|
*
|
|
|
|
|
* Section 3.3 (Preprocessor) of the GLSL 1.30 spec says:
|
|
|
|
|
*
|
|
|
|
|
* #define and #undef functionality are defined as is
|
|
|
|
|
* standard for C++ preprocessors for macro definitions
|
|
|
|
|
* both with and without macro parameters.
|
|
|
|
|
*
|
|
|
|
|
* At least as far as I can tell GCC allow '#undef __FILE__'.
|
|
|
|
|
* Furthermore, there are desktop OpenGL conformance tests
|
|
|
|
|
* that expect '#undef __VERSION__' and '#undef
|
|
|
|
|
* GL_core_profile' to work.
|
|
|
|
|
*/
|
|
|
|
|
if (parser->is_gles &&
|
|
|
|
|
(strcmp("__LINE__", $3) == 0
|
|
|
|
|
|| strcmp("__FILE__", $3) == 0
|
|
|
|
|
|| strcmp("__VERSION__", $3) == 0
|
|
|
|
|
|| strncmp("GL_", $3, 3) == 0))
|
2014-06-06 16:56:58 -07:00
|
|
|
glcpp_error(& @1, parser, "Built-in (pre-defined)"
|
2014-12-07 11:49:28 +13:00
|
|
|
" macro names cannot be undefined.");
|
2014-06-06 16:56:58 -07:00
|
|
|
|
2016-08-18 21:59:19 +02:00
|
|
|
entry = _mesa_hash_table_search (parser->defines, $3);
|
|
|
|
|
if (entry) {
|
|
|
|
|
_mesa_hash_table_remove (parser->defines, entry);
|
2010-05-25 15:28:58 -07:00
|
|
|
}
|
|
|
|
|
}
|
2016-03-04 18:47:39 -08:00
|
|
|
| HASH_TOKEN IF pp_tokens NEWLINE {
|
2010-08-11 12:43:44 -07:00
|
|
|
/* Be careful to only evaluate the 'if' expression if
|
|
|
|
|
* we are not skipping. When we are skipping, we
|
|
|
|
|
* simply push a new 0-valued 'if' onto the skip
|
|
|
|
|
* stack.
|
|
|
|
|
*
|
|
|
|
|
* This avoids generating diagnostics for invalid
|
|
|
|
|
* expressions that are being skipped. */
|
|
|
|
|
if (parser->skip_stack == NULL ||
|
|
|
|
|
parser->skip_stack->type == SKIP_NO_SKIP)
|
|
|
|
|
{
|
2012-06-09 16:29:38 -07:00
|
|
|
_glcpp_parser_expand_and_lex_from (parser,
|
2016-03-04 18:47:39 -08:00
|
|
|
IF_EXPANDED, $3,
|
2014-07-02 12:52:33 -07:00
|
|
|
EXPANSION_MODE_EVALUATE_DEFINED);
|
2010-08-11 12:43:44 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-08-04 16:24:39 -07:00
|
|
|
_glcpp_parser_skip_stack_push_if (parser, & @1, 0);
|
|
|
|
|
parser->skip_stack->type = SKIP_TO_ENDIF;
|
|
|
|
|
}
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
2014-06-25 13:55:18 -07:00
|
|
|
| HASH_TOKEN IF NEWLINE {
|
2010-08-11 13:59:22 -07:00
|
|
|
/* #if without an expression is only an error if we
|
|
|
|
|
* are not skipping */
|
|
|
|
|
if (parser->skip_stack == NULL ||
|
|
|
|
|
parser->skip_stack->type == SKIP_NO_SKIP)
|
|
|
|
|
{
|
|
|
|
|
glcpp_error(& @1, parser, "#if with no expression");
|
|
|
|
|
}
|
|
|
|
|
_glcpp_parser_skip_stack_push_if (parser, & @1, 0);
|
|
|
|
|
}
|
2016-03-04 18:47:39 -08:00
|
|
|
| HASH_TOKEN IFDEF IDENTIFIER junk NEWLINE {
|
2016-08-18 21:59:19 +02:00
|
|
|
struct hash_entry *entry =
|
|
|
|
|
_mesa_hash_table_search(parser->defines, $3);
|
|
|
|
|
macro_t *macro = entry ? entry->data : NULL;
|
2010-06-17 12:41:46 -07:00
|
|
|
_glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL);
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
2016-03-04 18:47:39 -08:00
|
|
|
| HASH_TOKEN IFNDEF IDENTIFIER junk NEWLINE {
|
2016-08-18 21:59:19 +02:00
|
|
|
struct hash_entry *entry =
|
|
|
|
|
_mesa_hash_table_search(parser->defines, $3);
|
|
|
|
|
macro_t *macro = entry ? entry->data : NULL;
|
glsl/glcpp: Correctly parse directives with intervening comments
It's legal (though highly bizarre) for a pre-processor directive to look like
this:
# /* why? */ define FOO bar
This behavior comes about since the specification defines separate logical
phases in a precise order, and comment-removal occurs in a phase before the
identification of directives.
Our implementation does not use an actual separate phase for comment removal,
so some extra care is necessary to correctly parse this. What we want is for
'#' to introduce a directive iff it is the first token on a line, (ignoring
whitespace and comments). Previously, we had a lexical rule that worked only
for whitespace (not comments) with the following regular expression to find a
directive-introducing '#' at the beginning of a line:
HASH ^{HSPACE}*#{HSPACE}*
In this commit, we switch to instead use a simple literal match of '#' to
return a HASH_TOKEN token and add a new <HASH> start condition for whenever
the HASH_TOKEN is the first non-space token of a line. This requires the
addition of the new bit of state: first_non_space_token_this_line.
This approach has a couple of implications on the glcpp parser:
1. The parser now sees two separate tokens, (such as HASH_TOKEN and
HASH_DEFINE) where it previously saw one token (HASH_DEFINE) for
the sequence "#define". This is a straightforward change throughout
the grammar.
2. The parser may now see a SPACE token before the HASH_TOKEN token of
a directive. Previously the lexical regular expression for {HASH}
would eat up the space and there would be no SPACE token.
This second implication is a bit of a nuisance for the parser. It causes a
SPACE token to appear in a production of the grammar with the following two
definitions of a control_line:
control_line
SPACE control_line
This is really ugly, since normally a space would simply be a token
separator, so it wouldn't appear in the tokens of a production. This leads to
a further problem with interleaved spaces and comments:
/* ... */ /* ... */ #define /* ..*/
For this, we must not return several consecutive SPACE tokens, or else we would need an arbitrary number of new productions:
SPACE SPACE control_line
SPACE SPACE SPACE control_line
ad nauseam
To avoid this problem, in this commit we also change the lexer to emit only a
single SPACE token for any series of consecutive spaces, (whether from actual
whitespace or comments). For this compression, we add a new bit of parser
state: last_token_was_space. And we also update the expected results of all
necessary test cases for the new compression of space tokens.
Fortunately, the compression of spaces should not lead to any semantic changes
in terms of what the eventual GLSL compiler sees.
So there's a lot happening in this commit, (particularly for such a tiny
feature). But fortunately, the lexer itself is looking cleaner than ever. The
only ugly bit is all the state updating, but it is at least isolated to a
single shared function.
Of course, a new "make check" test is added for the new feature, (directives
with comments and whitespace interleaved in many combinations).
And this commit fixes the following Khronos GLES3 CTS tests:
function_definition_with_comments_vertex
function_definition_with_comments_fragment
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-06-25 12:20:22 -07:00
|
|
|
_glcpp_parser_skip_stack_push_if (parser, & @3, macro == NULL);
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
2014-07-02 12:52:33 -07:00
|
|
|
| HASH_TOKEN ELIF pp_tokens NEWLINE {
|
2010-08-11 12:43:44 -07:00
|
|
|
/* Be careful to only evaluate the 'elif' expression
|
|
|
|
|
* if we are not skipping. When we are skipping, we
|
|
|
|
|
* simply change to a 0-valued 'elif' on the skip
|
|
|
|
|
* stack.
|
|
|
|
|
*
|
|
|
|
|
* This avoids generating diagnostics for invalid
|
|
|
|
|
* expressions that are being skipped. */
|
|
|
|
|
if (parser->skip_stack &&
|
|
|
|
|
parser->skip_stack->type == SKIP_TO_ELSE)
|
|
|
|
|
{
|
2012-06-09 16:29:38 -07:00
|
|
|
_glcpp_parser_expand_and_lex_from (parser,
|
2014-07-02 12:52:33 -07:00
|
|
|
ELIF_EXPANDED, $3,
|
|
|
|
|
EXPANSION_MODE_EVALUATE_DEFINED);
|
2010-08-11 12:43:44 -07:00
|
|
|
}
|
2013-12-17 16:37:33 +01:00
|
|
|
else if (parser->skip_stack &&
|
|
|
|
|
parser->skip_stack->has_else)
|
|
|
|
|
{
|
|
|
|
|
glcpp_error(& @1, parser, "#elif after #else");
|
|
|
|
|
}
|
2010-08-11 12:43:44 -07:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_glcpp_parser_skip_stack_change_if (parser, & @1,
|
|
|
|
|
"elif", 0);
|
|
|
|
|
}
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
2014-06-25 13:55:18 -07:00
|
|
|
| HASH_TOKEN ELIF NEWLINE {
|
2010-08-11 12:43:44 -07:00
|
|
|
/* #elif without an expression is an error unless we
|
|
|
|
|
* are skipping. */
|
|
|
|
|
if (parser->skip_stack &&
|
|
|
|
|
parser->skip_stack->type == SKIP_TO_ELSE)
|
|
|
|
|
{
|
2010-08-11 13:50:51 -07:00
|
|
|
glcpp_error(& @1, parser, "#elif with no expression");
|
2010-06-21 12:20:22 -07:00
|
|
|
}
|
2013-12-17 16:37:33 +01:00
|
|
|
else if (parser->skip_stack &&
|
|
|
|
|
parser->skip_stack->has_else)
|
|
|
|
|
{
|
|
|
|
|
glcpp_error(& @1, parser, "#elif after #else");
|
|
|
|
|
}
|
2010-08-11 12:43:44 -07:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_glcpp_parser_skip_stack_change_if (parser, & @1,
|
|
|
|
|
"elif", 0);
|
|
|
|
|
glcpp_warning(& @1, parser, "ignoring illegal #elif without expression");
|
|
|
|
|
}
|
2010-06-21 12:20:22 -07:00
|
|
|
}
|
2014-06-25 13:55:18 -07:00
|
|
|
| HASH_TOKEN ELSE { parser->lexing_directive = 1; } NEWLINE {
|
2013-12-17 16:37:33 +01:00
|
|
|
if (parser->skip_stack &&
|
|
|
|
|
parser->skip_stack->has_else)
|
|
|
|
|
{
|
|
|
|
|
glcpp_error(& @1, parser, "multiple #else");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_glcpp_parser_skip_stack_change_if (parser, & @1, "else", 1);
|
|
|
|
|
if (parser->skip_stack)
|
|
|
|
|
parser->skip_stack->has_else = true;
|
|
|
|
|
}
|
2014-06-12 10:39:39 -07:00
|
|
|
}
|
2014-06-25 13:55:18 -07:00
|
|
|
| HASH_TOKEN ENDIF {
|
2010-06-17 12:30:57 -07:00
|
|
|
_glcpp_parser_skip_stack_pop (parser, & @1);
|
2012-11-06 10:59:30 -08:00
|
|
|
} NEWLINE
|
2016-11-08 11:06:05 -08:00
|
|
|
| HASH_TOKEN VERSION_TOKEN version_constant NEWLINE {
|
|
|
|
|
if (parser->version_set) {
|
2014-01-29 12:48:51 -08:00
|
|
|
glcpp_error(& @1, parser, "#version must appear on the first line");
|
|
|
|
|
}
|
glsl/glcpp: Correctly parse directives with intervening comments
It's legal (though highly bizarre) for a pre-processor directive to look like
this:
# /* why? */ define FOO bar
This behavior comes about since the specification defines separate logical
phases in a precise order, and comment-removal occurs in a phase before the
identification of directives.
Our implementation does not use an actual separate phase for comment removal,
so some extra care is necessary to correctly parse this. What we want is for
'#' to introduce a directive iff it is the first token on a line, (ignoring
whitespace and comments). Previously, we had a lexical rule that worked only
for whitespace (not comments) with the following regular expression to find a
directive-introducing '#' at the beginning of a line:
HASH ^{HSPACE}*#{HSPACE}*
In this commit, we switch to instead use a simple literal match of '#' to
return a HASH_TOKEN token and add a new <HASH> start condition for whenever
the HASH_TOKEN is the first non-space token of a line. This requires the
addition of the new bit of state: first_non_space_token_this_line.
This approach has a couple of implications on the glcpp parser:
1. The parser now sees two separate tokens, (such as HASH_TOKEN and
HASH_DEFINE) where it previously saw one token (HASH_DEFINE) for
the sequence "#define". This is a straightforward change throughout
the grammar.
2. The parser may now see a SPACE token before the HASH_TOKEN token of
a directive. Previously the lexical regular expression for {HASH}
would eat up the space and there would be no SPACE token.
This second implication is a bit of a nuisance for the parser. It causes a
SPACE token to appear in a production of the grammar with the following two
definitions of a control_line:
control_line
SPACE control_line
This is really ugly, since normally a space would simply be a token
separator, so it wouldn't appear in the tokens of a production. This leads to
a further problem with interleaved spaces and comments:
/* ... */ /* ... */ #define /* ..*/
For this, we must not return several consecutive SPACE tokens, or else we would need an arbitrary number of new productions:
SPACE SPACE control_line
SPACE SPACE SPACE control_line
ad nauseam
To avoid this problem, in this commit we also change the lexer to emit only a
single SPACE token for any series of consecutive spaces, (whether from actual
whitespace or comments). For this compression, we add a new bit of parser
state: last_token_was_space. And we also update the expected results of all
necessary test cases for the new compression of space tokens.
Fortunately, the compression of spaces should not lead to any semantic changes
in terms of what the eventual GLSL compiler sees.
So there's a lot happening in this commit, (particularly for such a tiny
feature). But fortunately, the lexer itself is looking cleaner than ever. The
only ugly bit is all the state updating, but it is at least isolated to a
single shared function.
Of course, a new "make check" test is added for the new feature, (directives
with comments and whitespace interleaved in many combinations).
And this commit fixes the following Khronos GLES3 CTS tests:
function_definition_with_comments_vertex
function_definition_with_comments_fragment
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-06-25 12:20:22 -07:00
|
|
|
_glcpp_parser_handle_version_declaration(parser, $3, NULL, true);
|
2010-07-28 16:58:39 -07:00
|
|
|
}
|
2016-11-08 11:06:05 -08:00
|
|
|
| HASH_TOKEN VERSION_TOKEN version_constant IDENTIFIER NEWLINE {
|
|
|
|
|
if (parser->version_set) {
|
2014-01-29 12:48:51 -08:00
|
|
|
glcpp_error(& @1, parser, "#version must appear on the first line");
|
|
|
|
|
}
|
glsl/glcpp: Correctly parse directives with intervening comments
It's legal (though highly bizarre) for a pre-processor directive to look like
this:
# /* why? */ define FOO bar
This behavior comes about since the specification defines separate logical
phases in a precise order, and comment-removal occurs in a phase before the
identification of directives.
Our implementation does not use an actual separate phase for comment removal,
so some extra care is necessary to correctly parse this. What we want is for
'#' to introduce a directive iff it is the first token on a line, (ignoring
whitespace and comments). Previously, we had a lexical rule that worked only
for whitespace (not comments) with the following regular expression to find a
directive-introducing '#' at the beginning of a line:
HASH ^{HSPACE}*#{HSPACE}*
In this commit, we switch to instead use a simple literal match of '#' to
return a HASH_TOKEN token and add a new <HASH> start condition for whenever
the HASH_TOKEN is the first non-space token of a line. This requires the
addition of the new bit of state: first_non_space_token_this_line.
This approach has a couple of implications on the glcpp parser:
1. The parser now sees two separate tokens, (such as HASH_TOKEN and
HASH_DEFINE) where it previously saw one token (HASH_DEFINE) for
the sequence "#define". This is a straightforward change throughout
the grammar.
2. The parser may now see a SPACE token before the HASH_TOKEN token of
a directive. Previously the lexical regular expression for {HASH}
would eat up the space and there would be no SPACE token.
This second implication is a bit of a nuisance for the parser. It causes a
SPACE token to appear in a production of the grammar with the following two
definitions of a control_line:
control_line
SPACE control_line
This is really ugly, since normally a space would simply be a token
separator, so it wouldn't appear in the tokens of a production. This leads to
a further problem with interleaved spaces and comments:
/* ... */ /* ... */ #define /* ..*/
For this, we must not return several consecutive SPACE tokens, or else we would need an arbitrary number of new productions:
SPACE SPACE control_line
SPACE SPACE SPACE control_line
ad nauseam
To avoid this problem, in this commit we also change the lexer to emit only a
single SPACE token for any series of consecutive spaces, (whether from actual
whitespace or comments). For this compression, we add a new bit of parser
state: last_token_was_space. And we also update the expected results of all
necessary test cases for the new compression of space tokens.
Fortunately, the compression of spaces should not lead to any semantic changes
in terms of what the eventual GLSL compiler sees.
So there's a lot happening in this commit, (particularly for such a tiny
feature). But fortunately, the lexer itself is looking cleaner than ever. The
only ugly bit is all the state updating, but it is at least isolated to a
single shared function.
Of course, a new "make check" test is added for the new feature, (directives
with comments and whitespace interleaved in many combinations).
And this commit fixes the following Khronos GLES3 CTS tests:
function_definition_with_comments_vertex
function_definition_with_comments_fragment
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-06-25 12:20:22 -07:00
|
|
|
_glcpp_parser_handle_version_declaration(parser, $3, $4, true);
|
2014-01-17 14:22:49 -08:00
|
|
|
}
|
2014-06-25 11:59:55 -07:00
|
|
|
| HASH_TOKEN NEWLINE {
|
2014-01-25 11:57:02 -08:00
|
|
|
glcpp_parser_resolve_implicit_version(parser);
|
2012-08-02 13:21:54 -07:00
|
|
|
}
|
2014-06-25 13:55:18 -07:00
|
|
|
| HASH_TOKEN PRAGMA NEWLINE {
|
glsl/glcpp: Correctly parse directives with intervening comments
It's legal (though highly bizarre) for a pre-processor directive to look like
this:
# /* why? */ define FOO bar
This behavior comes about since the specification defines separate logical
phases in a precise order, and comment-removal occurs in a phase before the
identification of directives.
Our implementation does not use an actual separate phase for comment removal,
so some extra care is necessary to correctly parse this. What we want is for
'#' to introduce a directive iff it is the first token on a line, (ignoring
whitespace and comments). Previously, we had a lexical rule that worked only
for whitespace (not comments) with the following regular expression to find a
directive-introducing '#' at the beginning of a line:
HASH ^{HSPACE}*#{HSPACE}*
In this commit, we switch to instead use a simple literal match of '#' to
return a HASH_TOKEN token and add a new <HASH> start condition for whenever
the HASH_TOKEN is the first non-space token of a line. This requires the
addition of the new bit of state: first_non_space_token_this_line.
This approach has a couple of implications on the glcpp parser:
1. The parser now sees two separate tokens, (such as HASH_TOKEN and
HASH_DEFINE) where it previously saw one token (HASH_DEFINE) for
the sequence "#define". This is a straightforward change throughout
the grammar.
2. The parser may now see a SPACE token before the HASH_TOKEN token of
a directive. Previously the lexical regular expression for {HASH}
would eat up the space and there would be no SPACE token.
This second implication is a bit of a nuisance for the parser. It causes a
SPACE token to appear in a production of the grammar with the following two
definitions of a control_line:
control_line
SPACE control_line
This is really ugly, since normally a space would simply be a token
separator, so it wouldn't appear in the tokens of a production. This leads to
a further problem with interleaved spaces and comments:
/* ... */ /* ... */ #define /* ..*/
For this, we must not return several consecutive SPACE tokens, or else we would need an arbitrary number of new productions:
SPACE SPACE control_line
SPACE SPACE SPACE control_line
ad nauseam
To avoid this problem, in this commit we also change the lexer to emit only a
single SPACE token for any series of consecutive spaces, (whether from actual
whitespace or comments). For this compression, we add a new bit of parser
state: last_token_was_space. And we also update the expected results of all
necessary test cases for the new compression of space tokens.
Fortunately, the compression of spaces should not lead to any semantic changes
in terms of what the eventual GLSL compiler sees.
So there's a lot happening in this commit, (particularly for such a tiny
feature). But fortunately, the lexer itself is looking cleaner than ever. The
only ugly bit is all the state updating, but it is at least isolated to a
single shared function.
Of course, a new "make check" test is added for the new feature, (directives
with comments and whitespace interleaved in many combinations).
And this commit fixes the following Khronos GLES3 CTS tests:
function_definition_with_comments_vertex
function_definition_with_comments_fragment
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-06-25 12:20:22 -07:00
|
|
|
ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "#%s", $2);
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
control_line_error:
|
2014-07-29 16:56:06 -06:00
|
|
|
HASH_TOKEN ERROR_TOKEN NEWLINE {
|
glsl/glcpp: Correctly parse directives with intervening comments
It's legal (though highly bizarre) for a pre-processor directive to look like
this:
# /* why? */ define FOO bar
This behavior comes about since the specification defines separate logical
phases in a precise order, and comment-removal occurs in a phase before the
identification of directives.
Our implementation does not use an actual separate phase for comment removal,
so some extra care is necessary to correctly parse this. What we want is for
'#' to introduce a directive iff it is the first token on a line, (ignoring
whitespace and comments). Previously, we had a lexical rule that worked only
for whitespace (not comments) with the following regular expression to find a
directive-introducing '#' at the beginning of a line:
HASH ^{HSPACE}*#{HSPACE}*
In this commit, we switch to instead use a simple literal match of '#' to
return a HASH_TOKEN token and add a new <HASH> start condition for whenever
the HASH_TOKEN is the first non-space token of a line. This requires the
addition of the new bit of state: first_non_space_token_this_line.
This approach has a couple of implications on the glcpp parser:
1. The parser now sees two separate tokens, (such as HASH_TOKEN and
HASH_DEFINE) where it previously saw one token (HASH_DEFINE) for
the sequence "#define". This is a straightforward change throughout
the grammar.
2. The parser may now see a SPACE token before the HASH_TOKEN token of
a directive. Previously the lexical regular expression for {HASH}
would eat up the space and there would be no SPACE token.
This second implication is a bit of a nuisance for the parser. It causes a
SPACE token to appear in a production of the grammar with the following two
definitions of a control_line:
control_line
SPACE control_line
This is really ugly, since normally a space would simply be a token
separator, so it wouldn't appear in the tokens of a production. This leads to
a further problem with interleaved spaces and comments:
/* ... */ /* ... */ #define /* ..*/
For this, we must not return several consecutive SPACE tokens, or else we would need an arbitrary number of new productions:
SPACE SPACE control_line
SPACE SPACE SPACE control_line
ad nauseam
To avoid this problem, in this commit we also change the lexer to emit only a
single SPACE token for any series of consecutive spaces, (whether from actual
whitespace or comments). For this compression, we add a new bit of parser
state: last_token_was_space. And we also update the expected results of all
necessary test cases for the new compression of space tokens.
Fortunately, the compression of spaces should not lead to any semantic changes
in terms of what the eventual GLSL compiler sees.
So there's a lot happening in this commit, (particularly for such a tiny
feature). But fortunately, the lexer itself is looking cleaner than ever. The
only ugly bit is all the state updating, but it is at least isolated to a
single shared function.
Of course, a new "make check" test is added for the new feature, (directives
with comments and whitespace interleaved in many combinations).
And this commit fixes the following Khronos GLES3 CTS tests:
function_definition_with_comments_vertex
function_definition_with_comments_fragment
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-06-25 12:20:22 -07:00
|
|
|
glcpp_error(& @1, parser, "#%s", $2);
|
|
|
|
|
}
|
2014-07-01 17:40:28 -07:00
|
|
|
| HASH_TOKEN DEFINE_TOKEN NEWLINE {
|
|
|
|
|
glcpp_error (& @1, parser, "#define without macro name");
|
|
|
|
|
}
|
2014-06-25 13:55:18 -07:00
|
|
|
| HASH_TOKEN GARBAGE pp_tokens NEWLINE {
|
glsl/glcpp: Correctly parse directives with intervening comments
It's legal (though highly bizarre) for a pre-processor directive to look like
this:
# /* why? */ define FOO bar
This behavior comes about since the specification defines separate logical
phases in a precise order, and comment-removal occurs in a phase before the
identification of directives.
Our implementation does not use an actual separate phase for comment removal,
so some extra care is necessary to correctly parse this. What we want is for
'#' to introduce a directive iff it is the first token on a line, (ignoring
whitespace and comments). Previously, we had a lexical rule that worked only
for whitespace (not comments) with the following regular expression to find a
directive-introducing '#' at the beginning of a line:
HASH ^{HSPACE}*#{HSPACE}*
In this commit, we switch to instead use a simple literal match of '#' to
return a HASH_TOKEN token and add a new <HASH> start condition for whenever
the HASH_TOKEN is the first non-space token of a line. This requires the
addition of the new bit of state: first_non_space_token_this_line.
This approach has a couple of implications on the glcpp parser:
1. The parser now sees two separate tokens, (such as HASH_TOKEN and
HASH_DEFINE) where it previously saw one token (HASH_DEFINE) for
the sequence "#define". This is a straightforward change throughout
the grammar.
2. The parser may now see a SPACE token before the HASH_TOKEN token of
a directive. Previously the lexical regular expression for {HASH}
would eat up the space and there would be no SPACE token.
This second implication is a bit of a nuisance for the parser. It causes a
SPACE token to appear in a production of the grammar with the following two
definitions of a control_line:
control_line
SPACE control_line
This is really ugly, since normally a space would simply be a token
separator, so it wouldn't appear in the tokens of a production. This leads to
a further problem with interleaved spaces and comments:
/* ... */ /* ... */ #define /* ..*/
For this, we must not return several consecutive SPACE tokens, or else we would need an arbitrary number of new productions:
SPACE SPACE control_line
SPACE SPACE SPACE control_line
ad nauseam
To avoid this problem, in this commit we also change the lexer to emit only a
single SPACE token for any series of consecutive spaces, (whether from actual
whitespace or comments). For this compression, we add a new bit of parser
state: last_token_was_space. And we also update the expected results of all
necessary test cases for the new compression of space tokens.
Fortunately, the compression of spaces should not lead to any semantic changes
in terms of what the eventual GLSL compiler sees.
So there's a lot happening in this commit, (particularly for such a tiny
feature). But fortunately, the lexer itself is looking cleaner than ever. The
only ugly bit is all the state updating, but it is at least isolated to a
single shared function.
Of course, a new "make check" test is added for the new feature, (directives
with comments and whitespace interleaved in many combinations).
And this commit fixes the following Khronos GLES3 CTS tests:
function_definition_with_comments_vertex
function_definition_with_comments_fragment
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-06-25 12:20:22 -07:00
|
|
|
glcpp_error (& @1, parser, "Illegal non-directive after #");
|
|
|
|
|
}
|
2010-05-13 09:36:23 -07:00
|
|
|
;
|
|
|
|
|
|
2010-07-28 16:58:39 -07:00
|
|
|
integer_constant:
|
2010-05-27 14:36:29 -07:00
|
|
|
INTEGER_STRING {
|
|
|
|
|
if (strlen ($1) >= 3 && strncmp ($1, "0x", 2) == 0) {
|
|
|
|
|
$$ = strtoll ($1 + 2, NULL, 16);
|
|
|
|
|
} else if ($1[0] == '0') {
|
|
|
|
|
$$ = strtoll ($1, NULL, 8);
|
|
|
|
|
} else {
|
|
|
|
|
$$ = strtoll ($1, NULL, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
| INTEGER {
|
2010-05-26 09:32:12 -07:00
|
|
|
$$ = $1;
|
|
|
|
|
}
|
2010-07-28 16:58:39 -07:00
|
|
|
|
2016-11-08 11:06:05 -08:00
|
|
|
version_constant:
|
|
|
|
|
INTEGER_STRING {
|
|
|
|
|
/* Both octal and hexadecimal constants begin with 0. */
|
|
|
|
|
if ($1[0] == '0' && $1[1] != '\0') {
|
|
|
|
|
glcpp_error(&@1, parser, "invalid #version \"%s\" (not a decimal constant)", $1);
|
|
|
|
|
$$ = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$$ = strtoll($1, NULL, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 16:58:39 -07:00
|
|
|
expression:
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
integer_constant {
|
|
|
|
|
$$.value = $1;
|
2014-06-13 15:16:05 -07:00
|
|
|
$$.undefined_macro = NULL;
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
}
|
2012-06-08 15:00:49 -07:00
|
|
|
| IDENTIFIER {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = 0;
|
2012-11-26 15:00:05 -08:00
|
|
|
if (parser->is_gles)
|
2016-10-07 04:49:13 +02:00
|
|
|
$$.undefined_macro = linear_strdup(parser->linalloc, $1);
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
else
|
2014-06-13 15:16:05 -07:00
|
|
|
$$.undefined_macro = NULL;
|
2012-06-08 15:00:49 -07:00
|
|
|
}
|
2010-05-26 09:32:12 -07:00
|
|
|
| expression OR expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value || $3.value;
|
|
|
|
|
|
|
|
|
|
/* Short-circuit: Only flag undefined from right side
|
|
|
|
|
* if left side evaluates to false.
|
|
|
|
|
*/
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else if (! $1.value)
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression AND expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value && $3.value;
|
|
|
|
|
|
|
|
|
|
/* Short-circuit: Only flag undefined from right-side
|
|
|
|
|
* if left side evaluates to true.
|
|
|
|
|
*/
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else if ($1.value)
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression '|' expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value | $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression '^' expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value ^ $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression '&' expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value & $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression NOT_EQUAL expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value != $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression EQUAL expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value == $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression GREATER_OR_EQUAL expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value >= $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression LESS_OR_EQUAL expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value <= $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression '>' expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value > $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression '<' expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value < $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression RIGHT_SHIFT expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value >> $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression LEFT_SHIFT expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value << $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression '-' expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value - $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression '+' expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value + $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression '%' expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
if ($3.value == 0) {
|
2011-02-02 10:15:19 -08:00
|
|
|
yyerror (& @1, parser,
|
|
|
|
|
"zero modulus in preprocessor directive");
|
|
|
|
|
} else {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value % $3.value;
|
2011-02-02 10:15:19 -08:00
|
|
|
}
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression '/' expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
if ($3.value == 0) {
|
2011-01-10 13:33:07 -08:00
|
|
|
yyerror (& @1, parser,
|
|
|
|
|
"division by 0 in preprocessor directive");
|
|
|
|
|
} else {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value / $3.value;
|
2011-01-10 13:33:07 -08:00
|
|
|
}
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| expression '*' expression {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = $1.value * $3.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
if ($1.undefined_macro)
|
|
|
|
|
$$.undefined_macro = $1.undefined_macro;
|
|
|
|
|
else
|
|
|
|
|
$$.undefined_macro = $3.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| '!' expression %prec UNARY {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = ! $2.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
$$.undefined_macro = $2.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| '~' expression %prec UNARY {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = ~ $2.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
$$.undefined_macro = $2.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| '-' expression %prec UNARY {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = - $2.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
$$.undefined_macro = $2.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| '+' expression %prec UNARY {
|
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.
The GLSL ES Specification 3.00.4 says:
#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
as for C++ except for the following:
...
• Undefined identifiers not consumed by the defined operator do not
default to '0'. Use of such identifiers causes an error.
[Page 11 (page 127 of the PDF file)]
as well as:
The semantics of applying operators in the preprocessor match those
standard in the C++ preprocessor with the following exceptions:
• The 2nd operand in a logical and ('&&') operation is evaluated if
and only if the 1st operand evaluates to non-zero.
• The 2nd operand in a logical or ('||') operation is evaluated if
and only if the 1st operand evaluates to zero.
If an operand is not evaluated, the presence of undefined identifiers
in the operand will not cause an error.
(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).
The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.
A test is added for "make check" to ensure this behavior.
Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).
This commit fixes the following Khronos GLES3 conformance test:
undefined_identifiers.valid_undefined_identifier_1_vertex
undefined_identifiers.valid_undefined_identifier_1_fragment
undefined_identifiers.valid_undefined_identifier_2_vertex
undefined_identifiers.valid_undefined_identifier_2_fragment
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-06-13 14:54:46 -07:00
|
|
|
$$.value = + $2.value;
|
2014-06-13 15:16:05 -07:00
|
|
|
$$.undefined_macro = $2.undefined_macro;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
|
|
|
|
| '(' expression ')' {
|
|
|
|
|
$$ = $2;
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2010-05-25 13:09:03 -07:00
|
|
|
identifier_list:
|
2010-05-25 16:28:26 -07:00
|
|
|
IDENTIFIER {
|
|
|
|
|
$$ = _string_list_create (parser);
|
2016-10-07 04:49:13 +02:00
|
|
|
_string_list_append_item (parser, $$, $1);
|
2010-05-25 16:28:26 -07:00
|
|
|
}
|
|
|
|
|
| identifier_list ',' IDENTIFIER {
|
|
|
|
|
$$ = $1;
|
2016-10-07 04:49:13 +02:00
|
|
|
_string_list_append_item (parser, $$, $3);
|
2010-05-25 16:28:26 -07:00
|
|
|
}
|
2010-05-13 09:36:23 -07:00
|
|
|
;
|
|
|
|
|
|
2010-05-25 13:09:03 -07:00
|
|
|
text_line:
|
2010-05-25 14:52:43 -07:00
|
|
|
NEWLINE { $$ = NULL; }
|
2010-05-25 13:09:03 -07:00
|
|
|
| pp_tokens NEWLINE
|
2010-05-19 07:49:47 -07:00
|
|
|
;
|
|
|
|
|
|
2010-05-25 13:09:03 -07:00
|
|
|
replacement_list:
|
2010-05-25 14:52:43 -07:00
|
|
|
/* empty */ { $$ = NULL; }
|
2010-05-25 13:09:03 -07:00
|
|
|
| pp_tokens
|
2010-05-10 11:44:09 -07:00
|
|
|
;
|
|
|
|
|
|
2010-06-18 20:08:15 -07:00
|
|
|
junk:
|
|
|
|
|
/* empty */
|
|
|
|
|
| pp_tokens {
|
2014-06-13 15:40:42 -07:00
|
|
|
glcpp_error(&@1, parser, "extra tokens at end of directive");
|
2010-06-18 20:08:15 -07:00
|
|
|
}
|
2010-06-18 23:06:54 -07:00
|
|
|
;
|
|
|
|
|
|
2010-05-25 13:09:03 -07:00
|
|
|
pp_tokens:
|
2010-05-25 14:52:43 -07:00
|
|
|
preprocessing_token {
|
2010-05-25 16:59:02 -07:00
|
|
|
parser->space_tokens = 1;
|
2010-05-25 14:52:43 -07:00
|
|
|
$$ = _token_list_create (parser);
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_append (parser, $$, $1);
|
2010-05-25 14:52:43 -07:00
|
|
|
}
|
|
|
|
|
| pp_tokens preprocessing_token {
|
|
|
|
|
$$ = $1;
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_append (parser, $$, $2);
|
2010-05-25 14:52:43 -07:00
|
|
|
}
|
2010-05-20 22:27:07 -07:00
|
|
|
;
|
|
|
|
|
|
2010-05-25 13:09:03 -07:00
|
|
|
preprocessing_token:
|
2010-05-25 14:52:43 -07:00
|
|
|
IDENTIFIER {
|
|
|
|
|
$$ = _token_create_str (parser, IDENTIFIER, $1);
|
2010-06-16 16:58:31 -07:00
|
|
|
$$->location = yylloc;
|
2010-05-25 14:52:43 -07:00
|
|
|
}
|
2010-05-27 14:36:29 -07:00
|
|
|
| INTEGER_STRING {
|
|
|
|
|
$$ = _token_create_str (parser, INTEGER_STRING, $1);
|
2010-06-16 16:58:31 -07:00
|
|
|
$$->location = yylloc;
|
2010-05-26 09:32:12 -07:00
|
|
|
}
|
2010-05-26 11:15:21 -07:00
|
|
|
| operator {
|
2010-05-25 14:52:43 -07:00
|
|
|
$$ = _token_create_ival (parser, $1, $1);
|
2010-06-16 16:58:31 -07:00
|
|
|
$$->location = yylloc;
|
2010-05-25 14:52:43 -07:00
|
|
|
}
|
2014-07-02 12:52:33 -07:00
|
|
|
| DEFINED {
|
|
|
|
|
$$ = _token_create_ival (parser, DEFINED, DEFINED);
|
|
|
|
|
$$->location = yylloc;
|
|
|
|
|
}
|
2010-05-25 14:52:43 -07:00
|
|
|
| OTHER {
|
|
|
|
|
$$ = _token_create_str (parser, OTHER, $1);
|
2010-06-16 16:58:31 -07:00
|
|
|
$$->location = yylloc;
|
2010-05-25 14:52:43 -07:00
|
|
|
}
|
2010-05-25 16:28:26 -07:00
|
|
|
| SPACE {
|
2010-05-25 17:08:07 -07:00
|
|
|
$$ = _token_create_ival (parser, SPACE, SPACE);
|
2010-06-16 16:58:31 -07:00
|
|
|
$$->location = yylloc;
|
2010-05-25 16:28:26 -07:00
|
|
|
}
|
2010-05-13 09:36:23 -07:00
|
|
|
;
|
|
|
|
|
|
2010-05-26 11:15:21 -07:00
|
|
|
operator:
|
2010-05-25 14:52:43 -07:00
|
|
|
'[' { $$ = '['; }
|
|
|
|
|
| ']' { $$ = ']'; }
|
|
|
|
|
| '(' { $$ = '('; }
|
|
|
|
|
| ')' { $$ = ')'; }
|
|
|
|
|
| '{' { $$ = '{'; }
|
|
|
|
|
| '}' { $$ = '}'; }
|
|
|
|
|
| '.' { $$ = '.'; }
|
|
|
|
|
| '&' { $$ = '&'; }
|
|
|
|
|
| '*' { $$ = '*'; }
|
|
|
|
|
| '+' { $$ = '+'; }
|
|
|
|
|
| '-' { $$ = '-'; }
|
|
|
|
|
| '~' { $$ = '~'; }
|
|
|
|
|
| '!' { $$ = '!'; }
|
|
|
|
|
| '/' { $$ = '/'; }
|
|
|
|
|
| '%' { $$ = '%'; }
|
|
|
|
|
| LEFT_SHIFT { $$ = LEFT_SHIFT; }
|
|
|
|
|
| RIGHT_SHIFT { $$ = RIGHT_SHIFT; }
|
|
|
|
|
| '<' { $$ = '<'; }
|
|
|
|
|
| '>' { $$ = '>'; }
|
|
|
|
|
| LESS_OR_EQUAL { $$ = LESS_OR_EQUAL; }
|
|
|
|
|
| GREATER_OR_EQUAL { $$ = GREATER_OR_EQUAL; }
|
|
|
|
|
| EQUAL { $$ = EQUAL; }
|
|
|
|
|
| NOT_EQUAL { $$ = NOT_EQUAL; }
|
|
|
|
|
| '^' { $$ = '^'; }
|
|
|
|
|
| '|' { $$ = '|'; }
|
|
|
|
|
| AND { $$ = AND; }
|
|
|
|
|
| OR { $$ = OR; }
|
|
|
|
|
| ';' { $$ = ';'; }
|
|
|
|
|
| ',' { $$ = ','; }
|
2010-05-29 05:07:24 -07:00
|
|
|
| '=' { $$ = '='; }
|
2010-05-25 14:52:43 -07:00
|
|
|
| PASTE { $$ = PASTE; }
|
2014-06-25 14:17:37 -07:00
|
|
|
| PLUS_PLUS { $$ = PLUS_PLUS; }
|
|
|
|
|
| MINUS_MINUS { $$ = MINUS_MINUS; }
|
2010-05-19 13:28:24 -07:00
|
|
|
;
|
|
|
|
|
|
2010-05-10 11:44:09 -07:00
|
|
|
%%
|
|
|
|
|
|
2010-05-14 10:05:11 -07:00
|
|
|
string_list_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_string_list_create(glcpp_parser_t *parser)
|
2010-05-12 12:17:10 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
string_list_t *list;
|
2010-05-12 12:17:10 -07:00
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
list = linear_alloc_child(parser->linalloc, sizeof(string_list_t));
|
2016-03-31 16:49:59 +11:00
|
|
|
list->head = NULL;
|
|
|
|
|
list->tail = NULL;
|
2010-05-12 12:17:10 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return list;
|
2010-05-12 12:17:10 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-13 09:36:23 -07:00
|
|
|
void
|
2016-10-07 04:49:13 +02:00
|
|
|
_string_list_append_item(glcpp_parser_t *parser, string_list_t *list,
|
|
|
|
|
const char *str)
|
2010-05-12 12:17:10 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
string_node_t *node;
|
2010-05-12 12:17:10 -07:00
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
node = linear_alloc_child(parser->linalloc, sizeof(string_node_t));
|
|
|
|
|
node->str = linear_strdup(parser->linalloc, str);
|
2010-05-25 14:42:00 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
node->next = NULL;
|
2010-05-12 12:17:10 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list->head == NULL) {
|
|
|
|
|
list->head = node;
|
|
|
|
|
} else {
|
|
|
|
|
list->tail->next = node;
|
|
|
|
|
}
|
2010-05-12 12:17:10 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
list->tail = node;
|
2010-05-12 12:17:10 -07:00
|
|
|
}
|
2010-05-13 12:56:42 -07:00
|
|
|
|
|
|
|
|
int
|
2016-03-31 16:49:59 +11:00
|
|
|
_string_list_contains(string_list_t *list, const char *member, int *index)
|
2010-05-13 12:56:42 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
string_node_t *node;
|
|
|
|
|
int i;
|
2010-05-13 12:56:42 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list == NULL)
|
|
|
|
|
return 0;
|
2010-05-13 12:56:42 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
for (i = 0, node = list->head; node; i++, node = node->next) {
|
|
|
|
|
if (strcmp (node->str, member) == 0) {
|
|
|
|
|
if (index)
|
|
|
|
|
*index = i;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-13 12:56:42 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return 0;
|
2010-05-13 12:56:42 -07:00
|
|
|
}
|
|
|
|
|
|
2014-06-25 13:41:47 -07:00
|
|
|
/* Return duplicate string in list (if any), NULL otherwise. */
|
|
|
|
|
const char *
|
2016-03-31 16:49:59 +11:00
|
|
|
_string_list_has_duplicate(string_list_t *list)
|
2014-06-25 13:41:47 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
string_node_t *node, *dup;
|
2014-06-25 13:41:47 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list == NULL)
|
|
|
|
|
return NULL;
|
2014-06-25 13:41:47 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
for (node = list->head; node; node = node->next) {
|
|
|
|
|
for (dup = node->next; dup; dup = dup->next) {
|
|
|
|
|
if (strcmp (node->str, dup->str) == 0)
|
|
|
|
|
return node->str;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-25 13:41:47 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return NULL;
|
2014-06-25 13:41:47 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-13 12:56:42 -07:00
|
|
|
int
|
2016-03-31 16:49:59 +11:00
|
|
|
_string_list_length(string_list_t *list)
|
2010-05-13 12:56:42 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
int length = 0;
|
|
|
|
|
string_node_t *node;
|
2010-05-13 12:56:42 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list == NULL)
|
|
|
|
|
return 0;
|
2010-05-13 12:56:42 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
for (node = list->head; node; node = node->next)
|
|
|
|
|
length++;
|
2010-05-13 12:56:42 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return length;
|
2010-05-13 12:56:42 -07:00
|
|
|
}
|
|
|
|
|
|
2010-08-17 23:20:58 -07:00
|
|
|
int
|
2016-03-31 16:49:59 +11:00
|
|
|
_string_list_equal(string_list_t *a, string_list_t *b)
|
2010-08-17 23:20:58 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
string_node_t *node_a, *node_b;
|
|
|
|
|
|
|
|
|
|
if (a == NULL && b == NULL)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if (a == NULL || b == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
for (node_a = a->head, node_b = b->head;
|
|
|
|
|
node_a && node_b;
|
|
|
|
|
node_a = node_a->next, node_b = node_b->next)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (node_a->str, node_b->str))
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Catch the case of lists being different lengths, (which
|
|
|
|
|
* would cause the loop above to terminate after the shorter
|
|
|
|
|
* list). */
|
|
|
|
|
return node_a == node_b;
|
2010-08-17 23:20:58 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-14 10:44:19 -07:00
|
|
|
argument_list_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_argument_list_create(glcpp_parser_t *parser)
|
2010-05-13 12:56:42 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
argument_list_t *list;
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
list = linear_alloc_child(parser->linalloc, sizeof(argument_list_t));
|
2016-03-31 16:49:59 +11:00
|
|
|
list->head = NULL;
|
|
|
|
|
list->tail = NULL;
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return list;
|
2010-05-14 10:44:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2016-10-07 04:49:13 +02:00
|
|
|
_argument_list_append(glcpp_parser_t *parser,
|
|
|
|
|
argument_list_t *list, token_list_t *argument)
|
2010-05-14 10:44:19 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
argument_node_t *node;
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
node = linear_alloc_child(parser->linalloc, sizeof(argument_node_t));
|
2016-03-31 16:49:59 +11:00
|
|
|
node->argument = argument;
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
node->next = NULL;
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list->head == NULL) {
|
|
|
|
|
list->head = node;
|
|
|
|
|
} else {
|
|
|
|
|
list->tail->next = node;
|
|
|
|
|
}
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
list->tail = node;
|
2010-05-14 10:44:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2016-03-31 16:49:59 +11:00
|
|
|
_argument_list_length(argument_list_t *list)
|
2010-05-14 10:44:19 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
int length = 0;
|
|
|
|
|
argument_node_t *node;
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list == NULL)
|
|
|
|
|
return 0;
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
for (node = list->head; node; node = node->next)
|
|
|
|
|
length++;
|
2010-05-14 10:44:19 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return length;
|
2010-05-14 10:44:19 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-19 13:54:37 -07:00
|
|
|
token_list_t *
|
2016-03-31 16:49:59 +11:00
|
|
|
_argument_list_member_at(argument_list_t *list, int index)
|
2010-05-14 10:44:19 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
argument_node_t *node;
|
|
|
|
|
int i;
|
2010-05-13 12:56:42 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list == NULL)
|
|
|
|
|
return NULL;
|
2010-05-13 12:56:42 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
node = list->head;
|
|
|
|
|
for (i = 0; i < index; i++) {
|
|
|
|
|
node = node->next;
|
|
|
|
|
if (node == NULL)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-05-13 12:56:42 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (node)
|
|
|
|
|
return node->argument;
|
2010-05-13 12:56:42 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return NULL;
|
2010-05-13 12:56:42 -07:00
|
|
|
}
|
2010-05-19 13:54:37 -07:00
|
|
|
|
2010-05-25 14:52:43 -07:00
|
|
|
token_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_create_str(glcpp_parser_t *parser, int type, char *str)
|
2010-05-25 14:52:43 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_t *token;
|
2010-05-25 14:52:43 -07:00
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
token = linear_alloc_child(parser->linalloc, sizeof(token_t));
|
2016-03-31 16:49:59 +11:00
|
|
|
token->type = type;
|
|
|
|
|
token->value.str = str;
|
2011-01-21 14:32:31 -08:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return token;
|
2010-05-25 14:52:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
token_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_create_ival(glcpp_parser_t *parser, int type, int ival)
|
2010-05-25 14:52:43 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_t *token;
|
2010-05-25 14:52:43 -07:00
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
token = linear_alloc_child(parser->linalloc, sizeof(token_t));
|
2016-03-31 16:49:59 +11:00
|
|
|
token->type = type;
|
|
|
|
|
token->value.ival = ival;
|
2010-05-25 14:52:43 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return token;
|
2010-05-25 14:52:43 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-19 13:54:37 -07:00
|
|
|
token_list_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_create(glcpp_parser_t *parser)
|
2010-05-19 13:54:37 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_list_t *list;
|
2010-05-19 13:54:37 -07:00
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
list = linear_alloc_child(parser->linalloc, sizeof(token_list_t));
|
2016-03-31 16:49:59 +11:00
|
|
|
list->head = NULL;
|
|
|
|
|
list->tail = NULL;
|
|
|
|
|
list->non_space_tail = NULL;
|
2010-05-19 13:54:37 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return list;
|
2010-05-19 13:54:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_append(glcpp_parser_t *parser, token_list_t *list, token_t *token)
|
2010-05-19 13:54:37 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_node_t *node;
|
2010-05-19 13:54:37 -07:00
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
node = linear_alloc_child(parser->linalloc, sizeof(token_node_t));
|
2016-03-31 16:49:59 +11:00
|
|
|
node->token = token;
|
|
|
|
|
node->next = NULL;
|
2010-05-19 13:54:37 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list->head == NULL) {
|
|
|
|
|
list->head = node;
|
|
|
|
|
} else {
|
|
|
|
|
list->tail->next = node;
|
|
|
|
|
}
|
2010-05-19 13:54:37 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
list->tail = node;
|
|
|
|
|
if (token->type != SPACE)
|
|
|
|
|
list->non_space_tail = node;
|
2010-05-19 13:54:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2016-03-31 16:49:59 +11:00
|
|
|
_token_list_append_list(token_list_t *list, token_list_t *tail)
|
2010-05-19 13:54:37 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
if (tail == NULL || tail->head == NULL)
|
|
|
|
|
return;
|
2010-05-27 11:55:36 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list->head == NULL) {
|
|
|
|
|
list->head = tail->head;
|
|
|
|
|
} else {
|
|
|
|
|
list->tail->next = tail->head;
|
|
|
|
|
}
|
2010-05-19 13:54:37 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
list->tail = tail->tail;
|
|
|
|
|
list->non_space_tail = tail->non_space_tail;
|
2010-05-25 20:35:01 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-20 15:55:21 -07:00
|
|
|
static token_list_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_copy(glcpp_parser_t *parser, token_list_t *other)
|
2010-05-28 15:06:02 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_list_t *copy;
|
|
|
|
|
token_node_t *node;
|
2010-05-28 15:06:02 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (other == NULL)
|
|
|
|
|
return NULL;
|
2010-05-28 15:06:02 -07:00
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
copy = _token_list_create (parser);
|
2016-03-31 16:49:59 +11:00
|
|
|
for (node = other->head; node; node = node->next) {
|
2016-10-07 04:49:13 +02:00
|
|
|
token_t *new_token = linear_alloc_child(parser->linalloc, sizeof(token_t));
|
2016-03-31 16:49:59 +11:00
|
|
|
*new_token = *node->token;
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_append (parser, copy, new_token);
|
2016-03-31 16:49:59 +11:00
|
|
|
}
|
2010-05-28 15:06:02 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return copy;
|
2010-05-28 15:06:02 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-20 15:55:21 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_token_list_trim_trailing_space(token_list_t *list)
|
2010-05-25 20:35:01 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list->non_space_tail) {
|
|
|
|
|
list->non_space_tail->next = NULL;
|
|
|
|
|
list->tail = list->non_space_tail;
|
|
|
|
|
}
|
2010-05-19 13:54:37 -07:00
|
|
|
}
|
2010-05-25 14:42:00 -07:00
|
|
|
|
2011-01-31 14:08:22 -07:00
|
|
|
static int
|
2016-03-31 16:49:59 +11:00
|
|
|
_token_list_is_empty_ignoring_space(token_list_t *l)
|
2011-01-10 16:55:17 -08:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_node_t *n;
|
2011-01-10 16:55:17 -08:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (l == NULL)
|
|
|
|
|
return 1;
|
2011-01-10 16:55:17 -08:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
n = l->head;
|
|
|
|
|
while (n != NULL && n->token->type == SPACE)
|
|
|
|
|
n = n->next;
|
2011-01-10 16:55:17 -08:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return n == NULL;
|
2011-01-10 16:55:17 -08:00
|
|
|
}
|
|
|
|
|
|
2010-08-17 23:20:58 -07:00
|
|
|
int
|
2016-03-31 16:49:59 +11:00
|
|
|
_token_list_equal_ignoring_space(token_list_t *a, token_list_t *b)
|
2010-08-17 23:20:58 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_node_t *node_a, *node_b;
|
|
|
|
|
|
|
|
|
|
if (a == NULL || b == NULL) {
|
|
|
|
|
int a_empty = _token_list_is_empty_ignoring_space(a);
|
|
|
|
|
int b_empty = _token_list_is_empty_ignoring_space(b);
|
|
|
|
|
return a_empty == b_empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node_a = a->head;
|
|
|
|
|
node_b = b->head;
|
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
if (node_a == NULL && node_b == NULL)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (node_a == NULL || node_b == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
/* Make sure whitespace appears in the same places in both.
|
|
|
|
|
* It need not be exactly the same amount of whitespace,
|
|
|
|
|
* though.
|
|
|
|
|
*/
|
|
|
|
|
if (node_a->token->type == SPACE && node_b->token->type == SPACE) {
|
|
|
|
|
while (node_a && node_a->token->type == SPACE)
|
|
|
|
|
node_a = node_a->next;
|
|
|
|
|
while (node_b && node_b->token->type == SPACE)
|
|
|
|
|
node_b = node_b->next;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (node_a->token->type != node_b->token->type)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
switch (node_a->token->type) {
|
|
|
|
|
case INTEGER:
|
|
|
|
|
if (node_a->token->value.ival != node_b->token->value.ival) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case IDENTIFIER:
|
|
|
|
|
case INTEGER_STRING:
|
|
|
|
|
case OTHER:
|
|
|
|
|
if (strcmp(node_a->token->value.str, node_b->token->value.str)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node_a = node_a->next;
|
|
|
|
|
node_b = node_b->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
2010-08-17 23:20:58 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-26 08:05:19 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_token_print(char **out, size_t *len, token_t *token)
|
2010-05-26 08:05:19 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
if (token->type < 256) {
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "%c", token->type);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (token->type) {
|
|
|
|
|
case INTEGER:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "%" PRIiMAX, token->value.ival);
|
|
|
|
|
break;
|
|
|
|
|
case IDENTIFIER:
|
|
|
|
|
case INTEGER_STRING:
|
|
|
|
|
case OTHER:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "%s", token->value.str);
|
|
|
|
|
break;
|
|
|
|
|
case SPACE:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, " ");
|
|
|
|
|
break;
|
|
|
|
|
case LEFT_SHIFT:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "<<");
|
|
|
|
|
break;
|
|
|
|
|
case RIGHT_SHIFT:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, ">>");
|
|
|
|
|
break;
|
|
|
|
|
case LESS_OR_EQUAL:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "<=");
|
|
|
|
|
break;
|
|
|
|
|
case GREATER_OR_EQUAL:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, ">=");
|
|
|
|
|
break;
|
|
|
|
|
case EQUAL:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "==");
|
|
|
|
|
break;
|
|
|
|
|
case NOT_EQUAL:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "!=");
|
|
|
|
|
break;
|
|
|
|
|
case AND:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "&&");
|
|
|
|
|
break;
|
|
|
|
|
case OR:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "||");
|
|
|
|
|
break;
|
|
|
|
|
case PASTE:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "##");
|
|
|
|
|
break;
|
|
|
|
|
case PLUS_PLUS:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "++");
|
|
|
|
|
break;
|
|
|
|
|
case MINUS_MINUS:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "--");
|
|
|
|
|
break;
|
|
|
|
|
case DEFINED:
|
|
|
|
|
ralloc_asprintf_rewrite_tail (out, len, "defined");
|
|
|
|
|
break;
|
|
|
|
|
case PLACEHOLDER:
|
|
|
|
|
/* Nothing to print. */
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(!"Error: Don't know how to print token.");
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-05-26 08:05:19 -07:00
|
|
|
}
|
|
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
/* Return a new token formed by pasting 'token' and 'other'. Note that this
|
|
|
|
|
* function may return 'token' or 'other' directly rather than allocating
|
|
|
|
|
* anything new.
|
2010-05-29 05:54:19 -07:00
|
|
|
*
|
|
|
|
|
* Caution: Only very cursory error-checking is performed to see if
|
|
|
|
|
* the final result is a valid single token. */
|
|
|
|
|
static token_t *
|
2016-03-31 16:49:59 +11:00
|
|
|
_token_paste(glcpp_parser_t *parser, token_t *token, token_t *other)
|
2010-05-26 09:04:50 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_t *combined = NULL;
|
|
|
|
|
|
|
|
|
|
/* Pasting a placeholder onto anything makes no change. */
|
|
|
|
|
if (other->type == PLACEHOLDER)
|
|
|
|
|
return token;
|
|
|
|
|
|
|
|
|
|
/* When 'token' is a placeholder, just return 'other'. */
|
|
|
|
|
if (token->type == PLACEHOLDER)
|
|
|
|
|
return other;
|
|
|
|
|
|
|
|
|
|
/* A very few single-character punctuators can be combined
|
|
|
|
|
* with another to form a multi-character punctuator. */
|
|
|
|
|
switch (token->type) {
|
|
|
|
|
case '<':
|
|
|
|
|
if (other->type == '<')
|
2016-10-07 04:49:13 +02:00
|
|
|
combined = _token_create_ival (parser, LEFT_SHIFT, LEFT_SHIFT);
|
2016-03-31 16:49:59 +11:00
|
|
|
else if (other->type == '=')
|
2016-10-07 04:49:13 +02:00
|
|
|
combined = _token_create_ival (parser, LESS_OR_EQUAL, LESS_OR_EQUAL);
|
2016-03-31 16:49:59 +11:00
|
|
|
break;
|
|
|
|
|
case '>':
|
|
|
|
|
if (other->type == '>')
|
2016-10-07 04:49:13 +02:00
|
|
|
combined = _token_create_ival (parser, RIGHT_SHIFT, RIGHT_SHIFT);
|
2016-03-31 16:49:59 +11:00
|
|
|
else if (other->type == '=')
|
2016-10-07 04:49:13 +02:00
|
|
|
combined = _token_create_ival (parser, GREATER_OR_EQUAL, GREATER_OR_EQUAL);
|
2016-03-31 16:49:59 +11:00
|
|
|
break;
|
|
|
|
|
case '=':
|
|
|
|
|
if (other->type == '=')
|
2016-10-07 04:49:13 +02:00
|
|
|
combined = _token_create_ival (parser, EQUAL, EQUAL);
|
2016-03-31 16:49:59 +11:00
|
|
|
break;
|
|
|
|
|
case '!':
|
|
|
|
|
if (other->type == '=')
|
2016-10-07 04:49:13 +02:00
|
|
|
combined = _token_create_ival (parser, NOT_EQUAL, NOT_EQUAL);
|
2016-03-31 16:49:59 +11:00
|
|
|
break;
|
|
|
|
|
case '&':
|
|
|
|
|
if (other->type == '&')
|
2016-10-07 04:49:13 +02:00
|
|
|
combined = _token_create_ival (parser, AND, AND);
|
2016-03-31 16:49:59 +11:00
|
|
|
break;
|
|
|
|
|
case '|':
|
|
|
|
|
if (other->type == '|')
|
2016-10-07 04:49:13 +02:00
|
|
|
combined = _token_create_ival (parser, OR, OR);
|
2016-03-31 16:49:59 +11:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (combined != NULL) {
|
|
|
|
|
/* Inherit the location from the first token */
|
|
|
|
|
combined->location = token->location;
|
|
|
|
|
return combined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Two string-valued (or integer) tokens can usually just be
|
|
|
|
|
* mashed together. (We also handle a string followed by an
|
|
|
|
|
* integer here as well.)
|
|
|
|
|
*
|
|
|
|
|
* There are some exceptions here. Notably, if the first token
|
|
|
|
|
* is an integer (or a string representing an integer), then
|
|
|
|
|
* the second token must also be an integer or must be a
|
|
|
|
|
* string representing an integer that begins with a digit.
|
|
|
|
|
*/
|
|
|
|
|
if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING || token->type == INTEGER) &&
|
|
|
|
|
(other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING || other->type == INTEGER))
|
|
|
|
|
{
|
|
|
|
|
char *str;
|
|
|
|
|
int combined_type;
|
|
|
|
|
|
|
|
|
|
/* Check that pasting onto an integer doesn't create a
|
|
|
|
|
* non-integer, (that is, only digits can be
|
|
|
|
|
* pasted. */
|
|
|
|
|
if (token->type == INTEGER_STRING || token->type == INTEGER) {
|
|
|
|
|
switch (other->type) {
|
|
|
|
|
case INTEGER_STRING:
|
|
|
|
|
if (other->value.str[0] < '0' || other->value.str[0] > '9')
|
|
|
|
|
goto FAIL;
|
|
|
|
|
break;
|
|
|
|
|
case INTEGER:
|
|
|
|
|
if (other->value.ival < 0)
|
|
|
|
|
goto FAIL;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
goto FAIL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (token->type == INTEGER)
|
2016-10-07 04:49:13 +02:00
|
|
|
str = linear_asprintf(parser->linalloc, "%" PRIiMAX, token->value.ival);
|
2016-03-31 16:49:59 +11:00
|
|
|
else
|
2016-10-07 04:49:13 +02:00
|
|
|
str = linear_strdup(parser->linalloc, token->value.str);
|
2016-03-31 16:49:59 +11:00
|
|
|
|
|
|
|
|
if (other->type == INTEGER)
|
2016-10-07 04:49:13 +02:00
|
|
|
linear_asprintf_append(parser->linalloc, &str, "%" PRIiMAX, other->value.ival);
|
2016-03-31 16:49:59 +11:00
|
|
|
else
|
2016-10-07 04:49:13 +02:00
|
|
|
linear_strcat(parser->linalloc, &str, other->value.str);
|
2016-03-31 16:49:59 +11:00
|
|
|
|
|
|
|
|
/* New token is same type as original token, unless we
|
|
|
|
|
* started with an integer, in which case we will be
|
|
|
|
|
* creating an integer-string. */
|
|
|
|
|
combined_type = token->type;
|
|
|
|
|
if (combined_type == INTEGER)
|
|
|
|
|
combined_type = INTEGER_STRING;
|
|
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
combined = _token_create_str (parser, combined_type, str);
|
2016-03-31 16:49:59 +11:00
|
|
|
combined->location = token->location;
|
|
|
|
|
return combined;
|
|
|
|
|
}
|
2010-05-26 09:04:50 -07:00
|
|
|
|
2012-11-28 13:01:24 -08:00
|
|
|
FAIL:
|
2016-03-31 16:49:59 +11:00
|
|
|
glcpp_error (&token->location, parser, "");
|
|
|
|
|
ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "Pasting \"");
|
|
|
|
|
_token_print (&parser->info_log, &parser->info_log_length, token);
|
|
|
|
|
ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" and \"");
|
|
|
|
|
_token_print (&parser->info_log, &parser->info_log_length, other);
|
|
|
|
|
ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" does not give a valid preprocessing token.\n");
|
|
|
|
|
|
|
|
|
|
return token;
|
2010-05-26 09:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-26 08:05:19 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_token_list_print(glcpp_parser_t *parser, token_list_t *list)
|
2010-05-26 08:05:19 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_node_t *node;
|
2010-05-26 08:05:19 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list == NULL)
|
|
|
|
|
return;
|
2010-05-26 08:05:19 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
for (node = list->head; node; node = node->next)
|
|
|
|
|
_token_print (&parser->output, &parser->output_length, node->token);
|
2010-05-26 08:05:19 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-10 11:44:09 -07:00
|
|
|
void
|
2016-03-31 16:49:59 +11:00
|
|
|
yyerror(YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
|
2010-05-10 11:44:09 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
glcpp_error(locp, parser, "%s", error);
|
2010-05-10 11:44:09 -07:00
|
|
|
}
|
2010-05-10 16:16:06 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
static void
|
|
|
|
|
add_builtin_define(glcpp_parser_t *parser, const char *name, int value)
|
2010-07-28 16:58:39 -07:00
|
|
|
{
|
|
|
|
|
token_t *tok;
|
|
|
|
|
token_list_t *list;
|
|
|
|
|
|
|
|
|
|
tok = _token_create_ival (parser, INTEGER, value);
|
|
|
|
|
|
|
|
|
|
list = _token_list_create(parser);
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_append(parser, list, tok);
|
2010-07-28 16:58:39 -07:00
|
|
|
_define_object_macro(parser, NULL, name, list);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-12 12:17:10 -07:00
|
|
|
glcpp_parser_t *
|
2016-10-14 18:11:51 -07:00
|
|
|
glcpp_parser_create(const struct gl_extensions *extension_list,
|
|
|
|
|
glcpp_extension_iterator extensions, void *state, gl_api api)
|
2010-05-10 16:16:06 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
glcpp_parser_t *parser;
|
|
|
|
|
|
|
|
|
|
parser = ralloc (NULL, glcpp_parser_t);
|
|
|
|
|
|
|
|
|
|
glcpp_lex_init_extra (parser, &parser->scanner);
|
2016-08-18 21:59:19 +02:00
|
|
|
parser->defines = _mesa_hash_table_create(NULL, _mesa_key_hash_string,
|
|
|
|
|
_mesa_key_string_equal);
|
2016-10-07 04:49:13 +02:00
|
|
|
parser->linalloc = linear_alloc_parent(parser, 0);
|
2016-03-31 16:49:59 +11:00
|
|
|
parser->active = NULL;
|
|
|
|
|
parser->lexing_directive = 0;
|
2016-10-13 14:54:30 +03:00
|
|
|
parser->lexing_version_directive = 0;
|
2016-03-31 16:49:59 +11:00
|
|
|
parser->space_tokens = 1;
|
|
|
|
|
parser->last_token_was_newline = 0;
|
|
|
|
|
parser->last_token_was_space = 0;
|
|
|
|
|
parser->first_non_space_token_this_line = 1;
|
|
|
|
|
parser->newline_as_space = 0;
|
|
|
|
|
parser->in_control_line = 0;
|
|
|
|
|
parser->paren_count = 0;
|
|
|
|
|
parser->commented_newlines = 0;
|
|
|
|
|
|
|
|
|
|
parser->skip_stack = NULL;
|
|
|
|
|
parser->skipping = 0;
|
|
|
|
|
|
|
|
|
|
parser->lex_from_list = NULL;
|
|
|
|
|
parser->lex_from_node = NULL;
|
|
|
|
|
|
|
|
|
|
parser->output = ralloc_strdup(parser, "");
|
|
|
|
|
parser->output_length = 0;
|
|
|
|
|
parser->info_log = ralloc_strdup(parser, "");
|
|
|
|
|
parser->info_log_length = 0;
|
|
|
|
|
parser->error = 0;
|
|
|
|
|
|
|
|
|
|
parser->extensions = extensions;
|
2016-10-14 18:11:51 -07:00
|
|
|
parser->extension_list = extension_list;
|
2016-06-12 18:56:43 -04:00
|
|
|
parser->state = state;
|
2016-03-31 16:49:59 +11:00
|
|
|
parser->api = api;
|
2016-08-09 14:31:49 -07:00
|
|
|
parser->version = 0;
|
2016-11-08 11:06:05 -08:00
|
|
|
parser->version_set = false;
|
2016-03-31 16:49:59 +11:00
|
|
|
|
|
|
|
|
parser->has_new_line_number = 0;
|
|
|
|
|
parser->new_line_number = 1;
|
|
|
|
|
parser->has_new_source_number = 0;
|
|
|
|
|
parser->new_source_number = 0;
|
|
|
|
|
|
2016-10-13 14:54:30 +03:00
|
|
|
parser->is_gles = false;
|
|
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return parser;
|
2010-05-10 16:16:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2016-03-31 16:49:59 +11:00
|
|
|
glcpp_parser_destroy(glcpp_parser_t *parser)
|
2010-05-10 16:16:06 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
glcpp_lex_destroy (parser->scanner);
|
2016-08-18 21:59:19 +02:00
|
|
|
_mesa_hash_table_destroy(parser->defines, NULL);
|
2016-03-31 16:49:59 +11:00
|
|
|
ralloc_free (parser);
|
2010-05-10 16:16:06 -07:00
|
|
|
}
|
2010-05-11 12:30:09 -07:00
|
|
|
|
2010-05-25 16:28:26 -07:00
|
|
|
typedef enum function_status
|
|
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
FUNCTION_STATUS_SUCCESS,
|
|
|
|
|
FUNCTION_NOT_A_FUNCTION,
|
|
|
|
|
FUNCTION_UNBALANCED_PARENTHESES
|
2010-05-25 16:28:26 -07:00
|
|
|
} function_status_t;
|
|
|
|
|
|
|
|
|
|
/* Find a set of function-like macro arguments by looking for a
|
2010-05-28 15:06:02 -07:00
|
|
|
* balanced set of parentheses.
|
|
|
|
|
*
|
|
|
|
|
* When called, 'node' should be the opening-parenthesis token, (or
|
|
|
|
|
* perhaps preceeding SPACE tokens). Upon successful return *last will
|
|
|
|
|
* be the last consumed node, (corresponding to the closing right
|
|
|
|
|
* parenthesis).
|
2010-05-25 16:28:26 -07:00
|
|
|
*
|
|
|
|
|
* Return values:
|
|
|
|
|
*
|
|
|
|
|
* FUNCTION_STATUS_SUCCESS:
|
|
|
|
|
*
|
2016-03-31 16:49:59 +11:00
|
|
|
* Successfully parsed a set of function arguments.
|
2010-05-25 16:28:26 -07:00
|
|
|
*
|
|
|
|
|
* FUNCTION_NOT_A_FUNCTION:
|
|
|
|
|
*
|
2016-03-31 16:49:59 +11:00
|
|
|
* Macro name not followed by a '('. This is not an error, but
|
|
|
|
|
* simply that the macro name should be treated as a non-macro.
|
2010-05-25 16:28:26 -07:00
|
|
|
*
|
2010-06-02 15:49:54 -07:00
|
|
|
* FUNCTION_UNBALANCED_PARENTHESES
|
2010-05-25 16:28:26 -07:00
|
|
|
*
|
2016-03-31 16:49:59 +11:00
|
|
|
* Macro name is not followed by a balanced set of parentheses.
|
2010-05-25 16:28:26 -07:00
|
|
|
*/
|
|
|
|
|
static function_status_t
|
2016-10-07 04:49:13 +02:00
|
|
|
_arguments_parse(glcpp_parser_t *parser,
|
|
|
|
|
argument_list_t *arguments, token_node_t *node,
|
2016-03-31 16:49:59 +11:00
|
|
|
token_node_t **last)
|
2010-05-25 16:28:26 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_list_t *argument;
|
|
|
|
|
int paren_count;
|
|
|
|
|
|
|
|
|
|
node = node->next;
|
|
|
|
|
|
|
|
|
|
/* Ignore whitespace before first parenthesis. */
|
|
|
|
|
while (node && node->token->type == SPACE)
|
|
|
|
|
node = node->next;
|
|
|
|
|
|
|
|
|
|
if (node == NULL || node->token->type != '(')
|
|
|
|
|
return FUNCTION_NOT_A_FUNCTION;
|
|
|
|
|
|
|
|
|
|
node = node->next;
|
|
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
argument = _token_list_create (parser);
|
|
|
|
|
_argument_list_append (parser, arguments, argument);
|
2016-03-31 16:49:59 +11:00
|
|
|
|
|
|
|
|
for (paren_count = 1; node; node = node->next) {
|
|
|
|
|
if (node->token->type == '(') {
|
|
|
|
|
paren_count++;
|
|
|
|
|
} else if (node->token->type == ')') {
|
|
|
|
|
paren_count--;
|
|
|
|
|
if (paren_count == 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (node->token->type == ',' && paren_count == 1) {
|
|
|
|
|
_token_list_trim_trailing_space (argument);
|
2016-10-07 04:49:13 +02:00
|
|
|
argument = _token_list_create (parser);
|
|
|
|
|
_argument_list_append (parser, arguments, argument);
|
2016-03-31 16:49:59 +11:00
|
|
|
} else {
|
|
|
|
|
if (argument->head == NULL) {
|
|
|
|
|
/* Don't treat initial whitespace as part of the argument. */
|
|
|
|
|
if (node->token->type == SPACE)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_append(parser, argument, node->token);
|
2016-03-31 16:49:59 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (paren_count)
|
|
|
|
|
return FUNCTION_UNBALANCED_PARENTHESES;
|
|
|
|
|
|
|
|
|
|
*last = node;
|
|
|
|
|
|
|
|
|
|
return FUNCTION_STATUS_SUCCESS;
|
2010-05-25 16:28:26 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-20 16:44:03 -07:00
|
|
|
static token_list_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_create_with_one_ival(glcpp_parser_t *parser, int type, int ival)
|
2010-07-20 16:44:03 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_list_t *list;
|
|
|
|
|
token_t *node;
|
2010-07-20 16:44:03 -07:00
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
list = _token_list_create(parser);
|
|
|
|
|
node = _token_create_ival(parser, type, ival);
|
|
|
|
|
_token_list_append(parser, list, node);
|
2010-07-20 16:44:03 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return list;
|
2010-07-20 16:44:03 -07:00
|
|
|
}
|
|
|
|
|
|
2012-11-28 12:11:02 -08:00
|
|
|
static token_list_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_create_with_one_space(glcpp_parser_t *parser)
|
2012-11-28 12:11:02 -08:00
|
|
|
{
|
2016-10-07 04:49:13 +02:00
|
|
|
return _token_list_create_with_one_ival(parser, SPACE, SPACE);
|
2012-11-28 12:11:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static token_list_t *
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_create_with_one_integer(glcpp_parser_t *parser, int ival)
|
2012-11-28 12:11:02 -08:00
|
|
|
{
|
2016-10-07 04:49:13 +02:00
|
|
|
return _token_list_create_with_one_ival(parser, INTEGER, ival);
|
2012-11-28 12:11:02 -08:00
|
|
|
}
|
|
|
|
|
|
2014-07-02 12:52:33 -07:00
|
|
|
/* Evaluate a DEFINED token node (based on subsequent tokens in the list).
|
|
|
|
|
*
|
|
|
|
|
* Note: This function must only be called when "node" is a DEFINED token,
|
|
|
|
|
* (and will abort with an assertion failure otherwise).
|
|
|
|
|
*
|
|
|
|
|
* If "node" is followed, (ignoring any SPACE tokens), by an IDENTIFIER token
|
|
|
|
|
* (optionally preceded and followed by '(' and ')' tokens) then the following
|
|
|
|
|
* occurs:
|
|
|
|
|
*
|
2016-03-31 16:49:59 +11:00
|
|
|
* If the identifier is a defined macro, this function returns 1.
|
2014-07-02 12:52:33 -07:00
|
|
|
*
|
2016-03-31 16:49:59 +11:00
|
|
|
* If the identifier is not a defined macro, this function returns 0.
|
2014-07-02 12:52:33 -07:00
|
|
|
*
|
2016-03-31 16:49:59 +11:00
|
|
|
* In either case, *last will be updated to the last node in the list
|
|
|
|
|
* consumed by the evaluation, (either the token of the identifier or the
|
|
|
|
|
* token of the closing parenthesis).
|
2014-07-02 12:52:33 -07:00
|
|
|
*
|
|
|
|
|
* In all other cases, (such as "node is the final node of the list", or
|
|
|
|
|
* "missing closing parenthesis", etc.), this function generates a
|
|
|
|
|
* preprocessor error, returns -1 and *last will not be set.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_evaluate_defined(glcpp_parser_t *parser, token_node_t *node,
|
|
|
|
|
token_node_t **last)
|
2014-07-02 12:52:33 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_node_t *argument, *defined = node;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
assert(node->token->type == DEFINED);
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
node = node->next;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
/* Ignore whitespace after DEFINED token. */
|
|
|
|
|
while (node && node->token->type == SPACE)
|
|
|
|
|
node = node->next;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (node == NULL)
|
|
|
|
|
goto FAIL;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (node->token->type == IDENTIFIER || node->token->type == OTHER) {
|
|
|
|
|
argument = node;
|
|
|
|
|
} else if (node->token->type == '(') {
|
|
|
|
|
node = node->next;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
/* Ignore whitespace after '(' token. */
|
|
|
|
|
while (node && node->token->type == SPACE)
|
|
|
|
|
node = node->next;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (node == NULL || (node->token->type != IDENTIFIER &&
|
|
|
|
|
node->token->type != OTHER)) {
|
|
|
|
|
goto FAIL;
|
|
|
|
|
}
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
argument = node;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
node = node->next;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
/* Ignore whitespace after identifier, before ')' token. */
|
|
|
|
|
while (node && node->token->type == SPACE)
|
|
|
|
|
node = node->next;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (node == NULL || node->token->type != ')')
|
|
|
|
|
goto FAIL;
|
|
|
|
|
} else {
|
|
|
|
|
goto FAIL;
|
|
|
|
|
}
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
*last = node;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-08-18 21:59:19 +02:00
|
|
|
return _mesa_hash_table_search(parser->defines,
|
|
|
|
|
argument->token->value.str) ? 1 : 0;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
|
|
|
|
FAIL:
|
2016-03-31 16:49:59 +11:00
|
|
|
glcpp_error (&defined->token->location, parser,
|
|
|
|
|
"\"defined\" not followed by an identifier");
|
|
|
|
|
return -1;
|
2014-07-02 12:52:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Evaluate all DEFINED nodes in a given list, modifying the list in place.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_evaluate_defined_in_list(glcpp_parser_t *parser,
|
|
|
|
|
token_list_t *list)
|
2014-07-02 12:52:33 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_node_t *node, *node_prev, *replacement, *last = NULL;
|
|
|
|
|
int value;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list == NULL)
|
|
|
|
|
return;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
node_prev = NULL;
|
|
|
|
|
node = list->head;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
while (node) {
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (node->token->type != DEFINED)
|
|
|
|
|
goto NEXT;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
value = _glcpp_parser_evaluate_defined (parser, node, &last);
|
|
|
|
|
if (value == -1)
|
|
|
|
|
goto NEXT;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
replacement = linear_alloc_child(parser->linalloc, sizeof(token_node_t));
|
|
|
|
|
replacement->token = _token_create_ival (parser, INTEGER, value);
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
/* Splice replacement node into list, replacing from "node"
|
|
|
|
|
* through "last". */
|
|
|
|
|
if (node_prev)
|
|
|
|
|
node_prev->next = replacement;
|
|
|
|
|
else
|
|
|
|
|
list->head = replacement;
|
|
|
|
|
replacement->next = last->next;
|
|
|
|
|
if (last == list->tail)
|
|
|
|
|
list->tail = replacement;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
node = replacement;
|
2014-07-02 12:52:33 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
NEXT:
|
|
|
|
|
node_prev = node;
|
|
|
|
|
node = node->next;
|
|
|
|
|
}
|
2014-07-02 12:52:33 -07:00
|
|
|
}
|
|
|
|
|
|
2012-06-09 16:29:38 -07:00
|
|
|
/* Perform macro expansion on 'list', placing the resulting tokens
|
|
|
|
|
* into a new list which is initialized with a first token of type
|
|
|
|
|
* 'head_token_type'. Then begin lexing from the resulting list,
|
|
|
|
|
* (return to the current lexing source when this list is exhausted).
|
2014-07-02 12:52:33 -07:00
|
|
|
*
|
|
|
|
|
* See the documentation of _glcpp_parser_expand_token_list for a description
|
|
|
|
|
* of the "mode" parameter.
|
2012-06-09 16:29:38 -07:00
|
|
|
*/
|
2010-08-04 16:10:03 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_expand_and_lex_from(glcpp_parser_t *parser, int head_token_type,
|
|
|
|
|
token_list_t *list, expansion_mode_t mode)
|
2010-08-04 16:10:03 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_list_t *expanded;
|
|
|
|
|
token_t *token;
|
|
|
|
|
|
|
|
|
|
expanded = _token_list_create (parser);
|
|
|
|
|
token = _token_create_ival (parser, head_token_type, head_token_type);
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_append (parser, expanded, token);
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_expand_token_list (parser, list, mode);
|
|
|
|
|
_token_list_append_list (expanded, list);
|
|
|
|
|
glcpp_parser_lex_from (parser, expanded);
|
2010-08-04 16:10:03 -07:00
|
|
|
}
|
|
|
|
|
|
2011-09-29 17:04:47 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_apply_pastes(glcpp_parser_t *parser, token_list_t *list)
|
2011-09-29 17:04:47 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_node_t *node;
|
|
|
|
|
|
|
|
|
|
node = list->head;
|
|
|
|
|
while (node) {
|
|
|
|
|
token_node_t *next_non_space;
|
|
|
|
|
|
|
|
|
|
/* Look ahead for a PASTE token, skipping space. */
|
|
|
|
|
next_non_space = node->next;
|
|
|
|
|
while (next_non_space && next_non_space->token->type == SPACE)
|
|
|
|
|
next_non_space = next_non_space->next;
|
|
|
|
|
|
|
|
|
|
if (next_non_space == NULL)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (next_non_space->token->type != PASTE) {
|
|
|
|
|
node = next_non_space;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now find the next non-space token after the PASTE. */
|
|
|
|
|
next_non_space = next_non_space->next;
|
|
|
|
|
while (next_non_space && next_non_space->token->type == SPACE)
|
|
|
|
|
next_non_space = next_non_space->next;
|
|
|
|
|
|
|
|
|
|
if (next_non_space == NULL) {
|
|
|
|
|
yyerror(&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node->token = _token_paste(parser, node->token, next_non_space->token);
|
|
|
|
|
node->next = next_non_space->next;
|
|
|
|
|
if (next_non_space == list->tail)
|
|
|
|
|
list->tail = node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list->non_space_tail = list->tail;
|
2011-09-29 17:04:47 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-28 15:06:02 -07:00
|
|
|
/* This is a helper function that's essentially part of the
|
|
|
|
|
* implementation of _glcpp_parser_expand_node. It shouldn't be called
|
|
|
|
|
* except for by that function.
|
|
|
|
|
*
|
|
|
|
|
* Returns NULL if node is a simple token with no expansion, (that is,
|
|
|
|
|
* although 'node' corresponds to an identifier defined as a
|
|
|
|
|
* function-like macro, it is not followed with a parenthesized
|
|
|
|
|
* argument list).
|
|
|
|
|
*
|
|
|
|
|
* Compute the complete expansion of node (which is a function-like
|
|
|
|
|
* macro) and subsequent nodes which are arguments.
|
|
|
|
|
*
|
|
|
|
|
* Returns the token list that results from the expansion and sets
|
|
|
|
|
* *last to the last node in the list that was consumed by the
|
2010-07-22 16:36:04 -07:00
|
|
|
* expansion. Specifically, *last will be set as follows: as the
|
2010-05-28 15:06:02 -07:00
|
|
|
* token of the closing right parenthesis.
|
2014-07-02 12:52:33 -07:00
|
|
|
*
|
|
|
|
|
* See the documentation of _glcpp_parser_expand_token_list for a description
|
|
|
|
|
* of the "mode" parameter.
|
2010-05-28 15:06:02 -07:00
|
|
|
*/
|
|
|
|
|
static token_list_t *
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_expand_function(glcpp_parser_t *parser, token_node_t *node,
|
|
|
|
|
token_node_t **last, expansion_mode_t mode)
|
2010-05-25 16:28:26 -07:00
|
|
|
{
|
2016-08-18 21:59:19 +02:00
|
|
|
struct hash_entry *entry;
|
2016-03-31 16:49:59 +11:00
|
|
|
macro_t *macro;
|
|
|
|
|
const char *identifier;
|
|
|
|
|
argument_list_t *arguments;
|
|
|
|
|
function_status_t status;
|
|
|
|
|
token_list_t *substituted;
|
|
|
|
|
int parameter_index;
|
|
|
|
|
|
|
|
|
|
identifier = node->token->value.str;
|
|
|
|
|
|
2016-08-18 21:59:19 +02:00
|
|
|
entry = _mesa_hash_table_search(parser->defines, identifier);
|
|
|
|
|
macro = entry ? entry->data : NULL;
|
2016-03-31 16:49:59 +11:00
|
|
|
|
|
|
|
|
assert(macro->is_function);
|
|
|
|
|
|
|
|
|
|
arguments = _argument_list_create(parser);
|
2016-10-07 04:49:13 +02:00
|
|
|
status = _arguments_parse(parser, arguments, node, last);
|
2016-03-31 16:49:59 +11:00
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
case FUNCTION_STATUS_SUCCESS:
|
|
|
|
|
break;
|
|
|
|
|
case FUNCTION_NOT_A_FUNCTION:
|
|
|
|
|
return NULL;
|
|
|
|
|
case FUNCTION_UNBALANCED_PARENTHESES:
|
|
|
|
|
glcpp_error(&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Replace a macro defined as empty with a SPACE token. */
|
|
|
|
|
if (macro->replacements == NULL) {
|
|
|
|
|
return _token_list_create_with_one_space(parser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!((_argument_list_length (arguments) ==
|
|
|
|
|
_string_list_length (macro->parameters)) ||
|
|
|
|
|
(_string_list_length (macro->parameters) == 0 &&
|
|
|
|
|
_argument_list_length (arguments) == 1 &&
|
|
|
|
|
arguments->head->argument->head == NULL))) {
|
|
|
|
|
glcpp_error(&node->token->location, parser,
|
|
|
|
|
"Error: macro %s invoked with %d arguments (expected %d)\n",
|
|
|
|
|
identifier, _argument_list_length (arguments),
|
|
|
|
|
_string_list_length(macro->parameters));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Perform argument substitution on the replacement list. */
|
2016-10-07 04:49:13 +02:00
|
|
|
substituted = _token_list_create(parser);
|
2016-03-31 16:49:59 +11:00
|
|
|
|
|
|
|
|
for (node = macro->replacements->head; node; node = node->next) {
|
|
|
|
|
if (node->token->type == IDENTIFIER &&
|
|
|
|
|
_string_list_contains(macro->parameters, node->token->value.str,
|
|
|
|
|
¶meter_index)) {
|
|
|
|
|
token_list_t *argument;
|
|
|
|
|
argument = _argument_list_member_at(arguments, parameter_index);
|
|
|
|
|
/* Before substituting, we expand the argument tokens, or append a
|
|
|
|
|
* placeholder token for an empty argument. */
|
|
|
|
|
if (argument->head) {
|
|
|
|
|
token_list_t *expanded_argument;
|
|
|
|
|
expanded_argument = _token_list_copy(parser, argument);
|
|
|
|
|
_glcpp_parser_expand_token_list(parser, expanded_argument, mode);
|
|
|
|
|
_token_list_append_list(substituted, expanded_argument);
|
|
|
|
|
} else {
|
|
|
|
|
token_t *new_token;
|
|
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
new_token = _token_create_ival(parser, PLACEHOLDER,
|
2016-03-31 16:49:59 +11:00
|
|
|
PLACEHOLDER);
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_append(parser, substituted, new_token);
|
2016-03-31 16:49:59 +11:00
|
|
|
}
|
|
|
|
|
} else {
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_append(parser, substituted, node->token);
|
2016-03-31 16:49:59 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* After argument substitution, and before further expansion
|
|
|
|
|
* below, implement token pasting. */
|
|
|
|
|
|
|
|
|
|
_token_list_trim_trailing_space(substituted);
|
|
|
|
|
|
|
|
|
|
_glcpp_parser_apply_pastes(parser, substituted);
|
|
|
|
|
|
|
|
|
|
return substituted;
|
2010-05-25 15:24:59 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-28 15:06:02 -07:00
|
|
|
/* Compute the complete expansion of node, (and subsequent nodes after
|
|
|
|
|
* 'node' in the case that 'node' is a function-like macro and
|
|
|
|
|
* subsequent nodes are arguments).
|
|
|
|
|
*
|
|
|
|
|
* Returns NULL if node is a simple token with no expansion.
|
|
|
|
|
*
|
|
|
|
|
* Otherwise, returns the token list that results from the expansion
|
|
|
|
|
* and sets *last to the last node in the list that was consumed by
|
2010-07-20 16:44:03 -07:00
|
|
|
* the expansion. Specifically, *last will be set as follows:
|
2010-05-28 15:06:02 -07:00
|
|
|
*
|
2016-03-31 16:49:59 +11:00
|
|
|
* As 'node' in the case of object-like macro expansion.
|
2010-05-28 15:06:02 -07:00
|
|
|
*
|
2016-03-31 16:49:59 +11:00
|
|
|
* As the token of the closing right parenthesis in the case of
|
|
|
|
|
* function-like macro expansion.
|
2014-07-02 12:52:33 -07:00
|
|
|
*
|
|
|
|
|
* See the documentation of _glcpp_parser_expand_token_list for a description
|
|
|
|
|
* of the "mode" parameter.
|
2010-05-28 15:06:02 -07:00
|
|
|
*/
|
|
|
|
|
static token_list_t *
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_expand_node(glcpp_parser_t *parser, token_node_t *node,
|
|
|
|
|
token_node_t **last, expansion_mode_t mode)
|
2010-05-28 08:17:46 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_t *token = node->token;
|
|
|
|
|
const char *identifier;
|
2016-08-18 21:59:19 +02:00
|
|
|
struct hash_entry *entry;
|
2016-03-31 16:49:59 +11:00
|
|
|
macro_t *macro;
|
|
|
|
|
|
|
|
|
|
/* We only expand identifiers */
|
|
|
|
|
if (token->type != IDENTIFIER) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*last = node;
|
|
|
|
|
identifier = token->value.str;
|
|
|
|
|
|
|
|
|
|
/* Special handling for __LINE__ and __FILE__, (not through
|
|
|
|
|
* the hash table). */
|
|
|
|
|
if (strcmp(identifier, "__LINE__") == 0)
|
|
|
|
|
return _token_list_create_with_one_integer(parser, node->token->location.first_line);
|
|
|
|
|
|
|
|
|
|
if (strcmp(identifier, "__FILE__") == 0)
|
|
|
|
|
return _token_list_create_with_one_integer(parser, node->token->location.source);
|
|
|
|
|
|
|
|
|
|
/* Look up this identifier in the hash table. */
|
2016-08-18 21:59:19 +02:00
|
|
|
entry = _mesa_hash_table_search(parser->defines, identifier);
|
|
|
|
|
macro = entry ? entry->data : NULL;
|
2016-03-31 16:49:59 +11:00
|
|
|
|
|
|
|
|
/* Not a macro, so no expansion needed. */
|
|
|
|
|
if (macro == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* Finally, don't expand this macro if we're already actively
|
|
|
|
|
* expanding it, (to avoid infinite recursion). */
|
|
|
|
|
if (_parser_active_list_contains (parser, identifier)) {
|
|
|
|
|
/* We change the token type here from IDENTIFIER to OTHER to prevent any
|
|
|
|
|
* future expansion of this unexpanded token. */
|
|
|
|
|
char *str;
|
|
|
|
|
token_list_t *expansion;
|
|
|
|
|
token_t *final;
|
|
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
str = linear_strdup(parser->linalloc, token->value.str);
|
2016-03-31 16:49:59 +11:00
|
|
|
final = _token_create_str(parser, OTHER, str);
|
|
|
|
|
expansion = _token_list_create(parser);
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_append(parser, expansion, final);
|
2016-03-31 16:49:59 +11:00
|
|
|
return expansion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! macro->is_function) {
|
|
|
|
|
token_list_t *replacement;
|
|
|
|
|
|
|
|
|
|
/* Replace a macro defined as empty with a SPACE token. */
|
|
|
|
|
if (macro->replacements == NULL)
|
|
|
|
|
return _token_list_create_with_one_space(parser);
|
|
|
|
|
|
|
|
|
|
replacement = _token_list_copy(parser, macro->replacements);
|
|
|
|
|
_glcpp_parser_apply_pastes(parser, replacement);
|
|
|
|
|
return replacement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _glcpp_parser_expand_function(parser, node, last, mode);
|
2010-05-28 08:17:46 -07:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 15:35:41 -07:00
|
|
|
/* Push a new identifier onto the parser's active list.
|
2010-06-02 15:32:03 -07:00
|
|
|
*
|
|
|
|
|
* Here, 'marker' is the token node that appears in the list after the
|
|
|
|
|
* expansion of 'identifier'. That is, when the list iterator begins
|
2011-04-14 15:35:41 -07:00
|
|
|
* examining 'marker', then it is time to pop this node from the
|
2010-06-02 15:32:03 -07:00
|
|
|
* active stack.
|
|
|
|
|
*/
|
2011-04-14 15:35:41 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_parser_active_list_push(glcpp_parser_t *parser, const char *identifier,
|
|
|
|
|
token_node_t *marker)
|
2010-06-02 15:32:03 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
active_list_t *node;
|
2010-06-02 15:32:03 -07:00
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
node = linear_alloc_child(parser->linalloc, sizeof(active_list_t));
|
|
|
|
|
node->identifier = linear_strdup(parser->linalloc, identifier);
|
2016-03-31 16:49:59 +11:00
|
|
|
node->marker = marker;
|
|
|
|
|
node->next = parser->active;
|
2010-06-02 15:32:03 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
parser->active = node;
|
2010-06-02 15:32:03 -07:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 15:35:41 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_parser_active_list_pop(glcpp_parser_t *parser)
|
2010-06-02 15:32:03 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
active_list_t *node = parser->active;
|
2010-06-02 15:32:03 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (node == NULL) {
|
|
|
|
|
parser->active = NULL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-06-02 15:32:03 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
node = parser->active->next;
|
|
|
|
|
parser->active = node;
|
2010-06-02 15:32:03 -07:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 15:35:41 -07:00
|
|
|
static int
|
2016-03-31 16:49:59 +11:00
|
|
|
_parser_active_list_contains(glcpp_parser_t *parser, const char *identifier)
|
2010-06-02 15:32:03 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
active_list_t *node;
|
2010-06-02 15:32:03 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (parser->active == NULL)
|
|
|
|
|
return 0;
|
2010-06-02 15:32:03 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
for (node = parser->active; node; node = node->next)
|
|
|
|
|
if (strcmp(node->identifier, identifier) == 0)
|
|
|
|
|
return 1;
|
2010-06-02 15:32:03 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return 0;
|
2010-06-02 15:32:03 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-28 15:06:02 -07:00
|
|
|
/* Walk over the token list replacing nodes with their expansion.
|
|
|
|
|
* Whenever nodes are expanded the walking will walk over the new
|
|
|
|
|
* nodes, continuing to expand as necessary. The results are placed in
|
2014-07-02 12:52:33 -07:00
|
|
|
* 'list' itself.
|
|
|
|
|
*
|
|
|
|
|
* The "mode" argument controls the handling of any DEFINED tokens that
|
|
|
|
|
* result from expansion as follows:
|
|
|
|
|
*
|
2016-03-31 16:49:59 +11:00
|
|
|
* EXPANSION_MODE_IGNORE_DEFINED: Any resulting DEFINED tokens will be
|
|
|
|
|
* left in the final list, unevaluated. This is the correct mode
|
|
|
|
|
* for expanding any list in any context other than a
|
|
|
|
|
* preprocessor conditional, (#if or #elif).
|
2014-07-02 12:52:33 -07:00
|
|
|
*
|
2016-03-31 16:49:59 +11:00
|
|
|
* EXPANSION_MODE_EVALUATE_DEFINED: Any resulting DEFINED tokens will be
|
|
|
|
|
* evaluated to 0 or 1 tokens depending on whether the following
|
|
|
|
|
* token is the name of a defined macro. If the DEFINED token is
|
|
|
|
|
* not followed by an (optionally parenthesized) identifier, then
|
|
|
|
|
* an error will be generated. This the correct mode for
|
|
|
|
|
* expanding any list in the context of a preprocessor
|
|
|
|
|
* conditional, (#if or #elif).
|
2010-05-28 15:06:02 -07:00
|
|
|
*/
|
2010-05-26 08:05:19 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_expand_token_list(glcpp_parser_t *parser, token_list_t *list,
|
|
|
|
|
expansion_mode_t mode)
|
2010-05-26 08:05:19 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_node_t *node_prev;
|
|
|
|
|
token_node_t *node, *last = NULL;
|
|
|
|
|
token_list_t *expansion;
|
|
|
|
|
active_list_t *active_initial = parser->active;
|
|
|
|
|
|
|
|
|
|
if (list == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_token_list_trim_trailing_space (list);
|
|
|
|
|
|
|
|
|
|
node_prev = NULL;
|
|
|
|
|
node = list->head;
|
|
|
|
|
|
|
|
|
|
if (mode == EXPANSION_MODE_EVALUATE_DEFINED)
|
|
|
|
|
_glcpp_parser_evaluate_defined_in_list (parser, list);
|
|
|
|
|
|
|
|
|
|
while (node) {
|
|
|
|
|
|
|
|
|
|
while (parser->active && parser->active->marker == node)
|
|
|
|
|
_parser_active_list_pop (parser);
|
|
|
|
|
|
|
|
|
|
expansion = _glcpp_parser_expand_node (parser, node, &last, mode);
|
|
|
|
|
if (expansion) {
|
|
|
|
|
token_node_t *n;
|
|
|
|
|
|
|
|
|
|
if (mode == EXPANSION_MODE_EVALUATE_DEFINED) {
|
|
|
|
|
_glcpp_parser_evaluate_defined_in_list (parser, expansion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (n = node; n != last->next; n = n->next)
|
|
|
|
|
while (parser->active && parser->active->marker == n) {
|
|
|
|
|
_parser_active_list_pop (parser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_parser_active_list_push(parser, node->token->value.str, last->next);
|
|
|
|
|
|
|
|
|
|
/* Splice expansion into list, supporting a simple deletion if the
|
|
|
|
|
* expansion is empty.
|
|
|
|
|
*/
|
|
|
|
|
if (expansion->head) {
|
|
|
|
|
if (node_prev)
|
|
|
|
|
node_prev->next = expansion->head;
|
|
|
|
|
else
|
|
|
|
|
list->head = expansion->head;
|
|
|
|
|
expansion->tail->next = last->next;
|
|
|
|
|
if (last == list->tail)
|
|
|
|
|
list->tail = expansion->tail;
|
|
|
|
|
} else {
|
|
|
|
|
if (node_prev)
|
|
|
|
|
node_prev->next = last->next;
|
|
|
|
|
else
|
|
|
|
|
list->head = last->next;
|
|
|
|
|
if (last == list->tail)
|
|
|
|
|
list->tail = NULL;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
node_prev = node;
|
|
|
|
|
}
|
|
|
|
|
node = node_prev ? node_prev->next : list->head;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remove any lingering effects of this invocation on the
|
|
|
|
|
* active list. That is, pop until the list looks like it did
|
|
|
|
|
* at the beginning of this function. */
|
|
|
|
|
while (parser->active && parser->active != active_initial)
|
|
|
|
|
_parser_active_list_pop (parser);
|
|
|
|
|
|
|
|
|
|
list->non_space_tail = list->tail;
|
2010-05-28 15:06:02 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-25 15:24:59 -07:00
|
|
|
void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_print_expanded_token_list(glcpp_parser_t *parser,
|
|
|
|
|
token_list_t *list)
|
2010-05-25 15:24:59 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
if (list == NULL)
|
|
|
|
|
return;
|
2010-05-25 15:24:59 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_expand_token_list (parser, list, EXPANSION_MODE_IGNORE_DEFINED);
|
2010-05-26 08:05:19 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
_token_list_trim_trailing_space (list);
|
2010-05-26 08:05:19 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
_token_list_print (parser, list);
|
2010-05-25 15:24:59 -07:00
|
|
|
}
|
|
|
|
|
|
2010-07-20 15:55:21 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_check_for_reserved_macro_name(glcpp_parser_t *parser, YYLTYPE *loc,
|
|
|
|
|
const char *identifier)
|
2010-06-04 14:53:58 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
/* Section 3.3 (Preprocessor) of the GLSL 1.30 spec (and later) and
|
|
|
|
|
* the GLSL ES spec (all versions) say:
|
|
|
|
|
*
|
|
|
|
|
* "All macro names containing two consecutive underscores ( __ )
|
|
|
|
|
* are reserved for future use as predefined macro names. All
|
|
|
|
|
* macro names prefixed with "GL_" ("GL" followed by a single
|
|
|
|
|
* underscore) are also reserved."
|
|
|
|
|
*
|
|
|
|
|
* The intention is that names containing __ are reserved for internal
|
|
|
|
|
* use by the implementation, and names prefixed with GL_ are reserved
|
|
|
|
|
* for use by Khronos. Since every extension adds a name prefixed
|
|
|
|
|
* with GL_ (i.e., the name of the extension), that should be an
|
|
|
|
|
* error. Names simply containing __ are dangerous to use, but should
|
|
|
|
|
* be allowed.
|
|
|
|
|
*
|
|
|
|
|
* A future version of the GLSL specification will clarify this.
|
|
|
|
|
*/
|
|
|
|
|
if (strstr(identifier, "__")) {
|
|
|
|
|
glcpp_warning(loc, parser, "Macro names containing \"__\" are reserved "
|
|
|
|
|
"for use by the implementation.\n");
|
|
|
|
|
}
|
|
|
|
|
if (strncmp(identifier, "GL_", 3) == 0) {
|
|
|
|
|
glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n");
|
|
|
|
|
}
|
|
|
|
|
if (strcmp(identifier, "defined") == 0) {
|
|
|
|
|
glcpp_error (loc, parser, "\"defined\" cannot be used as a macro name");
|
|
|
|
|
}
|
2010-06-04 14:53:58 -07:00
|
|
|
}
|
|
|
|
|
|
2010-08-17 23:20:58 -07:00
|
|
|
static int
|
2016-03-31 16:49:59 +11:00
|
|
|
_macro_equal(macro_t *a, macro_t *b)
|
2010-08-17 23:20:58 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
if (a->is_function != b->is_function)
|
|
|
|
|
return 0;
|
2010-08-17 23:20:58 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (a->is_function) {
|
|
|
|
|
if (! _string_list_equal (a->parameters, b->parameters))
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-08-17 23:20:58 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
return _token_list_equal_ignoring_space(a->replacements, b->replacements);
|
2010-08-17 23:20:58 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-12 12:17:10 -07:00
|
|
|
void
|
2016-03-31 16:49:59 +11:00
|
|
|
_define_object_macro(glcpp_parser_t *parser, YYLTYPE *loc,
|
|
|
|
|
const char *identifier, token_list_t *replacements)
|
2010-05-13 09:36:23 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
macro_t *macro, *previous;
|
2016-08-18 21:59:19 +02:00
|
|
|
struct hash_entry *entry;
|
2016-03-31 16:49:59 +11:00
|
|
|
|
|
|
|
|
/* We define pre-defined macros before we've started parsing the actual
|
|
|
|
|
* file. So if there's no location defined yet, that's what were doing and
|
|
|
|
|
* we don't want to generate an error for using the reserved names. */
|
|
|
|
|
if (loc != NULL)
|
|
|
|
|
_check_for_reserved_macro_name(parser, loc, identifier);
|
|
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
macro = linear_alloc_child(parser->linalloc, sizeof(macro_t));
|
2016-03-31 16:49:59 +11:00
|
|
|
|
|
|
|
|
macro->is_function = 0;
|
|
|
|
|
macro->parameters = NULL;
|
2016-10-07 04:49:13 +02:00
|
|
|
macro->identifier = linear_strdup(parser->linalloc, identifier);
|
2016-03-31 16:49:59 +11:00
|
|
|
macro->replacements = replacements;
|
|
|
|
|
|
2016-08-18 21:59:19 +02:00
|
|
|
entry = _mesa_hash_table_search(parser->defines, identifier);
|
|
|
|
|
previous = entry ? entry->data : NULL;
|
2016-03-31 16:49:59 +11:00
|
|
|
if (previous) {
|
|
|
|
|
if (_macro_equal (macro, previous)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-18 21:59:19 +02:00
|
|
|
_mesa_hash_table_insert (parser->defines, identifier, macro);
|
2010-05-13 09:36:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2016-03-31 16:49:59 +11:00
|
|
|
_define_function_macro(glcpp_parser_t *parser, YYLTYPE *loc,
|
|
|
|
|
const char *identifier, string_list_t *parameters,
|
|
|
|
|
token_list_t *replacements)
|
2010-05-13 09:36:23 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
macro_t *macro, *previous;
|
2016-08-18 21:59:19 +02:00
|
|
|
struct hash_entry *entry;
|
2016-03-31 16:49:59 +11:00
|
|
|
const char *dup;
|
2010-05-13 09:36:23 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
_check_for_reserved_macro_name(parser, loc, identifier);
|
2010-06-04 14:53:58 -07:00
|
|
|
|
2014-06-25 13:41:47 -07:00
|
|
|
/* Check for any duplicate parameter names. */
|
2016-03-31 16:49:59 +11:00
|
|
|
if ((dup = _string_list_has_duplicate (parameters)) != NULL) {
|
|
|
|
|
glcpp_error (loc, parser, "Duplicate macro parameter \"%s\"", dup);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
macro = linear_alloc_child(parser->linalloc, sizeof(macro_t));
|
2016-03-31 16:49:59 +11:00
|
|
|
|
|
|
|
|
macro->is_function = 1;
|
|
|
|
|
macro->parameters = parameters;
|
2016-10-07 04:49:13 +02:00
|
|
|
macro->identifier = linear_strdup(parser->linalloc, identifier);
|
2016-03-31 16:49:59 +11:00
|
|
|
macro->replacements = replacements;
|
2016-08-18 21:59:19 +02:00
|
|
|
|
|
|
|
|
entry = _mesa_hash_table_search(parser->defines, identifier);
|
|
|
|
|
previous = entry ? entry->data : NULL;
|
2016-03-31 16:49:59 +11:00
|
|
|
if (previous) {
|
|
|
|
|
if (_macro_equal (macro, previous)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-18 21:59:19 +02:00
|
|
|
_mesa_hash_table_insert(parser->defines, identifier, macro);
|
2010-05-13 09:36:23 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-19 10:01:29 -07:00
|
|
|
static int
|
2016-03-31 16:49:59 +11:00
|
|
|
glcpp_parser_lex(YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
|
2010-05-19 10:01:29 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_node_t *node;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if (parser->lex_from_list == NULL) {
|
|
|
|
|
ret = glcpp_lex(yylval, yylloc, parser->scanner);
|
|
|
|
|
|
|
|
|
|
/* XXX: This ugly block of code exists for the sole
|
|
|
|
|
* purpose of converting a NEWLINE token into a SPACE
|
|
|
|
|
* token, but only in the case where we have seen a
|
|
|
|
|
* function-like macro name, but have not yet seen its
|
|
|
|
|
* closing parenthesis.
|
|
|
|
|
*
|
|
|
|
|
* There's perhaps a more compact way to do this with
|
|
|
|
|
* mid-rule actions in the grammar.
|
|
|
|
|
*
|
|
|
|
|
* I'm definitely not pleased with the complexity of
|
|
|
|
|
* this code here.
|
|
|
|
|
*/
|
|
|
|
|
if (parser->newline_as_space) {
|
|
|
|
|
if (ret == '(') {
|
|
|
|
|
parser->paren_count++;
|
|
|
|
|
} else if (ret == ')') {
|
|
|
|
|
parser->paren_count--;
|
|
|
|
|
if (parser->paren_count == 0)
|
|
|
|
|
parser->newline_as_space = 0;
|
|
|
|
|
} else if (ret == NEWLINE) {
|
|
|
|
|
ret = SPACE;
|
|
|
|
|
} else if (ret != SPACE) {
|
|
|
|
|
if (parser->paren_count == 0)
|
|
|
|
|
parser->newline_as_space = 0;
|
|
|
|
|
}
|
|
|
|
|
} else if (parser->in_control_line) {
|
|
|
|
|
if (ret == NEWLINE)
|
|
|
|
|
parser->in_control_line = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (ret == DEFINE_TOKEN || ret == UNDEF || ret == IF ||
|
|
|
|
|
ret == IFDEF || ret == IFNDEF || ret == ELIF || ret == ELSE ||
|
|
|
|
|
ret == ENDIF || ret == HASH_TOKEN) {
|
|
|
|
|
parser->in_control_line = 1;
|
|
|
|
|
} else if (ret == IDENTIFIER) {
|
2016-08-18 21:59:19 +02:00
|
|
|
struct hash_entry *entry = _mesa_hash_table_search(parser->defines,
|
|
|
|
|
yylval->str);
|
|
|
|
|
macro_t *macro = entry ? entry->data : NULL;
|
2016-03-31 16:49:59 +11:00
|
|
|
if (macro && macro->is_function) {
|
|
|
|
|
parser->newline_as_space = 1;
|
|
|
|
|
parser->paren_count = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node = parser->lex_from_node;
|
|
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
|
parser->lex_from_list = NULL;
|
|
|
|
|
return NEWLINE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*yylval = node->token->value;
|
|
|
|
|
ret = node->token->type;
|
|
|
|
|
|
|
|
|
|
parser->lex_from_node = node->next;
|
|
|
|
|
|
|
|
|
|
return ret;
|
2010-05-26 11:15:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
glcpp_parser_lex_from(glcpp_parser_t *parser, token_list_t *list)
|
2010-05-26 11:15:21 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
token_node_t *node;
|
2010-05-26 11:15:21 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
assert (parser->lex_from_list == NULL);
|
2010-05-26 11:15:21 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
/* Copy list, eliminating any space tokens. */
|
|
|
|
|
parser->lex_from_list = _token_list_create (parser);
|
2010-05-26 11:15:21 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
for (node = list->head; node; node = node->next) {
|
|
|
|
|
if (node->token->type == SPACE)
|
|
|
|
|
continue;
|
2016-10-07 04:49:13 +02:00
|
|
|
_token_list_append (parser, parser->lex_from_list, node->token);
|
2016-03-31 16:49:59 +11:00
|
|
|
}
|
2010-05-26 11:15:21 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
parser->lex_from_node = parser->lex_from_list->head;
|
2010-05-26 11:15:21 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
/* It's possible the list consisted of nothing but whitespace. */
|
|
|
|
|
if (parser->lex_from_node == NULL) {
|
|
|
|
|
parser->lex_from_list = NULL;
|
|
|
|
|
}
|
2010-05-19 10:01:29 -07:00
|
|
|
}
|
2010-05-20 22:27:07 -07:00
|
|
|
|
|
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_skip_stack_push_if(glcpp_parser_t *parser, YYLTYPE *loc,
|
|
|
|
|
int condition)
|
2010-05-20 22:27:07 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
skip_type_t current = SKIP_NO_SKIP;
|
|
|
|
|
skip_node_t *node;
|
|
|
|
|
|
|
|
|
|
if (parser->skip_stack)
|
|
|
|
|
current = parser->skip_stack->type;
|
|
|
|
|
|
2016-10-07 04:49:13 +02:00
|
|
|
node = linear_alloc_child(parser->linalloc, sizeof(skip_node_t));
|
2016-03-31 16:49:59 +11:00
|
|
|
node->loc = *loc;
|
|
|
|
|
|
|
|
|
|
if (current == SKIP_NO_SKIP) {
|
|
|
|
|
if (condition)
|
|
|
|
|
node->type = SKIP_NO_SKIP;
|
|
|
|
|
else
|
|
|
|
|
node->type = SKIP_TO_ELSE;
|
|
|
|
|
} else {
|
|
|
|
|
node->type = SKIP_TO_ENDIF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node->has_else = false;
|
|
|
|
|
node->next = parser->skip_stack;
|
|
|
|
|
parser->skip_stack = node;
|
2010-05-20 22:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_skip_stack_change_if(glcpp_parser_t *parser, YYLTYPE *loc,
|
|
|
|
|
const char *type, int condition)
|
2010-05-20 22:27:07 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
if (parser->skip_stack == NULL) {
|
|
|
|
|
glcpp_error (loc, parser, "#%s without #if\n", type);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parser->skip_stack->type == SKIP_TO_ELSE) {
|
|
|
|
|
if (condition)
|
|
|
|
|
parser->skip_stack->type = SKIP_NO_SKIP;
|
|
|
|
|
} else {
|
|
|
|
|
parser->skip_stack->type = SKIP_TO_ENDIF;
|
|
|
|
|
}
|
2010-05-20 22:27:07 -07:00
|
|
|
}
|
2010-05-25 14:42:00 -07:00
|
|
|
|
2010-05-20 22:27:07 -07:00
|
|
|
static void
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_skip_stack_pop(glcpp_parser_t *parser, YYLTYPE *loc)
|
2010-05-20 22:27:07 -07:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
skip_node_t *node;
|
2010-05-20 22:27:07 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (parser->skip_stack == NULL) {
|
|
|
|
|
glcpp_error (loc, parser, "#endif without #if\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-05-20 22:27:07 -07:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
node = parser->skip_stack;
|
|
|
|
|
parser->skip_stack = node->next;
|
2010-05-20 22:27:07 -07:00
|
|
|
}
|
2012-08-02 13:06:45 -07:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t version,
|
2014-01-17 14:22:49 -08:00
|
|
|
const char *es_identifier,
|
|
|
|
|
bool explicitly_set)
|
2012-08-02 13:06:45 -07:00
|
|
|
{
|
2016-11-08 11:06:05 -08:00
|
|
|
if (parser->version_set)
|
2016-03-31 16:49:59 +11:00
|
|
|
return;
|
|
|
|
|
|
2016-08-09 14:31:49 -07:00
|
|
|
parser->version = version;
|
2016-11-08 11:06:05 -08:00
|
|
|
parser->version_set = true;
|
2016-03-31 16:49:59 +11:00
|
|
|
|
|
|
|
|
add_builtin_define (parser, "__VERSION__", version);
|
|
|
|
|
|
|
|
|
|
parser->is_gles = (version == 100) ||
|
|
|
|
|
(es_identifier && (strcmp(es_identifier, "es") == 0));
|
|
|
|
|
|
|
|
|
|
/* Add pre-defined macros. */
|
2016-06-12 18:56:43 -04:00
|
|
|
if (parser->is_gles)
|
2016-03-31 16:49:59 +11:00
|
|
|
add_builtin_define(parser, "GL_ES", 1);
|
2016-06-12 18:56:43 -04:00
|
|
|
else if (version >= 150)
|
2016-03-31 16:49:59 +11:00
|
|
|
add_builtin_define(parser, "GL_core_profile", 1);
|
2015-12-30 18:47:18 -05:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
/* Currently, all ES2/ES3 implementations support highp in the
|
|
|
|
|
* fragment shader, so we always define this macro in ES2/ES3.
|
|
|
|
|
* If we ever get a driver that doesn't support highp, we'll
|
|
|
|
|
* need to add a flag to the gl_context and check that here.
|
|
|
|
|
*/
|
|
|
|
|
if (version >= 130 || parser->is_gles)
|
|
|
|
|
add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1);
|
2015-11-17 15:36:15 -08:00
|
|
|
|
2016-06-12 18:56:43 -04:00
|
|
|
/* Add all the extension macros available in this context */
|
|
|
|
|
if (parser->extensions)
|
|
|
|
|
parser->extensions(parser->state, add_builtin_define, parser,
|
|
|
|
|
version, parser->is_gles);
|
|
|
|
|
|
2016-10-14 18:11:51 -07:00
|
|
|
if (parser->extension_list) {
|
|
|
|
|
/* If MESA_shader_integer_functions is supported, then the building
|
|
|
|
|
* blocks required for the 64x64 => 64 multiply exist. Add defines for
|
|
|
|
|
* those functions so that they can be tested.
|
|
|
|
|
*/
|
|
|
|
|
if (parser->extension_list->MESA_shader_integer_functions) {
|
2016-10-17 13:55:27 -07:00
|
|
|
add_builtin_define(parser, "__have_builtin_builtin_sign64", 1);
|
2016-10-14 18:11:51 -07:00
|
|
|
add_builtin_define(parser, "__have_builtin_builtin_umul64", 1);
|
2016-10-17 17:54:40 -07:00
|
|
|
add_builtin_define(parser, "__have_builtin_builtin_udiv64", 1);
|
2016-10-18 16:46:35 -07:00
|
|
|
add_builtin_define(parser, "__have_builtin_builtin_umod64", 1);
|
2016-10-17 17:54:40 -07:00
|
|
|
add_builtin_define(parser, "__have_builtin_builtin_idiv64", 1);
|
2016-10-18 16:46:35 -07:00
|
|
|
add_builtin_define(parser, "__have_builtin_builtin_imod64", 1);
|
2016-10-14 18:11:51 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
if (explicitly_set) {
|
|
|
|
|
ralloc_asprintf_rewrite_tail(&parser->output, &parser->output_length,
|
|
|
|
|
"#version %" PRIiMAX "%s%s", version,
|
|
|
|
|
es_identifier ? " " : "",
|
|
|
|
|
es_identifier ? es_identifier : "");
|
|
|
|
|
}
|
2014-01-17 14:22:49 -08:00
|
|
|
}
|
|
|
|
|
|
2014-01-26 18:06:18 -08:00
|
|
|
/* GLSL version if no version is explicitly specified. */
|
2014-01-17 14:22:49 -08:00
|
|
|
#define IMPLICIT_GLSL_VERSION 110
|
|
|
|
|
|
2014-01-26 18:06:18 -08:00
|
|
|
/* GLSL ES version if no version is explicitly specified. */
|
|
|
|
|
#define IMPLICIT_GLSL_ES_VERSION 100
|
|
|
|
|
|
2014-01-17 14:22:49 -08:00
|
|
|
void
|
2014-01-25 11:57:02 -08:00
|
|
|
glcpp_parser_resolve_implicit_version(glcpp_parser_t *parser)
|
2014-01-17 14:22:49 -08:00
|
|
|
{
|
2016-03-31 16:49:59 +11:00
|
|
|
int language_version = parser->api == API_OPENGLES2 ?
|
|
|
|
|
IMPLICIT_GLSL_ES_VERSION : IMPLICIT_GLSL_VERSION;
|
2014-01-26 18:06:18 -08:00
|
|
|
|
2016-03-31 16:49:59 +11:00
|
|
|
_glcpp_parser_handle_version_declaration(parser, language_version,
|
|
|
|
|
NULL, false);
|
2012-08-02 13:06:45 -07:00
|
|
|
}
|