summaryrefslogtreecommitdiff
path: root/source/slang/slang-ast-print.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/slang/slang-ast-print.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/slang/slang-ast-print.cpp')
-rw-r--r--source/slang/slang-ast-print.cpp92
1 files changed, 56 insertions, 36 deletions
diff --git a/source/slang/slang-ast-print.cpp b/source/slang/slang-ast-print.cpp
index f3ed4ee0b..8900706fa 100644
--- a/source/slang/slang-ast-print.cpp
+++ b/source/slang/slang-ast-print.cpp
@@ -2,10 +2,10 @@
#include "slang-ast-print.h"
#include "core/slang-char-util.h"
-
#include "slang-check-impl.h"
-namespace Slang {
+namespace Slang
+{
ASTPrinter::Part::Kind ASTPrinter::Part::getKind(ASTPrinter::Part::Type type)
{
@@ -14,14 +14,14 @@ ASTPrinter::Part::Kind ASTPrinter::Part::getKind(ASTPrinter::Part::Type type)
switch (type)
{
- case Type::ParamType: return Kind::Type;
- case Type::ParamName: return Kind::Name;
- case Type::ReturnType: return Kind::Type;
- case Type::DeclPath: return Kind::Name;
- case Type::GenericParamType: return Kind::Type;
- case Type::GenericParamValue: return Kind::Value;
- case Type::GenericParamValueType: return Kind::Type;
- default: break;
+ case Type::ParamType: return Kind::Type;
+ case Type::ParamName: return Kind::Name;
+ case Type::ReturnType: return Kind::Type;
+ case Type::DeclPath: return Kind::Name;
+ case Type::GenericParamType: return Kind::Type;
+ case Type::GenericParamValue: return Kind::Value;
+ case Type::GenericParamValueType: return Kind::Type;
+ default: break;
}
return Kind::None;
}
@@ -71,7 +71,7 @@ void ASTPrinter::addVal(Val* val)
val->toText(m_builder);
}
-/* static */void ASTPrinter::appendDeclName(Decl* decl, StringBuilder& out)
+/* static */ void ASTPrinter::appendDeclName(Decl* decl, StringBuilder& out)
{
if (as<ConstructorDecl>(decl))
{
@@ -132,14 +132,15 @@ void ASTPrinter::_addDeclPathRec(const DeclRef<Decl>& declRef, Index depth)
else if (auto namespaceDeclRef = parentDeclRef.as<NamespaceDecl>())
{
_addDeclPathRec(namespaceDeclRef, depth + 1);
- // Hmm, it could be argued that we follow the . as seen in AggType as is followed in some other languages
- // like Java.
- // That it is useful to have a distinction between something that is a member/method and something that is
- // in a scope (such as a namespace), and is something that has returned to later languages probably for that
- // reason (Slang accepts . or ::). So for now this is follows the :: convention.
+ // Hmm, it could be argued that we follow the . as seen in AggType as is followed in some
+ // other languages like Java. That it is useful to have a distinction between something that
+ // is a member/method and something that is in a scope (such as a namespace), and is
+ // something that has returned to later languages probably for that reason (Slang accepts .
+ // or ::). So for now this is follows the :: convention.
//
- // It could be argued them that the previous '.' use should vary depending on that distinction.
-
+ // It could be argued them that the previous '.' use should vary depending on that
+ // distinction.
+
sb << toSlice("::");
}
else if (auto extensionDeclRef = parentDeclRef.as<ExtensionDecl>())
@@ -150,7 +151,9 @@ void ASTPrinter::_addDeclPathRec(const DeclRef<Decl>& declRef, Index depth)
{
if (auto unspecializedDeclRef = isDeclRefTypeOf<Decl>(type))
{
- type = DeclRefType::create(m_astBuilder, unspecializedDeclRef.getDecl()->getDefaultDeclRef());
+ type = DeclRefType::create(
+ m_astBuilder,
+ unspecializedDeclRef.getDecl()->getDefaultDeclRef());
}
}
addType(type);
@@ -172,7 +175,7 @@ void ASTPrinter::_addDeclPathRec(const DeclRef<Decl>& declRef, Index depth)
Name* moduleName = moduleDecl->getName();
if ((m_optionFlags & OptionFlag::ModuleName) && moduleName)
{
- sb << moduleName->text;
+ sb << moduleName->text;
}
return;
}
@@ -181,11 +184,11 @@ void ASTPrinter::_addDeclPathRec(const DeclRef<Decl>& declRef, Index depth)
// If the parent declaration is a generic, then we need to print out its
// signature
- if (parentGenericDeclRef &&
- !declRef.as<GenericValueParamDecl>() &&
+ if (parentGenericDeclRef && !declRef.as<GenericValueParamDecl>() &&
!declRef.as<GenericTypeParamDeclBase>())
{
- auto substArgs = tryGetGenericArguments(SubstitutionSet(declRef), parentGenericDeclRef.getDecl());
+ auto substArgs =
+ tryGetGenericArguments(SubstitutionSet(declRef), parentGenericDeclRef.getDecl());
if (substArgs.getCount())
{
// If the name we printed previously was an operator
@@ -214,7 +217,8 @@ void ASTPrinter::_addDeclPathRec(const DeclRef<Decl>& declRef, Index depth)
if (as<Witness>(arg))
continue;
- if (!first) sb << ", ";
+ if (!first)
+ sb << ", ";
addVal(arg);
first = false;
}
@@ -238,7 +242,8 @@ void ASTPrinter::addGenericParams(const DeclRef<GenericDecl>& genericDeclRef)
{
if (auto genericTypeParam = paramDeclRef.as<GenericTypeParamDecl>())
{
- if (!first) sb << ", ";
+ if (!first)
+ sb << ", ";
first = false;
{
@@ -248,7 +253,8 @@ void ASTPrinter::addGenericParams(const DeclRef<GenericDecl>& genericDeclRef)
}
else if (auto genericValParam = paramDeclRef.as<GenericValueParamDecl>())
{
- if (!first) sb << ", ";
+ if (!first)
+ sb << ", ";
first = false;
{
@@ -265,7 +271,8 @@ void ASTPrinter::addGenericParams(const DeclRef<GenericDecl>& genericDeclRef)
}
else if (auto genericTypePackParam = paramDeclRef.as<GenericTypePackParamDecl>())
{
- if (!first) sb << ", ";
+ if (!first)
+ sb << ", ";
first = false;
{
ScopePart scopePart(this, Part::Type::GenericParamType);
@@ -299,7 +306,8 @@ void ASTPrinter::addDeclParams(const DeclRef<Decl>& declRef, List<Range<Index>>*
auto addParamElement = [&](Type* type, Index elementIndex)
{
- if (!first) sb << ", ";
+ if (!first)
+ sb << ", ";
// Type part.
{
@@ -350,7 +358,8 @@ void ASTPrinter::addDeclParams(const DeclRef<Decl>& declRef, List<Range<Index>>*
};
if (auto typePack = as<ConcreteTypePack>(paramType))
{
- for (Index elementIndex = 0; elementIndex < typePack->getTypeCount(); ++elementIndex)
+ for (Index elementIndex = 0; elementIndex < typePack->getTypeCount();
+ ++elementIndex)
{
addParamElement(typePack->getElementType(elementIndex), elementIndex);
}
@@ -367,7 +376,9 @@ void ASTPrinter::addDeclParams(const DeclRef<Decl>& declRef, List<Range<Index>>*
{
addGenericParams(genericDeclRef);
- addDeclParams(m_astBuilder->getMemberDeclRef(genericDeclRef, genericDeclRef.getDecl()->inner), outParamRange);
+ addDeclParams(
+ m_astBuilder->getMemberDeclRef(genericDeclRef, genericDeclRef.getDecl()->inner),
+ outParamRange);
}
else
{
@@ -493,7 +504,8 @@ void ASTPrinter::addDeclResultType(const DeclRef<Decl>& inDeclRef)
DeclRef<Decl> declRef = inDeclRef;
if (auto genericDeclRef = declRef.as<GenericDecl>())
{
- declRef = m_astBuilder->getMemberDeclRef<Decl>(genericDeclRef, genericDeclRef.getDecl()->inner);
+ declRef =
+ m_astBuilder->getMemberDeclRef<Decl>(genericDeclRef, genericDeclRef.getDecl()->inner);
}
if (declRef.as<ConstructorDecl>())
@@ -518,7 +530,7 @@ void ASTPrinter::addDeclResultType(const DeclRef<Decl>& inDeclRef)
}
}
-/* static */void ASTPrinter::addDeclSignature(const DeclRef<Decl>& declRef)
+/* static */ void ASTPrinter::addDeclSignature(const DeclRef<Decl>& declRef)
{
addDeclKindPrefix(declRef.getDecl());
addDeclPath(declRef);
@@ -526,7 +538,9 @@ void ASTPrinter::addDeclResultType(const DeclRef<Decl>& inDeclRef)
addDeclResultType(declRef);
}
-/* static */String ASTPrinter::getDeclSignatureString(DeclRef<Decl> declRef, ASTBuilder* astBuilder)
+/* static */ String ASTPrinter::getDeclSignatureString(
+ DeclRef<Decl> declRef,
+ ASTBuilder* astBuilder)
{
ASTPrinter astPrinter(
astBuilder,
@@ -535,14 +549,20 @@ void ASTPrinter::addDeclResultType(const DeclRef<Decl>& inDeclRef)
return astPrinter.getString();
}
-/* static */String ASTPrinter::getDeclSignatureString(const LookupResultItem& item, ASTBuilder* astBuilder)
+/* static */ String ASTPrinter::getDeclSignatureString(
+ const LookupResultItem& item,
+ ASTBuilder* astBuilder)
{
return getDeclSignatureString(item.declRef, astBuilder);
}
-/* static */UnownedStringSlice ASTPrinter::getPart(Part::Type partType, const UnownedStringSlice& slice, const List<Part>& parts)
+/* static */ UnownedStringSlice ASTPrinter::getPart(
+ Part::Type partType,
+ const UnownedStringSlice& slice,
+ const List<Part>& parts)
{
- const Index index = parts.findFirstIndex([&](const Part& part) -> bool { return part.type == partType; });
+ const Index index =
+ parts.findFirstIndex([&](const Part& part) -> bool { return part.type == partType; });
return index >= 0 ? getPart(slice, parts[index]) : UnownedStringSlice();
}