Skip to content

Commit

Permalink
Fixing code formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Apr 14, 2024
1 parent f842585 commit fd8f9f4
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 24 deletions.
Binary file modified modules/test/bifs/Hola.class
Binary file not shown.
Binary file modified modules/test/components/ModuleAbort.class
Binary file not shown.
Binary file modified modules/test/config/Scheduler.class
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.util.Textifier;
import org.objectweb.asm.util.TraceClassVisitor;
import ortus.boxlang.compiler.Boxpiler;
import ortus.boxlang.compiler.ClassInfo;
Expand Down Expand Up @@ -66,7 +65,7 @@ public Class<IBoxRunnable> compileStatement( String source, BoxSourceType type )

@Override
public void printTranspiledCode( ParsingResult result, ClassInfo classInfo, PrintStream target ) {
doCompileClassInfo( classInfo, new TraceClassVisitor( null, new PrintWriter( target ) ));
doCompileClassInfo( classInfo, new TraceClassVisitor( null, new PrintWriter( target ) ) );
}

@Override
Expand All @@ -80,14 +79,13 @@ public void compileClassInfo( String FQN ) {

doCompileClassInfo( classInfo, classWriter );

byte[] bytes = classWriter.toByteArray();
byte[] bytes = classWriter.toByteArray();

diskClassUtil.writeBytes( classInfo.FQN(), ".class", bytes );

throw new UnsupportedOperationException( "Unimplemented method 'generateJavaSource'" );
}


private void doCompileClassInfo( ClassInfo classInfo, ClassVisitor classVisitor ) {
Transpiler transpiler = Transpiler.getTranspiler();
transpiler.setProperty( "classname", classInfo.className() );
Expand All @@ -97,10 +95,10 @@ private void doCompileClassInfo( ClassInfo classInfo, ClassVisitor classVisitor
transpiler.setProperty( "returnType", classInfo.returnType() );
transpiler.setProperty( "sourceType", classInfo.sourceType().name() );

ParsingResult result = parseClassInfo( classInfo );
ParsingResult result = parseClassInfo( classInfo );

// TODO: define method.
MethodVisitor methodVisitor = classVisitor.visitMethod(Opcodes.ACC_PUBLIC, "m", "()V", null, null);
MethodVisitor methodVisitor = classVisitor.visitMethod( Opcodes.ACC_PUBLIC, "m", "()V", null, null );
methodVisitor.visitCode();
transpiler.transpile( result.getRoot(), methodVisitor );
methodVisitor.visitEnd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

public class AsmTranspiler extends Transpiler {

static Logger logger = LoggerFactory.getLogger( AsmTranspiler.class );
static Logger logger = LoggerFactory.getLogger( AsmTranspiler.class );

private static HashMap<Class<?>, Transformer> registry = new HashMap<>();
private static HashMap<Class<?>, Transformer> registry = new HashMap<>();

public AsmTranspiler() {
// TODO: instance write to static field. Seems like an oversight in Java version (retained until clarified).
Expand All @@ -34,7 +34,8 @@ public void transform( BoxNode node, MethodVisitor visitor ) {
Transformer transformer = registry.get( node.getClass() );
if ( transformer != null ) {
transformer.transform( node, visitor );
logger.atTrace().log( "Transforming {} node with source {} - transformer is {}", transformer.getClass().getSimpleName(), node.getSourceText(), transformer );
logger.atTrace().log( "Transforming {} node with source {} - transformer is {}", transformer.getClass().getSimpleName(), node.getSourceText(),
transformer );
return;
}
throw new IllegalStateException( "unsupported: " + node.getClass().getSimpleName() + " : " + node.getSourceText() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

public interface ITranspiler {

void transpile(BoxNode node, MethodVisitor visitor ) throws BoxRuntimeException;
void transpile( BoxNode node, MethodVisitor visitor ) throws BoxRuntimeException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public abstract class Transpiler implements ITranspiler {

private final HashMap<String, String> properties = new HashMap<String, String>();
private final HashMap<String, String> properties = new HashMap<String, String>();

/**
* Set a property
Expand Down Expand Up @@ -39,5 +39,5 @@ public static Transpiler getTranspiler() {
@Override
public abstract void transpile( BoxNode node, MethodVisitor visitor ) throws BoxRuntimeException;

public abstract void transform(BoxNode node, MethodVisitor visitor );
public abstract void transform( BoxNode node, MethodVisitor visitor );
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

public abstract class AbstractTransformer implements Transformer {

protected Transpiler transpiler;
protected Logger logger;
protected Transpiler transpiler;
protected Logger logger;

public AbstractTransformer(Transpiler transpiler) {
this.transpiler = transpiler;
public AbstractTransformer( Transpiler transpiler ) {
this.transpiler = transpiler;
this.logger = LoggerFactory.getLogger( this.getClass() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public BoxStringLiteralTransformer( Transpiler transpiler ) {

@Override
public void transform( BoxNode node, MethodVisitor visitor ) throws IllegalStateException {
BoxStringLiteral literal = ( BoxStringLiteral ) node;
BoxStringLiteral literal = ( BoxStringLiteral ) node;
visitor.visitLdcInsn( literal.getValue() );
logger.atTrace().log( "{} -> {}", node.getSourceText(), literal.getValue() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@

public class BoxWhileTransformer extends AbstractTransformer {

public BoxWhileTransformer(Transpiler processor ) {
public BoxWhileTransformer( Transpiler processor ) {
super( processor );
}

@Override
public void transform(BoxNode node, MethodVisitor visitor) throws IllegalStateException {
public void transform( BoxNode node, MethodVisitor visitor ) throws IllegalStateException {
BoxWhile boxWhile = ( BoxWhile ) node;
Label start = new Label(), end = new Label();
visitor.visitLabel(start);
Label start = new Label(), end = new Label();
visitor.visitLabel( start );
transpiler.transpile( boxWhile.getCondition(), visitor );
visitor.visitJumpInsn(Opcodes.IFEQ, end);
visitor.visitJumpInsn( Opcodes.IFEQ, end );
for ( BoxNode statement : boxWhile.getBody() ) {
transpiler.transform( statement, visitor );
}
visitor.visitJumpInsn(Opcodes.GOTO, start);
visitor.visitLabel(end);
visitor.visitJumpInsn( Opcodes.GOTO, start );
visitor.visitLabel( end );
}
}

0 comments on commit fd8f9f4

Please sign in to comment.