Skip to content

Commit

Permalink
Clean up and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed May 17, 2016
1 parent c6a6ac6 commit 0769be6
Show file tree
Hide file tree
Showing 34 changed files with 555 additions and 535 deletions.
Expand Up @@ -97,7 +97,7 @@ public void ternaryOnNonNull( Expression test, Expression onTrue, Expression onF
} }


@Override @Override
public void eq( Expression lhs, Expression rhs, TypeReference type ) public void equal( Expression lhs, Expression rhs, TypeReference type )
{ {


} }
Expand Down
Expand Up @@ -58,14 +58,14 @@ public void accept( ExpressionVisitor visitor )
}; };
} }


public static Expression eq( final Expression lhs, final Expression rhs, TypeReference type ) public static Expression equal( final Expression lhs, final Expression rhs, TypeReference type )
{ {
return new Expression() return new Expression()
{ {
@Override @Override
public void accept( ExpressionVisitor visitor ) public void accept( ExpressionVisitor visitor )
{ {
visitor.eq( lhs, rhs, type ); visitor.equal( lhs, rhs, type );
} }
}; };
} }
Expand Down
Expand Up @@ -135,22 +135,22 @@ public void ternary( Expression test, Expression onTrue, Expression onFalse )
@Override @Override
public void ternaryOnNull( Expression test, Expression onTrue, Expression onFalse ) public void ternaryOnNull( Expression test, Expression onTrue, Expression onFalse )
{ {
ternary( Expression.eq( test, Expression.constant( null ), TypeReference.OBJECT ), ternary( Expression.equal( test, Expression.constant( null ), TypeReference.OBJECT ),
onTrue, onFalse ); onTrue, onFalse );
} }


@Override @Override
public void ternaryOnNonNull( Expression test, Expression onTrue, Expression onFalse ) public void ternaryOnNonNull( Expression test, Expression onTrue, Expression onFalse )
{ {
ternary( Expression.not( ternary( Expression.not(
Expression.eq( test, Expression.constant( null ), TypeReference.OBJECT )), Expression.equal( test, Expression.constant( null ), TypeReference.OBJECT )),
onTrue, onFalse ); onTrue, onFalse );
} }


