Skip to content
Snippets Groups Projects
Commit 0fc0a1f6 authored by dohan's avatar dohan
Browse files

adapt to new parser

parent 15ecfd4c
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,14 @@ configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
def parser_version = '2.7.1-SNAPSHOT'
def parser_version
if (project.version.endsWith("-SNAPSHOT")) {
parser_version = '2.9.7-SNAPSHOT'
}
else {
parser_version = '2.9.6'
}
def tlatools_version = '1.0.2'
dependencies {
......@@ -85,13 +92,15 @@ task createJar(type: Jar, dependsOn: build){
}
task tla2b(dependsOn: createJar) << {
task tla2b(dependsOn: createJar) {
doLast{
copy {
from('build/libs/')
into('.')
include('TLA2B.jar')
}
}
}
if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) {
......
package de.tla2b.output;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
import de.be4.classicalb.core.parser.util.Utils;
......@@ -13,17 +13,17 @@ import de.be4.classicalb.core.parser.node.TIdentifierLiteral;
public class Renamer extends DepthFirstAdapter {
private final java.util.Hashtable<Node, String> namesTables;
private final HashMap<Node, String> namesTables;
private final Set<String> globalNames;
public Renamer(Start start) {
this.namesTables = new Hashtable<Node, String>();
this.globalNames = new HashSet<String>();
this.namesTables = new HashMap<>();
this.globalNames = new HashSet<>();
start.apply(this);
}
private final static Set<String> KEYWORDS = new HashSet<String>();
private final static Set<String> KEYWORDS = new HashSet<>();
static {
KEYWORDS.add("seq");
KEYWORDS.add("left");
......@@ -80,7 +80,7 @@ public class Renamer extends DepthFirstAdapter {
@Override
public void caseAIdentifierExpression(AIdentifierExpression node) {
String name = Utils.getIdentifierAsString(node.getIdentifier());
String name = Utils.getAIdentifierAsString(node);
String newName = incName(name, new HashSet<String>());
namesTables.put(node, newName);
}
......@@ -93,16 +93,15 @@ public class Renamer extends DepthFirstAdapter {
}
private Boolean existingName(String name) {
if (globalNames.contains(name) || KEYWORDS.contains(name)) {
return true;
} else
return false;
return globalNames.contains(name) || KEYWORDS.contains(name);
}
private String incName(String name, Set<String> tempSet) {
String res = name;
for (int i = 1; existingName(res) || tempSet.contains(res); i++) {
int i = 1;
while (existingName(res) || tempSet.contains(res)) {
res = name + "_" + i;
i++;
}
return res;
}
......
......@@ -34,8 +34,6 @@ import tlc2.value.StringValue;
import tlc2.value.Value;
import tlc2.value.ValueConstants;
import de.be4.classicalb.core.parser.Definitions;
import de.be4.classicalb.core.parser.exceptions.BException;
import de.be4.classicalb.core.parser.exceptions.CheckException;
import de.be4.classicalb.core.parser.node.*;
import de.hhu.stups.sablecc.patch.PositionedNode;
import de.hhu.stups.sablecc.patch.SourcePosition;
......@@ -262,24 +260,19 @@ public class BAstCreator extends BuiltInOPs
}
if (defs.size() > 0) {
if (!defs.isEmpty()) {
ADefinitionsMachineClause defClause = new ADefinitionsMachineClause();
defClause.setDefinitions(defs);
machineClauseList.add(defClause);
try {
for (PDefinition def : defs) {
if (def instanceof AExpressionDefinitionDefinition) {
bDefinitions.addDefinition((AExpressionDefinitionDefinition) def, Definitions.Type.Expression);
} else if (def instanceof APredicateDefinitionDefinition) {
bDefinitions.addDefinition((APredicateDefinitionDefinition) def, Definitions.Type.Predicate);
} else {
bDefinitions.addDefinition((ASubstitutionDefinitionDefinition) def,
Definitions.Type.Substitution);
}
bDefinitions.addDefinition((ASubstitutionDefinitionDefinition) def, Definitions.Type.Substitution);
}
} catch (BException | CheckException e) {
throw new AssertionError(e);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment