summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-syntax.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-11-16 12:17:49 -0800
committerGitHub <noreply@github.com>2022-11-16 12:17:49 -0800
commit801aa3b44254341018a1acbe754f2ce3b0900e2a (patch)
treeb3066778522edb99bf64c0ac80c91b0b4cb788f8 /source/slang/slang-syntax.cpp
parent09d8e048d2264d89886cda8e87e8a452d4f913c1 (diff)
Clean up type checking of higher order expressions. (#2519)
* Clean up type checking of higher order expressions. * Replace `goto` with `break` to pacify clang. * Fix. * Fixes. * Fix more tests. * Fix lowerWitnessTable parameter error. * Exclude attributes from ast printing. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-syntax.cpp')
-rw-r--r--source/slang/slang-syntax.cpp52
1 files changed, 40 insertions, 12 deletions
diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp
index 80f57905f..4f05bc936 100644
--- a/source/slang/slang-syntax.cpp
+++ b/source/slang/slang-syntax.cpp
@@ -15,16 +15,22 @@ namespace Slang
void printDiagnosticArg(StringBuilder& sb, Decl* decl)
{
+ if (!decl)
+ return;
sb << getText(decl->getName());
}
void printDiagnosticArg(StringBuilder& sb, Type* type)
{
+ if (!type)
+ return;
type->toText(sb);
}
void printDiagnosticArg(StringBuilder& sb, Val* val)
{
+ if (!val)
+ return;
val->toText(sb);
}
@@ -44,13 +50,17 @@ void printDiagnosticArg(StringBuilder& sb, QualType const& type)
sb << "<null>";
}
-SourceLoc const& getDiagnosticPos(SyntaxNode const* syntax)
+SourceLoc getDiagnosticPos(SyntaxNode const* syntax)
{
+ if (!syntax)
+ return SourceLoc();
return syntax->loc;
}
-SourceLoc const& getDiagnosticPos(TypeExp const& typeExp)
+SourceLoc getDiagnosticPos(TypeExp const& typeExp)
{
+ if (!typeExp.exp)
+ return SourceLoc();
return typeExp.exp->loc;
}
@@ -365,7 +375,6 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt
SLANG_ASSERT(!requirementDictionary.ContainsKey(decl));
requirementDictionary.Add(decl, witness);
- requirementList.add(KeyValuePair<Decl*, RequirementWitness>(decl, witness));
}
//
@@ -1169,10 +1178,10 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt
}
ThisTypeSubstitution* findThisTypeSubstitution(
- Substitutions* substs,
+ const Substitutions* substs,
InterfaceDecl* interfaceDecl)
{
- for(Substitutions* s = substs; s; s = s->outer)
+ for(const Substitutions* s = substs; s; s = s->outer)
{
auto thisTypeSubst = as<ThisTypeSubstitution>(s);
if(!thisTypeSubst)
@@ -1181,7 +1190,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt
if(thisTypeSubst->interfaceDecl != interfaceDecl)
continue;
- return thisTypeSubst;
+ return const_cast<ThisTypeSubstitution*>(thisTypeSubst);
}
return nullptr;
@@ -1236,7 +1245,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt
}
// Prints a partially qualified type name with generic substitutions.
- static void _printNestedDecl(const Substitutions* substitutions, Decl* decl, StringBuilder& out)
+ void _printNestedDecl(const Substitutions* substitutions, Decl* decl, StringBuilder& out)
{
// If there is a parent scope for the declaration, print it first.
// Exclude top-level namespaces like `tu0` or `core`.
@@ -1258,12 +1267,28 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt
out << ".";
}
}
-
- // Print this type's name.
- auto name = decl->getName();
- if (name)
+ // If we have a ThisTypeSubstitution to an interface decl, print the substituted sub
+ // type instead.
+ for (;;)
{
- out << name->text;
+ if (auto interfaceDecl = as<InterfaceDecl>(decl))
+ {
+ if (auto thisSubst = findThisTypeSubstitution(substitutions, interfaceDecl))
+ {
+ if (auto subTypeWitness = as<SubtypeWitness>(thisSubst->witness))
+ {
+ out << subTypeWitness->sub;
+ break;
+ }
+ }
+ }
+ // Otherwise, just print this type's name.
+ auto name = decl->getName();
+ if (name)
+ {
+ out << name->text;
+ }
+ break;
}
// Look for generic substitutions on this type.
@@ -1280,6 +1305,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt
bool isFirst = true;
for (const auto& it : genericSubstitution->getArgs())
{
+ // Don't print out witnesses.
+ if (as<Witness>(it))
+ continue;
if (!isFirst)
out << ", ";
isFirst = false;