Skip to content

Commit ad9e331

Browse files
committed
feature: add semantics check for file IO operations
Signed-off-by: Aman Prashant <[email protected]>
1 parent ea2f0bf commit ad9e331

File tree

15 files changed

+937
-43
lines changed

15 files changed

+937
-43
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2023 Broadcom.
3+
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4+
*
5+
* This program and the accompanying materials are made
6+
* available under the terms of the Eclipse Public License 2.0
7+
* which is available at https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Broadcom, Inc. - initial API and implementation
13+
*
14+
*/
15+
16+
package org.eclipse.lsp.cobol.common.model;
17+
18+
/** Enumeration of file operation types */
19+
public enum FileOperationKind {
20+
INPUT,
21+
OUTPUT,
22+
I_O,
23+
EXTEND
24+
}

server/common/src/main/java/org/eclipse/lsp/cobol/common/model/NodeType.java

+41-35
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,55 @@
1616

1717
/** Enumeration of Node types. */
1818
public enum NodeType {
19-
ROOT,
20-
PROGRAM,
21-
SECTION,
22-
VARIABLE_DEFINITION,
23-
VARIABLE_DEFINITION_NAME,
24-
QUALIFIED_REFERENCE_NODE,
25-
VARIABLE_USAGE,
26-
VARIABLE,
27-
FILE_USAGE,
28-
FILE_CONTROL_ENTRY,
29-
PROGRAM_ID,
30-
PROGRAM_END,
31-
PROCEDURE_DIVISION,
32-
PARAGRAPH,
33-
GO_TO,
34-
PROCEDURE_SECTION,
35-
PERFORM,
36-
EXIT,
37-
EXIT_SECTION,
38-
GO_BACK,
39-
STOP,
19+
AT_END,
20+
CODE_BLOCK_PARENT,
21+
CODE_BLOCK_USAGE,
22+
COMPILER_DIRECTIVE,
23+
COPY,
24+
CUSTOM,
25+
DELETE_STATEMENT,
26+
DIVISION,
27+
EMBEDDED_CODE,
4028
EVALUATE,
4129
EVALUATE_WHEN,
4230
EVALUATE_WHEN_OTHER,
31+
EXIT,
32+
EXIT_SECTION,
33+
FILE_CONTROL_ENTRY,
34+
FILE_USAGE,
35+
GO_BACK,
36+
GO_TO,
4337
IF,
4438
IF_ELSE,
45-
JSON_PARSE,
46-
XML_PARSE,
4739
JSON_GENERATE,
40+
JSON_PARSE,
41+
LITERAL,
42+
OBSOLETE,
43+
OPEN_STATEMENT,
44+
PARAGRAPH,
45+
PARAGRAPH_NAME_NODE,
46+
PERFORM,
47+
PROCEDURE_DIVISION,
48+
PROCEDURE_SECTION,
49+
PROGRAM,
50+
PROGRAM_END,
51+
PROGRAM_ID,
52+
QUALIFIED_REFERENCE_NODE,
53+
READ_STATEMENT,
54+
REWRITE_STATEMENT,
55+
ROOT,
56+
SECTION,
57+
SECTION_NAME_NODE,
4858
SENTENCE,
59+
START_STATEMENT,
4960
STATEMENT,
50-
EMBEDDED_CODE,
51-
CODE_BLOCK_USAGE,
52-
CODE_BLOCK_PARENT,
53-
COPY,
54-
DIVISION,
55-
LITERAL,
61+
STOP,
5662
SUBROUTINE,
5763
SUBROUTINE_NAME_NODE,
58-
PARAGRAPH_NAME_NODE,
59-
SECTION_NAME_NODE,
60-
CUSTOM,
61-
OBSOLETE,
62-
AT_END,
63-
COMPILER_DIRECTIVE
64+
VARIABLE,
65+
VARIABLE_DEFINITION,
66+
VARIABLE_DEFINITION_NAME,
67+
VARIABLE_USAGE,
68+
WRITE_STATEMENT,
69+
XML_PARSE
6470
}

server/common/src/main/java/org/eclipse/lsp/cobol/common/model/tree/statements/StatementNode.java

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import lombok.extern.slf4j.Slf4j;
1919
import org.eclipse.lsp.cobol.common.model.Locality;
20+
import org.eclipse.lsp.cobol.common.model.NodeType;
2021
import org.eclipse.lsp.cobol.common.model.tree.Node;
2122

2223
import static org.eclipse.lsp.cobol.common.model.NodeType.STATEMENT;
@@ -31,4 +32,8 @@ public abstract class StatementNode extends Node {
3132
protected StatementNode(Locality locality) {
3233
super(locality, STATEMENT);
3334
}
35+
36+
protected StatementNode(Locality locality, NodeType nodeType) {
37+
super(locality, nodeType);
38+
}
3439
}

