|
|
|
@ -15,13 +15,6 @@ |
|
|
|
|
*/ |
|
|
|
|
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.TextBuffer; |
|
|
|
|
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.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 SIDE_EFFECTS_FREE = 2; |
|
|
|
|
public static final int BOTH_FLAGS = 3; |
|
|
|
@ -144,58 +139,53 @@ public class Exprent implements IMatchable { |
|
|
|
|
// *****************************************************************************
|
|
|
|
|
// IMatchable implementation
|
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public IMatchable findObject(MatchNode matchNode, int index) { |
|
|
|
|
|
|
|
|
|
if(matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) { |
|
|
|
|
if (matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<Exprent> lstAllExprents = getAllExprents(); |
|
|
|
|
|
|
|
|
|
if(lstAllExprents == null || lstAllExprents.isEmpty()) { |
|
|
|
|
if (lstAllExprents == null || lstAllExprents.isEmpty()) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String position = (String)matchNode.getRuleValue(MatchProperties.EXPRENT_POSITION); |
|
|
|
|
if(position != null) { |
|
|
|
|
if(position.matches("-?\\d+")) { |
|
|
|
|
return lstAllExprents.get((lstAllExprents.size() + Integer.parseInt(position)) % lstAllExprents.size()); // care for negative positions
|
|
|
|
|
if (position != null) { |
|
|
|
|
if (position.matches("-?\\d+")) { |
|
|
|
|
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 null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean match(MatchNode matchNode, MatchEngine engine) { |
|
|
|
|
|
|
|
|
|
if(matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) { |
|
|
|
|
if (matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(Entry<MatchProperties, RuleValue> rule : matchNode.getRules().entrySet()) { |
|
|
|
|
switch(rule.getKey()) { |
|
|
|
|
case EXPRENT_TYPE: |
|
|
|
|
if(this.type != ((Integer)rule.getValue().value).intValue()) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case EXPRENT_RET: |
|
|
|
|
if(!engine.checkAndSetVariableValue((String)rule.getValue().value, this)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
for (Entry<MatchProperties, RuleValue> rule : matchNode.getRules().entrySet()) { |
|
|
|
|
MatchProperties key = rule.getKey(); |
|
|
|
|
if (key == MatchProperties.EXPRENT_TYPE && this.type != ((Integer)rule.getValue().value).intValue()) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (key == MatchProperties.EXPRENT_RET && !engine.checkAndSetVariableValue((String)rule.getValue().value, this)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String toString() { |
|
|
|
|
return toJava(0, new BytecodeMappingTracer()).toString(); |
|
|
|
|
return toJava(0, BytecodeMappingTracer.DUMMY).toString(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |