aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/AST/Interp/Source.h
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/AST/Interp/Source.h')
-rw-r--r--contrib/llvm-project/clang/lib/AST/Interp/Source.h55
1 files changed, 24 insertions, 31 deletions
diff --git a/contrib/llvm-project/clang/lib/AST/Interp/Source.h b/contrib/llvm-project/clang/lib/AST/Interp/Source.h
index 19c652b7331a..c28b488ff554 100644
--- a/contrib/llvm-project/clang/lib/AST/Interp/Source.h
+++ b/contrib/llvm-project/clang/lib/AST/Interp/Source.h
@@ -13,16 +13,21 @@
#ifndef LLVM_CLANG_AST_INTERP_SOURCE_H
#define LLVM_CLANG_AST_INTERP_SOURCE_H
-#include "clang/AST/Decl.h"
+#include "PrimType.h"
+#include "clang/AST/DeclBase.h"
#include "clang/AST/Stmt.h"
+#include "llvm/ADT/PointerUnion.h"
#include "llvm/Support/Endian.h"
namespace clang {
+class Expr;
+class SourceLocation;
+class SourceRange;
namespace interp {
class Function;
/// Pointer into the code segment.
-class CodePtr {
+class CodePtr final {
public:
CodePtr() : Ptr(nullptr) {}
@@ -42,49 +47,36 @@ public:
}
bool operator!=(const CodePtr &RHS) const { return Ptr != RHS.Ptr; }
+ const std::byte *operator*() const { return Ptr; }
- /// Reads data and advances the pointer.
- template <typename T> T read() {
- T Value = ReadHelper<T>(Ptr);
- Ptr += sizeof(T);
- return Value;
- }
+ operator bool() const { return Ptr; }
-private:
- /// Constructor used by Function to generate pointers.
- CodePtr(const char *Ptr) : Ptr(Ptr) {}
-
- /// Helper to decode a value or a pointer.
- template <typename T>
- static std::enable_if_t<!std::is_pointer<T>::value, T>
- ReadHelper(const char *Ptr) {
- using namespace llvm::support;
- return endian::read<T, endianness::native, 1>(Ptr);
- }
-
- template <typename T>
- static std::enable_if_t<std::is_pointer<T>::value, T>
- ReadHelper(const char *Ptr) {
+ /// Reads data and advances the pointer.
+ template <typename T> std::enable_if_t<!std::is_pointer<T>::value, T> read() {
+ assert(aligned(Ptr));
using namespace llvm::support;
- auto Punned = endian::read<uintptr_t, endianness::native, 1>(Ptr);
- return reinterpret_cast<T>(Punned);
+ T Value = endian::read<T, llvm::endianness::native>(Ptr);
+ Ptr += align(sizeof(T));
+ return Value;
}
private:
friend class Function;
-
+ /// Constructor used by Function to generate pointers.
+ CodePtr(const std::byte *Ptr) : Ptr(Ptr) {}
/// Pointer into the code owned by a function.
- const char *Ptr;
+ const std::byte *Ptr;
};
/// Describes the statement/declaration an opcode was generated from.
-class SourceInfo {
+class SourceInfo final {
public:
SourceInfo() {}
SourceInfo(const Stmt *E) : Source(E) {}
SourceInfo(const Decl *D) : Source(D) {}
SourceLocation getLoc() const;
+ SourceRange getRange() const;
const Stmt *asStmt() const { return Source.dyn_cast<const Stmt *>(); }
const Decl *asDecl() const { return Source.dyn_cast<const Decl *>(); }
@@ -104,12 +96,13 @@ public:
virtual ~SourceMapper() {}
/// Returns source information for a given PC in a function.
- virtual SourceInfo getSource(Function *F, CodePtr PC) const = 0;
+ virtual SourceInfo getSource(const Function *F, CodePtr PC) const = 0;
/// Returns the expression if an opcode belongs to one, null otherwise.
- const Expr *getExpr(Function *F, CodePtr PC) const;
+ const Expr *getExpr(const Function *F, CodePtr PC) const;
/// Returns the location from which an opcode originates.
- SourceLocation getLocation(Function *F, CodePtr PC) const;
+ SourceLocation getLocation(const Function *F, CodePtr PC) const;
+ SourceRange getRange(const Function *F, CodePtr PC) const;
};
} // namespace interp