Structures generated by higher-order grammars and the safety constraint