[ClavaAst] Adds BinaryOperator.getOpTry()
@@ -16,6 +16,7 @@ package pt.up.fe.specs.clava.ast.expr;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import org.suikasoft.jOptions.Datakey.DataKey;
import org.suikasoft.jOptions.Datakey.KeyFactory;
@@ -23,6 +24,7 @@ import org.suikasoft.jOptions.Interfaces.DataStore;
import pt.up.fe.specs.clava.ClavaNode;
import pt.up.fe.specs.clava.ast.expr.enums.BinaryOperatorKind;
+import pt.up.fe.specs.util.lazy.Lazy;
/**
* Represents a builtin binary operation expression.
@@ -80,6 +82,21 @@ public class BinaryOperator extends Operator {
}
+ private static final Lazy<Map<String, BinaryOperatorKind>> OP_MAP = Lazy.newInstance(BinaryOperator::buildOpMap);
+
+ private static Map<String, BinaryOperatorKind> buildOpMap() {
+ Map<String, BinaryOperatorKind> opMap = new HashMap<>();
+ for (var entry : KIND_NAMES.entrySet()) {
+ opMap.put(entry.getValue(), entry.getKey());
+ }
+
+ return opMap;
+ }
+
+ public static Optional<BinaryOperatorKind> getOpTry(String opName) {
+ return Optional.ofNullable(OP_MAP.get().get(opName));
+ }
+
public BinaryOperator(DataStore data, Collection<? extends ClavaNode> children) {
super(data, children);
}
