summaryrefslogtreecommitdiff
path: root/source/slang/slang-syntax.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-02-11 16:16:43 -0500
committerGitHub <noreply@github.com>2020-02-11 16:16:43 -0500
commit9b3e768bceae562deeb330067f3ef5febc2e5244 (patch)
tree9282a68c9696f3bb0863b8e9a0474dd523edc788 /source/slang/slang-syntax.h
parent30d0932add53a50a80f07ce28576bd779b82b4c1 (diff)
Small improvements around List (#1216)
* * Improved fastRemoveAt * Fixed off by one bug * Fixed const safeness with List<> * Made List begin and end const safe. * Revert to previous RefPtr usage. * Fix bug with casting. * Tabs -> spaces. Small fixes/improvements to List. * Improve comment on List. * hasContent -> isNonEmpty
Diffstat (limited to 'source/slang/slang-syntax.h')
-rw-r--r--source/slang/slang-syntax.h37
1 files changed, 20 insertions, 17 deletions
diff --git a/source/slang/slang-syntax.h b/source/slang/slang-syntax.h
index c5160e47b..6177b894d 100644
--- a/source/slang/slang-syntax.h
+++ b/source/slang/slang-syntax.h
@@ -753,8 +753,8 @@ namespace Slang
struct Iterator
{
- Element* m_cursor;
- Element* m_end;
+ const Element* m_cursor;
+ const Element* m_end;
bool operator!=(Iterator const& other)
{
@@ -766,9 +766,9 @@ namespace Slang
m_cursor = adjust(m_cursor + 1, m_end);
}
- RefPtr<T>& operator*()
+ const RefPtr<T>& operator*()
{
- return *(RefPtr<T>*)m_cursor;
+ return *(RefPtr<T>*)(m_cursor);
}
};
@@ -784,7 +784,7 @@ namespace Slang
return iter;
}
- static Element* adjust(Element* cursor, Element* end)
+ static const Element* adjust(const Element* cursor, const Element* end)
{
while (cursor != end)
{
@@ -797,7 +797,7 @@ namespace Slang
// TODO(tfoley): It is ugly to have these.
// We should probably fix the call sites instead.
- RefPtr<T>& getFirst() { return *begin(); }
+ const RefPtr<T>& getFirst() { return *begin(); }
Index getCount()
{
Index count = 0;
@@ -819,8 +819,11 @@ namespace Slang
return result;
}
- Element* m_begin;
- Element* m_end;
+ bool isEmpty() const { return m_end == m_begin; }
+ bool isNonEmpty() const { return m_end != m_begin; }
+
+ const Element* m_begin;
+ const Element* m_end;
};
struct TransparentMemberInfo
@@ -861,17 +864,17 @@ namespace Slang
struct Iterator
{
FilteredMemberRefList const* list;
- RefPtr<Decl>* ptr;
- RefPtr<Decl>* end;
+ const RefPtr<Decl>* ptr;
+ const RefPtr<Decl>* end;
Iterator() : list(nullptr), ptr(nullptr) {}
Iterator(
- FilteredMemberRefList const* list,
- RefPtr<Decl>* ptr,
- RefPtr<Decl>* end)
- : list(list)
- , ptr(ptr)
- , end(end)
+ FilteredMemberRefList const* inList,
+ const RefPtr<Decl>* inPtr,
+ const RefPtr<Decl>* inEnd)
+ : list(inList)
+ , ptr(inPtr)
+ , end(inEnd)
{}
bool operator!=(Iterator other)
@@ -893,7 +896,7 @@ namespace Slang
Iterator begin() const { return Iterator(this, Adjust(decls.begin(), decls.end()), decls.end()); }
Iterator end() const { return Iterator(this, decls.end(), decls.end()); }
- RefPtr<Decl>* Adjust(RefPtr<Decl>* ptr, RefPtr<Decl>* end) const
+ const RefPtr<Decl>* Adjust(const RefPtr<Decl>* ptr, const RefPtr<Decl>* end) const
{
for (; ptr != end; ptr++)
{