|
|
@ -15,13 +15,6 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.jetbrains.java.decompiler.modules.decompiler.exps; |
|
|
|
package org.jetbrains.java.decompiler.modules.decompiler.exps; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map.Entry; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.jetbrains.java.decompiler.main.DecompilerContext; |
|
|
|
import org.jetbrains.java.decompiler.main.DecompilerContext; |
|
|
|
import org.jetbrains.java.decompiler.main.TextBuffer; |
|
|
|
import org.jetbrains.java.decompiler.main.TextBuffer; |
|
|
|
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; |
|
|
|
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; |
|
|
@ -34,8 +27,10 @@ import org.jetbrains.java.decompiler.struct.match.MatchEngine; |
|
|
|
import org.jetbrains.java.decompiler.struct.match.MatchNode; |
|
|
|
import org.jetbrains.java.decompiler.struct.match.MatchNode; |
|
|
|
import org.jetbrains.java.decompiler.struct.match.MatchNode.RuleValue; |
|
|
|
import org.jetbrains.java.decompiler.struct.match.MatchNode.RuleValue; |
|
|
|
|
|
|
|
|
|
|
|
public class Exprent implements IMatchable { |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.Map.Entry; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Exprent implements IMatchable { |
|
|
|
public static final int MULTIPLE_USES = 1; |
|
|
|
public static final int MULTIPLE_USES = 1; |
|
|
|
public static final int SIDE_EFFECTS_FREE = 2; |
|
|
|
public static final int SIDE_EFFECTS_FREE = 2; |
|
|
|
public static final int BOTH_FLAGS = 3; |
|
|
|
public static final int BOTH_FLAGS = 3; |
|
|
@ -145,50 +140,45 @@ public class Exprent implements IMatchable { |
|
|
|
// IMatchable implementation
|
|
|
|
// IMatchable implementation
|
|
|
|
// *****************************************************************************
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public IMatchable findObject(MatchNode matchNode, int index) { |
|
|
|
public IMatchable findObject(MatchNode matchNode, int index) { |
|
|
|
|
|
|
|
if (matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) { |
|
|
|
if(matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) { |
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<Exprent> lstAllExprents = getAllExprents(); |
|
|
|
List<Exprent> lstAllExprents = getAllExprents(); |
|
|
|
|
|
|
|
if (lstAllExprents == null || lstAllExprents.isEmpty()) { |
|
|
|
if(lstAllExprents == null || lstAllExprents.isEmpty()) { |
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String position = (String)matchNode.getRuleValue(MatchProperties.EXPRENT_POSITION); |
|
|
|
String position = (String)matchNode.getRuleValue(MatchProperties.EXPRENT_POSITION); |
|
|
|
if(position != null) { |
|
|
|
if (position != null) { |
|
|
|
if(position.matches("-?\\d+")) { |
|
|
|
if (position.matches("-?\\d+")) { |
|
|
|
return lstAllExprents.get((lstAllExprents.size() + Integer.parseInt(position)) % lstAllExprents.size()); // care for negative positions
|
|
|
|
return lstAllExprents |
|
|
|
|
|
|
|
.get((lstAllExprents.size() + Integer.parseInt(position)) % lstAllExprents.size()); // care for negative positions
|
|
|
|
} |
|
|
|
} |
|
|
|
} else if(index < lstAllExprents.size()) { // use 'index' parameter
|
|
|
|
} |
|
|
|
|
|
|
|
else if (index < lstAllExprents.size()) { // use 'index' parameter
|
|
|
|
return lstAllExprents.get(index); |
|
|
|
return lstAllExprents.get(index); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean match(MatchNode matchNode, MatchEngine engine) { |
|
|
|
public boolean match(MatchNode matchNode, MatchEngine engine) { |
|
|
|
|
|
|
|
if (matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) { |
|
|
|
if(matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) { |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(Entry<MatchProperties, RuleValue> rule : matchNode.getRules().entrySet()) { |
|
|
|
for (Entry<MatchProperties, RuleValue> rule : matchNode.getRules().entrySet()) { |
|
|
|
switch(rule.getKey()) { |
|
|
|
MatchProperties key = rule.getKey(); |
|
|
|
case EXPRENT_TYPE: |
|
|
|
if (key == MatchProperties.EXPRENT_TYPE && this.type != ((Integer)rule.getValue().value).intValue()) { |
|
|
|
if(this.type != ((Integer)rule.getValue().value).intValue()) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (key == MatchProperties.EXPRENT_RET && !engine.checkAndSetVariableValue((String)rule.getValue().value, this)) { |
|
|
|
break; |
|
|
|
return false; |
|
|
|
case EXPRENT_RET: |
|
|
|
|
|
|
|
if(!engine.checkAndSetVariableValue((String)rule.getValue().value, this)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -196,6 +186,6 @@ public class Exprent implements IMatchable { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return toJava(0, new BytecodeMappingTracer()).toString(); |
|
|
|
return toJava(0, BytecodeMappingTracer.DUMMY).toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |