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
- Kotlin
- Java
repositories {
mavenLocal()
mavenCentral()
flatDir {
dirs("deps")
}
}
dependencies {
implementation(files("deps/clparser-with-dependencies-1.0.1-all.jar"))
}
repositories {
mavenLocal()
mavenCentral()
flatDir {
dirs("deps")
}
}
dependencies {
implementation(files("deps/clparser-with-dependencies-1.0.1-all.jar"))
implementation "com.strumenta.kolasu:kolasu-javalib:1.5.107"
}
Inventory file-related commands
- Kotlin
- Java
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")
}
import com.strumenta.cl.model.CLCompilationUnit;
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.javalib.Traversing;
import java.io.File;
import java.util.concurrent.atomic.AtomicInteger;
public class FileOperations {
public static String formatExpr(CLExpression expr) {
if (expr instanceof CLReferenceExpr ref) return ref.getName().getName();
if (expr instanceof CLLiteral lit) return lit.getText();
if (expr instanceof QualifiedObjectName q) {
return q.getContainer() != null ? q.getContainer() + "/" + q.getName() : q.getName();
}
return expr == null ? "?" : expr.toString();
}
public static void printFileOperations(File clFile, File license) {
LicenseManager.INSTANCE.registerLicense(license);
CLCompilationUnit root = new CLKolasuParser().parse(clFile).getRoot();
if (root == null) return;
System.out.println("DCLF:");
Traversing.walkDescendantsBreadthFirst(root, DeclareFileCommand.class, cmd ->
System.out.println(" file=" + formatExpr(cmd.getFile())));
System.out.println("OVRDBF:");
Traversing.walkDescendantsBreadthFirst(root, OverrideWithDataBaseFileCommand.class, cmd ->
System.out.println(" file=" + formatExpr(cmd.getFile())));
System.out.println("OPNDBF:");
Traversing.walkDescendantsBreadthFirst(root, OpenDataBaseFileCommand.class, cmd ->
System.out.println(" file=" + formatExpr(cmd.getFile())
+ " option=" + formatExpr(cmd.getOption())));
System.out.println("OPNQRYF:");
Traversing.walkDescendantsBreadthFirst(root, OpenQueryFileCommand.class, cmd ->
System.out.println(" file=" + formatExpr(cmd.getFile())));
System.out.println("CLRPFM:");
Traversing.walkDescendantsBreadthFirst(root, ClearPhysicalFileMemberCommand.class, cmd ->
System.out.println(" file=" + formatExpr(cmd.getFile())));
AtomicInteger rcvf = new AtomicInteger();
Traversing.walkDescendantsBreadthFirst(root, ReceiveFileCommand.class, cmd -> rcvf.incrementAndGet());
System.out.println("RCVF occurrences: " + rcvf.get());
}
}
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.