From 7c4cad43309ebce4a9f3c656ca4629f8ac9ed877 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Thu, 15 Sep 2022 15:36:51 +0200 Subject: [PATCH] [clang][Interp][NFC] Make a few InterpStack functions const --- clang/lib/AST/Interp/InterpStack.cpp | 2 +- clang/lib/AST/Interp/InterpStack.h | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/clang/lib/AST/Interp/InterpStack.cpp b/clang/lib/AST/Interp/InterpStack.cpp index 5c803f3..7fe678e 100644 --- a/clang/lib/AST/Interp/InterpStack.cpp +++ b/clang/lib/AST/Interp/InterpStack.cpp @@ -46,7 +46,7 @@ void *InterpStack::grow(size_t Size) { return Object; } -void *InterpStack::peek(size_t Size) { +void *InterpStack::peek(size_t Size) const { assert(Chunk && "Stack is empty!"); StackChunk *Ptr = Chunk; diff --git a/clang/lib/AST/Interp/InterpStack.h b/clang/lib/AST/Interp/InterpStack.h index b02d3c6..2888f88 100644 --- a/clang/lib/AST/Interp/InterpStack.h +++ b/clang/lib/AST/Interp/InterpStack.h @@ -48,12 +48,12 @@ public: } /// Returns a reference to the value on the top of the stack. - template T &peek() { + template T &peek() const { return *reinterpret_cast(peek(aligned_size())); } /// Returns a pointer to the top object. - void *top() { return Chunk ? peek(0) : nullptr; } + void *top() const { return Chunk ? peek(0) : nullptr; } /// Returns the size of the stack in bytes. size_t size() const { return StackSize; } @@ -72,7 +72,7 @@ private: /// Grows the stack to accommodate a value and returns a pointer to it. void *grow(size_t Size); /// Returns a pointer from the top of the stack. - void *peek(size_t Size); + void *peek(size_t Size) const; /// Shrinks the stack. void shrink(size_t Size); @@ -94,10 +94,13 @@ private: : Next(nullptr), Prev(Prev), End(reinterpret_cast(this + 1)) {} /// Returns the size of the chunk, minus the header. - size_t size() { return End - start(); } + size_t size() const { return End - start(); } /// Returns a pointer to the start of the data region. char *start() { return reinterpret_cast(this + 1); } + const char *start() const { + return reinterpret_cast(this + 1); + } }; static_assert(sizeof(StackChunk) < ChunkSize, "Invalid chunk size"); -- 2.7.4