Skip to content

Add a bit of documentation for typed COBOL AST#576

Draft
GBertholon wants to merge 1 commit intoOCamlPro:masterfrom
GBertholon:doc-typed-ast
Draft

Add a bit of documentation for typed COBOL AST#576
GBertholon wants to merge 1 commit intoOCamlPro:masterfrom
GBertholon:doc-typed-ast

Conversation

@GBertholon
Copy link
Copy Markdown
Contributor

This PR tries to add missing documentation on the typed COBOL AST.

Currently this is a draft with open questions where I need some input to produce a useful and missing documentation.

I also suggest some very minor refactorings that I am ready to perform.

@GBertholon GBertholon requested a review from nberth April 16, 2026 16:34
Copy link
Copy Markdown
Collaborator

@nberth nberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting investigations. Some of my comments describe changes that could also be included in this PR. In addition, please fit the comments within 80 characters (on the lines that follow field definitions I think).

field_redefinitions: item_redefinitions;
field_conditions: condition_names; (** Named conditions on the value of this field. *)
field_redefines: Cobol_ptree.qualname with_loc option; (** set iff this field is a redefinition. In that case this field must appear only inside item_redefinitions of the item it redefines. TODO: remove and extend item_redefintions type instead? *)
field_redefinitions: item_redefinitions; (** list alternative definitions for this field *)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of extending item_redefinitions instead, probably with a record like { item_redefinitions_redefine: Cobol_ptree.qualname with_loc; item_redefinitions: item_definition wiith_loc nel; }, and then having field_redefinitions: item_redefinitions option; or something like that.

artifacts: artifacts;
ptree: Cobol_ptree.compilation_group; (* Parse tree to access information missing in the typed AST. Is this field supposed to be stable? Should it only be used to access things that are inaccessible from cobol_unit ? *)
group: Cobol_unit.Types.group; (* The typed AST view as an unordered set of cobol_unit *)
artifacts: artifacts; (* Other typing artifacts *)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ptree is left here to ease its direct use by further passes in the analysis pipeline and queries in the LSP server (in which some position-based queries need to be performed on the parse-tree instead of the typed AST). Its presence here is not mandatory so it could be removed.

{
data_items: Cobol_data.Types.data_definition named_n_ordered;
data_items: Cobol_data.Types.data_definition named_n_ordered; (* FIXME: Is the ordered part useful here ? Isn't it already exposed in a more structured way by data_records... *)
data_records: Cobol_data.Types.record list;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it makes sense to keep the ordered alternative as some data items are anonymous (fillers) and therefore do not belong to the resolution map. Additionally the data_definition brings more info than item_definitions themselves, that are the types accessible from the record descriptions.

(* data items *)

(** data_definitions exposes two views on the records in DATA DIVISION:
- [data_items] contains all the fields with direct access by name.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note it's not "fields" but "items": an item is either a field or a table, and a table is always anonymous.
So data_items "contains all data items with direct access by name or ordered access."


(** data_definitions exposes two views on the records in DATA DIVISION:
- [data_items] contains all the fields with direct access by name.
- [data_records] is a list of record trees where each element represent a record root (typically at level 01) *)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- [data_records] is a list of record trees where each element represent a record root (typically at level 01) *)
- [data_records] is a list of record trees where each element represents a record definition (typically a level 01 or 77 data item) *)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants