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
18namespace Fortran::runtime {
19
20class Descriptor;
21
22template <typename CHAR>
23RT_API_ATTRS int CharacterScalarCompare(
24 const CHAR *x, const CHAR *y, std::size_t xChars, std::size_t yChars);
25extern template RT_API_ATTRS int CharacterScalarCompare<char>(
26 const char *x, const char *y, std::size_t xChars, std::size_t yChars);
27extern 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);
30extern 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
34extern "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.
41void RTDECL(CharacterConcatenate)(Descriptor &accumulator,
42 const Descriptor &from, const char *sourceFile = nullptr,
43 int sourceLine = 0);
44
45// Convenience specialization for ASCII scalars concatenation.
46void 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.
57int RTDECL(CharacterCompareScalar)(const Descriptor &, const Descriptor &);
58int RTDECL(CharacterCompareScalar1)(
59 const char *x, const char *y, std::size_t xChars, std::size_t yChars);
60int RTDECL(CharacterCompareScalar2)(const char16_t *x, const char16_t *y,
61 std::size_t xChars, std::size_t yChars);
62int 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.
67void 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.
74std::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.
78void 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.
82void RTDECL(Adjustl)(Descriptor &result, const Descriptor &,
83 const char *sourceFile = nullptr, int sourceLine = 0);
84void RTDECL(Adjustr)(Descriptor &result, const Descriptor &,
85 const char *sourceFile = nullptr, int sourceLine = 0);
86std::size_t RTDECL(LenTrim1)(const char *, std::size_t);
87std::size_t RTDECL(LenTrim2)(const char16_t *, std::size_t);
88std::size_t RTDECL(LenTrim4)(const char32_t *, std::size_t);
89void RTDECL(LenTrim)(Descriptor &result, const Descriptor &, int kind,
90 const char *sourceFile = nullptr, int sourceLine = 0);
91void RTDECL(Repeat)(Descriptor &result, const Descriptor &string,
92 std::int64_t ncopies, const char *sourceFile = nullptr, int sourceLine = 0);
93void RTDECL(Trim)(Descriptor &result, const Descriptor &string,
94 const char *sourceFile = nullptr, int sourceLine = 0);
95
96void RTDECL(CharacterMax)(Descriptor &accumulator, const Descriptor &x,
97 const char *sourceFile = nullptr, int sourceLine = 0);
98void RTDECL(CharacterMin)(Descriptor &accumulator, const Descriptor &x,
99 const char *sourceFile = nullptr, int sourceLine = 0);
100
101std::size_t RTDECL(Index1)(const char *, std::size_t, const char *substring,
102 std::size_t, bool back = false);
103std::size_t RTDECL(Index2)(const char16_t *, std::size_t,
104 const char16_t *substring, std::size_t, bool back = false);
105std::size_t RTDECL(Index4)(const char32_t *, std::size_t,
106 const char32_t *substring, std::size_t, bool back = false);
107void 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
111std::size_t RTDECL(Scan1)(
112 const char *, std::size_t, const char *set, std::size_t, bool back = false);
113std::size_t RTDECL(Scan2)(const char16_t *, std::size_t, const char16_t *set,
114 std::size_t, bool back = false);
115std::size_t RTDECL(Scan4)(const char32_t *, std::size_t, const char32_t *set,
116 std::size_t, bool back = false);
117void 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
121std::size_t RTDECL(Verify1)(
122 const char *, std::size_t, const char *set, std::size_t, bool back = false);
123std::size_t RTDECL(Verify2)(const char16_t *, std::size_t, const char16_t *set,
124 std::size_t, bool back = false);
125std::size_t RTDECL(Verify4)(const char32_t *, std::size_t, const char32_t *set,
126 std::size_t, bool back = false);
127void 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.

source code of flang/include/flang/Runtime/character.h