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