Debian Codegraph @

clang/lib/AST/ByteCode/InitMap.cpp

raw
1 //===----------------------- InitMap.cpp ------------------------*- 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 #include "InitMap.h"
9
10 using namespace clang;
11 using namespace clang::interp;
12
13 InitMap::InitMap(unsigned N)
14 : UninitFields(N), Data(std::make_unique<T[]>(numFields(N))) {}
15
16 bool InitMap::initializeElement(unsigned I) {
17 unsigned Bucket = I / PER_FIELD;
18 T Mask = T(1) << (I % PER_FIELD);
19 if (!(data()[Bucket] & Mask)) {
20 data()[Bucket] |= Mask;
21 UninitFields -= 1;
22 }
23 return UninitFields == 0;
24 }
25
26 bool InitMap::isElementInitialized(unsigned I) const {
27 if (UninitFields == 0)
28 return true;
29 unsigned Bucket = I / PER_FIELD;
30 return data()[Bucket] & (T(1) << (I % PER_FIELD));
31 }