1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_RUNTIME_STRING_BUILDER_APPEND_H_
18 #define ART_RUNTIME_STRING_BUILDER_APPEND_H_
19 
20 #include <stddef.h>
21 #include <stdint.h>
22 
23 #include "base/bit_utils.h"
24 #include "base/locks.h"
25 #include "obj_ptr.h"
26 
27 namespace art {
28 
29 class Thread;
30 
31 namespace mirror {
32 class String;
33 }  // namespace mirror
34 
35 class StringBuilderAppend {
36  public:
37   enum class Argument : uint8_t {
38     kEnd = 0u,
39     kObject,
40     kStringBuilder,
41     kString,
42     kCharArray,
43     kBoolean,
44     kChar,
45     kInt,
46     kLong,
47     kFloat,
48     kDouble,
49     kLast = kDouble
50   };
51 
52   static constexpr size_t kBitsPerArg =
53       MinimumBitsToStore(static_cast<size_t>(Argument::kLast));
54   static constexpr size_t kMaxArgs = BitSizeOf<uint32_t>() / kBitsPerArg;
55   static_assert(kMaxArgs * kBitsPerArg == BitSizeOf<uint32_t>(), "Expecting no extra bits.");
56   static constexpr uint32_t kArgMask = MaxInt<uint32_t>(kBitsPerArg);
57 
58   static ObjPtr<mirror::String> AppendF(uint32_t format, const uint32_t* args, Thread* self)
59       REQUIRES_SHARED(Locks::mutator_lock_);
60 
61  private:
62   class Builder;
63 };
64 
65 }  // namespace art
66 
67 #endif  // ART_RUNTIME_STRING_BUILDER_APPEND_H_
68