Skip to content
Snippets Groups Projects
  • Iain Buclaw's avatar
    f4c3ce32
    d: Delay completing aggregate and enum types until after attributes have been applied. · f4c3ce32
    Iain Buclaw authored
    Because of forward/recursive references, the TYPE_SIZE, TYPE_ALIGN, and
    TYPE_MODE of structs and enums were set before laying out its members.
    
    This adds a new macro TYPE_FORWARD_REFERENCES for storing those forward
    references against the incomplete type, laying them out after the type
    has been completed.  Construction of the TYPE_DECL has also been moved
    on earlier in the type generation pass, which will allow the possibility
    of adding gdc-specific type attributes to the D front-end in the future.
    
    gcc/d/ChangeLog:
    
    	* d-attribs.cc (apply_user_attributes): Set ATTR_FLAG_TYPE_IN_PLACE
    	only on incomplete types.
    	* d-codegen.cc (copy_aggregate_type): Set TYPE_STUB_DECL after copy.
    	* d-compiler.cc (Compiler::onParseModule): Adjust.
    	* d-tree.h (AGGREGATE_OR_ENUM_TYPE_CHECK): Define.
    	(TYPE_FORWARD_REFERENCES): Define.
    	* decl.cc (gcc_attribute_p): Update documentation.
    	(DeclVisitor::visit (StructDeclaration *)): Exit before building type
    	node if gcc.attributes symbol.
    	(DeclVisitor::visit (ClassDeclaration *)): Build type node and add
    	TYPE_NAME to current binding level before emitting anything else.
    	(DeclVisitor::visit (InterfaceDeclaration *)): Likewise.
    	(DeclVisitor::visit (EnumDeclaration *)): Likewise.
    	(build_type_decl): Move rest_of_decl_compilation() call to
    	finish_aggregate_type().
    	* types.cc (insert_aggregate_field): Move layout_decl() call to
    	finish_aggregate_type().
    	(insert_aggregate_bitfield): Likewise.
    	(layout_aggregate_members): Adjust.
    	(finish_incomplete_fields): New function.
    	(finish_aggregate_type): Handle forward referenced field types.  Call
    	rest_of_type_compilation() after completing the aggregate.
    	(TypeVisitor::visit (TypeEnum *)): Don't set size and alignment until
    	after apply_user_attributes().  Call rest_of_type_compilation() after
    	completing the enumeral.
    	(TypeVisitor::visit (TypeStruct *)): Call build_type_decl() before
    	apply_user_attributes().  Don't set size, alignment, and mode until
    	after apply_user_attributes().
    	(TypeVisitor::visit (TypeClass *)): Call build_type_decl() before
    	applly_user_attributes().
    f4c3ce32
    History
    d: Delay completing aggregate and enum types until after attributes have been applied.
    Iain Buclaw authored
    Because of forward/recursive references, the TYPE_SIZE, TYPE_ALIGN, and
    TYPE_MODE of structs and enums were set before laying out its members.
    
    This adds a new macro TYPE_FORWARD_REFERENCES for storing those forward
    references against the incomplete type, laying them out after the type
    has been completed.  Construction of the TYPE_DECL has also been moved
    on earlier in the type generation pass, which will allow the possibility
    of adding gdc-specific type attributes to the D front-end in the future.
    
    gcc/d/ChangeLog:
    
    	* d-attribs.cc (apply_user_attributes): Set ATTR_FLAG_TYPE_IN_PLACE
    	only on incomplete types.
    	* d-codegen.cc (copy_aggregate_type): Set TYPE_STUB_DECL after copy.
    	* d-compiler.cc (Compiler::onParseModule): Adjust.
    	* d-tree.h (AGGREGATE_OR_ENUM_TYPE_CHECK): Define.
    	(TYPE_FORWARD_REFERENCES): Define.
    	* decl.cc (gcc_attribute_p): Update documentation.
    	(DeclVisitor::visit (StructDeclaration *)): Exit before building type
    	node if gcc.attributes symbol.
    	(DeclVisitor::visit (ClassDeclaration *)): Build type node and add
    	TYPE_NAME to current binding level before emitting anything else.
    	(DeclVisitor::visit (InterfaceDeclaration *)): Likewise.
    	(DeclVisitor::visit (EnumDeclaration *)): Likewise.
    	(build_type_decl): Move rest_of_decl_compilation() call to
    	finish_aggregate_type().
    	* types.cc (insert_aggregate_field): Move layout_decl() call to
    	finish_aggregate_type().
    	(insert_aggregate_bitfield): Likewise.
    	(layout_aggregate_members): Adjust.
    	(finish_incomplete_fields): New function.
    	(finish_aggregate_type): Handle forward referenced field types.  Call
    	rest_of_type_compilation() after completing the aggregate.
    	(TypeVisitor::visit (TypeEnum *)): Don't set size and alignment until
    	after apply_user_attributes().  Call rest_of_type_compilation() after
    	completing the enumeral.
    	(TypeVisitor::visit (TypeStruct *)): Call build_type_decl() before
    	apply_user_attributes().  Don't set size, alignment, and mode until
    	after apply_user_attributes().
    	(TypeVisitor::visit (TypeClass *)): Call build_type_decl() before
    	applly_user_attributes().