clang
22.0.0git
include
clang
AST
APNumericStorage.h
Go to the documentation of this file.
1
//===--- APNumericStorage.h - Store APInt/APFloat in ASTContext -*- 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
#ifndef LLVM_CLANG_AST_APNUMERICSTORAGE_H
10
#define LLVM_CLANG_AST_APNUMERICSTORAGE_H
11
12
#include "llvm/ADT/APFloat.h"
13
#include "llvm/ADT/APInt.h"
14
15
namespace
clang
{
16
class
ASTContext
;
17
18
/// Used by IntegerLiteral/FloatingLiteral/EnumConstantDecl to store the
19
/// numeric without leaking memory.
20
///
21
/// For large floats/integers, APFloat/APInt will allocate memory from the heap
22
/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator
23
/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
24
/// the APFloat/APInt values will never get freed. APNumericStorage uses
25
/// ASTContext's allocator for memory allocation.
26
class
APNumericStorage {
27
union
{
28
uint64_t
VAL
;
///< Used to store the <= 64 bits integer value.
29
uint64_t *
pVal
;
///< Used to store the >64 bits integer value.
30
};
31
32
bool
hasAllocation()
const
{
return
llvm::APInt::getNumWords(
BitWidth
) > 1; }
33
34
APNumericStorage
(
const
APNumericStorage
&) =
delete
;
35
void
operator=(
const
APNumericStorage
&) =
delete
;
36
37
protected
:
38
unsigned
BitWidth
;
39
APNumericStorage
() :
VAL
(0),
BitWidth
(0) {}
40
41
llvm::APInt
getIntValue
()
const
{
42
unsigned
NumWords = llvm::APInt::getNumWords(
BitWidth
);
43
if
(NumWords > 1)
44
return
llvm::APInt(
BitWidth
,
llvm::ArrayRef
(
pVal
, NumWords));
45
return
llvm::APInt(
BitWidth
,
VAL
);
46
}
47
void
setIntValue
(
const
ASTContext
&
C
,
const
llvm::APInt &Val);
48
};
49
50
class
APIntStorage
:
private
APNumericStorage {
51
public
:
52
llvm::APInt
getValue
()
const
{
return
getIntValue
(); }
53
unsigned
getBitWidth
()
const
{
return
BitWidth
; }
54
void
setValue
(
const
ASTContext
&
C
,
const
llvm::APInt &Val) {
55
setIntValue
(
C
, Val);
56
}
57
};
58
59
class
APFloatStorage
:
private
APNumericStorage {
60
public
:
61
llvm::APFloat
getValue
(
const
llvm::fltSemantics &Semantics)
const
{
62
return
llvm::APFloat(Semantics,
getIntValue
());
63
}
64
void
setValue
(
const
ASTContext
&
C
,
const
llvm::APFloat &Val) {
65
setIntValue
(
C
, Val.bitcastToAPInt());
66
}
67
};
68
69
}
// end namespace clang
70
71
#endif
// LLVM_CLANG_AST_APNUMERICSTORAGE_H
clang::APFloatStorage
Definition
APNumericStorage.h:59
clang::APFloatStorage::getValue
llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const
Definition
APNumericStorage.h:61
clang::APFloatStorage::setValue
void setValue(const ASTContext &C, const llvm::APFloat &Val)
Definition
APNumericStorage.h:64
clang::APIntStorage
Definition
APNumericStorage.h:50
clang::APIntStorage::getBitWidth
unsigned getBitWidth() const
Definition
APNumericStorage.h:53
clang::APIntStorage::setValue
void setValue(const ASTContext &C, const llvm::APInt &Val)
Definition
APNumericStorage.h:54
clang::APIntStorage::getValue
llvm::APInt getValue() const
Definition
APNumericStorage.h:52
clang::APNumericStorage::pVal
uint64_t * pVal
Used to store the >64 bits integer value.
Definition
APNumericStorage.h:29
clang::APNumericStorage::VAL
uint64_t VAL
Used to store the <= 64 bits integer value.
Definition
APNumericStorage.h:28
clang::APNumericStorage::getIntValue
llvm::APInt getIntValue() const
Definition
APNumericStorage.h:41
clang::APNumericStorage::BitWidth
unsigned BitWidth
Definition
APNumericStorage.h:38
clang::APNumericStorage::APNumericStorage
APNumericStorage()
Definition
APNumericStorage.h:39
clang::APNumericStorage::setIntValue
void setIntValue(const ASTContext &C, const llvm::APInt &Val)
Definition
Expr.cpp:943
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition
ASTContext.h:220
llvm::ArrayRef
Definition
LLVM.h:31
clang
The JSON file list parser is used to communicate input to InstallAPI.
Definition
CalledOnceCheck.h:17
clang::LinkageSpecLanguageIDs::C
@ C
Definition
DeclCXX.h:3007
Generated on
for clang by
1.14.0