-
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 7 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 |
---|---|---|
|
@@ -24,9 +24,20 @@ execRule: EXEC SQL sqlCode END_EXEC | |
| {notifyError("cobolParser.missingEndExec");} EXEC SQL sqlCode DOT_FS? EOF | ||
| {notifyError("cobolParser.missingEndExec");} EXEC SQL; | ||
|
||
nonExecRule: result_set_locator_host_variable; | ||
nonExecRule: host_variable_rule; | ||
|
||
host_variable_rule: (result_set_locator_host_variable | binary_host_variable); | ||
|
||
result_set_locator_host_variable: dbs_level_01 entry_name (USAGE IS?)? SQL TYPE IS RESULT_SET_LOCATOR VARYING; | ||
|
||
binary_host_variable: dbs_level_01 entry_name host_variable_usage binary_host_variable_type; | ||
binary_host_variable_type: BINARY LPARENCHAR binary_host_variable_binary_size RPARENCHAR | VARBINARY LPARENCHAR binary_host_variable_varbinary_size RPARENCHAR | BINARY VARYING; | ||
|
||
binary_host_variable_binary_size: T=dbs_integerliteral_expanded {validateIntegerRange($T.start, $T.text, 1, 255);}; | ||
binary_host_variable_varbinary_size: T=dbs_integerliteral_expanded {validateIntegerRange($T.start, $T.text, 1, 32704);}; | ||
|
||
host_variable_usage: (USAGE IS?)? SQL TYPE IS; | ||
|
||
entry_name : (FILLER |dbs_host_names); | ||
sqlCode | ||
: ~END_EXEC*? | ||
|
@@ -1783,6 +1794,8 @@ dbs_sql_identifier: NONNUMERICLITERAL | IDENTIFIER | FILENAME | FILENAME (DOT_FS | |
dbs_comma_separator: (COMMASEPARATORDB2 | COMMACHAR); | ||
dbs_semicolon_end: SEMICOLON_FS | SEMICOLONSEPARATORSQL; | ||
|
||
dbs_integerliteral_expanded: MINUSCHAR? (INTEGERLITERAL|SINGLEDIGITLITERAL|SINGLEDIGIT_1); | ||
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 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. make sense 👍 |
||
|
||
dbs_integer0: T=dbs_integer {validateValue($T.text, "0");}; | ||
dbs_integer1: T=dbs_integer {validateValue($T.text, "1");}; | ||
dbs_integer2: T=dbs_integer {validateValue($T.text, "2");}; | ||
|
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.
( BINARY | VARBINARY | BINARY VARYING) LPARENCHAR binary_host_variable_varbinary_size RPARENCHAR
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.
looks like
01 VBIN-VAR USAGE IS SQL TYPE IS BINARY VARYING(10).
is a valid syntaxAlso, this introduces
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.
Do we know the max length when using BINARY VARYING? I've kept the sizes separate in order to allow for bounds/range checking as BINARY and VARBINARY have different max sizes. (255 and 32704 respectively)
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.
Well theoretically, these are semantics check and not a syntax issue. But I don't mind it either ways. As a general rule I like to consolidate sub rules to avoid look ahead burden. This is explained at improving-the-performance-of-an-antlr-parse ( check section - Consolidating sub rules)
Since this is a small rule, it doesn't matter a lot here.
For the semantics check, we can always do these in Visitor as the binary_host_variable parser rule context would have all the appropriate value within it.