Commit ee6141f0 authored by Lubomir Bulej's avatar Lubomir Bulej

Started moving Java name handling from the AsmHelper and Constants classes to JavaNames class.

parent 11234525
......@@ -11,7 +11,7 @@ import org.objectweb.asm.commons.AdviceAdapter;
import ch.usi.dag.disl.localvar.ThreadLocalVar;
import ch.usi.dag.disl.util.AsmHelper;
import ch.usi.dag.disl.util.Constants;
import ch.usi.dag.disl.util.JavaNames;
final class TLVInserter extends ClassVisitor {
......@@ -27,7 +27,7 @@ final class TLVInserter extends ClassVisitor {
String sig, String[] exceptions) {
// add field initialization
if (Constants.isConstructorName (name)) {
if (JavaNames.isConstructorName (name)) {
return new TLVInitializer(super.visitMethod(access, name, desc,
sig, exceptions), access, name, desc);
}
......
......@@ -32,9 +32,9 @@ import ch.usi.dag.disl.localvar.SyntheticLocalVar;
import ch.usi.dag.disl.localvar.ThreadLocalVar;
import ch.usi.dag.disl.util.AsmHelper;
import ch.usi.dag.disl.util.AsmHelper.Insns;
import ch.usi.dag.disl.util.Constants;
import ch.usi.dag.disl.util.FrameHelper;
import ch.usi.dag.disl.util.Insn;
import ch.usi.dag.disl.util.JavaNames;
import ch.usi.dag.disl.util.Logging;
import ch.usi.dag.disl.util.ReflectionHelper;
import ch.usi.dag.util.logging.Logger;
......@@ -74,7 +74,7 @@ abstract class AbstractParser {
for (final MethodNode method : dislClass.methods) {
// get the code
if (Constants.isInitializerName (method.name)) {
if (JavaNames.isInitializerName (method.name)) {
cinit = method;
break;
}
......
......@@ -23,7 +23,7 @@ import ch.usi.dag.disl.processor.ArgProcessor;
import ch.usi.dag.disl.processor.ArgProcessorKind;
import ch.usi.dag.disl.processor.ArgProcessorMethod;
import ch.usi.dag.disl.util.AsmHelper;
import ch.usi.dag.disl.util.Constants;
import ch.usi.dag.disl.util.JavaNames;
import ch.usi.dag.util.Strings;
......@@ -70,8 +70,8 @@ class ArgProcessorParser extends AbstractParser {
try {
final String className = AsmHelper.className (disClass);
return disClass.methods.parallelStream ().unordered ()
.filter (m -> !Constants.isConstructorName (m.name))
.filter (m -> !Constants.isInitializerName (m.name))
.filter (m -> !JavaNames.isConstructorName (m.name))
.filter (m -> !JavaNames.isInitializerName (m.name))
// Throws ParserRuntimeException.
.map (m -> __parseMethodWrapper (className, m))
.collect (Collectors.toList ());
......
......@@ -26,12 +26,12 @@ import ch.usi.dag.disl.exception.SnippetParserException;
import ch.usi.dag.disl.guard.GuardHelper;
import ch.usi.dag.disl.marker.Marker;
import ch.usi.dag.disl.marker.Parameter;
import ch.usi.dag.disl.scope.Scope;
import ch.usi.dag.disl.scope.ScopeMatcher;
import ch.usi.dag.disl.scope.Scope;
import ch.usi.dag.disl.snippet.Snippet;
import ch.usi.dag.disl.snippet.SnippetUnprocessedCode;
import ch.usi.dag.disl.util.AsmHelper;
import ch.usi.dag.disl.util.Constants;
import ch.usi.dag.disl.util.JavaNames;
import ch.usi.dag.disl.util.ReflectionHelper;
......@@ -60,8 +60,8 @@ class SnippetParser extends AbstractParser {
final String className = AsmHelper.className (dislClass);
snippets.addAll (dislClass.methods.parallelStream ().unordered ()
.filter (m -> !Constants.isConstructorName (m.name))
.filter (m -> !Constants.isInitializerName (m.name))
.filter (m -> !JavaNames.isConstructorName (m.name))
.filter (m -> !JavaNames.isInitializerName (m.name))
.map (m -> __parseSnippetWrapper (className, m))
.collect (Collectors.toList ())
);
......@@ -91,7 +91,6 @@ class SnippetParser extends AbstractParser {
}
// parse snippet
private Snippet __parseSnippet (
final String className, final MethodNode method
) throws ParserException, ReflectionException, MarkerException, GuardException {
......
......@@ -32,6 +32,7 @@ import ch.usi.dag.disl.util.AsmHelper;
import ch.usi.dag.disl.util.AsmHelper.Insns;
import ch.usi.dag.disl.util.Constants;
import ch.usi.dag.disl.util.Insn;
import ch.usi.dag.disl.util.JavaNames;
import ch.usi.dag.disl.util.ReflectionHelper;
import ch.usi.dag.disl.util.cfg.CtrlFlowGraph;
......@@ -187,7 +188,7 @@ public class UnprocessedCode {
final MethodInsnNode insn = e.getInsn ();
throw new DiSLInitializationException (
"%s: invocation of static context method %s.%s: %s",
location (insn), AsmHelper.internalToStdName (insn.owner),
location (insn), JavaNames.internalToCanonical (insn.owner),
insn.name, e.getMessage ()
);
}
......
......@@ -16,7 +16,7 @@ import ch.usi.dag.disl.exception.ExclusionPrepareException;
import ch.usi.dag.disl.exception.ManifestInfoException;
import ch.usi.dag.disl.scope.Scope;
import ch.usi.dag.disl.scope.ScopeMatcher;
import ch.usi.dag.disl.util.Constants;
import ch.usi.dag.disl.util.JavaNames;
public abstract class ExclusionSet {
......@@ -28,10 +28,6 @@ public abstract class ExclusionSet {
private static final String JAR_PATH_END = "!";
private static final char JAR_ENTRY_DELIM = '/';
private static final char CLASS_DELIM = '.';
private static final String ALL_METHODS = ".*";
......@@ -109,12 +105,10 @@ public abstract class ExclusionSet {
final String entryName = entry.getName ();
// add all classes to the exclusion list
if (entryName.endsWith (Constants.CLASS_EXT)) {
String className = entryName.replace (JAR_ENTRY_DELIM, CLASS_DELIM);
// remove class ext
final int classNameEnd = className.lastIndexOf (Constants.CLASS_EXT);
className = className.substring (0, classNameEnd);
if (JavaNames.hasClassFileExtension (entryName)) {
final String className = JavaNames.internalToCanonical (
JavaNames.stripClassFileExtension (entryName)
);
// add exclusion for all methods
final String classExcl = className + ALL_METHODS;
......
......@@ -14,7 +14,7 @@ import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.snippet.Shadow.WeavingRegion;
import ch.usi.dag.disl.util.AsmHelper;
import ch.usi.dag.disl.util.AsmHelper.Insns;
import ch.usi.dag.disl.util.Constants;
import ch.usi.dag.disl.util.JavaNames;
/**
......@@ -65,7 +65,7 @@ public class AfterInitBodyMarker extends AbstractMarker {
//
// Fast path for non-constructor methods.
//
if (!Constants.isConstructorName (method.name)) {
if (!JavaNames.isConstructorName (method.name)) {
return method.instructions.getFirst ();
}
......
......@@ -9,7 +9,7 @@ import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import ch.usi.dag.disl.util.AsmHelper.Insns;
import ch.usi.dag.disl.util.Constants;
import ch.usi.dag.disl.util.JavaNames;
/**
* Marks object creation.
......@@ -44,7 +44,7 @@ public class NewObjMarker extends AbstractDWRMarker {
MethodInsnNode min = (MethodInsnNode) instruction;
if (Constants.isConstructorName (min.name)) {
if (JavaNames.isConstructorName (min.name)) {
regions.add(new MarkedRegion(instruction, instruction));
}
}
......
......@@ -3,6 +3,7 @@ package ch.usi.dag.disl.staticcontext;
import org.objectweb.asm.Opcodes;
import ch.usi.dag.disl.util.Constants;
import ch.usi.dag.disl.util.JavaNames;
/**
......@@ -38,9 +39,7 @@ public class MethodStaticContext extends AbstractStaticContext {
* qualified class name, with packages delimited by the '.' character.
*/
public String thisClassCanonicalName () {
return __classInternalName ().replace (
Constants.PACKAGE_INTERN_DELIM, Constants.PACKAGE_STD_DELIM
);
return JavaNames.internalToCanonical (__classInternalName ());
}
......@@ -217,7 +216,7 @@ public class MethodStaticContext extends AbstractStaticContext {
* Returns {@code true} if this method is a constructor.
*/
public boolean isMethodConstructor () {
return Constants.isConstructorName (__methodName ());
return JavaNames.isConstructorName (__methodName ());
}
......@@ -225,7 +224,7 @@ public class MethodStaticContext extends AbstractStaticContext {
* Returns {@code true} if this method is a class initializer.
*/
public boolean isMethodInitializer () {
return Constants.isInitializerName (__methodName ());
return JavaNames.isInitializerName (__methodName ());
}
......
......@@ -1158,17 +1158,7 @@ public abstract class AsmHelper {
* @return Canonical class name for the given {@link ClassNode}.
*/
public static String className (final ClassNode classNode) {
return internalToStdName (classNode.name);
}
/**
* @return Canonical class name for the given internal class name.
*/
public static String internalToStdName (final String internalName) {
return internalName.replace (
Constants.PACKAGE_INTERN_DELIM, Constants.PACKAGE_STD_DELIM
);
return JavaNames.internalToCanonical (classNode.name);
}
}
......@@ -7,19 +7,6 @@ public final class Constants {
final public static char PACKAGE_STD_DELIM = '.';
final public static char PACKAGE_INTERN_DELIM = '/';
final public static String CONSTRUCTOR_NAME = "<init>";
final public static String STATIC_INIT_NAME = "<clinit>";
final public static String CLASS_DELIM = ".";
final public static String CLASS_EXT = ".class";
public static final boolean isConstructorName (final String name) {
return CONSTRUCTOR_NAME.equals (name);
}
public static final boolean isInitializerName (final String name) {
return STATIC_INIT_NAME.equals (name);
}
}
......@@ -53,7 +53,7 @@ public final class JavaNames {
return name + __CLASS_FILE_EXTENSION__;
}
public static String removeClassFileExtension (final String name) {
public static String stripClassFileExtension (final String name) {
final int extensionStart = name.lastIndexOf (__CLASS_FILE_EXTENSION__);
return (extensionStart >= 0) ? name.substring (0, extensionStart) : name;
}
......
......@@ -39,6 +39,7 @@ import ch.usi.dag.disl.util.AsmHelper;
import ch.usi.dag.disl.util.AsmHelper.Insns;
import ch.usi.dag.disl.util.FrameHelper;
import ch.usi.dag.disl.util.Insn;
import ch.usi.dag.disl.util.JavaNames;
import ch.usi.dag.disl.weaver.pe.MaxCalculator;
import ch.usi.dag.disl.weaver.pe.PartialEvaluator;
......@@ -1093,7 +1094,7 @@ public class WeavingCode {
"%s: unexpected bytecode at call site in %s.%s() "+
"when applying ArgumentProcessorContext.getArgs() ",
__location (snippet, invokeInsn),
AsmHelper.internalToStdName (shadow.getClassNode ().name),
JavaNames.internalToCanonical (shadow.getClassNode ().name),
shadow.getMethodNode ().name
);
}
......@@ -1107,7 +1108,7 @@ public class WeavingCode {
"%s: failed to obtain source frame at call site in %s.%s() "+
"when applying ArgumentProcessorContext.getArgs() ",
__location (snippet, invokeInsn),
AsmHelper.internalToStdName (shadow.getClassNode ().name),
JavaNames.internalToCanonical (shadow.getClassNode ().name),
shadow.getMethodNode ().name
);
}
......
......@@ -14,6 +14,7 @@ import ch.usi.dag.disl.DiSL;
import ch.usi.dag.disl.DiSL.CodeOption;
import ch.usi.dag.disl.exception.DiSLException;
import ch.usi.dag.disl.util.Constants;
import ch.usi.dag.disl.util.JavaNames;
import ch.usi.dag.disl.util.Logging;
import ch.usi.dag.util.Strings;
import ch.usi.dag.util.logging.Logger;
......@@ -228,7 +229,7 @@ final class RequestProcessor {
// dump the class code
try (
final FileOutputStream fo = new FileOutputStream (
pathWithPkg + simpleClassName + Constants.CLASS_EXT
pathWithPkg + JavaNames.appendClassFileExtension (simpleClassName)
);
) {
fo.write(byteCode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment