Skip to content

Commit

Permalink
Intermediate commit - need to replace with SubstitutingDb2SqlVisitor …
Browse files Browse the repository at this point in the history
…to keep current tests working

Making issue 69 pass, but DB2 SQL creates multiple placeholders which are repeated every substitution, needs fixing
  • Loading branch information
avishek-sen-gupta committed Dec 2, 2024
1 parent 333ab5a commit cb5e934
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* This serves as a container for all IDMS-related code fragments which are then re-inserted
* back into the parse tree on writing as JSON
*/
public class IdmsContainerNode extends ParserRuleContext {
public class DialectContainerNode extends ParserRuleContext {
private final ParseTree dialectNode;
@Getter private final LocalisedDialect dialect;

public IdmsContainerNode(ParseTree dialectNode, CobolParser.DialectNodeFillerContext parent, LocalisedDialect dialect) {
public DialectContainerNode(ParseTree dialectNode, CobolParser.DialectNodeFillerContext parent, LocalisedDialect dialect) {
super(parent, 1);
this.dialectNode = dialectNode;
this.dialect = dialect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void enterDialectNodeFiller(CobolParser.DialectNodeFillerContext ctx) {
LocalisedDialect dialect = PersistentData.dialect("IDMS-" + guid);
ParseTree dialectNode = PersistentData.getDialectNode("IDMS-" + guid);
LOGGER.finer(String.format("Restoring _DIALECT_ %s: %s", guid, dialectNode.getText()));
ctx.addChild(new IdmsContainerNode(dialectNode, ctx, dialect));
ctx.addChild(new DialectContainerNode(dialectNode, ctx, dialect));
restores++;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.antlr.v4.runtime.tree.ParseTree;
import org.eclipse.lsp.cobol.core.CobolParser;
import org.smojol.common.ast.NodeText;
import org.smojol.common.idms.IdmsContainerNode;
import org.smojol.common.idms.DialectContainerNode;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -80,7 +80,7 @@ public void buildDialectNodeRepository() {
LOGGER.info("WARNING: The following dialect node has no children: " + n.getText());
}
String markerID = "_DIALECT_ " + n.getChild(1).getText();
ParseTree idmsContainer = findByCondition(n, c -> c.getClass() == IdmsContainerNode.class, 1);
ParseTree idmsContainer = findByCondition(n, c -> c.getClass() == DialectContainerNode.class, 1);
String text = NodeText.originalText(idmsContainer.getChild(0), NodeText::PASSTHROUGH);
symbolText.put(markerID, text);
});
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import com.google.common.collect.ImmutableList;
import org.smojol.common.ast.*;
import org.smojol.common.idms.IdmsContainerNode;
import org.smojol.common.idms.DialectContainerNode;
import org.smojol.common.vm.stack.StackFrames;

import java.util.List;

public class CicsBlockFlowNode extends CobolFlowNode {

public CicsBlockFlowNode(IdmsContainerNode containerNode, FlowNode scope, FlowNodeService nodeService, StackFrames stackFrames) {
public CicsBlockFlowNode(DialectContainerNode containerNode, FlowNode scope, FlowNodeService nodeService, StackFrames stackFrames) {
super(containerNode, scope, nodeService, stackFrames);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.smojol.common.ast.FlowNodeService;
import org.smojol.common.ast.NullFlowNode;
import org.smojol.common.ast.SyntaxIdentity;
import org.smojol.common.idms.IdmsContainerNode;
import org.smojol.common.idms.DialectContainerNode;
import org.eclipse.lsp.cobol.core.CobolParser;
import org.eclipse.lsp.cobol.dialects.idms.IdmsParser;
import org.smojol.common.vm.stack.StackFrames;
Expand Down Expand Up @@ -187,7 +187,7 @@ private static boolean isCompositeNode(ParseTree executionContext) {
return
executionContext.getClass() == CobolParser.DialectSectionContext.class ||
executionContext.getClass() == IdmsParser.IdmsIfStatementContext.class ||
executionContext.getClass() == IdmsContainerNode.class ||
executionContext.getClass() == DialectContainerNode.class ||
executionContext.getClass() == IdmsParser.InquireMapIfStatementContext.class
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.eclipse.lsp.cobol.core.CobolParser;
import org.eclipse.lsp.cobol.dialects.idms.IdmsParser;
import org.smojol.common.ast.*;
import org.smojol.common.idms.IdmsContainerNode;
import org.smojol.common.idms.DialectContainerNode;
import org.smojol.common.navigation.CobolEntityNavigator;
import org.smojol.common.vm.stack.StackFrames;

Expand Down Expand Up @@ -39,17 +39,22 @@ public String name() {
@Override
public void buildInternalFlow() {
CobolEntityNavigator navigator = nodeService.getNavigator();
IdmsContainerNode containerNode = (IdmsContainerNode) navigator.findByCondition(n -> n.getClass() == IdmsContainerNode.class);
DialectContainerNode containerNode = (DialectContainerNode) navigator.findByCondition(n -> n.getClass() == DialectContainerNode.class);
LocalisedDialect dialect = containerNode.getDialect();
switch (dialect) {
case IDMS: buildIdmsFlow(navigator);
break;
case CICS: buildCicsFLow(containerNode);
break;
case DB2_SQL: buildDb2SqlFlow(containerNode);
}
}

private void buildCicsFLow(IdmsContainerNode containerNode) {
private void buildDb2SqlFlow(DialectContainerNode containerNode) {
dialectChildNode = new CicsBlockFlowNode(containerNode, this, nodeService, staticFrameContext);

}
private void buildCicsFLow(DialectContainerNode containerNode) {
dialectChildNode = new CicsBlockFlowNode(containerNode, this, nodeService, staticFrameContext);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import java.util.Map;

import static org.smojol.toolkit.task.CommandLineAnalysisTask.BUILD_BASE_ANALYSIS;
import static org.smojol.toolkit.task.CommandLineAnalysisTask.WRITE_RAW_AST;

public class ExecCicsBuildMain_Issue69 {
public class ExecDb2SqlBuildMain_Issue69 {
public static void main(String[] args) throws IOException, InterruptedException {
Map<String, List<AnalysisTaskResult>> result = new CodeTaskRunner("/Users/asgupta/code/smojol/smojol-test-code",
"/Users/asgupta/code/smojol/out/report",
Expand All @@ -31,7 +32,7 @@ LanguageDialect.COBOL, new FullProgram(FlowchartOutputFormat.PNG, new UUIDProvid
new OccursIgnoringFormat1DataStructureBuilder(),
new ProgramSearch(),
new LocalFilesystemOperations())
.runForPrograms(ImmutableList.of(BUILD_BASE_ANALYSIS), ImmutableList.of("exec-cics-issue-69.cbl"));
.runForPrograms(ImmutableList.of(BUILD_BASE_ANALYSIS, WRITE_RAW_AST), ImmutableList.of("exec-db2-sql-issue-69.cbl"));
AnalysisTaskResultOK ok = (AnalysisTaskResultOK) result.values().stream().toList().getFirst().getFirst();
BaseAnalysisModel base = ok.getDetail();
System.out.println("DONE");
Expand Down

0 comments on commit cb5e934

Please sign in to comment.