X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fgenerate.cpp;h=53676c26784cf7d32709639fea843459e3cf4269;hb=041ba4b1acd55337239c5ce24cc310118c621206;hp=770fb460d657196cf7781fd0ea9b9553a2728b21;hpb=50ab5ca2babc8d9592903da6072a13b381ed6656;p=libs%2Fgl.git diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index 770fb460..53676c26 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -116,31 +116,58 @@ void ConstantSpecializer::visit(VariableDeclaration &var) void BlockHierarchyResolver::enter(Block &block) { + r_any_resolved |= (current_block!=block.parent); block.parent = current_block; } TypeResolver::TypeResolver(): - stage(0) + stage(0), + iface_block(0), + r_any_resolved(false) { } -void TypeResolver::apply(Stage &s) +bool TypeResolver::apply(Stage &s) { stage = &s; s.types.clear(); + r_any_resolved = false; s.content.visit(*this); + return r_any_resolved; +} + +TypeDeclaration *TypeResolver::get_or_create_array_type(TypeDeclaration &type) +{ + map::iterator i = array_types.find(&type); + if(i!=array_types.end()) + return i->second; + + BasicTypeDeclaration *array = new BasicTypeDeclaration; + array->source = BUILTIN_SOURCE; + array->name = type.name+"[]"; + array->kind = BasicTypeDeclaration::ARRAY; + array->base = type.name; + array->base_type = &type; + stage->content.body.insert(type_insert_point, array); + array_types[&type] = array; + return array; } -TypeDeclaration *TypeResolver::resolve_type(const string &name) +void TypeResolver::resolve_type(TypeDeclaration *&type, const string &name, bool array) { + TypeDeclaration *resolved = 0; map::iterator i = stage->types.find(name); if(i!=stage->types.end()) { map::iterator j = alias_map.find(i->second); - return (j!=alias_map.end() ? j->second : i->second); + resolved = (j!=alias_map.end() ? j->second : i->second); } - else - return 0; + + if(resolved && array) + resolved = get_or_create_array_type(*resolved); + + r_any_resolved |= (resolved!=type); + type=resolved; } void TypeResolver::visit(Block &block) @@ -155,7 +182,7 @@ void TypeResolver::visit(Block &block) void TypeResolver::visit(BasicTypeDeclaration &type) { - type.base_type = resolve_type(type.base); + resolve_type(type.base_type, type.base, false); if(type.kind==BasicTypeDeclaration::VECTOR && type.base_type) if(BasicTypeDeclaration *basic_base = dynamic_cast(type.base_type)) @@ -175,7 +202,7 @@ void TypeResolver::visit(BasicTypeDeclaration &type) void TypeResolver::visit(ImageTypeDeclaration &type) { - type.base_type = resolve_type(type.base); + resolve_type(type.base_type, type.base, false); stage->types.insert(make_pair(type.name, &type)); } @@ -187,48 +214,59 @@ void TypeResolver::visit(StructDeclaration &strct) void TypeResolver::visit(VariableDeclaration &var) { - TypeDeclaration *type = resolve_type(var.type); - if(var.array && type) + resolve_type(var.type_declaration, var.type, var.array); + if(iface_block && var.interface==iface_block->interface) + var.interface.clear(); +} + +void TypeResolver::visit(InterfaceBlock &iface) +{ + if(iface.members) { - map::iterator i = array_types.find(type); - if(i==array_types.end()) - { - BasicTypeDeclaration *array = new BasicTypeDeclaration; - array->source = BUILTIN_SOURCE; - array->name = type->name+"[]"; - array->kind = BasicTypeDeclaration::ARRAY; - array->base = type->name; - array->base_type = type; - stage->content.body.insert(type_insert_point, array); - array->visit(*this); - type = array; - } - else - type = i->second; + SetForScope set_iface(iface_block, &iface); + iface.members->visit(*this); + + StructDeclaration *strct = new StructDeclaration; + strct->source = INTERNAL_SOURCE; + strct->name = format("_%s_%s", iface.interface, iface.name); + strct->members.body.splice(strct->members.body.begin(), iface.members->body); + stage->content.body.insert(type_insert_point, strct); + stage->types.insert(make_pair(strct->name, strct)); + + iface.members = 0; + strct->interface_block = &iface; + iface.struct_declaration = strct; } - var.type_declaration = type; + + TypeDeclaration *type = iface.struct_declaration; + if(type && iface.array) + type = get_or_create_array_type(*type); + r_any_resolved = (type!=iface.type_declaration); + iface.type_declaration = type; } void TypeResolver::visit(FunctionDeclaration &func) { - func.return_type_declaration = resolve_type(func.return_type); + resolve_type(func.return_type_declaration, func.return_type, false); TraversingVisitor::visit(func); } VariableResolver::VariableResolver(): stage(0), - r_members(0), + r_any_resolved(false), record_target(false), r_self_referencing(false), r_assignment_target(0) { } -void VariableResolver::apply(Stage &s) +bool VariableResolver::apply(Stage &s) { stage = &s; s.interface_blocks.clear(); + r_any_resolved = false; s.content.visit(*this); + return r_any_resolved; } void VariableResolver::enter(Block &block) @@ -236,21 +274,33 @@ void VariableResolver::enter(Block &block) block.variables.clear(); } +void VariableResolver::visit_and_replace(RefPtr &expr) +{ + r_replacement_expr = 0; + expr->visit(*this); + if(r_replacement_expr) + { + expr = r_replacement_expr; + r_any_resolved = true; + } + r_replacement_expr = 0; +} + void VariableResolver::visit(VariableReference &var) { - var.declaration = 0; - r_members = 0; + VariableDeclaration *declaration = 0; + /* Look for variable declarations in the block hierarchy first. Interface blocks are always defined in the top level so we can't accidentally skip one. */ - for(Block *block=current_block; (!var.declaration && block); block=block->parent) + for(Block *block=current_block; (!declaration && block); block=block->parent) { map::iterator i = block->variables.find(var.name); if(i!=block->variables.end()) - var.declaration = i->second; + declaration = i->second; } - if(!var.declaration) + if(!declaration) { const map &blocks = stage->interface_blocks; map::const_iterator i = blocks.find("_"+var.name); @@ -258,29 +308,29 @@ void VariableResolver::visit(VariableReference &var) { /* The name refers to an interface block with an instance name rather than a variable. Prepare a new syntax tree node accordingly. */ - r_iface_ref = new InterfaceBlockReference; - r_iface_ref->source = var.source; - r_iface_ref->line = var.line; - r_iface_ref->name = var.name; - r_iface_ref->declaration = i->second; - r_members = &i->second->members.variables; + InterfaceBlockReference *iface_ref = new InterfaceBlockReference; + iface_ref->source = var.source; + iface_ref->line = var.line; + iface_ref->name = var.name; + iface_ref->declaration = i->second; + r_replacement_expr = iface_ref; } else { // Look for the variable in anonymous interface blocks. - for(i=blocks.begin(); (!var.declaration && i!=blocks.end()); ++i) - if(i->second->instance_name.empty()) + for(i=blocks.begin(); (!declaration && i!=blocks.end()); ++i) + if(i->second->instance_name.empty() && i->second->struct_declaration) { - map::iterator j = i->second->members.variables.find(var.name); - if(j!=i->second->members.variables.end()) - var.declaration = j->second; + const map &iface_vars = i->second->struct_declaration->members.variables; + map::const_iterator j = iface_vars.find(var.name); + if(j!=iface_vars.end()) + declaration = j->second; } } } - if(var.declaration) - if(StructDeclaration *strct = dynamic_cast(var.declaration->type_declaration)) - r_members = &strct->members.variables; + r_any_resolved |= (declaration!=var.declaration); + var.declaration = declaration; if(record_target) { @@ -300,49 +350,31 @@ void VariableResolver::visit(VariableReference &var) void VariableResolver::visit(InterfaceBlockReference &iface) { - iface.declaration = 0; - for(Block *block=current_block; block; block=block->parent) - { - map::iterator i = stage->interface_blocks.find("_"+iface.name); - if(i!=stage->interface_blocks.end()) - { - iface.declaration = i->second; - r_members = &i->second->members.variables; - break; - } - } + map::iterator i = stage->interface_blocks.find("_"+iface.name); + InterfaceBlock *declaration = (i!=stage->interface_blocks.end() ? i->second : 0); + r_any_resolved |= (declaration!=iface.declaration); + iface.declaration = declaration; } void VariableResolver::visit(MemberAccess &memacc) { - r_members = 0; - r_iface_ref = 0; - memacc.left->visit(*this); - - if(r_iface_ref) - memacc.left = r_iface_ref; - r_iface_ref = 0; + visit_and_replace(memacc.left); - memacc.declaration = 0; - if(r_members) + VariableDeclaration *declaration = 0; + if(StructDeclaration *strct = dynamic_cast(memacc.left->type)) { - map::iterator i = r_members->find(memacc.member); - if(i!=r_members->end()) - { - memacc.declaration = i->second; - if(StructDeclaration *strct = dynamic_cast(i->second->type_declaration)) - r_members = &strct->members.variables; - } - else - r_members = 0; + map::iterator i = strct->members.variables.find(memacc.member); + if(i!=strct->members.variables.end()) + declaration = i->second; } + + r_any_resolved |= (declaration!=memacc.declaration); + memacc.declaration = declaration; } void VariableResolver::visit(UnaryExpression &unary) { - TraversingVisitor::visit(unary); - r_members = 0; - r_iface_ref = 0; + visit_and_replace(unary.expression); } void VariableResolver::visit(BinaryExpression &binary) @@ -353,21 +385,15 @@ void VariableResolver::visit(BinaryExpression &binary) /* The subscript expression is not a part of the primary assignment target. */ SetFlag set(record_target, false); - binary.right->visit(*this); + visit_and_replace(binary.right); } - r_members = 0; - r_iface_ref = 0; - binary.left->visit(*this); - if(r_iface_ref) - binary.left = r_iface_ref; + visit_and_replace(binary.left); } else { - TraversingVisitor::visit(binary); - r_members = 0; + visit_and_replace(binary.left); + visit_and_replace(binary.right); } - - r_iface_ref = 0; } void VariableResolver::visit(Assignment &assign) @@ -375,31 +401,30 @@ void VariableResolver::visit(Assignment &assign) { SetFlag set(record_target); r_assignment_target = 0; - assign.left->visit(*this); + visit_and_replace(assign.left); + r_any_resolved |= (r_assignment_target!=assign.target_declaration); assign.target_declaration = r_assignment_target; } r_self_referencing = false; - assign.right->visit(*this); + visit_and_replace(assign.right); assign.self_referencing = (r_self_referencing || assign.oper->token[0]!='='); - - r_members = 0; - r_iface_ref = 0; } void VariableResolver::visit(FunctionCall &call) { - TraversingVisitor::visit(call); - r_members = 0; - r_iface_ref = 0; + for(NodeArray::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i) + visit_and_replace(*i); } void VariableResolver::visit(VariableDeclaration &var) { - if(!block_interface.empty() && var.interface.empty()) - var.interface = block_interface; - - TraversingVisitor::visit(var); + if(var.layout) + var.layout->visit(*this); + if(var.array_size) + visit_and_replace(var.array_size); + if(var.init_expression) + visit_and_replace(var.init_expression); current_block->variables.insert(make_pair(var.name, &var)); } @@ -411,11 +436,23 @@ void VariableResolver::visit(InterfaceBlock &iface) if(!iface.instance_name.empty()) stage->interface_blocks.insert(make_pair("_"+iface.instance_name, &iface)); - SetForScope set_iface(block_interface, iface.interface); TraversingVisitor::visit(iface); } +ExpressionResolver::ExpressionResolver(): + stage(0), + r_any_resolved(false) +{ } + +bool ExpressionResolver::apply(Stage &s) +{ + stage = &s; + r_any_resolved = false; + s.content.visit(*this); + return r_any_resolved; +} + bool ExpressionResolver::is_scalar(BasicTypeDeclaration &type) { return (type.kind==BasicTypeDeclaration::INT || type.kind==BasicTypeDeclaration::FLOAT); @@ -509,34 +546,39 @@ bool ExpressionResolver::convert_to_element(RefPtr &expr, BasicTypeD return false; } +void ExpressionResolver::resolve(Expression &expr, TypeDeclaration *type, bool lvalue) +{ + r_any_resolved |= (type!=expr.type || lvalue!=expr.lvalue); + expr.type = type; + expr.lvalue = lvalue; +} + void ExpressionResolver::visit(Literal &literal) { if(literal.value.check_type()) - literal.type = find_type(BasicTypeDeclaration::BOOL, 1); + resolve(literal, find_type(BasicTypeDeclaration::BOOL, 1), false); else if(literal.value.check_type()) - literal.type = find_type(BasicTypeDeclaration::INT, 32); + resolve(literal, find_type(BasicTypeDeclaration::INT, 32), false); else if(literal.value.check_type()) - literal.type = find_type(BasicTypeDeclaration::FLOAT, 32); + resolve(literal, find_type(BasicTypeDeclaration::FLOAT, 32), false); } void ExpressionResolver::visit(ParenthesizedExpression &parexpr) { TraversingVisitor::visit(parexpr); - - parexpr.type = parexpr.expression->type; - parexpr.lvalue = parexpr.expression->lvalue; + resolve(parexpr, parexpr.expression->type, parexpr.expression->lvalue); } void ExpressionResolver::visit(VariableReference &var) { if(var.declaration) - var.type = var.declaration->type_declaration; - var.lvalue = true; + resolve(var, var.declaration->type_declaration, true); } void ExpressionResolver::visit(InterfaceBlockReference &iface) { - iface.lvalue = true; + if(iface.declaration) + resolve(iface, iface.declaration->type_declaration, true); } void ExpressionResolver::visit(MemberAccess &memacc) @@ -544,8 +586,7 @@ void ExpressionResolver::visit(MemberAccess &memacc) TraversingVisitor::visit(memacc); if(memacc.declaration) - memacc.type = memacc.declaration->type_declaration; - memacc.lvalue = memacc.left->lvalue; + resolve(memacc, memacc.declaration->type_declaration, memacc.left->lvalue); } void ExpressionResolver::visit(UnaryExpression &unary) @@ -559,27 +600,25 @@ void ExpressionResolver::visit(UnaryExpression &unary) char oper = unary.oper->token[0]; if(oper=='!') { - if(basic->kind==BasicTypeDeclaration::BOOL) - unary.type = basic; + if(basic->kind!=BasicTypeDeclaration::BOOL) + return; } else if(oper=='~') { - if(basic->kind==BasicTypeDeclaration::INT) - unary.type = basic; + if(basic->kind!=BasicTypeDeclaration::INT) + return; } else if(oper=='+' || oper=='-') { BasicTypeDeclaration *elem = get_element_type(*basic); - if(elem && is_scalar(*elem)) - unary.type = basic; + if(!elem || !is_scalar(*elem)) + return; } - unary.lvalue = unary.expression->lvalue; + resolve(unary, basic, unary.expression->lvalue); } -void ExpressionResolver::visit(BinaryExpression &binary) +void ExpressionResolver::visit(BinaryExpression &binary, bool assign) { - TraversingVisitor::visit(binary); - /* Binary operators are only defined for basic types (not for image or structure types). */ BasicTypeDeclaration *basic_left = dynamic_cast(binary.left->type); @@ -587,8 +626,6 @@ void ExpressionResolver::visit(BinaryExpression &binary) if(!basic_left || !basic_right) return; - binary.lvalue = false; - char oper = binary.oper->token[0]; if(oper=='[') { @@ -597,8 +634,7 @@ void ExpressionResolver::visit(BinaryExpression &binary) if((!is_vector_or_matrix(*basic_left) && basic_left->kind!=BasicTypeDeclaration::ARRAY) || basic_right->kind!=BasicTypeDeclaration::INT) return; - binary.type = basic_left->base_type; - binary.lvalue = binary.left->lvalue; + resolve(binary, basic_left->base_type, binary.left->lvalue); return; } else if(basic_left->kind==BasicTypeDeclaration::ARRAY || basic_right->kind==BasicTypeDeclaration::ARRAY) @@ -614,7 +650,10 @@ void ExpressionResolver::visit(BinaryExpression &binary) Compatibility elem_compat = get_compatibility(*elem_left, *elem_right); if(elem_compat==NOT_COMPATIBLE) return; + if(assign && (compat==LEFT_CONVERTIBLE || elem_compat==LEFT_CONVERTIBLE)) + return; + TypeDeclaration *type = 0; char oper2 = binary.oper->token[1]; if((oper=='<' && oper2!='<') || (oper=='>' && oper2!='>')) { @@ -623,7 +662,7 @@ void ExpressionResolver::visit(BinaryExpression &binary) if(!is_scalar(*elem_left) || !is_scalar(*elem_right) || compat==NOT_COMPATIBLE) return; - binary.type = find_type(BasicTypeDeclaration::BOOL, 1); + type = find_type(BasicTypeDeclaration::BOOL, 1); } else if((oper=='=' || oper=='!') && oper2=='=') { @@ -631,7 +670,7 @@ void ExpressionResolver::visit(BinaryExpression &binary) if(compat==NOT_COMPATIBLE) return; - binary.type = find_type(BasicTypeDeclaration::BOOL, 1); + type = find_type(BasicTypeDeclaration::BOOL, 1); } else if(oper2=='&' || oper2=='|' || oper2=='^') { @@ -639,7 +678,7 @@ void ExpressionResolver::visit(BinaryExpression &binary) if(basic_left->kind!=BasicTypeDeclaration::BOOL || basic_right->kind!=BasicTypeDeclaration::BOOL) return; - binary.type = basic_left; + type = basic_left; } else if((oper=='&' || oper=='|' || oper=='^' || oper=='%') && !oper2) { @@ -647,15 +686,21 @@ void ExpressionResolver::visit(BinaryExpression &binary) if(basic_left->kind!=BasicTypeDeclaration::INT || basic_right->kind!=BasicTypeDeclaration::INT) return; - binary.type = (compat==LEFT_CONVERTIBLE ? basic_right : basic_left); + type = (compat==LEFT_CONVERTIBLE ? basic_right : basic_left); } else if((oper=='<' || oper=='>') && oper2==oper) { - // Shifts only apply to integers. - if(basic_left->kind!=BasicTypeDeclaration::INT || basic_right->kind!=BasicTypeDeclaration::INT) + // Shifts apply to integer scalars and vectors, with some restrictions. + if(elem_left->kind!=BasicTypeDeclaration::INT || elem_right->kind!=BasicTypeDeclaration::INT) + return; + unsigned left_size = (basic_left->kind==BasicTypeDeclaration::INT ? 1 : basic_left->kind==BasicTypeDeclaration::VECTOR ? basic_left->size : 0); + unsigned right_size = (basic_right->kind==BasicTypeDeclaration::INT ? 1 : basic_right->kind==BasicTypeDeclaration::VECTOR ? basic_right->size : 0); + if(!left_size || (left_size==1 && right_size!=1) || (left_size>1 && right_size!=1 && right_size!=left_size)) return; - binary.type = basic_left; + type = basic_left; + // Don't perform conversion even if the operands are of different sizes. + compat = SAME_TYPE; } else if(oper=='+' || oper=='-' || oper=='*' || oper=='/') { @@ -678,30 +723,33 @@ void ExpressionResolver::visit(BinaryExpression &binary) BasicTypeDeclaration *elem_result = (elem_compat==LEFT_CONVERTIBLE ? elem_right : elem_left); if(basic_left->kind==BasicTypeDeclaration::VECTOR) - binary.type = find_type(*elem_result, BasicTypeDeclaration::VECTOR, basic_right->size&0xFFFF); + type = find_type(*elem_result, BasicTypeDeclaration::VECTOR, basic_right->size&0xFFFF); else if(basic_right->kind==BasicTypeDeclaration::VECTOR) - binary.type = find_type(*elem_result, BasicTypeDeclaration::VECTOR, basic_left->size>>16); + type = find_type(*elem_result, BasicTypeDeclaration::VECTOR, basic_left->size>>16); else - binary.type = find_type(*elem_result, BasicTypeDeclaration::MATRIX, (basic_left->size&0xFFFF0000)|(basic_right->size&0xFFFF)); + type = find_type(*elem_result, BasicTypeDeclaration::MATRIX, (basic_left->size&0xFFFF0000)|(basic_right->size&0xFFFF)); } else if(compat==NOT_COMPATIBLE) { // Arithmetic between scalars and matrices or vectors is supported. if(is_scalar(*basic_left) && is_vector_or_matrix(*basic_right)) - binary.type = (elem_compat==RIGHT_CONVERTIBLE ? find_type(*elem_left, basic_right->kind, basic_right->size) : basic_right); + type = (elem_compat==RIGHT_CONVERTIBLE ? find_type(*elem_left, basic_right->kind, basic_right->size) : basic_right); else if(is_vector_or_matrix(*basic_left) && is_scalar(*basic_right)) - binary.type = (elem_compat==LEFT_CONVERTIBLE ? find_type(*elem_right, basic_left->kind, basic_left->size) : basic_left); + type = (elem_compat==LEFT_CONVERTIBLE ? find_type(*elem_right, basic_left->kind, basic_left->size) : basic_left); else return; } else if(compat==LEFT_CONVERTIBLE) - binary.type = basic_right; + type = basic_right; else - binary.type = basic_left; + type = basic_left; } else return; + if(assign && type!=basic_left) + return; + bool converted = true; if(compat==LEFT_CONVERTIBLE) convert_to(binary.left, *basic_right); @@ -713,28 +761,53 @@ void ExpressionResolver::visit(BinaryExpression &binary) converted = convert_to_element(binary.right, *elem_left); if(!converted) - binary.type = 0; + type = 0; + + resolve(binary, type, assign); +} + +void ExpressionResolver::visit(BinaryExpression &binary) +{ + TraversingVisitor::visit(binary); + visit(binary, false); } void ExpressionResolver::visit(Assignment &assign) { TraversingVisitor::visit(assign); - assign.type = assign.left->type; - assign.lvalue = true; + + if(assign.oper->token[0]!='=') + return visit(assign, true); + else if(assign.left->type!=assign.right->type) + { + BasicTypeDeclaration *basic_left = dynamic_cast(assign.left->type); + BasicTypeDeclaration *basic_right = dynamic_cast(assign.right->type); + if(!basic_left || !basic_right) + return; + + Compatibility compat = get_compatibility(*basic_left, *basic_right); + if(compat==RIGHT_CONVERTIBLE) + convert_to(assign.right, *basic_left); + else if(compat!=SAME_TYPE) + return; + } + + resolve(assign, assign.left->type, true); } void ExpressionResolver::visit(FunctionCall &call) { TraversingVisitor::visit(call); + TypeDeclaration *type = 0; if(call.declaration) - call.type = call.declaration->return_type_declaration; + type = call.declaration->return_type_declaration; else if(call.constructor) { map::const_iterator i=stage->types.find(call.name); - call.type = (i!=stage->types.end() ? i->second : 0); + type = (i!=stage->types.end() ? i->second : 0); } - call.lvalue = false; + resolve(call, type, false); } void ExpressionResolver::visit(BasicTypeDeclaration &type) @@ -759,11 +832,13 @@ void ExpressionResolver::visit(VariableDeclaration &var) } -void FunctionResolver::apply(Stage &s) +bool FunctionResolver::apply(Stage &s) { stage = &s; s.functions.clear(); + r_any_resolved = false; s.content.visit(*this); + return r_any_resolved; } void FunctionResolver::visit(FunctionCall &call) @@ -807,7 +882,6 @@ void FunctionResolver::visit(FunctionDeclaration &func) InterfaceGenerator::InterfaceGenerator(): stage(0), function_scope(false), - iface_block(0), copy_block(false), iface_target_block(0) { } @@ -891,6 +965,7 @@ InterfaceBlock *InterfaceGenerator::generate_interface(InterfaceBlock &out_block InterfaceBlock *in_block = new InterfaceBlock; in_block->interface = "in"; in_block->name = out_block.name; + in_block->members = new Block; in_block->instance_name = out_block.instance_name; if(stage->type==Stage::GEOMETRY) in_block->array = true; @@ -901,9 +976,12 @@ InterfaceBlock *InterfaceGenerator::generate_interface(InterfaceBlock &out_block { SetFlag set_copy(copy_block, true); - SetForScope set_target(iface_target_block, &in_block->members); - SetForScope::iterator> set_ins_pt(iface_insert_point, in_block->members.body.end()); - out_block.members.visit(*this); + SetForScope set_target(iface_target_block, in_block->members.get()); + SetForScope::iterator> set_ins_pt(iface_insert_point, in_block->members->body.end()); + if(out_block.struct_declaration) + out_block.struct_declaration->members.visit(*this); + else if(out_block.members) + out_block.members->visit(*this); } iface_target_block->body.insert(iface_insert_point, in_block); @@ -966,10 +1044,11 @@ void InterfaceGenerator::visit(VariableReference &var) } for(j=prev_blocks.begin(); j!=prev_blocks.end(); ++j) - if(j->second->instance_name.empty()) + if(j->second->instance_name.empty() && j->second->struct_declaration) { - i = j->second->members.variables.find(var.name); - if(i!=j->second->members.variables.end()) + const map &iface_vars = j->second->struct_declaration->members.variables; + i = iface_vars.find(var.name); + if(i!=iface_vars.end()) { generate_interface(*j->second); return; @@ -980,28 +1059,8 @@ void InterfaceGenerator::visit(VariableReference &var) void InterfaceGenerator::visit(VariableDeclaration &var) { if(copy_block) - { generate_interface(var, "in", var.name); - return; - } - - if(iface_block) - { - if(iface_block->linked_block) - { - // Link all variables to their counterparts in the linked block. - const map &linked_vars = iface_block->linked_block->members.variables; - map::const_iterator i = linked_vars.find(var.name); - if(i!=linked_vars.end()) - { - var.linked_declaration = i->second; - var.linked_declaration->linked_declaration = &var; - } - } - return; - } - - if(var.interface=="out") + else if(var.interface=="out") { /* For output variables in function scope, generate a global interface and replace the local declaration with an assignment. */ @@ -1057,7 +1116,6 @@ void InterfaceGenerator::visit(InterfaceBlock &iface) } } - SetForScope set_iface(iface_block, &iface); TraversingVisitor::visit(iface); }