Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 3fa03ca

Browse files
authored
Haxe-Cpp synchronized blocks & methods support + Thread improvements in all targets + Kotlin 1.1.4-2 (#264)
* Haxe-Cpp synchronized blocks support + Thread improvements in all targets + Kotlin 1.1.4-2 * Small fix * Extract modifier convenience properties * Add synchronized method test * Remove old comments * Use new modifier shortcuts + reformat * Support synchronized methods in haxe * Initial common synchronized method support * Complete unification of synchronized method support for targets supporting finally * Fixed C# target * Initial C# Thread support * Do not reference System.out or System.err if possible * Revert "Do not reference System.out or System.err if possible" This reverts commit f245c2f * Test threads on D target
1 parent 4670454 commit 3fa03ca

File tree

33 files changed

+879
-510
lines changed

33 files changed

+879
-510
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
jtranscVersion=0.6.7
2-
kotlinVersion=1.1.4
2+
kotlinVersion=1.1.4-2
33
file.encoding=UTF-8
44
kotlin.incremental=true
55
org.gradle.daemon=true

jtransc-core/src/com/jtransc/ast/ast.kt

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,12 @@ class AstClass(
340340
val source: String,
341341
program: AstProgram,
342342
val name: FqName,
343-
val modifiers: AstModifiers,
343+
override val modifiers: AstModifiers,
344344
val extending: FqName? = null,
345345
val implementing: List<FqName> = listOf(),
346346
annotations: List<AstAnnotation> = listOf(),
347347
val classId: Int = program.lastClassId++
348-
) : AstAnnotatedElement(program, name.ref, annotations), IUserData by UserData() {
348+
) : AstAnnotatedElement(program, name.ref, annotations), IUserData by UserData(), WithAstModifiersClass {
349349
val types get() = program.types
350350

351351
val implementingUnique by lazy { implementing.distinct() }
@@ -680,14 +680,14 @@ class AstField(
680680
val id: Int = containingClass.program.lastFieldId++,
681681
name: String,
682682
type: AstType,
683-
val modifiers: AstModifiers,
683+
override val modifiers: AstModifiers,
684684
val desc: String,
685685
annotations: List<AstAnnotation>,
686686
val genericSignature: String?,
687687
val constantValue: Any? = null,
688688
val types: AstTypes,
689689
override val ref: AstFieldRef = AstFieldRef(containingClass.name, name, type)
690-
) : AstMember(containingClass, name, type, if (genericSignature != null) types.demangle(genericSignature) else type, modifiers.isStatic, modifiers.visibility, ref, annotations), FieldRef {
690+
) : AstMember(containingClass, name, type, if (genericSignature != null) types.demangle(genericSignature) else type, modifiers.isStatic, modifiers.visibility, ref, annotations), FieldRef, WithAstModifiersField {
691691
val uniqueName = containingClass.uniqueNames.alloc(name)
692692
val isFinal: Boolean = modifiers.isFinal
693693
val refWithoutClass: AstFieldWithoutClassRef by lazy { AstFieldWithoutClassRef(this.name, this.type) }
@@ -711,7 +711,7 @@ class AstMethod constructor(
711711
val signature: String,
712712
val genericSignature: String?,
713713
val defaultTag: Any?,
714-
val modifiers: AstModifiers,
714+
override val modifiers: AstModifiers,
715715
var generateBody: () -> AstBody?,
716716
val bodyRef: AstMethodRef? = null,
717717
val parameterAnnotations: List<List<AstAnnotation>> = listOf(),
@@ -721,7 +721,7 @@ class AstMethod constructor(
721721
containingClass, name, methodType,
722722
if (genericSignature != null) containingClass.types.demangleMethod(genericSignature) else methodType,
723723
modifiers.isStatic, modifiers.visibility, ref, annotations
724-
), MethodRef {
724+
), MethodRef, WithAstModifiersMethod {
725725
val types: AstTypes get() = program.types
726726

727727
val parameterAnnotationsList: List<AstAnnotationList> = parameterAnnotations.map { AstAnnotationList(ref, it) }
@@ -736,8 +736,6 @@ class AstMethod constructor(
736736
}
737737
}
738738

739-
val isNative: Boolean = modifiers.isNative
740-
741739
private var generatedBody: Boolean = false
742740
private var generatedBodyBody: AstBody? = null
743741

@@ -845,8 +843,19 @@ val AstMethodRef.isInstanceInit: Boolean get() = name == "<init>"
845843
val AstMethodRef.isClassInit: Boolean get() = name == "<clinit>"
846844
val AstMethodRef.isClassOrInstanceInit: Boolean get() = isInstanceInit || isClassInit
847845

846+
interface WithAstModifiers {
847+
val modifiers: AstModifiers
848+
}
849+
850+
interface WithAstModifiersMember : WithAstModifiers
851+
interface WithAstModifiersMethod : WithAstModifiersMember
852+
interface WithAstModifiersField : WithAstModifiersMember
853+
interface WithAstModifiersParameter : WithAstModifiers
854+
interface WithAstModifiersClass : WithAstModifiers
855+
848856
@Suppress("unused")
849-
data class AstModifiers(val acc: Int) {
857+
data class AstModifiers(val acc: Int) : WithAstModifiersMethod, WithAstModifiersField, WithAstModifiersClass, WithAstModifiersParameter {
858+
override val modifiers = this
850859
companion object {
851860
fun withFlags(vararg flags: Int): AstModifiers {
852861
var out = 0
@@ -875,43 +884,6 @@ data class AstModifiers(val acc: Int) {
875884
const val ACC_MANDATED = 0x8000 // parameter
876885
}
877886

878-
val isPublic: Boolean get() = acc hasFlag ACC_PUBLIC
879-
val isPrivate: Boolean get() = acc hasFlag ACC_PRIVATE
880-
val isProtected: Boolean get() = acc hasFlag ACC_PROTECTED
881-
val isStatic: Boolean get() = acc hasFlag ACC_STATIC
882-
val isFinal: Boolean get() = acc hasFlag ACC_FINAL
883-
val isSuper: Boolean get() = acc hasFlag ACC_SUPER
884-
val isSynchronized: Boolean get() = acc hasFlag ACC_SYNCHRONIZED
885-
val isVolatile: Boolean get() = acc hasFlag ACC_VOLATILE
886-
val isBridge: Boolean get() = acc hasFlag ACC_BRIDGE
887-
val isVarargs: Boolean get() = acc hasFlag ACC_VARARGS
888-
val isTransient: Boolean get() = acc hasFlag ACC_TRANSIENT
889-
val isNative: Boolean get() = acc hasFlag ACC_NATIVE
890-
val isInterface: Boolean get() = acc hasFlag ACC_INTERFACE
891-
val isAbstract: Boolean get() = acc hasFlag ACC_ABSTRACT
892-
val isStrict: Boolean get() = acc hasFlag ACC_STRICT
893-
val isSynthetic: Boolean get() = acc hasFlag ACC_SYNTHETIC
894-
val isAnnotation: Boolean get() = acc hasFlag ACC_ANNOTATION
895-
val isEnum: Boolean get() = acc hasFlag ACC_ENUM
896-
val isMandated: Boolean get() = acc hasFlag ACC_MANDATED
897-
val isConcrete: Boolean get() = !isNative && !isAbstract
898-
899-
val visibility: AstVisibility get() = if (isPublic) {
900-
AstVisibility.PUBLIC
901-
} else if (isProtected) {
902-
AstVisibility.PROTECTED
903-
} else {
904-
AstVisibility.PRIVATE
905-
}
906-
907-
val classType: AstClassType get() = if (isInterface) {
908-
AstClassType.INTERFACE
909-
} else if (isAbstract) {
910-
AstClassType.ABSTRACT
911-
} else {
912-
AstClassType.CLASS
913-
}
914-
915887
fun with(flags: Int) = AstModifiers(this.acc or flags)
916888
fun without(flags: Int) = AstModifiers(this.acc and flags.inv())
917889

@@ -927,6 +899,38 @@ data class AstModifiers(val acc: Int) {
927899
override fun toString(): String = "$acc"
928900
}
929901

902+
val WithAstModifiers.isPublic: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_PUBLIC
903+
val WithAstModifiers.isPrivate: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_PRIVATE
904+
val WithAstModifiers.isProtected: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_PROTECTED
905+
val WithAstModifiersMember.isStatic: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_STATIC
906+
val WithAstModifiers.isFinal: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_FINAL
907+
val WithAstModifiersMethod.isSynchronized: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_SYNCHRONIZED
908+
val WithAstModifiersField.isVolatile: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_VOLATILE
909+
val WithAstModifiersMethod.isBridge: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_BRIDGE
910+
val WithAstModifiersMethod.isVarargs: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_VARARGS
911+
val WithAstModifiersField.isTransient: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_TRANSIENT
912+
val WithAstModifiersMethod.isNative: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_NATIVE
913+
val WithAstModifiersMethod.isAbstract: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_ABSTRACT
914+
val WithAstModifiersMethod.isStrict: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_STRICT
915+
val WithAstModifiers.isSynthetic: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_SYNTHETIC
916+
val WithAstModifiersParameter.isMandated: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_MANDATED
917+
val WithAstModifiersMethod.isConcrete: Boolean get() = !isNative && !isAbstract
918+
val WithAstModifiers.visibility: AstVisibility get() = when {
919+
isPublic -> AstVisibility.PUBLIC
920+
isProtected -> AstVisibility.PROTECTED
921+
else -> AstVisibility.PRIVATE
922+
}
923+
val WithAstModifiersClass.isSuper: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_SUPER
924+
val WithAstModifiersClass.isInterface: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_INTERFACE
925+
val WithAstModifiersClass.isAbstract: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_ABSTRACT
926+
val WithAstModifiersClass.isAnnotation: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_ANNOTATION
927+
val WithAstModifiersClass.isEnum: Boolean get() = modifiers.acc hasFlag AstModifiers.ACC_ENUM
928+
val WithAstModifiersClass.classType: AstClassType get() = when {
929+
isInterface -> AstClassType.INTERFACE
930+
isAbstract -> AstClassType.ABSTRACT
931+
else -> AstClassType.CLASS
932+
}
933+
930934
fun ARRAY(type: AstClass) = AstType.ARRAY(type.astType)
931935

932936
fun getCommonTypePrim(a: AstType.Primitive, b: AstType.Primitive): AstType.Primitive {

jtransc-core/src/com/jtransc/ast/ast_body.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ object AstExprUtils {
721721
val clazz = program.get3(e.method.classRef)
722722
val refMethod = program.get(e.method) ?: invalidOp("Can't find method: ${e.method} while generating $context")
723723
// https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.invokespecial
724-
return if (refMethod.modifiers.isPrivate || refMethod.isInstanceInit) {
724+
return if (refMethod.isPrivate || refMethod.isInstanceInit) {
725725
// Call this!
726726
AstExpr.CALL_INSTANCE(e.obj.value, e.method, e.args.map { it.value }, e.isSpecial)
727727
} else {

jtransc-core/src/com/jtransc/ast/template/CommonTagHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ object CommonTagHandler {
4242
val desc2 = dataParts.joinToString(":")
4343
val classFqname = resolveClassName(dataParts[0], params)
4444
if (!program.contains(classFqname)) {
45-
invalidOp("evalReference: Can't find class '$classFqname' (I)")
45+
invalidOp("evalReference: Can't find class '$classFqname' (I) : parts : $dataParts")
4646
}
4747
val clazz = program[classFqname]
4848
val types = program.types

jtransc-core/src/com/jtransc/ast/treeshaking/TemplateReferences.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ fun GetClassTemplateReferences(program: AstProgram, templateStr: String, current
2727
return _GetTemplateReferences(program, templateStr, currentClass, classes = true, config = config).map { (it as CommonTagHandler.CLASS_REF).clazz }
2828
}
2929

30-
3130
fun _GetTemplateReferences(program: AstProgram, templateStr: String, currentClass: FqName, classes: Boolean, config: TRefConfig): List<CommonTagHandler.Result> {
3231
val refs = arrayListOf<CommonTagHandler.Result>()
3332
val params: HashMap<String, Any?> = hashMapOf("CLASS" to currentClass.fqname)

0 commit comments

Comments
 (0)