Skip to content

Commit

Permalink
Instead of FrontendFailure, throw UnsupportedElement
Browse files Browse the repository at this point in the history
  • Loading branch information
leventeBajczi committed Oct 17, 2024
1 parent 244eb92 commit c24de49
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2024 Budapest University of Technology and Economics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package hu.bme.mit.theta.frontend;

public class UnsupportedFrontendElementException extends RuntimeException {
public UnsupportedFrontendElementException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@

import hu.bme.mit.theta.c.frontend.dsl.gen.CBaseVisitor;
import hu.bme.mit.theta.c.frontend.dsl.gen.CParser;
import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionAccessContext;
import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionBracesContext;
import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionBracketsContext;
import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionDecrementContext;
import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionIncrementContext;
import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionMemberAccessContext;
import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionPtrMemberAccessContext;
import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.*;
import hu.bme.mit.theta.common.Tuple2;
import hu.bme.mit.theta.common.logging.Logger;
import hu.bme.mit.theta.common.logging.Logger.Level;
Expand All @@ -35,33 +29,22 @@
import hu.bme.mit.theta.core.type.abstracttype.AbstractExprs;
import hu.bme.mit.theta.core.type.abstracttype.DivExpr;
import hu.bme.mit.theta.core.type.abstracttype.ModExpr;
import hu.bme.mit.theta.core.type.anytype.Dereference;
import hu.bme.mit.theta.core.type.anytype.Exprs;
import hu.bme.mit.theta.core.type.anytype.IteExpr;
import hu.bme.mit.theta.core.type.anytype.RefExpr;
import hu.bme.mit.theta.core.type.anytype.Reference;
import hu.bme.mit.theta.core.type.anytype.*;
import hu.bme.mit.theta.core.type.booltype.BoolExprs;
import hu.bme.mit.theta.core.type.booltype.BoolType;
import hu.bme.mit.theta.core.type.bvtype.BvAndExpr;
import hu.bme.mit.theta.core.type.bvtype.BvExprs;
import hu.bme.mit.theta.core.type.bvtype.BvOrExpr;
import hu.bme.mit.theta.core.type.bvtype.BvType;
import hu.bme.mit.theta.core.type.bvtype.BvXorExpr;
import hu.bme.mit.theta.core.type.bvtype.*;
import hu.bme.mit.theta.core.type.fptype.FpLitExpr;
import hu.bme.mit.theta.core.type.inttype.IntType;
import hu.bme.mit.theta.core.utils.BvUtils;
import hu.bme.mit.theta.core.utils.FpUtils;
import hu.bme.mit.theta.frontend.ParseContext;
import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException;
import hu.bme.mit.theta.frontend.transformation.ArchitectureConfig;
import hu.bme.mit.theta.frontend.transformation.grammar.function.FunctionVisitor;
import hu.bme.mit.theta.frontend.transformation.grammar.preprocess.TypedefVisitor;
import hu.bme.mit.theta.frontend.transformation.grammar.type.TypeVisitor;
import hu.bme.mit.theta.frontend.transformation.model.declaration.CDeclaration;
import hu.bme.mit.theta.frontend.transformation.model.statements.CAssignment;
import hu.bme.mit.theta.frontend.transformation.model.statements.CCall;
import hu.bme.mit.theta.frontend.transformation.model.statements.CCompound;
import hu.bme.mit.theta.frontend.transformation.model.statements.CExpr;
import hu.bme.mit.theta.frontend.transformation.model.statements.CStatement;
import hu.bme.mit.theta.frontend.transformation.model.statements.*;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CArray;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CPointer;
Expand All @@ -70,23 +53,14 @@
import org.kframework.mpfr.BinaryMathContext;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import static com.google.common.base.Preconditions.checkState;
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Add;
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Div;
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq;
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Geq;
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Ite;
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Mod;
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Neq;
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Sub;
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.*;
import static hu.bme.mit.theta.core.type.anytype.Exprs.Reference;
import static hu.bme.mit.theta.core.type.fptype.FpExprs.FpType;
import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int;
Expand Down Expand Up @@ -310,7 +284,7 @@ public Expr<?> visitRelationalExpression(CParser.RelationalExpressionContext ctx
guard = AbstractExprs.Geq(leftExpr, rightExpr);
break;
default:
throw new IllegalStateException("Unexpected value: " + ctx.signs.get(i).getText());
throw new UnsupportedFrontendElementException("Unexpected relational expression sign: " + ctx.signs.get(i).getText());
}
// MaxEnumAnalyzer.instance.consume(guard); TODO: handle circular dependency
CComplexType signedInt = CComplexType.getSignedInt(parseContext);
Expand Down Expand Up @@ -415,7 +389,7 @@ public Expr<?> visitMultiplicativeExpression(CParser.MultiplicativeExpressionCon
}
break;
default:
throw new IllegalStateException("Unexpected value: " + ctx.signs.get(i).getText());
throw new UnsupportedFrontendElementException("Unexpected multiplicative expression sign: " + ctx.signs.get(i).getText());
}
parseContext.getMetadata().create(expr, "cType", smallestCommonType);
expr = smallestCommonType.castTo(expr);
Expand Down Expand Up @@ -665,9 +639,9 @@ public Expr<?> visitPrimaryExpressionConstant(CParser.PrimaryExpressionConstantC

BigFloat bigFloat;
if (text.startsWith("0x")) {
throw new UnsupportedOperationException("Hexadecimal FP constants are not yet supported!");
throw new UnsupportedFrontendElementException("Hexadecimal FP constants are not yet supported!");
} else if (text.startsWith("0b")) {
throw new UnsupportedOperationException("Binary FP constants are not yet supported!");
throw new UnsupportedFrontendElementException("Binary FP constants are not yet supported!");
} else {
bigFloat = new BigFloat(text, new BinaryMathContext(significand - 1, exponent));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import hu.bme.mit.theta.core.type.LitExpr;
import hu.bme.mit.theta.core.type.NullaryExpr;
import hu.bme.mit.theta.core.type.inttype.IntType;
import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException;

import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int;

Expand All @@ -32,7 +33,7 @@ public IntType getType() {

@Override
public LitExpr<IntType> eval(Valuation val) {
throw new UnsupportedOperationException("UnsupportedInitializer expressions are not supported.");
throw new UnsupportedFrontendElementException("UnsupportedInitializer expressions are not supported.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import hu.bme.mit.theta.common.logging.Logger.Level;
import hu.bme.mit.theta.core.type.Expr;
import hu.bme.mit.theta.frontend.ParseContext;
import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException;
import hu.bme.mit.theta.frontend.transformation.grammar.expression.UnsupportedInitializer;
import hu.bme.mit.theta.frontend.transformation.grammar.function.FunctionVisitor;
import hu.bme.mit.theta.frontend.transformation.grammar.preprocess.TypedefVisitor;
Expand Down Expand Up @@ -140,7 +141,7 @@ public CDeclaration visitStructDeclaratorSimple(CParser.StructDeclaratorSimpleCo

@Override
public CDeclaration visitStructDeclaratorConstant(CParser.StructDeclaratorConstantContext ctx) {
throw new UnsupportedOperationException("Not yet supported!");
throw new UnsupportedFrontendElementException("Not yet supported!");
}

@Override
Expand Down Expand Up @@ -191,17 +192,17 @@ public CDeclaration visitDirectDeclaratorArray1(CParser.DirectDeclaratorArray1Co

@Override
public CDeclaration visitDirectDeclaratorArray2(CParser.DirectDeclaratorArray2Context ctx) {
throw new UnsupportedOperationException("Not yet implemented!");
throw new UnsupportedFrontendElementException("Not yet implemented!");
}

@Override
public CDeclaration visitDirectDeclaratorArray3(CParser.DirectDeclaratorArray3Context ctx) {
throw new UnsupportedOperationException("Not yet implemented!");
throw new UnsupportedFrontendElementException("Not yet implemented!");
}

@Override
public CDeclaration visitDirectDeclaratorArray4(CParser.DirectDeclaratorArray4Context ctx) {
throw new UnsupportedOperationException("Not yet implemented!");
throw new UnsupportedFrontendElementException("Not yet implemented!");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import hu.bme.mit.theta.common.logging.Logger.Level;
import hu.bme.mit.theta.core.type.Expr;
import hu.bme.mit.theta.frontend.ParseContext;
import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException;
import hu.bme.mit.theta.frontend.transformation.grammar.preprocess.TypedefVisitor;
import hu.bme.mit.theta.frontend.transformation.model.declaration.CDeclaration;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType;
Expand Down Expand Up @@ -194,15 +195,15 @@ public CSimpleType visitStorageClassSpecifier(CParser.StorageClassSpecifierConte
case "auto":
case "register":
case "_Thread_local":
throw new UnsupportedOperationException("Not yet implemented");
throw new UnsupportedFrontendElementException("Not yet implemented (" + ctx.getText() + ")");
}
throw new UnsupportedOperationException(
throw new UnsupportedFrontendElementException(
"Storage class specifier not expected: " + ctx.getText());
}

@Override
public CSimpleType visitTypeSpecifierAtomic(CParser.TypeSpecifierAtomicContext ctx) {
throw new UnsupportedOperationException("Not yet implemented");
throw new UnsupportedFrontendElementException("Not yet implemented");
}

@Override
Expand All @@ -212,7 +213,7 @@ public CSimpleType visitTypeSpecifierCompound(CParser.TypeSpecifierCompoundConte

@Override
public CSimpleType visitTypeSpecifierFunctionPointer(CParser.TypeSpecifierFunctionPointerContext ctx) {
throw new UnsupportedOperationException("Function pointers not yet implemented");
throw new UnsupportedFrontendElementException("Function pointers not yet implemented");
}

@Override
Expand Down Expand Up @@ -285,7 +286,7 @@ public CSimpleType visitEnumUsage(CParser.EnumUsageContext ctx) {

@Override
public CSimpleType visitTypeSpecifierExtension(CParser.TypeSpecifierExtensionContext ctx) {
throw new UnsupportedOperationException("Not yet implemented");
throw new UnsupportedFrontendElementException("Not yet implemented typeSpecifierExtension");
}

@Override
Expand Down Expand Up @@ -348,7 +349,7 @@ public CSimpleType visitTypeSpecifierTypedefName(CParser.TypeSpecifierTypedefNam

@Override
public CSimpleType visitTypeSpecifierTypeof(CParser.TypeSpecifierTypeofContext ctx) {
throw new UnsupportedOperationException("Not yet implemented");
throw new UnsupportedFrontendElementException("Not yet implemented typeSpecifierTypeof");
}

@Override
Expand All @@ -357,13 +358,13 @@ public CSimpleType visitTypeQualifier(CParser.TypeQualifierContext ctx) {
case "const":
return null;
case "restrict":
throw new UnsupportedOperationException("Not yet implemented!");
throw new UnsupportedFrontendElementException("Not yet implemented 'restrict'!");
case "volatile":
return Volatile();
case "_Atomic":
return Atomic();
}
throw new UnsupportedOperationException(
throw new UnsupportedFrontendElementException(
"Type qualifier " + ctx.getText() + " not expected!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import hu.bme.mit.theta.core.type.bvtype.BvExprs;
import hu.bme.mit.theta.core.type.bvtype.BvType;
import hu.bme.mit.theta.frontend.ParseContext;
import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType;

import java.util.List;
Expand Down Expand Up @@ -99,7 +100,7 @@ public Expr<?> getrExpression() {
ret = BvExprs.Or(List.of((Expr<BvType>) type.castTo(lValue), (Expr<BvType>) type.castTo(rExpression)));
break;
default:
throw new RuntimeException("Bad operator: " + operator);
throw new UnsupportedFrontendElementException("Unsupported operator: " + operator);
}
parseContext.getMetadata().create(ret, "cType", CComplexType.getType(lValue, parseContext));
ret = CComplexType.getType(lValue, parseContext).castTo(ret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import hu.bme.mit.theta.common.Tuple2;
import hu.bme.mit.theta.core.type.Expr;
import hu.bme.mit.theta.frontend.ParseContext;
import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType;

import java.util.ArrayList;
Expand All @@ -38,7 +39,7 @@ public CInitializerList(CComplexType type, ParseContext parseContext) {

@Override
public Expr<?> getExpression() {
throw new UnsupportedOperationException("Cannot create expression of initializer list.");
throw new UnsupportedFrontendElementException("Cannot create expression of initializer list.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import hu.bme.mit.theta.core.type.Expr;
import hu.bme.mit.theta.frontend.ParseContext;
import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException;

/**
* Every Program, Function and Statement is a subclass of this base class.
Expand Down Expand Up @@ -60,23 +61,23 @@ public void setId(String id) {
* @return The expression associated with the statement.
*/
public Expr<?> getExpression() {
throw new RuntimeException("Cannot get expression!");
throw new UnsupportedFrontendElementException("Cannot get expression!");
}

public CStatement getPostStatements() {
return postStatements;
}

public void setPostStatements(CStatement postStatements) {
throw new UnsupportedOperationException("Only CCompounds shall currently have pre- and post statements!");
throw new UnsupportedFrontendElementException("Only CCompounds shall currently have pre- and post statements!");
}

public CStatement getPreStatements() {
return preStatements;
}

public void setPreStatements(CStatement preStatements) {
throw new UnsupportedOperationException("Only CCompounds shall currently have pre- and post statements!");
throw new UnsupportedFrontendElementException("Only CCompounds shall currently have pre- and post statements!");
}

public abstract <P, R> R accept(CStatementVisitor<P, R> visitor, P param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@
import hu.bme.mit.theta.core.type.fptype.FpType;
import hu.bme.mit.theta.core.type.inttype.IntType;
import hu.bme.mit.theta.frontend.ParseContext;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CArray;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CCompound;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CFunction;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CPointer;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CStruct;
import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.*;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.CInteger;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.Fitsall;
import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.c128.C128;
Expand Down Expand Up @@ -62,12 +59,7 @@
import java.util.Map.Entry;
import java.util.Optional;

import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.getCastVisitor;
import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.getLimitVisitor;
import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.getNullValueVisitor;
import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.getTypeVisitor;
import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.getUnitValueVisitor;
import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.getValueVisitor;
import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.*;

public abstract class CComplexType {
private final CSimpleType origin;
Expand Down Expand Up @@ -208,7 +200,7 @@ private static CComplexType getType(Type type, ParseContext parseContext) {
if (longDoubleType.equals(type)) {
return new CFloat(null, parseContext);
}
throw new RuntimeException("No suitable size found for type: " + type);
throw new UnsupportedFrontendElementException("No suitable size found for type: " + type);
} else if (type instanceof BvType) {
for (Entry<String, Integer> entry : parseContext.getArchitecture().standardTypeSizes.entrySet()) {
String s = entry.getKey();
Expand All @@ -230,9 +222,9 @@ private static CComplexType getType(Type type, ParseContext parseContext) {
}
}
}
throw new RuntimeException("No suitable width found for type: " + type);
throw new UnsupportedFrontendElementException("No suitable width found for type: " + type);
} else {
throw new RuntimeException("Not yet implemented for type: " + type);
throw new UnsupportedFrontendElementException("Not yet implemented for type: " + type);
}
}

Expand Down Expand Up @@ -307,7 +299,7 @@ public <T, R> R accept(CComplexTypeVisitor<T, R> visitor, T param) {

public static class CComplexTypeVisitor<T, R> {
public R visit(CComplexType type, T param) {
throw new UnsupportedOperationException("Not (yet) implemented (" + type.getClass().getSimpleName() + " in " + this.getClass().getName() + ")");
throw new UnsupportedFrontendElementException("Not (yet) implemented (" + type.getClass().getSimpleName() + " in " + this.getClass().getName() + ")");
}

public R visit(CVoid type, T param) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String getTypeName() {

@Override
public CInteger getSignedVersion() {
throw new RuntimeException("Bool does not have a signed version!");
throw new RuntimeException("Fitsall does not have a signed version!");
}

@Override
Expand Down
Loading

0 comments on commit c24de49

Please sign in to comment.