server/common/src/main/java/org/eclipse/lsp/cobol/common/model/tree/variable/VariableDefinitionNode.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public final class VariableDefinitionNode extends Node {
5656
private final boolean isSignClausePresent;
5757
private final String valueToken;
5858
private final String fileDescriptor;
59+
private final boolean isExternal;
5960
@Setter private String fileControlClause;
6061
private final boolean isSortDescription;
6162
@Setter private List<UsageFormat> usageClauses;
@@ -85,7 +86,8 @@ private VariableDefinitionNode(
8586
boolean isSortDescription,
8687
boolean isDynamicLength,
8788
boolean isJustified,
88-
boolean isUnBounded) {
89+
boolean isUnBounded,
90+
boolean isExternal) {
8991
super(location, NodeType.VARIABLE_DEFINITION);
9092
this.level = level;
9193
this.variableName = variableName;
@@ -108,6 +110,7 @@ private VariableDefinitionNode(
108110
this.isDynamicLength = isDynamicLength;
109111
this.isJustified = isJustified;
110112
this.isUnBounded = isUnBounded;
113+
this.isExternal = isExternal;
111114
}
112115

113116
private static SyntaxError checkClauseIsSingle(
@@ -356,6 +359,7 @@ public static final class Builder {
356359
boolean isDynamicLength;
357360
boolean isJustified;
358361
boolean isUnBounded;
362+
boolean isExternal;
359363

360364
private Builder() {}
361365

@@ -387,7 +391,8 @@ public VariableDefinitionNode build() {
387391
isSortDescription,
388392
isDynamicLength,
389393
isJustified,
390-
isUnBounded);
394+
isUnBounded,
395+
isExternal);
391396
}
392397
}
393398
}

server/common/src/main/java/org/eclipse/lsp/cobol/common/model/tree/variables/FileDescriptionNode.java

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@ToString(callSuper = true)
3232
@EqualsAndHashCode(callSuper = true)
3333
public class FileDescriptionNode extends VariableNode {
34+
@Getter private final boolean isExternal;
3435
@Getter private final String fileDescriptorText;
3536
@Getter private final String fileControlClause;
3637

@@ -39,9 +40,11 @@ public FileDescriptionNode(
3940
String name,
4041
VariableType variableType,
4142
boolean global,
43+
boolean isExternal,
4244
String fileDescriptorText,
4345
String fileControlClause) {
4446
super(location, name, variableType, global);
47+
this.isExternal = isExternal;
4548
this.fileDescriptorText = fileDescriptorText;
4649
this.fileControlClause = fileControlClause;
4750
}

server/engine/src/main/java/org/eclipse/lsp/cobol/cfg/CFASTBuilderImpl.java

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.eclipse.lsp.cobol.cfg;
1616

1717
import org.eclipse.lsp.cobol.common.model.tree.*;
18+
import org.eclipse.lsp.cobol.common.model.tree.statements.StatementNode;
1819
import org.eclipse.lsp.cobol.common.model.variables.DivisionType;
1920
import org.eclipse.lsp.cobol.core.model.extendedapi.*;
2021
import org.eclipse.lsp4j.Position;
@@ -77,6 +78,8 @@ private void traverse(CFASTNode parent, Node node) {
7778
addChild(parent, new CFASTNode(CFASTNodeType.ENDIF.getValue()));
7879
} else if (node instanceof SentenceNode) {
7980
node.getChildren().forEach(child -> traverse(parent, child));
81+
} else if (node instanceof StatementNode) {
82+
node.getChildren().forEach(child -> traverse(parent, child));
8083
} else if (node instanceof IfElseNode) {
8184
addChild(parent, new CFASTNode(CFASTNodeType.ELSE.getValue()));
8285
node.getChildren().forEach(child -> traverse(parent, child));

server/engine/src/main/java/org/eclipse/lsp/cobol/core/engine/pipeline/stages/TransformTreeStage.java

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.eclipse.lsp.cobol.core.engine.processors.implicit.ImplicitVariablesProcessor;
3838
import org.eclipse.lsp.cobol.core.engine.symbols.SymbolAccumulatorService;
3939
import org.eclipse.lsp.cobol.core.engine.symbols.SymbolsRepository;
40+
import org.eclipse.lsp.cobol.core.model.tree.FileOperationStatementNode;
41+
import org.eclipse.lsp.cobol.core.model.tree.logic.FileOperationProcess;
4042
import org.eclipse.lsp.cobol.core.semantics.CopybooksRepository;
4143
import org.eclipse.lsp.cobol.core.visitor.CobolVisitor;
4244
import org.eclipse.lsp.cobol.service.settings.CachingConfigurationService;
@@ -207,6 +209,7 @@ private void registerProcessors(AnalysisConfig analysisConfig, ProcessingContext
207209
ctx.register(v, JsonGenerateNode.class, new JsonGenerateProcess(symbolAccumulatorService));
208210
ctx.register(v, XMLParseNode.class, new XMLParseProcess(symbolAccumulatorService));
209211
ctx.register(v, FileStatusNode.class, new FileStatusProcess(symbolAccumulatorService));
212+
ctx.register(v, FileOperationStatementNode.class, new FileOperationProcess());
210213

211214
// Dialects
212215
List<ProcessorDescription> pds = dialectService.getProcessors(analysisConfig.getDialects());

0 commit comments

Comments
 (0)