Skip to content

Commit 9c1755b

Browse files
Very rough beginnings of argument handling in DetermineCopyInOut()
1 parent 527b2d7 commit 9c1755b

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

flang/lib/Evaluate/call.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,23 @@ ProcedureRef::~ProcedureRef() {}
248248

249249
void ProcedureRef::Deleter(ProcedureRef *p) { delete p; }
250250

251+
// We don't know the dummy argument info (e.g., procedure with implicit
252+
// interface
253+
static void DetermineCopyInOutArgument(
254+
const characteristics::Procedure &procInfo, ActualArgument &actual) {
255+
256+
// Only check that actual argument is contiguous
257+
// For non-contiguous, do copy-in
258+
}
259+
260+
static void DetermineCopyInOutArgument(
261+
const characteristics::Procedure &procInfo,
262+
ActualArgument &actual, characteristics::DummyArgument &dummy) {
263+
264+
// TODO: assert? procInfo.HasExplicitInterface()
265+
266+
}
267+
251268
void ProcedureRef::DetermineCopyInOut() {
252269
if (!proc_.GetSymbol()) {
253270
return;
@@ -261,6 +278,50 @@ void ProcedureRef::DetermineCopyInOut() {
261278
}
262279
// TODO: at this point have dummy arguments as procInfo->dummyArguments
263280
// and have actual arguments via arguments_
281+
282+
// TODO: implicitly declared procedure may not have any information about
283+
// its dummy args. Handle this case.
284+
285+
// Don't change anything about actual or dummy arguments, except for
286+
// computing copy-in/copy-out information. If detect something wrong with
287+
// the arguments, stop processing and let semantic analysis generate the
288+
// error messages.
289+
size_t index{0};
290+
std::set<std::string> processedKeywords;
291+
bool seenKeyword{false};
292+
for (auto &actual : arguments_) {
293+
if (!actual) {
294+
continue;
295+
}
296+
if (index >= procInfo->dummyArguments.size()) {
297+
// More actual arguments than dummy arguments. Semantic analysis will
298+
// deal with the error.
299+
return;
300+
}
301+
if (actual->keyword()) {
302+
seenKeyword = true;
303+
auto actualName = actual->keyword()->ToString();
304+
if (processedKeywords.find(actualName) != processedKeywords.end()) {
305+
// Actual arguments with duplicate keywords. Semantic analysis will
306+
// deal with the error.
307+
return;
308+
}
309+
else {
310+
processedKeywords.insert(actualName);
311+
312+
}
313+
}
314+
else if (seenKeyword) {
315+
// Non-keyword actual argument after have seen at least one keyword
316+
// actual argument. Semantic analysis will deal with the error.
317+
return;
318+
}
319+
else {
320+
// Positional argument processing
321+
}
322+
323+
++index;
324+
}
264325
}
265326

266327
} // namespace Fortran::evaluate

0 commit comments

Comments
 (0)