diff --git a/source/slang/slang-ast-iterator.h b/source/slang/slang-ast-iterator.h index 2b6a2d3e28..40a943dc08 100644 --- a/source/slang/slang-ast-iterator.h +++ b/source/slang/slang-ast-iterator.h @@ -132,12 +132,30 @@ struct ASTIterator for (auto arg : expr->arguments) dispatchIfNotNull(arg); } + void visitPackExpr(PackExpr* expr) + { + for (auto arg : expr->args) + dispatchIfNotNull(arg); + } + + void visitExpandExpr(ExpandExpr* expr) + { + iterator->maybeDispatchCallback(expr); + dispatchIfNotNull(expr->baseExpr); + } + + void visitEachExpr(EachExpr* expr) + { + iterator->maybeDispatchCallback(expr); + dispatchIfNotNull(expr->baseExpr); + } void visitDerefExpr(DerefExpr* expr) { iterator->maybeDispatchCallback(expr); dispatchIfNotNull(expr->base); } + void visitMatrixSwizzleExpr(MatrixSwizzleExpr* expr) { iterator->maybeDispatchCallback(expr); diff --git a/source/slang/slang-ast-print.cpp b/source/slang/slang-ast-print.cpp index d3e0289013..f5f99f01d9 100644 --- a/source/slang/slang-ast-print.cpp +++ b/source/slang/slang-ast-print.cpp @@ -170,7 +170,7 @@ void ASTPrinter::_addDeclPathRec(const DeclRef& declRef, Index depth) // signature if (parentGenericDeclRef && !declRef.as() && - !declRef.as()) + !declRef.as()) { auto substArgs = tryGetGenericArguments(SubstitutionSet(declRef), parentGenericDeclRef.getDecl()); if (substArgs.getCount()) @@ -250,6 +250,16 @@ void ASTPrinter::addGenericParams(const DeclRef& genericDeclRef) addType(getType(m_astBuilder, genericValParam)); } } + else if (auto genericTypePackParam = paramDeclRef.as()) + { + if (!first) sb << ", "; + first = false; + { + ScopePart scopePart(this, Part::Type::GenericParamType); + sb << "each "; + sb << getText(genericTypePackParam.getName()); + } + } else { } @@ -269,57 +279,73 @@ void ASTPrinter::addDeclParams(const DeclRef& declRef, List>* bool first = true; for (auto paramDeclRef : getParameters(m_astBuilder, funcDeclRef)) { - if (!first) sb << ", "; - auto rangeStart = sb.getLength(); ParamDecl* paramDecl = paramDeclRef.getDecl(); + auto paramType = getType(m_astBuilder, paramDeclRef); + auto addParamElement = [&](Type* type, Index elementIndex) { - ScopePart scopePart(this, Part::Type::ParamType); - - // Seems these apply to parameters/VarDeclBase and are not part of the 'type' - // but seems more appropriate to put in the Type Part + if (!first) sb << ", "; - if (paramDecl->hasModifier()) - { - sb << toSlice("inout "); - } - else if (paramDecl->hasModifier()) + // Type part. { - sb << toSlice("out "); - } - else if (paramDecl->hasModifier()) - { - sb << toSlice("in "); + ScopePart scopePart(this, Part::Type::ParamType); + + // Seems these apply to parameters/VarDeclBase and are not part of the 'type' + // but seems more appropriate to put in the Type Part + + if (paramDecl->hasModifier()) + { + sb << toSlice("inout "); + } + else if (paramDecl->hasModifier()) + { + sb << toSlice("out "); + } + else if (paramDecl->hasModifier()) + { + sb << toSlice("in "); + } + + // And this to params/variables (not the type) + if (paramDecl->hasModifier()) + { + sb << toSlice("const "); + } + + addType(type); } - // And this to params/variables (not the type) - if (paramDecl->hasModifier()) + // Output the parameter name if there is one, and it's enabled in the options + if (m_optionFlags & OptionFlag::ParamNames && paramDecl->getName()) { - sb << toSlice("const "); + sb << " "; + { + ScopePart scopePart(this, Part::Type::ParamName); + sb << paramDecl->getName()->text; + if (elementIndex != -1) + sb << "_" << elementIndex; + } } - addType(getType(m_astBuilder, paramDeclRef)); - } + auto rangeEnd = sb.getLength(); - // Output the parameter name if there is one, and it's enabled in the options - if (m_optionFlags & OptionFlag::ParamNames && paramDecl->getName()) + if (outParamRange) + outParamRange->add(makeRange(rangeStart, rangeEnd)); + first = false; + }; + if (auto typePack = as(paramType)) { - sb << " "; - + for (Index elementIndex = 0; elementIndex < typePack->getTypeCount(); ++elementIndex) { - ScopePart scopePart(this, Part::Type::ParamName); - sb << paramDecl->getName()->text; + addParamElement(typePack->getElementType(elementIndex), elementIndex); } } - - auto rangeEnd = sb.getLength(); - - if (outParamRange) - outParamRange->add(makeRange(rangeStart, rangeEnd)); - - first = false; + else + { + addParamElement(paramType, -1); + } } sb << ")"; diff --git a/source/slang/slang-language-server-ast-lookup.cpp b/source/slang/slang-language-server-ast-lookup.cpp index 755805b516..5c73d2ab9d 100644 --- a/source/slang/slang-language-server-ast-lookup.cpp +++ b/source/slang/slang-language-server-ast-lookup.cpp @@ -461,7 +461,16 @@ struct ASTLookupExprVisitor: public ExprVisitor return false; } bool visitTryExpr(TryExpr* expr) { return dispatchIfNotNull(expr->base); } - bool visitHigherOrderInvokeExpr(HigherOrderInvokeExpr* expr) + bool visitPackExpr(PackExpr* expr) + { + for (auto arg : expr->args) + { + if(dispatchIfNotNull(arg)) + return true; + } + return false; + } + bool reportLookupResultIfInExprLeadingIdentifierRange(Expr* expr) { auto humaneLoc = context->sourceManager->getHumaneLoc(expr->loc, SourceLocType::Actual); auto tokenLen = context->doc->getTokenLength(humaneLoc.line, humaneLoc.column); @@ -473,6 +482,24 @@ struct ASTLookupExprVisitor: public ExprVisitor context->results.add(result); return true; } + return false; + } + bool visitExpandExpr(ExpandExpr* expr) + { + if (reportLookupResultIfInExprLeadingIdentifierRange(expr)) + return true; + return dispatchIfNotNull(expr->baseExpr); + } + bool visitEachExpr(EachExpr* expr) + { + if (reportLookupResultIfInExprLeadingIdentifierRange(expr)) + return true; + return dispatchIfNotNull(expr->baseExpr); + } + bool visitHigherOrderInvokeExpr(HigherOrderInvokeExpr* expr) + { + if (reportLookupResultIfInExprLeadingIdentifierRange(expr)) + return true; return dispatchIfNotNull(expr->baseFunction); } bool visitTreatAsDifferentiableExpr(TreatAsDifferentiableExpr* expr) diff --git a/source/slang/slang-language-server.cpp b/source/slang/slang-language-server.cpp index ed03a5dc4c..81c7d24cf8 100644 --- a/source/slang/slang-language-server.cpp +++ b/source/slang/slang-language-server.cpp @@ -245,6 +245,10 @@ String getDeclKindString(DeclRef declRef) { return "(generic type parameter) "; } + else if (declRef.as()) + { + return "(generic type pack parameter) "; + } else if (declRef.as()) { return "(generic value parameter) ";