summaryrefslogtreecommitdiffstats
path: root/source/slang
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
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')
-rw-r--r--source/slang/slang-check-decl.cpp8
-rw-r--r--source/slang/slang-check-overload.cpp7
-rw-r--r--source/slang/slang-lexer.cpp8
-rw-r--r--source/slang/slang-lexer.h24
-rw-r--r--source/slang/slang-syntax.h37
5 files changed, 40 insertions, 44 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index f8df46ff7..a37d80ae8 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -2559,7 +2559,7 @@ namespace Slang
}
funcDecl->ReturnType = resultType;
- for (auto & para : funcDecl->GetParameters())
+ for (auto& para : funcDecl->GetParameters())
{
ensureDecl(para, DeclCheckState::ReadyForReference);
}
@@ -2779,11 +2779,7 @@ namespace Slang
// subscript(uint index) -> T { get; }
//
- bool anyAccessors = false;
- for(auto accessorDecl : decl->getMembersOfType<AccessorDecl>())
- {
- anyAccessors = true;
- }
+ bool anyAccessors = decl->getMembersOfType<AccessorDecl>().isNonEmpty();
if(!anyAccessors)
{
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp
index dc013b781..20d1af09a 100644
--- a/source/slang/slang-check-overload.cpp
+++ b/source/slang/slang-check-overload.cpp
@@ -440,11 +440,8 @@ namespace Slang
// A call may yield an l-value, and we should take a look at the candidate to be sure
if(auto subscriptDeclRef = candidate.item.declRef.as<SubscriptDecl>())
{
- for(auto setter : subscriptDeclRef.getDecl()->getMembersOfType<SetterDecl>())
- {
- callExpr->type.IsLeftValue = true;
- }
- for(auto refAccessor : subscriptDeclRef.getDecl()->getMembersOfType<RefAccessorDecl>())
+ const auto& decl = subscriptDeclRef.getDecl();
+ if (decl->getMembersOfType<SetterDecl>().isNonEmpty() || decl->getMembersOfType<RefAccessorDecl>().isNonEmpty())
{
callExpr->type.IsLeftValue = true;
}
diff --git a/source/slang/slang-lexer.cpp b/source/slang/slang-lexer.cpp
index 6d13a053d..9b3bed88e 100644
--- a/source/slang/slang-lexer.cpp
+++ b/source/slang/slang-lexer.cpp
@@ -12,18 +12,18 @@
namespace Slang
{
- Token TokenReader::GetEndOfFileToken()
+ Token TokenReader::getEndOfFileToken()
{
return Token(TokenType::EndOfFile, UnownedStringSlice::fromLiteral(""), SourceLoc());
}
- Token* TokenList::begin() const
+ const Token* TokenList::begin() const
{
SLANG_ASSERT(m_tokens.getCount());
return &m_tokens[0];
}
- Token* TokenList::end() const
+ const Token* TokenList::end() const
{
SLANG_ASSERT(m_tokens.getCount());
SLANG_ASSERT(m_tokens[m_tokens.getCount() - 1].type == TokenType::EndOfFile);
@@ -59,7 +59,7 @@ namespace Slang
Token TokenReader::advanceToken()
{
if (!m_cursor)
- return GetEndOfFileToken();
+ return getEndOfFileToken();
Token token = m_nextToken;
if (m_cursor < m_end)
diff --git a/source/slang/slang-lexer.h b/source/slang/slang-lexer.h
index 0d19fe617..d1a1ba844 100644
--- a/source/slang/slang-lexer.h
+++ b/source/slang/slang-lexer.h
@@ -12,8 +12,8 @@ namespace Slang
struct TokenList
{
- Token* begin() const;
- Token* end() const;
+ const Token* begin() const;
+ const Token* end() const;
SLANG_FORCE_INLINE void add(const Token& token) { m_tokens.add(token); }
@@ -29,13 +29,13 @@ namespace Slang
, m_end (tokenList.end ())
{}
- Token* begin() const { return m_begin; }
- Token* end () const { return m_end ; }
+ const Token* begin() const { return m_begin; }
+ const Token* end () const { return m_end ; }
int getCount() { return (int)(m_end - m_begin); }
- Token* m_begin;
- Token* m_end;
+ const Token* m_begin;
+ const Token* m_end;
};
struct TokenReader
@@ -45,17 +45,17 @@ namespace Slang
explicit TokenReader(TokenSpan const& tokens)
: m_cursor(tokens.begin())
, m_end (tokens.end ())
- , m_nextToken(tokens.begin() ? *tokens.begin() : GetEndOfFileToken())
+ , m_nextToken(tokens.begin() ? *tokens.begin() : getEndOfFileToken())
{}
explicit TokenReader(TokenList const& tokens)
: m_cursor(tokens.begin())
, m_end (tokens.end ())
- , m_nextToken(tokens.begin() ? *tokens.begin() : GetEndOfFileToken())
+ , m_nextToken(tokens.begin() ? *tokens.begin() : getEndOfFileToken())
{}
struct ParsingCursor
{
Token nextToken;
- Token* tokenReaderCursor = nullptr;
+ const Token* tokenReaderCursor = nullptr;
};
ParsingCursor getCursor()
{
@@ -78,9 +78,9 @@ namespace Slang
int getCount() { return (int)(m_end - m_cursor); }
- Token* m_cursor;
- Token* m_end;
- static Token GetEndOfFileToken();
+ const Token* m_cursor;
+ const Token* m_end;
+ static Token getEndOfFileToken();
};
typedef unsigned int LexerFlags;
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++)
{