Blender V5.3
grammar.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12
13#include "scope.hh"
14#include "token.hh"
15#include "token_stream.hh"
16
18
19#define EXPRESSION_TOKENS \
20 Ampersand: \
21 case BitwiseNot: \
22 case Colon: \
23 case Decrement: \
24 case Divide: \
25 case Dot: \
26 case Equal: \
27 case GEqual: \
28 case GThan: \
29 case Increment: \
30 case LEqual: \
31 case LogicalAnd: \
32 case LogicalOr: \
33 case LThan: \
34 case Minus: \
35 case Modulo: \
36 case Multiply: \
37 case Not: \
38 case NotEqual: \
39 case Or: \
40 case Plus: \
41 case Question: \
42 case RShift: \
43 case LShift: \
44 case AssignAdd: \
45 case AssignSub: \
46 case AssignMul: \
47 case AssignDiv: \
48 case AssignLShift: \
49 case AssignRShift: \
50 case Xor
51
52/*
53 * Simple Recursive Descent Parser that creates AST nodes.
54 * For now, the AST nodes are just ranges of token (called Scopes) with a specific semantic
55 * attached.
56 *
57 * Since shader code transformations are happening on code still contains macros and preprocessor
58 * directives, this parser need to be much less pedantic regarding the target syntax.
59 */
62
64
65 using Node = Scope;
67
69
74
76 {
77 open_scope(curr, ScopeType::Global);
78 /* Skip first whitespace token if it exists. */
79 if (peek() == NewLine || peek() == Space) {
80 next();
81 }
83 close_scope(parser.back(), ScopeType::Global);
84 match(EndOfFile);
85 }
86
88 {
89 while (true) {
90 switch (peek()) {
91 case Hash:
93 break;
94 case SquareOpen:
96 break;
97 case Namespace:
99 break;
100 case Class:
101 case Struct:
102 case Union:
104 break;
105 case Enum:
107 break;
108 case ParOpen:
110 break;
111 case TemplateOpen:
113 break;
114 case Template:
116 break;
117 case Using:
118 next();
119 match_if(Namespace);
120 qualified_id();
121 break;
122 case Assign:
123 assignment();
124 break;
125 case BracketOpen:
126 /* For C++/HLSL compatibility. */
128 break;
129 case Const:
130 case Colon:
131 case Constexpr:
132 case SemiColon:
133 case Inline:
134 case Static: /* For C++ compatibility. */
135 case NotEqual: /* For MSL matrix operators. */
136 case Minus: /* For MSL matrix operators. */
137 case Typename: /* For MSL / C++. */
138 case Word:
139 next();
140 break;
141 case EndOfFile:
142 case BracketClose:
143 return;
144 default:
145 error("Unexpected token \"" + to_str(peek()) + "\": Expecting declaration");
146 break;
147 }
148 }
149 }
150
151 /* Example: `struct [[a]] A {}`. */
153 {
154 match(Struct, Class, Union);
155 /* Optional attributes. */
156 if (peek() == '[') {
157 attribute();
158 }
159
160 if (peek() == '{') {
161 /* Nameless struct */
162 }
163 else {
164 /* Note we allow `struct A::B` syntax because it is used during namespace lowering. */
165 qualified_id();
166 if (peek() == ';') {
167 /* Allowed because of shared C++ files which have C++ code not yet rejected. */
168 // error("Forward declaration of classes is not supported");
169 return;
170 }
171 if (peek() == Word) {
172 /* Struct keyword usage in variable declaration. */
173 /* Supported because of explicit host shared struct members and C++ shared code. */
174 next();
175 return;
176 }
177 }
178 /* For specialization. */
179 if (peek() == lexit::TemplateOpen) {
181 if (peek() == ';') {
182 /* Template explicit instantiation. */
183 return;
184 }
185 }
186 open_scope(curr, ScopeType::Struct);
187 match('{');
188 members_decl();
189 close_scope(curr, ScopeType::Struct);
190 match('}');
191 /* Support C-style anonymous struct for C compatibility. */
192 match_if(Word);
193 match(';');
194 }
195
197 {
198 while (true) {
199 switch (peek()) {
200 case Hash:
201 preprocessor();
202 break;
203 case SquareOpen:
205 break;
206 case Private:
207 case Public:
208 next();
209 match(':');
210 break;
211 case Class:
212 case Struct:
213 // error("Nested class declaration is not supported");
214 // return;
215 /* Supported because of explicit host shared struct members and C++ shared code. */
217 break;
218 case Enum:
219 // error("Nested enum declaration not supported");
220 // return;
221 /* Supported because of explicit host shared struct members. */
222 if (curr.next(2) == Word) {
223 next();
224 }
225 else {
227 }
228 break;
229 case Union:
231 break;
232 case ParOpen:
234 break;
235 case TemplateOpen:
237 break;
238 case Template:
240 break;
241 case BracketClose:
242 return;
243 case Assign:
244 assignment();
245 break;
246 case Using:
247 next();
248 match_if(Namespace);
249 break;
250 case Const:
251 case Constexpr:
252 case Static:
253 case SemiColon:
254 case Colon:
255 case Ampersand: /* For references. */
256 case Inline: /* For MSL / C++. */
257 case Typename: /* For MSL / C++. */
258 case Number: /* For C++ bit-flags. */
259 case Star: /* For C++ pointers. */
260 case Default: /* For C++ constructor. */
261 case Comma: /* For C++ constructor. */
262 case Equal: /* For C++ operator. */
263 case Minus: /* For C++ operator. */
264 case Plus: /* For C++ operator. */
265 case Divide: /* For C++ operator. */
266 case Word:
267 next();
268 break;
269 default:
270 error("Unexpected token \"" + to_str(peek()) + "\"");
271 return;
272 }
273 }
274 }
275
276 /* Example: `enum [[a]] A : a {}`. */
278 {
279 match(Enum);
280 /* Optional class qualifier. */
281 match_if(Class);
282 /* Optional attributes. */
283 if (peek() == '[') {
284 attribute();
285 }
286 /* Note we allow `struct A::B` syntax because it is used during namespace lowering. */
287 match_if(Word);
288 if (match_if(':')) {
289 /* Underlying type. */
290 match(Word);
291 }
292
293 open_scope(curr, ScopeType::Local);
294 match('{');
295 enum_values();
296 close_scope(curr, ScopeType::Local);
297 match('}');
298 }
299
301 {
302 while (true) {
303 switch (peek()) {
304 case Hash:
305 preprocessor();
306 break;
307 case ParOpen:
309 break;
310 case BracketClose:
311 return;
312 case Assign:
313 assignment();
314 break;
315 case Comma:
316 case Word:
317 case Number:
318 next();
319 break;
320 default:
321 error("Unexpected token \"" + to_str(peek()) + "\"");
322 return;
323 }
324 }
325 }
326
327 /* Example: `union {}`. */
329 {
330 match(Union);
331 open_scope(curr, ScopeType::Local);
332 match('{');
333 members_decl();
334 close_scope(curr, ScopeType::Local);
335 match('}');
336 }
337
339 {
340 match(Template);
341
342 if (peek() == Word || peek() == Struct) {
343 /* Template instantiation. */
344 return;
345 }
347 }
348
350 {
351 if ((curr.prev() != '.') && (curr.prev(1) != '>' && curr.prev(2) != '-')) {
352 /* Expected a method call. */
353 error("Expected explicit template method call");
354 }
355 else {
356 match(Template);
357 }
358 }
359
361 {
362 open_scope(curr, ScopeType::Template);
363 match(TemplateOpen);
364
365 bool in_argument = false;
366 while (true) {
367 switch (peek()) {
368 case Hash:
369 preprocessor();
370 break;
371 case TemplateOpen:
373 break;
374 case TemplateClose:
375 if (in_argument) {
376 in_argument = false;
377 close_scope(curr.prev(), ScopeType::TemplateArg);
378 }
379 close_scope(curr, ScopeType::Template);
380 match(TemplateClose);
381 return;
382 case Comma:
383 if (in_argument) {
384 in_argument = false;
385 close_scope(curr.prev(), ScopeType::TemplateArg);
386 }
387 next();
388 break;
389 case Assign:
390 if (!in_argument) {
391 /* Expecting at least a type before an assignment. */
392 match(Word);
393 }
394 /* For MSL/C++ compatibility. */
395 assignment();
396 break;
397 case Star: /* For C++ shared headers. */
398 case Class: /* Used during union processing. */
399 case Struct: /* Used during union processing. */
400 case Colon: /* Could be removed if using qualified_id(). */
401 case LThan:
402 case Plus:
403 case Minus:
404 case Divide:
405 case Modulo:
406 case GThan:
407 case LEqual:
408 case GEqual:
409 case Equal:
410 case Const:
411 case Word:
412 case Number:
413 case Enum:
414 case Typename:
415 if (!in_argument) {
416 open_scope(curr, ScopeType::TemplateArg);
417 in_argument = true;
418 }
419 next();
420 break;
421 default:
422 error("Unexpected token \"" + to_str(peek()) + "\"");
423 return;
424 }
425 }
426 }
427
428 /* Example: `A::T<t> A::B<T>(){}`. */
430 {
432 match_if(Const);
433 if (match_if(';')) {
434 /* Template instantiation or forward declaration. */
435 return;
436 }
437 if (peek() == '{') {
439 return;
440 }
441 /* Function call.
442 * Could eventually become an error but is currently used by create info macros. */
443 }
444
446 {
447 open_scope(curr, ScopeType::Assignment);
448 match('=');
449
450 while (true) {
451 switch (peek()) {
452 case Hash:
453 preprocessor();
454 break;
455 case Template:
457 break;
458 case TemplateOpen:
460 break;
461 case ParOpen:
463 break;
464 case SquareOpen:
465 subscript();
466 break;
467 case BracketOpen:
469 break;
470 case Assign:
471 close_scope(curr.prev(), ScopeType::Assignment);
472 assignment();
473 return;
474 case ParClose:
475 case BracketClose:
476 case TemplateClose:
477 case Comma:
478 case SemiColon:
479 close_scope(curr.prev(), ScopeType::Assignment);
480 return;
481 case This:
482 case Default: /* For C++ constructor. */
483 case Typename: /* For MSL / C++. */
484 case Word:
485 case String:
486 case Number:
488 next();
489 break;
490 default:
491 error("Unexpected token \"" + to_str(peek()) + "\"");
492 return;
493 }
494 }
495 }
496
498 {
499 open_scope(curr, type);
500 match('{');
501
502 while (true) {
503 switch (peek()) {
504 case Hash:
505 preprocessor();
506 break;
507 case Template:
509 break;
510 case TemplateOpen:
512 break;
513 case BracketOpen:
515 break;
516 case BracketClose:
517 close_scope(curr, type);
518 match('}');
519 return;
520 case ParOpen:
522 break;
523 case SquareOpen:
525 break;
526 case Assign:
527 assignment();
528 break;
529 case For:
530 for_loop();
531 break;
532 case While:
533 while_loop();
534 break;
535 case Do:
537 break;
538 case Switch:
540 break;
541 case If:
542 next();
544 break;
545 case Else:
546 next();
547 if (peek() == If) {
548 break;
549 }
551 break;
552 case Using:
553 next();
554 match_if(Namespace);
555 qualified_id();
556 break;
557 case Static:
558 case This:
559 case Case: /* For switch cases. */
560 case Default: /* For switch cases. */
561 case Comma:
562 case Break:
563 case Const:
564 case Constexpr:
565 case Continue:
566 case Return:
567 case SemiColon:
568 case Word:
569 case String:
570 case Number:
571 case Typename: /* For MSL / C++. */
573 next();
574 break;
575 default:
576 error("Unexpected token \"" + to_str(peek()) + "\"");
577 return;
578 }
579 }
580 }
581
588
589 void for_loop()
590 {
591 match(For);
594 }
595
597 {
598 match(While);
601 }
602
604 {
605 match(Do);
607 match(While);
609 }
610
611 void condition(int arg_needed, ScopeType type)
612 {
613 match_if(Constexpr);
614
615 open_scope(curr, type);
616 match('(');
617
618 int arg_count = 0;
619 bool in_argument = false;
620 while (true) {
621 switch (peek()) {
622 case Hash:
623 preprocessor();
624 break;
625 case ParOpen:
626 if (!in_argument) {
627 if (type == ScopeType::LoopArgs) {
628 open_scope(curr, ScopeType::LoopArg);
629 }
630 in_argument = true;
631 }
633 break;
634 case ParClose:
635 ++arg_count;
636 if (in_argument) {
637 in_argument = false;
638 if (type == ScopeType::LoopArgs) {
639 close_scope(curr.prev(), ScopeType::LoopArg);
640 }
641 }
642 close_scope(curr, type);
643 if (arg_count < arg_needed) {
644 /* Error about missing semicolon. */
645 error("Missing loop or conditional statement");
646 return;
647 }
648 match(')');
649 /* Optional attribute. */
650 if (peek() == '[') {
651 attribute();
652 }
653 return;
654 case SemiColon:
655 ++arg_count;
656 if (arg_count == arg_needed) {
657 /* Error about extra semicolon. */
658 error("Extraneous loop or conditional statement");
659 return;
660 }
661 if (in_argument && type == ScopeType::LoopArgs) {
662 in_argument = false;
663 close_scope(curr.prev(), ScopeType::LoopArg);
664 }
665 next();
666 break;
667 case SquareOpen:
668 subscript();
669 break;
670 case Comma:
671 case This:
672 case Word:
673 case Number:
674 case Assign: /* Because LEqual and GEqual might not be parsed. */
676 if (!in_argument) {
677 if (type == ScopeType::LoopArgs) {
678 open_scope(curr, ScopeType::LoopArg);
679 }
680 in_argument = true;
681 }
682 next();
683 break;
684 default:
685 error("Unexpected token \"" + to_str(peek()) + "\"");
686 return;
687 }
688 }
689 }
690
692 {
693 open_scope(curr, ScopeType::FunctionArgs);
694 match('(');
695
696 bool in_argument = false;
697 while (true) {
698 switch (peek()) {
699 case Hash:
700 preprocessor();
701 break;
702 case ParOpen:
703 if (!in_argument) {
704 /* This could be enabled once we get rid of all global level macros. */
705 // /* Expecting at least a type before a function call. */
706 // match(Word);
707 open_scope(curr, ScopeType::FunctionArg);
708 in_argument = true;
709 }
711 break;
712 case BracketOpen:
713 if (!in_argument) {
714 /* Expecting at least a type before a function call. */
715 match(Word);
716 }
717 /* For initializer list constructor of parameters. */
719 break;
720 case TemplateOpen:
722 break;
723 case ParClose:
724 if (in_argument) {
725 in_argument = false;
726 close_scope(curr.prev(), ScopeType::FunctionArg);
727 }
728 close_scope(curr, ScopeType::FunctionArgs);
729 match(')');
730 return;
731 case Comma:
732 if (in_argument) {
733 in_argument = false;
734 close_scope(curr.prev(), ScopeType::FunctionArg);
735 }
736 next();
737 break;
738 case SquareOpen:
739 if (!in_argument) {
740 open_scope(curr, ScopeType::FunctionArg);
741 in_argument = true;
742 }
744 break;
745 case Assign:
746 if (!in_argument) {
747 /* Expecting at least a type before an assignment. */
748 match(Word);
749 }
750 assignment();
751 break;
752 case String: /* Needed for legacy create info. */
753 case EXPRESSION_TOKENS: /* Needed for some macros. */
754 case Word:
755 case Number:
756 case Const:
757 case Constexpr:
758 if (!in_argument) {
759 open_scope(curr, ScopeType::FunctionArg);
760 in_argument = true;
761 }
762 next();
763 break;
764 default:
765 error("Unexpected token \"" + to_str(peek()) + "\"");
766 return;
767 }
768 }
769 }
770
772 {
773 TokenType prev = curr.prev().type();
774 if (prev == Word || prev == lexit::TemplateClose) {
776 }
777 else {
779 }
780 }
781
783 {
784 open_scope(curr, ScopeType::Local);
785 match('(');
786
787 while (true) {
788 switch (peek()) {
789 case Hash:
790 preprocessor();
791 break;
792 case ParOpen:
794 break;
795 case ParClose:
796 close_scope(curr, ScopeType::Local);
797 match(')');
798 return;
799 case SquareOpen:
800 subscript();
801 break;
802 case This:
803 case Comma:
804 case Number:
805 case Word:
806 case String:
807 case Assign: /* Because LEqual and GEqual might not be parsed. */
809 next();
810 break;
811 default:
812 error("Unexpected token \"" + to_str(peek()) + "\"");
813 return;
814 }
815 }
816 }
817
819 {
820 open_scope(curr, ScopeType::FunctionCall);
821 match('(');
822
823 bool in_argument = false;
824 while (true) {
825 switch (peek()) {
826 case Hash:
827 preprocessor();
828 break;
829 case ParOpen:
830 if (!in_argument) {
831 open_scope(curr, ScopeType::FunctionParam);
832 in_argument = true;
833 }
835 break;
836 case ParClose:
837 if (in_argument) {
838 in_argument = false;
839 close_scope(curr.prev(), ScopeType::FunctionParam);
840 }
841 close_scope(curr, ScopeType::FunctionCall);
842 match(')');
843 return;
844 case Template:
846 break;
847 case TemplateOpen:
849 break;
850 case BracketOpen:
852 break;
853 case Comma:
854 if (in_argument) {
855 in_argument = false;
856 close_scope(curr.prev(), ScopeType::FunctionParam);
857 }
858 next();
859 break;
860 case SquareOpen:
861 subscript();
862 break;
863 case Number:
864 case Word:
865 case String:
866 case This:
867 case Assign: /* Because LEqual and GEqual might not be parsed. */
869 if (!in_argument) {
870 open_scope(curr, ScopeType::FunctionParam);
871 in_argument = true;
872 }
873 next();
874 break;
875 default:
876 error("Unexpected token \"" + to_str(peek()) + "\"");
877 return;
878 }
879 }
880 }
881
883 {
884 if (curr.next() == '[') {
885 attribute();
886 }
887 else {
888 subscript();
889 }
890 }
891
893 {
894 open_scope(curr, ScopeType::Subscript);
895 match('[');
896 if (peek() == '[') {
897 error("Unexpected attribute specifier");
898 return;
899 }
900
901 while (true) {
902 switch (peek()) {
903 case Hash:
904 preprocessor();
905 break;
906 case ParOpen:
908 break;
909 case SquareOpen:
910 subscript();
911 break;
912 case SquareClose:
913 close_scope(curr, ScopeType::Subscript);
914 match(']');
915 return;
916 case Comma: /* For structure binding. */
917 case Number:
918 case Word:
919 case This:
920 case Assign: /* Because LEqual and GEqual might not be parsed. */
922 next();
923 break;
924 default:
925 error("Unexpected token \"" + to_str(peek()) + "\"");
926 return;
927 }
928 }
929 }
930
932 {
933 open_scope(curr, ScopeType::Subscript);
934 match('[');
935 open_scope(curr, ScopeType::Attributes);
936 match('[');
937
938 bool in_attribute = false;
939 while (true) {
940 switch (peek()) {
941 case SquareClose:
942 if (in_attribute) {
943 in_attribute = false;
944 close_scope(curr.prev(), ScopeType::Attribute);
945 }
946 close_scope(curr, ScopeType::Attributes);
947 match(']');
948 close_scope(curr, ScopeType::Subscript);
949 match(']');
950 /* Attributes can be chained. */
951 if (peek() == '[') {
952 attribute();
953 }
954 return;
955 case ParOpen:
957 break;
958 case Comma:
959 if (in_attribute) {
960 in_attribute = false;
961 close_scope(curr.prev(), ScopeType::Attribute);
962 }
963 next();
964 break;
965 case Word:
966 if (!in_attribute) {
967 open_scope(curr, ScopeType::Attribute);
968 in_attribute = true;
969 }
970 next();
971 break;
972 default:
973 error("Unexpected token \"" + to_str(peek()) + "\"");
974 return;
975 }
976 }
977 }
978
979 /* Example: `namespace A::B {}`. */
981 {
982 match(Namespace);
983 qualified_id();
984 open_scope(curr, ScopeType::Namespace);
985 match('{');
987 close_scope(curr, ScopeType::Namespace);
988 match('}');
989 }
990
991 /* Example: `A::B`. */
993 {
994 match(Word);
995 while (peek() == ':') {
996 match(':');
997 match(':');
998 match(Word);
999 }
1000 }
1001
1002 /* Example: `#define A\n`. */
1004 {
1005 const LexerBase &lex = parser;
1006 open_scope(curr, ScopeType::Preprocessor);
1007
1008 int tok_id = curr.index_;
1009 while (true) {
1010 const TokenType type = lex.types_[tok_id];
1011 if (type == EndOfFile) {
1012 tok_id--;
1013 break;
1014 }
1015 std::string_view tok_str = lex[tok_id].str_with_whitespace();
1016 size_t new_line = -1;
1017 while ((new_line = tok_str.find("\n", new_line + 1)) != std::string::npos) {
1018 if (new_line == 0 || tok_str[new_line - 1] != '\\') {
1019 break;
1020 }
1021 }
1022 if (new_line != std::string::npos) {
1023 break;
1024 }
1025 tok_id++;
1026 }
1027 curr = lex[tok_id];
1028 close_scope(curr, ScopeType::Preprocessor);
1029 next();
1030 }
1031
1032 private:
1033 void open_scope(Token tok, ScopeType type)
1034 {
1035 int index = parser.scope_types.size();
1036 parser.scope_types.emplace_back(type);
1037 parser.scope_ranges.emplace_back(tok.index_, 1);
1038
1039 ScopeLinks &links = parser.scope_links.emplace_back();
1040 links.parent_ = curr_node.index_;
1041 if (links.parent_ != -1) {
1042 ScopeLinks &parent_links = parser.scope_links[links.parent_];
1043 if (parent_links.child_first_ == -1) {
1044 parent_links.child_first_ = index;
1045 }
1046 links.prev_ = parent_links.child_last_;
1047 parent_links.child_last_ = index;
1048 }
1049 if (links.prev_ != -1) {
1050 parser.scope_links[links.prev_].next_ = index;
1051 }
1052
1054 }
1055
1056 void close_scope(Token tok, ScopeType type)
1057 {
1058 if (curr_node.type() == type) {
1059 IndexRange &range = parser.scope_ranges[curr_node.index_];
1060 /* On error/EOF unwind, `tok` is invalid: extend the scope to the last token. */
1061 const int64_t end = tok.is_valid() ? tok.index_ : parser.size();
1062 range.size = end - range.start + 1;
1064 }
1065 }
1066
1067 TokenType peek() const
1068 {
1069 return curr.type();
1070 }
1071
1072 void error(const std::string &str)
1073 {
1075 /* Set token to EndOfFile/Invalid. */
1076 curr = Token(parser);
1077 }
1078
1079 void match(char expected)
1080 {
1081 if (curr != TokenType(expected)) {
1082 error("Syntax Error: Expected token \"" + to_str(TokenType(expected)) + "\" but got \"" +
1083 to_str(curr.type()) + "\"");
1084 }
1085 next();
1086 }
1087
1088 void match(char expected, char expected2)
1089 {
1090 if (curr != TokenType(expected) && curr != TokenType(expected2)) {
1091 error("Syntax Error: Expected token \"" + to_str(TokenType(expected)) + "\" or \"" +
1092 to_str(TokenType(expected2)) + "\" but got \"" + to_str(curr.type()) + "\"");
1093 }
1094 next();
1095 }
1096
1097 void match(char expected, char expected2, char expected3)
1098 {
1099 if (curr != TokenType(expected) && curr != TokenType(expected2) &&
1100 curr != TokenType(expected3))
1101 {
1102 error("Syntax Error: Expected token \"" + to_str(TokenType(expected)) + "\" or \"" +
1103 to_str(TokenType(expected2)) + "\" or \"" + to_str(TokenType(expected3)) +
1104 "\" but got \"" + to_str(curr.type()) + "\"");
1105 }
1106 next();
1107 }
1108
1109 /* Only go to next token if matching an optional token. */
1110 bool match_if(char expected)
1111 {
1112 if (curr == TokenType(expected)) {
1113 next();
1114 return true;
1115 }
1116 return false;
1117 }
1118
1119 Token next()
1120 {
1121 return curr = curr.next();
1122 }
1123};
1124
1126{
1127 LexerBase &lex = *this;
1128
1130
1131 scope_types.clear();
1132 scope_ranges.clear();
1133 scope_links.clear();
1134
1135 size_t predicted_scope_count = lex.size() / 2;
1136 scope_types.reserve(predicted_scope_count);
1137 scope_ranges.reserve(predicted_scope_count);
1138 scope_links.reserve(predicted_scope_count);
1139
1140 ScopeParser p(*this, lex[0], err_handler);
1141 p.translation_unit();
1142
1144
1145 update_string_view();
1146}
1147
1148} // namespace blender::gpu::shader::parser
long long int int64_t
#define str(s)
#define EXPRESSION_TOKENS
Definition grammar.cc:19
TokenType
Definition types.hh:41
@ GThan
Definition types.hh:149
@ ParOpen
Definition types.hh:53
@ Default
Definition types.hh:129
@ While
Definition types.hh:92
@ EndOfFile
Definition types.hh:77
@ Private
Definition types.hh:123
@ LThan
Definition types.hh:150
@ For
Definition types.hh:91
@ BracketOpen
Definition types.hh:55
@ Return
Definition types.hh:115
@ Do
Definition types.hh:87
@ Hash
Definition types.hh:49
@ Static
Definition types.hh:105
@ Enum
Definition types.hh:106
@ Struct
Definition types.hh:117
@ Union
Definition types.hh:109
@ SquareOpen
Definition types.hh:57
@ Modulo
Definition types.hh:152
@ Space
Definition types.hh:47
@ Ampersand
Definition types.hh:50
@ Switch
Definition types.hh:95
@ ParClose
Definition types.hh:54
@ Case
Definition types.hh:96
@ Else
Definition types.hh:98
@ LEqual
Definition types.hh:104
@ Namespace
Definition types.hh:107
@ TemplateOpen
Definition types.hh:130
@ SquareClose
Definition types.hh:58
@ Plus
Definition types.hh:68
@ Break
Definition types.hh:83
@ Colon
Definition types.hh:65
@ Continue
Definition types.hh:110
@ TemplateClose
Definition types.hh:131
@ Using
Definition types.hh:121
@ Constexpr
Definition types.hh:86
@ NotEqual
Definition types.hh:89
@ String
Definition types.hh:154
@ If
Definition types.hh:97
@ Const
Definition types.hh:85
@ NewLine
Definition types.hh:46
@ Number
Definition types.hh:44
@ Equal
Definition types.hh:90
@ Divide
Definition types.hh:70
@ SemiColon
Definition types.hh:62
@ Inline
Definition types.hh:103
@ Assign
Definition types.hh:61
@ Minus
Definition types.hh:69
@ Word
Definition types.hh:43
@ This
Definition types.hh:120
@ Typename
Definition types.hh:84
@ Star
Definition types.hh:67
@ Public
Definition types.hh:124
@ GEqual
Definition types.hh:94
@ BracketClose
Definition types.hh:56
@ Template
Definition types.hh:119
@ Class
Definition types.hh:118
@ Comma
Definition types.hh:66
void report(Token tok, std::string_view message)
void build_scope_tree(ErrorHandler &err_handler)
Definition grammar.cc:1125
std::vector< ScopeLinks > scope_links
std::vector< IndexRange > scope_ranges
void condition(int arg_needed, ScopeType type)
Definition grammar.cc:611
ScopeParser(ParserBase &parser, Token tok, ErrorHandler &error_handler)
Definition grammar.cc:70
uint32_t size() const
Return the amount of token inside the buffer.
Definition lexit.hh:214
AlignedArrayPtr< TokenType > types_
Definition lexit.hh:125
Token prev(int i=1) const
Definition lexit.hh:376
int32_t index_
Definition lexit.hh:51
Token(const TokenBuffer *buf, int32_t index)
Definition lexit.hh:337
const TokenType & type() const
Definition lexit.hh:354
Token next(int i=1) const
Definition lexit.hh:372