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.
ENUM_CLASS(TypeCategory,Integer,Real,Complex,Character,Logical,Derived)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 Carriagecontrol, // nonstandard
56 Convert, // nonstandard
57 Dispose, // nonstandard
58 )
59
60 // Floating-point rounding modes; these are packed into a byte to save
61 // room in the runtime's format processing context structure.
62 enum class RoundingMode : std::uint8_t {
63 TiesToEven, // ROUND=NEAREST, RN - default IEEE rounding
64 ToZero, // ROUND=ZERO, RZ - truncation
65 Down, // ROUND=DOWN, RD
66 Up, // ROUND=UP, RU
67 TiesAwayFromZero, // ROUND=COMPATIBLE, RC - ties round away from zero
68 };
69
70 // Fortran arrays may have up to 15 dimensions (See Fortran 2018 section 5.4.6).
71 static constexpr int maxRank{15};
72 } // namespace Fortran::common
73 #endif // FORTRAN_COMMON_FORTRAN_H_
74