@@ -111,51 +111,50 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) {
111
111
112
112
for (const auto &typeDef : ir.typeDefs ) {
113
113
if (ir.shouldOutput (typeDef)) {
114
- if (!typeDef->usesOpaqueType ()) {
115
- s << *typeDef;
116
- } else if (!typeDef->getType ()) {
117
- llvm::errs () << " Error: type definition for "
118
- << typeDef->getName () << " was not found.\n " ;
119
- llvm::errs ().flush ();
120
- } else {
121
- llvm::errs () << " Error: Typedef " << typeDef->getName ()
122
- << " is skipped because it references an "
123
- " opaque type.\n " ;
124
- llvm::errs ().flush ();
114
+ s << *typeDef;
115
+ if (typeDef->getType ()) {
116
+ auto *structOrUnion =
117
+ dynamic_cast <StructOrUnion *>(typeDef->getType ().get ());
118
+ if (structOrUnion &&
119
+ structOrUnion->hasIllegalUsageOfOpaqueType ()) {
120
+ llvm::errs ()
121
+ << " Error: record " << structOrUnion->getName ()
122
+ << " has field of incomplete type. Declarations "
123
+ " that use this type may not work properly.\n " ;
124
+ llvm::errs ().flush ();
125
+ }
125
126
}
126
127
}
127
128
}
128
129
129
130
for (const auto &variable : ir.variables ) {
130
- if (!variable->usesOpaqueType ()) {
131
+ if (!variable->hasIllegalUsageOfOpaqueType ()) {
131
132
s << *variable;
132
133
} else {
133
- llvm::errs ()
134
- << " Error: Variable " << variable->getName ()
135
- << " is skipped because it references an opaque type.\n " ;
134
+ llvm::errs () << " Error: Variable " << variable->getName ()
135
+ << " is skipped because it has incomplete type.\n " ;
136
136
}
137
137
}
138
138
139
139
for (const auto &varDefine : ir.varDefines ) {
140
- if (!varDefine->usesOpaqueType ()) {
140
+ if (!varDefine->hasIllegalUsageOfOpaqueType ()) {
141
141
s << *varDefine;
142
142
} else {
143
- llvm::errs () << " Error: Typedef " << varDefine->getName ()
144
- << " is skipped because it references an "
145
- " opaque type.\n " ;
143
+ llvm::errs () << " Error: Variable alias " << varDefine->getName ()
144
+ << " is skipped because it has incomplete type\n " ;
146
145
llvm::errs ().flush ();
147
146
}
148
147
}
149
148
150
149
for (const auto &func : ir.functions ) {
151
- if (func->isLegalScalaNativeFunction ()) {
152
- s << *func;
153
- } else {
150
+ if (!func->isLegalScalaNativeFunction ()) {
154
151
llvm::errs ()
155
152
<< " Warning: Function " << func->getName ()
156
153
<< " is skipped because Scala Native does not support "
157
154
" passing structs and arrays by value.\n " ;
158
155
llvm::errs ().flush ();
156
+ } else {
157
+ s << *func;
159
158
}
160
159
}
161
160
@@ -193,13 +192,13 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) {
193
192
194
193
for (const auto &st : ir.structs ) {
195
194
if (ir.shouldOutput (st) && st->hasHelperMethods () &&
196
- !st->usesOpaqueType ()) {
195
+ !st->hasIllegalUsageOfOpaqueType ()) {
197
196
s << " \n " << st->generateHelperClass ();
198
197
}
199
198
}
200
199
201
200
for (const auto &u : ir.unions ) {
202
- if (ir.shouldOutput (u) && !u->usesOpaqueType ()) {
201
+ if (ir.shouldOutput (u) && !u->hasIllegalUsageOfOpaqueType ()) {
203
202
s << " \n " << u->generateHelperClass ();
204
203
}
205
204
}
@@ -480,38 +479,17 @@ bool IR::shouldOutput(const std::shared_ptr<T> &type) const {
480
479
if (typeDef) {
481
480
/* unused typedefs from main file are not printed if they are aliases
482
481
* for opaque types */
483
- return !typeDef->referencesOpaqueType () && inMainFile (*typeDef);
482
+ return !typeDef->isAliasForOpaqueType () && inMainFile (*typeDef);
484
483
}
485
484
return inMainFile (*type);
486
485
}
487
486
488
487
void IR::fixPointersToOpaqueTypes () {
489
- std::shared_ptr<Type> pointerToByte =
490
- std::make_shared<PointerType>(std::make_shared<PrimitiveType>(" Byte" ));
491
488
for (const auto &typeDef : typeDefs) {
492
489
if (shouldOutput (typeDef)) {
493
- if (typeDef->referencesOpaqueType ()) {
494
- std::shared_ptr<Type> pointerToStruct =
495
- std::make_shared<PointerType>(typeDef);
496
- replaceType (pointerToStruct, pointerToByte);
490
+ if (typeDef->isAliasForOpaqueType ()) {
491
+ // TODO: ?
497
492
}
498
493
}
499
494
}
500
495
}
501
-
502
- void IR::replaceType (std::shared_ptr<Type> type,
503
- std::shared_ptr<Type> replacement) {
504
- replaceType (functions, type, replacement);
505
- replaceType (typeDefs, type, replacement);
506
- replaceType (structs, type, replacement);
507
- replaceType (unions, type, replacement);
508
- }
509
-
510
- template <typename T>
511
- void IR::replaceType (std::vector<std::shared_ptr<T>> declarations,
512
- std::shared_ptr<Type> type,
513
- std::shared_ptr<Type> replacement) {
514
- for (const auto &declaration : declarations) {
515
- declaration->replaceType (type, replacement);
516
- }
517
- }
0 commit comments