Skip to content

Commit

Permalink
Merge pull request #35 from DoclerLabs/develop
Browse files Browse the repository at this point in the history
prepare 0.34.0
  • Loading branch information
aliokan authored Jan 15, 2018
2 parents 1203362 + 3fc535d commit 2fa1883
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/hex/compiletime/basic/StaticCompileTimeContextFactory.hx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ class StaticCompileTimeContextFactory extends CompileTimeContextFactory
else if ( constructorVO.cType != null ) constructorVO.cType;
else ContextFactoryUtil.getComplexType( constructorVO.type, constructorVO.filePosition );

if ( constructorVO.isPublic )
if ( constructorVO.isPublic || constructorVO.lazy )
{
hex.compiletime.util.ContextBuilder.getInstance( this )
.addField( id, type, constructorVO.filePosition, (constructorVO.lazy?result:null) );
.addField( id, type, constructorVO.filePosition, (constructorVO.lazy?result:null), constructorVO.isPublic );

if ( !constructorVO.lazy )
{
Expand Down
18 changes: 6 additions & 12 deletions src/hex/compiletime/factory/ClassInstanceFactory.hx
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,15 @@ class ClassInstanceFactory
if ( staticRef != null )//static variable - with factory method
{
var e = _staticRefFactory( pack, staticRef, factoryMethod, args );
vo.type = try _fqcn( e )//Assign right type description
catch ( e : Dynamic )
try _fqcn( _staticRefFactory( pack, staticRef, factoryMethod, _nullArray( argsLength ) ) )
catch ( e : Dynamic ) _blankType( vo );
vo.type = vo.abstractType != null ? vo.abstractType :
try _fqcn( e ) catch ( e : Dynamic ) _blankType( vo );
getResult( e, id, vo );
}
else if ( staticCall != null )//static method call - with factory method
{
var e = _staticCallFactory( pack, staticCall, factoryMethod, args );
vo.type = try _fqcn( e )//Assign right type description
catch ( e : Dynamic )
try _fqcn( _staticCallFactory( pack, staticCall, factoryMethod, _nullArray( argsLength ) ) )
catch ( e : Dynamic ) _blankType( vo );
vo.type = vo.abstractType != null ? vo.abstractType :
try _fqcn( e ) catch ( e : Dynamic ) _blankType( vo );

getResult( e, id, vo );
}
Expand All @@ -94,10 +90,8 @@ class ClassInstanceFactory
else if ( staticCall != null )//simple static method call
{
var e = _staticCall( pack, staticCall, args );
vo.type = try _fqcn( e )//Assign right type description
catch ( e : Dynamic )
try _fqcn( _staticCall( pack, staticCall, _nullArray( argsLength ) ) )
catch ( e : Dynamic ) _blankType( vo );
vo.type = vo.abstractType != null ? vo.abstractType :
try _fqcn( e ) catch ( e : Dynamic ) _blankType( vo );

getResult( e, id, vo );
}
Expand Down
9 changes: 5 additions & 4 deletions src/hex/compiletime/util/ContextBuilder.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hex.compiletime.util;

#if macro
import haxe.macro.Expr.Access;
import haxe.macro.Expr.TypeDefinition;
import hex.core.IApplicationContext;
import hex.core.HashCodeFactory;
Expand Down Expand Up @@ -88,9 +89,9 @@ class ContextBuilder
ContextBuilder._Map.set( owner, new ContextBuilder( owner, applicationContextClassName ) );
}

public function addField( fieldName : String, ct : haxe.macro.Expr.ComplexType, pos : haxe.macro.Expr.Position, lazyExpr : haxe.macro.Expr = null ) : Void
public function addField( fieldName : String, ct : haxe.macro.Expr.ComplexType, pos : haxe.macro.Expr.Position, lazyExpr : haxe.macro.Expr = null, isPublic : Bool = true ) : Void
{
var field = ContextUtil.buildField( fieldName, ct, pos, lazyExpr!=null );
var field = ContextUtil.buildField( fieldName, ct, pos, lazyExpr!=null, isPublic );
this._iteration.definition.fields.push( field );

if ( lazyExpr != null )
Expand All @@ -103,7 +104,7 @@ class ContextBuilder
}
return this.$fieldName;
}
var lazyField = ContextUtil.buildLazyField( fieldName, ct, lazyExpr, pos );
var lazyField = ContextUtil.buildLazyField( fieldName, ct, lazyExpr, pos, isPublic );
this._iteration.definition.fields.push( lazyField );
}
}
Expand All @@ -130,7 +131,7 @@ class ContextBuilder

