Skip to main content
Version: 1.0.1

File and Database Operations

CL members often declare display or database files (DCLF), override them (OVRDBF), open them (OPNDBF / OPNQRYF), and read records (RCVF). Collecting these commands gives a file footprint for each program — useful for impact analysis when files or libraries change.

Add Dependencies​

repositories {
mavenLocal()
mavenCentral()
flatDir {
dirs("deps")
}
}

dependencies {
implementation(files("deps/clparser-with-dependencies-1.0.1-all.jar"))
}
import com.strumenta.cl.model.CLExpression
import com.strumenta.cl.model.CLLiteral
import com.strumenta.cl.model.CLReferenceExpr
import com.strumenta.cl.model.ClearPhysicalFileMemberCommand
import com.strumenta.cl.model.DeclareFileCommand
import com.strumenta.cl.model.OpenDataBaseFileCommand
import com.strumenta.cl.model.OpenQueryFileCommand
import com.strumenta.cl.model.OverrideWithDataBaseFileCommand
import com.strumenta.cl.model.QualifiedObjectName
import com.strumenta.cl.model.ReceiveFileCommand
import com.strumenta.cl.parser.CLKolasuParser
import com.strumenta.kolasu.commercial.LicenseManager
import com.strumenta.kolasu.traversing.walkDescendants
import java.io.File

fun formatExpr(expr: CLExpression?): String =
when (expr) {
is CLReferenceExpr -> expr.name.name
is CLLiteral -> expr.text
is QualifiedObjectName ->
if (expr.container != null) "${expr.container}/${expr.name}" else expr.name
null -> "?"
else -> expr.toString()
}

fun printFileOperations(clFile: File, license: File) {
LicenseManager.registerLicense(license)
val root = CLKolasuParser().parse(clFile).root ?: return

println("DCLF:")
root.walkDescendants(DeclareFileCommand::class).forEach {
println(" file=${formatExpr(it.file)}")
}

println("OVRDBF:")
root.walkDescendants(OverrideWithDataBaseFileCommand::class).forEach {
println(" file=${formatExpr(it.file)}")
}

println("OPNDBF:")
root.walkDescendants(OpenDataBaseFileCommand::class).forEach {
println(" file=${formatExpr(it.file)} option=${formatExpr(it.option)}")
}

println("OPNQRYF:")
root.walkDescendants(OpenQueryFileCommand::class).forEach {
println(" file=${formatExpr(it.file)}")
}

println("CLRPFM:")
root.walkDescendants(ClearPhysicalFileMemberCommand::class).forEach {
println(" file=${formatExpr(it.file)}")
}

val rcvf = root.walkDescendants(ReceiveFileCommand::class).count()
println("RCVF occurrences: $rcvf")
}

These commands are typed AST classes (see the AST reference). File and object names are parse-time expressions only — the semantics module does not resolve library/object catalogs.