org.jetbrains.java.decompiler.struct.match.MatchEngine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vineflower Show documentation
Show all versions of vineflower Show documentation
Modern Java & JVM language decompiler aiming to be as accurate as possible, with an emphasis on output quality.
The newest version!
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.struct.match;
import org.jetbrains.java.decompiler.modules.decompiler.exps.ExitExprent;
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
import org.jetbrains.java.decompiler.modules.decompiler.exps.FunctionExprent.FunctionType;
import org.jetbrains.java.decompiler.modules.decompiler.stats.IfStatement;
import org.jetbrains.java.decompiler.modules.decompiler.stats.Statement;
import org.jetbrains.java.decompiler.struct.gen.VarType;
import org.jetbrains.java.decompiler.struct.match.IMatchable.MatchProperties;
import org.jetbrains.java.decompiler.struct.match.MatchNode.RuleValue;
import java.util.*;
// Engine to match a statement or exprent tree against a given pattern.
// The pattern can contain variables, which are set and can be extracted from the match.
// "It's like regex, but worse"
public class MatchEngine {
private static final Map stat_properties = new HashMap<>();
private static final Map expr_properties = new HashMap<>();
private static final Map stat_type = new HashMap<>();
private static final Map expr_type = new HashMap<>();
private static final Map expr_func_type = new HashMap<>();
private static final Map expr_exit_type = new HashMap<>();
private static final Map stat_if_type = new HashMap<>();
private static final Map expr_const_type = new HashMap<>();
static {
stat_properties.put("type", MatchProperties.STATEMENT_TYPE);
stat_properties.put("ret", MatchProperties.STATEMENT_RET);
stat_properties.put("position", MatchProperties.STATEMENT_POSITION);
stat_properties.put("statsize", MatchProperties.STATEMENT_STATSIZE);
stat_properties.put("exprsize", MatchProperties.STATEMENT_EXPRSIZE);
stat_properties.put("iftype", MatchProperties.STATEMENT_IFTYPE);
expr_properties.put("type", MatchProperties.EXPRENT_TYPE);
expr_properties.put("ret", MatchProperties.EXPRENT_RET);
expr_properties.put("position", MatchProperties.EXPRENT_POSITION);
expr_properties.put("functype", MatchProperties.EXPRENT_FUNCTYPE);
expr_properties.put("exittype", MatchProperties.EXPRENT_EXITTYPE);
expr_properties.put("consttype", MatchProperties.EXPRENT_CONSTTYPE);
expr_properties.put("constvalue", MatchProperties.EXPRENT_CONSTVALUE);
expr_properties.put("invclass", MatchProperties.EXPRENT_INVOCATION_CLASS);
expr_properties.put("signature", MatchProperties.EXPRENT_INVOCATION_SIGNATURE);
expr_properties.put("parameter", MatchProperties.EXPRENT_PARAMETER);
expr_properties.put("index", MatchProperties.EXPRENT_VAR_INDEX);
expr_properties.put("name", MatchProperties.EXPRENT_NAME);
stat_type.put("if", Statement.StatementType.IF);
stat_type.put("do", Statement.StatementType.DO);
stat_type.put("switch", Statement.StatementType.SWITCH);
stat_type.put("trycatch", Statement.StatementType.TRY_CATCH);
stat_type.put("basicblock", Statement.StatementType.BASIC_BLOCK);
stat_type.put("sequence", Statement.StatementType.SEQUENCE);
expr_type.put("annotation", Exprent.Type.ANNOTATION);
expr_type.put("array", Exprent.Type.ARRAY);
expr_type.put("assert", Exprent.Type.ASSERT);
expr_type.put("assignment", Exprent.Type.ASSIGNMENT);
expr_type.put("constant", Exprent.Type.CONST);
expr_type.put("exit", Exprent.Type.EXIT);
expr_type.put("field", Exprent.Type.FIELD);
expr_type.put("function", Exprent.Type.FUNCTION);
expr_type.put("if", Exprent.Type.IF);
expr_type.put("invocation", Exprent.Type.INVOCATION);
expr_type.put("monitor", Exprent.Type.MONITOR);
expr_type.put("new", Exprent.Type.NEW);
expr_type.put("switch", Exprent.Type.SWITCH);
expr_type.put("switchhead", Exprent.Type.SWITCH_HEAD);
expr_type.put("var", Exprent.Type.VAR);
expr_type.put("yield", Exprent.Type.YIELD);
expr_func_type.put("eq", FunctionType.EQ);
expr_func_type.put("neq", FunctionType.NE);
expr_func_type.put("ternary", FunctionType.TERNARY);
expr_exit_type.put("return", ExitExprent.Type.RETURN);
expr_exit_type.put("throw", ExitExprent.Type.THROW);
stat_if_type.put("if", IfStatement.IFTYPE_IF);
stat_if_type.put("ifelse", IfStatement.IFTYPE_IFELSE);
expr_const_type.put("null", VarType.VARTYPE_NULL);
expr_const_type.put("string", VarType.VARTYPE_STRING);
}
private final MatchNode rootNode;
private final ThreadLocal
© 2015 - 2024 Weber Informatics LLC | Privacy Policy