// Symbol and expression type translation
//===--------------------------------------------------------------------===//
-/// TypeBuilder translates expression and symbol type taking into account
+/// TypeBuilderImpl translates expression and symbol type taking into account
/// their shape and length parameters. For symbols, attributes such as
/// ALLOCATABLE or POINTER are reflected in the fir type.
/// It uses evaluate::DynamicType and evaluate::Shape when possible to
/// Do not use the FirOpBuilder from the AbstractConverter to get fir/mlir types
/// since it is not guaranteed to exist yet when we lower types.
namespace {
-struct TypeBuilder {
+struct TypeBuilderImpl {
- TypeBuilder(Fortran::lower::AbstractConverter &converter)
+ TypeBuilderImpl(Fortran::lower::AbstractConverter &converter)
: converter{converter}, context{&converter.getMLIRContext()} {}
- mlir::Type genExprType(const Fortran::lower::SomeExpr &expr) {
+ template <typename A>
+ mlir::Type genExprType(const A &expr) {
std::optional<Fortran::evaluate::DynamicType> dynamicType = expr.GetType();
if (!dynamicType)
return genTypelessExprType(expr);
converter.getFoldingContext(), std::move(expr)));
}
+ template <typename A>
+ mlir::Type genTypelessExprType(const A &expr) {
+ fir::emitFatalError(converter.getCurrentLocation(), "not a typeless expr");
+ }
+
mlir::Type genTypelessExprType(const Fortran::lower::SomeExpr &expr) {
return std::visit(
Fortran::common::visitors{
}
llvm_unreachable("unknown character kind");
}
+
+ template <typename A>
+ Fortran::lower::LenParameterTy getCharacterLength(const A &expr) {
+ return fir::SequenceType::getUnknownExtent();
+ }
Fortran::lower::LenParameterTy
getCharacterLength(const Fortran::lower::SomeExpr &expr) {
// Do not use dynamic type length here. We would miss constant
mlir::Type Fortran::lower::translateDerivedTypeToFIRType(
Fortran::lower::AbstractConverter &converter,
const Fortran::semantics::DerivedTypeSpec &tySpec) {
- return TypeBuilder{converter}.genDerivedType(tySpec);
+ return TypeBuilderImpl{converter}.genDerivedType(tySpec);
}
mlir::Type Fortran::lower::translateSomeExprToFIRType(
Fortran::lower::AbstractConverter &converter, const SomeExpr &expr) {
- return TypeBuilder{converter}.genExprType(expr);
+ return TypeBuilderImpl{converter}.genExprType(expr);
}
mlir::Type Fortran::lower::translateSymbolToFIRType(
Fortran::lower::AbstractConverter &converter, const SymbolRef symbol) {
- return TypeBuilder{converter}.genSymbolType(symbol);
+ return TypeBuilderImpl{converter}.genSymbolType(symbol);
}
mlir::Type Fortran::lower::translateVariableToFIRType(
Fortran::lower::AbstractConverter &converter,
const Fortran::lower::pft::Variable &var) {
- return TypeBuilder{converter}.genVariableType(var);
+ return TypeBuilderImpl{converter}.genVariableType(var);
}
mlir::Type Fortran::lower::convertReal(mlir::MLIRContext *context, int kind) {
return genRealType(context, kind);
}
+
+template <typename T>
+mlir::Type Fortran::lower::TypeBuilder<T>::genType(
+ Fortran::lower::AbstractConverter &converter,
+ const Fortran::evaluate::FunctionRef<T> &funcRef) {
+ return TypeBuilderImpl{converter}.genExprType(funcRef);
+}
+
+using namespace Fortran::evaluate;
+using namespace Fortran::common;
+FOR_EACH_SPECIFIC_TYPE(template class Fortran::lower::TypeBuilder, )