summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-07-06 13:15:26 -0700
committerGitHub <noreply@github.com>2017-07-06 13:15:26 -0700
commitaf8c0eae90c76d2c8f745badf6f743cefe15f777 (patch)
tree57632ee0f4b4944b311c0e50173fbeab0fe7d109 /source
parent21a14cb4e0d578bc4f8a460016269a1199cac0da (diff)
parent9795ed654e7b8daaff0bef1ccae1507ff659d3bd (diff)
Merge pull request #54 from tfoleyNV/falcor-fixes
Fix issues found during testing of v0.4.0 with Falcor
Diffstat (limited to 'source')
-rw-r--r--source/core/exception.h7
-rw-r--r--source/core/int-set.h36
-rw-r--r--source/core/list.h98
-rw-r--r--source/core/slang-io.cpp6
-rw-r--r--source/core/slang-string.cpp2
-rw-r--r--source/core/slang-string.h18
-rw-r--r--source/core/smart-pointer.h1
-rw-r--r--source/core/text-io.cpp2
-rw-r--r--source/core/text-io.h2
-rw-r--r--source/slang/check.cpp50
-rw-r--r--source/slang/diagnostics.cpp6
-rw-r--r--source/slang/diagnostics.h1
-rw-r--r--source/slang/emit.cpp44
-rw-r--r--source/slang/lower.cpp292
-rw-r--r--source/slang/options.cpp2
-rw-r--r--source/slang/parameter-binding.cpp66
-rw-r--r--source/slang/preprocessor.cpp6
-rw-r--r--source/slang/reflection.cpp6
-rw-r--r--source/slang/slang-stdlib.cpp5
-rw-r--r--source/slang/slang.cpp39
-rw-r--r--source/slang/syntax.cpp4
-rw-r--r--source/slang/syntax.h4
-rw-r--r--source/slang/type-layout.cpp20
23 files changed, 471 insertions, 246 deletions
diff --git a/source/core/exception.h b/source/core/exception.h
index 6739c6778..dc674de7f 100644
--- a/source/core/exception.h
+++ b/source/core/exception.h
@@ -110,6 +110,13 @@ namespace Slang
{
}
};
+
+ #define SLANG_UNEXPECTED(reason) \
+ throw Slang::Exception("unexpected: " reason)
+
+ #define SLANG_UNIMPLEMENTED_X(what) \
+ throw Slang::NotImplementedException("unimplemented: " what)
+
}
#endif \ No newline at end of file
diff --git a/source/core/int-set.h b/source/core/int-set.h
index a56a58d64..6b6f5e7a8 100644
--- a/source/core/int-set.h
+++ b/source/core/int-set.h
@@ -46,7 +46,7 @@ namespace Slang
{
SetMax(maxVal);
}
- int Size() const
+ UInt Size() const
{
return buffer.Count()*32;
}
@@ -57,40 +57,40 @@ namespace Slang
}
void SetAll()
{
- for (int i = 0; i<buffer.Count(); i++)
+ for (UInt i = 0; i<buffer.Count(); i++)
buffer[i] = 0xFFFFFFFF;
}
- void Resize(int size)
+ void Resize(UInt size)
{
- int oldBufferSize = buffer.Count();
+ UInt oldBufferSize = buffer.Count();
buffer.SetSize((size+31)>>5);
if (buffer.Count() > oldBufferSize)
memset(buffer.Buffer()+oldBufferSize, 0, (buffer.Count()-oldBufferSize) * sizeof(int));
}
void Clear()
{
- for (int i = 0; i<buffer.Count(); i++)
+ for (UInt i = 0; i<buffer.Count(); i++)
buffer[i] = 0;
}
- void Add(int val)
+ void Add(UInt val)
{
- int id = val>>5;
+ UInt id = val>>5;
if (id < buffer.Count())
buffer[id] |= (1<<(val&31));
else
{
- int oldSize = buffer.Count();
+ UInt oldSize = buffer.Count();
buffer.SetSize(id+1);
memset(buffer.Buffer() + oldSize, 0, (buffer.Count()-oldSize)*sizeof(int));
buffer[id] |= (1<<(val&31));
}
}
- void Remove(int val)
+ void Remove(UInt val)
{
if ((val>>5) < buffer.Count())
buffer[(val>>5)] &= ~(1<<(val&31));
}
- bool Contains(int val) const
+ bool Contains(UInt val) const
{
if ((val>>5) >= buffer.Count())
return false;
@@ -98,7 +98,7 @@ namespace Slang
}
void UnionWith(const IntSet & set)
{
- for (int i = 0; i<Math::Min(set.buffer.Count(), buffer.Count()); i++)
+ for (UInt i = 0; i<Math::Min(set.buffer.Count(), buffer.Count()); i++)
{
buffer[i] |= set.buffer[i];
}
@@ -109,7 +109,7 @@ namespace Slang
{
if (buffer.Count() != set.buffer.Count())
return false;
- for (int i = 0; i<buffer.Count(); i++)
+ for (UInt i = 0; i<buffer.Count(); i++)
if (buffer[i] != set.buffer[i])
return false;
return true;
@@ -122,7 +122,7 @@ namespace Slang
{
if (set.buffer.Count() < buffer.Count())
memset(buffer.Buffer() + set.buffer.Count(), 0, (buffer.Count()-set.buffer.Count())*sizeof(int));
- for (int i = 0; i<Math::Min(set.buffer.Count(), buffer.Count()); i++)
+ for (UInt i = 0; i<Math::Min(set.buffer.Count(), buffer.Count()); i++)
{
buffer[i] &= set.buffer[i];
}
@@ -131,26 +131,26 @@ namespace Slang
{
rs.buffer.SetSize(Math::Max(set1.buffer.Count(), set2.buffer.Count()));
rs.Clear();
- for (int i = 0; i<set1.buffer.Count(); i++)
+ for (UInt i = 0; i<set1.buffer.Count(); i++)
rs.buffer[i] |= set1.buffer[i];
- for (int i = 0; i<set2.buffer.Count(); i++)
+ for (UInt i = 0; i<set2.buffer.Count(); i++)
rs.buffer[i] |= set2.buffer[i];
}
static void Intersect(IntSet & rs, const IntSet & set1, const IntSet & set2)
{
rs.buffer.SetSize(Math::Min(set1.buffer.Count(), set2.buffer.Count()));
- for (int i = 0; i<rs.buffer.Count(); i++)
+ for (UInt i = 0; i<rs.buffer.Count(); i++)
rs.buffer[i] = set1.buffer[i] & set2.buffer[i];
}
static void Subtract(IntSet & rs, const IntSet & set1, const IntSet & set2)
{
rs.buffer.SetSize(set1.buffer.Count());
- for (int i = 0; i<Math::Min(set1.buffer.Count(), set2.buffer.Count()); i++)
+ for (UInt i = 0; i<Math::Min(set1.buffer.Count(), set2.buffer.Count()); i++)
rs.buffer[i] = set1.buffer[i] & (~set2.buffer[i]);
}
static bool HasIntersection(const IntSet & set1, const IntSet & set2)
{
- for (int i = 0; i<Math::Min(set1.buffer.Count(), set2.buffer.Count()); i++)
+ for (UInt i = 0; i<Math::Min(set1.buffer.Count(), set2.buffer.Count()); i++)
{
if (set1.buffer[i] & set2.buffer[i])
return true;
diff --git a/source/core/list.h b/source/core/list.h
index 5315f788f..aeba9557f 100644
--- a/source/core/list.h
+++ b/source/core/list.h
@@ -34,19 +34,19 @@ namespace Slang
class AllocateMethod
{
public:
- static inline T* Alloc(int size)
+ static inline T* Alloc(UInt size)
{
TAllocator allocator;
T * rs = (T*)allocator.Alloc(size*sizeof(T));
Initializer<T, std::is_pod<T>::value>::Initialize(rs, size);
return rs;
}
- static inline void Free(T * ptr, int bufferSize)
+ static inline void Free(T * ptr, UInt bufferSize)
{
TAllocator allocator;
if (!std::is_trivially_destructible<T>::value)
{
- for (int i = 0; i<bufferSize; i++)
+ for (UInt i = 0; i<bufferSize; i++)
ptr[i].~T();
}
allocator.Free(ptr);
@@ -57,11 +57,11 @@ namespace Slang
class AllocateMethod<T, StandardAllocator>
{
public:
- static inline T* Alloc(int size)
+ static inline T* Alloc(UInt size)
{
return new T[size];
}
- static inline void Free(T* ptr, int /*bufferSize*/)
+ static inline void Free(T* ptr, UInt /*bufferSize*/)
{
delete [] ptr;
}
@@ -83,7 +83,7 @@ namespace Slang
{
private:
- inline T * Allocate(int size)
+ inline T * Allocate(UInt size)
{
return AllocateMethod<T, TAllocator>::Alloc(size);
@@ -92,9 +92,9 @@ namespace Slang
static const int InitialSize = 16;
TAllocator allocator;
private:
- T * buffer;
- int _count;
- int bufferSize;
+ T* buffer;
+ UInt _count;
+ UInt bufferSize;
void FreeBuffer()
{
AllocateMethod<T, TAllocator>::Free(buffer, bufferSize);
@@ -239,7 +239,7 @@ namespace Slang
{
if (bufferSize < _count + 1)
{
- int newBufferSize = InitialSize;
+ UInt newBufferSize = InitialSize;
if (bufferSize)
newBufferSize = (bufferSize << 1);
@@ -252,7 +252,7 @@ namespace Slang
{
if (bufferSize < _count + 1)
{
- int newBufferSize = InitialSize;
+ UInt newBufferSize = InitialSize;
if (bufferSize)
newBufferSize = (bufferSize << 1);
@@ -262,7 +262,7 @@ namespace Slang
}
- int Count() const
+ UInt Count() const
{
return _count;
}
@@ -272,21 +272,21 @@ namespace Slang
return buffer;
}
- int Capacity() const
+ UInt Capacity() const
{
return bufferSize;
}
- void Insert(int id, const T & val)
+ void Insert(UInt id, const T & val)
{
InsertRange(id, &val, 1);
}
- void InsertRange(int id, const T * vals, int n)
+ void InsertRange(UInt id, const T * vals, UInt n)
{
if (bufferSize < _count + n)
{
- int newBufferSize = InitialSize;
+ UInt newBufferSize = InitialSize;
while (newBufferSize < _count + n)
newBufferSize = newBufferSize << 1;
@@ -300,9 +300,9 @@ namespace Slang
}
else*/
{
- for (int i = 0; i < id; i++)
+ for (UInt i = 0; i < id; i++)
newBuffer[i] = buffer[i];
- for (int i = id; i < _count; i++)
+ for (UInt i = id; i < _count; i++)
newBuffer[i + n] = T(static_cast<T&&>(buffer[i]));
}
FreeBuffer();
@@ -316,14 +316,14 @@ namespace Slang
memmove(buffer + id + n, buffer + id, sizeof(T) * (_count - id));
else*/
{
- for (int i = _count - 1; i >= id; i--)
- buffer[i + n] = static_cast<T&&>(buffer[i]);
+ for (UInt i = _count; i > id; i--)
+ buffer[i + n - 1] = static_cast<T&&>(buffer[i - 1]);
}
}
/*if (std::has_trivial_copy_assign<T>::value && std::has_trivial_destructor<T>::value)
memcpy(buffer + id, vals, sizeof(T) * n);
else*/
- for (int i = 0; i < n; i++)
+ for (UInt i = 0; i < n; i++)
buffer[id + i] = vals[i];
_count += n;
@@ -345,7 +345,7 @@ namespace Slang
InsertRange(_count, list.Buffer(), list.Count());
}
- void AddRange(const T * vals, int n)
+ void AddRange(const T * vals, UInt n)
{
InsertRange(_count, vals, n);
}
@@ -355,21 +355,19 @@ namespace Slang
InsertRange(_count, list.buffer, list._count);
}
- void RemoveRange(int id, int deleteCount)
+ void RemoveRange(UInt id, UInt deleteCount)
{
#if _DEBUG
- if (id >= _count || id < 0)
+ if (id >= _count)
throw "Remove: Index out of range.";
- if(deleteCount < 0)
- throw "Remove: deleteCount smaller than zero.";
#endif
- int actualDeleteCount = ((id + deleteCount) >= _count)? (_count - id) : deleteCount;
- for (int i = id + actualDeleteCount; i < _count; i++)
+ UInt actualDeleteCount = ((id + deleteCount) >= _count)? (_count - id) : deleteCount;
+ for (UInt i = id + actualDeleteCount; i < _count; i++)
buffer[i - actualDeleteCount] = static_cast<T&&>(buffer[i]);
_count -= actualDeleteCount;
}
- void RemoveAt(int id)
+ void RemoveAt(UInt id)
{
RemoveRange(id, 1);
}
@@ -395,7 +393,7 @@ namespace Slang
FastRemoveAt(idx);
}
- void FastRemoveAt(int idx)
+ void FastRemoveAt(UInt idx)
{
if (idx != -1 && _count - 1 != idx)
{
@@ -409,7 +407,7 @@ namespace Slang
_count = 0;
}
- void Reserve(int size)
+ void Reserve(UInt size)
{
if(size > bufferSize)
{
@@ -420,7 +418,7 @@ namespace Slang
memcpy(newBuffer, buffer, _count * sizeof(T));
else*/
{
- for (int i = 0; i < _count; i++)
+ for (UInt i = 0; i < _count; i++)
newBuffer[i] = static_cast<T&&>(buffer[i]);
}
FreeBuffer();
@@ -430,9 +428,9 @@ namespace Slang
}
}
- void GrowToSize(int size)
+ void GrowToSize(UInt size)
{
- int newBufferSize = 1<<Math::Log2Ceil(size);
+ UInt newBufferSize = UInt(1) << Math::Log2Ceil(size);
if (bufferSize < newBufferSize)
{
Reserve(newBufferSize);
@@ -440,13 +438,13 @@ namespace Slang
this->_count = size;
}
- void SetSize(int size)
+ void SetSize(UInt size)
{
Reserve(size);
_count = size;
}
- void UnsafeShrinkToSize(int size)
+ void UnsafeShrinkToSize(UInt size)
{
_count = size;
}
@@ -472,19 +470,19 @@ namespace Slang
#endif
#endif
- FORCE_INLINE T & operator [](int id) const
+ FORCE_INLINE T & operator [](UInt id) const
{
#if _DEBUG
- if(id >= _count || id < 0)
+ if(id >= _count)
throw IndexOutofRangeException("Operator[]: Index out of Range.");
#endif
return buffer[id];
}
template<typename Func>
- int FindFirst(const Func & predicate) const
+ UInt FindFirst(const Func & predicate) const
{
- for (int i = 0; i < _count; i++)
+ for (UInt i = 0; i < _count; i++)
{
if (predicate(buffer[i]))
return i;
@@ -493,18 +491,18 @@ namespace Slang
}
template<typename Func>
- int FindLast(const Func & predicate) const
+ UInt FindLast(const Func & predicate) const
{
- for (int i = _count - 1; i >= 0; i--)
+ for (UInt i = _count; i > 0; i--)
{
- if (predicate(buffer[i]))
- return i;
+ if (predicate(buffer[i-1]))
+ return i-1;
}
return -1;
}
template<typename T2>
- int IndexOf(const T2 & val) const
+ UInt IndexOf(const T2 & val) const
{
for (int i = 0; i < _count; i++)
{
@@ -515,12 +513,12 @@ namespace Slang
}
template<typename T2>
- int LastIndexOf(const T2 & val) const
+ UInt LastIndexOf(const T2 & val) const
{
- for (int i = _count - 1; i >= 0; i--)
+ for (int i = _count; i > 0; i--)
{
- if(buffer[i] == val)
- return i;
+ if(buffer[i-1] == val)
+ return i-1;
}
return -1;
}
@@ -532,7 +530,7 @@ namespace Slang
bool Contains(const T & val)
{
- for (int i = 0; i<_count; i++)
+ for (UInt i = 0; i<_count; i++)
if (buffer[i] == val)
return true;
return false;
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 684fed0a1..24d5aa412 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -23,7 +23,7 @@ namespace Slang
String Path::TruncateExt(const String & path)
{
- int dotPos = path.LastIndexOf('.');
+ UInt dotPos = path.LastIndexOf('.');
if (dotPos != -1)
return path.SubString(0, dotPos);
else
@@ -32,7 +32,7 @@ namespace Slang
String Path::ReplaceExt(const String & path, const char * newExt)
{
StringBuilder sb(path.Length()+10);
- int dotPos = path.LastIndexOf('.');
+ UInt dotPos = path.LastIndexOf('.');
if (dotPos == -1)
dotPos = path.Length();
sb.Append(path.Buffer(), dotPos);
@@ -72,7 +72,7 @@ namespace Slang
String Path::GetFileNameWithoutEXT(const String & path)
{
String fileName = GetFileName(path);
- int dotPos = fileName.LastIndexOf('.');
+ UInt dotPos = fileName.LastIndexOf('.');
if (dotPos == -1)
return fileName;
return fileName.SubString(0, dotPos);
diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp
index 3b9bcc87f..8938db595 100644
--- a/source/core/slang-string.cpp
+++ b/source/core/slang-string.cpp
@@ -149,7 +149,7 @@ namespace Slang
return String(buf);
}
- OSString String::ToWString(int* outLength) const
+ OSString String::ToWString(UInt* outLength) const
{
if (!buffer)
{
diff --git a/source/core/slang-string.h b/source/core/slang-string.h
index 8294d4bc3..3c1b48e8c 100644
--- a/source/core/slang-string.h
+++ b/source/core/slang-string.h
@@ -452,7 +452,7 @@ namespace Slang
return getData();
}
- OSString ToWString(int* len = 0) const;
+ OSString ToWString(UInt* len = 0) const;
bool Equals(const String & str, bool caseSensitive = true)
{
@@ -506,7 +506,7 @@ namespace Slang
String result;
for (auto c : *this)
{
- int d = (c >= 'a' && c <= 'z') ? (c - ('a' - 'A')) : c;
+ char d = (c >= 'a' && c <= 'z') ? (c - ('a' - 'A')) : c;
result.append(d);
}
return result;
@@ -517,7 +517,7 @@ namespace Slang
String result;
for (auto c : *this)
{
- int d = (c >= 'A' && c <= 'Z') ? (c - ('A' - 'a')) : c;
+ char d = (c >= 'A' && c <= 'Z') ? (c - ('A' - 'a')) : c;
result.append(d);
}
return result;
@@ -636,13 +636,13 @@ namespace Slang
class StringBuilder : public String
{
private:
- static const int InitialSize = 1024;
+ enum { InitialSize = 1024 };
public:
- explicit StringBuilder(int bufferSize = InitialSize)
+ explicit StringBuilder(UInt bufferSize = InitialSize)
{
ensureUniqueStorageWithCapacity(bufferSize);
}
- void EnsureCapacity(int size)
+ void EnsureCapacity(UInt size)
{
ensureUniqueStorageWithCapacity(size);
}
@@ -678,7 +678,7 @@ namespace Slang
}
StringBuilder & operator << (const char * str)
{
- Append(str, (int)strlen(str));
+ Append(str, strlen(str));
return *this;
}
StringBuilder & operator << (const String & str)
@@ -736,9 +736,9 @@ namespace Slang
}
void Append(const char * str)
{
- Append(str, (int)strlen(str));
+ Append(str, strlen(str));
}
- void Append(const char * str, int strLen)
+ void Append(const char * str, UInt strLen)
{
append(str, str + strLen);
}
diff --git a/source/core/smart-pointer.h b/source/core/smart-pointer.h
index c31cdefe0..19ddde931 100644
--- a/source/core/smart-pointer.h
+++ b/source/core/smart-pointer.h
@@ -9,6 +9,7 @@ namespace Slang
{
// TODO: Need to centralize these typedefs
typedef uintptr_t UInt;
+ typedef intptr_t Int;
// Base class for all reference-counted objects
class RefObject
diff --git a/source/core/text-io.cpp b/source/core/text-io.cpp
index 7815d7422..ec41b8d7d 100644
--- a/source/core/text-io.cpp
+++ b/source/core/text-io.cpp
@@ -215,7 +215,7 @@ namespace Slang
{
#ifdef _WIN32
int flag = IS_TEXT_UNICODE_SIGNATURE | IS_TEXT_UNICODE_REVERSE_SIGNATURE | IS_TEXT_UNICODE_STATISTICS | IS_TEXT_UNICODE_ASCII16;
- int rs = IsTextUnicode(buffer.Buffer(), buffer.Count(), &flag);
+ int rs = IsTextUnicode(buffer.Buffer(), (int) buffer.Count(), &flag);
if (rs)
{
if (flag & (IS_TEXT_UNICODE_SIGNATURE | IS_TEXT_UNICODE_STATISTICS))
diff --git a/source/core/text-io.h b/source/core/text-io.h
index 9519d51f1..c914e340a 100644
--- a/source/core/text-io.h
+++ b/source/core/text-io.h
@@ -273,7 +273,7 @@ namespace Slang
RefPtr<Stream> stream;
List<char> buffer;
Encoding * encoding;
- int ptr;
+ UInt ptr;
char ReadBufferChar();
void ReadBuffer();
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index a79af3f37..2d61c60a4 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -717,7 +717,7 @@ namespace Slang
// up with initializer arguments.
- int argIndex = 0;
+ UInt argIndex = 0;
for(auto fieldDeclRef : getMembersOfType<StructField>(toStructDeclRef))
{
if(argIndex >= argCount)
@@ -1144,27 +1144,27 @@ namespace Slang
return constIntVal;
}
- void visit(ModifierDecl* decl)
+ void visit(ModifierDecl*)
{
// These are only used in the stdlib, so no checking is needed
}
- void visit(GenericTypeParamDecl* decl)
+ void visit(GenericTypeParamDecl*)
{
// These are only used in the stdlib, so no checking is needed for now
}
- void visit(GenericValueParamDecl* decl)
+ void visit(GenericValueParamDecl*)
{
// These are only used in the stdlib, so no checking is needed for now
}
- void visit(GenericTypeConstraintDecl* decl)
+ void visit(GenericTypeConstraintDecl*)
{
// These are only used in the stdlib, so no checking is needed for now
}
- void visit(Modifier* modifier)
+ void visit(Modifier*)
{
// Do nothing with modifiers for now
}
@@ -1442,7 +1442,7 @@ namespace Slang
if (fstParamCount != sndParamCount)
return false;
- for (int ii = 0; ii < fstParamCount; ++ii)
+ for (UInt ii = 0; ii < fstParamCount; ++ii)
{
auto fstParam = fstParams[ii];
auto sndParam = sndParams[ii];
@@ -1597,10 +1597,10 @@ namespace Slang
template<typename T>
T* FindOuterStmt()
{
- int outerStmtCount = outerStmts.Count();
- for (int ii = outerStmtCount - 1; ii >= 0; --ii)
+ UInt outerStmtCount = outerStmts.Count();
+ for (UInt ii = outerStmtCount; ii > 0; --ii)
{
- auto outerStmt = outerStmts[ii];
+ auto outerStmt = outerStmts[ii-1];
auto found = dynamic_cast<T*>(outerStmt);
if (found)
return found;
@@ -2988,8 +2988,8 @@ namespace Slang
struct ParamCounts
{
- int required;
- int allowed;
+ UInt required;
+ UInt allowed;
};
// count the number of parameters required/allowed for a callable
@@ -3048,7 +3048,7 @@ namespace Slang
OverloadResolveContext& context,
OverloadCandidate const& candidate)
{
- int argCount = context.appExpr->Arguments.Count();
+ UInt argCount = context.appExpr->Arguments.Count();
ParamCounts paramCounts = { 0, 0 };
switch (candidate.flavor)
{
@@ -3187,7 +3187,7 @@ namespace Slang
OverloadCandidate& candidate)
{
auto& args = context.appExpr->Arguments;
- int argCount = args.Count();
+ UInt argCount = args.Count();
List<DeclRef<ParameterSyntaxNode>> params;
switch (candidate.flavor)
@@ -3208,7 +3208,7 @@ namespace Slang
// case where one or more parameters had defaults.
assert(argCount <= params.Count());
- for (int ii = 0; ii < argCount; ++ii)
+ for (UInt ii = 0; ii < argCount; ++ii)
{
auto& arg = args[ii];
auto param = params[ii];
@@ -3410,7 +3410,7 @@ namespace Slang
bool anyFiltered = false;
// Note that we are querying the list length on every iteration,
// because we might remove things.
- for (int cc = 0; cc < context.bestCandidates.Count(); ++cc)
+ for (UInt cc = 0; cc < context.bestCandidates.Count(); ++cc)
{
int cmp = CompareOverloadCandidates(&candidate, &context.bestCandidates[cc]);
if (cmp < 0)
@@ -3624,8 +3624,8 @@ namespace Slang
// Their arguments must unify
assert(fst->args.Count() == snd->args.Count());
- int argCount = fst->args.Count();
- for (int aa = 0; aa < argCount; ++aa)
+ UInt argCount = fst->args.Count();
+ for (UInt aa = 0; aa < argCount; ++aa)
{
if (!TryUnifyVals(constraints, fst->args[aa], snd->args[aa]))
return false;
@@ -3865,8 +3865,8 @@ namespace Slang
auto& args = context.appExpr->Arguments;
auto params = GetParameters(funcDeclRef).ToArray();
- int argCount = args.Count();
- int paramCount = params.Count();
+ UInt argCount = args.Count();
+ UInt paramCount = params.Count();
// Bail out on mismatch.
// TODO(tfoley): need more nuance here
@@ -3875,7 +3875,7 @@ namespace Slang
return DeclRef<Decl>(nullptr, nullptr);
}
- for (int aa = 0; aa < argCount; ++aa)
+ for (UInt aa = 0; aa < argCount; ++aa)
{
#if 0
if (!TryUnifyArgAndParamTypes(constraints, args[aa], params[aa]))
@@ -4289,9 +4289,9 @@ namespace Slang
}
}
- int candidateCount = context.bestCandidates.Count();
- int maxCandidatesToPrint = 10; // don't show too many candidates at once...
- int candidateIndex = 0;
+ UInt candidateCount = context.bestCandidates.Count();
+ UInt maxCandidatesToPrint = 10; // don't show too many candidates at once...
+ UInt candidateIndex = 0;
for (auto candidate : context.bestCandidates)
{
String declString = getDeclSignatureString(candidate.item);
@@ -4561,7 +4561,7 @@ namespace Slang
}
if (params)
{
- for (int i = 0; i < (*params).Count(); i++)
+ for (UInt i = 0; i < (*params).Count(); i++)
{
if ((*params)[i]->HasModifier<OutModifier>())
{
diff --git a/source/slang/diagnostics.cpp b/source/slang/diagnostics.cpp
index 45c0c9b76..0c55a94bd 100644
--- a/source/slang/diagnostics.cpp
+++ b/source/slang/diagnostics.cpp
@@ -26,6 +26,12 @@ void printDiagnosticArg(StringBuilder& sb, int str)
sb << str;
}
+void printDiagnosticArg(StringBuilder& sb, UInt val)
+{
+ // TODO: make this robust
+ sb << (int) val;
+}
+
void printDiagnosticArg(StringBuilder& sb, Slang::String const& str)
{
sb << str;
diff --git a/source/slang/diagnostics.h b/source/slang/diagnostics.h
index 4c698f95b..8834f1a6e 100644
--- a/source/slang/diagnostics.h
+++ b/source/slang/diagnostics.h
@@ -77,6 +77,7 @@ namespace Slang
void printDiagnosticArg(StringBuilder& sb, char const* str);
void printDiagnosticArg(StringBuilder& sb, int val);
+ void printDiagnosticArg(StringBuilder& sb, UInt val);
void printDiagnosticArg(StringBuilder& sb, Slang::String const& str);
void printDiagnosticArg(StringBuilder& sb, Decl* decl);
void printDiagnosticArg(StringBuilder& sb, Type* type);
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index 71b39aabb..79a8277bf 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -549,8 +549,8 @@ static void emitSimpleCallExpr(
}
Emit(context, "(");
- int argCount = callExpr->Arguments.Count();
- for (int aa = 0; aa < argCount; ++aa)
+ UInt argCount = callExpr->Arguments.Count();
+ for (UInt aa = 0; aa < argCount; ++aa)
{
if (aa != 0) Emit(context, ", ");
EmitExpr(context, callExpr->Arguments[aa]);
@@ -721,8 +721,8 @@ static void emitCallExpr(
emit(context, name);
Emit(context, "(");
- int argCount = callExpr->Arguments.Count();
- for (int aa = 0; aa < argCount; ++aa)
+ UInt argCount = callExpr->Arguments.Count();
+ for (UInt aa = 0; aa < argCount; ++aa)
{
if (aa != 0) Emit(context, ", ");
EmitExpr(context, callExpr->Arguments[aa]);
@@ -734,7 +734,7 @@ static void emitCallExpr(
{
// General case: we are going to emit some more complex text.
- int argCount = callExpr->Arguments.Count();
+ UInt argCount = callExpr->Arguments.Count();
Emit(context, "(");
@@ -782,8 +782,8 @@ static void emitCallExpr(
Emit(context, "(");
EmitExpr(context, memberExpr->BaseExpression);
Emit(context, ")[");
- int argCount = callExpr->Arguments.Count();
- for (int aa = 0; aa < argCount; ++aa)
+ UInt argCount = callExpr->Arguments.Count();
+ for (UInt aa = 0; aa < argCount; ++aa)
{
if (aa != 0) Emit(context, ", ");
EmitExpr(context, callExpr->Arguments[aa]);
@@ -1483,12 +1483,6 @@ static void EmitType(EmitContext* context, RefPtr<ExpressionType> type, Token co
EmitType(context, type, CodePosition(), nameToken.Content, nameToken.Position);
}
-
-static void EmitType(EmitContext* context, RefPtr<ExpressionType> type, String const& name)
-{
- EmitType(context, type, CodePosition(), name, CodePosition());
-}
-
static void EmitType(EmitContext* context, RefPtr<ExpressionType> type)
{
EmitType(context, type, nullptr);
@@ -1497,21 +1491,17 @@ static void EmitType(EmitContext* context, RefPtr<ExpressionType> type)
static void EmitType(EmitContext* context, TypeExp const& typeExp, Token const& nameToken)
{
EmitType(context, typeExp.type,
- typeExp.exp ? typeExp.exp->Position : CodePosition(), nameToken.Content, nameToken.Position);
+ typeExp.exp ? typeExp.exp->Position : CodePosition(),
+ nameToken.Content, nameToken.Position);
}
static void EmitType(EmitContext* context, TypeExp const& typeExp, String const& name)
{
- EmitType(context, typeExp.type, typeExp.exp->Position, name, CodePosition());
-}
-
-static void EmitType(EmitContext* context, TypeExp const& typeExp)
-{
- advanceToSourceLocation(context, typeExp.exp->Position);
- EmitType(context, typeExp.type, nullptr);
+ EmitType(context, typeExp.type,
+ typeExp.exp ? typeExp.exp->Position : CodePosition(),
+ name, CodePosition());
}
-
// Statements
// Emit a statement as a `{}`-enclosed block statement, but avoid adding redundant
@@ -1974,8 +1964,8 @@ static void EmitDeclRef(EmitContext* context, DeclRef<Decl> declRef)
Substitutions* subst = declRef.substitutions.Ptr();
Emit(context, "<");
- int argCount = subst->args.Count();
- for (int aa = 0; aa < argCount; ++aa)
+ UInt argCount = subst->args.Count();
+ for (UInt aa = 0; aa < argCount; ++aa)
{
if (aa != 0) Emit(context, ",");
EmitVal(context, subst->args[aa]);
@@ -2064,7 +2054,7 @@ static void EmitModifiers(EmitContext* context, RefPtr<Decl> decl)
if (argCount != 0)
{
Emit(context, "(");
- for (int aa = 0; aa < argCount; ++aa)
+ for (UInt aa = 0; aa < argCount; ++aa)
{
if (aa != 0) Emit(context, ", ");
EmitExpr(context, args[aa]);
@@ -3025,9 +3015,9 @@ String emitEntryPoint(
// where there were global-scope uniforms.
auto globalScopeLayout = programLayout->globalScopeLayout;
StructTypeLayout* globalStructLayout = nullptr;
- if( auto globalStructLayout = globalScopeLayout.As<StructTypeLayout>() )
+ if( auto gs = globalScopeLayout.As<StructTypeLayout>() )
{
- globalStructLayout = globalStructLayout.Ptr();
+ globalStructLayout = gs.Ptr();
}
else if(auto globalConstantBufferLayout = globalScopeLayout.As<ParameterBlockTypeLayout>())
{
diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp
index 674614cd3..f9bf97107 100644
--- a/source/slang/lower.cpp
+++ b/source/slang/lower.cpp
@@ -60,6 +60,7 @@ struct StructuralTransformVisitorBase
RefPtr<ScopeDecl> transformSyntaxField(ScopeDecl* decl)
{
+ if(!decl) return nullptr;
return visitor->transformSyntaxField(decl).As<ScopeDecl>();
}
@@ -80,7 +81,7 @@ struct StructuralTransformStmtVisitor
: StructuralTransformVisitorBase<V>
, StmtVisitor<StructuralTransformStmtVisitor<V>, RefPtr<StatementSyntaxNode>>
{
- void transformFields(StatementSyntaxNode* result, StatementSyntaxNode* obj)
+ void transformFields(StatementSyntaxNode*, StatementSyntaxNode*)
{
}
@@ -263,6 +264,7 @@ struct LoweringVisitor
RefPtr<ExpressionType> lowerType(
ExpressionType* type)
{
+ if(!type) return nullptr;
return TypeVisitor::dispatch(type);
}
@@ -456,12 +458,11 @@ struct LoweringVisitor
// Statements
//
- StatementSyntaxNode* translateStmtRef(
- StatementSyntaxNode* stmt)
- {
- throw "unimplemented";
- }
-
+ // Lowering one statement to another.
+ // The source statement might desugar into multiple statements,
+ // (or event to none), and in such a case this function wraps
+ // the result up as a `SeqStmt` or `EmptyStmt` as appropriate.
+ //
RefPtr<StatementSyntaxNode> lowerStmt(
StatementSyntaxNode* stmt)
{
@@ -483,6 +484,37 @@ struct LoweringVisitor
}
}
+
+ // Structure to track "outer" statements during lowering
+ struct StmtLoweringState
+ {
+ // The next "outer" statement entry
+ StmtLoweringState* parent = nullptr;
+
+ // The outer statement (both lowered and original)
+ StatementSyntaxNode* loweredStmt = nullptr;
+ StatementSyntaxNode* originalStmt = nullptr;
+ };
+ StmtLoweringState stmtLoweringState;
+
+ // Translate a reference from one statement to an outer statement
+ StatementSyntaxNode* translateStmtRef(
+ StatementSyntaxNode* originalStmt)
+ {
+ if(!originalStmt) return nullptr;
+
+ for( auto state = &stmtLoweringState; state; state = state->parent )
+ {
+ if(state->originalStmt == originalStmt)
+ return state->loweredStmt;
+ }
+
+ assert(!"unexepcted");
+
+ return nullptr;
+ }
+
+ // Expand a statement to be lowered into one or more statements
void lowerStmtImpl(
StatementSyntaxNode* stmt)
{
@@ -498,14 +530,17 @@ struct LoweringVisitor
LoweringVisitor pushScope(
RefPtr<ScopeStmt> loweredStmt,
- RefPtr<ScopeStmt> stmt)
+ RefPtr<ScopeStmt> originalStmt)
{
- loweredStmt->scopeDecl = translateDeclRef(stmt->scopeDecl).As<ScopeDecl>();
+ loweredStmt->scopeDecl = translateDeclRef(originalStmt->scopeDecl).As<ScopeDecl>();
LoweringVisitor subVisitor = *this;
subVisitor.isBuildingStmt = true;
subVisitor.stmtBeingBuilt = nullptr;
subVisitor.parentDecl = loweredStmt->scopeDecl;
+ subVisitor.stmtLoweringState.parent = &stmtLoweringState;
+ subVisitor.stmtLoweringState.originalStmt = originalStmt;
+ subVisitor.stmtLoweringState.loweredStmt = loweredStmt;
return subVisitor;
}
@@ -562,11 +597,11 @@ struct LoweringVisitor
void visit(BlockStmt* stmt)
{
RefPtr<BlockStmt> loweredStmt = new BlockStmt();
+ lowerScopeStmtFields(loweredStmt, stmt);
LoweringVisitor subVisitor = pushScope(loweredStmt, stmt);
- subVisitor.stmtBeingBuilt = loweredStmt;
- subVisitor.lowerStmtImpl(stmt->body);
+ loweredStmt->body = subVisitor.lowerStmt(stmt->body);
addStmt(loweredStmt);
}
@@ -589,10 +624,152 @@ struct LoweringVisitor
DeclVisitor::dispatch(stmt->decl);
}
- // catch-all
- void visit(StatementSyntaxNode* stmt)
+ void lowerStmtFields(
+ StatementSyntaxNode* loweredStmt,
+ StatementSyntaxNode* originalStmt)
+ {
+ loweredStmt->Position = originalStmt->Position;
+ loweredStmt->modifiers = originalStmt->modifiers;
+ }
+
+ void lowerScopeStmtFields(
+ ScopeStmt* loweredStmt,
+ ScopeStmt* originalStmt)
+ {
+ lowerStmtFields(loweredStmt, originalStmt);
+ loweredStmt->scopeDecl = translateDeclRef(originalStmt->scopeDecl).As<ScopeDecl>();
+ }
+
+ // Child statements reference their parent statement,
+ // so we need to translate that cross-reference
+ void lowerChildStmtFields(
+ ChildStmt* loweredStmt,
+ ChildStmt* originalStmt)
+ {
+ lowerStmtFields(loweredStmt, originalStmt);
+
+ loweredStmt->parentStmt = translateStmtRef(originalStmt->parentStmt);
+ }
+
+ void visit(ContinueStatementSyntaxNode* stmt)
+ {
+ RefPtr<ContinueStatementSyntaxNode> loweredStmt = new ContinueStatementSyntaxNode();
+ lowerChildStmtFields(loweredStmt, stmt);
+ addStmt(loweredStmt);
+ }
+
+ void visit(BreakStatementSyntaxNode* stmt)
+ {
+ RefPtr<BreakStatementSyntaxNode> loweredStmt = new BreakStatementSyntaxNode();
+ lowerChildStmtFields(loweredStmt, stmt);
+ addStmt(loweredStmt);
+ }
+
+ void visit(DefaultStmt* stmt)
+ {
+ RefPtr<DefaultStmt> loweredStmt = new DefaultStmt();
+ lowerChildStmtFields(loweredStmt, stmt);
+ addStmt(loweredStmt);
+ }
+
+ void visit(DiscardStatementSyntaxNode* stmt)
+ {
+ RefPtr<DiscardStatementSyntaxNode> loweredStmt = new DiscardStatementSyntaxNode();
+ lowerStmtFields(loweredStmt, stmt);
+ addStmt(loweredStmt);
+ }
+
+ void visit(EmptyStatementSyntaxNode* stmt)
+ {
+ RefPtr<EmptyStatementSyntaxNode> loweredStmt = new EmptyStatementSyntaxNode();
+ lowerStmtFields(loweredStmt, stmt);
+ addStmt(loweredStmt);
+ }
+
+ void visit(UnparsedStmt* stmt)
+ {
+ RefPtr<UnparsedStmt> loweredStmt = new UnparsedStmt();
+ lowerStmtFields(loweredStmt, stmt);
+
+ loweredStmt->tokens = stmt->tokens;
+
+ addStmt(loweredStmt);
+ }
+
+ void visit(CaseStmt* stmt)
+ {
+ RefPtr<CaseStmt> loweredStmt = new CaseStmt();
+ lowerChildStmtFields(loweredStmt, stmt);
+
+ loweredStmt->expr = lowerExpr(stmt->expr);
+
+ addStmt(loweredStmt);
+ }
+
+ void visit(IfStatementSyntaxNode* stmt)
+ {
+ RefPtr<IfStatementSyntaxNode> loweredStmt = new IfStatementSyntaxNode();
+ lowerStmtFields(loweredStmt, stmt);
+
+ loweredStmt->Predicate = lowerExpr(stmt->Predicate);
+ loweredStmt->PositiveStatement = lowerStmt(stmt->PositiveStatement);
+ loweredStmt->NegativeStatement = lowerStmt(stmt->NegativeStatement);
+
+ addStmt(loweredStmt);
+ }
+
+ void visit(SwitchStmt* stmt)
+ {
+ RefPtr<SwitchStmt> loweredStmt = new SwitchStmt();
+ lowerScopeStmtFields(loweredStmt, stmt);
+
+ LoweringVisitor subVisitor = pushScope(loweredStmt, stmt);
+
+ loweredStmt->condition = subVisitor.lowerExpr(stmt->condition);
+ loweredStmt->body = subVisitor.lowerStmt(stmt->body);
+
+ addStmt(loweredStmt);
+ }
+
+
+ void visit(ForStatementSyntaxNode* stmt)
{
- auto loweredStmt = structuralTransform(stmt, this);
+ RefPtr<ForStatementSyntaxNode> loweredStmt = new ForStatementSyntaxNode();
+ lowerScopeStmtFields(loweredStmt, stmt);
+
+ LoweringVisitor subVisitor = pushScope(loweredStmt, stmt);
+
+ loweredStmt->InitialStatement = subVisitor.lowerStmt(stmt->InitialStatement);
+ loweredStmt->SideEffectExpression = subVisitor.lowerExpr(stmt->SideEffectExpression);
+ loweredStmt->PredicateExpression = subVisitor.lowerExpr(stmt->PredicateExpression);
+ loweredStmt->Statement = subVisitor.lowerStmt(stmt->Statement);
+
+ addStmt(loweredStmt);
+ }
+
+ void visit(WhileStatementSyntaxNode* stmt)
+ {
+ RefPtr<WhileStatementSyntaxNode> loweredStmt = new WhileStatementSyntaxNode();
+ lowerScopeStmtFields(loweredStmt, stmt);
+
+ LoweringVisitor subVisitor = pushScope(loweredStmt, stmt);
+
+ loweredStmt->Predicate = subVisitor.lowerExpr(stmt->Predicate);
+ loweredStmt->Statement = subVisitor.lowerStmt(stmt->Statement);
+
+ addStmt(loweredStmt);
+ }
+
+ void visit(DoWhileStatementSyntaxNode* stmt)
+ {
+ RefPtr<DoWhileStatementSyntaxNode> loweredStmt = new DoWhileStatementSyntaxNode();
+ lowerScopeStmtFields(loweredStmt, stmt);
+
+ LoweringVisitor subVisitor = pushScope(loweredStmt, stmt);
+
+ loweredStmt->Statement = subVisitor.lowerStmt(stmt->Statement);
+ loweredStmt->Predicate = subVisitor.lowerExpr(stmt->Predicate);
+
addStmt(loweredStmt);
}
@@ -666,13 +843,13 @@ struct LoweringVisitor
}
RefPtr<Substitutions> translateSubstitutions(
- Substitutions* substitutions)
+ Substitutions* inSubstitutions)
{
- if (!substitutions) return nullptr;
+ if (!inSubstitutions) return nullptr;
RefPtr<Substitutions> result = new Substitutions();
- result->genericDecl = translateDeclRef(substitutions->genericDecl).As<GenericDecl>();
- for (auto arg : substitutions->args)
+ result->genericDecl = translateDeclRef(inSubstitutions->genericDecl).As<GenericDecl>();
+ for (auto arg : inSubstitutions->args)
{
result->args.Add(translateVal(arg));
}
@@ -740,9 +917,8 @@ struct LoweringVisitor
}
else
{
- DeclVisitor::dispatch(declBase);
+ return DeclVisitor::dispatch(declBase);
}
-
}
RefPtr<Decl> lowerDecl(
@@ -827,11 +1003,68 @@ struct LoweringVisitor
}
// Catch-all
- RefPtr<Decl> visit(
- Decl* decl)
+
+ RefPtr<Decl> visit(ModifierDecl*)
{
- assert(!"unimplemented");
- return decl;
+ // should not occur in user code
+ SLANG_UNEXPECTED("modifiers shouldn't occur in user code");
+ }
+
+ RefPtr<Decl> visit(GenericValueParamDecl*)
+ {
+ SLANG_UNEXPECTED("generics should be lowered to specialized decls");
+ }
+
+ RefPtr<Decl> visit(GenericTypeParamDecl*)
+ {
+ SLANG_UNEXPECTED("generics should be lowered to specialized decls");
+ }
+
+ RefPtr<Decl> visit(GenericTypeConstraintDecl*)
+ {
+ SLANG_UNEXPECTED("generics should be lowered to specialized decls");
+ }
+
+ RefPtr<Decl> visit(GenericDecl*)
+ {
+ SLANG_UNEXPECTED("generics should be lowered to specialized decls");
+ }
+
+ RefPtr<Decl> visit(ProgramSyntaxNode*)
+ {
+ SLANG_UNEXPECTED("module decls should be lowered explicitly");
+ }
+
+ RefPtr<Decl> visit(SubscriptDecl*)
+ {
+ // We don't expect to find direct references to a subscript
+ // declaration, but rather to the underlying accessors
+ return nullptr;
+ }
+
+ RefPtr<Decl> visit(InheritanceDecl*)
+ {
+ // We should deal with these explicitly, as part of lowering
+ // the type that contains them.
+ return nullptr;
+ }
+
+ RefPtr<Decl> visit(ExtensionDecl*)
+ {
+ // Extensions won't exist in the lowered code: their members
+ // will turn into ordinary functions that get called explicitly
+ return nullptr;
+ }
+
+ RefPtr<Decl> visit(TypeDefDecl* decl)
+ {
+ RefPtr<TypeDefDecl> loweredDecl = new TypeDefDecl();
+ lowerDeclCommon(loweredDecl, decl);
+
+ loweredDecl->Type = lowerType(decl->Type);
+
+ addMember(shared->loweredProgram, loweredDecl);
+ return loweredDecl;
}
RefPtr<ImportDecl> visit(ImportDecl* decl)
@@ -922,8 +1155,8 @@ struct LoweringVisitor
//
// If this is a global variable (program scope), then add it
// to the global scope.
- RefPtr<ContainerDecl> parentDecl = decl->ParentDecl;
- if (auto parentModuleDecl = parentDecl.As<ProgramSyntaxNode>())
+ RefPtr<ContainerDecl> pp = decl->ParentDecl;
+ if (auto parentModuleDecl = pp.As<ProgramSyntaxNode>())
{
addMember(
translateDeclRef(parentModuleDecl),
@@ -1138,10 +1371,6 @@ struct LoweringVisitor
subscriptExpr->Position = varExpr->Position;
subscriptExpr->BaseExpression = varExpr;
- // TODO: we need to construct syntax for a loop to initialize
- // the array here...
- throw "unimplemented";
-
// Note that we use the original `varLayout` that was passed in,
// since that is the layout that will ultimately need to be
// used on the array elements.
@@ -1154,6 +1383,9 @@ struct LoweringVisitor
varLayout,
subscriptExpr);
+ // TODO: we need to construct syntax for a loop to initialize
+ // the array here...
+ throw "unimplemented";
}
else if (auto declRefType = varType->As<DeclRefType>())
{
diff --git a/source/slang/options.cpp b/source/slang/options.cpp
index cced0f0ff..db949e78d 100644
--- a/source/slang/options.cpp
+++ b/source/slang/options.cpp
@@ -80,7 +80,7 @@ struct OptionsParser
{
auto translationUnitIndex = spAddTranslationUnit(compileRequest, language, nullptr);
- assert(translationUnitIndex == rawTranslationUnits.Count());
+ assert(UInt(translationUnitIndex) == rawTranslationUnits.Count());
RawTranslationUnit rawTranslationUnit;
rawTranslationUnit.sourceLanguage = language;
diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp
index 8d008618f..5811fd9fa 100644
--- a/source/slang/parameter-binding.cpp
+++ b/source/slang/parameter-binding.cpp
@@ -14,8 +14,8 @@ namespace Slang {
// Information on ranges of registers already claimed/used
struct UsedRange
{
- int begin;
- int end;
+ UInt begin;
+ UInt end;
};
bool operator<(UsedRange left, UsedRange right)
{
@@ -51,7 +51,7 @@ struct UsedRanges
ranges.Sort();
}
- void Add(int begin, int end)
+ void Add(UInt begin, UInt end)
{
UsedRange range;
range.begin = begin;
@@ -61,16 +61,16 @@ struct UsedRanges
// Try to find space for `count` entries
- int Allocate(int count)
+ UInt Allocate(UInt count)
{
- int begin = 0;
+ UInt begin = 0;
- int rangeCount = ranges.Count();
- for (int rr = 0; rr < rangeCount; ++rr)
+ UInt rangeCount = ranges.Count();
+ for (UInt rr = 0; rr < rangeCount; ++rr)
{
// try to fit in before this range...
- int end = ranges[rr].begin;
+ UInt end = ranges[rr].begin;
// If there is enough space...
if (end >= begin + count)
@@ -165,8 +165,8 @@ struct ParameterBindingContext
struct LayoutSemanticInfo
{
LayoutResourceKind kind; // the register kind
- int space;
- int index;
+ UInt space;
+ UInt index;
// TODO: need to deal with component-granularity binding...
};
@@ -229,15 +229,15 @@ LayoutSemanticInfo ExtractLayoutSemanticInfo(
// TODO: handle component mask part of things...
info.kind = kind;
- info.index = index;
+ info.index = (int) index;
info.space = space;
return info;
}
static bool doesParameterMatch(
- ParameterBindingContext* context,
- RefPtr<VarLayout> varLayout,
- ParameterInfo* parameterInfo)
+ ParameterBindingContext*,
+ RefPtr<VarLayout>,
+ ParameterInfo*)
{
// TODO: need to implement this eventually
return true;
@@ -250,20 +250,23 @@ static bool doesParameterMatch(
template<typename T>
static bool findLayoutArg(
RefPtr<ModifiableSyntaxNode> syntax,
- int* outVal)
+ UInt* outVal)
{
for( auto modifier : syntax->GetModifiersOfType<T>() )
{
- *outVal = (int) strtol(modifier->valToken.Content.Buffer(), nullptr, 10);
- return true;
+ if( modifier )
+ {
+ *outVal = (UInt) strtoull(modifier->valToken.Content.Buffer(), nullptr, 10);
+ return true;
+ }
}
return false;
}
template<typename T>
static bool findLayoutArg(
- DeclRef<Decl> declRef,
- int* outVal)
+ DeclRef<Decl> declRef,
+ UInt* outVal)
{
return findLayoutArg<T>(declRef.getDecl(), outVal);
}
@@ -395,7 +398,6 @@ getTypeLayoutForGlobalShaderParameter(
ParameterBindingContext* context,
VarDeclBase* varDecl)
{
- auto rules = context->layoutRules;
switch( context->shared->sourceLanguage )
{
case SourceLanguage::Slang:
@@ -478,7 +480,7 @@ static void addExplicitParameterBinding(
ParameterBindingContext* context,
RefPtr<ParameterInfo> parameterInfo,
LayoutSemanticInfo const& semanticInfo,
- int count)
+ UInt count)
{
auto kind = semanticInfo.kind;
@@ -575,7 +577,7 @@ static void addExplicitParameterBindings_GLSL(
LayoutSemanticInfo semanticInfo;
semanticInfo.index = 0;
semanticInfo.space = 0;
- if( (resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::DescriptorTableSlot)) )
+ if( (resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::DescriptorTableSlot)) != nullptr )
{
// Try to find `binding` and `set`
if(!findLayoutArg<GLSLBindingLayoutModifier>(varDecl, &semanticInfo.index))
@@ -583,19 +585,19 @@ static void addExplicitParameterBindings_GLSL(
findLayoutArg<GLSLSetLayoutModifier>(varDecl, &semanticInfo.space);
}
- else if( (resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::VertexInput)) )
+ else if( (resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::VertexInput)) != nullptr )
{
// Try to find `location` binding
if(!findLayoutArg<GLSLLocationLayoutModifier>(varDecl, &semanticInfo.index))
return;
}
- else if( (resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::FragmentOutput)) )
+ else if( (resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::FragmentOutput)) != nullptr )
{
// Try to find `location` binding
if(!findLayoutArg<GLSLLocationLayoutModifier>(varDecl, &semanticInfo.index))
return;
}
- else if( (resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::SpecializationConstant)) )
+ else if( (resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::SpecializationConstant)) != nullptr )
{
// Try to find `constant_id` binding
if(!findLayoutArg<GLSLConstantIDLayoutModifier>(varDecl, &semanticInfo.index))
@@ -733,8 +735,8 @@ SimpleSemanticInfo decomposeSimpleSemantic(
// look for a trailing sequence of decimal digits
// at the end of the composed name
- int length = composedName.Length();
- int indexLoc = length;
+ UInt length = composedName.Length();
+ UInt indexLoc = length;
while( indexLoc > 0 )
{
auto c = composedName[indexLoc-1];
@@ -888,29 +890,29 @@ static RefPtr<TypeLayout> processEntryPointParameter(
{
return processSimpleEntryPointParameter(context, basicType, state);
}
- else if(auto basicType = type->As<VectorExpressionType>())
+ else if(auto vectorType = type->As<VectorExpressionType>())
{
- return processSimpleEntryPointParameter(context, basicType, state);
+ return processSimpleEntryPointParameter(context, vectorType, state);
}
// A matrix is processed as if it was an array of rows
else if( auto matrixType = type->As<MatrixExpressionType>() )
{
auto rowCount = GetIntVal(matrixType->getRowCount());
- return processSimpleEntryPointParameter(context, basicType, state, (int) rowCount);
+ return processSimpleEntryPointParameter(context, matrixType, state, (int) rowCount);
}
else if( auto arrayType = type->As<ArrayExpressionType>() )
{
// Note: Bad Things will happen if we have an array input
// without a semantic already being enforced.
- auto elementCount = GetIntVal(arrayType->ArrayLength);
+ auto elementCount = (UInt) GetIntVal(arrayType->ArrayLength);
// We use the first element to derive the layout for the element type
auto elementTypeLayout = processEntryPointParameter(context, arrayType->BaseType, state);
// We still walk over subsequent elements to make sure they consume resources
// as needed
- for( int ii = 1; ii < elementCount; ++ii )
+ for( UInt ii = 1; ii < elementCount; ++ii )
{
processEntryPointParameter(context, arrayType->BaseType, state);
}
diff --git a/source/slang/preprocessor.cpp b/source/slang/preprocessor.cpp
index f84355018..a186ce201 100644
--- a/source/slang/preprocessor.cpp
+++ b/source/slang/preprocessor.cpp
@@ -600,8 +600,8 @@ static void MaybeBeginMacroExpansion(
expansion->environment = &expansion->argumentEnvironment;
// Try to read any arguments present.
- int paramCount = macro->params.Count();
- int argIndex = 0;
+ UInt paramCount = macro->params.Count();
+ UInt argIndex = 0;
switch (PeekRawTokenType(preprocessor))
{
@@ -702,7 +702,7 @@ static void MaybeBeginMacroExpansion(
GetSink(preprocessor)->diagnose(PeekLoc(preprocessor), Diagnostics::expectedTokenInMacroArguments, TokenType::RParent, PeekRawTokenType(preprocessor));
}
- int argCount = argIndex;
+ UInt argCount = argIndex;
if (argCount != paramCount)
{
// TODO: diagnose
diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp
index 40cd7061b..f71435c6f 100644
--- a/source/slang/reflection.cpp
+++ b/source/slang/reflection.cpp
@@ -191,11 +191,11 @@ SLANG_API size_t spReflectionType_GetElementCount(SlangReflectionType* inType)
if(auto arrayType = dynamic_cast<ArrayExpressionType*>(type))
{
- return GetIntVal(arrayType->ArrayLength);
+ return (size_t) GetIntVal(arrayType->ArrayLength);
}
else if( auto vectorType = dynamic_cast<VectorExpressionType*>(type))
{
- return GetIntVal(vectorType->elementCount);
+ return (size_t) GetIntVal(vectorType->elementCount);
}
return 0;
@@ -688,7 +688,7 @@ SLANG_API unsigned spReflection_GetParameterCount(SlangReflection* inProgram)
if(auto globalStructLayout = globalLayout.As<StructTypeLayout>())
{
- return globalStructLayout->fields.Count();
+ return (unsigned) globalStructLayout->fields.Count();
}
return 0;
diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp
index 513fa3b96..ff727cbb6 100644
--- a/source/slang/slang-stdlib.cpp
+++ b/source/slang/slang-stdlib.cpp
@@ -1598,10 +1598,9 @@ namespace Slang
{ 3, "Alpha" },
};
- for(auto cc : kGatherComponets)
+ for(auto kk : kGatherComponets)
{
- auto componentIndex = cc.componentIndex;
- auto componentName = cc.componentName;
+ auto componentName = kk.componentName;
EMIT_LINE_DIRECTIVE();
sb << "vector<T, 4> Gather" << componentName << "(SamplerState s, ";
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 182a5818d..c4944c5a4 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -19,17 +19,6 @@
namespace Slang {
-static void stdlibDiagnosticCallback(
- char const* message,
- void* userData)
-{
- fputs(message, stderr);
- fflush(stderr);
-#ifdef WIN32
- OutputDebugStringA(message);
-#endif
-}
-
class Session
{
public:
@@ -281,9 +270,9 @@ int CompileRequest::executeActions()
return err;
}
-int CompileRequest::addTranslationUnit(SourceLanguage language, String const& name)
+int CompileRequest::addTranslationUnit(SourceLanguage language, String const&)
{
- int result = translationUnits.Count();
+ UInt result = translationUnits.Count();
RefPtr<TranslationUnitRequest> translationUnit = new TranslationUnitRequest();
translationUnit->compileRequest = this;
@@ -291,7 +280,7 @@ int CompileRequest::addTranslationUnit(SourceLanguage language, String const& na
translationUnits.Add(translationUnit);
- return result;
+ return (int) result;
}
void CompileRequest::addTranslationUnitSourceString(
@@ -336,27 +325,27 @@ void CompileRequest::addTranslationUnitSourceFile(
int CompileRequest::addEntryPoint(
int translationUnitIndex,
String const& name,
- Profile profile)
+ Profile entryPointProfile)
{
RefPtr<EntryPointRequest> entryPoint = new EntryPointRequest();
entryPoint->compileRequest = this;
entryPoint->name = name;
- entryPoint->profile = profile;
+ entryPoint->profile = entryPointProfile;
entryPoint->translationUnitIndex = translationUnitIndex;
auto translationUnit = translationUnits[translationUnitIndex].Ptr();
translationUnit->entryPoints.Add(entryPoint);
- int result = entryPoints.Count();
+ UInt result = entryPoints.Count();
entryPoints.Add(entryPoint);
- return result;
+ return (int) result;
}
RefPtr<ProgramSyntaxNode> CompileRequest::loadModule(
String const& name,
String const& path,
String const& source,
- CodePosition const& loc)
+ CodePosition const&)
{
RefPtr<TranslationUnitRequest> translationUnit = new TranslationUnitRequest();
translationUnit->compileRequest = this;
@@ -714,7 +703,7 @@ SLANG_API void spAddTranslationUnitSourceFile(
auto req = REQ(request);
if(!path) return;
if(translationUnitIndex < 0) return;
- if(translationUnitIndex >= req->translationUnits.Count()) return;
+ if(Slang::UInt(translationUnitIndex) >= req->translationUnits.Count()) return;
req->addTranslationUnitSourceFile(
translationUnitIndex,
@@ -732,7 +721,7 @@ SLANG_API void spAddTranslationUnitSourceString(
auto req = REQ(request);
if(!source) return;
if(translationUnitIndex < 0) return;
- if(translationUnitIndex >= req->translationUnits.Count()) return;
+ if(Slang::UInt(translationUnitIndex) >= req->translationUnits.Count()) return;
if(!path) path = "";
@@ -744,7 +733,7 @@ SLANG_API void spAddTranslationUnitSourceString(
}
SLANG_API SlangProfileID spFindProfile(
- SlangSession* session,
+ SlangSession*,
char const* name)
{
return Slang::Profile::LookUp(name).raw;
@@ -760,7 +749,7 @@ SLANG_API int spAddEntryPoint(
auto req = REQ(request);
if(!name) return -1;
if(translationUnitIndex < 0) return -1;
- if(translationUnitIndex >= req->translationUnits.Count()) return -1;
+ if(Slang::UInt(translationUnitIndex) >= req->translationUnits.Count()) return -1;
return req->addEntryPoint(
translationUnitIndex,
@@ -785,7 +774,7 @@ spGetDependencyFileCount(
{
if(!request) return 0;
auto req = REQ(request);
- return req->mDependencyFilePaths.Count();
+ return (int) req->mDependencyFilePaths.Count();
}
/** Get the path to a file this compilation dependend on.
@@ -805,7 +794,7 @@ spGetTranslationUnitCount(
SlangCompileRequest* request)
{
auto req = REQ(request);
- return req->translationUnits.Count();
+ return (int) req->translationUnits.Count();
}
// Get the output code associated with a specific translation unit
diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp
index 12d8c90bb..94e0d5914 100644
--- a/source/slang/syntax.cpp
+++ b/source/slang/syntax.cpp
@@ -782,9 +782,9 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra)
if (genericDecl != subst->genericDecl)
return false;
- int argCount = args.Count();
+ UInt argCount = args.Count();
assert(args.Count() == subst->args.Count());
- for (int aa = 0; aa < argCount; ++aa)
+ for (UInt aa = 0; aa < argCount; ++aa)
{
if (!args[aa]->EqualsVal(subst->args[aa].Ptr()))
return false;
diff --git a/source/slang/syntax.h b/source/slang/syntax.h
index 6587e18c3..4329f6cbd 100644
--- a/source/slang/syntax.h
+++ b/source/slang/syntax.h
@@ -420,9 +420,9 @@ namespace Slang
// TODO(tfoley): It is ugly to have these.
// We should probably fix the call sites instead.
RefPtr<T>& First() { return *begin(); }
- int Count()
+ UInt Count()
{
- int count = 0;
+ UInt count = 0;
for (auto iter : (*this))
{
(void)iter;
diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp
index bef777ce5..2fcf64226 100644
--- a/source/slang/type-layout.cpp
+++ b/source/slang/type-layout.cpp
@@ -225,7 +225,7 @@ struct DefaultVaryingLayoutRulesImpl : DefaultLayoutRulesImpl
return kind;
}
- SimpleLayoutInfo GetScalarLayout(BaseType baseType) override
+ SimpleLayoutInfo GetScalarLayout(BaseType) override
{
// Assume that all scalars take up one "slot"
return SimpleLayoutInfo(
@@ -233,7 +233,7 @@ struct DefaultVaryingLayoutRulesImpl : DefaultLayoutRulesImpl
1);
}
- virtual SimpleLayoutInfo GetScalarLayout(slang::TypeReflection::ScalarType scalarType)
+ virtual SimpleLayoutInfo GetScalarLayout(slang::TypeReflection::ScalarType)
{
// Assume that all scalars take up one "slot"
return SimpleLayoutInfo(
@@ -241,7 +241,7 @@ struct DefaultVaryingLayoutRulesImpl : DefaultLayoutRulesImpl
1);
}
- SimpleLayoutInfo GetVectorLayout(SimpleLayoutInfo elementInfo, size_t elementCount) override
+ SimpleLayoutInfo GetVectorLayout(SimpleLayoutInfo, size_t) override
{
// Vectors take up one slot by default
//
@@ -276,7 +276,7 @@ struct GLSLSpecializationConstantLayoutRulesImpl : DefaultLayoutRulesImpl
return LayoutResourceKind::SpecializationConstant;
}
- SimpleLayoutInfo GetScalarLayout(BaseType baseType) override
+ SimpleLayoutInfo GetScalarLayout(BaseType) override
{
// Assume that all scalars take up one "slot"
return SimpleLayoutInfo(
@@ -284,7 +284,7 @@ struct GLSLSpecializationConstantLayoutRulesImpl : DefaultLayoutRulesImpl
1);
}
- virtual SimpleLayoutInfo GetScalarLayout(slang::TypeReflection::ScalarType scalarType)
+ virtual SimpleLayoutInfo GetScalarLayout(slang::TypeReflection::ScalarType)
{
// Assume that all scalars take up one "slot"
return SimpleLayoutInfo(
@@ -292,7 +292,7 @@ struct GLSLSpecializationConstantLayoutRulesImpl : DefaultLayoutRulesImpl
1);
}
- SimpleLayoutInfo GetVectorLayout(SimpleLayoutInfo elementInfo, size_t elementCount) override
+ SimpleLayoutInfo GetVectorLayout(SimpleLayoutInfo, size_t elementCount) override
{
// GLSL doesn't support vectors of specialization constants,
// but we will assume that, if supported, they would use one slot per element.
@@ -308,7 +308,7 @@ GLSLSpecializationConstantLayoutRulesImpl kGLSLSpecializationConstantLayoutRules
struct GLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl
{
- virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind kind) override
+ virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind) override
{
// In Vulkan GLSL, pretty much every object is just a descriptor-table slot.
// We can refine this method once we support a case where this isn't true.
@@ -954,7 +954,7 @@ SimpleLayoutInfo GetLayoutImpl(
return GetSimpleLayoutImpl(
rules->GetVectorLayout(
GetLayout(vecType->elementType.Ptr(), rules),
- GetIntVal(vecType->elementCount)),
+ (size_t) GetIntVal(vecType->elementCount)),
type,
rules,
outTypeLayout);
@@ -964,8 +964,8 @@ SimpleLayoutInfo GetLayoutImpl(
return GetSimpleLayoutImpl(
rules->GetMatrixLayout(
GetLayout(matType->getElementType(), rules),
- GetIntVal(matType->getRowCount()),
- GetIntVal(matType->getColumnCount())),
+ (size_t) GetIntVal(matType->getRowCount()),
+ (size_t) GetIntVal(matType->getColumnCount())),
type,
rules,
outTypeLayout);