2020-02-25 23:11:52 +08:00
|
|
|
//===-- lib/Parser/tools.cpp ----------------------------------------------===//
|
2019-04-17 06:59:04 +08:00
|
|
|
//
|
2019-12-21 04:52:07 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-04-17 06:59:04 +08:00
|
|
|
//
|
2020-01-11 04:12:03 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-04-17 06:59:04 +08:00
|
|
|
|
2020-02-25 23:11:52 +08:00
|
|
|
#include "flang/Parser/tools.h"
|
2019-04-17 06:59:04 +08:00
|
|
|
|
|
|
|
namespace Fortran::parser {
|
|
|
|
|
|
|
|
const Name &GetLastName(const Name &x) { return x; }
|
|
|
|
|
|
|
|
const Name &GetLastName(const StructureComponent &x) {
|
|
|
|
return GetLastName(x.component);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetLastName(const DataRef &x) {
|
|
|
|
return std::visit(
|
|
|
|
common::visitors{
|
|
|
|
[](const Name &name) -> const Name & { return name; },
|
|
|
|
[](const common::Indirection<StructureComponent> &sc)
|
|
|
|
-> const Name & { return GetLastName(sc.value()); },
|
|
|
|
[](const common::Indirection<ArrayElement> &sc) -> const Name & {
|
|
|
|
return GetLastName(sc.value().base);
|
|
|
|
},
|
|
|
|
[](const common::Indirection<CoindexedNamedObject> &ci)
|
|
|
|
-> const Name & { return GetLastName(ci.value().base); },
|
|
|
|
},
|
|
|
|
x.u);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetLastName(const Substring &x) {
|
|
|
|
return GetLastName(std::get<DataRef>(x.t));
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetLastName(const Designator &x) {
|
|
|
|
return std::visit(
|
|
|
|
[](const auto &y) -> const Name & { return GetLastName(y); }, x.u);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetLastName(const ProcComponentRef &x) {
|
|
|
|
return GetLastName(x.v.thing);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetLastName(const ProcedureDesignator &x) {
|
|
|
|
return std::visit(
|
|
|
|
[](const auto &y) -> const Name & { return GetLastName(y); }, x.u);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetLastName(const Call &x) {
|
|
|
|
return GetLastName(std::get<ProcedureDesignator>(x.t));
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetLastName(const FunctionReference &x) { return GetLastName(x.v); }
|
|
|
|
|
|
|
|
const Name &GetLastName(const Variable &x) {
|
|
|
|
return std::visit(
|
|
|
|
[](const auto &indirection) -> const Name & {
|
|
|
|
return GetLastName(indirection.value());
|
|
|
|
},
|
|
|
|
x.u);
|
|
|
|
}
|
2019-04-23 20:57:50 +08:00
|
|
|
|
|
|
|
const Name &GetLastName(const AllocateObject &x) {
|
|
|
|
return std::visit(
|
|
|
|
[](const auto &y) -> const Name & { return GetLastName(y); }, x.u);
|
|
|
|
}
|
[flang] Allocate semantic checks (second part)
Implement semantic checks and realted tests for constraints:
C937, C938, C939, C940, C941, C942, C945 (second part),
C946, C947, C948, C949 and C950.
Original-commit: flang-compiler/f18@b4965d272b1749d554e3d1388c0a7856591741e8
Tree-same-pre-rewrite: false
2019-04-26 16:10:04 +08:00
|
|
|
|
2020-06-19 08:17:04 +08:00
|
|
|
const Name &GetFirstName(const Name &x) { return x; }
|
|
|
|
|
|
|
|
const Name &GetFirstName(const StructureComponent &x) {
|
|
|
|
return GetFirstName(x.base);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetFirstName(const DataRef &x) {
|
|
|
|
return std::visit(
|
|
|
|
common::visitors{
|
|
|
|
[](const Name &name) -> const Name & { return name; },
|
|
|
|
[](const common::Indirection<StructureComponent> &sc)
|
|
|
|
-> const Name & { return GetFirstName(sc.value()); },
|
|
|
|
[](const common::Indirection<ArrayElement> &sc) -> const Name & {
|
|
|
|
return GetFirstName(sc.value().base);
|
|
|
|
},
|
|
|
|
[](const common::Indirection<CoindexedNamedObject> &ci)
|
|
|
|
-> const Name & { return GetFirstName(ci.value().base); },
|
|
|
|
},
|
|
|
|
x.u);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetFirstName(const Substring &x) {
|
|
|
|
return GetFirstName(std::get<DataRef>(x.t));
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetFirstName(const Designator &x) {
|
|
|
|
return std::visit(
|
|
|
|
[](const auto &y) -> const Name & { return GetFirstName(y); }, x.u);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetFirstName(const ProcComponentRef &x) {
|
|
|
|
return GetFirstName(x.v.thing);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetFirstName(const ProcedureDesignator &x) {
|
|
|
|
return std::visit(
|
|
|
|
[](const auto &y) -> const Name & { return GetFirstName(y); }, x.u);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetFirstName(const Call &x) {
|
|
|
|
return GetFirstName(std::get<ProcedureDesignator>(x.t));
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetFirstName(const FunctionReference &x) {
|
|
|
|
return GetFirstName(x.v);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Name &GetFirstName(const Variable &x) {
|
|
|
|
return std::visit(
|
|
|
|
[](const auto &indirect) -> const Name & {
|
|
|
|
return GetFirstName(indirect.value());
|
|
|
|
},
|
|
|
|
x.u);
|
|
|
|
}
|
|
|
|
|
[flang] Allocate semantic checks (second part)
Implement semantic checks and realted tests for constraints:
C937, C938, C939, C940, C941, C942, C945 (second part),
C946, C947, C948, C949 and C950.
Original-commit: flang-compiler/f18@b4965d272b1749d554e3d1388c0a7856591741e8
Tree-same-pre-rewrite: false
2019-04-26 16:10:04 +08:00
|
|
|
const CoindexedNamedObject *GetCoindexedNamedObject(const DataRef &base) {
|
|
|
|
return std::visit(
|
|
|
|
common::visitors{
|
|
|
|
[](const Name &) -> const CoindexedNamedObject * { return nullptr; },
|
|
|
|
[](const common::Indirection<CoindexedNamedObject> &x)
|
|
|
|
-> const CoindexedNamedObject * { return &x.value(); },
|
|
|
|
[](const auto &x) -> const CoindexedNamedObject * {
|
|
|
|
return GetCoindexedNamedObject(x.value().base);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
base.u);
|
|
|
|
}
|
2020-07-08 03:15:39 +08:00
|
|
|
const CoindexedNamedObject *GetCoindexedNamedObject(
|
|
|
|
const Designator &designator) {
|
|
|
|
return std::visit(common::visitors{
|
|
|
|
[](const DataRef &x) -> const CoindexedNamedObject * {
|
|
|
|
return GetCoindexedNamedObject(x);
|
|
|
|
},
|
|
|
|
[](const Substring &x) -> const CoindexedNamedObject * {
|
|
|
|
return GetCoindexedNamedObject(
|
|
|
|
std::get<DataRef>(x.t));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
designator.u);
|
|
|
|
}
|
|
|
|
const CoindexedNamedObject *GetCoindexedNamedObject(const Variable &variable) {
|
|
|
|
return std::visit(
|
|
|
|
common::visitors{
|
|
|
|
[](const common::Indirection<Designator> &designator)
|
|
|
|
-> const CoindexedNamedObject * {
|
|
|
|
return GetCoindexedNamedObject(designator.value());
|
|
|
|
},
|
|
|
|
[](const auto &) -> const CoindexedNamedObject * { return nullptr; },
|
|
|
|
},
|
|
|
|
variable.u);
|
|
|
|
}
|
[flang] Allocate semantic checks (second part)
Implement semantic checks and realted tests for constraints:
C937, C938, C939, C940, C941, C942, C945 (second part),
C946, C947, C948, C949 and C950.
Original-commit: flang-compiler/f18@b4965d272b1749d554e3d1388c0a7856591741e8
Tree-same-pre-rewrite: false
2019-04-26 16:10:04 +08:00
|
|
|
const CoindexedNamedObject *GetCoindexedNamedObject(
|
|
|
|
const AllocateObject &allocateObject) {
|
|
|
|
return std::visit(
|
|
|
|
common::visitors{
|
|
|
|
[](const StructureComponent &x) -> const CoindexedNamedObject * {
|
|
|
|
return GetCoindexedNamedObject(x.base);
|
|
|
|
},
|
2019-08-16 04:50:27 +08:00
|
|
|
[](const auto &) -> const CoindexedNamedObject * { return nullptr; },
|
[flang] Allocate semantic checks (second part)
Implement semantic checks and realted tests for constraints:
C937, C938, C939, C940, C941, C942, C945 (second part),
C946, C947, C948, C949 and C950.
Original-commit: flang-compiler/f18@b4965d272b1749d554e3d1388c0a7856591741e8
Tree-same-pre-rewrite: false
2019-04-26 16:10:04 +08:00
|
|
|
},
|
|
|
|
allocateObject.u);
|
|
|
|
}
|
2020-03-29 12:00:16 +08:00
|
|
|
} // namespace Fortran::parser
|