diff options
| -rw-r--r-- | slang.h | 1 | ||||
| -rw-r--r-- | source/core/basic.h | 2 | ||||
| -rw-r--r-- | source/core/common.h | 6 | ||||
| -rw-r--r-- | source/core/core.natvis | 40 | ||||
| -rw-r--r-- | source/core/core.vcxproj | 5 | ||||
| -rw-r--r-- | source/core/dictionary.h | 406 | ||||
| -rw-r--r-- | source/core/exception.h | 5 | ||||
| -rw-r--r-- | source/core/link.h | 334 | ||||
| -rw-r--r-- | source/core/linq.h | 665 | ||||
| -rw-r--r-- | source/core/memory-pool.cpp | 132 | ||||
| -rw-r--r-- | source/core/memory-pool.h | 122 | ||||
| -rw-r--r-- | source/core/slang-io.cpp | 7 | ||||
| -rw-r--r-- | source/core/slang-io.h | 20 | ||||
| -rw-r--r-- | source/core/slang-math.cpp | 8 | ||||
| -rw-r--r-- | source/core/stream.h | 243 | ||||
| -rw-r--r-- | source/core/text-io.h | 11 | ||||
| -rw-r--r-- | source/slang/check.cpp | 2 | ||||
| -rw-r--r-- | source/slang/compiler.h | 22 | ||||
| -rw-r--r-- | source/slang/diagnostics.cpp | 11 | ||||
| -rw-r--r-- | source/slang/syntax.h | 16 |
20 files changed, 20 insertions, 2038 deletions
@@ -884,7 +884,6 @@ namespace slang #ifdef SLANG_INCLUDE_IMPLEMENTATION #include "source/core/slang-io.cpp" -#include "source/core/slang-math.cpp" #include "source/core/slang-string.cpp" #include "source/core/stream.cpp" #include "source/core/text-io.cpp" diff --git a/source/core/basic.h b/source/core/basic.h index c5ed11091..e89d740bf 100644 --- a/source/core/basic.h +++ b/source/core/basic.h @@ -6,10 +6,8 @@ #include "slang-string.h" #include "array.h" #include "list.h" -#include "link.h" #include "smart-pointer.h" #include "exception.h" #include "dictionary.h" -#include "linq.h" #endif
\ No newline at end of file diff --git a/source/core/common.h b/source/core/common.h index ac8456009..25e85dc66 100644 --- a/source/core/common.h +++ b/source/core/common.h @@ -20,12 +20,6 @@ namespace Slang #else typedef int PtrInt; #endif - class Object - { - public: - virtual ~Object() - {} - }; template <typename T> inline T&& _Move(T & obj) diff --git a/source/core/core.natvis b/source/core/core.natvis index 271e39663..19c6db395 100644 --- a/source/core/core.natvis +++ b/source/core/core.natvis @@ -42,18 +42,6 @@ </Expand> </Type> -<Type Name="Slang::LinkedList<*>"> - <DisplayString>{{ size={FCount} }}</DisplayString> - <Expand> - <LinkedListItems> - <Size>FCount</Size> - <HeadPointer>FHead</HeadPointer> - <NextPointer>pNext</NextPointer> - <ValueNode>Value</ValueNode> - </LinkedListItems> - </Expand> -</Type> - <Type Name="Slang::Dictionary<*,*>"> <DisplayString>{{ size={_count} }}</DisplayString> <Expand> @@ -66,34 +54,6 @@ </Expand> </Type> -<Type Name="Slang::EnumerableDictionary<*,*>"> - <DisplayString>{{ size={_count} }}</DisplayString> - <Expand> - <Item Name="[size]">_count</Item> - <Item Name="[capacity]">bucketSizeMinusOne + 1</Item> - <LinkedListItems> - <Size>kvPairs.FCount</Size> - <HeadPointer>kvPairs.FHead</HeadPointer> - <NextPointer>pNext</NextPointer> - <ValueNode>Value</ValueNode> - </LinkedListItems> - </Expand> -</Type> - -<Type Name="Slang::EnumerableHashSet<*,*>"> - <DisplayString>{{ size={dict._count} }}</DisplayString> - <Expand> - <Item Name="[size]">dict._count</Item> - <Item Name="[capacity]">dict.bucketSizeMinusOne + 1</Item> - <LinkedListItems> - <Size>dict.kvPairs.FCount</Size> - <HeadPointer>dict.kvPairs.FHead</HeadPointer> - <NextPointer>pNext</NextPointer> - <ValueNode>Value</ValueNode> - </LinkedListItems> - </Expand> -</Type> - <Type Name="Slang::RefPtrImpl<*,*,*>"> <SmartPointer Usage="Minimal">pointer</SmartPointer> <DisplayString Condition="pointer == 0">empty</DisplayString> diff --git a/source/core/core.vcxproj b/source/core/core.vcxproj index bba6102b7..88e776703 100644 --- a/source/core/core.vcxproj +++ b/source/core/core.vcxproj @@ -28,10 +28,7 @@ <ClInclude Include="exception.h" /> <ClInclude Include="hash.h" /> <ClInclude Include="int-set.h" /> - <ClInclude Include="link.h" /> - <ClInclude Include="linq.h" /> <ClInclude Include="list.h" /> - <ClInclude Include="memory-pool.h" /> <ClInclude Include="secure-crt.h" /> <ClInclude Include="slang-io.h" /> <ClInclude Include="slang-math.h" /> @@ -42,9 +39,7 @@ <ClInclude Include="type-traits.h" /> </ItemGroup> <ItemGroup> - <ClCompile Include="memory-pool.cpp" /> <ClCompile Include="slang-io.cpp" /> - <ClCompile Include="slang-math.cpp" /> <ClCompile Include="slang-string.cpp" /> <ClCompile Include="stream.cpp" /> <ClCompile Include="text-io.cpp" /> diff --git a/source/core/dictionary.h b/source/core/dictionary.h index c052685fd..408835454 100644 --- a/source/core/dictionary.h +++ b/source/core/dictionary.h @@ -487,398 +487,6 @@ namespace Slang } }; - template<typename TKey, typename TValue> - class EnumerableDictionary - { - friend class Iterator; - friend class ItemProxy; - private: - inline int GetProbeOffset(int /*probeIdx*/) const - { - // quadratic probing - return 1; - } - private: - int bucketSizeMinusOne, shiftBits; - int _count; - IntSet marks; - - // debug op - struct Op - { - TKey key; - int opType; - Op() - {} - Op(const TKey & key, int t) - { - this->key = key; - opType = t; - } - }; - LinkedList<KeyValuePair<TKey, TValue>> kvPairs; - LinkedNode<KeyValuePair<TKey, TValue>>** hashMap; - void Free() - { - if (hashMap) - delete[] hashMap; - hashMap = 0; - kvPairs.Clear(); - } - inline bool IsDeleted(int pos) const - { - return marks.Contains((pos << 1) + 1); - } - inline bool IsEmpty(int pos) const - { - return !marks.Contains((pos << 1)); - } - inline void SetDeleted(int pos, bool val) - { - if (val) - marks.Add((pos << 1) + 1); - else - marks.Remove((pos << 1) + 1); - } - inline void SetEmpty(int pos, bool val) - { - if (val) - marks.Remove((pos << 1)); - else - marks.Add((pos << 1)); - } - struct FindPositionResult - { - int ObjectPosition; - int InsertionPosition; - FindPositionResult() - { - ObjectPosition = -1; - InsertionPosition = -1; - } - FindPositionResult(int objPos, int insertPos) - { - ObjectPosition = objPos; - InsertionPosition = insertPos; - } - - }; - template<typename T> - inline int GetHashPos(T & key) const - { - return ((unsigned int)(GetHashCode(key) * 2654435761)) >> shiftBits; - } - template<typename T> - FindPositionResult FindPosition(const T & key) const - { - int hashPos = GetHashPos((T&)key); - int insertPos = -1; - int numProbes = 0; - while (numProbes <= bucketSizeMinusOne) - { - if (IsEmpty(hashPos)) - { - if (insertPos == -1) - return FindPositionResult(-1, hashPos); - else - return FindPositionResult(-1, insertPos); - } - else if (IsDeleted(hashPos)) - { - if (insertPos == -1) - insertPos = hashPos; - } - else if (hashMap[hashPos]->Value.Key == key) - { - return FindPositionResult(hashPos, -1); - } - numProbes++; - hashPos = (hashPos + GetProbeOffset(numProbes)) & bucketSizeMinusOne; - } - if (insertPos != -1) - return FindPositionResult(-1, insertPos); - throw InvalidOperationException("Hash map is full. This indicates an error in Key::Equal or Key::GetHashCode."); - } - TValue & _Insert(KeyValuePair<TKey, TValue> && kvPair, int pos) - { - auto node = kvPairs.AddLast(); - node->Value = _Move(kvPair); - hashMap[pos] = node; - SetEmpty(pos, false); - SetDeleted(pos, false); - return node->Value.Value; - } - void Rehash() - { - if (bucketSizeMinusOne == -1 || _count / (float)bucketSizeMinusOne >= MaxLoadFactor) - { - int newSize = (bucketSizeMinusOne + 1) * 2; - int newShiftBits = shiftBits - 1; - if (newSize == 0) - { - newSize = 16; - newShiftBits = 28; - } - EnumerableDictionary<TKey, TValue> newDict; - newDict.shiftBits = newShiftBits; - newDict.bucketSizeMinusOne = newSize - 1; - newDict.hashMap = new LinkedNode<KeyValuePair<TKey, TValue>>*[newSize]; - newDict.marks.SetMax(newSize * 2); - if (hashMap) - { - for (auto & kvPair : *this) - { - newDict.Add(_Move(kvPair)); - } - } - *this = _Move(newDict); - } - } - - bool AddIfNotExists(KeyValuePair<TKey, TValue> && kvPair) - { - Rehash(); - auto pos = FindPosition(kvPair.Key); - if (pos.ObjectPosition != -1) - return false; - else if (pos.InsertionPosition != -1) - { - _count++; - _Insert(_Move(kvPair), pos.InsertionPosition); - return true; - } - else - throw InvalidOperationException("Inconsistent find result returned. This is a bug in Dictionary implementation."); - } - void Add(KeyValuePair<TKey, TValue> && kvPair) - { - if (!AddIfNotExists(_Move(kvPair))) - throw KeyExistsException("The key already exists in Dictionary."); - } - TValue & Set(KeyValuePair<TKey, TValue> && kvPair) - { - Rehash(); - auto pos = FindPosition(kvPair.Key); - if (pos.ObjectPosition != -1) - { - hashMap[pos.ObjectPosition]->Delete(); - return _Insert(_Move(kvPair), pos.ObjectPosition); - } - else if (pos.InsertionPosition != -1) - { - _count++; - return _Insert(_Move(kvPair), pos.InsertionPosition); - } - else - throw InvalidOperationException("Inconsistent find result returned. This is a bug in Dictionary implementation."); - } - public: - typedef typename LinkedList<KeyValuePair<TKey, TValue>>::Iterator Iterator; - - typename LinkedList<KeyValuePair<TKey, TValue>>::Iterator begin() const - { - return kvPairs.begin(); - } - typename LinkedList<KeyValuePair<TKey, TValue>>::Iterator end() const - { - return kvPairs.end(); - } - public: - void Add(const TKey & key, const TValue & value) - { - Add(KeyValuePair<TKey, TValue>(key, value)); - } - void Add(TKey && key, TValue && value) - { - Add(KeyValuePair<TKey, TValue>(_Move(key), _Move(value))); - } - bool AddIfNotExists(const TKey & key, const TValue & value) - { - return AddIfNotExists(KeyValuePair<TKey, TValue>(key, value)); - } - bool AddIfNotExists(TKey && key, TValue && value) - { - return AddIfNotExists(KeyValuePair<TKey, TValue>(_Move(key), _Move(value))); - } - void Remove(const TKey & key) - { - if (_count > 0) - { - auto pos = FindPosition(key); - if (pos.ObjectPosition != -1) - { - kvPairs.Delete(hashMap[pos.ObjectPosition]); - hashMap[pos.ObjectPosition] = 0; - SetDeleted(pos.ObjectPosition, true); - _count--; - } - } - } - void Clear() - { - _count = 0; - kvPairs.Clear(); - marks.Clear(); - } - template<typename T> - bool ContainsKey(const T & key) const - { - if (bucketSizeMinusOne == -1) - return false; - auto pos = FindPosition(key); - return pos.ObjectPosition != -1; - } - template<typename T> - TValue * TryGetValue(const T & key) const - { - if (bucketSizeMinusOne == -1) - return nullptr; - auto pos = FindPosition(key); - if (pos.ObjectPosition != -1) - { - return &(hashMap[pos.ObjectPosition]->Value.Value); - } - return nullptr; - } - template<typename T> - bool TryGetValue(const T & key, TValue & value) const - { - if (bucketSizeMinusOne == -1) - return false; - auto pos = FindPosition(key); - if (pos.ObjectPosition != -1) - { - value = hashMap[pos.ObjectPosition]->Value.Value; - return true; - } - return false; - } - class ItemProxy - { - private: - const EnumerableDictionary<TKey, TValue> * dict; - TKey key; - public: - ItemProxy(const TKey & _key, const EnumerableDictionary<TKey, TValue> * _dict) - { - this->dict = _dict; - this->key = _key; - } - ItemProxy(TKey && _key, const EnumerableDictionary<TKey, TValue> * _dict) - { - this->dict = _dict; - this->key = _Move(_key); - } - TValue & GetValue() const - { - auto pos = dict->FindPosition(key); - if (pos.ObjectPosition != -1) - { - return dict->hashMap[pos.ObjectPosition]->Value.Value; - } - else - { - throw KeyNotFoundException("The key does not exists in dictionary."); - } - } - inline TValue & operator()() const - { - return GetValue(); - } - operator TValue&() const - { - return GetValue(); - } - TValue & operator = (const TValue & val) - { - return ((EnumerableDictionary<TKey, TValue>*)dict)->Set(KeyValuePair<TKey, TValue>(_Move(key), val)); - } - TValue & operator = (TValue && val) - { - return ((EnumerableDictionary<TKey, TValue>*)dict)->Set(KeyValuePair<TKey, TValue>(_Move(key), _Move(val))); - } - }; - ItemProxy operator [](const TKey & key) const - { - return ItemProxy(key, this); - } - ItemProxy operator [](TKey && key) const - { - return ItemProxy(_Move(key), this); - } - int Count() const - { - return _count; - } - KeyValuePair<TKey, TValue> & First() const - { - return kvPairs.First(); - } - KeyValuePair<TKey, TValue> & Last() const - { - return kvPairs.Last(); - } - private: - template<typename... Args> - void Init(const KeyValuePair<TKey, TValue> & kvPair, Args... args) - { - Add(kvPair); - Init(args...); - } - public: - EnumerableDictionary() - { - bucketSizeMinusOne = -1; - shiftBits = 32; - _count = 0; - hashMap = 0; - } - template<typename Arg, typename... Args> - EnumerableDictionary(Arg arg, Args... args) - { - Init(arg, args...); - } - EnumerableDictionary(const EnumerableDictionary<TKey, TValue> & other) - : bucketSizeMinusOne(-1), _count(0), hashMap(0) - { - *this = other; - } - EnumerableDictionary(EnumerableDictionary<TKey, TValue> && other) - : bucketSizeMinusOne(-1), _count(0), hashMap(0) - { - *this = (_Move(other)); - } - EnumerableDictionary<TKey, TValue> & operator = (const EnumerableDictionary<TKey, TValue> & other) - { - if (this == &other) - return *this; - Clear(); - for (auto & item : other) - Add(item.Key, item.Value); - return *this; - } - EnumerableDictionary<TKey, TValue> & operator = (EnumerableDictionary<TKey, TValue> && other) - { - if (this == &other) - return *this; - Free(); - bucketSizeMinusOne = other.bucketSizeMinusOne; - _count = other._count; - hashMap = other.hashMap; - shiftBits = other.shiftBits; - marks = _Move(other.marks); - other.hashMap = 0; - other._count = 0; - other.bucketSizeMinusOne = -1; - kvPairs = _Move(other.kvPairs); - return *this; - } - ~EnumerableDictionary() - { - Free(); - } - }; - class _DummyClass {}; @@ -996,20 +604,6 @@ namespace Slang template <typename T> class HashSet : public HashSetBase<T, Dictionary<T, _DummyClass>> {}; - - template <typename T> - class EnumerableHashSet : public HashSetBase<T, EnumerableDictionary<T, _DummyClass>> - { - public: - T & First() const - { - return this->dict.First().Key; - } - T & Last() const - { - return this->dict.Last().Key; - } - }; } #endif diff --git a/source/core/exception.h b/source/core/exception.h index 4671ae10b..6739c6778 100644 --- a/source/core/exception.h +++ b/source/core/exception.h @@ -6,7 +6,7 @@ namespace Slang { - class Exception : public Object + class Exception { public: String Message; @@ -16,6 +16,9 @@ namespace Slang : Message(message) { } + + virtual ~Exception() + {} }; class IndexOutofRangeException : public Exception diff --git a/source/core/link.h b/source/core/link.h deleted file mode 100644 index f74a250b9..000000000 --- a/source/core/link.h +++ /dev/null @@ -1,334 +0,0 @@ -#ifndef CORE_LIB_LINK_H -#define CORE_LIB_LINK_H - -#include "Common.h" -#include "Exception.h" - -namespace Slang -{ - template<typename T> - class LinkedList; - - template<typename T> - class LinkedNode - { - template<typename T1> - friend class LinkedList; - private: - LinkedNode<T> *pPrev, *pNext; - LinkedList<T> * FLink; - public: - T Value; - LinkedNode (LinkedList<T> * lnk):FLink(lnk) - { - pPrev = pNext = 0; - }; - LinkedNode<T> * GetPrevious() - { - return pPrev; - }; - LinkedNode<T> * GetNext() - { - return pNext; - }; - LinkedNode<T> * InsertAfter(const T & nData) - { - LinkedNode<T> * n = new LinkedNode<T>(FLink); - n->Value = nData; - n->pPrev = this; - n->pNext = this->pNext; - LinkedNode<T> *npp = n->pNext; - if (npp) - { - npp->pPrev = n; - } - pNext = n; - if (!n->pNext) - FLink->FTail = n; - FLink->FCount ++; - return n; - }; - LinkedNode<T> * InsertBefore(const T & nData) - { - LinkedNode<T> * n = new LinkedNode<T>(FLink); - n->Value = nData; - n->pPrev = pPrev; - n->pNext = this; - pPrev = n; - LinkedNode<T> *npp = n->pPrev; - if (npp) - npp->pNext = n; - if (!n->pPrev) - FLink->FHead = n; - FLink->FCount ++; - return n; - }; - void Delete() - { - if (pPrev) - pPrev->pNext = pNext; - if (pNext) - pNext->pPrev = pPrev; - FLink->FCount --; - if (FLink->FHead == this) - { - FLink->FHead = pNext; - } - if (FLink->FTail == this) - { - FLink->FTail = pPrev; - } - delete this; - } - }; - template<typename T> - class LinkedList - { - template<typename T1> - friend class LinkedNode; - private: - LinkedNode<T> * FHead, *FTail; - int FCount; - public: - class Iterator - { - public: - LinkedNode<T> * Current, *Next; - void SetCurrent(LinkedNode<T> * cur) - { - Current = cur; - if (Current) - Next = Current->GetNext(); - else - Next = 0; - } - Iterator() - { - Current = Next = 0; - } - Iterator(LinkedNode<T> * cur) - { - SetCurrent(cur); - } - T & operator *() const - { - return Current->Value; - } - Iterator& operator ++() - { - SetCurrent(Next); - return *this; - } - Iterator operator ++(int) - { - Iterator rs = *this; - SetCurrent(Next); - return rs; - } - bool operator != (const Iterator & iter) const - { - return Current != iter.Current; - } - bool operator == (const Iterator & iter) const - { - return Current == iter.Current; - } - }; - Iterator begin() const - { - return Iterator(FHead); - } - Iterator end() const - { - return Iterator(0); - } - public: - LinkedList() : FHead(0), FTail(0), FCount(0) - { - } - ~LinkedList() - { - Clear(); - } - LinkedList(const LinkedList<T> & link) : FHead(0), FTail(0), FCount(0) - { - this->operator=(link); - } - LinkedList(LinkedList<T> && link) : FHead(0), FTail(0), FCount(0) - { - this->operator=(_Move(link)); - } - LinkedList<T> & operator = (LinkedList<T> && link) - { - if (FHead != 0) - Clear(); - FHead = link.FHead; - FTail = link.FTail; - FCount = link.FCount; - link.FHead = 0; - link.FTail = 0; - link.FCount = 0; - for (auto node = FHead; node; node = node->GetNext()) - node->FLink = this; - return *this; - } - LinkedList<T> & operator = (const LinkedList<T> & link) - { - if (FHead != 0) - Clear(); - auto p = link.FHead; - while (p) - { - AddLast(p->Value); - p = p->GetNext(); - } - return *this; - } - template<typename IteratorFunc> - void ForEach(const IteratorFunc & f) - { - auto p = FHead; - while (p) - { - f(p->Value); - p = p->GetNext(); - } - } - LinkedNode<T> * GetNode(int x) - { - LinkedNode<T> *pCur = FHead; - for (int i=0;i<x;i++) - { - if (pCur) - pCur = pCur->pNext; - else - throw "Index out of range"; - } - return pCur; - }; - LinkedNode<T> * Find(const T& fData) - { - for (LinkedNode<T> * pCur = FHead; pCur; pCur = pCur->pNext) - { - if (pCur->Value == fData) - return pCur; - } - return 0; - }; - LinkedNode<T> * FirstNode() const - { - return FHead; - }; - T & First() const - { - if (!FHead) - throw IndexOutofRangeException("LinkedList: index out of range."); - return FHead->Value; - } - T & Last() const - { - if (!FTail) - throw IndexOutofRangeException("LinkedList: index out of range."); - return FTail->Value; - } - LinkedNode<T> * LastNode() const - { - return FTail; - }; - LinkedNode<T> * AddLast(const T & nData) - { - LinkedNode<T> * n = new LinkedNode<T>(this); - n->Value = nData; - n->pPrev = FTail; - if (FTail) - FTail->pNext = n; - n->pNext = 0; - FTail = n; - if (!FHead) - FHead = n; - FCount ++; - return n; - }; - // Insert a blank node - LinkedNode<T> * AddLast() - { - LinkedNode<T> * n = new LinkedNode<T>(this); - n->pPrev = FTail; - if (FTail) - FTail->pNext = n; - n->pNext = 0; - FTail = n; - if (!FHead) - FHead = n; - FCount ++; - return n; - }; - LinkedNode<T> * AddFirst(const T& nData) - { - LinkedNode<T> *n = new LinkedNode<T>(this); - n->Value = nData; - n->pPrev = 0; - n->pNext = FHead; - if (FHead) - FHead->pPrev = n; - FHead = n; - if (!FTail) - FTail = n; - FCount ++; - return n; - }; - void Delete(LinkedNode<T>*n, int Count = 1) - { - LinkedNode<T> *n1,*n2 = 0, *tn; - n1 = n->pPrev; - tn = n; - int numDeleted = 0; - for (int i=0; i<Count; i++) - { - n2 = tn->pNext; - delete tn; - tn = n2; - numDeleted++; - if (tn == 0) - break; - } - if (n1) - n1->pNext = n2; - else - FHead = n2; - if (n2) - n2->pPrev = n1; - else - FTail = n1; - FCount -= numDeleted; - } - void Clear() - { - for (LinkedNode<T> *n = FHead; n; ) - { - LinkedNode<T> * tmp = n->pNext; - delete n; - n = tmp; - } - FHead = 0; - FTail = 0; - FCount = 0; - } - List<T> ToList() const - { - List<T> rs; - rs.Reserve(FCount); - for (auto & item : *this) - { - rs.Add(item); - } - return rs; - } - int Count() - { - return FCount; - } - }; -} - -#endif diff --git a/source/core/linq.h b/source/core/linq.h deleted file mode 100644 index 52af3abd0..000000000 --- a/source/core/linq.h +++ /dev/null @@ -1,665 +0,0 @@ -#ifndef FUNDAMENTAL_LIB_LINQ_H -#define FUNDAMENTAL_LIB_LINQ_H - -#include "List.h" - -namespace Slang -{ - template <typename T> - T ConstructT(); - - template <typename T> - class RemoveReference - { - public: - typedef T Type; - }; - - template <typename T> - class RemoveReference<T&> - { - public: - typedef T Type; - }; - - template <typename T> - class RemoveReference<T&&> - { - public: - typedef T Type; - }; - - template<typename T> - struct RemovePointer - { - typedef T Type; - }; - - template<typename T> - struct RemovePointer<T*> - { - typedef T Type; - }; - - template <typename TQueryable1, typename TEnumerator1, typename TQueryable2, typename TEnumerator2, typename T> - class ConcatQuery - { - private: - TQueryable1 items1; - TQueryable2 items2; - public: - ConcatQuery(const TQueryable1 & queryable1, const TQueryable2 & queryable2) - : items1(queryable1), items2(queryable2) - {} - class Enumerator - { - private: - TEnumerator1 ptr1; - TEnumerator1 end1; - TEnumerator2 ptr2; - TEnumerator2 end2; - public: - Enumerator(const Enumerator &) = default; - Enumerator(TEnumerator1 pptr, TEnumerator1 pend, TEnumerator2 pptr2, TEnumerator2 pend2) - : ptr1(pptr), end1(pend), ptr2(pptr2), end2(pend2) - {} - T operator *() const - { - if (ptr1 != end1) - return *(ptr1); - else - return *(ptr2); - } - Enumerator& operator ++() - { - if (ptr1 != end1) - ++ptr1; - else - ++ptr2; - return *this; - } - Enumerator operator ++(int) - { - Enumerator rs = *this; - ++rs; - return rs; - } - bool operator != (const Enumerator & iter) const - { - return ptr1 != iter.ptr1 || ptr2 != iter.ptr2; - } - bool operator == (const Enumerator & iter) const - { - return ptr1 == iter.ptr1 && ptr2 == iter.ptr2; - } - }; - Enumerator begin() const - { - return Enumerator(items1.begin(), items1.end(), items2.begin(), items2.end()); - } - Enumerator end() const - { - return Enumerator(items1.end(), items1.end(), items2.end(), items2.end()); - } - }; - - template <typename TQueryable, typename TEnumerator, typename T, typename TFunc> - class WhereQuery - { - private: - TQueryable items; - TFunc func; - public: - WhereQuery(const TQueryable & queryable, const TFunc & f) - : items(queryable), func(f) - {} - class Enumerator - { - private: - TEnumerator ptr; - TEnumerator end; - const TFunc * func; - public: - Enumerator(const Enumerator &) = default; - Enumerator(TEnumerator ptr, TEnumerator end, const TFunc & f) - : ptr(ptr), end(end), func(&f) - {} - T operator *() const - { - return *(ptr); - } - Enumerator& operator ++() - { - ++ptr; - while (ptr != end) - { - if ((*func)(*ptr)) - break; - else - ++ptr; - } - return *this; - } - Enumerator operator ++(int) - { - Enumerator rs = *this; - while (rs.ptr != end) - { - if ((*func)(*rs.ptr)) - break; - ++rs.ptr; - } - return rs; - } - bool operator != (const Enumerator & iter) const - { - return ptr != iter.ptr; - } - bool operator == (const Enumerator & iter) const - { - return ptr == iter.ptr; - } - }; - Enumerator begin() const - { - auto ptr = items.begin(); - auto end = items.end(); - while (ptr != end) - { - if (func(*ptr)) - break; - ++ptr; - } - return Enumerator(ptr, end, func); - } - Enumerator end() const - { - return Enumerator(items.end(), items.end(), func); - } - }; - - template <typename TQueryable, typename TEnumerator, typename T> - class SkipQuery - { - private: - TQueryable items; - int count = 0; - public: - SkipQuery(const TQueryable & queryable, int pCount) - : items(queryable), count(pCount) - {} - class Enumerator - { - private: - TEnumerator ptr; - TEnumerator end; - public: - Enumerator(const Enumerator &) = default; - Enumerator(TEnumerator pptr, TEnumerator pend) - : ptr(pptr), end(pend) - { - } - T operator *() const - { - return *(ptr); - } - Enumerator& operator ++() - { - ++ptr; - return *this; - } - Enumerator operator ++(int) - { - Enumerator rs = *this; - ++ptr; - return rs; - } - bool operator != (const Enumerator & iter) const - { - return ptr != iter.ptr; - } - bool operator == (const Enumerator & iter) const - { - return ptr == iter.ptr; - } - }; - Enumerator begin() const - { - auto ptr = items.begin(); - auto end = items.end(); - for (int i = 0; i < count; i++) - if (ptr != end) - ++ptr; - return Enumerator(ptr, end); - } - Enumerator end() const - { - return Enumerator(items.end(), items.end()); - } - }; - - template <typename TQueryable, typename TEnumerator, typename T, typename TFunc> - class SelectQuery - { - private: - TQueryable items; - TFunc func; - public: - SelectQuery(const TQueryable & queryable, const TFunc & f) - : items(queryable), func(f) - {} - class Enumerator - { - private: - TEnumerator ptr; - TEnumerator end; - const TFunc * func; - public: - Enumerator(const Enumerator &) = default; - Enumerator(TEnumerator ptr, TEnumerator end, const TFunc & f) - : ptr(ptr), end(end), func(&f) - {} - auto operator *() const -> decltype((*func)(*ptr)) - { - return (*func)(*ptr); - } - Enumerator& operator ++() - { - ++ptr; - return *this; - } - Enumerator operator ++(int) - { - Enumerator rs = *this; - ++rs; - return rs; - } - bool operator != (const Enumerator & iter) const - { - return !(ptr == iter.ptr); - } - bool operator == (const Enumerator & iter) const - { - return ptr == iter.ptr; - } - }; - Enumerator begin() const - { - return Enumerator(items.begin(), items.end(), func); - } - Enumerator end() const - { - return Enumerator(items.end(), items.end(), func); - } - }; - - template <typename TQueryable, typename TEnumerator, typename T, typename TFunc> - class SelectManyQuery - { - private: - TQueryable items; - TFunc func; - SelectManyQuery() - {} - public: - SelectManyQuery(const TQueryable & queryable, const TFunc & f) - : items(queryable), func(f) - {} - template<typename TItems, typename TItemPtr> - class Enumerator - { - private: - TEnumerator ptr; - TEnumerator end; - const TFunc * func; - TItems items; - TItemPtr subPtr; - public: - Enumerator(const Enumerator &) = default; - Enumerator(TEnumerator ptr, TEnumerator end, const TFunc & f) - : ptr(ptr), end(end), func(&f) - { - if (ptr != end) - { - items = f(*ptr); - subPtr = items.begin(); - } - } - auto operator *() const -> decltype(*subPtr) - { - return *subPtr; - } - Enumerator& operator ++() - { - ++subPtr; - while (subPtr == items.end() && ptr != end) - { - ++ptr; - if (ptr != end) - { - items = (*func)(*ptr); - subPtr = items.begin(); - } - else - break; - } - - return *this; - } - Enumerator operator ++(int) - { - Enumerator rs = *this; - ++rs; - return rs; - } - bool operator != (const Enumerator & iter) const - { - return !operator==(iter); - } - bool operator == (const Enumerator & iter) const - { - if (ptr == iter.ptr) - { - if (ptr == end) - return true; - else - return subPtr == iter.subPtr; - } - else - return false; - } - }; - auto begin() const ->Enumerator<decltype(func(ConstructT<T>())), decltype(func(ConstructT<T>()).begin())> - { - return Enumerator<decltype(func(ConstructT<T>())), decltype(func(ConstructT<T>()).begin())>(items.begin(), items.end(), func); - } - auto end() const ->Enumerator<decltype(func(ConstructT<T>())), decltype(func(ConstructT<T>()).begin())> - { - return Enumerator<decltype(func(ConstructT<T>())), decltype(func(ConstructT<T>()).begin())>(items.end(), items.end(), func); - } - }; - - template <typename T> - struct EnumeratorType - { - typedef decltype(ConstructT<T>().begin()) Type; - }; - - template <typename TFunc, typename TArg> - class ExtractReturnType - { - public: - static TFunc * f; - static TArg ConstructArg() {}; - typedef decltype((*f)(ConstructArg())) ReturnType; - }; - - template <typename T> - class ExtractItemType - { - public: - typedef typename RemovePointer<decltype(ConstructT<T>().begin())>::Type Type; - }; - - template <typename TQueryable, typename TEnumerator, typename T> - class Queryable - { - private: - TQueryable items; - public: - auto begin() const -> decltype(items.begin()) - { - return items.begin(); - } - auto end() const -> decltype(items.end()) - { - return items.end(); - } - public: - const TQueryable & GetItems() const - { - return items; - } - Queryable(const TQueryable & items) - : items(items) - {} - - Queryable<SkipQuery<TQueryable, TEnumerator, T>, typename SkipQuery<TQueryable, TEnumerator, T>::Enumerator, T> Skip(int count) const - { - return Queryable<SkipQuery<TQueryable, TEnumerator, T>, typename SkipQuery<TQueryable, TEnumerator, T>::Enumerator, T>(SkipQuery<TQueryable, TEnumerator, T>(items, count)); - } - - template<typename TQueryable2, typename TEnumerator2> - Queryable<ConcatQuery<TQueryable, TEnumerator, TQueryable2, TEnumerator2, T>, typename ConcatQuery<TQueryable, TEnumerator, TQueryable2, TEnumerator2, T>::Enumerator, T> Concat(const Queryable<TQueryable2, TEnumerator2, T> & other) const - { - return Queryable<ConcatQuery<TQueryable, TEnumerator, TQueryable2, TEnumerator2, T>, typename ConcatQuery<TQueryable, TEnumerator, TQueryable2, TEnumerator2, T>::Enumerator, T>(ConcatQuery<TQueryable, TEnumerator, TQueryable2, TEnumerator2, T>(this->items, other.GetItems())); - } - - template<typename TFunc> - Queryable<WhereQuery<TQueryable, TEnumerator, T, TFunc>, typename WhereQuery<TQueryable, TEnumerator, T, TFunc>::Enumerator, T> Where(const TFunc & f) const - { - return Queryable<WhereQuery<TQueryable, TEnumerator, T, TFunc>, typename WhereQuery<TQueryable, TEnumerator, T, TFunc>::Enumerator, T>(WhereQuery<TQueryable, TEnumerator, T, TFunc>(items, f)); - } - - template<typename TFunc> - Queryable<SelectQuery<TQueryable, TEnumerator, T, TFunc>, typename SelectQuery<TQueryable, TEnumerator, T, TFunc>::Enumerator, typename RemoveReference<typename ExtractReturnType<TFunc, T>::ReturnType>::Type> Select(const TFunc & f) const - { - return Queryable<SelectQuery<TQueryable, TEnumerator, T, TFunc>, typename SelectQuery<TQueryable, TEnumerator, T, TFunc>::Enumerator, typename RemoveReference<typename ExtractReturnType<TFunc, T>::ReturnType>::Type>(SelectQuery<TQueryable, TEnumerator, T, TFunc>(items, f)); - } - - template<typename TFunc> - auto SelectMany(const TFunc & f) const ->Queryable<SelectManyQuery<TQueryable, TEnumerator, T, TFunc>, typename EnumeratorType<SelectManyQuery<TQueryable, TEnumerator, T, TFunc>>::Type, typename ExtractItemType<decltype(f(ConstructT<T>()))>::Type> - { - return Queryable<SelectManyQuery<TQueryable, TEnumerator, T, TFunc>, typename EnumeratorType<SelectManyQuery<TQueryable, TEnumerator, T, TFunc>>::Type, typename ExtractItemType<decltype(f(ConstructT<T>()))>::Type>(SelectManyQuery<TQueryable, TEnumerator, T, TFunc>(items, f)); - } - - template<typename TAggregateResult, typename TFunc> - auto Aggregate(const TAggregateResult & initial, const TFunc & f) const -> decltype(f(initial, *items.begin())) - { - TAggregateResult rs = initial; - for (auto && x : items) - rs = f(rs, x); - return rs; - } - - template<typename TFunc> - bool Any(const TFunc & condition) const - { - for (auto && x : items) - if (condition(x)) - return true; - return false; - } - - template<typename TFunc> - T & First(const TFunc & condition) const - { - for (auto && x : items) - if (condition(x)) - return x; - } - - template <typename TFunc> - T Max(const TFunc & selector) const - { - return Aggregate(*items.begin(), [&](const T & v0, const T & v1) - { - return selector(v0) > selector(v1) ? v0 : v1; - }); - } - - template <typename TFunc> - T Min(const TFunc & selector) const - { - return Aggregate(*items.begin(), [&](const T & v0, const T & v1) - { - return selector(v0) < selector(v1) ? v0 : v1; - }); - } - - template <typename TFunc> - auto Sum(const TFunc & selector) const -> decltype(selector(ConstructT<T>())) - { - decltype(selector(ConstructT<T>())) rs(0); - for (auto && x : items) - rs = rs + selector(x); - return rs; - } - - T Max() const - { - return Aggregate(*items.begin(), [](const T & v0, const T & v1) {return v0 > v1 ? v0 : v1; }); - } - - T Min() const - { - return Aggregate(*items.begin(), [](const T & v0, const T & v1) {return v0 < v1 ? v0 : v1; }); - } - - T Sum() const - { - T rs = T(0); - for (auto && x : items) - rs = rs + x; - return rs; - } - - T Avg() const - { - T rs = T(0); - int count = 0; - for (auto && x : items) - { - rs = rs + x; - count++; - } - return rs / count; - } - - int Count() const - { - int rs = 0; - for (auto && x : items) - rs++; - return rs; - } - - List<T> ToList() const - { - List<T> rs; - for (auto && val : items) - rs.Add(val); - return rs; - } - }; - - - template<typename T, typename TAllocator> - inline Queryable<ArrayView<T>, T*, T> From(const List<T, TAllocator> & list) - { - return Queryable<ArrayView<T>, T*, T>(list.GetArrayView()); - } - - template<typename T, typename TAllocator> - inline Queryable<List<T, TAllocator>, T*, T> From(List<T, TAllocator> && list) - { - return Queryable<List<T, TAllocator>, T*, T>(_Move(list)); - } - - template<typename T> - inline Queryable<ArrayView<T>, T*, T> From(const ArrayView<T> & list) - { - return Queryable<ArrayView<T>, T*, T>(list); - } - - template<typename T, int count> - inline Queryable<Array<T, count>, T*, T> From(const Array<T, count> & list) - { - return Queryable<Array<T, count>, T*, T>(list); - } - - template<typename T> - inline auto From(const T & list) -> Queryable<T, decltype(list.begin()), decltype(*list.begin())> - { - return Queryable<T, decltype(list.begin()), decltype(*list.begin())>(list); - } - - template<typename T> - inline Queryable<Array<T, 1>, T*, T> FromSingle(const T & obj) - { - Array<T, 1> arr; - arr.Add(obj); - return From(arr); - } - - template<typename T> - struct LinkedListView - { - typename LinkedList<T>::Iterator start, last; - typename LinkedList<T>::Iterator begin() const - { - return start; - } - typename LinkedList<T>::Iterator end() const - { - return last; - } - }; - - template<typename T> - inline Queryable<LinkedListView<T>, LinkedNode<T>, T> From(const LinkedList<T> & list) - { - LinkedListView<T> view; - view.start = list.begin(); - view.last = list.end(); - return Queryable<LinkedListView<T>, LinkedNode<T>, T>(view); - } - - template<typename TKey, typename TValue> - struct EnumerableDictView - { - typename EnumerableDictionary<TKey, TValue>::Iterator start, last; - typename EnumerableDictionary<TKey, TValue>::Iterator begin() const - { - return start; - } - typename EnumerableDictionary<TKey, TValue>::Iterator end() const - { - return last; - } - }; - - template<typename TKey, typename TValue> - inline Queryable<EnumerableDictView<TKey, TValue>, typename EnumerableDictionary<TKey, TValue>::Iterator, KeyValuePair<TKey, TValue>> From(const EnumerableDictionary<TKey, TValue> & dict) - { - EnumerableDictView<TKey, TValue> view; - view.start = dict.begin(); - view.last = dict.end(); - return Queryable<EnumerableDictView<TKey, TValue>, typename EnumerableDictionary<TKey, TValue>::Iterator, KeyValuePair<TKey, TValue>>(view); - } - - template<typename TKey> - struct EnumerableHashSetView - { - typename HashSetBase<TKey, EnumerableDictionary<TKey, _DummyClass>>::Iterator start, last; - typename EnumerableHashSet<TKey>::Iterator begin() const - { - return start; - } - typename EnumerableHashSet<TKey>::Iterator end() const - { - return last; - } - }; - - template<typename TKey> - inline Queryable<EnumerableHashSetView<TKey>, typename HashSetBase<TKey, EnumerableDictionary<TKey, _DummyClass>>::Iterator, TKey> From(const EnumerableHashSet<TKey> & dict) - { - EnumerableHashSetView<TKey> view; - view.start = dict.begin(); - view.last = dict.end(); - return Queryable<EnumerableHashSetView<TKey>, typename HashSetBase<TKey, EnumerableDictionary<TKey, _DummyClass>>::Iterator, TKey>(view); - } -} - -#endif
\ No newline at end of file diff --git a/source/core/memory-pool.cpp b/source/core/memory-pool.cpp deleted file mode 100644 index aec1efc37..000000000 --- a/source/core/memory-pool.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include "memory-pool.h" -#include <cassert> - -namespace Slang -{ - MemoryPool::MemoryPool(unsigned char * pBuffer, int pLog2BlockSize, int numBlocks) - { - Init(pBuffer, pLog2BlockSize, numBlocks); - } - void MemoryPool::Init(unsigned char * pBuffer, int pLog2BlockSize, int numBlocks) - { - assert(pLog2BlockSize >= 1 && pLog2BlockSize <= 30); - assert(numBlocks >= 4); - buffer = pBuffer; - blockSize = 1 << pLog2BlockSize; - log2BlockSize = pLog2BlockSize; - numLevels = Math::Log2Floor(numBlocks); - freeList[0] = (FreeListNode*)buffer; - freeList[0]->NextPtr = nullptr; - freeList[0]->PrevPtr = nullptr; - used.SetMax(1 << (numLevels)); - for (int i = 1; i < MaxLevels; i++) - { - freeList[i] = nullptr; - } - } - int MemoryPool::AllocBlock(int level) - { - if (level < 0) - return -1; - if (freeList[level] == nullptr) - { - auto largeBlockAddr = AllocBlock(level - 1); - if (largeBlockAddr != -1) - { - auto block1 = (FreeListNode*)(buffer + ((largeBlockAddr ^ (1 << (numLevels - level))) << log2BlockSize)); - block1->NextPtr = nullptr; - block1->PrevPtr = nullptr; - freeList[level] = block1; - - int blockIndex = (1 << level) + (largeBlockAddr >> (numLevels-level)) - 1; - used.Add(blockIndex); - return largeBlockAddr; - } - else - return -1; - } - else - { - auto node = freeList[level]; - if (node->NextPtr) - { - node->NextPtr->PrevPtr = node->PrevPtr; - } - freeList[level] = freeList[level]->NextPtr; - int rs = (int)((unsigned char *)node - buffer) >> log2BlockSize; - int blockIndex = (1 << level) + (rs >> (numLevels - level)) - 1; - used.Add(blockIndex); - return rs; - } - } - unsigned char * MemoryPool::Alloc(int size) - { - if (size == 0) - return nullptr; - int originalSize = size; - if (size < blockSize) - size = blockSize; - int order = numLevels - (Math::Log2Ceil(size) - log2BlockSize); - assert(order >= 0 && order < MaxLevels); - - bytesAllocated += (1 << ((numLevels-order) + log2BlockSize)); - bytesWasted += (1 << ((numLevels - order) + log2BlockSize)) - originalSize; - - int blockId = AllocBlock(order); - if (blockId != -1) - return buffer + (blockId << log2BlockSize); - else - return nullptr; - } - void MemoryPool::FreeBlock(unsigned char * ptr, int level) - { - int indexInLevel = (int)(ptr - buffer) >> (numLevels - level + log2BlockSize); - int blockIndex = (1 << level) + indexInLevel - 1; - assert(used.Contains(blockIndex)); - int buddyIndex = (blockIndex & 1) ? blockIndex + 1 : blockIndex - 1; - used.Remove(blockIndex); - if (level > 0 && !used.Contains(buddyIndex)) - { - auto buddyPtr = (FreeListNode *)(buffer + ((((int)(ptr - buffer) >> log2BlockSize) ^ (1 << (numLevels - level))) << log2BlockSize)); - if (buddyPtr->PrevPtr) - { - buddyPtr->PrevPtr->NextPtr = buddyPtr->NextPtr; - } - if (buddyPtr->NextPtr) - { - buddyPtr->NextPtr->PrevPtr = buddyPtr->PrevPtr; - } - if (freeList[level] == buddyPtr) - { - freeList[level] = buddyPtr->NextPtr; - } - // recursively free parent blocks - auto parentPtr = Math::Min(buddyPtr, (FreeListNode*)ptr); - if (level > 0) - FreeBlock((unsigned char*)parentPtr, level - 1); - } - else - { - // insert to freelist - auto freeNode = (FreeListNode *)ptr; - freeNode->NextPtr = freeList[level]; - freeNode->PrevPtr = nullptr; - if (freeList[level]) - freeList[level]->PrevPtr = freeNode; - freeList[level] = freeNode; - } - } - void MemoryPool::Free(unsigned char * ptr, int size) - { - if (size == 0) - return; - int originalSize = size; - if (size < blockSize) - size = blockSize; - int level = numLevels - (Math::Log2Ceil(size) - log2BlockSize); - bytesAllocated -= (1 << ((numLevels-level) + log2BlockSize)); - bytesWasted -= (1 << ((numLevels - level) + log2BlockSize)) - originalSize; - FreeBlock(ptr, level); - } -} - diff --git a/source/core/memory-pool.h b/source/core/memory-pool.h deleted file mode 100644 index e735fb11c..000000000 --- a/source/core/memory-pool.h +++ /dev/null @@ -1,122 +0,0 @@ -#ifndef CORE_LIB_MEMORY_POOL_H -#define CORE_LIB_MEMORY_POOL_H - -#include "basic.h" -#include "int-set.h" - -namespace Slang -{ - struct MemoryBlockFields - { - unsigned int Occupied : 1; - unsigned int Order : 31; - }; - struct FreeListNode - { - FreeListNode * PrevPtr = nullptr, *NextPtr = nullptr; - }; - class MemoryPool - { - private: - static const int MaxLevels = 32; - int blockSize = 0, log2BlockSize = 0; - int numLevels = 0; - int bytesAllocated = 0; - int bytesWasted = 0; - unsigned char * buffer = nullptr; - FreeListNode * freeList[MaxLevels]; - IntSet used; - int AllocBlock(int level); - void FreeBlock(unsigned char * ptr, int level); - public: - MemoryPool(unsigned char * buffer, int log2BlockSize, int numBlocks); - MemoryPool() = default; - void Init(unsigned char * buffer, int log2BlockSize, int numBlocks); - unsigned char * Alloc(int size); - void Free(unsigned char * ptr, int size); - }; - - class OutofPoolMemoryException : public Exception - {}; - - template<typename T, int PoolSize> - class ObjectPool - { - static const int ObjectSize = sizeof(T) < 8 ? 8 : sizeof(T); - private: - struct FreeList - { - FreeList* Next; - }; - FreeList * freeList = nullptr; - int allocPtr = 0; - int poolSize = 0; - void * buffer = 0; - T * GetFreeObject() - { - if (freeList) - { - auto rs = (T*)freeList; - freeList = freeList->Next; - return rs; - } - return nullptr; - } - public: - ObjectPool() - { - freeList = nullptr; - allocPtr = 0; - buffer = malloc(PoolSize * ObjectSize); - } - - void Close() - { - free(buffer); - } - - void Free(T * obj) - { - auto newList = (FreeList*)obj; - newList->Next = freeList; - freeList = newList; - } - - void * Buffer() - { - return buffer; - } - - T * Alloc() - { - auto rs = GetFreeObject(); - if (!rs) - { - if (allocPtr < PoolSize) - { - rs = (T*)buffer + allocPtr; - allocPtr++; - } - } - if (!rs) - { - throw OutofPoolMemoryException(); - } - return rs; - } - }; -}; - -#define USE_POOL_ALLOCATOR(T, PoolSize) \ -private:\ - static Slang::ObjectPool<T, PoolSize> _pool;\ -public:\ - void * operator new(std::size_t) { return _pool.Alloc(); } \ - void operator delete(void * ptr) {_pool.Free((T*)ptr); }\ - int GetObjectId() { return (int)(this - (T*)_pool.Buffer()); }\ - static void ClosePool(); -#define IMPL_POOL_ALLOCATOR(T, PoolSize) \ -Slang::ObjectPool<T, PoolSize> T::_pool;\ -void T::ClosePool() { _pool.Close(); } - -#endif
\ No newline at end of file diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 5675bf24b..dc2793fc4 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -10,13 +10,6 @@ namespace Slang { - CommandLineWriter * currentCommandWriter = nullptr; - - void SetCommandLineWriter(CommandLineWriter * writer) - { - currentCommandWriter = writer; - } - bool File::Exists(const String & fileName) { #ifdef _WIN32 diff --git a/source/core/slang-io.h b/source/core/slang-io.h index fb9583c67..869fad873 100644 --- a/source/core/slang-io.h +++ b/source/core/slang-io.h @@ -35,26 +35,6 @@ namespace Slang static String Combine(const String & path1, const String & path2, const String & path3); static bool CreateDir(const String & path); }; - - class CommandLineWriter : public Object - { - public: - virtual void Write(const String & text) = 0; - }; - - void SetCommandLineWriter(CommandLineWriter * writer); - - extern CommandLineWriter * currentCommandWriter; - template<typename ...Args> - void uiprintf(const wchar_t * format, Args... args) - { - if (currentCommandWriter) - { - char buffer[1024]; - snprintf(buffer, 1024, format, args...); - currentCommandWriter->Write(buffer); - } - } } #endif
\ No newline at end of file diff --git a/source/core/slang-math.cpp b/source/core/slang-math.cpp deleted file mode 100644 index 76be23f30..000000000 --- a/source/core/slang-math.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "slang-math.h" - -#if 0 -namespace Slang -{ - const float Math::Pi = 3.141592654f; -} -#endif diff --git a/source/core/stream.h b/source/core/stream.h index 1a5f96307..0f5991cb7 100644 --- a/source/core/stream.h +++ b/source/core/stream.h @@ -32,9 +32,10 @@ namespace Slang Start, End, Current }; - class Stream : public Slang::Object + class Stream { public: + virtual ~Stream() {} virtual Int64 GetPosition()=0; virtual void Seek(SeekOrigin origin, Int64 offset)=0; virtual Int64 Read(void * buffer, Int64 length) = 0; @@ -45,147 +46,6 @@ namespace Slang virtual void Close() = 0; }; - class BinaryReader - { - private: - RefPtr<Stream> stream; - inline void Throw(Int64 val) - { - if (val == 0) - throw IOException("read operation failed."); - } - public: - BinaryReader(RefPtr<Stream> stream) - { - this->stream = stream; - } - Stream * GetStream() - { - return stream.Ptr(); - } - void ReleaseStream() - { - stream.Release(); - } - template<typename T> - void Read(T * buffer, int count) - { - stream->Read(buffer, sizeof(T)*(Int64)count); - } - template<typename T> - void Read(T & buffer) - { - Throw(stream->Read(&buffer, sizeof(T))); - } - template<typename T> - void Read(List<T> & buffer) - { - int count = ReadInt32(); - buffer.SetSize(count); - Read(buffer.Buffer(), count); - } - void Read(String & buffer) - { - buffer = ReadString(); - } - int ReadInt32() - { - int rs; - Throw(stream->Read(&rs, sizeof(int))); - return rs; - } - short ReadInt16() - { - short rs; - Throw(stream->Read(&rs, sizeof(short))); - return rs; - } - Int64 ReadInt64() - { - Int64 rs; - Throw(stream->Read(&rs, sizeof(Int64))); - return rs; - } - float ReadFloat() - { - float rs; - Throw(stream->Read(&rs, sizeof(float))); - return rs; - } - double ReadDouble() - { - double rs; - Throw(stream->Read(&rs, sizeof(double))); - return rs; - } - char ReadChar() - { - char rs; - Throw(stream->Read(&rs, sizeof(char))); - return rs; - } - String ReadString() - { - int len = ReadInt32(); - char * buffer = new char[len+1]; - try - { - Throw(stream->Read(buffer, len)); - } - catch(IOException & e) - { - delete [] buffer; - throw e; - } - buffer[len] = 0; - return String::FromBuffer(buffer, len); - } - }; - - class BinaryWriter - { - private: - RefPtr<Stream> stream; - public: - BinaryWriter(RefPtr<Stream> stream) - { - this->stream = stream; - } - Stream * GetStream() - { - return stream.Ptr(); - } - template<typename T> - void Write(const T& val) - { - stream->Write(&val, sizeof(T)); - } - template<typename T> - void Write(T * buffer, int count) - { - stream->Write(buffer, sizeof(T)*(Int64)count); - } - template<typename T> - void Write(const List<T> & list) - { - Write(list.Count()); - stream->Write(list.Buffer(), sizeof(T)*list.Count()); - } - void Write(const String & str) - { - Write(str.Length()); - Write(str.Buffer(), str.Length()); - } - void ReleaseStream() - { - stream.Release(); - } - void Close() - { - stream->Close(); - } - }; - enum class FileMode { Create, Open, CreateNew, Append @@ -222,105 +82,6 @@ namespace Slang virtual void Close(); virtual bool IsEnd(); }; - - class MemoryStream : public Stream - { - private: - List<unsigned char> writeBuffer; - ArrayView<unsigned char> readBuffer; - int ptr = 0; - bool isReadStream; - public: - MemoryStream() - { - isReadStream = false; - } - MemoryStream(unsigned char * mem, int length) - { - isReadStream = true; - readBuffer = MakeArrayView(mem, length); - } - MemoryStream(ArrayView<unsigned char> source) - { - isReadStream = true; - readBuffer = source; - } - virtual Int64 GetPosition() - { - return ptr; - } - virtual void Seek(SeekOrigin origin, Int64 offset) - { - if (origin == SeekOrigin::Start) - ptr = (int)offset; - else if (origin == SeekOrigin::End) - { - if (isReadStream) - ptr = readBuffer.Count() + (int)offset; - else - ptr = writeBuffer.Count() + (int)offset; - } - } - virtual Int64 Read(void * pbuffer, Int64 length) - { - Int64 i; - for (i = 0; i < length; i++) - { - if (ptr + i < readBuffer.Count()) - { - ((unsigned char*)pbuffer)[i] = readBuffer[(int)(ptr + i)]; - } - else - break; - } - return i; - } - virtual Int64 Write(const void * pbuffer, Int64 length) - { - writeBuffer.SetSize(ptr); - if (pbuffer) - writeBuffer.AddRange((unsigned char *)pbuffer, (int)length); - else - for (auto i = 0; i < length; i++) - writeBuffer.Add(0); - ptr = writeBuffer.Count(); - return length; - } - virtual bool CanRead() - { - return isReadStream; - } - virtual bool CanWrite() - { - return !isReadStream; - } - virtual void Close() - { - writeBuffer.SetSize(0); - writeBuffer.Compress(); - } - virtual bool IsEnd() - { - if (isReadStream) - return ptr >= readBuffer.Count(); - else - return ptr == writeBuffer.Count(); - } - void * GetBuffer() - { - if (isReadStream) - return readBuffer.Buffer(); - else - return writeBuffer.Buffer(); - } - int GetBufferSize() - { - if (isReadStream) - return readBuffer.Count(); - else - return writeBuffer.Count(); - } - }; } #endif diff --git a/source/core/text-io.h b/source/core/text-io.h index e0881cb91..acdaf0b9d 100644 --- a/source/core/text-io.h +++ b/source/core/text-io.h @@ -9,14 +9,14 @@ namespace Slang using Slang::List; using Slang::_EndLine; - class TextReader : public Slang::Object + class TextReader { protected: char decodedChar[5]; int decodedCharPtr = 0, decodedCharSize = 0; virtual void ReadChar() = 0; public: - ~TextReader() + virtual ~TextReader() { Close(); } @@ -45,10 +45,10 @@ namespace Slang } }; - class TextWriter : public Slang::Object + class TextWriter { public: - ~TextWriter() + virtual ~TextWriter() { Close(); } @@ -267,7 +267,7 @@ namespace Slang } }; - class StreamReader : public TextReader + class StreamReader : public TextReader { private: RefPtr<Stream> stream; @@ -311,7 +311,6 @@ namespace Slang stream.Release(); } }; - } #endif diff --git a/source/slang/check.cpp b/source/slang/check.cpp index b3e1baf79..8fcd905c8 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -1068,7 +1068,7 @@ namespace Slang return genericDecl; } - virtual void visitInterfaceDecl(InterfaceDecl* decl) override + virtual void visitInterfaceDecl(InterfaceDecl* /*decl*/) override { // TODO: do some actual checking of members here } diff --git a/source/slang/compiler.h b/source/slang/compiler.h index 3b6696647..f34be794b 100644 --- a/source/slang/compiler.h +++ b/source/slang/compiler.h @@ -152,28 +152,6 @@ namespace Slang TranslationUnitOptions const& getTranslationUnitOptions() { return *translationUnitOptions; } }; -#if 0 - - class ShaderCompiler : public Slang::Object - { - public: - virtual void Compile( - CompileResult& result, - CollectionOfTranslationUnits* collectionOfTranslationUnits, - const CompileOptions& options, - CompileRequest* request) = 0; - - virtual TranslationUnitResult PassThrough( - String const& sourceText, - String const& sourcePath, - const CompileOptions & options, - TranslationUnitOptions const& translationUnitOptions) = 0; - - }; - - ShaderCompiler * CreateShaderCompiler(); -#endif - TranslationUnitResult passThrough( String const& sourceText, String const& sourcePath, diff --git a/source/slang/diagnostics.cpp b/source/slang/diagnostics.cpp index e9c7e965a..45c0c9b76 100644 --- a/source/slang/diagnostics.cpp +++ b/source/slang/diagnostics.cpp @@ -36,11 +36,6 @@ void printDiagnosticArg(StringBuilder& sb, Decl* decl) sb << decl->Name.Content; } -void printDiagnosticArg(StringBuilder& sb, Type* type) -{ - sb << type->DataType->ToString(); -} - void printDiagnosticArg(StringBuilder& sb, ExpressionType* type) { sb << type->ToString(); @@ -174,10 +169,10 @@ void DiagnosticSink::diagnoseImpl(CodePosition const& pos, DiagnosticInfo const& if( callback ) { // If so, pass the error string along to them - StringBuilder sb; - formatDiagnostic(sb, diagnostic); + StringBuilder messageBuilder; + formatDiagnostic(messageBuilder, diagnostic); - callback(sb.ProduceString().begin(), callbackUserData); + callback(messageBuilder.ProduceString().begin(), callbackUserData); } else { diff --git a/source/slang/syntax.h b/source/slang/syntax.h index 3cd46914f..96eb3d530 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -1133,16 +1133,6 @@ namespace Slang return 0; } - class Type - { - public: - RefPtr<ExpressionType> DataType; - // ContrainedWorlds: Implementation must be defined at at least one of of these worlds in order to satisfy global dependency - // FeasibleWorlds: The component can be computed at any of these worlds - EnumerableHashSet<String> ConstrainedWorlds, FeasibleWorlds; - EnumerableHashSet<String> PinnedWorlds; - }; - class ContainerDecl; @@ -2507,7 +2497,7 @@ namespace Slang // - class SyntaxVisitor : public Object + class SyntaxVisitor { protected: DiagnosticSink * sink = nullptr; @@ -2523,6 +2513,10 @@ namespace Slang SyntaxVisitor(DiagnosticSink * sink) : sink(sink) {} + virtual ~SyntaxVisitor() + { + } + virtual RefPtr<ProgramSyntaxNode> VisitProgram(ProgramSyntaxNode* program) { for (auto & m : program->Members) |
