Cleanup (minor optimization)

master
Roman Shevchenko 8 years ago
parent 249903478c
commit a8403429ef
  1. 6
      src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java
  2. 64
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/Exprent.java
  3. 7
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java

@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,6 +21,8 @@ import java.util.*;
import java.util.Map.Entry;
public class BytecodeMappingTracer {
public static final BytecodeMappingTracer DUMMY = new BytecodeMappingTracer();
private int currentSourceLine;
private StructLineNumberTableAttribute lineNumberTable = null;
private final Map<Integer, Integer> mapping = new HashMap<Integer, Integer>(); // bytecode offset, source line
@ -116,4 +118,4 @@ public class BytecodeMappingTracer {
}
return res;
}
}
}

@ -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();
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -494,11 +494,6 @@ public class Statement implements IMatchable {
return false;
}
// to be overwritten
public TextBuffer toJava() {
return toJava(0, new BytecodeMappingTracer());
}
public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
throw new RuntimeException("not implemented");
}

Loading…
Cancel
Save