Blender V5.3
symbol.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
8
9#include "processor.hh"
10#include "symbol_table.hh"
11#include "type_checker.hh"
12
13namespace bsl {
14
15using namespace blender::gpu::shader::parser;
16using namespace blender::gpu::shader::parser::ast;
17using namespace std;
18using Token = blender::gpu::shader::parser::Token;
19
21
24
28
30 Node node,
31 const std::string &prefix,
32 TemplateInst template_inst = {})
33 {
34 Node parent = node.parent();
35
36 if (parent.parent().type() == NodeType::TemplateDecl) {
37 parse_template_arguments(scope, parent.parent(), template_inst);
38 }
39
40 if (parent.type() == NodeType::FuncDecl) {
41 parse_function_return_type(scope, ast::FuncDecl(parent).return_type());
42 parse_function_arguments(scope, ast::FuncDecl(parent).arguments());
43 }
44 if (parent.type() == NodeType::ForLoop) {
45 parse_loop_arguments(scope, parent);
46 }
47
48 int offset = 0;
49 int bitfield_offset = 0;
50 SymbolVariable *bitfield_base = nullptr;
51
52 /* For enums, the value of the last declaration. */
53 ConstexprValue enum_last_val(-1);
54
55 if (node.type() == NodeType::FuncDecl || node.type() == NodeType::ClassDecl ||
56 node.type() == NodeType::LocalScope)
57 {
58 for (Node child = node.child_first(); child.is_valid(); child = child.next()) {
59 switch (child.type()) {
60 case NodeType::Preprocessor:
61 parse_preprocessor(scope, child);
62 break;
63 case NodeType::Namespace:
64 parse_namespace(scope, child, prefix);
65 break;
66 case NodeType::UsingStmt:
67 parse_using_stmt(scope, child);
68 break;
69 case NodeType::LocalScope:
70 parse_local_scope(scope, child, prefix);
71 break;
72 case NodeType::ClassDecl:
73 parse_class_decl(scope, child, parent, offset, prefix);
74 break;
75 case NodeType::EnumValue:
76 parse_enum_value(scope, child, parent, enum_last_val, prefix);
77 break;
78 case NodeType::FuncForwardDecl:
79 parse_func_forward_decl(scope, child);
80 break;
81 case NodeType::FuncDecl:
82 parse_func_decl(scope, child, prefix);
83 break;
84 case NodeType::VarDecl:
85 parse_var_decl(scope, child, offset, bitfield_offset, bitfield_base, prefix);
86 break;
87 case NodeType::StructuredBinding:
88 parse_structured_binding(scope, child);
89 break;
90 case NodeType::TemplateDecl:
91 parse_template_decl(scope, child);
92 break;
93 case NodeType::TemplateInst:
94 parse_template_inst(scope, child, prefix);
95 break;
96 case NodeType::TemplateSpec:
97 parse_template_spec(scope, child, prefix);
98 break;
99 case NodeType::SwitchStmt:
100 /* Special case for switch statements which are 3 level deep. */
101 for (SwitchCase stmt : child.children_of_type<SwitchCase>()) {
102 for (LocalScope local : stmt.children_of_type<LocalScope>()) {
103 parse_local_scope(scope, local, prefix);
104 }
105 }
106 break;
107 case NodeType::ForLoop:
108 case NodeType::DoWhileLoop:
109 case NodeType::WhileLoop:
110 case NodeType::IfStmt:
111 case NodeType::ElseIfStmt:
112 case NodeType::ElseStmt:
113 case NodeType::ReturnStmt:
114 /* Convert local scopes that are nested one level deeper (eg. if, etc...). */
115 for (LocalScope local : child.children_of_type<LocalScope>()) {
116 parse_local_scope(scope, local, prefix);
117 }
118 break;
119 case NodeType::PipelineDecl:
120 parse_pipeline_decl(scope, child, prefix);
121 break;
122 default:
123 break;
124 }
125 }
126 }
127 }
128
129 void parse_local_scope(SymbolScope &scope, LocalScope local_node, const std::string &prefix)
130 {
131 SymbolScope *sym = table.scp_arena.alloc(&scope, local_node);
132 scope.scopes.emplace(sym->identifier, sym);
133
134 parse_scope(*sym, local_node, prefix + sym->identifier + ns_sep);
135 }
136
137 /* Create declaration for each template argument so name lookup will work with these. */
139 {
140 TemplateParamList params = inst.parameters();
141 Expr param = params.child_first();
142
143 assert(scope.parent != nullptr);
144 /* Search for types in the parent namespace, where the instantiation resides. */
145 SymbolScope &inst_scope = *scope.parent;
146
147 for (TemplateArg arg : decl.arguments().children_range()) {
148 assert(arg.is_valid());
149 if (arg.front() == Typename) {
150 IdQualified arg_id = arg.type();
151 string id(arg_id.str());
152 if (param.child_count() != 1 || param.child_first().type() != NodeType::LocalVar) {
154 return;
155 }
156 IdQualified type_id(LocalVar(param.child_first()).identifier());
157 SymbolClass *resolved = inst_scope.lookup_class(table, type_id).unwrap(this);
158 /* IMPORTANT: Instantiate at argument declaration. Allow correct lookup. */
159 scope.classes.emplace(id, resolved, arg.identifier().front());
160 scope.scopes.emplace(id, resolved);
161 }
162 else {
163 IdQualified type = arg.type();
164 string id(arg.identifier().str());
165 SymbolClass *cls = inst_scope.lookup_class(table, type).unwrap(this);
166 SymbolVariable *var = table.var_arena.alloc(&scope, cls, arg.identifier().front(), id);
167 auto val = table.expr_type_analysis(scope, param.child_first()).unwrap(this);
168 if (!val.is_constexpr()) {
170 return;
171 }
172 var->is_constexpr = true;
173 var->value = val.value;
174 if (scope.variable_emplace(id, var)) {
175 error(var->loc.tok, Diag::Redefinition, id);
176 }
177 }
178 param = param.next();
179 }
180 }
181
183 {
184 SymbolFunction *fn_sym = static_cast<SymbolFunction *>(&scope);
185 fn_sym->return_type = fn_sym->lookup_class(table, return_type.identifier()).unwrap(this);
186
187 if (fn_sym->is_entry_point() && fn_sym->return_type != table.void_cls) {
188 error(return_type, Diag::EntryPointVoidReturn);
189 }
190 }
191
192 /* Create declaration for each function argument so name lookup will work with these.
193 * Also create declaration for `this_`. */
195 {
196 SymbolFunction *fn_sym = static_cast<SymbolFunction *>(&scope);
197 const bool is_entry_point = fn_sym->is_entry_point();
198 const auto entry_point_type = fn_sym->entry_point_type;
199
200 for (FuncArg arg : arg_list.children_of_type<FuncArg>()) {
201 auto attr = resource_type_from_attributes(arg.attributes()).unwrap(this);
202
203 SymbolClass *type = scope.lookup_class(table, arg.type().identifier()).unwrap(this);
204 if (type->is_error) {
205 error(
206 arg.type().identifier(), Diag::UnknownTypeNameWithArg, arg.type().identifier().str());
207 }
208 SymbolVariable *var = table.var_arena.alloc(&scope, type, arg.declarator(), table);
209 if (scope.variable_emplace(var)) {
211 }
212 /* Register argument type for argument resolution. */
213 fn_sym->add_argument(arg.type().is_const(), type, arg.declarator().initial_value().expr());
214
215 switch (attr.res_type) {
217 var->identifier = "gpu_BaseInstance";
218 break;
220 var->identifier = "gl_FrontFacing";
221 break;
223 var->identifier = "gl_InstanceID";
224 break;
226 var->identifier = "gl_PointSize";
227 break;
229 var->identifier = "gl_ClipDistance";
230 break;
232 var->identifier = "gl_Layer";
233 break;
235 var->identifier = "gpu_InstanceIndex";
236 break;
238 var->identifier = "gpu_ViewportIndex";
239 break;
241 var->identifier = "gl_VertexID";
242 break;
244 var->identifier = "gl_Position";
245 break;
247 var->identifier = "gl_FragDepth";
248 break;
250 var->identifier = "gl_FragCoord";
251 break;
253 var->identifier = "gpu_BaryCoord";
254 break;
256 var->identifier = "gl_FragStencilRefARB";
257 break;
259 var->identifier = "gl_PointCoord";
260 break;
262 var->identifier = "gl_LocalInvocationID";
263 break;
265 var->identifier = "gl_LocalInvocationIndex";
266 break;
268 var->identifier = "gl_GlobalInvocationID";
269 break;
271 var->identifier = "gl_WorkGroupID";
272 break;
274 var->identifier = "gl_NumWorkGroups";
275 break;
278 error(arg.type(),
281 to_str(type->srt_type));
282 }
283 break;
285 switch (entry_point_type) {
287 error(arg.type(), Diag::AttributeNotAllowedInComp, "out");
288 break;
291 error(arg.type().identifier(),
294 to_str(type->srt_type));
295 }
296 break;
299 error(arg.type().identifier(),
302 to_str(type->srt_type));
303 }
304 break;
306 error(arg.type().identifier(), Diag::AttributeOnlyEntryPointsCanUseOut);
307 break;
308 }
309 break;
310 case ResourceType::IN:
311 switch (entry_point_type) {
313 error(arg.type().identifier(), Diag::AttributeNotAllowedInComp, "in");
314 break;
318 {
319 error(arg.type().identifier(),
323 to_str(type->srt_type));
324 }
325 break;
328 error(arg.type().identifier(),
331 to_str(type->srt_type));
332 }
333 break;
335 error(arg.type().identifier(), Diag::AttributeOnlyEntryPointsCanUseIn);
336 break;
337 }
338 break;
339 default:
340 break;
341 }
342
343 if (is_entry_point && attr.srt_type != ResourceTableType::ENTRY_POINT &&
344 attr.res_type != ResourceType::RESOURCE_TABLE)
345 {
346 error(arg, Diag::ExpectedEntryPointResourceAttribute, to_str(attr.srt_type));
347 }
348 else if (!is_entry_point && attr.srt_type != ResourceTableType::NONE &&
349 attr.res_type != ResourceType::RESOURCE_TABLE)
350 {
352 }
353
354 if (!is_entry_point && attr.condition.is_valid()) {
356 }
357
358 if (attr.condition.is_valid()) {
359 var->condition = attr.condition;
360 }
361 }
362
363 if (scope.parent != nullptr) {
364 /* Add `this_` to the var declarations. */
365 auto &fns = scope.parent->functions;
366 if (auto it = fns.find(scope.identifier); it != fns.end()) {
367 SymbolFunction *fn = it->second.second;
368 if (fn->fn_type == SymbolFunction::MEMBER) {
369 SymbolVariable *var = table.var_arena.alloc(
370 &scope, fn->parent_class(), arg_list.front(), "this_");
371 scope.variable_emplace(var);
372 }
373 }
374 }
375 }
376
377 /* Parse declarators inside for loop conditions. */
379 {
380 for (VarDecl var : loop.condition().descendants_of_type<VarDecl>()) {
381 SymbolClass *type = scope.lookup_class(table, var.type().identifier()).unwrap(this);
382 for (Declarator decl : var.children_of_type<Declarator>()) {
383 SymbolVariable *sym = table.var_arena.alloc(&scope, type, decl, table);
384 sym->type = type;
385 if (scope.variable_emplace(sym)) {
386 NOTE(scope.variables.find(sym->identifier)->second.first.tok,
388 sym->identifier);
389 error(sym->loc.tok, Diag::Redefinition, sym->identifier);
390 }
391 }
392 }
393 }
394
395 void parse_preprocessor(SymbolScope & /*scope*/, Preprocessor directive)
396 {
397 /* Keep track of all defines with value to make sure to not hit an undefined symbol error. */
398 Token type = directive.front().next();
399 if (type.str() == "define") {
400 Token name = type.next();
401 if (name == directive.back()) {
402 /* Doesn't define anything. */
403 return;
404 }
405 Token value = name.next();
406 bool is_func = false;
407 if (value == '(' && name.str_with_whitespace().back() != ' ') {
408 /* This is a functional macro. */
409 is_func = true;
410 value = value.next(')');
411 if (value == directive.back()) {
412 /* Doesn't define anything. */
413 return;
414 }
415 value = value.next();
416 }
417
418 SymbolScope *root = table.root;
419 /* Macro is not empty and defines something. Assume it is a int constant. */
420 if (is_func) {
422 root, name, table.int_cls, string(name.str()), SymbolFunction::GLOBAL);
423
424 root->functions.emplace(fn);
425 }
426 else {
427 SymbolClass *type = table.int_cls;
428 if (directive.back() == value) {
429 if (value == Number ||
430 (value == Word && (value.str() == "true" || value.str() == "false")))
431 {
432 /* Value is a single token try to guess its type. */
433 type = table.get_literal_type(value.str());
434 }
435 else if (value == Word) {
436 /* Try to match type. Workaround for legacy type alias. */
437 SymbolClass *cls = nullptr;
438 if (value.str() == "int") {
439 cls = table.int_cls;
440 }
441 else if (value.str() == "uint") {
442 cls = table.uint_cls;
443 }
444 else if (value.str() == "float") {
445 cls = table.float_cls;
446 }
447 else if (value.str() == "bool") {
448 cls = table.bool_cls;
449 }
450 if (cls) {
451 /* TODO: Make a warning/error if this just defines a type alias. */
452 root->classes.emplace(string(name.str()), cls);
453 }
454 }
455 }
456 SymbolVariable *var = table.var_arena.alloc(root, type, name, string(name.str()));
457 var->is_macro = true;
458 root->variable_emplace(var);
459 }
460 /* TODO: Make a warning/error if this just defines a constant in global space without #if
461 * directives. */
462 }
463 }
464
465 void parse_namespace(SymbolScope &scope, ast::Namespace decl, string ns_prefix)
466 {
467 IdQualified ns = decl.identifier();
468 /* Walk nested identifier */
469 SymbolScope *ns_scope = &scope;
470 for (Id id : ns.children_of_type<Id>()) {
471 /* In case the namespace doesn't exist, create it. */
472 SymbolScope *sym = table.scp_arena.alloc(ns_scope, id, SymbolScope::NAMESPACE);
473 ns_scope = ns_scope->scopes.try_emplace(sym->identifier, sym).first->second;
474 ns_prefix = ns_prefix + sym->identifier + ns_sep;
475 }
476 parse_scope(*ns_scope, decl.body(), ns_prefix);
477 }
478
480 {
481 if (stmt.is_namespace()) {
483 }
484 else {
485 IdQualified aliased(stmt.aliased());
486 IdQualified name(stmt.identifier());
487 string identifier(name.name().str());
488 SymbolFunction *fun = scope.lookup_function(table, aliased).unwrap(this);
489 if (!fun->is_error) {
490 scope.functions.emplace(identifier, fun, stmt.identifier().front());
491 return;
492 }
493 SymbolClass *type = scope.lookup_class(table, aliased).unwrap(this);
494 if (type->is_error && fun->is_error) {
496 return;
497 }
498 if (type) {
499 scope.classes.emplace(identifier, type, stmt.identifier().front());
500 return;
501 }
502 }
503 }
504
506 EnumValue val,
507 ClassDecl cls,
508 ConstexprValue &enum_last_val,
509 const string &prefix)
510 {
511 SymbolClass *type = scope.lookup_class(table, cls.parent_class()).unwrap(this);
512
513 SymbolVariable *sym = table.var_arena.alloc(&scope, type, val);
514 sym->is_static = true;
515 sym->is_constexpr = true;
516 /* Resolve its value. */
517 if (AssignStmt assign = val.value(); assign.is_valid()) {
518 if (auto result = initialize_assign(scope, type, assign); result.is_constexpr()) {
519 sym->value = result.value;
520 }
521 else {
523 }
524 }
525 else {
526 /* Note: Add unsigned to not change the type of the ConstexprValue. */
527 sym->value = enum_last_val + ConstexprValue(1u);
528 }
529
530 if (scope.variable_emplace(sym)) {
531 NOTE(scope.variables.find(sym->identifier)->second.first.tok,
533 sym->identifier);
534 error(sym->loc.tok, Diag::Redefinition, sym->identifier);
535 }
536 /* Save value for the next member. */
537 enum_last_val = sym->value;
538 /* Alias to the parent namespace for non-anonymous, non-class enum. */
539 if (!cls.is_enum_class()) {
540 if (scope.parent->variable_emplace(sym)) {
541 NOTE(scope.variables.find(sym->identifier)->second.first.tok,
543 sym->identifier);
544 error(sym->loc.tok, Diag::Redefinition, sym->identifier);
545 }
546 }
547 /* TODO(fclem): Not enabling this for non-class-enum to stay compatible with the older
548 * compiler. */
549 if (cls.is_enum_class()) {
550 /* Set resolved identifier. */
551 sym->identifier = prefix + sym->identifier;
552 }
553 }
554
557 ClassDecl parent_class,
558 int &offset,
559 const std::string &prefix,
560 const std::string &suffix = "",
561 optional<SourceLocation> poi = nullopt,
562 TemplateInst temp = {},
563 SymbolClassTemplate *cls_template = nullptr)
564 {
565 SymbolClass *cls = table.cls_arena.alloc(&scope, decl, suffix);
566 if (!scope.classes.emplace(cls).second) {
568 return table.err_cls;
569 }
570 if (poi) {
571 cls->poi = poi;
572 }
573 else if (scope.poi) {
574 /* Classes inherit the point of instantiation of their parent scope. */
575 cls->poi = scope.poi;
576 }
577
578 scope.scopes.emplace(cls->identifier, cls);
579
580 if (!cls->is_enum && cls->is_anonymous &&
581 anonymous_scope_prefix(cls).non_anonymous_parent == nullptr)
582 {
584 return table.err_cls;
585 }
586
587 if (cls_template) {
588 /* Add the template definition early so it can be queried during instantiation. */
589 cls_template->instances.emplace(suffix, cls);
590 /* Create an alias to the unspecified class name (no template arg): e.g. `A` -> `A<T>`. */
591 string alias_name = cls->identifier.substr(0, cls->identifier.size() - suffix.size());
592 cls->classes.emplace(alias_name, cls);
593 }
594
595 parse_scope(*cls, decl.body(), prefix + cls->identifier + ns_sep, temp);
596
597 /* Set identifier to resolved symbol. */
598 cls->identifier = prefix + cls->identifier;
599
600 if (cls->is_enum) {
601 SymbolClass *underlying_type = scope.lookup_class(table, decl.parent_class()).unwrap(this);
602 cls->size = underlying_type->size;
603 cls->align = underlying_type->align;
604 cls->builtin_class = underlying_type->builtin_class;
605 cls->is_std140_compatible = cls->size == 4;
606 cls->is_std430_compatible = cls->size == 4;
607
608 /* Create scalar constructor. */
609 SymbolFunction *ctor = table.fun_arena.alloc(
610 &scope, decl.front(), cls, cls->original, SymbolFunction::Type::GLOBAL);
611 ctor->add_argument(true, cls);
612 ctor->allow_vector_promotion = true;
613 scope.function_emplace(ctor, true);
614 ctor->identifier = prefix + ctor->identifier;
615 }
616 else {
618
619 if (cls->is_anonymous) {
620 /* Instantiate into parent class as member. */
621 SymbolVariable *var = table.var_arena.alloc(
622 &scope, cls, decl.front(), cls->original + ns_sep);
623 if (scope.variable_emplace(cls->original, var)) {
624 error(var->loc.tok, Diag::Redefinition, cls->original);
625 }
626
627 var->type = cls;
628 var->set_offset(parent_class.is_union(), offset);
629 }
630 }
631 return cls;
632 }
633
635 {
636 /* Treat the forward declaration as a standard function declaration to parse its signature. */
637 SymbolFunction *fn = table.fun_arena.alloc(&scope, table.err_cls, decl);
638 /* Mark as forward declared so it doesn't conflict with or replace the actual definition. */
639 fn->is_defined = false;
640
641 if (scope.poi) {
642 /* Functions inherit the point of instantiation of their class. */
643 fn->poi = scope.poi;
644 }
645 /* Emplace the function into the scope so it becomes available during function lookups. */
646 bool is_overload = scope.function_emplace(fn);
647 if (is_overload && fn->is_entry_point()) {
648 error(decl.identifier(), Diag::RedefinitionOfEntryPointFunction, decl.identifier().str());
649 }
650 /* Parse the return type and arguments to correctly populate matching criteria. */
651 parse_function_return_type(*fn, decl.return_type());
652 parse_function_arguments(*fn, decl.arguments());
653 /* Record as function prototype. */
654 scope.function_prototypes.emplace_back(decl, fn);
655 }
656
658 FuncDecl func,
659 const std::string &prefix,
660 const std::string &suffix = "",
661 optional<SourceLocation> poi = nullopt,
662 TemplateInst temp = {})
663 {
664 /* Set return type to error type since we need to parse it after template argument
665 * instantiation. */
666 SymbolFunction *fn = nullptr;
667 if (auto [fdecl, fn_ptr] = scope.lookup_function_forward_decl(func); fdecl.is_valid()) {
668 fn = fn_ptr;
669 /* Modify symbol location if it is forward declared. */
670 fn->loc = fdecl.front();
671 fn->is_defined = true;
672 fn->decl = func;
673 /* Use attributes of the definition. */
674 fn->is_inline = func.attributes().contains_attr("force_inline");
675 /* Note: We discard the argument parsed by the forward declaration.
676 * They are parsed again by `parse_scope`. */
677 fn->variables.clear();
678 fn->arg_const.clear();
679 fn->arg_types.clear();
680 fn->arg_defaults.clear();
681 }
682 else {
683 fn = table.fun_arena.alloc(&scope, table.err_cls, func, suffix);
684
685 bool is_overload = scope.function_emplace(fn);
686 if (is_overload && fn->is_entry_point()) {
688 }
689 }
690
691 if (poi) {
692 fn->poi = poi;
693 }
694 else if (scope.poi) {
695 /* Functions inherit the point of instantiation of their class. */
696 fn->poi = scope.poi;
697 }
698
699 parse_scope(*fn, func.body(), prefix + fn->identifier + ns_sep, temp);
700
701 /* Set resolved identifier. */
702 switch (fn->fn_type) {
705 fn->identifier = prefix + fn->identifier;
706 break;
708 /* Member function use overload resolution. */
709 fn->identifier = "_" + fn->identifier;
710 break;
711 }
712
713 if (fn->is_inline && fn->return_type != table.void_cls) {
714 /* Create return variable instance. To be used during inlining. */
715 SymbolVariable *var = table.var_arena.alloc(
719 }
720 }
721
722 return fn;
723 }
724
726 {
727 /* Do not parse. Only keep the symbol definition. The instantiation will do the parsing. */
728 if (decl.is_function()) {
729 FuncDecl fn_decl(decl.decl());
730 /* Set return type to error type since we need to parse it after template argument
731 * instantiation. */
732 SymbolFunction *fn = table.fun_arena.alloc(&scope, table.err_cls, fn_decl);
733 fn->is_complete = false;
734 fn = scope.functions.emplace(fn).first;
735 if (fn->template_data) {
737 }
738 else {
739 fn->template_data = table.tmp_fun_arena.alloc(decl);
740 }
741 }
742 else {
743 SymbolClass *cls = table.cls_arena.alloc(&scope, decl.decl());
745 if (!scope.classes.emplace(cls).second) {
746 ClassDecl cls_decl(decl.decl());
747 error(cls_decl.identifier(), Diag::Redefinition, cls_decl.identifier().str());
748 }
749 }
750 }
751
752 template<typename DeclAst, typename SymbolT>
754 DeclAst &decl,
755 const SymbolT &sym)
756 {
757 if (sym.template_data == nullptr) {
759 return {};
760 }
761 TemplateDecl temp_decl = sym.template_data->decl;
762 if (temp_decl.arguments().child_count() != temp_params.child_count()) {
764 return {};
765 }
766 return temp_decl;
767 }
768
769 void parse_template_inst(SymbolScope &scope, TemplateInst temp, const std::string &prefix)
770 {
771 TemplateParamList tmp_params = temp.parameters();
772
773 if (temp.is_function()) {
774 const FuncForwardDecl decl = temp.decl();
775 const IdQualified id = decl.identifier();
776 const SourceLocation poi = id.front();
778
779 if (TemplateDecl temp_decl = check_template_instance(tmp_params, decl, *fn);
780 temp_decl.is_valid())
781 {
782 auto mangled =
783 table.mangle_identifier(temp_decl.arguments(), tmp_params, scope).unwrap(this);
784
785 SymbolScope *parent = &scope;
786 if (fn->fn_type == SymbolFunction::MEMBER) {
787 parent = nullptr;
788 Id start = id.namespace_start();
790 if (auto *parent_cls = scope.lookup_class(table, start, last).unwrap(this); parent_cls) {
791 if (parent_cls->template_data && !last.template_params().is_valid()) {
793 }
794 parent = parent_cls;
795 }
796
797 if (parent == nullptr) {
799 return;
800 }
801 }
802 else {
803 parent = fn->parent;
804 }
805
806 string full_id = string(id.name().str()) + "<" + mangled.str_debug.substr(2) + ">";
809 *parent, temp_decl.decl(), prefix, mangled.str, poi, temp);
810 fn_inst->is_specialization = true;
811 fn_inst->template_data = fn->template_data;
812 /* For compatibility with previous version of BSL, do not mangle function names with
813 * arguments if ADL is possible. */
814 if (fn->template_data->is_adl_possible()) {
815 fn_inst->identifier = fn_inst->identifier.substr(
816 0, fn_inst->identifier.size() - mangled.str.size());
817 }
818 fn->template_data->instances.emplace(mangled.str, fn_inst);
819 fn->add_overload(fn_inst);
820 }
821 }
822 else {
823 const ClassDecl decl = temp.decl();
824 const IdQualified id = decl.identifier();
825 const SourceLocation poi = id.front();
826 auto *cls = scope.lookup_class_base(table, id);
827
828 if (TemplateDecl temp_decl = check_template_instance(tmp_params, decl, *cls);
829 temp_decl.is_valid())
830 {
831 auto mangled =
832 table.mangle_identifier(temp_decl.arguments(), tmp_params, scope).unwrap(this);
833 string full_id = string(id.name().str()) + "<" + mangled.str_debug.substr(2) + ">";
835 int unused_offset = 0;
836 parse_class_decl(scope,
837 temp_decl.decl(),
838 Node{},
839 unused_offset,
840 prefix,
841 mangled.str,
842 poi,
843 temp,
844 cls->template_data);
845 }
846 }
847 }
848
849 void parse_template_spec(SymbolScope &scope, TemplateSpec temp, const std::string &prefix)
850 {
851 TemplateParamList temp_params = temp.parameters();
852 /* Instantiate the whole symbol into the current namespace. */
853 if (temp.is_function()) {
854 const FuncDecl decl = temp.decl();
855 const IdQualified id = decl.identifier();
856 const SourceLocation poi = id.front();
857 auto *fn = scope.lookup_function_base(table, decl.identifier());
858
859 if (TemplateDecl temp_decl = check_template_instance(temp_params, decl, *fn);
860 temp_decl.is_valid())
861 {
862 auto mangled =
863 table.mangle_identifier(temp_decl.arguments(), temp_params, scope).unwrap(this);
864 string full_id = string(decl.identifier().str()) + "<" + mangled.str_debug.substr(2) + ">";
866 SymbolFunction *spec = parse_func_decl(scope, decl, prefix, mangled.str, poi);
867 spec->is_specialization = true;
868 spec->template_data = fn->template_data;
869 /* For compatibility with previous version of BSL, do not mangle function names with
870 * arguments if ADL is possible. */
871 if (fn->template_data->is_adl_possible()) {
872 spec->identifier = spec->identifier.substr(0,
873 spec->identifier.size() - mangled.str.size());
874 }
875 fn->template_data->instances.emplace(mangled.str, spec);
876 fn->add_overload(spec);
877 }
878 }
879 else {
880 const ClassDecl decl = temp.decl();
881 const IdQualified id = decl.identifier();
882 const SourceLocation poi = id.front();
883 auto *cls = scope.lookup_class_base(table, decl.identifier());
884
885 if (TemplateDecl temp_decl = check_template_instance(temp_params, decl, *cls);
886 temp_decl.is_valid())
887 {
888 auto mangled =
889 table.mangle_identifier(temp_decl.arguments(), temp_params, scope).unwrap(this);
890 string full_id = string(decl.identifier().str()) + "<" + mangled.str_debug.substr(2) + ">";
892 int unused_offset = 0;
894 scope, decl, Node{}, unused_offset, prefix, mangled.str, poi);
895 cls->template_data->instances.emplace(mangled.str, spec);
896 }
897 }
898 }
899
900 void parse_pipeline_decl(SymbolScope &scope, PipelineDecl decl, const std::string &prefix)
901 {
902 SymbolVariable *sym = table.var_arena.alloc(
903 &scope, table.void_cls, decl.front(), string(decl.identifier().str()));
904 sym->is_static = true;
905 if (scope.variable_emplace(sym)) {
906 NOTE(scope.variables.find(sym->identifier)->second.first.tok,
908 sym->identifier);
909 error(decl, Diag::Redefinition, sym->identifier);
910 }
911 /* Set resolved identifier. */
912 sym->identifier = prefix + sym->identifier;
913 }
914
916 {
917 AssignStmt assign = decl.assign();
918 Expr expr = assign.expr();
919 if (!expr.is_valid()) {
921 return;
922 }
923
924 SymbolClass *cls = table.expr_type_analysis(scope, expr.child_first()).unwrap(this).type;
925 if (cls->is_error) {
927 return;
928 }
929
930 Id id = decl.child_first();
931
932 /* Create temp variable to write to. */
933 SymbolVariable *tmp = table.var_arena.alloc(&scope, cls, decl.front(), decl.tmp_id());
934 if (scope.variable_emplace(tmp)) {
935 NOTE(scope.variables.find(tmp->identifier)->second.first.tok,
937 tmp->identifier);
939 }
940
942 if (!id.is_valid()) {
944 return;
945 }
946 /* Make copy of the variable in local scope. */
947 SymbolVariable *sym = table.var_arena.alloc(*var);
948 sym->identifier = id.str();
949 sym->parent = &scope;
950 if (scope.variable_emplace(sym)) {
951 NOTE(scope.variables.find(sym->identifier)->second.first.tok,
953 sym->identifier);
954 error(decl, Diag::Redefinition, sym->identifier);
955 }
956 /* Resolve to the tmp variable member. */
957 sym->identifier = tmp->identifier + '.' + var->identifier;
958
959 id = id.next();
960 }
961 if (id.is_valid()) {
963 return;
964 }
965 }
966
968 VarDecl var,
969 int &offset,
970 int &bitfield_offset,
971 SymbolVariable *&bitfield_base,
972 const std::string &prefix)
973 {
974 IdQualified type_id = var.type().identifier();
975 string_view type_id_str = type_id.str();
976
977 /* Assumes C++ compilation already checked that all declarator uses the same type.
978 * Deduce type using only the first declarator. */
980
981 SymbolClass *type = ((type_id_str == "auto") ? table.resolve_auto_type(scope, first_decl) :
982 scope.lookup_class(table, type_id))
983 .unwrap(this);
984
985 if (type->is_error) {
986 error(var, Diag::UnknownTypeNameWithArg, type_id_str);
987 return;
988 }
989
990 SymbolClass *cls = scope.as_class();
991
992 auto attr = resource_type_from_attributes(var.attributes()).unwrap(this);
993
994 if (attr.res_type == ResourceType::UNIFORM_BUF && !type->is_std140_compatible) {
996 type->ensure_size_and_align(this);
997 }
998 else if (attr.res_type == ResourceType::STORAGE_BUF && !type->is_std430_compatible) {
1000 type->ensure_size_and_align(this, true);
1001 }
1002
1003 if (cls) {
1004 if (cls->srt_type == ResourceTableType::NONE && attr.srt_type != ResourceTableType::NONE) {
1005 if (cls->is_anonymous) {
1007 }
1008 if (attr.srt_type != ResourceTableType::VERTEX_IN &&
1009 attr.srt_type != ResourceTableType::VERTEX_OUT &&
1010 attr.srt_type != ResourceTableType::FRAGMENT_IN &&
1011 attr.srt_type != ResourceTableType::FRAGMENT_OUT &&
1012 attr.srt_type != ResourceTableType::RESOURCE_TABLE)
1013 {
1015 }
1016 cls->srt_type = attr.srt_type;
1017 }
1018 else if (cls->srt_type != attr.srt_type) {
1019 error(var,
1021 to_str(cls->srt_type),
1022 to_str(attr.srt_type));
1023 }
1024 }
1025 else if (attr.res_type == ResourceType::RESOURCE_TABLE) {
1026 /* Currently supported as noop for legacy resource table reference getter. */
1027 }
1028 else if (attr.res_type != ResourceType::NONE) {
1030 }
1031
1032 if (attr.condition.is_valid()) {
1033 if (attr.res_type == ResourceType::NONE) {
1035 }
1036 else if (attr.res_type == ResourceType::SHARED) {
1037 error(var, Diag::ConditionAttributeUnsupported, to_str(attr.res_type));
1038 }
1039 }
1040
1041 const bool is_srt_local_ref = type->is_srt() && cls == nullptr;
1042
1043 string anon_prefix;
1044 SymbolScope *named_parent = cls;
1045 if (cls && cls->is_anonymous) {
1046 auto prefix = anonymous_scope_prefix(cls);
1047 anon_prefix = prefix.prefix;
1048 named_parent = prefix.non_anonymous_parent;
1049 }
1050
1051 const bool is_ref = var.is_reference();
1053 if (is_ref != decl.is_reference()) {
1055 continue;
1056 }
1057 ast::BitField bitfield = decl.bitfield();
1058
1059 SymbolVariable *sym = table.var_arena.alloc(&scope, type, decl, table);
1060 sym->res_type = attr.res_type;
1061 sym->is_static |= attr.res_type != ResourceType::NONE;
1062 if (scope.variable_emplace(sym)) {
1063 NOTE(scope.variables.find(sym->identifier)->second.first.tok,
1065 sym->identifier);
1066 error(sym->loc.tok, Diag::Redefinition, sym->identifier);
1067 }
1068
1069 if (is_srt_local_ref && !is_ref) {
1071 }
1072
1073 /* Capacity attribute. */
1074 if (attr.capacity.is_valid()) {
1075 if (sym->array_dimensions != 1) {
1077 }
1078 /* TODO(fclem): Check that this references a single reachable compilation constant. */
1079 sym->capacity_value = attr.capacity;
1080 }
1081
1082 if (attr.condition.is_valid()) {
1083 sym->condition = attr.condition;
1084 }
1085
1086 /* Local References. */
1087 if (is_ref && cls == nullptr) {
1088 AssignStmt stmt = decl.initial_value();
1089 if (stmt.is_valid() && stmt.expr().is_valid()) {
1090 /* Run analysis to check if we bind a temporary. */
1091 /* Run const analysis to check if we bind a const expr. */
1093 table.expr_type_analysis(scope, stmt.expr().child_first(), true).unwrap(this);
1094
1095 if (result.is_temporary && !result.type->is_srt()) {
1097 }
1098 else if (type != result.type) {
1099 error(decl, Diag::ReferenceTypeMismatch, type->identifier, result.type->identifier);
1100 }
1101
1102 sym->reference_value = stmt.expr();
1103 sym->array_dimensions = result.array_dim;
1104 }
1105 else {
1107 }
1108 }
1109
1110 if (cls) {
1111 if (sym->is_bitfield) {
1112 if ((sym->type != table.int_cls && sym->type != table.uint_cls) ||
1113 sym->array_dimensions != 0)
1114 {
1115 error(decl, Diag::BitFieldNotIntegral, sym->type->original);
1116 }
1117 const Node width = bitfield.expr().child_first();
1118 if (!width.is_valid()) {
1120 continue;
1121 }
1122 ExpressionResult result = table.expr_type_analysis(scope, width).unwrap(this);
1123 if (!result.is_constexpr()) {
1125 }
1126 int len = result.value.comp_as<int>(0);
1127 if (len > 32) {
1129 }
1130 else if (len == 0) {
1132 }
1133 else if (len < 0) {
1135 }
1136 else {
1137 if (bitfield_base && bitfield_offset + len <= 32 && !cls->is_union) {
1138 /* Fits in existing bitfield. */
1139 sym->bit_length = len;
1140 sym->bit_offset = bitfield_offset;
1141 bitfield_offset += len;
1142 }
1143 else {
1144 /* Doesn't fit in existing bitfield or first in bitfield. Start a new bitfield. */
1145 sym->bit_length = len;
1146 sym->bit_offset = 0;
1147 bitfield_offset = len;
1148 bitfield_base = sym;
1149 }
1150 }
1151 }
1152 else {
1153 /* Terminate any in progress bitfield. */
1154 bitfield_base = nullptr;
1155 }
1156
1157 if (sym->bit_offset != 0 && bitfield_base) {
1158 /* Bitfield members copy their offset from the first bitfield member. */
1159 sym->offset = bitfield_base->offset;
1160 }
1161 else {
1162 sym->set_offset(cls->is_union, offset);
1163 }
1164
1165 /* Alias to the first, non-anonymous parent. */
1166 if (cls->is_anonymous) {
1167 if (named_parent->variable_emplace(sym)) {
1168 error(sym->loc.tok, Diag::Redefinition, sym->identifier);
1169 }
1170 }
1171
1172 if (bitfield_base) {
1173 /* Alias to the first member of the bitfield, so that it gets the same accessor
1174 * decoration below. */
1175 sym->identifier = bitfield_base->original;
1176 }
1177
1178 if (cls->is_anonymous || cls->is_union) {
1179 /* Append accessor function. */
1180 string suffix = cls->is_union ? "()" : "";
1181 string prefix = cls->is_union ? "_" : "";
1182 /* Rename to the resolved symbol. */
1183 sym->identifier = anon_prefix + prefix + sym->identifier + suffix;
1184
1185 if (sym->is_static) {
1186 error(var,
1188 decl.identifier().str(),
1189 (cls->is_anonymous ? "anonymous" : "local"),
1190 (cls->is_union ? "union" : "struct"));
1191 }
1192 }
1193
1194 if (bitfield_base) {
1195 /* Note: we mutate assignments into bitfieldInsert in a second pass. */
1196 sym->identifier += ".bitfieldExtract(" + to_string(sym->bit_offset) + ", " +
1197 to_string(sym->bit_length) + ")";
1198 }
1199 }
1200
1201 if (sym->is_static) {
1202 if (attr.res_type == ResourceType::VERT_ATTR_OUT ||
1203 attr.res_type == ResourceType::FRAG_OUT)
1204 {
1205 sym->identifier = prefix + sym->identifier;
1206 }
1207 }
1208
1209 if (sym->is_constexpr) {
1210 if (sym->array_dimensions > 0) {
1212 }
1213
1214 ExpressionResult result = initialize_constexpr(scope, sym->type, decl);
1215 /* For now demote constexpr if we couldn't deduce its value. */
1216 if (result.is_constexpr()) {
1217 sym->value = result.value;
1218 }
1219
1220 if (!sym->is_static) {
1221 if (sym->parent_class()) {
1223 }
1224 else if (sym->parent->parent_function()) {
1225 /* Only case where its fine. */
1226 }
1227 else {
1228 /* Could be allowed if compiler can make them also static.
1229 * This is required for MSL where we have a wrapper class. */
1231 }
1232 }
1233 }
1234 }
1235 }
1236
1238 SymbolClass *cls,
1240 {
1241 if (list.is_empty()) {
1242 return cls;
1243 }
1244 if (list.child_count() != 1) {
1246 return cls;
1247 }
1248 if (Initializer init = list.child_first(); init.is_valid()) {
1249 Node node = init.child_first();
1250 if (node.type() == NodeType::InitializerList) {
1251 return eval_scalar_initializer_list(scope, cls, node);
1252 }
1253 return table.expr_type_analysis(scope, node.child_first()).unwrap(this);
1254 }
1255 return cls;
1256 }
1257
1259 {
1261 if (InitializerList list = assign.initializer_list(); list.is_valid()) {
1263 }
1264 else {
1265 result = table.expr_type_analysis(scope, assign.expr().child_first()).unwrap(this);
1266 }
1267 return result;
1268 }
1269
1271 SymbolClass *cls,
1273 {
1274 if (cls != table.int_cls && cls != table.int2_cls && cls != table.int3_cls &&
1275 cls != table.int4_cls && cls != table.uint_cls && cls != table.uint2_cls &&
1276 cls != table.uint3_cls && cls != table.uint4_cls && cls != table.bool_cls &&
1277 cls != table.bool2_cls && cls != table.bool3_cls && cls != table.bool4_cls &&
1278 cls != table.float_cls && cls != table.float2_cls && cls != table.float3_cls &&
1279 cls != table.float4_cls)
1280 {
1282 return {table.err_cls};
1283 }
1284
1286 if (AssignStmt assign = decl.initial_value(); assign.is_valid()) {
1287 result = initialize_assign(scope, cls, assign);
1288 }
1289 else if (InitializerList list = decl.initializer_list(); list.is_valid()) {
1291 }
1292
1293 if (result.type != cls) {
1294 error(decl,
1296 decl.identifier().str(),
1297 cls->original,
1298 result.type->original);
1299 }
1300 else if (!result.is_constexpr()) {
1302 }
1303
1304 return result;
1305 }
1306
1311
1313 {
1314 string prefix;
1315 SymbolClass *parent = nullptr;
1316 /* Support multiple nesting level. */
1317 do {
1318 /* Union members need to go through the getter functions. */
1319 parent = cls->parent->as_class();
1320 bool access = parent && parent->is_union && parent->is_anonymous;
1321 prefix = (access ? "_" : "") + cls->original + "_" + (access ? "()" : "") + "." + prefix;
1322 } while ((cls = parent, cls && cls->is_anonymous));
1323
1324 return {prefix, cls};
1325 }
1326}; // namespace blender::gpu::shader::parser
1327
1329{
1330 SymbolParser symbol_parser(err_handler, *this);
1331 symbol_parser.parse_scope(*root, node, "");
1332
1333 if (err_handler.err.has_value()) {
1334 throw ParserException();
1335 }
1336}
1337
1338} // namespace bsl
void init()
static constexpr const char * namespace_separator
Definition processor.hh:51
#define NOTE(node, diag, id)
#define str(s)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
Definition codegen.cc:18
SymbolTemplate< SymbolClass > SymbolClassTemplate
static const char * ns_sep
Definition symbol.cc:20
Result< ParsedAttribute > resource_type_from_attributes(AttrList list)
Definition resource.cc:17
@ TemplateParameterNotConstexpr
@ ConstexprVarMustBeInitializedByConstantExpr
@ TemplateInvalidArg
@ ReferenceCannotBindTemporary
@ StructuredBindingTooManyNames
@ ExprNotIntegralConstant
@ AnonymousUnionNotSupportedAtNamespaceScope
@ ConstexprMemberNonStatic
@ ExpectedScalarInitializer
@ ConstexprGlobalNonStatic
@ ResourceOutOfClassDeclaration
@ NoteInStorageBufferDeclaration
@ ExpectedResourceDefinitionOfType
@ RedefinitionOfEntryPointFunction
@ StaticDataMemberNotAllowed
@ ResourcesNotAllowedInAnonymousStruct
@ TemplateParameterCountMismatch
@ ConditionAttributeUnsupported
@ NoteInUniformBufferDeclaration
@ ConstexprVarMustNotBeArray
@ NoteInstantiationClassTemplateRequested
@ UnknownTypeNameWithArg
@ ExpectedEntryPointResourceAttribute
@ AttributeNotAllowedInComp
@ AttributeOnlyEntryPointsCanUseOut
@ InvalidResourceTypeForResourceTableClass
@ ReferenceMixedVarDecl
@ AttributeOnlyEntryPointsCanUseIn
@ NotePreviousDefinition
@ BitFieldSizeTooLarge
@ NoteInstantiationFuncTemplateRequested
@ BitFieldNotIntegral
@ AutoTypeCannotBeDeduced
@ ReferenceVariableRequiresInitializer
@ RedefinitionTemplate
@ ResourceAttributesOnlyOnEntryPointArgs
@ TemplateMissingDefinition
@ ConstexprVarMustBeValidType
@ EntryPointVoidReturn
@ TemplateMissingParameters
@ StructuredBindingNotEnoughNames
@ TemplateMissingParentClassInstantiation
@ ExpectedResourceOfType
@ ReferenceTypeMismatch
@ ExpectedResourceOfEitherType
@ CapacityArrayDimensionMismatch
@ ConditionAttributeNotOnResource
@ ResourceTableMustBeReference
@ BitFieldSizeNegative
@ UsingNamespaceNotSupported
@ ConstexprVarMustBeInitializedByCorrectType
@ Number
Definition types.hh:44
@ Word
Definition types.hh:43
@ Typename
Definition types.hh:84
string to_string(const char *str)
Definition string.cpp:202
InitializerList initializer_list() const
Definition ast.hh:791
bool contains_attr(std::string_view attr_name) const
Definition ast.hh:759
TemplateParamList template_params() const
Definition ast.hh:508
RecursiveTypedRange< NodeT > descendants_of_type() const
Definition ast.hh:426
TypedChildRange< NodeT > children_of_type() const
Definition ast.hh:379
std::string_view str() const
Definition ast.cc:113
TemplateParamList parameters() const
Definition ast.hh:1345
TemplateParamList parameters() const
Definition ast.hh:1330
ConstexprValue(int32_t s)
Definition constexpr.hh:139
void error(Token tok, const string &msg)
NodeErrorHandler(ErrorHandler &handler)
Represents a specific position within a source file or included sub-file.
SymbolClassTemplate * template_data
ResourceTableType srt_type
builtin::ClassId builtin_class
bool is_srt() const
void ensure_size_and_align(NodeErrorHandler *err_handler=nullptr, bool check_st430=false)
SymbolFunctionTemplate * template_data
SymbolClass * return_type
void add_argument(bool is_const, SymbolClass *type, ast::Expr default_value={})
enum bsl::SymbolFunction::EntryPointType entry_point_type
bool is_entry_point() const
static constexpr const char * inline_fn_ret_id
enum bsl::SymbolFunction::Type fn_type
void parse_local_scope(SymbolScope &scope, LocalScope local_node, const std::string &prefix)
Definition symbol.cc:129
void parse_enum_value(SymbolScope &scope, EnumValue val, ClassDecl cls, ConstexprValue &enum_last_val, const string &prefix)
Definition symbol.cc:505
void parse_template_inst(SymbolScope &scope, TemplateInst temp, const std::string &prefix)
Definition symbol.cc:769
void parse_template_decl(SymbolScope &scope, TemplateDecl decl)
Definition symbol.cc:725
SymbolParser(ErrorHandler &handler, SymbolTable &table)
Definition symbol.cc:25
SymbolTable & table
Definition symbol.cc:23
void parse_var_decl(SymbolScope &scope, VarDecl var, int &offset, int &bitfield_offset, SymbolVariable *&bitfield_base, const std::string &prefix)
Definition symbol.cc:967
void parse_function_arguments(SymbolScope &scope, FuncArgList arg_list)
Definition symbol.cc:194
void parse_template_spec(SymbolScope &scope, TemplateSpec temp, const std::string &prefix)
Definition symbol.cc:849
void parse_template_arguments(SymbolScope &scope, TemplateDecl decl, TemplateInst inst)
Definition symbol.cc:138
void parse_pipeline_decl(SymbolScope &scope, PipelineDecl decl, const std::string &prefix)
Definition symbol.cc:900
ExpressionResult initialize_assign(const SymbolScope &scope, SymbolClass *cls, AssignStmt assign)
Definition symbol.cc:1258
ExpressionResult eval_scalar_initializer_list(const SymbolScope &scope, SymbolClass *cls, InitializerList list)
Definition symbol.cc:1237
ExpressionResult initialize_constexpr(const SymbolScope &scope, SymbolClass *cls, Declarator decl)
Definition symbol.cc:1270
void parse_preprocessor(SymbolScope &, Preprocessor directive)
Definition symbol.cc:395
void parse_using_stmt(SymbolScope &scope, UsingStmt stmt)
Definition symbol.cc:479
static AnonScopePrefix anonymous_scope_prefix(SymbolClass *cls)
Definition symbol.cc:1312
void parse_scope(SymbolScope &scope, Node node, const std::string &prefix, TemplateInst template_inst={})
Definition symbol.cc:29
SymbolFunction * parse_func_decl(SymbolScope &scope, FuncDecl func, const std::string &prefix, const std::string &suffix="", optional< SourceLocation > poi=nullopt, TemplateInst temp={})
Definition symbol.cc:657
void parse_func_forward_decl(SymbolScope &scope, FuncForwardDecl decl)
Definition symbol.cc:634
TemplateDecl check_template_instance(TemplateParamList temp_params, DeclAst &decl, const SymbolT &sym)
Definition symbol.cc:753
void parse_namespace(SymbolScope &scope, ast::Namespace decl, string ns_prefix)
Definition symbol.cc:465
void parse_function_return_type(SymbolScope &scope, ast::IdType return_type)
Definition symbol.cc:182
void parse_structured_binding(SymbolScope &scope, StructuredBinding decl)
Definition symbol.cc:915
void parse_loop_arguments(SymbolScope &scope, ForLoop loop)
Definition symbol.cc:378
SymbolClass * parse_class_decl(SymbolScope &scope, ClassDecl decl, ClassDecl parent_class, int &offset, const std::string &prefix, const std::string &suffix="", optional< SourceLocation > poi=nullopt, TemplateInst temp={}, SymbolClassTemplate *cls_template=nullptr)
Definition symbol.cc:555
unordered_map< string, SymbolScope * > scopes
vector< SymbolVariable * > non_static_variables_in_declaration_order() const
vector< std::pair< ast::FuncForwardDecl, SymbolFunction * > > function_prototypes
bool function_emplace(SymbolFunction *fn, bool builtin=false)
SymbolMap< SymbolFunction > functions
optional< SourceLocation > poi
bool variable_emplace(string id, SymbolVariable *var)
SymbolMap< SymbolVariable > variables
SymbolFunction * lookup_function_base(const SymbolTable &table, ast::IdQualified id) const
SymbolMap< SymbolClass > classes
Result< SymbolFunction * > lookup_function(const SymbolTable &table, ast::IdQualified id, optional< SourceLocation > loc=nullopt) const
SymbolClass * lookup_class_base(const SymbolTable &table, ast::IdQualified id) const
SymbolClass * as_class()
Result< SymbolClass * > lookup_class(const SymbolTable &table, ast::IdQualified id, optional< SourceLocation > loc=nullopt) const
std::pair< ast::FuncForwardDecl, SymbolFunction * > lookup_function_forward_decl(ast::FuncDecl decl) const
SymbolClass * float4_cls
void parse(ast::LocalScope node, ErrorHandler &err_handler)
Definition symbol.cc:1328
SymbolClass * void_cls
SymbolClass * bool3_cls
SymbolClass * uint4_cls
SymbolClass * uint3_cls
SymbolScope * root
SymbolClass * int2_cls
SymbolClass * float2_cls
Result< StringPair > mangle_identifier(ast::TemplateArgList args, ast::TemplateParamList list, const SymbolScope &scope) const
SymbolClass * uint_cls
Allocator< SymbolFunction > fun_arena
SymbolClass * uint2_cls
SymbolClass * bool2_cls
SymbolClass * get_literal_type(string_view lit) const
SymbolClass * float_cls
SymbolClass * bool_cls
Result< SymbolClass * > resolve_auto_type(SymbolScope &scope, ast::Declarator decl) const
Allocator< SymbolClass > cls_arena
SymbolClass * err_cls
Allocator< SymbolScope > scp_arena
SymbolClass * int3_cls
Allocator< SymbolClassTemplate > tmp_cls_arena
SymbolClass * float3_cls
Result< ExpressionResult > expr_type_analysis(const SymbolScope &scope, ast::Node start_node, bool is_reference=false) const
SymbolClass * int4_cls
SymbolClass * int_cls
Allocator< SymbolVariable > var_arena
SymbolClass * bool4_cls
Allocator< SymbolFunctionTemplate > tmp_fun_arena
unordered_map< string, T * > instances
SymbolScope * parent
SourceLocation loc
std::string_view str() const
Definition lexit.hh:381
std::string_view str_with_whitespace() const
Definition lexit.hh:388
Token next(int i=1) const
Definition lexit.hh:372