Path: blob/21.2-virgl/src/compiler/glsl/glcpp/glcpp.h
4547 views
/*1* Copyright © 2010 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*/2223#ifndef GLCPP_H24#define GLCPP_H2526#include <stdint.h>27#include <stdbool.h>2829#include "main/menums.h"3031#include "util/ralloc.h"3233#include "util/hash_table.h"3435#include "util/string_buffer.h"3637struct gl_context;3839#define yyscan_t void*4041/* Some data types used for parser values. */4243typedef struct expression_value {44intmax_t value;45char *undefined_macro;46} expression_value_t;474849typedef struct string_node {50const char *str;51struct string_node *next;52} string_node_t;5354typedef struct string_list {55string_node_t *head;56string_node_t *tail;57} string_list_t;5859typedef struct token token_t;60typedef struct token_list token_list_t;6162typedef union YYSTYPE63{64intmax_t ival;65expression_value_t expression_value;66char *str;67string_list_t *string_list;68token_t *token;69token_list_t *token_list;70} YYSTYPE;7172# define YYSTYPE_IS_TRIVIAL 173# define YYSTYPE_IS_DECLARED 17475typedef struct YYLTYPE {76int first_line;77int first_column;78int last_line;79int last_column;80unsigned source;81} YYLTYPE;82# define YYLTYPE_IS_DECLARED 183# define YYLTYPE_IS_TRIVIAL 18485# define YYLLOC_DEFAULT(Current, Rhs, N) \86do { \87if (N) \88{ \89(Current).first_line = YYRHSLOC(Rhs, 1).first_line; \90(Current).first_column = YYRHSLOC(Rhs, 1).first_column; \91(Current).last_line = YYRHSLOC(Rhs, N).last_line; \92(Current).last_column = YYRHSLOC(Rhs, N).last_column; \93} \94else \95{ \96(Current).first_line = (Current).last_line = \97YYRHSLOC(Rhs, 0).last_line; \98(Current).first_column = (Current).last_column = \99YYRHSLOC(Rhs, 0).last_column; \100} \101(Current).source = 0; \102} while (0)103104struct token {105int type;106YYSTYPE value;107YYLTYPE location;108};109110typedef struct token_node {111token_t *token;112struct token_node *next;113} token_node_t;114115struct token_list {116token_node_t *head;117token_node_t *tail;118token_node_t *non_space_tail;119};120121typedef struct argument_node {122token_list_t *argument;123struct argument_node *next;124} argument_node_t;125126typedef struct argument_list {127argument_node_t *head;128argument_node_t *tail;129} argument_list_t;130131typedef struct glcpp_parser glcpp_parser_t;132133typedef enum {134TOKEN_CLASS_IDENTIFIER,135TOKEN_CLASS_IDENTIFIER_FINALIZED,136TOKEN_CLASS_FUNC_MACRO,137TOKEN_CLASS_OBJ_MACRO138} token_class_t;139140token_class_t141glcpp_parser_classify_token (glcpp_parser_t *parser,142const char *identifier,143int *parameter_index);144145typedef struct {146int is_function;147string_list_t *parameters;148const char *identifier;149token_list_t *replacements;150} macro_t;151152typedef struct expansion_node {153macro_t *macro;154token_node_t *replacements;155struct expansion_node *next;156} expansion_node_t;157158typedef enum skip_type {159SKIP_NO_SKIP,160SKIP_TO_ELSE,161SKIP_TO_ENDIF162} skip_type_t;163164typedef struct skip_node {165skip_type_t type;166bool has_else;167YYLTYPE loc; /* location of the initial #if/#elif/... */168struct skip_node *next;169} skip_node_t;170171typedef struct active_list {172const char *identifier;173token_node_t *marker;174struct active_list *next;175} active_list_t;176177struct _mesa_glsl_parse_state;178179typedef void (*glcpp_extension_iterator)(180struct _mesa_glsl_parse_state *state,181void (*add_builtin_define)(glcpp_parser_t *, const char *, int),182glcpp_parser_t *data,183unsigned version,184bool es);185186struct glcpp_parser {187void *linalloc;188yyscan_t scanner;189struct hash_table *defines;190active_list_t *active;191int lexing_directive;192int lexing_version_directive;193int space_tokens;194int last_token_was_newline;195int last_token_was_space;196int first_non_space_token_this_line;197int newline_as_space;198int in_control_line;199bool in_define;200int paren_count;201int commented_newlines;202skip_node_t *skip_stack;203int skipping;204token_list_t *lex_from_list;205token_node_t *lex_from_node;206struct _mesa_string_buffer *output;207struct _mesa_string_buffer *info_log;208int error;209glcpp_extension_iterator extensions;210const struct gl_extensions *extension_list;211void *state;212gl_api api;213struct gl_context *gl_ctx;214unsigned version;215216/**217* Has the #version been set?218*219* A separate flag is used because any possible sentinel value in220* \c ::version could also be set by a #version line.221*/222bool version_set;223224bool has_new_line_number;225int new_line_number;226bool has_new_source_number;227int new_source_number;228bool is_gles;229};230231glcpp_parser_t *232glcpp_parser_create(struct gl_context *gl_ctx,233glcpp_extension_iterator extensions, void *state);234235int236glcpp_parser_parse (glcpp_parser_t *parser);237238void239glcpp_parser_destroy (glcpp_parser_t *parser);240241void242glcpp_parser_resolve_implicit_version(glcpp_parser_t *parser);243244int245glcpp_preprocess(void *ralloc_ctx, const char **shader, char **info_log,246glcpp_extension_iterator extensions, void *state,247struct gl_context *g_ctx);248249/* Functions for writing to the info log */250251void252glcpp_error (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...);253254void255glcpp_warning (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...);256257/* Generated by glcpp-lex.l to glcpp-lex.c */258259int260glcpp_lex_init_extra (glcpp_parser_t *parser, yyscan_t* scanner);261262void263glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader);264265int266glcpp_lex (YYSTYPE *lvalp, YYLTYPE *llocp, yyscan_t scanner);267268int269glcpp_lex_destroy (yyscan_t scanner);270271/* Generated by glcpp-parse.y to glcpp-parse.c */272273int274yyparse (glcpp_parser_t *parser);275276#endif277278279