@@ -87,7 +87,8 @@ void IR::addVarDefine(std::string name, std::shared_ptr<Variable> variable) {
8787bool IR::libObjEmpty () const {
8888 return functions.empty () && !shouldOutputType (typeDefs) &&
8989 !shouldOutputType (structs) && !shouldOutputType (unions) &&
90- varDefines.empty () && variables.empty () && enums.empty ();
90+ varDefines.empty () && variables.empty () &&
91+ !shouldOutputType (enums) && literalDefines.empty ();
9192}
9293
9394llvm::raw_ostream &operator <<(llvm::raw_ostream &s, const IR &ir) {
@@ -97,24 +98,21 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) {
9798 s << " package " << ir.packageName << " \n\n " ;
9899 }
99100
100- if (!ir.libObjEmpty () || ir.shouldOutputType (ir.enums ) ||
101- !ir.literalDefines .empty ()) {
102- s << " import scala.scalanative._\n "
103- << " import scala.scalanative.native._\n\n " ;
101+ if (ir.libObjEmpty ()) {
102+ return s;
104103 }
105104
106- std::string objectName = handleReservedWords (ir.objectName );
105+ s << " import scala.scalanative._\n "
106+ << " import scala.scalanative.native._\n\n " ;
107107
108- bool isLibObjectEmpty = ir.libObjEmpty ();
109-
110- if (!isLibObjectEmpty) {
108+ if (!ir.functions .empty () || !ir.varDefines .empty () ||
109+ !ir.variables .empty ()) {
111110 if (!ir.linkName .empty ()) {
112111 s << " @native.link(\" " << ir.linkName << " \" )\n " ;
113112 }
114-
115- s << " @native.extern\n "
116- << " object " << objectName << " {\n " ;
113+ s << " @native.extern\n " ;
117114 }
115+ s << " object " << handleReservedWords (ir.objectName ) << " {\n " ;
118116
119117 std::vector<std::shared_ptr<const Type>> visitedTypes;
120118
@@ -171,22 +169,20 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) {
171169 }
172170 }
173171
174- if (ir.hasHelperMethods ()) {
175- s << " \n object implicits {\n " << ir.getHelperMethods () << " }\n " ;
176- }
177-
178- if (!isLibObjectEmpty) {
179- s << " }\n\n " ;
180- }
181-
182172 if (!ir.literalDefines .empty ()) {
183- s << " object " << ir. libName << " Defines {\n " ;
173+ s << " \n object defines {\n " ;
184174 for (const auto &literalDefine : ir.literalDefines ) {
185175 s << literalDefine->getDefinition (ir.locationManager );
186176 }
187- s << " }\n\n " ;
177+ s << " }\n " ;
178+ }
179+
180+ if (ir.hasHelperMethods ()) {
181+ s << " \n object implicits {\n " << ir.getHelperMethods () << " }\n " ;
188182 }
189183
184+ s << " }\n\n " ;
185+
190186 return s;
191187}
192188
0 commit comments