Warning: This file is not a C or C++ file. It does not have highlighting.

1//===-- Lower/ConvertType.h -- lowering of types ----------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10//
11//===----------------------------------------------------------------------===//
12///
13/// Conversion of front-end TYPE, KIND, ATTRIBUTE (TKA) information to FIR/MLIR.
14/// This is meant to be the single point of truth (SPOT) for all type
15/// conversions when lowering to FIR. This implements all lowering of parse
16/// tree TKA to the FIR type system. If one is converting front-end types and
17/// not using one of the routines provided here, it's being done wrong.
18///
19//===----------------------------------------------------------------------===//
20
21#ifndef FORTRAN_LOWER_CONVERT_TYPE_H
22#define FORTRAN_LOWER_CONVERT_TYPE_H
23
24#include "flang/Common/Fortran.h"
25#include "flang/Evaluate/type.h"
26#include "mlir/IR/BuiltinTypes.h"
27
28namespace mlir {
29class Location;
30class MLIRContext;
31class Type;
32} // namespace mlir
33
34namespace Fortran {
35namespace common {
36template <typename>
37class Reference;
38} // namespace common
39
40namespace evaluate {
41template <typename>
42class Expr;
43template <typename>
44class FunctionRef;
45struct SomeType;
46} // namespace evaluate
47
48namespace semantics {
49class Symbol;
50class DerivedTypeSpec;
51class DerivedTypeDetails;
52class Scope;
53} // namespace semantics
54
55namespace lower {
56class AbstractConverter;
57namespace pft {
58struct Variable;
59}
60
61using SomeExpr = evaluate::Expr<evaluate::SomeType>;
62using SymbolRef = common::Reference<const semantics::Symbol>;
63
64// Type for compile time constant length type parameters.
65using LenParameterTy = std::int64_t;
66
67/// Get a FIR type based on a category and kind.
68mlir::Type getFIRType(mlir::MLIRContext *ctxt, common::TypeCategory tc,
69 int kind, llvm::ArrayRef<LenParameterTy>);
70
71/// Get a FIR type for a derived type
72mlir::Type
73translateDerivedTypeToFIRType(Fortran::lower::AbstractConverter &,
74 const Fortran::semantics::DerivedTypeSpec &);
75
76/// Translate a SomeExpr to an mlir::Type.
77mlir::Type translateSomeExprToFIRType(Fortran::lower::AbstractConverter &,
78 const SomeExpr &expr);
79
80/// Translate a Fortran::semantics::Symbol to an mlir::Type.
81mlir::Type translateSymbolToFIRType(Fortran::lower::AbstractConverter &,
82 const SymbolRef symbol);
83
84/// Translate a Fortran::lower::pft::Variable to an mlir::Type.
85mlir::Type translateVariableToFIRType(Fortran::lower::AbstractConverter &,
86 const pft::Variable &variable);
87
88/// Translate a REAL of KIND to the mlir::Type.
89mlir::Type convertReal(mlir::MLIRContext *ctxt, int KIND);
90
91bool isDerivedTypeWithLenParameters(const semantics::Symbol &);
92
93template <typename T>
94class TypeBuilder {
95public:
96 static mlir::Type genType(Fortran::lower::AbstractConverter &,
97 const Fortran::evaluate::FunctionRef<T> &);
98};
99using namespace evaluate;
100FOR_EACH_SPECIFIC_TYPE(extern template class TypeBuilder, )
101
102/// A helper class to reverse iterate through the component names of a derived
103/// type, including the parent component and the component of the parents. This
104/// is useful to deal with StructureConstructor lowering.
105class ComponentReverseIterator {
106public:
107 ComponentReverseIterator(const Fortran::semantics::DerivedTypeSpec &derived) {
108 setCurrentType(derived);
109 }
110 /// Does the current type has a component with \name (does not look-up the
111 /// components of the parent if any)? If there is a match, the iterator
112 /// is advanced to the search result.
113 bool lookup(const Fortran::parser::CharBlock &name) {
114 componentIt = std::find(componentIt, componentItEnd, name);
115 return componentIt != componentItEnd;
116 };
117
118 /// Advance iterator to the last components of the current type parent.
119 const Fortran::semantics::DerivedTypeSpec &advanceToParentType();
120
121private:
122 void setCurrentType(const Fortran::semantics::DerivedTypeSpec &derived);
123 const Fortran::semantics::DerivedTypeSpec *currentParentType = nullptr;
124 const Fortran::semantics::DerivedTypeDetails *currentTypeDetails = nullptr;
125 using name_iterator =
126 std::list<Fortran::parser::CharBlock>::const_reverse_iterator;
127 name_iterator componentIt{};
128 name_iterator componentItEnd{};
129};
130} // namespace lower
131} // namespace Fortran
132
133#endif // FORTRAN_LOWER_CONVERT_TYPE_H
134

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of flang/include/flang/Lower/ConvertType.h