use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class OpSubstitutions method setTypeSubstDef.
private void setTypeSubstDef(final AFuncOpSubstitution node, final String idString) {
final AExpressionDefinitionDefinition oldDefinition = (AExpressionDefinitionDefinition) definitions.getDefinition(idString);
final Node defRhs = oldDefinition.getRhs();
final PSubstitution rhsSubst;
if (defRhs instanceof AFunctionExpression) {
final AFunctionExpression rhsFunction = (AFunctionExpression) defRhs;
rhsSubst = new AOpSubstitution(rhsFunction.getIdentifier(), new LinkedList<PExpression>(rhsFunction.getParameters()));
rhsSubst.setStartPos(rhsFunction.getStartPos());
rhsSubst.setEndPos(rhsFunction.getEndPos());
} else if (defRhs instanceof AIdentifierExpression) {
final AIdentifierExpression rhsIdent = (AIdentifierExpression) defRhs;
rhsSubst = new AOpSubstitution(rhsIdent, new LinkedList<PExpression>());
rhsSubst.setStartPos(rhsIdent.getStartPos());
rhsSubst.setEndPos(rhsIdent.getEndPos());
} else {
// some other expression was parsed (NOT allowed)
throw new VisitorException(new CheckException("Expecting operation", node));
}
final TIdentifierLiteral oldDefId = oldDefinition.getName();
final TDefLiteralSubstitution defId = new TDefLiteralSubstitution(oldDefId.getText(), oldDefId.getLine(), oldDefId.getPos());
final ASubstitutionDefinitionDefinition substDef = new ASubstitutionDefinitionDefinition(defId, new LinkedList<PExpression>(oldDefinition.getParameters()), rhsSubst);
substDef.setStartPos(oldDefinition.getStartPos());
substDef.setEndPos(oldDefinition.getEndPos());
definitions.replaceDefinition(idString, Type.Substitution, substDef);
oldDefinition.replaceBy(substDef);
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class OpSubstitutions method caseAIdentifierExpression.
@Override
public void caseAIdentifierExpression(final AIdentifierExpression node) {
final String identifierString = Utils.getTIdentifierListAsString(node.getIdentifier());
final Integer number = scopedVariables.get(identifierString);
final Type type = definitions.getType(identifierString);
if (number == null && type != Type.NoDefinition) {
if (type == Type.Expression || type == Type.ExprOrSubst) {
/*
* getFirst() is enough cause definitions cannot have composed
* identifiers
*/
replaceWithDefExpression(node, node.getIdentifier().getFirst(), null);
if (type == Type.ExprOrSubst) {
// type is determined now => set to Expression
definitions.setDefinitionType(identifierString, Type.Expression);
}
} else {
// finding some other type here is an error!
throw new VisitorException(new CheckException("Expecting expression here but found definition with type '" + type + "'", node));
}
}
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class RulesProject method collectAllOperations.
private void collectAllOperations() {
for (IModel iModel : bModels) {
final RulesParseUnit unit = (RulesParseUnit) iModel;
final List<AbstractOperation> operations = unit.getOperations();
for (AbstractOperation abstractOperation : operations) {
final String name = abstractOperation.getName();
if (allOperations.containsKey(name)) {
this.bExceptionList.add(new BException(abstractOperation.getFileName(), new CheckException("Duplicate operation name: '" + name + "'.", abstractOperation.getNameLiteral())));
}
allOperations.put(name, abstractOperation);
}
}
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class RulesProject method checkVisibilityOfTIdentifierList.
private void checkVisibilityOfTIdentifierList(AbstractOperation operation, List<TIdentifierLiteral> dependencyList) {
List<String> machineReferences = operation.getMachineReferencesAsString();
machineReferences.add(operation.getMachineName());
for (TIdentifierLiteral tIdentifierLiteral : dependencyList) {
String otherOpName = tIdentifierLiteral.getText();
if (allOperations.containsKey(otherOpName)) {
AbstractOperation abstractOperation = allOperations.get(otherOpName);
String otherMachineName = abstractOperation.getMachineName();
if (!machineReferences.contains(otherMachineName)) {
this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Operation '" + otherOpName + "' is not visible in RULES_MACHINE '" + operation.getMachineName() + "'.", tIdentifierLiteral)));
}
}
}
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class RulesProject method checkFunctionCalls.
private void checkFunctionCalls(AbstractOperation abstractOperation) {
boolean errorOccured = false;
for (TIdentifierLiteral tIdentifierLiteral : abstractOperation.getFunctionCalls()) {
final String functionName = tIdentifierLiteral.getText();
if (!allOperations.containsKey(functionName) || !(allOperations.get(functionName) instanceof FunctionOperation)) {
this.bExceptionList.add(new BException(abstractOperation.getFileName(), new CheckException("Unknown FUNCTION name '" + functionName + "'", tIdentifierLiteral)));
errorOccured = true;
}
}
if (!errorOccured) {
checkVisibilityOfTIdentifierList(abstractOperation, abstractOperation.getFunctionCalls());
}
}
Aggregations