@Override @Override
public void eq( Expression lhs, Expression rhs, TypeReference ignored ) public void equal( Expression lhs, Expression rhs, TypeReference ignored )
{ {
result.append( "eq(" ); result.append( "equal(" );
lhs.accept( this ); lhs.accept( this );
result.append( ", " ); result.append( ", " );
rhs.accept( this ); rhs.accept( this );
Expand Down
Expand Up @@ -45,7 +45,7 @@ public interface ExpressionVisitor


void ternaryOnNonNull( Expression test, Expression onTrue, Expression onFalse ); void ternaryOnNonNull( Expression test, Expression onTrue, Expression onFalse );


void eq( Expression lhs, Expression rhs, TypeReference type ); void equal( Expression lhs, Expression rhs, TypeReference type );


void or( Expression lhs, Expression rhs ); void or( Expression lhs, Expression rhs );


Expand Down
Expand Up @@ -215,7 +215,7 @@ public void ternaryOnNonNull( Expression test, Expression onTrue, Expression onF
} }


@Override @Override
public void eq( Expression lhs, Expression rhs, TypeReference type ) public void equal( Expression lhs, Expression rhs, TypeReference type )
{ {
switch ( type.simpleName() ) switch ( type.simpleName() )
{ {
Expand Down
Expand Up @@ -316,7 +316,6 @@ private boolean needsToCallSuperConstructor()
return declaration.isConstructor() && !calledSuper; return declaration.isConstructor() && !calledSuper;
} }



private boolean loadsSuper( Expression expression ) private boolean loadsSuper( Expression expression )
{ {
final boolean[] loadsSuper = new boolean[]{false}; final boolean[] loadsSuper = new boolean[]{false};
Expand Down
Expand Up @@ -161,13 +161,13 @@ public void beginIfNot( Expression test )
@Override @Override
public void beginIfNull( Expression test ) public void beginIfNull( Expression test )
{ {
beginIf(Expression.eq(test, Expression.constant( null ), TypeReference.OBJECT)); beginIf(Expression.equal(test, Expression.constant( null ), TypeReference.OBJECT));
} }


@Override @Override
public void beginIfNonNull( Expression test ) public void beginIfNonNull( Expression test )
{ {
beginIfNot(Expression.eq(test, Expression.constant( null ), TypeReference.OBJECT)); beginIfNot(Expression.equal(test, Expression.constant( null ), TypeReference.OBJECT));
} }


@Override @Override
Expand Down Expand Up @@ -329,20 +329,20 @@ public void ternary( Expression test, Expression onTrue, Expression onFalse )
@Override @Override
public void ternaryOnNull( Expression test, Expression onTrue, Expression onFalse ) public void ternaryOnNull( Expression test, Expression onTrue, Expression onFalse )
{ {
ternary( Expression.eq( test, Expression.constant( null ), TypeReference.OBJECT ), ternary( Expression.equal( test, Expression.constant( null ), TypeReference.OBJECT ),
onTrue, onFalse ); onTrue, onFalse );
} }


@Override @Override
public void ternaryOnNonNull( Expression test, Expression onTrue, Expression onFalse ) public void ternaryOnNonNull( Expression test, Expression onTrue, Expression onFalse )
{ {
ternary( Expression.not( ternary( Expression.not(
Expression.eq( test, Expression.constant( null ), TypeReference.OBJECT )), Expression.equal( test, Expression.constant( null ), TypeReference.OBJECT )),
onTrue, onFalse ); onTrue, onFalse );
} }


@Override @Override
public void eq( Expression lhs, Expression rhs, TypeReference ignored ) public void equal( Expression lhs, Expression rhs, TypeReference ignored )
{ {
lhs.accept( this ); lhs.accept( this );
append( " == " ); append( " == " );
Expand Down
Expand Up @@ -384,7 +384,6 @@ public void shouldGenerateStaticParameterizedTypeField() throws Throwable
assertEquals( Arrays.asList( "FOO", "BAR", "BAZ" ), foo ); assertEquals( Arrays.asList( "FOO", "BAR", "BAZ" ), foo );
} }



public interface Thrower<E extends Exception> public interface Thrower<E extends Exception>
{ {
void doThrow() throws E; void doThrow() throws E;
Expand Down Expand Up @@ -545,7 +544,6 @@ public void shouldGenerateNestedWhileLoop() throws Throwable
methodReference( Iterator.class, boolean.class, "hasNext" ) ) ) ) methodReference( Iterator.class, boolean.class, "hasNext" ) ) ) )
{ {



inner.expression( invoke( inner.expression( invoke(
Expression.cast( Runnable.class, Expression.cast( Runnable.class,
invoke( callEach.load( "targets" ), invoke( callEach.load( "targets" ),
Expand Down Expand Up @@ -1005,7 +1003,6 @@ public void shouldHandleTernaryOperator() throws Throwable
assertTrue( checker1.ranOnTrue ); assertTrue( checker1.ranOnTrue );
assertFalse( checker1.ranOnFalse ); assertFalse( checker1.ranOnFalse );



TernaryChecker checker2 = new TernaryChecker(); TernaryChecker checker2 = new TernaryChecker();
assertThat( ternary.invoke( false, checker2 ), equalTo( "on false" ) ); assertThat( ternary.invoke( false, checker2 ), equalTo( "on false" ) );
assertFalse( checker2.ranOnTrue ); assertFalse( checker2.ranOnTrue );
Expand Down Expand Up @@ -1043,7 +1040,6 @@ public void shouldHandleTernaryOnNullOperator() throws Throwable
assertTrue( checker1.ranOnTrue ); assertTrue( checker1.ranOnTrue );
assertFalse( checker1.ranOnFalse ); assertFalse( checker1.ranOnFalse );



TernaryChecker checker2 = new TernaryChecker(); TernaryChecker checker2 = new TernaryChecker();
assertThat( ternary.invoke( new Object(), checker2 ), equalTo( "on false" ) ); assertThat( ternary.invoke( new Object(), checker2 ), equalTo( "on false" ) );
assertFalse( checker2.ranOnTrue ); assertFalse( checker2.ranOnTrue );
Expand Down Expand Up @@ -1081,7 +1077,6 @@ public void shouldHandleTernaryOnNonNullOperator() throws Throwable
assertTrue( checker1.ranOnTrue ); assertTrue( checker1.ranOnTrue );
assertFalse( checker1.ranOnFalse ); assertFalse( checker1.ranOnFalse );



TernaryChecker checker2 = new TernaryChecker(); TernaryChecker checker2 = new TernaryChecker();
assertThat( ternary.invoke( null, checker2 ), equalTo( "on false" ) ); assertThat( ternary.invoke( null, checker2 ), equalTo( "on false" ) );
assertFalse( checker2.ranOnTrue ); assertFalse( checker2.ranOnTrue );
Expand All @@ -1093,79 +1088,79 @@ public void shouldHandleEquality() throws Throwable
{ {
// boolean // boolean
assertTrue( compareForType( boolean.class, true, true, assertTrue( compareForType( boolean.class, true, true,
( a, b ) -> Expression.eq( a, b, typeReference( boolean.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( boolean.class ) ) ) );
assertTrue( compareForType( boolean.class, false, false, assertTrue( compareForType( boolean.class, false, false,
( a, b ) -> Expression.eq( a, b, typeReference( boolean.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( boolean.class ) ) ) );
assertFalse( compareForType( boolean.class, true, false, assertFalse( compareForType( boolean.class, true, false,
( a, b ) -> Expression.eq( a, b, typeReference( boolean.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( boolean.class ) ) ) );
assertFalse( compareForType( boolean.class, false, true, assertFalse( compareForType( boolean.class, false, true,
( a, b ) -> Expression.eq( a, b, typeReference( boolean.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( boolean.class ) ) ) );


// byte // byte
assertTrue( compareForType( byte.class, (byte) 42, (byte) 42, assertTrue( compareForType( byte.class, (byte) 42, (byte) 42,
( a, b ) -> Expression.eq( a, b, typeReference( byte.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( byte.class ) ) ) );
assertFalse( compareForType( byte.class, (byte) 43, (byte) 42, assertFalse( compareForType( byte.class, (byte) 43, (byte) 42,
( a, b ) -> Expression.eq( a, b, typeReference( byte.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( byte.class ) ) ) );
assertFalse( compareForType( byte.class, (byte) 42, (byte) 43, assertFalse( compareForType( byte.class, (byte) 42, (byte) 43,
( a, b ) -> Expression.eq( a, b, typeReference( byte.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( byte.class ) ) ) );


// short // short
assertTrue( compareForType( short.class, (short) 42, (short) 42, assertTrue( compareForType( short.class, (short) 42, (short) 42,
( a, b ) -> Expression.eq( a, b, typeReference( short.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( short.class ) ) ) );
assertFalse( compareForType( short.class, (short) 43, (short) 42, assertFalse( compareForType( short.class, (short) 43, (short) 42,
( a, b ) -> Expression.eq( a, b, typeReference( short.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( short.class ) ) ) );
assertFalse( compareForType( short.class, (short) 42, (short) 43, assertFalse( compareForType( short.class, (short) 42, (short) 43,
( a, b ) -> Expression.eq( a, b, typeReference( short.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( short.class ) ) ) );


// char // char
assertTrue( compareForType( char.class, (char) 42, (char) 42, assertTrue( compareForType( char.class, (char) 42, (char) 42,
( a, b ) -> Expression.eq( a, b, typeReference( char.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( char.class ) ) ) );
assertFalse( compareForType( char.class, (char) 43, (char) 42, assertFalse( compareForType( char.class, (char) 43, (char) 42,
( a, b ) -> Expression.eq( a, b, typeReference( char.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( char.class ) ) ) );
assertFalse( compareForType( char.class, (char) 42, (char) 43, assertFalse( compareForType( char.class, (char) 42, (char) 43,
( a, b ) -> Expression.eq( a, b, typeReference( char.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( char.class ) ) ) );


//int //int
assertTrue( compareForType( int.class, 42, 42, assertTrue( compareForType( int.class, 42, 42,
( a, b ) -> Expression.eq( a, b, typeReference( int.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( int.class ) ) ) );
assertFalse( compareForType( int.class, 43, 42, assertFalse( compareForType( int.class, 43, 42,
( a, b ) -> Expression.eq( a, b, typeReference( int.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( int.class ) ) ) );
assertFalse( compareForType( int.class, 42, 43, assertFalse( compareForType( int.class, 42, 43,
( a, b ) -> Expression.eq( a, b, typeReference( int.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( int.class ) ) ) );


//long //long
assertTrue( compareForType( long.class, 42L, 42L, assertTrue( compareForType( long.class, 42L, 42L,
( a, b ) -> Expression.eq( a, b, typeReference( long.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( long.class ) ) ) );
assertFalse( compareForType( long.class, 43L, 42L, assertFalse( compareForType( long.class, 43L, 42L,
( a, b ) -> Expression.eq( a, b, typeReference( long.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( long.class ) ) ) );
assertFalse( compareForType( long.class, 42L, 43L, assertFalse( compareForType( long.class, 42L, 43L,
( a, b ) -> Expression.eq( a, b, typeReference( long.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( long.class ) ) ) );


//float //float
assertTrue( compareForType( float.class, 42F, 42F, assertTrue( compareForType( float.class, 42F, 42F,
( a, b ) -> Expression.eq( a, b, typeReference( float.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( float.class ) ) ) );
assertFalse( compareForType( float.class, 43F, 42F, assertFalse( compareForType( float.class, 43F, 42F,
( a, b ) -> Expression.eq( a, b, typeReference( float.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( float.class ) ) ) );
assertFalse( compareForType( float.class, 42F, 43F, assertFalse( compareForType( float.class, 42F, 43F,
( a, b ) -> Expression.eq( a, b, typeReference( float.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( float.class ) ) ) );


//double //double
assertTrue( compareForType( double.class, 42D, 42D, assertTrue( compareForType( double.class, 42D, 42D,
( a, b ) -> Expression.eq( a, b, typeReference( double.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( double.class ) ) ) );
assertFalse( compareForType( double.class, 43D, 42D, assertFalse( compareForType( double.class, 43D, 42D,
( a, b ) -> Expression.eq( a, b, typeReference( double.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( double.class ) ) ) );
assertFalse( compareForType( double.class, 42D, 43D, assertFalse( compareForType( double.class, 42D, 43D,
( a, b ) -> Expression.eq( a, b, typeReference( double.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( double.class ) ) ) );


//reference //reference
Object obj1 = new Object(); Object obj1 = new Object();
Object obj2 = new Object(); Object obj2 = new Object();
assertTrue( compareForType( Object.class, obj1, obj1, assertTrue( compareForType( Object.class, obj1, obj1,
( a, b ) -> Expression.eq( a, b, typeReference( Object.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( Object.class ) ) ) );
assertFalse( compareForType( Object.class, obj1, obj2, assertFalse( compareForType( Object.class, obj1, obj2,
( a, b ) -> Expression.eq( a, b, typeReference( Object.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( Object.class ) ) ) );
assertFalse( compareForType( Object.class, obj2, obj1, assertFalse( compareForType( Object.class, obj2, obj1,
( a, b ) -> Expression.eq( a, b, typeReference( Object.class ) ) ) ); ( a, b ) -> Expression.equal( a, b, typeReference( Object.class ) ) ) );
} }


@Test @Test
Expand Down Expand Up @@ -1410,7 +1405,6 @@ public void shouldGenerateTryCatch() throws Throwable
doThrow( theFailure ).when( failBody ).run(); doThrow( theFailure ).when( failBody ).run();
MethodHandle run = instanceMethod( handle.newInstance(), "run", Runnable.class, Runnable.class ); MethodHandle run = instanceMethod( handle.newInstance(), "run", Runnable.class, Runnable.class );



//success //success
run.invoke( successBody, successCatch ); run.invoke( successBody, successCatch );
verify( successBody ).run(); verify( successBody ).run();
Expand Down Expand Up @@ -1454,7 +1448,6 @@ public void shouldGenerateTryCatchWithNestedBlock() throws Throwable
Runnable runnable = mock( Runnable.class ); Runnable runnable = mock( Runnable.class );
MethodHandle run = instanceMethod( handle.newInstance(), "run", Runnable.class, Runnable.class, boolean.class ); MethodHandle run = instanceMethod( handle.newInstance(), "run", Runnable.class, Runnable.class, boolean.class );



// then // then
run.invoke( runnable, mock( Runnable.class ), false ); run.invoke( runnable, mock( Runnable.class ), false );
verify( runnable, never() ).run(); verify( runnable, never() ).run();
Expand Down Expand Up @@ -1489,7 +1482,6 @@ public void shouldGenerateTryAndMultipleCatch() throws Throwable
} }


// when // when

Runnable body1 = mock( Runnable.class ), body2 = mock( Runnable.class ), Runnable body1 = mock( Runnable.class ), body2 = mock( Runnable.class ),
catcher11 = mock( Runnable.class ), catcher12 = mock( Runnable.class ), catcher11 = mock( Runnable.class ), catcher12 = mock( Runnable.class ),
catcher21 = mock( Runnable.class ), catcher22 = mock( Runnable.class ); catcher21 = mock( Runnable.class ), catcher22 = mock( Runnable.class );
Expand All @@ -1499,20 +1491,17 @@ public void shouldGenerateTryAndMultipleCatch() throws Throwable
MethodHandle run = MethodHandle run =
instanceMethod( handle.newInstance(), "run", Runnable.class, Runnable.class, Runnable.class ); instanceMethod( handle.newInstance(), "run", Runnable.class, Runnable.class, Runnable.class );



run.invoke( body1, catcher11, catcher12 ); run.invoke( body1, catcher11, catcher12 );
verify( body1 ).run(); verify( body1 ).run();
verify( catcher11 ).run(); verify( catcher11 ).run();
verify( catcher12, never() ).run(); verify( catcher12, never() ).run();



run.invoke( body2, catcher21, catcher22 ); run.invoke( body2, catcher21, catcher22 );
verify( body2 ).run(); verify( body2 ).run();
verify( catcher22 ).run(); verify( catcher22 ).run();
verify( catcher21, never() ).run(); verify( catcher21, never() ).run();
} }



@Test @Test
public void shouldThrowException() throws Throwable public void shouldThrowException() throws Throwable
{ {
Expand Down
Expand Up @@ -28,10 +28,6 @@ import scala.collection.JavaConverters._


class MatchAcceptanceTest extends ExecutionEngineFunSuite with QueryStatisticsTestSupport with NewPlannerTestSupport { class MatchAcceptanceTest extends ExecutionEngineFunSuite with QueryStatisticsTestSupport with NewPlannerTestSupport {


test("foo") {
println(executeWithAllPlanners("EXPLAIN RETURN 1 + 2").executionPlanDescription())
println(executeWithAllPlannersAndRuntimesAndCompatibilityMode("RETURN 1 + 2").dumpToString())
}
test("make sure non-existing nodes are not returned") { test("make sure non-existing nodes are not returned") {
executeWithAllPlannersAndCompatibilityMode("match (n) where id(n) = 10 return n") should be(empty) executeWithAllPlannersAndCompatibilityMode("match (n) where id(n) = 10 return n") should be(empty)
executeWithAllPlannersAndCompatibilityMode("match ()-[r]->() where id(r) = 10 return r") should be(empty) executeWithAllPlannersAndCompatibilityMode("match ()-[r]->() where id(r) = 10 return r") should be(empty)
Expand Down
Expand Up @@ -47,11 +47,6 @@ public CompilationPhaseEvent beginPhase( CompilationPhase phase )
return NONE_PHASE; return NONE_PHASE;
} }
}; };
CompilationPhaseEvent NONE_PHASE = new CompilationPhaseEvent() CompilationPhaseEvent NONE_PHASE = () -> {
{
@Override
public void close()
{
}
}; };
} }
Expand Up @@ -19,7 +19,7 @@
*/ */
package org.neo4j.cypher.internal.compiler.v3_1.codegen package org.neo4j.cypher.internal.compiler.v3_1.codegen


import org.neo4j.helpers.Clock import java.time.Clock


/** /**
* Configuration modes for code generation * Configuration modes for code generation
Expand Down Expand Up @@ -47,6 +47,6 @@ case object ByteCodeMode extends CodeGenMode
*/ */
case class CodeGenConfiguration(mode: CodeGenMode = ByteCodeMode, case class CodeGenConfiguration(mode: CodeGenMode = ByteCodeMode,
saveSource: Boolean = false, saveSource: Boolean = false,
clock: Clock = Clock.SYSTEM_CLOCK, clock: Clock = Clock.systemUTC(),
packageName: String = "org.neo4j.cypher.internal.compiler.v3_1.generated" packageName: String = "org.neo4j.cypher.internal.compiler.v3_1.generated"
) )
Expand Up @@ -51,7 +51,7 @@ class CodeGenerator(val structure: CodeStructure[GeneratedQuery], conf: CodeGenC


val fp = planContext.statistics match { val fp = planContext.statistics match {
case igs: InstrumentedGraphStatistics => case igs: InstrumentedGraphStatistics =>
Some(PlanFingerprint(conf.clock.currentTimeMillis(), planContext.txIdProvider(), igs.snapshot.freeze)) Some(PlanFingerprint(conf.clock.millis(), planContext.txIdProvider(), igs.snapshot.freeze))
case _ => case _ =>
None None
} }
Expand Down

0 comments on commit 0769be6

Please sign in to comment.