for ( field in this._iteration.definition.fields )
{
if ( field.name != 'new' )
if ( field.name != 'new' && field.access.indexOf( APrivate ) == -1 )
{
switch( field.kind )
{
Expand Down
12 changes: 6 additions & 6 deletions src/hex/compiletime/util/ContextUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -140,35 +140,35 @@ class ContextUtil
return classExpr;
}

public static function buildField( instanceID : String, ct : ComplexType, pos : haxe.macro.Expr.Position, lazy : Bool ) : Field
public static function buildField( instanceID : String, ct : ComplexType, pos : haxe.macro.Expr.Position, lazy : Bool, isPublic : Bool = true ) : Field
{
return !lazy ?
{
name: instanceID,
pos: pos,
kind: FVar( ct ),
access: [ APublic ]
access: isPublic ? [ APublic ] : [ APrivate ]
}
:
{
name: instanceID,
pos: pos,
kind: FProp( 'get', 'null', ct ),
access: [ APublic ]
access: isPublic ? [ APublic ] : [ APrivate ]
}
}

public static function buildLazyField( instanceID : String, ct : ComplexType, body : Expr, pos : haxe.macro.Expr.Position ) : Field
public static function buildLazyField( instanceID : String, ct : ComplexType, body : Expr, pos : haxe.macro.Expr.Position, isPublic : Bool = true ) : Field
{
var lazyField : Field =
{
name: 'get_' + instanceID,
meta: [ { name: ":noCompletion", params: [], pos: pos } ],
pos: pos,
kind: null,
access: [ APublic ]
access: isPublic ? [ APublic ] : [ APrivate ]
}

lazyField.kind = FFun(
{
args: [],
Expand Down
2 changes: 1 addition & 1 deletion src/hex/vo/ConstructorVO.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ConstructorVO extends AssemblerVO

public var abstractType : String;
public var lazy : Bool;
public var isPublic : Bool;
public var isPublic = false;

public var shouldAssign = true;

Expand Down
5 changes: 5 additions & 0 deletions test/context/flow/closureFromStaticCall.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@context
{
@public
test = hex.mock.Sample.test();
}
6 changes: 6 additions & 0 deletions test/context/flow/genericInference.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@context
{
@type("hex.mock.Sample")
sample = hex.mock.Sample.getSomething();
sample.testType( sample );
}
13 changes: 13 additions & 0 deletions test/context/flow/primitives/publicString.flow
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,17 @@
isPublic = 'isPublic';

isPrivate = 'isPrivate';

@public
wasPrivate = isPrivate;

@lazy
@public
isLazy = hex.mock.MockLazyFactory.getLazy( '3' );

@lazy
isPrivateAndLazy = hex.mock.MockLazyFactory.getLazy( '4' );

@public
wasPrivateAndLazy = isPrivateAndLazy;
}
22 changes: 22 additions & 0 deletions test/hex/compiletime/flow/BasicStaticFlowCompilerTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import hex.mock.MockReceiver;
import hex.mock.MockRectangle;
import hex.mock.MockServiceProvider;
import hex.mock.MockTriggerListener;
import hex.mock.Sample;
import hex.runtime.ApplicationAssembler;
import hex.structures.Point;
import hex.structures.Size;
Expand Down Expand Up @@ -1297,6 +1298,27 @@ class BasicStaticFlowCompilerTest
code.execute();

Assert.equals( 'isPublic', code.locator.isPublic );
Assert.equals( 'isPrivate', code.locator.wasPrivate );
Assert.equals( '3', code.locator.isLazy );
Assert.equals( '4', code.locator.wasPrivateAndLazy );
//Assert.equals( 4, code.locator.isPrivateAndLazy );
}

@Test( "test generic inference" )
public function testGenericInference() : Void
{
Sample.value = null;
var code = BasicStaticFlowCompiler.compile( this._myApplicationAssembler, "context/flow/genericInference.flow", "BasicStaticFlowCompiler_testGenericInference" );
code.execute();
Assert.isNotNull( Sample.value );
}

@Test( "test closure returned from static call" )
public function testClosureReturnedFromStaticCall() : Void
{
var code = BasicStaticFlowCompiler.compile( this._myApplicationAssembler, "context/flow/closureFromStaticCall.flow", "BasicStaticFlowCompiler_testClosureReturnedFromStaticCall" );
code.execute();
Assert.equals( "test", code.locator.test() );
}
}

12 changes: 12 additions & 0 deletions test/hex/mock/MockLazyFactory.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package hex.mock;

/**
* ...
* @author Francis Bourre
*/
class MockLazyFactory
{
function new() { }

public static function getLazy<T>( value : T ) return value;
}
21 changes: 21 additions & 0 deletions test/hex/mock/Sample.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package hex.mock;

/**
* ...
* @author Francis Bourre
*/
class Sample
{
static public var value : Sample;

public function new() {}

public function testType( value : Sample ) : Void
Sample.value = value;

static public function getSomething<T>() : T
return cast new Sample();

static public function test() : Void->String
return function () return "test";
}

0 comments on commit 2fa1883

Please sign in to comment.