summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ast-print.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-06-07 14:10:49 -0700
committerGitHub <noreply@github.com>2022-06-07 14:10:49 -0700
commit0c64995ea28febcc7d38e1519da8d93391ce2e7d (patch)
tree8696ab86b29caf80c3ebbd205c700e24b8c20bf3 /source/slang/slang-ast-print.cpp
parent8c4a15c522861d2f30eacc9cd2b03ad793018639 (diff)
Major language server features. (#2264)
* Major language server features. * Include slangd in binary release. * Fix compiler issues. * Fix compiler error. * Completion resolve. * Various improvements. * Update diagnostic test expected output. * Bug fix for source locations. * Adjust diagnostic update frequency. * Update github actions to store artifacts. * Fix infinite parser loop. * Fix parser recovery. * Fix parser recovery. * Update test. * Fix test. * Disable IR gen for language server. * Allow commit characters in auto completion. * Fix lookup for invoke exprs. * More parser robustness fixes. * update solution file Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ast-print.cpp')
-rw-r--r--source/slang/slang-ast-print.cpp128
1 files changed, 126 insertions, 2 deletions
diff --git a/source/slang/slang-ast-print.cpp b/source/slang/slang-ast-print.cpp
index 3ffb481c6..3608e44f1 100644
--- a/source/slang/slang-ast-print.cpp
+++ b/source/slang/slang-ast-print.cpp
@@ -26,6 +26,40 @@ ASTPrinter::Part::Kind ASTPrinter::Part::getKind(ASTPrinter::Part::Type type)
void ASTPrinter::addType(Type* type)
{
+ if (!type)
+ {
+ m_builder << "<error>";
+ return;
+ }
+ if (m_optionFlags & OptionFlag::SimplifiedBuiltinType)
+ {
+ if (auto vectorType = as<VectorExpressionType>(type))
+ {
+ if (as<BasicExpressionType>(vectorType->elementType))
+ {
+ vectorType->elementType->toText(m_builder);
+ if (as<ConstantIntVal>(vectorType->elementCount))
+ {
+ m_builder << vectorType->elementCount;
+ return;
+ }
+ }
+ }
+ else if (auto matrixType = as<MatrixExpressionType>(type))
+ {
+ auto elementType = matrixType->getElementType();
+ if (as<BasicExpressionType>(elementType))
+ {
+ matrixType->getElementType()->toText(m_builder);
+ if (as<ConstantIntVal>(matrixType->getRowCount()) &&
+ as<ConstantIntVal>(matrixType->getColumnCount()))
+ {
+ m_builder << matrixType->getRowCount() << "x" << matrixType->getColumnCount();
+ return;
+ }
+ }
+ }
+ }
type->toText(m_builder);
}
@@ -223,7 +257,7 @@ void ASTPrinter::addGenericParams(const DeclRef<GenericDecl>& genericDeclRef)
sb << ">";
}
-void ASTPrinter::addDeclParams(const DeclRef<Decl>& declRef)
+void ASTPrinter::addDeclParams(const DeclRef<Decl>& declRef, List<Array<Index, 2>>* outParamRange)
{
auto& sb = m_builder;
@@ -237,6 +271,8 @@ void ASTPrinter::addDeclParams(const DeclRef<Decl>& declRef)
{
if (!first) sb << ", ";
+ auto rangeStart = sb.getLength();
+
ParamDecl* paramDecl = paramDeclRef;
{
@@ -278,6 +314,11 @@ void ASTPrinter::addDeclParams(const DeclRef<Decl>& declRef)
}
}
+ auto rangeEnd = sb.getLength();
+
+ if (outParamRange)
+ outParamRange->add(makeArray<Index>(rangeStart, rangeEnd));
+
first = false;
}
@@ -287,7 +328,7 @@ void ASTPrinter::addDeclParams(const DeclRef<Decl>& declRef)
{
addGenericParams(genericDeclRef);
- addDeclParams(DeclRef<Decl>(getInner(genericDeclRef), genericDeclRef.substitutions));
+ addDeclParams(DeclRef<Decl>(getInner(genericDeclRef), genericDeclRef.substitutions), outParamRange);
}
else
{
@@ -300,10 +341,85 @@ void ASTPrinter::addDeclKindPrefix(Decl* decl)
{
decl = genericDecl->inner;
}
+ for (auto modifier : decl->modifiers)
+ {
+ if (modifier->getKeywordName())
+ {
+ if (m_optionFlags & OptionFlag::NoInternalKeywords)
+ {
+ if (as<TargetIntrinsicModifier>(modifier))
+ continue;
+ if (as<MagicTypeModifier>(modifier))
+ continue;
+ if (as<IntrinsicOpModifier>(modifier))
+ continue;
+ if (as<IntrinsicTypeModifier>(modifier))
+ continue;
+ if (as<BuiltinModifier>(modifier))
+ continue;
+ if (as<BuiltinTypeModifier>(modifier))
+ continue;
+ }
+ m_builder << modifier->getKeywordName()->text << " ";
+ }
+ }
if (as<FuncDecl>(decl))
{
m_builder << "func ";
}
+ else if (as<StructDecl>(decl))
+ {
+ m_builder << "struct ";
+ }
+ else if (as<InterfaceDecl>(decl))
+ {
+ m_builder << "interface ";
+ }
+ else if (as<ClassDecl>(decl))
+ {
+ m_builder << "class ";
+ }
+ else if (auto typedefDecl = as<TypeDefDecl>(decl))
+ {
+ m_builder << "typedef ";
+ if (typedefDecl->type.type)
+ {
+ addType(typedefDecl->type.type);
+ m_builder << " ";
+ }
+ }
+ else if (auto propertyDecl = as<PropertyDecl>(decl))
+ {
+ m_builder << "property ";
+ }
+ else if (as<NamespaceDecl>(decl))
+ {
+ m_builder << "namespace ";
+ }
+ else if (auto varDecl = as<VarDeclBase>(decl))
+ {
+ if (varDecl->getType())
+ {
+ addType(varDecl->getType());
+ m_builder << " ";
+ }
+ }
+ else if (as<EnumDecl>(decl))
+ {
+ m_builder << "enum ";
+ }
+ else if (auto enumCase = as<EnumCaseDecl>(decl))
+ {
+ if (enumCase->getType())
+ {
+ addType(enumCase->getType());
+ m_builder << " ";
+ }
+ }
+ else if (auto assocType = as<AssocTypeDecl>(decl))
+ {
+ m_builder << "associatedtype ";
+ }
}
void ASTPrinter::addDeclResultType(const DeclRef<Decl>& inDeclRef)
@@ -326,6 +442,14 @@ void ASTPrinter::addDeclResultType(const DeclRef<Decl>& inDeclRef)
addType(getResultType(m_astBuilder, callableDeclRef));
}
}
+ else if (auto propertyDecl = declRef.as<PropertyDecl>())
+ {
+ if (propertyDecl.getDecl()->type.type)
+ {
+ m_builder << " : ";
+ addType(declRef.substitute(m_astBuilder, propertyDecl.getDecl()->type.type));
+ }
+ }
}
/* static */void ASTPrinter::addDeclSignature(const DeclRef<Decl>& declRef)