X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Freflect.cpp;h=258244e88b4e2457b441a75bfe9ecbed24fcc2b8;hp=c2a913f982acfcb61c6ca7a0289f3233f3d434e9;hb=38712d8ecc57d043a2419ffbaeeb57f7a6586f14;hpb=523491787b2b0321748a53f139c1a4355d2f9e85 diff --git a/source/glsl/reflect.cpp b/source/glsl/reflect.cpp index c2a913f9..258244e8 100644 --- a/source/glsl/reflect.cpp +++ b/source/glsl/reflect.cpp @@ -1,3 +1,4 @@ +#include #include "reflect.h" using namespace std; @@ -33,6 +34,8 @@ bool can_convert(const BasicTypeDeclaration &from, const BasicTypeDeclaration &t return from.size<=to.size; else if(from.kind!=to.kind) return false; + else if(from.kind==BasicTypeDeclaration::INT && from.sign!=to.sign) + return from.sign && from.size<=to.size; else if(is_vector_or_matrix(from) && from.size==to.size) { BasicTypeDeclaration *from_base = dynamic_cast(from.base_type); @@ -46,13 +49,6 @@ bool can_convert(const BasicTypeDeclaration &from, const BasicTypeDeclaration &t unsigned TypeComparer::next_tag = 1; -TypeComparer::TypeComparer(): - first(0), - second(0), - first_tag(0), - r_result(false) -{ } - void TypeComparer::compare(Node &node1, Node &node2) { if(&node1==&node2) @@ -119,11 +115,54 @@ void TypeComparer::visit(VariableReference &var) } } +void TypeComparer::visit(UnaryExpression &unary) +{ + if(UnaryExpression *unary1 = multi_visit(unary)) + { + if(unary1->oper!=unary.oper) + r_result = false; + else + compare(*unary1->expression, *unary.expression); + } +} + +void TypeComparer::visit(BinaryExpression &binary) +{ + if(BinaryExpression *binary1 = multi_visit(binary)) + { + if(binary1->oper!=binary.oper) + r_result = false; + else + { + compare(*binary1->left, *binary.left); + if(r_result) + compare(*binary1->right, *binary.right); + } + } +} + +void TypeComparer::visit(TernaryExpression &ternary) +{ + if(TernaryExpression *ternary1 = multi_visit(ternary)) + { + if(ternary1->oper!=ternary.oper) + r_result = false; + else + { + compare(*ternary1->condition, *ternary.condition); + if(r_result) + compare(*ternary1->true_expr, *ternary.true_expr); + if(r_result) + compare(*ternary1->false_expr, *ternary.false_expr); + } + } +} + void TypeComparer::visit(BasicTypeDeclaration &basic) { if(BasicTypeDeclaration *basic1 = multi_visit(basic)) { - if(basic1->kind!=basic.kind || basic1->size!=basic.size) + if(basic1->kind!=basic.kind || basic1->size!=basic.size || basic1->sign!=basic.sign) r_result = false; else if(basic1->base_type && basic.base_type) compare(*basic1->base_type, *basic.base_type); @@ -156,8 +195,8 @@ void TypeComparer::visit(StructDeclaration &strct) else { r_result = true; - NodeList::const_iterator i = strct1->members.body.begin(); - NodeList::const_iterator j = strct.members.body.begin(); + auto i = strct1->members.body.begin(); + auto j = strct.members.body.begin(); for(; (r_result && i!=strct1->members.body.end()); ++i, ++j) compare(**i, **j); } @@ -188,10 +227,6 @@ void TypeComparer::visit(VariableDeclaration &var) } -LocationCounter::LocationCounter(): - r_count(0) -{ } - void LocationCounter::visit(BasicTypeDeclaration &basic) { r_count = basic.kind==BasicTypeDeclaration::MATRIX ? basic.size>>16 : 1; @@ -205,10 +240,10 @@ void LocationCounter::visit(ImageTypeDeclaration &) void LocationCounter::visit(StructDeclaration &strct) { unsigned total = 0; - for(NodeList::const_iterator i=strct.members.body.begin(); i!=strct.members.body.end(); ++i) + for(const RefPtr &s: strct.members.body) { r_count = 1; - (*i)->visit(*this); + s->visit(*this); total += r_count; } r_count = total; @@ -254,12 +289,12 @@ void MemoryRequirementsCalculator::visit(StructDeclaration &strct) { unsigned total = 0; unsigned max_align = 1; - for(NodeList::iterator i=strct.members.body.begin(); i!=strct.members.body.end(); ++i) + for(const RefPtr &s: strct.members.body) { r_size = 0; r_alignment = 1; r_offset = -1; - (*i)->visit(*this); + s->visit(*this); if(r_offset) total = r_offset; total += r_alignment-1; @@ -275,10 +310,9 @@ void MemoryRequirementsCalculator::visit(VariableDeclaration &var) { if(var.layout) { - const vector qualifiers = var.layout->qualifiers; - for(vector::const_iterator i=qualifiers.begin(); (r_offset<0 && i!=qualifiers.end()); ++i) - if(i->name=="offset") - r_offset = i->value; + auto i = find_member(var.layout->qualifiers, string("offset"), &Layout::Qualifier::name); + if(i!=var.layout->qualifiers.end()) + r_offset = i->value; } if(var.type_declaration) @@ -319,7 +353,8 @@ void DependencyCollector::visit(FunctionCall &call) if(call.declaration) { dependencies.insert(call.declaration); - call.declaration->visit(*this); + if(call.declaration->definition) + call.declaration->definition->visit(*this); } TraversingVisitor::visit(call); }