-
Notifications
You must be signed in to change notification settings - Fork 62
feat: Db2 binary host variable support #2337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
39ac9ec
9a442d8
acbb561
066bba1
e6c4be5
e90f196
536eff3
d2303c8
43275ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,33 @@ public List<Node> visitResult_set_locator_host_variable( | |
return ImmutableList.of(variableDefinitionNode); | ||
} | ||
|
||
@Override | ||
public List<Node> visitBinary_host_variable(Db2SqlParser.Binary_host_variableContext ctx) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, we would need to add test, for usage of generated variables There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The IBM DB2 preprocessor converts the DB2 variable types to those supported by COBOL. These generated variables should already be taken care of. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is that below program with db2 pre/co-processor would compile fine. But cobol-ls would start to throw error variable not defined. Identification Division.
Program-Id. 'TEST1'.
Data Division.
Working-Storage Section.
LINKAGE SECTION.
01 VBIN-VAR USAGE IS SQL TYPE IS BINARY VARYING(10).
PROCEDURE division.
display VBIN-VAR-LEN.
display VBIN-VAR-TEXT.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll take it from here. Let's merge this PR if everything else is fine. |
||
addReplacementContext(ctx); | ||
Locality statementLocality = getLocality(this.context.getExtendedDocument().mapLocation(constructRange(ctx))); | ||
|
||
Db2WorkingAndLinkageSectionNode semanticsNode = new Db2WorkingAndLinkageSectionNode(statementLocality); | ||
|
||
VariableDefinitionNode variableDefinitionNode = | ||
VariableDefinitionNode.builder() | ||
.level(Integer.parseInt(ctx.dbs_level_01().getText())) | ||
.levelLocality( | ||
getLocality( | ||
this.context.getExtendedDocument().mapLocation(constructRange(ctx.entry_name())))) | ||
.statementLocality(statementLocality) | ||
.variableNameAndLocality( | ||
new VariableNameAndLocality( | ||
VisitorHelper.getName(ctx.entry_name()), | ||
getLocality( | ||
this.context | ||
.getExtendedDocument() | ||
.mapLocation(constructRange(ctx.entry_name()))))) | ||
.usageClauses(ImmutableList.of(UsageFormat.DISPLAY)) | ||
.build(); | ||
variableDefinitionNode.addChild(semanticsNode); | ||
return ImmutableList.of(variableDefinitionNode); | ||
} | ||
|
||
private Locality getLocality(Location location) { | ||
Locality.LocalityBuilder builder = | ||
Locality.builder().uri(location.getUri()).range(location.getRange()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if -ve length should be allowed at grammar level. This would always be +ve integer as per doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct, but if the user types a minus sign by accident we can now catch that. See the screenshot at the bottom of the initial comment/post in the PR as an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense 👍