Repository: shader-slang/slang
File: source/slang/slang-check-modifier.cpp (C++)

Code before:

    case ASTNodeType::ActualGlobalModifier:
    case ASTNodeType::MatrixLayoutModifier:
    case ASTNodeType::RowMajorLayoutModifier:
    case ASTNodeType::HLSLRowMajorLayoutModifier:
    case ASTNodeType::GLSLColumnMajorLayoutModifier:
    case ASTNodeType::ColumnMajorLayoutModifier:
    case ASTNodeType::HLSLColumnMajorLayoutModifier:
    case ASTNodeType::GLSLRowMajorLayoutModifier:
    case ASTNodeType::HLSLEffectSharedModifier:
        return as<VarDeclBase>(decl) || as<GLSLInterfaceBlockDecl>(decl);

    case ASTNodeType::GLSLPrecisionModifier:
        return as<VarDeclBase>(decl) || as<GLSLInterfaceBlockDecl>(decl) || as<CallableDecl>(decl);
    case ASTNodeType::HLSLGroupSharedModifier:
        // groupshared must be global or static.
        if (!as<VarDeclBase>(decl))
            return false;
        return isGlobalDecl(decl) || isEffectivelyStatic(decl);
    case ASTNodeType::DynModifier:
        return as<InterfaceDecl>(decl) || as<VarDecl>(decl) || as<ParamDecl>(decl);
    case ASTNodeType::OverrideModifier:
        {
            Decl* parent = getParentDecl(decl);
            return as<FunctionDeclBase>(decl) &&
                   (as<AggTypeDecl>(parent) || as<ExtensionDecl>(parent));
        }
    default:
        return true;
    }
}

void GLSLBindingOffsetTracker::setBindingOffset(int binding, int64_t byteOffset)
{
    bindingToByteOffset.set(binding, byteOffset);
}

int64_t GLSLBindingOffsetTracker::getNextBindingOffset(int binding)
{
    int64_t currentOffset;
    if (bindingToByteOffset.addIfNotExists(binding, 0))
        currentOffset = 0;
    else
        currentOffset = bindingToByteOffset.getValue(binding) + sizeof(uint32_t);

    bindingToByteOffset.set(binding, currentOffset + sizeof(uint32_t));
    return currentOffset;
}

AttributeBase* SemanticsVisitor::checkGLSLLayoutAttribute(
    UncheckedGLSLLayoutAttribute* uncheckedAttr,

Review comment (suggestion):
can just check for `AggTypeDeclBase`, which includes both the ExtensionDecl and AggTypeDecl.

Code after:

    case ASTNodeType::ActualGlobalModifier:
    case ASTNodeType::MatrixLayoutModifier:
    case ASTNodeType::RowMajorLayoutModifier:
    case ASTNodeType::HLSLRowMajorLayoutModifier:
    case ASTNodeType::GLSLColumnMajorLayoutModifier:
    case ASTNodeType::ColumnMajorLayoutModifier:
    case ASTNodeType::HLSLColumnMajorLayoutModifier:
    case ASTNodeType::GLSLRowMajorLayoutModifier:
    case ASTNodeType::HLSLEffectSharedModifier:
        return as<VarDeclBase>(decl) || as<GLSLInterfaceBlockDecl>(decl);

    case ASTNodeType::GLSLPrecisionModifier:
        return as<VarDeclBase>(decl) || as<GLSLInterfaceBlockDecl>(decl) || as<CallableDecl>(decl);
    case ASTNodeType::HLSLGroupSharedModifier:
        // groupshared must be global or static.
        if (!as<VarDeclBase>(decl))
            return false;
        return isGlobalDecl(decl) || isEffectivelyStatic(decl);
    case ASTNodeType::DynModifier:
        return as<InterfaceDecl>(decl) || as<VarDecl>(decl) || as<ParamDecl>(decl);
    case ASTNodeType::OverrideModifier:
        {
            Decl* parent = getParentDecl(decl);
            return as<FunctionDeclBase>(decl) && as<AggTypeDeclBase>(parent);
        }
    default:
        return true;
    }
}

void GLSLBindingOffsetTracker::setBindingOffset(int binding, int64_t byteOffset)
{
    bindingToByteOffset.set(binding, byteOffset);
}

int64_t GLSLBindingOffsetTracker::getNextBindingOffset(int binding)
{
    int64_t currentOffset;
    if (bindingToByteOffset.addIfNotExists(binding, 0))
        currentOffset = 0;
    else
        currentOffset = bindingToByteOffset.getValue(binding) + sizeof(uint32_t);

    bindingToByteOffset.set(binding, currentOffset + sizeof(uint32_t));
    return currentOffset;
}

AttributeBase* SemanticsVisitor::checkGLSLLayoutAttribute(
    UncheckedGLSLLayoutAttribute* uncheckedAttr,
    ModifiableSyntaxNode* attrTarget)