-
Notifications
You must be signed in to change notification settings - Fork 4
/
glsl.y
1495 lines (1286 loc) · 46.8 KB
/
glsl.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%{
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include <assert.h>
#include "glsl_parser.h" //For context struct
#include "glsl.parser.h" //For GLSL_STYPE and GLSL_LTYPE
#include "glsl.lexer.h" //For glsl_lex()
static void glsl_error(GLSL_LTYPE *loc, struct glsl_parse_context *c, const char *s);
#define GLSL_STACK_BUFFER_SIZE (1024*1024)
#define GLSL_STACK_BUFFER_PAYLOAD_SIZE (GLSL_STACK_BUFFER_SIZE - sizeof(intptr_t))
uint8_t *glsl_parse_alloc(struct glsl_parse_context *context, size_t size, int align)
{
uint8_t *ret;
if (size + align > (context->cur_buffer_end - context->cur_buffer)) {
uint8_t *next_buffer = (uint8_t *)malloc(GLSL_STACK_BUFFER_SIZE);
if (context->cur_buffer) {
uint8_t **pnext = (uint8_t **)context->cur_buffer_end;
*pnext = next_buffer;
}
context->cur_buffer_start = next_buffer;
context->cur_buffer = next_buffer;
context->cur_buffer_end = next_buffer + GLSL_STACK_BUFFER_PAYLOAD_SIZE;
if (!context->first_buffer) {
context->first_buffer = context->cur_buffer;
}
*((uint8_t **)context->cur_buffer_end) = NULL;
}
ret = context->cur_buffer;
uint8_t *trunc = (uint8_t *)((~((intptr_t)align - 1)) & ((intptr_t)ret));
if (trunc != ret) {
ret = trunc + align;
}
context->cur_buffer = ret + size;
return ret;
}
void glsl_parse_dealloc(struct glsl_parse_context *context)
{
uint8_t *buffer = context->first_buffer;
while (buffer) {
uint8_t *next = *((uint8_t **)(buffer + GLSL_STACK_BUFFER_PAYLOAD_SIZE));
free(buffer);
buffer = next;
}
}
static char *glsl_parse_strdup(struct glsl_parse_context *context, const char *c)
{
int len = strlen(c);
char *ret = (char *)glsl_parse_alloc(context, len + 1, 1);
strcpy(ret, c);
return ret;
}
struct glsl_node *new_glsl_node(struct glsl_parse_context *context, int code, ...)
{
struct glsl_node *temp;
int i;
int n = 0;
va_list vl;
va_start(vl, code);
while (1) {
temp = va_arg(vl, struct glsl_node *);
if (temp)
n++;
else
break;
}
va_end(vl);
struct glsl_node *g = (struct glsl_node *)glsl_parse_alloc(context, offsetof(struct glsl_node, children[n]), 8);
g->code = code;
g->child_count = n;
va_start(vl, code);
for (i = 0; i < n; i++) {
temp = va_arg(vl, struct glsl_node *);
g->children[i] = temp;
}
va_end(vl);
return g;
}
static struct glsl_node *new_glsl_identifier(struct glsl_parse_context *context, const char *str)
{
struct glsl_node *n = new_glsl_node(context, IDENTIFIER, NULL);
if (!str)
n->data.str = NULL;
else
n->data.str = glsl_parse_strdup(context, str);
return n;
}
static struct glsl_node *new_glsl_string(struct glsl_parse_context *context, int code, const char *str)
{
struct glsl_node *n = new_glsl_node(context, code, NULL);
n->data.str = glsl_parse_strdup(context, str);
return n;
}
#define scanner context->scanner //To allow the scanner to find it's context
%}
%defines
%define api.prefix {glsl_}
%define api.value.type union
%pure-parser
%parse-param { struct glsl_parse_context * context }
%lex-param { void * scanner }
%locations
%type <struct glsl_node *> translation_unit
%type <struct glsl_node *> external_declaration
%type <struct glsl_node *> function_definition
%type <struct glsl_node *> compound_statement_no_new_scope
%type <struct glsl_node *> statement
%type <struct glsl_node *> statement_list
%type <struct glsl_node *> compound_statement
%type <struct glsl_node *> simple_statement
%type <struct glsl_node *> declaration
%type <struct glsl_node *> identifier_list
%type <struct glsl_node *> init_declarator_list
%type <struct glsl_node *> single_declaration
%type <struct glsl_node *> initializer
%type <struct glsl_node *> initializer_list
%type <struct glsl_node *> expression_statement
%type <struct glsl_node *> selection_statement
%type <struct glsl_node *> switch_statement
%type <struct glsl_node *> switch_statement_list
%type <struct glsl_node *> case_label
%type <struct glsl_node *> iteration_statement
%type <struct glsl_node *> statement_no_new_scope
%type <struct glsl_node *> for_init_statement
%type <struct glsl_node *> conditionopt
%type <struct glsl_node *> condition
%type <struct glsl_node *> for_rest_statement
%type <struct glsl_node *> jump_statement
%type <struct glsl_node *> function_prototype
%type <struct glsl_node *> function_declarator
%type <struct glsl_node *> parameter_declaration
%type <struct glsl_node *> parameter_declarator
%type <struct glsl_node *> function_header
%type <struct glsl_node *> function_parameter_list
%type <struct glsl_node *> fully_specified_type
%type <struct glsl_node *> parameter_type_specifier
%type <struct glsl_node *> primary_expression
%type <struct glsl_node *> expression
%type <struct glsl_node *> assignment_expression
%type <struct glsl_node *> conditional_expression
%type <struct glsl_node *> logical_or_expression
%type <struct glsl_node *> logical_xor_expression
%type <struct glsl_node *> logical_and_expression
%type <struct glsl_node *> exclusive_or_expression
%type <struct glsl_node *> constant_expression
%type <struct glsl_node *> and_expression
%type <struct glsl_node *> equality_expression
%type <struct glsl_node *> relational_expression
%type <struct glsl_node *> shift_expression
%type <struct glsl_node *> additive_expression
%type <struct glsl_node *> multiplicative_expression
%type <struct glsl_node *> unary_expression
%type <struct glsl_node *> postfix_expression
%type <struct glsl_node *> integer_expression
%type <struct glsl_node *> inclusive_or_expression
%type <struct glsl_node *> function_call
%type <struct glsl_node *> function_call_or_method
%type <struct glsl_node *> function_call_generic
%type <struct glsl_node *> function_call_parameter_list
%type <struct glsl_node *> function_identifier
%type <struct glsl_node *> type_specifier
%type <struct glsl_node *> type_specifier_nonarray
%type <struct glsl_node *> struct_specifier
%type <struct glsl_node *> array_specifier
%type <struct glsl_node *> array_specifier_list
%type <struct glsl_node *> struct_declaration_list
%type <struct glsl_node *> struct_declaration
%type <struct glsl_node *> struct_declarator_list
%type <struct glsl_node *> struct_declarator
%type <struct glsl_node *> type_qualifier
%type <struct glsl_node *> single_type_qualifier
%type <struct glsl_node *> layout_qualifier
%type <struct glsl_node *> layout_qualifier_id_list
%type <struct glsl_node *> layout_qualifier_id
%type <struct glsl_node *> precision_qualifier
%type <struct glsl_node *> invariant_qualifier
%type <struct glsl_node *> precise_qualifier
%type <struct glsl_node *> storage_qualifier
%type <struct glsl_node *> interpolation_qualifier
%type <struct glsl_node *> type_name_list
%type <struct glsl_node *> variable_identifier
%type <struct glsl_node *> decl_identifier
%type <struct glsl_node *> block_identifier
%type <struct glsl_node *> struct_name
%type <struct glsl_node *> type_name
%type <struct glsl_node *> param_name
%type <struct glsl_node *> function_name
%type <struct glsl_node *> field_identifier
%type <struct glsl_node *> type_specifier_identifier
%type <struct glsl_node *> layout_identifier
%type <int> assignment_operator
%type <int> unary_operator
%token CONST
%token BOOL
%token FLOAT
%token DOUBLE
%token INT
%token UINT
%token BREAK
%token CONTINUE
%token DO
%token ELSE
%token FOR
%token IF
%token DISCARD
%token RETURN
%token RETURN_VALUE
%token SWITCH
%token CASE
%token DEFAULT
%token SUBROUTINE
%token BVEC2
%token BVEC3
%token BVEC4
%token IVEC2
%token IVEC3
%token IVEC4
%token UVEC2
%token UVEC3
%token UVEC4
%token VEC2
%token VEC3
%token VEC4
%token MAT2
%token MAT3
%token MAT4
%token CENTROID
%token IN
%token OUT
%token INOUT
%token UNIFORM
%token PATCH
%token SAMPLE
%token BUFFER
%token SHARED
%token COHERENT
%token VOLATILE
%token RESTRICT
%token READONLY
%token WRITEONLY
%token DVEC2
%token DVEC3
%token DVEC4
%token DMAT2
%token DMAT3
%token DMAT4
%token NOPERSPECTIVE
%token FLAT
%token SMOOTH
%token LAYOUT
%token MAT2X2
%token MAT2X3
%token MAT2X4
%token MAT3X2
%token MAT3X3
%token MAT3X4
%token MAT4X2
%token MAT4X3
%token MAT4X4
%token DMAT2X2
%token DMAT2X3
%token DMAT2X4
%token DMAT3X2
%token DMAT3X3
%token DMAT3X4
%token DMAT4X2
%token DMAT4X3
%token DMAT4X4
%token ATOMIC_UINT
%token SAMPLER1D
%token SAMPLER2D
%token SAMPLER3D
%token SAMPLERCUBE
%token SAMPLER1DSHADOW
%token SAMPLER2DSHADOW
%token SAMPLERCUBESHADOW
%token SAMPLER1DARRAY
%token SAMPLER2DARRAY
%token SAMPLER1DARRAYSHADOW
%token SAMPLER2DARRAYSHADOW
%token ISAMPLER1D
%token ISAMPLER2D
%token ISAMPLER3D
%token ISAMPLERCUBE
%token ISAMPLER1DARRAY
%token ISAMPLER2DARRAY
%token USAMPLER1D
%token USAMPLER2D
%token USAMPLER3D
%token USAMPLERCUBE
%token USAMPLER1DARRAY
%token USAMPLER2DARRAY
%token SAMPLER2DRECT
%token SAMPLER2DRECTSHADOW
%token ISAMPLER2DRECT
%token USAMPLER2DRECT
%token SAMPLERBUFFER
%token ISAMPLERBUFFER
%token USAMPLERBUFFER
%token SAMPLERCUBEARRAY
%token SAMPLERCUBEARRAYSHADOW
%token ISAMPLERCUBEARRAY
%token USAMPLERCUBEARRAY
%token SAMPLER2DMS
%token ISAMPLER2DMS
%token USAMPLER2DMS
%token SAMPLER2DMSARRAY
%token ISAMPLER2DMSARRAY
%token USAMPLER2DMSARRAY
%token IMAGE1D
%token IIMAGE1D
%token UIMAGE1D
%token IMAGE2D
%token IIMAGE2D
%token UIMAGE2D
%token IMAGE3D
%token IIMAGE3D
%token UIMAGE3D
%token IMAGE2DRECT
%token IIMAGE2DRECT
%token UIMAGE2DRECT
%token IMAGECUBE
%token IIMAGECUBE
%token UIMAGECUBE
%token IMAGEBUFFER
%token IIMAGEBUFFER
%token UIMAGEBUFFER
%token IMAGE1DARRAY
%token IIMAGE1DARRAY
%token UIMAGE1DARRAY
%token IMAGE2DARRAY
%token IIMAGE2DARRAY
%token UIMAGE2DARRAY
%token IMAGECUBEARRAY
%token IIMAGECUBEARRAY
%token UIMAGECUBEARRAY
%token IMAGE2DMS
%token IIMAGE2DMS
%token UIMAGE2DMS
%token IMAGE2DMSARRAY
%token IIMAGE2DMSARRAY
%token UIMAGE2DMSARRAY
%token STRUCT
%token VOID
%token WHILE
%token <char *> IDENTIFIER
%token <float> FLOATCONSTANT
%token <double> DOUBLECONSTANT
%token <int> INTCONSTANT
%token <unsigned int> UINTCONSTANT
%token TRUE_VALUE
%token FALSE_VALUE
%token LEFT_OP
%token RIGHT_OP
%token INC_OP
%token DEC_OP
%token LE_OP
%token GE_OP
%token EQ_OP
%token NE_OP
%token AND_OP
%token OR_OP
%token XOR_OP
%token MUL_ASSIGN
%token DIV_ASSIGN
%token ADD_ASSIGN
%token MOD_ASSIGN
%token LEFT_ASSIGN
%token RIGHT_ASSIGN
%token AND_ASSIGN
%token XOR_ASSIGN
%token OR_ASSIGN
%token SUB_ASSIGN
%token LEFT_PAREN
%token RIGHT_PAREN
%token LEFT_BRACKET
%token RIGHT_BRACKET
%token LEFT_BRACE
%token RIGHT_BRACE
%token DOT
%token COMMA
%token COLON
%token EQUAL
%token SEMICOLON
%token BANG
%token DASH
%token TILDE
%token PLUS
%token STAR
%token SLASH
%token PERCENT
%token LEFT_ANGLE
%token RIGHT_ANGLE
%token VERTICAL_BAR
%token CARET
%token AMPERSAND
%token QUESTION
%token INVARIANT
%token PRECISE
%token HIGHP
%token MEDIUMP
%token LOWP
%token PRECISION
%token AT
%token UNARY_PLUS
%token UNARY_DASH
%token PRE_INC_OP
%token PRE_DEC_OP
%token POST_DEC_OP
%token POST_INC_OP
%token ARRAY_REF_OP
%token FUNCTION_CALL
%token TYPE_NAME_LIST
%token TYPE_SPECIFIER
%token POSTFIX_EXPRESSION
%token TYPE_QUALIFIER_LIST
%token STRUCT_DECLARATION
%token STRUCT_DECLARATOR
%token STRUCT_SPECIFIER
%token FUNCTION_DEFINITION
%token DECLARATION
%token STATEMENT_LIST
%token TRANSLATION_UNIT
%token PRECISION_DECLARATION
%token BLOCK_DECLARATION
%token TYPE_QUALIFIER_DECLARATION
%token IDENTIFIER_LIST
%token INIT_DECLARATOR_LIST
%token FULLY_SPECIFIED_TYPE
%token SINGLE_DECLARATION
%token SINGLE_INIT_DECLARATION
%token INITIALIZER_LIST
%token EXPRESSION_STATEMENT
%token SELECTION_STATEMENT
%token SELECTION_STATEMENT_ELSE
%token SWITCH_STATEMENT
%token FOR_REST_STATEMENT
%token WHILE_STATEMENT
%token DO_STATEMENT
%token FOR_STATEMENT
%token CASE_LABEL
%token CONDITION_OPT
%token ASSIGNMENT_CONDITION
%token EXPRESSION_CONDITION
%token FUNCTION_HEADER
%token FUNCTION_DECLARATION
%token FUNCTION_PARAMETER_LIST
%token PARAMETER_DECLARATION
%token PARAMETER_DECLARATOR
%token UNINITIALIZED_DECLARATION
%token ARRAY_SPECIFIER
%token ARRAY_SPECIFIER_LIST
%token STRUCT_DECLARATOR_LIST
%token FUNCTION_CALL_PARAMETER_LIST
%token STRUCT_DECLARATION_LIST
%token LAYOUT_QUALIFIER_ID
%token LAYOUT_QUALIFIER_ID_LIST
%token SUBROUTINE_TYPE
%token PAREN_EXPRESSION
%token INIT_DECLARATOR
%token INITIALIZER
%token TERNARY_EXPRESSION
%token FIELD_IDENTIFIER
%token NUM_GLSL_TOKEN
%%
root : { context->root = new_glsl_node(context, TRANSLATION_UNIT, NULL); }
| translation_unit { context->root = $1; }
;
translation_unit : external_declaration
{ $$ = new_glsl_node(context, TRANSLATION_UNIT, $1, NULL); }
| translation_unit external_declaration
{ $$ = new_glsl_node(context, TRANSLATION_UNIT, $1, $2, NULL); }
;
block_identifier : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
;
decl_identifier : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
;
struct_name : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
;
type_name : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
;
param_name : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
;
function_name : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
;
field_identifier : IDENTIFIER { $$ = new_glsl_string(context, FIELD_IDENTIFIER, $1); }
;
variable_identifier : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
;
layout_identifier : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
;
type_specifier_identifier : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
;
external_declaration : function_definition { $$ = $1; }
| declaration { $$ = $1; }
;
function_definition : function_prototype compound_statement_no_new_scope
{ $$ = new_glsl_node(context, FUNCTION_DEFINITION,
$1,
$2,
NULL); }
| function_prototype
{ $$ = new_glsl_node(context, FUNCTION_DEFINITION,
$1,
new_glsl_node(context, STATEMENT_LIST, NULL),
NULL); }
;
compound_statement_no_new_scope : LEFT_BRACE RIGHT_BRACE { $$ = new_glsl_node(context, STATEMENT_LIST, NULL); }
| LEFT_BRACE statement_list RIGHT_BRACE { $$ = $2; }
;
statement : compound_statement { $$ = $1; }
| simple_statement { $$ = $1; }
;
statement_list : statement { $$ = new_glsl_node(context, STATEMENT_LIST, $1, NULL); }
| statement_list statement { $$ = new_glsl_node(context, STATEMENT_LIST, $1, $2, NULL); }
;
compound_statement : LEFT_BRACE RIGHT_BRACE { $$ = new_glsl_node(context, STATEMENT_LIST, NULL); }
| LEFT_BRACE statement_list RIGHT_BRACE { $$ = $2; }
;
simple_statement : declaration { $$ = $1; }
| expression_statement { $$ = $1; }
| selection_statement { $$ = $1; }
| switch_statement { $$ = $1; }
| case_label { $$= $1; }
| iteration_statement { $$ = $1; }
| jump_statement { $$ = $1; }
;
declaration : function_prototype SEMICOLON { $$ = new_glsl_node(context, DECLARATION, $1, NULL); }
| init_declarator_list SEMICOLON { $$ = new_glsl_node(context, DECLARATION, $1, NULL); }
| PRECISION precision_qualifier type_specifier SEMICOLON
{ $$ = new_glsl_node(context, DECLARATION,
new_glsl_node(context, PRECISION_DECLARATION,
$2,
$3,
NULL),
NULL); }
| type_qualifier block_identifier LEFT_BRACE struct_declaration_list RIGHT_BRACE SEMICOLON
{ $$ = new_glsl_node(context, DECLARATION,
new_glsl_node(context, BLOCK_DECLARATION,
$1,
$2,
$4,
new_glsl_identifier(context, NULL),
new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
NULL),
NULL); }
| type_qualifier block_identifier LEFT_BRACE struct_declaration_list RIGHT_BRACE decl_identifier SEMICOLON
{ $$ = new_glsl_node(context, DECLARATION,
new_glsl_node(context, BLOCK_DECLARATION,
$1,
$2,
$4,
$6,
new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
NULL),
NULL); }
| type_qualifier block_identifier LEFT_BRACE struct_declaration_list RIGHT_BRACE decl_identifier array_specifier_list SEMICOLON
{ $$ = new_glsl_node(context, DECLARATION,
new_glsl_node(context, BLOCK_DECLARATION,
$1,
$2,
$4,
$6,
$7,
NULL),
NULL); }
| type_qualifier SEMICOLON
{ $$ = new_glsl_node(context, DECLARATION,
new_glsl_node(context, UNINITIALIZED_DECLARATION,
$1,
new_glsl_identifier(context, NULL),
NULL),
NULL); }
| type_qualifier type_name SEMICOLON
{ $$ = new_glsl_node(context, DECLARATION,
new_glsl_node(context, UNINITIALIZED_DECLARATION,
$1,
$2,
new_glsl_node(context, IDENTIFIER_LIST, NULL),
NULL),
NULL); }
| type_qualifier type_name identifier_list SEMICOLON
{ $$ = new_glsl_node(context, DECLARATION,
new_glsl_node(context, UNINITIALIZED_DECLARATION,
$1,
$2,
$3,
NULL),
NULL); }
;
identifier_list : COMMA decl_identifier { $$ = new_glsl_node(context, IDENTIFIER_LIST, $2, NULL); }
| identifier_list COMMA decl_identifier
{ $$ = new_glsl_node(context, IDENTIFIER_LIST, $1, $3, NULL); }
;
init_declarator_list : single_declaration { $$ = new_glsl_node(context, INIT_DECLARATOR_LIST, $1, NULL); }
| init_declarator_list COMMA decl_identifier
{ $$ = new_glsl_node(context, INIT_DECLARATOR_LIST,
$1,
new_glsl_node(context, INIT_DECLARATOR,
$3,
new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
NULL),
NULL); }
| init_declarator_list COMMA decl_identifier array_specifier_list
{ $$ = new_glsl_node(context, INIT_DECLARATOR_LIST,
$1,
new_glsl_node(context, INIT_DECLARATOR,
$3,
$4,
NULL),
NULL); }
| init_declarator_list COMMA decl_identifier array_specifier_list EQUAL initializer
{ $$ = new_glsl_node(context, INIT_DECLARATOR_LIST,
$1,
new_glsl_node(context, INIT_DECLARATOR,
$3,
$4,
$6,
NULL),
NULL); }
| init_declarator_list COMMA decl_identifier EQUAL initializer
{ $$ = new_glsl_node(context, INIT_DECLARATOR_LIST,
$1,
new_glsl_node(context, INIT_DECLARATOR,
$3,
new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
$5,
NULL),
NULL); }
;
single_declaration : fully_specified_type
{ $$ = new_glsl_node(context, SINGLE_DECLARATION,
$1,
new_glsl_identifier(context, NULL),
new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
NULL); }
| fully_specified_type decl_identifier
{ $$ = new_glsl_node(context, SINGLE_DECLARATION,
$1,
$2,
new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
NULL); }
| fully_specified_type decl_identifier array_specifier_list
{ $$ = new_glsl_node(context, SINGLE_DECLARATION, $1, $2, $3, NULL); }
| fully_specified_type decl_identifier array_specifier_list EQUAL initializer
{ $$ = new_glsl_node(context, SINGLE_INIT_DECLARATION, $1, $2, $3, $5, NULL); }
| fully_specified_type decl_identifier EQUAL initializer
{ $$ = new_glsl_node(context, SINGLE_INIT_DECLARATION,
$1,
$2,
new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
$4,
NULL); }
;
initializer : assignment_expression { $$ = new_glsl_node(context, INITIALIZER, $1, NULL); }
| LEFT_BRACE initializer_list RIGHT_BRACE { $$ = new_glsl_node(context, INITIALIZER, $2, NULL); }
| LEFT_BRACE initializer_list COMMA RIGHT_BRACE { $$ = new_glsl_node(context, INITIALIZER, $2, NULL); }
;
initializer_list : initializer
{ $$ = new_glsl_node(context, INITIALIZER_LIST, $1, NULL); }
| initializer_list COMMA initializer
{ $$ = new_glsl_node(context, INITIALIZER_LIST, $1, $3, NULL); }
;
expression_statement : SEMICOLON { $$ = new_glsl_node(context, EXPRESSION_STATEMENT, NULL); }
| expression SEMICOLON { $$ = new_glsl_node(context, EXPRESSION_STATEMENT, $1, NULL); }
;
selection_statement : IF LEFT_PAREN expression RIGHT_PAREN statement
{ $$ = new_glsl_node(context, SELECTION_STATEMENT, $3, $5, NULL); }
| IF LEFT_PAREN expression RIGHT_PAREN statement ELSE statement
{ $$ = new_glsl_node(context, SELECTION_STATEMENT_ELSE, $3, $5, $7, NULL); }
;
switch_statement : SWITCH LEFT_PAREN expression RIGHT_PAREN LEFT_BRACE switch_statement_list RIGHT_BRACE
{ $$ = new_glsl_node(context, SWITCH_STATEMENT, $3, $6, NULL); }
;
switch_statement_list : { $$ = new_glsl_node(context, STATEMENT_LIST, NULL); }
| statement_list { $$ = $1; }
;
case_label : CASE expression COLON { $$ = new_glsl_node(context, CASE_LABEL, $2, NULL); }
| DEFAULT COLON { $$ = new_glsl_node(context, CASE_LABEL, NULL); }
;
iteration_statement : WHILE LEFT_PAREN condition RIGHT_PAREN statement_no_new_scope
{ $$ = new_glsl_node(context, WHILE_STATEMENT, $3, $5, NULL); }
| DO statement WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON
{ $$ = new_glsl_node(context, DO_STATEMENT, $2, $5, NULL); }
| FOR LEFT_PAREN for_init_statement for_rest_statement RIGHT_PAREN statement_no_new_scope
{ $$ = new_glsl_node(context, FOR_STATEMENT, $3, $4, $6, NULL); }
;
statement_no_new_scope : compound_statement_no_new_scope { $$ = $1; }
| simple_statement { $$ = $1; }
;
for_init_statement : expression_statement { $$ = $1; }
| declaration { $$ = $1; }
;
conditionopt : condition { $$ = new_glsl_node(context, CONDITION_OPT, $1, NULL); }
| { $$ = new_glsl_node(context, CONDITION_OPT, NULL); }
;
condition : expression
{ $$ = new_glsl_node(context, EXPRESSION_CONDITION, $1, NULL); }
| fully_specified_type variable_identifier EQUAL initializer
{ $$ = new_glsl_node(context, ASSIGNMENT_CONDITION, $1, $2, $4, NULL); }
;
for_rest_statement : conditionopt SEMICOLON
{ $$ = new_glsl_node(context, FOR_REST_STATEMENT, $1, NULL); }
| conditionopt SEMICOLON expression
{ $$ = new_glsl_node(context, FOR_REST_STATEMENT, $1, $3, NULL); }
;
jump_statement : CONTINUE SEMICOLON
{ $$ = new_glsl_node(context, CONTINUE, NULL); }
| BREAK SEMICOLON
{ $$ = new_glsl_node(context, BREAK, NULL); }
| RETURN SEMICOLON
{ $$ = new_glsl_node(context, RETURN, NULL); }
| RETURN expression SEMICOLON
{ $$ = new_glsl_node(context, RETURN_VALUE, $2, NULL); }
| DISCARD SEMICOLON
{ $$ = new_glsl_node(context, DISCARD, NULL); }
;
function_prototype : function_declarator RIGHT_PAREN { $$ = $1; }
;
function_declarator : function_header
{ $$ = new_glsl_node(context, FUNCTION_DECLARATION,
$1,
new_glsl_node(context, FUNCTION_PARAMETER_LIST, NULL),
NULL); }
| function_header function_parameter_list
{ $$ = new_glsl_node(context, FUNCTION_DECLARATION,
$1,
$2,
NULL); }
;
function_parameter_list : parameter_declaration
{ $$ = new_glsl_node(context, FUNCTION_PARAMETER_LIST, $1, NULL); }
| function_parameter_list COMMA parameter_declaration
{ $$ = new_glsl_node(context, FUNCTION_PARAMETER_LIST, $1, $3, NULL); }
;
parameter_declaration : type_qualifier parameter_declarator
{ $$ = new_glsl_node(context, PARAMETER_DECLARATION, $1, $2, NULL); }
| parameter_declarator
{ $$ = new_glsl_node(context, PARAMETER_DECLARATION,
new_glsl_node(context, TYPE_QUALIFIER_LIST, NULL),
$1,
NULL); }
| type_qualifier parameter_type_specifier
{ $$ = new_glsl_node(context, PARAMETER_DECLARATION, $1, $2, NULL); }
| parameter_type_specifier
{ $$ = new_glsl_node(context, PARAMETER_DECLARATION,
new_glsl_node(context, TYPE_QUALIFIER_LIST, NULL),
$1,
NULL); }
;
parameter_declarator : type_specifier param_name
{ $$ = new_glsl_node(context, PARAMETER_DECLARATOR, $1, $2, NULL); }
| type_specifier param_name array_specifier_list
{ $$ = new_glsl_node(context, PARAMETER_DECLARATOR, $1, $2, $3, NULL);}
;
function_header : fully_specified_type function_name LEFT_PAREN
{ $$ = new_glsl_node(context, FUNCTION_HEADER, $1, $2, NULL); }
;
fully_specified_type : type_specifier
{ $$ = new_glsl_node(context, FULLY_SPECIFIED_TYPE,
new_glsl_node(context, TYPE_QUALIFIER_LIST, NULL),
$1,
NULL); }
| type_qualifier type_specifier
{ $$ = new_glsl_node(context, FULLY_SPECIFIED_TYPE, $1, $2, NULL); }
;
parameter_type_specifier : type_specifier
{ $$ = new_glsl_node(context, PARAMETER_DECLARATOR, $1, NULL); }
;
type_specifier : type_specifier_nonarray
{ $$ = new_glsl_node(context, TYPE_SPECIFIER,
$1,
new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
NULL); }
| type_specifier_nonarray array_specifier_list
{ $$ = new_glsl_node(context, TYPE_SPECIFIER, $1, $2, NULL); }
;
array_specifier_list : array_specifier
{ $$ = new_glsl_node(context, ARRAY_SPECIFIER_LIST, $1, NULL); }
| array_specifier_list array_specifier
{ $$ = new_glsl_node(context, ARRAY_SPECIFIER_LIST, $1, $2, NULL); }
;
array_specifier : LEFT_BRACKET RIGHT_BRACKET
{ $$ = new_glsl_node(context, ARRAY_SPECIFIER, NULL); }
| LEFT_BRACKET constant_expression RIGHT_BRACKET
{ $$ = new_glsl_node(context, ARRAY_SPECIFIER, $2, NULL); }
;
type_specifier_nonarray : VOID { $$ = new_glsl_node(context, VOID, NULL); }
| FLOAT { $$ = new_glsl_node(context, FLOAT, NULL); }
| DOUBLE { $$ = new_glsl_node(context, DOUBLE, NULL); }
| INT { $$ = new_glsl_node(context, INT, NULL); }
| UINT { $$ = new_glsl_node(context, UINT, NULL); }
| BOOL { $$ = new_glsl_node(context, BOOL, NULL); }
| VEC2 { $$ = new_glsl_node(context, VEC2, NULL); }
| VEC3 { $$ = new_glsl_node(context, VEC3, NULL); }
| VEC4 { $$ = new_glsl_node(context, VEC4, NULL); }
| DVEC2 { $$ = new_glsl_node(context, DVEC2, NULL); }
| DVEC3 { $$ = new_glsl_node(context, DVEC3, NULL); }
| DVEC4 { $$ = new_glsl_node(context, DVEC4, NULL); }
| BVEC2 { $$ = new_glsl_node(context, BVEC2, NULL); }
| BVEC3 { $$ = new_glsl_node(context, BVEC3, NULL); }
| BVEC4 { $$ = new_glsl_node(context, BVEC4, NULL); }
| IVEC2 { $$ = new_glsl_node(context, IVEC2, NULL); }
| IVEC3 { $$ = new_glsl_node(context, IVEC3, NULL); }
| IVEC4 { $$ = new_glsl_node(context, IVEC4, NULL); }
| UVEC2 { $$ = new_glsl_node(context, UVEC2, NULL); }
| UVEC3 { $$ = new_glsl_node(context, UVEC3, NULL); }
| UVEC4 { $$ = new_glsl_node(context, UVEC4, NULL); }
| MAT2 { $$ = new_glsl_node(context, MAT2, NULL); }
| MAT3 { $$ = new_glsl_node(context, MAT3, NULL); }
| MAT4 { $$ = new_glsl_node(context, MAT4, NULL); }
| MAT2X2 { $$ = new_glsl_node(context, MAT2X2, NULL); }
| MAT2X3 { $$ = new_glsl_node(context, MAT2X3, NULL); }
| MAT2X4 { $$ = new_glsl_node(context, MAT2X4, NULL); }
| MAT3X2 { $$ = new_glsl_node(context, MAT3X2, NULL); }
| MAT3X3 { $$ = new_glsl_node(context, MAT3X3, NULL); }
| MAT3X4 { $$ = new_glsl_node(context, MAT3X4, NULL); }
| MAT4X2 { $$ = new_glsl_node(context, MAT4X2, NULL); }
| MAT4X3 { $$ = new_glsl_node(context, MAT4X3, NULL); }
| MAT4X4 { $$ = new_glsl_node(context, MAT4X4, NULL); }
| DMAT2 { $$ = new_glsl_node(context, DMAT2, NULL); }
| DMAT3 { $$ = new_glsl_node(context, DMAT3, NULL); }
| DMAT4 { $$ = new_glsl_node(context, DMAT4, NULL); }
| DMAT2X2 { $$ = new_glsl_node(context, DMAT2X2, NULL); }
| DMAT2X3 { $$ = new_glsl_node(context, DMAT2X3, NULL); }
| DMAT2X4 { $$ = new_glsl_node(context, DMAT2X4, NULL); }
| DMAT3X2 { $$ = new_glsl_node(context, DMAT3X2, NULL); }
| DMAT3X3 { $$ = new_glsl_node(context, DMAT3X3, NULL); }
| DMAT3X4 { $$ = new_glsl_node(context, DMAT3X4, NULL); }
| DMAT4X2 { $$ = new_glsl_node(context, DMAT4X2, NULL); }
| DMAT4X3 { $$ = new_glsl_node(context, DMAT4X3, NULL); }
| DMAT4X4 { $$ = new_glsl_node(context, DMAT4X4, NULL); }
| ATOMIC_UINT { $$ = new_glsl_node(context, UINT, NULL); }
| SAMPLER1D { $$ = new_glsl_node(context, SAMPLER1D, NULL); }
| SAMPLER2D { $$ = new_glsl_node(context, SAMPLER2D, NULL); }
| SAMPLER3D { $$ = new_glsl_node(context, SAMPLER3D, NULL); }
| SAMPLERCUBE { $$ = new_glsl_node(context, SAMPLERCUBE, NULL); }
| SAMPLER1DSHADOW { $$ = new_glsl_node(context, SAMPLER1DSHADOW, NULL); }
| SAMPLER2DSHADOW { $$ = new_glsl_node(context, SAMPLER2DSHADOW, NULL); }
| SAMPLERCUBESHADOW { $$ = new_glsl_node(context, SAMPLERCUBESHADOW, NULL); }
| SAMPLER1DARRAY { $$ = new_glsl_node(context, SAMPLER1DARRAY, NULL); }
| SAMPLER2DARRAY { $$ = new_glsl_node(context, SAMPLER2DARRAY, NULL); }
| SAMPLER1DARRAYSHADOW { $$ = new_glsl_node(context, SAMPLER1DARRAYSHADOW, NULL); }
| SAMPLER2DARRAYSHADOW { $$ = new_glsl_node(context, SAMPLER2DARRAYSHADOW, NULL); }
| SAMPLERCUBEARRAY { $$ = new_glsl_node(context, SAMPLERCUBEARRAY, NULL); }
| SAMPLERCUBEARRAYSHADOW { $$ = new_glsl_node(context, SAMPLERCUBEARRAYSHADOW, NULL); }
| ISAMPLER1D { $$ = new_glsl_node(context, ISAMPLER1D, NULL); }
| ISAMPLER2D { $$ = new_glsl_node(context, ISAMPLER2D, NULL); }
| ISAMPLER3D { $$ = new_glsl_node(context, ISAMPLER3D, NULL); }
| ISAMPLERCUBE { $$ = new_glsl_node(context, ISAMPLERCUBE, NULL); }
| ISAMPLER1DARRAY { $$ = new_glsl_node(context, ISAMPLER1DARRAY, NULL); }
| ISAMPLER2DARRAY { $$ = new_glsl_node(context, ISAMPLER2DARRAY, NULL); }
| ISAMPLERCUBEARRAY { $$ = new_glsl_node(context, ISAMPLERCUBEARRAY, NULL); }
| USAMPLER1D { $$ = new_glsl_node(context, USAMPLER1D, NULL); }
| USAMPLER2D { $$ = new_glsl_node(context, USAMPLER2D, NULL); }
| USAMPLER3D { $$ = new_glsl_node(context, USAMPLER3D, NULL); }
| USAMPLERCUBE { $$ = new_glsl_node(context, USAMPLERCUBE, NULL); }
| USAMPLER1DARRAY { $$ = new_glsl_node(context, USAMPLER1DARRAY, NULL); }
| USAMPLER2DARRAY { $$ = new_glsl_node(context, USAMPLER2DARRAY, NULL); }
| USAMPLERCUBEARRAY { $$ = new_glsl_node(context, USAMPLERCUBEARRAY, NULL); }
| SAMPLER2DRECT { $$ = new_glsl_node(context, SAMPLER2DRECT, NULL); }
| SAMPLER2DRECTSHADOW { $$ = new_glsl_node(context, SAMPLER2DRECTSHADOW, NULL); }
| ISAMPLER2DRECT { $$ = new_glsl_node(context, ISAMPLER2DRECT, NULL); }
| USAMPLER2DRECT { $$ = new_glsl_node(context, USAMPLER2DRECT, NULL); }
| SAMPLERBUFFER { $$ = new_glsl_node(context, SAMPLERBUFFER, NULL); }
| ISAMPLERBUFFER { $$ = new_glsl_node(context, ISAMPLERBUFFER, NULL); }
| USAMPLERBUFFER { $$ = new_glsl_node(context, USAMPLERBUFFER, NULL); }
| SAMPLER2DMS { $$ = new_glsl_node(context, SAMPLER2DMS, NULL); }
| ISAMPLER2DMS { $$ = new_glsl_node(context, ISAMPLER2DMS, NULL); }
| USAMPLER2DMS { $$ = new_glsl_node(context, USAMPLER2DMS, NULL); }
| SAMPLER2DMSARRAY { $$ = new_glsl_node(context, SAMPLER2DMSARRAY, NULL); }
| ISAMPLER2DMSARRAY { $$ = new_glsl_node(context, ISAMPLER2DMSARRAY, NULL); }
| USAMPLER2DMSARRAY { $$ = new_glsl_node(context, USAMPLER2DMSARRAY, NULL); }
| IMAGE1D { $$ = new_glsl_node(context, IMAGE1D, NULL); }
| IIMAGE1D { $$ = new_glsl_node(context, IIMAGE1D, NULL); }
| UIMAGE1D { $$ = new_glsl_node(context, UIMAGE1D, NULL); }
| IMAGE2D { $$ = new_glsl_node(context, IMAGE2D, NULL); }
| IIMAGE2D { $$ = new_glsl_node(context, IIMAGE2D, NULL); }
| UIMAGE2D { $$ = new_glsl_node(context, UIMAGE2D, NULL); }
| IMAGE3D { $$ = new_glsl_node(context, IMAGE3D, NULL); }
| IIMAGE3D { $$ = new_glsl_node(context, IIMAGE3D, NULL); }
| UIMAGE3D { $$ = new_glsl_node(context, UIMAGE3D, NULL); }
| IMAGE2DRECT { $$ = new_glsl_node(context, IMAGE2DRECT, NULL); }
| IIMAGE2DRECT { $$ = new_glsl_node(context, IIMAGE2DRECT, NULL); }
| UIMAGE2DRECT { $$ = new_glsl_node(context, UIMAGE2DRECT, NULL); }
| IMAGECUBE { $$ = new_glsl_node(context, IMAGECUBE, NULL); }
| IIMAGECUBE { $$ = new_glsl_node(context, IIMAGECUBE, NULL); }
| UIMAGECUBE { $$ = new_glsl_node(context, UIMAGECUBE, NULL); }
| IMAGEBUFFER { $$ = new_glsl_node(context, IMAGEBUFFER, NULL); }
| IIMAGEBUFFER { $$ = new_glsl_node(context, IIMAGEBUFFER, NULL); }