use of de.be4.eventb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class OpSubstitutions method caseAFuncOpSubstitution.
@Override
public void caseAFuncOpSubstitution(final AFuncOpSubstitution node) {
final PExpression expression = node.getFunction();
PExpression idExpr = null;
LinkedList<PExpression> parameters = null;
Type type = null;
TIdentifierLiteral idToken = null;
String idString = null;
if (expression instanceof AFunctionExpression) {
// the operation was parsed as a function expression
final AFunctionExpression function = (AFunctionExpression) expression;
final PExpression funcId = function.getIdentifier();
if (funcId instanceof AIdentifierExpression) {
final AIdentifierExpression identifier = (AIdentifierExpression) funcId;
idString = Utils.getTIdentifierListAsString(identifier.getIdentifier());
idToken = identifier.getIdentifier().get(0);
type = definitions.getType(idString);
} else {
type = Type.NoDefinition;
}
idExpr = function.getIdentifier();
parameters = new LinkedList<>(function.getParameters());
} else if (expression instanceof AIdentifierExpression) {
// the operation was parsed as an identifier expression
final AIdentifierExpression identifier = (AIdentifierExpression) expression;
idString = Utils.getTIdentifierListAsString(identifier.getIdentifier());
idToken = identifier.getIdentifier().get(0);
type = definitions.getType(idString);
idExpr = expression;
parameters = new LinkedList<>();
} else {
// some other expression was parsed (NOT allowed)
throw new BParseException(null, "Expecting operation");
}
if (type != Type.NoDefinition && idToken != null) {
if (type == Type.Substitution || type == Type.ExprOrSubst) {
// create DefinitionSubstitution
final ADefinitionSubstitution defSubst = new ADefinitionSubstitution(new TDefLiteralSubstitution(idToken.getText(), idToken.getLine(), idToken.getPos()), parameters);
if (type == Type.ExprOrSubst) {
// type is determined now => set to Substitution
setTypeSubstDef(node, idString);
}
// transfer position information
final PositionedNode posNode = node;
final PositionedNode newPosNode = defSubst;
newPosNode.setStartPos(posNode.getStartPos());
newPosNode.setEndPos(posNode.getEndPos());
node.replaceBy(defSubst);
defSubst.apply(this);
} else {
// finding some other type here is an error!
throw new VisitorException(new CheckException("Expecting substitution here but found definition with type '" + type + "'", node));
}
} else {
// no def, no problem ;-)
final AOpSubstitution opSubst = new AOpSubstitution(idExpr, parameters);
opSubst.setStartPos(idExpr.getStartPos());
opSubst.setEndPos(idExpr.getEndPos());
node.replaceBy(opSubst);
opSubst.apply(this);
}
}
use of de.be4.eventb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class RulesMachineChecker method caseAMachineHeader.
@Override
public void caseAMachineHeader(AMachineHeader node) {
if (!node.getParameters().isEmpty()) {
errorList.add(new CheckException("A RULES_MACHINE must not have any machine parameters", node));
}
LinkedList<TIdentifierLiteral> nameList = node.getName();
if (nameList.size() > 1) {
errorList.add(new CheckException("Renaming of a RULES_MACHINE name is not allowed.", node));
}
this.nameLiteral = nameList.get(0);
this.machineName = nameLiteral.getText();
}
use of de.be4.eventb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class RulesMachineChecker method inAOperationCallSubstitution.
@Override
public void inAOperationCallSubstitution(AOperationCallSubstitution node) {
LinkedList<TIdentifierLiteral> opNameList = node.getOperation();
if (opNameList.size() > 1) {
errorList.add(new CheckException("Renaming of operation names is not allowed.", node));
}
List<PExpression> copy = new ArrayList<>(node.getResultIdentifiers());
checkThatIdentifiersAreLocalVariables(copy);
if (currentOperation != null) {
currentOperation.addFunctionCall(opNameList.get(0));
}
}
use of de.be4.eventb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class RulesProject method checkForCycles.
private boolean checkForCycles(AbstractOperation operation, List<TIdentifierLiteral> directDependencies, List<AbstractOperation> ancestors) {
List<String> ancestorsNames = new ArrayList<>();
for (AbstractOperation op : ancestors) {
String opName = op.getName();
ancestorsNames.add(opName);
}
for (TIdentifierLiteral id : directDependencies) {
final String opName = id.getText();
if (ancestorsNames.contains(opName)) {
StringBuilder sb = new StringBuilder();
for (int index = ancestorsNames.indexOf(opName); index < ancestors.size(); index++) {
final String name = ancestors.get(index).getName();
sb.append(name);
sb.append(" -> ");
}
sb.append(opName);
this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Cyclic dependencies between operations: " + sb.toString(), id)));
return true;
}
}
return false;
}
use of de.be4.eventb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class RulesProject method checkVisibilityOfAIdentifierList.
private void checkVisibilityOfAIdentifierList(AbstractOperation operation, List<AIdentifierExpression> dependencyList) {
List<TIdentifierLiteral> tidentifierList = new ArrayList<>();
for (AIdentifierExpression aIdentifier : dependencyList) {
tidentifierList.add(aIdentifier.getIdentifier().get(0));
}
checkVisibilityOfTIdentifierList(operation, tidentifierList);
}
Aggregations