Warning: This file is not a C or C++ file. It does not have highlighting.
1 | //===-- include/flang/Runtime/character.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 | // Defines API between compiled code and the CHARACTER |
10 | // support functions in the runtime library. |
11 | |
12 | #ifndef FORTRAN_RUNTIME_CHARACTER_H_ |
13 | #define FORTRAN_RUNTIME_CHARACTER_H_ |
14 | #include "flang/Runtime/entry-names.h" |
15 | #include <cstddef> |
16 | #include <cstdint> |
17 | |
18 | namespace Fortran::runtime { |
19 | |
20 | class Descriptor; |
21 | |
22 | template <typename CHAR> |
23 | RT_API_ATTRS int CharacterScalarCompare( |
24 | const CHAR *x, const CHAR *y, std::size_t xChars, std::size_t yChars); |
25 | extern template RT_API_ATTRS int CharacterScalarCompare<char>( |
26 | const char *x, const char *y, std::size_t xChars, std::size_t yChars); |
27 | extern template RT_API_ATTRS int CharacterScalarCompare<char16_t>( |
28 | const char16_t *x, const char16_t *y, std::size_t xChars, |
29 | std::size_t yChars); |
30 | extern template RT_API_ATTRS int CharacterScalarCompare<char32_t>( |
31 | const char32_t *x, const char32_t *y, std::size_t xChars, |
32 | std::size_t yChars); |
33 | |
34 | extern "C" { |
35 | |
36 | // Appends the corresponding (or expanded) characters of 'operand' |
37 | // to the (elements of) a (re)allocation of 'accumulator', which must be an |
38 | // initialized CHARACTER allocatable scalar or array descriptor -- use |
39 | // AllocatableInitCharacter() to set one up. Crashes when not |
40 | // conforming. Assumes independence of data. |
41 | void RTDECL(CharacterConcatenate)(Descriptor &accumulator, |
42 | const Descriptor &from, const char *sourceFile = nullptr, |
43 | int sourceLine = 0); |
44 | |
45 | // Convenience specialization for ASCII scalars concatenation. |
46 | void RTDECL(CharacterConcatenateScalar1)( |
47 | Descriptor &accumulator, const char *from, std::size_t chars); |
48 | |
49 | // CHARACTER comparisons. The kinds must match. Like std::memcmp(), |
50 | // the result is less than zero, zero, or greater than zero if the first |
51 | // argument is less than the second, equal to the second, or greater than |
52 | // the second, respectively. The shorter argument is treated as if it were |
53 | // padded on the right with blanks. |
54 | // N.B.: Calls to the restricted specific intrinsic functions LGE, LGT, LLE, |
55 | // & LLT are converted into calls to these during lowering; they don't have |
56 | // to be able to be passed as actual procedure arguments. |
57 | int RTDECL(CharacterCompareScalar)(const Descriptor &, const Descriptor &); |
58 | int RTDECL(CharacterCompareScalar1)( |
59 | const char *x, const char *y, std::size_t xChars, std::size_t yChars); |
60 | int RTDECL(CharacterCompareScalar2)(const char16_t *x, const char16_t *y, |
61 | std::size_t xChars, std::size_t yChars); |
62 | int RTDECL(CharacterCompareScalar4)(const char32_t *x, const char32_t *y, |
63 | std::size_t xChars, std::size_t yChars); |
64 | |
65 | // General CHARACTER comparison; the result is a LOGICAL(KIND=1) array that |
66 | // is established and populated. |
67 | void RTDECL(CharacterCompare)( |
68 | Descriptor &result, const Descriptor &, const Descriptor &); |
69 | |
70 | // Special-case support for optimized ASCII scalar expressions. |
71 | |
72 | // Copies data from 'rhs' to the remaining space (lhsLength - offset) |
73 | // in 'lhs', if any. Returns the new offset. Assumes independence. |
74 | std::size_t RTDECL(CharacterAppend1)(char *lhs, std::size_t lhsBytes, |
75 | std::size_t offset, const char *rhs, std::size_t rhsBytes); |
76 | |
77 | // Appends any necessary spaces to a CHARACTER(KIND=1) scalar. |
78 | void RTDECL(CharacterPad1)(char *lhs, std::size_t bytes, std::size_t offset); |
79 | |
80 | // Intrinsic functions |
81 | // The result descriptors below are all established by the runtime. |
82 | void RTDECL(Adjustl)(Descriptor &result, const Descriptor &, |
83 | const char *sourceFile = nullptr, int sourceLine = 0); |
84 | void RTDECL(Adjustr)(Descriptor &result, const Descriptor &, |
85 | const char *sourceFile = nullptr, int sourceLine = 0); |
86 | std::size_t RTDECL(LenTrim1)(const char *, std::size_t); |
87 | std::size_t RTDECL(LenTrim2)(const char16_t *, std::size_t); |
88 | std::size_t RTDECL(LenTrim4)(const char32_t *, std::size_t); |
89 | void RTDECL(LenTrim)(Descriptor &result, const Descriptor &, int kind, |
90 | const char *sourceFile = nullptr, int sourceLine = 0); |
91 | void RTDECL(Repeat)(Descriptor &result, const Descriptor &string, |
92 | std::int64_t ncopies, const char *sourceFile = nullptr, int sourceLine = 0); |
93 | void RTDECL(Trim)(Descriptor &result, const Descriptor &string, |
94 | const char *sourceFile = nullptr, int sourceLine = 0); |
95 | |
96 | void RTDECL(CharacterMax)(Descriptor &accumulator, const Descriptor &x, |
97 | const char *sourceFile = nullptr, int sourceLine = 0); |
98 | void RTDECL(CharacterMin)(Descriptor &accumulator, const Descriptor &x, |
99 | const char *sourceFile = nullptr, int sourceLine = 0); |
100 | |
101 | std::size_t RTDECL(Index1)(const char *, std::size_t, const char *substring, |
102 | std::size_t, bool back = false); |
103 | std::size_t RTDECL(Index2)(const char16_t *, std::size_t, |
104 | const char16_t *substring, std::size_t, bool back = false); |
105 | std::size_t RTDECL(Index4)(const char32_t *, std::size_t, |
106 | const char32_t *substring, std::size_t, bool back = false); |
107 | void RTDECL(Index)(Descriptor &result, const Descriptor &string, |
108 | const Descriptor &substring, const Descriptor *back /*can be null*/, |
109 | int kind, const char *sourceFile = nullptr, int sourceLine = 0); |
110 | |
111 | std::size_t RTDECL(Scan1)( |
112 | const char *, std::size_t, const char *set, std::size_t, bool back = false); |
113 | std::size_t RTDECL(Scan2)(const char16_t *, std::size_t, const char16_t *set, |
114 | std::size_t, bool back = false); |
115 | std::size_t RTDECL(Scan4)(const char32_t *, std::size_t, const char32_t *set, |
116 | std::size_t, bool back = false); |
117 | void RTDECL(Scan)(Descriptor &result, const Descriptor &string, |
118 | const Descriptor &set, const Descriptor *back /*can be null*/, int kind, |
119 | const char *sourceFile = nullptr, int sourceLine = 0); |
120 | |
121 | std::size_t RTDECL(Verify1)( |
122 | const char *, std::size_t, const char *set, std::size_t, bool back = false); |
123 | std::size_t RTDECL(Verify2)(const char16_t *, std::size_t, const char16_t *set, |
124 | std::size_t, bool back = false); |
125 | std::size_t RTDECL(Verify4)(const char32_t *, std::size_t, const char32_t *set, |
126 | std::size_t, bool back = false); |
127 | void RTDECL(Verify)(Descriptor &result, const Descriptor &string, |
128 | const Descriptor &set, const Descriptor *back /*can be null*/, int kind, |
129 | const char *sourceFile = nullptr, int sourceLine = 0); |
130 | } |
131 | } // namespace Fortran::runtime |
132 | #endif // FORTRAN_RUNTIME_CHARACTER_H_ |
133 |
Warning: This file is not a C or C++ file. It does not have highlighting.