- if(!prefixed && !prefix_hint.empty())
- {
- if(name.front()!='_')
- name = "_"+name;
- name = prefix_hint+name;
- if(name.front()!='_')
- name = "_"+name;
- prefixed = true;
- size_without_number = name.size();
- }
+ bool unused = true;
+ for(const Block *b=█ (unused && b); b=b->parent)
+ unused = !b->variables.count(name);
+ if(unused)
+ return name;
+
+ name.erase(base_size);
+ name += format("_%d", number);
+ ++number;
+ }
+}
+
+bool is_same_type(const TypeDeclaration &type1, const TypeDeclaration &type2)
+{
+ if(const BasicTypeDeclaration *basic1 = dynamic_cast<const BasicTypeDeclaration *>(&type1))
+ {
+ const BasicTypeDeclaration *basic2 = dynamic_cast<const BasicTypeDeclaration *>(&type2);
+ if(!basic2)
+ return false;
+
+ if(basic1->kind!=basic2->kind || basic1->size!=basic2->size)
+ return false;
+
+ if(basic1->base_type && basic2->base_type)
+ return is_same_type(*basic1->base_type, *basic2->base_type);
+ else
+ return (!basic1->base_type && !basic2->base_type);
+ }
+ else if(const ImageTypeDeclaration *image1 = dynamic_cast<const ImageTypeDeclaration *>(&type1))
+ {
+ const ImageTypeDeclaration *image2 = dynamic_cast<const ImageTypeDeclaration *>(&type2);
+ if(!image2)
+ return false;
+
+ if(image1->dimensions!=image2->dimensions || image1->array!=image2->array)
+ return false;
+ if(image1->sampled!=image2->sampled || image1->shadow!=image2->shadow)
+ return false;
+
+ if(image1->base_type && image2->base_type)
+ return is_same_type(*image1->base_type, *image2->base_type);