FLANG

Fortran.h
1 //===-- include/flang/Common/Fortran.h --------------------------*- 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 #ifndef FORTRAN_COMMON_FORTRAN_H_
10 #define FORTRAN_COMMON_FORTRAN_H_
11
12 // Fortran language concepts that are used in many phases are defined
13 // once here to avoid redundancy and needless translation.
14
15 #include "idioms.h"
16 #include <cinttypes>
17 #include <vector>
18
19 namespace Fortran::common {
20
21 // Fortran has five kinds of intrinsic data types, plus the derived types.
22 ENUM_CLASS(TypeCategory, Integer, Real, Complex, Character, Logical, Derived)
23
24 constexpr bool IsNumericTypeCategory(TypeCategory category) {
25 return category == TypeCategory::Integer || category == TypeCategory::Real ||
26 category == TypeCategory::Complex;
27 }
28
29 // Kinds of IMPORT statements. Default means IMPORT or IMPORT :: names.
30 ENUM_CLASS(ImportKind, Default, Only, None, All)
31
32 // The attribute on a type parameter can be KIND or LEN.
33 ENUM_CLASS(TypeParamAttr, Kind, Len)
34
35 ENUM_CLASS(NumericOperator, Power, Multiply, Divide, Add, Subtract)
36 const char *AsFortran(NumericOperator);
37
38 ENUM_CLASS(LogicalOperator, And, Or, Eqv, Neqv, Not)
39 const char *AsFortran(LogicalOperator);
40
41 ENUM_CLASS(RelationalOperator, LT, LE, EQ, NE, GE, GT)
42 const char *AsFortran(RelationalOperator);
43
44 ENUM_CLASS(Intent, Default, In, Out, InOut)
45
46 ENUM_CLASS(IoStmtKind, None, Backspace, Close, Endfile, Flush, Inquire, Open,
47 Print, Read, Rewind, Wait, Write)
48
49 // Union of specifiers for all I/O statements.
50 ENUM_CLASS(IoSpecKind, Access, Action, Advance, Asynchronous, Blank, Decimal,
51 Delim, Direct, Encoding, End, Eor, Err, Exist, File, Fmt, Form, Formatted,
52 Id, Iomsg, Iostat, Name, Named, Newunit, Nextrec, Nml, Number, Opened, Pad,
53 Pending, Pos, Position, Read, Readwrite, Rec, Recl, Round, Sequential, Sign,
54 Size, Status, Stream, Unformatted, Unit, Write,
55 Convert, // nonstandard
56 Dispose, // nonstandard
57 )
58
59 // Floating-point rounding modes; these are packed into a byte to save
60 // room in the runtime's format processing context structure.
61 enum class RoundingMode : std::uint8_t {
62 TiesToEven, // ROUND=NEAREST, RN - default IEEE rounding
63 ToZero, // ROUND=ZERO, RZ - truncation
64 Down, // ROUND=DOWN, RD
65 Up, // ROUND=UP, RU
66 TiesAwayFromZero, // ROUND=COMPATIBLE, RC - ties round away from zero
67 };
68
69 // Fortran arrays may have up to 15 dimensions (See Fortran 2018 section 5.4.6).
70 static constexpr int maxRank{15};
71 } // namespace Fortran::common
72 #endif // FORTRAN_COMMON_FORTRAN_H_